Example #1
0
 def _test_recall(self):
     cmd.scene('s1', 'recall')
     cmd.ray(1, 1)  # force scene update
     self.assertEqual(['m3'], cmd.get_object_list('(visible)'))
     self.assertEqual(['m3'], cmd.get_object_list('(enabled)'))
     cmd.enable('g1')
     cmd.ray(1, 1)  # force scene update
     self.assertEqual(['m1', 'm3'], cmd.get_object_list('(visible)'))
     self.assertEqual(['m1', 'm3'], cmd.get_object_list('(enabled)'))
Example #2
0
 def _test_recall(self):
     cmd.scene('s1', 'recall')
     cmd.ray(1, 1)  # force scene update
     self.assertEqual(['m3'], cmd.get_object_list('(visible)'))
     self.assertEqual(['m3'], cmd.get_object_list('(enabled)'))
     cmd.enable('g1')
     cmd.ray(1, 1)  # force scene update
     self.assertEqual(['m1', 'm3'], cmd.get_object_list('(visible)'))
     self.assertEqual(['m1', 'm3'], cmd.get_object_list('(enabled)'))
Example #3
0
def scenes_to_frames():
    """Assign scenes to frames"""
    # Scene 001 from frames 1-150
    cmd.scene('001', animate=0)
    cmd.mview('store', 1)
    cmd.mview('store', 150)
    # Scene 002 from frames 250-400
    cmd.scene('002', animate=0)
    cmd.mview('store', 250)
    cmd.mview('store', 400)
def scenes_to_frames():
    """Assign scenes to frames"""
    # Scene 001 from frames 1-150
    cmd.scene('001', animate=0)
    cmd.mview('store', 1)
    cmd.mview('store', 150)
    # Scene 002 from frames 250-400
    cmd.scene('002', animate=0)
    cmd.mview('store', 250)
    cmd.mview('store', 400)
Example #5
0
def additional_camera():
    # Add a rotation to the global view
    cmd.scene('001', animate=0)
    cmd.turn('y', -40)
    cmd.mview('store', 80)
    cmd.turn('y', 40)
    cmd.mview('store', 140)
    # Add panning to the close-up
    cmd.scene('002', animate=0)
    cmd.move('x', 5)
    cmd.mview('store', 320)
Example #6
0
def additional_camera():
    # Add a rotation to the global view
    cmd.scene('001', animate=0)
    cmd.turn('y', -40)
    cmd.mview('store', 80)
    cmd.turn('y', 40)
    cmd.mview('store', 140)
    # Add panning to the close-up
    cmd.scene('002', animate=0)
    cmd.move('x', 5)
    cmd.mview('store', 320)
Example #7
0
 def testSceneInsertBeforeAfter(self):
     # insert_before and insert_after
     cmd.scene('F1', 'store')
     cmd.scene('F2', 'store')
     cmd.scene('F1')
     cmd.scene('new', 'insert_after')
     cmd.scene('new', 'insert_before')
     names = cmd.get_scene_list()
     self.assertEqual(names[0], 'F1')
     self.assertEqual(names[3], 'F2')
     # we don't know the auto naming counter, but we know this:
     self.assertTrue(names[1] > names[2])
Example #8
0
def ray_tracer(width, height, scenes="all", ray=1, directory=""):
    """
	ray_tracer will call png for scenes in a pymol session.  All these scenes will be
	produced with the same dimensions.  By default, all scenes are generated with ray
	tracing turned on in the current directory.  Files will be named the same as their
	scene names.
	
	width, height = The width and height in pixels of the resulting images.
	scenes = A scene or pythonic list of scenes to raytrace (e.g. "scene1" or ["scene1", "scene2"]).  By default, do all scenes.
	raytrace = Should we raytrace?  Passed on to ray in png command.
	directory = By default, images will be saved in the current directory.  A relative path can be given
		here for a different directory to be used.
	"""

    #Check if 'all' happens to be a scene name.  If so, print an error message and quit.
    assert (
        "all" not in cmd.get_scene_list()
    ), "You have 'all' as a scene name.  This causes a conflict with ray_tracer.  Change the scene name."

    #The directory name must end in a forward / (unless it is an empty string).  If it doesn't, add one for the user
    if (directory != "" and directory[-1:] != "/"): directory = directory + "/"

    #Figure out which scenes to png
    #if scenes == all, get all scenes and use that as our list.
    if (scenes == 'all'):
        scene_list = cmd.get_scene_list()
    #if scenes is a list object, use that as our list.
    elif (isinstance(scenes, list)):
        scene_list = scenes
    #Otherwise, assume we have a string that corresponds to a scene name
    else:
        scene_list = [scenes]

    #Make sure that the scene_animation setting is set to 0, or changing view will not work.
    cmd.set("scene_animation", 0)

    #scene_list should now have a list of all the scenes to render.
    #Loop over scene_list and cmd.png each one.
    for scene in scene_list:
        #Check that the scene actually exists, or spit out an error.
        if (scene not in cmd.get_scene_list()):
            print("The scene " + scene +
                  " is not a scene in your pymol environment.  Skipping.")
            continue

        #Change to the appropriate scene.
        cmd.scene(scene)
        cmd.sync()
        #Figure out the full name of the output file.
        imgname = directory + scene + ".png"

        #Actually make the image.
        cmd.png(filename=imgname, width=width, height=height, ray=ray)
