Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help
Special pages
SBGrid Resources
SBGrid Consortium
SBGrid Data Bank
Software Webinars
PyMOL Webinar
PyMOL Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
FocalBlur
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Script== Load the script using the [[run]] command <source lang="python"> from pymol import cmd from tempfile import mkdtemp from shutil import rmtree from math import sin,cos,pi,sqrt from PIL import Image def FocalBlur(aperture=2.0,samples=10,ray=0,width=0,height=0): ''' DESCRIPTION Creates fancy figures by introducing a focal blur to the image. The object at the origin will be in focus. AUTHOR Jarl Underhaug University of Bergen jarl_dot_underhaug_at_gmail_dot_com Updates by Jason Vertrees and Thomas Holder USAGE FocalBlur aperture=float, samples=int, ray=0/1, width=int, height=int EXAMPELS FocalBlur aperture=1, samples=100 FocalBlur aperture=2, samples=100, ray=1, width=600, height=400 ''' # Formalize the parameter types ray = (ray in ("True", "true", 1, "1")) aperture, samples = float(aperture), int(samples) width, height = int(width), int(height) # Create a temporary directory tmpdir = mkdtemp() # Get the orientation of the protein and the light light = cmd.get('light')[1:-1] light = [float(s) for s in light.split(',')] view = cmd.get_view() # Rotate the protein and the light in order to create the blur for frame in range(samples): # Angles to rotate protein and light # Populate angles as Fermat's spiral theta = frame * pi * 110.0/144.0 radius = 0.5 * aperture * sqrt(frame/float(samples-1)) x = cos(theta) * radius y = sin(theta) * radius xr = x/180.0*pi yr = y/180.0*pi # Rotate the protein cmd.turn('x',x) cmd.turn('y',y) # Rotate the light ly = light[1]*cos(xr)-light[2]*sin(xr) lz = light[2]*cos(xr)+light[1]*sin(xr) lx = light[0]*cos(yr)+lz*sin(yr) lz = lz*cos(yr)-lx*sin(yr) cmd.set('light',[lx,ly,lz]) curFile = "%s/frame-%04d.png" % (tmpdir,frame) print "Created frame %i/%i (%0.0f%%)" % (frame+1,samples,100*(frame+1)/samples) # Save the image to temporary directory if ray: cmd.ray(width,height) cmd.png(curFile) else: cmd.png(curFile,quiet=1) # Create the average/blured image try: avg = Image.blend(avg,Image.open(curFile),1.0/(frame+1)) except: avg = Image.open(curFile) # Return the protein and the light to the original orientation cmd.set('light',light) cmd.set_view(view) # Load the blured image avg.save('%s/avg.png' % (tmpdir)) cmd.load('%s/avg.png' % (tmpdir)) # Delete the temporary files rmtree(tmpdir) cmd.extend('FocalBlur', FocalBlur) </source> [[Category:Script_Library]]
Summary:
Please note that all contributions to PyMOL Wiki are considered to be released under the GNU Free Documentation License 1.2 (see
PyMOL Wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
FocalBlur
(section)
Add topic