Example #9
0
 def testSceneInsertBeforeAfter(self):
     # insert_before and insert_after
     cmd.scene('F1', 'store')
     cmd.scene('F2', 'store')
     cmd.scene('F1')
     cmd.scene('new', 'insert_after')
     cmd.scene('new', 'insert_before')
     names = cmd.get_scene_list()
     self.assertEqual(names[0], 'F1')
     self.assertEqual(names[3], 'F2')
     # we don't know the auto naming counter, but we know this:
     self.assertTrue(names[1] > names[2])
Example #10
0
 def test_add_scenes(self):
     cmd.fragment('gly', 'm1')
     cmd.scene('001', 'store')
     cmd.turn('x', 90)
     cmd.scene('002', 'store')
     movie.add_scenes()
     self.assertEqual(cmd.count_frames(), 615)
     cmd.mset()
     movie.add_scenes(['001', '002'], pause=3)
     self.assertEqual(cmd.count_frames(), 315)
     cmd.mset()
     movie.add_scenes('["001", "002"]') # string
     self.assertEqual(cmd.count_frames(), 615)
Example #11
0
 def test_add_scenes(self):
     cmd.fragment('gly', 'm1')
     cmd.scene('001', 'store')
     cmd.turn('x', 90)
     cmd.scene('002', 'store')
     movie.add_scenes()
     self.assertEqual(cmd.count_frames(), 615)
     cmd.mset()
     movie.add_scenes(['001', '002'], pause=3)
     self.assertEqual(cmd.count_frames(), 315)
     cmd.mset()
     movie.add_scenes('["001", "002"]')  # string
     self.assertEqual(cmd.count_frames(), 615)
def set_up_scenes():
    """Set up the scenes for a global view and a close-up on the binding site"""
    cmd.zoom('Cathepsin', 10)  # Zoom out to get a view on the whole complex
    cmd.scene('001',
              'store',
              message='This is the first scene with a view on the complex!')
    cmd.set_view(
        closeup
    )  # Get a close-up of the ligand by using the manually chosen viewpoint
    cmd.scene(
        '002',
        'store',
        message='This is the second scene with a close-up on the ligand!')
Example #13
0
def insert_scene():
    global views
    global actions
    global settings
    global frames
    global cur_index
    global cur_view
    global scenes
    global scene_counter
    global models
    global fades
 
    cur_index += 1
    cur_view = cmd.get_view()
    views.insert( cur_index, [cv for cv in cur_view] )
    frames.insert( cur_index, 50 )
 
    #deal with dictionaries
    actions = incKeyAbove( actions, cur_index )
    scenes = incKeyAbove( scenes, cur_index )
    settings = incKeyAbove( settings, cur_index )
    models = incKeyAbove( models, cur_index )
    fades = incKeyAbove( fades, cur_index )
 
    #this stuff has to be done after the above
    #find a free scene name
    i = 1
    found = 1
    while found == 1:
        found = 0
        for sname in scenes.values():
            print "|"+sname+"|"
            if sname == "slerpy_"+str(i):
                found = 1
                break
        if found == 1:
            i += 1
        else:
            break
    newname = "slerpy_"+str(i)
 
    scene_counter += 1
    cmd.scene( newname, "store" )
    scenes[ cur_index ] = newname
    actions[ cur_index ] = "scene "+newname
 
    print "New view:"
    print_view( cur_view )
    print "Inserted view with index", cur_index, "and a 50 frame transition"
    print "Added scene",newname
Example #14
0
    def test(self):
        cmd.pseudoatom('m1')
        cmd.pseudoatom('m2')
        cmd.pseudoatom('m3')
        cmd.group('g1', 'm1')
        cmd.disable('g1')
        cmd.disable('m2')
        cmd.ray(1, 1)  # force scene update
        cmd.scene('s1', 'store')

        self._test_recall()
        cmd.disable('*')
        self._test_recall()
        cmd.enable('*')
        self._test_recall()
Example #15
0
    def test(self):
        cmd.pseudoatom('m1')
        cmd.pseudoatom('m2')
        cmd.pseudoatom('m3')
        cmd.group('g1', 'm1')
        cmd.disable('g1')
        cmd.disable('m2')
        cmd.ray(1, 1)  # force scene update
        cmd.scene('s1', 'store')

        self._test_recall()
        cmd.disable('*')
        self._test_recall()
        cmd.enable('*')
        self._test_recall()
Example #16
0
def insert_scene():
    global views
    global actions
    global settings
    global frames
    global cur_index
    global cur_view
    global scenes
    global scene_counter
    global models
    global fades

    cur_index += 1
    cur_view = cmd.get_view()
    views.insert(cur_index, [cv for cv in cur_view])
    frames.insert(cur_index, 50)

    #deal with dictionaries
    actions = incKeyAbove(actions, cur_index)
    scenes = incKeyAbove(scenes, cur_index)
    settings = incKeyAbove(settings, cur_index)
    models = incKeyAbove(models, cur_index)
    fades = incKeyAbove(fades, cur_index)

    #this stuff has to be done after the above
    #find a free scene name
    i = 1
    while True:
        for sname in scenes.values():
            print "|" + sname + "|"
            if sname == "slerpy_" + str(i):
                break
        else:
            break
        i += 1
    newname = "slerpy_" + str(i)

    scene_counter += 1
    cmd.scene(newname, "store")
    scenes[cur_index] = newname
    actions[cur_index] = "scene " + newname

    print "New view:"
    print_view(cur_view)
    print "Inserted view with index", cur_index, "and a 50 frame transition"
    print "Added scene", newname
Example #17
0
 def testSceneOrder(self):
     cmd.scene('Z0', 'store')
     cmd.scene('F1', 'store')
     cmd.scene('F10', 'store')
     cmd.scene('F2', 'store')
     cmd.scene_order('*', True)
     self.assertEqual(cmd.get_scene_list(), ['F1', 'F2', 'F10', 'Z0'])
     cmd.scene_order('F10 F1')
     self.assertEqual(cmd.get_scene_list(), ['F2', 'F10', 'F1', 'Z0'])
     cmd.scene_order('F10 F1', location='top')
     self.assertEqual(cmd.get_scene_list(), ['F10', 'F1', 'F2', 'Z0'])
     cmd.scene_order('F10 F1', location='bottom')
     self.assertEqual(cmd.get_scene_list(), ['F2', 'Z0', 'F10', 'F1'])
Example #18
0
 def testSceneOrder(self):
     cmd.scene('Z0', 'store')
     cmd.scene('F1', 'store')
     cmd.scene('F10', 'store')
     cmd.scene('F2', 'store')
     cmd.scene_order('*', True)
     self.assertEqual(cmd.get_scene_list(), ['F1', 'F2', 'F10', 'Z0'])
     cmd.scene_order('F10 F1')
     self.assertEqual(cmd.get_scene_list(), ['F2', 'F10', 'F1', 'Z0'])
     cmd.scene_order('F10 F1', location='top')
     self.assertEqual(cmd.get_scene_list(), ['F10', 'F1', 'F2', 'Z0'])
     cmd.scene_order('F10 F1', location='bottom')
     self.assertEqual(cmd.get_scene_list(), ['F2', 'Z0', 'F10', 'F1'])
Example #19
0
    def test_scenes(self):
        self._load_example()

        cmd.scene('s1', 'store')
        cmd.enable('g1')
        cmd.scene('s2', 'store')
        cmd.mset('1x4')
        cmd.mview('store', 1, scene='s2')
        cmd.mview('store', 4, scene='s1')

        with testing.mkdtemp() as tempdir:
            # export
            prefix = os.path.join(tempdir, 'frame')
            cmd.mpng(prefix, width=100, height=100)

            img = self.get_imagearray(prefix + '0002.png')
            self.assertImageHasColor('red', img)
            self.assertImageHasColor('blue', img)

            img = self.get_imagearray(prefix + '0003.png')
            self.assertImageHasNotColor('red', img)
            self.assertImageHasColor('blue', img)
Example #20
0
    def test_scenes(self):
        self._load_example()

        cmd.scene('s1', 'store')
        cmd.enable('g1')
        cmd.scene('s2', 'store')
        cmd.mset('1x4')
        cmd.mview('store', 1, scene='s2')
        cmd.mview('store', 4, scene='s1')

        with testing.mkdtemp() as tempdir:
            # export
            prefix = os.path.join(tempdir, 'frame')
            cmd.mpng(prefix, width=100, height=100)

            img = self.get_imagearray(prefix + '0002.png')
            self.assertImageHasColor('red', img)
            self.assertImageHasColor('blue', img)

            img = self.get_imagearray(prefix + '0003.png')
            self.assertImageHasNotColor('red', img)
            self.assertImageHasColor('blue', img)
# Make a pymol movie that shows all objects in turn

from pymol import cmd

objs = cmd.get_object_list()

n_frame_per_obj = 20

# Initialize the frames

cmd.mset('1', n_frame_per_obj * len(objs))

# Create a scene for each frame

cmd.scene(key='*', action='clear')
cmd.scene(key='original_scene', action='store')

for obj in objs:

    # Hide everything but this object

    cmd.scene(key='original_scene', action='recall')
    cmd.hide('everything', 'not ' + obj)
    cmd.scene(key=obj + '_scene', action='store')

# Make the movie

cmd.mview(action='clear', first=1, last=n_frame_per_obj * len(objs))

for i, obj in enumerate(objs):
    frame_start = i * n_frame_per_obj + 1
Example #22
0
    )

    #make it pretty
    cmd.show('nb_spheres', pdbid + '* and resn hoh')
    cmd.show('lines', pdbid + '* and not elem h')
    cmd.show('ribbon', pdbid + '*')

    #parse filename, get resid, zoom, store scene
    if len(pdbparse) > 2:
        pdbid_curr = pdbid
        res_chain = pdbparse[-1]
        if pdbid_curr != pdbid or res_chain != res_chain_last:
            if res_chain.find('_') > -1:
                res = res_chain.split('_')[0]
                chain = res_chain.split('_')[1]
                cmd.show(
                    'sticks', pdbid + '* and resi ' + res + ' and chain ' +
                    chain + ' and not elem h')
                cmd.orient(pdb + ' and resi ' + res + ' and chain ' + chain)
            else:
                res = res_chain
                cmd.show('sticks',
                         pdbid + '* and resi ' + res + ' and not elem h')
                cmd.orient(pdb + ' and resi ' + res)
            cmd.scene('new', 'store', '', 1, 1)
            res_chain_last = res_chain

    pdbid_last = pdbid

#cmd.extend("color_by_attype",color_by_attype)
Example #23
0
 def __exit__(self, type, value, traceback):
     cmd.scene(self.name, 'recall')
     cmd.scene(self.name, 'delete')
Example #24
0
 def _make_scenes(self, n=3):
     for i in range(1, n + 1):
         cmd.scene('%03d' % i, 'store')
    cmd.mview('store', 400)


setup_pymol()
cmd.load('../../input-files/Cathepsin.pdb')  # Load the PDB file
initial_representations()
set_up_scenes()
scenes_to_frames()

# Apart from moving between scenes, independent camera movements can be added to the animation
# One of them, the zoom (cmd.zoom) was already used
# Two other movements are rotation (cmd.turn) and panning (cmd.move)
# Let's add a rotation to the global view and a panning to the close-up to make them more interesting

cmd.scene(
    '001', animate=0
)  # Select the first scene again (we need the camera view as a starting point)
cmd.turn('y', -40)  # Turn the camera 40 degrees left around the y-axis
cmd.mview('store', 80)  # Store the changed view/assign it to frame 60
cmd.turn(
    'y',
    40)  # Turn the camera 40 degrees in the other direction around the y-axis
cmd.mview('store', 140)  # Assign the view to frame 120

cmd.scene('002', animate=0)  # Select the second scene
cmd.move('x', 5)  # Move along the x-axis
cmd.mview('store', 320)  # Assign the view to frame 320

# Rewind and turn off ray-tracing
cmd.rewind()  # Rewind the movie to frame 1
cmd.set('ray_trace_frames', 0)  # Turn ray-tracing for frames off
    cmd.scene('002', animate=0)
    cmd.mview('store', 250)
    cmd.mview('store', 400)

setup_pymol()
cmd.load('../../input-files/Cathepsin.pdb')  # Load the PDB file
initial_representations()
set_up_scenes()
scenes_to_frames()

# Apart from moving between scenes, independent camera movements can be added to the animation
# One of them, the zoom (cmd.zoom) was already used
# Two other movements are rotation (cmd.turn) and panning (cmd.move)
# Let's add a rotation to the global view and a panning to the close-up to make them more interesting

cmd.scene('001', animate=0)  # Select the first scene again (we need the camera view as a starting point)
cmd.turn('y', -40)  # Turn the camera 40 degrees left around the y-axis
cmd.mview('store', 80)  # Store the changed view/assign it to frame 60
cmd.turn('y', 40)  # Turn the camera 40 degrees in the other direction around the y-axis
cmd.mview('store', 140)  # Assign the view to frame 120

cmd.scene('002', animate=0)  # Select the second scene
cmd.move('x', 5)  # Move along the x-axis
cmd.mview('store', 320)  # Assign the view to frame 320

# Rewind and turn off ray-tracing
cmd.rewind()  # Rewind the movie to frame 1
cmd.set('ray_trace_frames', 0)  # Turn ray-tracing for frames off

# Running the script, you should now see the additional camera movements additional to the scene transitions
# Note that there are also transitions back to original scene 001 and scene 002 views after the movements
Example #27
0
import pymol
from pymol import cmd
#pymol.pymol_argv = [ 'pymol', '-qc'] #  Quiet / no GUI
pymol.finish_launching()

cmd.fetch('1TUP', async=False)

cmd.disable('all')
cmd.enable('1TUP')
cmd.hide('all')
cmd.show('sphere', 'name zn')

cmd.show('surface', 'chain A+B+C')
cmd.show('cartoon', 'chain E+F')
cmd.scene('S0', action='store', view=0, frame=0, animate=-1)

cmd.show('cartoon')
cmd.hide('surface')

cmd.scene('S1', action='store', view=0, frame=0, animate=-1)

cmd.hide('cartoon', 'chain A+B+C')
cmd.show('mesh', 'chain A')
cmd.show('sticks', 'chain A+B+C')
cmd.scene('S2', action='store', view=0, frame=0, animate=-1)

cmd.set('ray_trace_mode', 0)
cmd.mset(1, 500)


cmd.frame(0)
def set_up_scenes():
    """Set up the scenes for a global view and a close-up on the binding site"""
    cmd.zoom('Cathepsin', 10)  # Zoom out to get a view on the whole complex
    cmd.scene('001', 'store', message='This is the first scene with a view on the complex!')
    cmd.set_view(closeup)  # Get a close-up of the ligand by using the manually chosen viewpoint
    cmd.scene('002', 'store', message='This is the second scene with a close-up on the ligand!')
def create_views(options):

    polar_interactions_defined = not options.has_key(
        "no_polar_interactions_found")
    water_in_binding_site = options[
        "water_in_binding_site"] and options.has_key("water_to_enable_list")
    halogen_bonds_defined = options[
        'check_halogen_interaction'] and options.has_key(
            'halogen_bond_selections')
    # print ("polar_interactions_defined" , polar_interactions_defined)
    # print ("halogen_bonds_defined" , halogen_bonds_defined)

    cmd.disable("all")
    cmd.orient("protein_surface")
    cmd.zoom("protein_surface", 5)
    cmd.enable("protein_surface")
    cmd.set("transparency", 0.5)
    cmd.enable("protein_cartoon")
    cmd.view("1", action="store")
    cmd.scene("F1", action="store")

    # 2 and F2 show ligand in pocket
    cmd.disable("all")
    cmd.enable("protein_surface")
    cmd.set("transparency", 0.5)
    cmd.enable("protein_cartoon")
    cmd.enable("ligand")
    cmd.view("2", action="store")
    cmd.scene("F2", action="store")

    # 3 and F3
    cmd.disable("all")
    cmd.enable("protein_cartoon")
    cmd.enable("ligand")
    cmd.view("3", action="store")
    cmd.scene("F3", action="store")

    # 4 and F4
    cmd.disable("all")
    cmd.enable("ligand")
    cmd.view("4", action="store")
    cmd.scene("F4", action="store")

    # 5 and F5
    cmd.disable("all")
    cmd.enable("ligand")
    cmd.enable("protein_cartoon")
    if options["cofactor_in_binding_site"]:
        cmd.enable("cofactor")
    cmd.orient("ligand")
    cmd.zoom("binding_site", 5)
    cmd.view("5", action="store")
    cmd.scene("F5", action="store")

    # 6 and F6
    cmd.disable("all")
    cmd.enable("ligand")
    cmd.enable("binding_site")
    if options["cofactor_in_binding_site"]:
        cmd.enable("cofactor")
    if polar_interactions_defined:
        cmd.enable("polar_interacting_residues")
        cmd.enable("polar_int_d")
        cmd.zoom("polar_interacting_residues", 5)
        if water_in_binding_site:
            for sel in options["water_to_enable_list"]:
                cmd.enable(sel)
    else:
        cmd.zoom("binding_site", 5)
    cmd.view("6", action="store")
    cmd.scene("F6", action="store")

    # 7 and F7
    cmd.disable("all")
    cmd.enable("ligand")
    if options["cofactor_in_binding_site"]:
        cmd.enable("cofactor")
    # cmd.enable("binding_site")
    if polar_interactions_defined:
        cmd.enable("polar_interacting_residues")
        cmd.enable("polar_int_d")
        cmd.enable("interaction_polar")
        cmd.zoom("polar_int_d", 5)
        if water_in_binding_site:
            for sel in options["water_to_enable_list"]:
                cmd.enable(sel)
    else:
        cmd.zoom("ligand", 5)
    cmd.view("7", action="store")
    cmd.scene("F7", action="store")

    # 8 and F8
    if halogen_bonds_defined:
        cmd.disable("all")
        cmd.enable("ligand")
        for selection in options['halogen_bond_selections']:
            cmd.enable(selection)
        for selection2 in options['halogen_interaction_partners']:
            cmd.enable(selection2)
        cmd.zoom(options['halogen_bond_selections'][0], 5)
        cmd.view("8", action="store")
        cmd.scene("F8", action="store")

    # 9 and F9
    # zoom between polar interactions?
    """
Example #30
0
    def testScene(self):
        cmd.fragment('ala', 'm1')
        cmd.fragment('gly', 'm2')
        cmd.create('m2', 'm2', 1, 2)
        cmd.create('m2', 'm2', 1, 3)
        cmd.create('m2', 'm2', 1, 4)

        # store
        cmd.show_as('sticks', 'm1')
        cmd.show_as('spheres', 'm2')
        cmd.color('blue', 'm1')
        cmd.color('yellow', 'm2')
        view_001 = cmd.get_view()
        cmd.scene('new', 'store', 'hello world')

        # store
        cmd.frame(3)
        cmd.show_as('lines')
        cmd.color('red')
        cmd.turn('x', 45)
        view_002 = cmd.get_view()
        cmd.scene('new', 'store')

        # we actually don't know the auto naming counter
        # self.assertEqual(cmd.get_scene_list(), ['001', '002'])
        names = cmd.get_scene_list()

        # recall
        cmd.scene(names[0], 'recall', animate=0)
        self.assertArrayEqual(view_001, cmd.get_view(), delta=1e-3)
        self.assertEqual(cmd.count_atoms('m1'), cmd.count_atoms('color blue'))
        self.assertEqual(cmd.count_atoms('m1'), cmd.count_atoms('rep sticks'))
        self.assertEqual(cmd.count_atoms('m2'),
                         cmd.count_atoms('color yellow'))
        self.assertEqual(cmd.count_atoms('m2'), cmd.count_atoms('rep spheres'))
        self.assertNotEqual(cmd.get_wizard(), None)
        self.assertEqual(cmd.get_state(), 1)

        # recall
        cmd.scene(names[1], 'recall', animate=0)
        self.assertArrayEqual(view_002, cmd.get_view(), delta=1e-3)
        self.assertEqual(0, cmd.count_atoms('color blue'))
        self.assertEqual(0, cmd.count_atoms('rep sticks'))
        self.assertEqual(cmd.count_atoms(), cmd.count_atoms('color red'))
        self.assertEqual(cmd.count_atoms(), cmd.count_atoms('rep lines'))
        self.assertEqual(cmd.get_wizard(), None)
        self.assertEqual(cmd.get_state(), 3)

        # with movie (not playing) it must not recall the state
        cmd.mset('1-4')
        cmd.frame(1)
        cmd.scene(names[1], 'recall', animate=0)
        self.assertEqual(cmd.get_state(), 1)

        # rename and delete
        cmd.scene('F2', 'store')
        cmd.scene(names[0], 'rename', new_key='F1')
        cmd.scene(names[1], 'delete')
        self.assertEqual(cmd.get_scene_list(), ['F1', 'F2'])
Example #31
0
from pymol import cmd

def myasserttrue(b):
    if not b:
        raise UserWarning('myasserttrue')

def myassertequal(a, b):
    if a != b:
        raise UserWarning('myassertequal %s != %s' % (a, b))

myassertequal(cmd.get_names(), ['1rx1', '1rx1_2fofc', 'mesh'])
myassertequal(cmd.count_atoms('color forest'), 1268)
myassertequal(cmd.count_atoms('color red'), 48)
myassertequal(cmd.count_atoms('color orange'), 1)
myasserttrue(cmd.get('bg_rgb') in ('yellow', '[ 1.00000, 1.00000, 0.00000 ]', '0xffff00'))
myassertequal(cmd.get_extent('mesh'), [[1.3251924514770508, 15.123332977294922, -12.337624549865723], [51.682502746582031, 73.096115112304688, 37.698299407958984]])
myassertequal(cmd.get_wizard_stack()[0].__class__.__name__, 'Mutagenesis')

cmd.scene('F1', 'recall')
myassertequal(cmd.get_wizard_stack()[-1].message[0], "First Scene")

def set_up_scenes():
    """Set up the scenes for a global view and a close-up on the binding site"""
    cmd.zoom('Cathepsin', 10)  # Zoom out to get a view on the whole complex
    cmd.scene('001', 'store', message='This is the first scene with a view on the complex!')
    cmd.set_view(closeup)  # Get a close-up of the ligand by using the manually chosen viewpoint
    cmd.scene('002', 'store', message='This is the second scene with a close-up on the ligand!')

setup_pymol()
cmd.load('../../input-files/Cathepsin.pdb')  # Load the PDB file
initial_representations()
set_up_scenes()

# With the scenes ready, we need to assign them to frames, i.e. set how long a scene should appear in the animation
cmd.scene('001', animate=0)  # First, select the scene to assign
cmd.mview('store', 1)  # We assign it to the first frame, i.e. the movie should start showing the first scene
cmd.mview('store', 150)  # Also assign it to frame 200. Scene 001 is now shown for 150 frames
cmd.scene('002', animate=0)  # Now, choose the close-up scene
cmd.mview('store', 250)  # Assign it to frame 250
cmd.mview('store', 400)  # Also assign it to frame 400

# Using scenes, we don't have to bother about transitions (the camera flights) between scenes.
# PyMOL takes care of that. It interpolates a smooth transition between the scenes.
# Let's rewind to frame 1 and see how the animation looks. To get a fast preview, we have to turn off ray tracing.
cmd.rewind()  # Rewind the movie to frame 1
cmd.set('ray_trace_frames', 0)  # Turn ray-tracing for frames off


# By default, PyMOL shows the video in a loop and also takes care of the transition of the last to the first scene.
# This setting is perfect for producing videos for presentations that should loop over and over again.
Example #33
0
import pymol
from pymol import cmd
#pymol.pymol_argv = [ 'pymol', '-qc'] #  Quiet / no GUI
pymol.finish_launching()

cmd.fetch('1TUP', async=False)

cmd.disable('all')
cmd.enable('1TUP')
cmd.hide('all')
cmd.show('sphere', 'name zn')

cmd.show('surface', 'chain A+B+C')
cmd.show('cartoon', 'chain E+F')
cmd.scene('S0', action='store', view=0, frame=0, animate=-1)

cmd.show('cartoon')
cmd.hide('surface')

cmd.scene('S1', action='store', view=0, frame=0, animate=-1)

cmd.hide('cartoon', 'chain A+B+C')
cmd.show('mesh', 'chain A')
cmd.show('sticks', 'chain A+B+C')
cmd.scene('S2', action='store', view=0, frame=0, animate=-1)

cmd.set('ray_trace_mode', 0)
cmd.mset(1, 500)

cmd.frame(0)
cmd.scene('S0')
Example #34
0
 def __enter__(self):
     import random
     self.name = 'tmp_%d' % (random.randint(0, 1e8))
     cmd.scene(self.name, 'store', **self.kwargs)
Example #35
0
    def testScene(self):
        cmd.fragment('ala', 'm1')
        cmd.fragment('gly', 'm2')
        cmd.create('m2', 'm2', 1, 2)
        cmd.create('m2', 'm2', 1, 3)
        cmd.create('m2', 'm2', 1, 4)

        # store
        cmd.show_as('sticks', 'm1')
        cmd.show_as('spheres', 'm2')
        cmd.color('blue', 'm1')
        cmd.color('yellow', 'm2')
        view_001 = cmd.get_view()
        cmd.scene('new', 'store', 'hello world')

        # store
        cmd.frame(3)
        cmd.show_as('lines')
        cmd.color('red')
        cmd.turn('x', 45)
        view_002 = cmd.get_view()
        cmd.scene('new', 'store')

        # we actually don't know the auto naming counter
        # self.assertEqual(cmd.get_scene_list(), ['001', '002'])
        names = cmd.get_scene_list()

        # recall
        cmd.scene(names[0], 'recall', animate=0)
        self.assertArrayEqual(view_001, cmd.get_view(), delta=1e-3)
        self.assertEqual(cmd.count_atoms('m1'), cmd.count_atoms('color blue'))
        self.assertEqual(cmd.count_atoms('m1'), cmd.count_atoms('rep sticks'))
        self.assertEqual(cmd.count_atoms('m2'), cmd.count_atoms('color yellow'))
        self.assertEqual(cmd.count_atoms('m2'), cmd.count_atoms('rep spheres'))
        self.assertNotEqual(cmd.get_wizard(), None)
        self.assertEqual(cmd.get_state(), 1)

        # recall
        cmd.scene(names[1], 'recall', animate=0)
        self.assertArrayEqual(view_002, cmd.get_view(), delta=1e-3)
        self.assertEqual(0, cmd.count_atoms('color blue'))
        self.assertEqual(0, cmd.count_atoms('rep sticks'))
        self.assertEqual(cmd.count_atoms(), cmd.count_atoms('color red'))
        self.assertEqual(cmd.count_atoms(), cmd.count_atoms('rep lines'))
        self.assertEqual(cmd.get_wizard(), None)
        self.assertEqual(cmd.get_state(), 3)

        # with movie (not playing) it must not recall the state
        cmd.mset('1-4')
        cmd.frame(1)
        cmd.scene(names[1], 'recall', animate=0)
        self.assertEqual(cmd.get_state(), 1)

        # rename and delete
        cmd.scene('F2', 'store')
        cmd.scene(names[0], 'rename', new_key='F1')
        cmd.scene(names[1], 'delete')
        self.assertEqual(cmd.get_scene_list(), ['F1', 'F2'])
Example #36
0
    cmd.viewport(800, 800)


setup_pymol()

# After setting up PyMOL, we will load a PDB file an prepare it for a simple use case.
# Let's show the complex between Cathepsin K and one of its inhibitors (PDB ID 1VSN)

cmd.load('../../input-files/Cathepsin.pdb')  # Load the PDB file

# A good starting point for an animation is to hide all representation to start from scratch
# Then, we want to show the protein in cartoon representation and its ligand in ball-and-stick representation
cmd.hide('everything', 'all')  # Hide everything
cmd.show('cartoon', 'all')  # Show protein in cartoon representation
cmd.select('ligand', 'resn NFT')  # Select the ligand (NFT)
cmd.deselect()  # Deselect everything to hide the selection markers in PyMOL
cmd.show("sticks", "ligand")  # Show the ligand in ball-and-stick representation

# Now let's zoom out to show the whole protein and then do a close-up on the ligand.
# In both cases, we will save the camera perspective as a scene.
# We can switch between saved scenes and connect them later. It's just like in a movie storyboard.
cmd.zoom('Cathepsin', 10)  # Zoom out to get a view on the whole complex
cmd.scene('001', 'store', message='This is the first scene with a view on the complex!')  # Save the first scene (001)
cmd.zoom('ligand', 5)  # Get a close-up of the ligand
cmd.scene('002', 'store', message='This is the second scene with a close-up on the ligand!')  # Save the second scene


# Running the script, PyMOL should display you the complex with the chosen representations and two scenes
# The scenes are accessible in the lower left corner. You can click on the buttons to switch between them.
# We can use this feature later to connect the scenes and make a smooth transition for the movie.
# Note that the scene messages are optional, i.e. you can omit the message argument.
    cmd.set_view(
        closeup
    )  # Get a close-up of the ligand by using the manually chosen viewpoint
    cmd.scene(
        '002',
        'store',
        message='This is the second scene with a close-up on the ligand!')


setup_pymol()
cmd.load('../../input-files/Cathepsin.pdb')  # Load the PDB file
initial_representations()
set_up_scenes()

# With the scenes ready, we need to assign them to frames, i.e. set how long a scene should appear in the animation
cmd.scene('001', animate=0)  # First, select the scene to assign
cmd.mview(
    'store', 1
)  # We assign it to the first frame, i.e. the movie should start showing the first scene
cmd.mview(
    'store',
    150)  # Also assign it to frame 200. Scene 001 is now shown for 150 frames
cmd.scene('002', animate=0)  # Now, choose the close-up scene
cmd.mview('store', 250)  # Assign it to frame 250
cmd.mview('store', 400)  # Also assign it to frame 400

# Using scenes, we don't have to bother about transitions (the camera flights) between scenes.
# PyMOL takes care of that. It interpolates a smooth transition between the scenes.
# Let's rewind to frame 1 and see how the animation looks. To get a fast preview, we have to turn off ray tracing.
cmd.rewind()  # Rewind the movie to frame 1
cmd.set('ray_trace_frames', 0)  # Turn ray-tracing for frames off
# Let's show the complex between Cathepsin K and one of its inhibitors (PDB ID 1VSN)

cmd.load('../../input-files/Cathepsin.pdb')  # Load the PDB file

# A good starting point for an animation is to hide all representation to start from scratch
# Then, we want to show the protein in cartoon representation and its ligand in ball-and-stick representation
cmd.hide('everything', 'all')  # Hide everything
cmd.show('cartoon', 'all')  # Show protein in cartoon representation
cmd.select('ligand', 'resn NFT')  # Select the ligand (NFT)
cmd.deselect()  # Deselect everything to hide the selection markers in PyMOL
cmd.show("sticks",
         "ligand")  # Show the ligand in ball-and-stick representation

# Now let's zoom out to show the whole protein and then do a close-up on the ligand.
# In both cases, we will save the camera perspective as a scene.
# We can switch between saved scenes and connect them later. It's just like in a movie storyboard.
cmd.zoom('Cathepsin', 10)  # Zoom out to get a view on the whole complex
cmd.scene('001',
          'store',
          message='This is the first scene with a view on the complex!'
          )  # Save the first scene (001)
cmd.zoom('ligand', 5)  # Get a close-up of the ligand
cmd.scene('002',
          'store',
          message='This is the second scene with a close-up on the ligand!'
          )  # Save the second scene

# Running the script, PyMOL should display you the complex with the chosen representations and two scenes
# The scenes are accessible in the lower left corner. You can click on the buttons to switch between them.
# We can use this feature later to connect the scenes and make a smooth transition for the movie.
# Note that the scene messages are optional, i.e. you can omit the message argument.
Example #39
0
 def _make_scenes(self, n=3):
     for i in range(1, n + 1):
         cmd.scene('%03d' % i, 'store')