def makeMovie(numClusts, frameRate): real = int(numClusts)+1; fr = int(frameRate) movieSetup = "1 x" + str(real*fr) cmd.mset(movieSetup) #Load in all the system data. for x in range(0, real): # load the next system. clustName = "system-" + str(x) system = clustName + ".xyz" cmd.load(system) # Set the sphere scale and view cmd.set("sphere_scale","0.5","all") #Set the right view cmd.set_view("0.910306633, -0.382467061, 0.158301696, 0.326706469, 0.898694992, 0.292592257, -0.254171938, -0.214630708, 0.943043232, 0.000000000, 0.000000000, -99.425979614, 10.461934090, 13.087766647, 11.786855698, 80.009132385, 118.842796326, -20.000000000") #Set all the frame data for x in range(0, real): # set the current frame. frameNum = (x*fr)+1 cmd.frame(frameNum) clustName = "system-" + str(x) movieState = "hide; show spheres, " + clustName cmd.mdo(frameNum,movieState) cmd.mview("store") cmd.mview("reinterpolate") cmd.mplay()
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)
def frames2states(selection, specification): ''' DESCRIPTION Map specific object states to frames. "specification" is a sequence of "frame:state" mappings. EXAMPLE fetch 1d7q 1nmr, async=0 mset 1-20 # reverse state order just for 1nmr frames2states 1nmr, 1:20 20:1 ''' names = cmd.get_object_list('(' + selection + ')') for x in specification.split(): frame, state = x.split(':') cmd.frame(int(frame)) for name in names: cmd.mview('store', object=name, state=int(state))
def frames2states(selection, specification): ''' DESCRIPTION Map specific object states to frames. "specification" is a sequence of "frame:state" mappings. EXAMPLE fetch 1d7q 1nmr, async=0 mset 1-20 # reverse state order just for 1nmr frames2states 1nmr, 1:20 20:1 ''' names = cmd.get_object_list('(' + selection + ')') for x in specification.split(): frame, state = x.split(':') cmd.frame(int(frame)) for name in names: cmd.mview('store', object=name, state=int(state))
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)
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)
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)
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)
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.
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
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') cmd.mview() cmd.frame(60) cmd.set_view((-0.175534308, -0.331560850, -0.926960170, 0.541812420, 0.753615797, -0.372158051, 0.821965039, -0.567564785, 0.047358301, 0.000000000, 0.000000000, -249.619018555, 58.625568390, 15.602619171, 77.781631470, 196.801528931, 302.436492920, -20.000000000)) cmd.mview() cmd.frame(90) cmd.set_view((-0.175534308, -0.331560850, -0.926960170, 0.541812420, 0.753615797, -0.372158051, 0.821965039, -0.567564785, 0.047358301, -0.000067875, 0.000017881, -249.615447998, 54.029174805, 26.956727982, 77.124832153,
import pymol from pymol import cmd, util from glob import glob import re #cmd.load('nucleophilic.pse') cmd.mset() cmd.rewind() nloop = 4 seconds = 4 fps = 30 degrees = 30 #cmd.mset(1, ) nframes = seconds * fps for loop in range(nloop): cmd.movie.add_nutate(seconds,degrees) objname = '2020-08-20-benzotriazoles-dockscores-x10876' cmd.load(objname + '.sdf') cmd.hide('sticks', 'hydrogen') cmd.mview('store', 1, object=objname, state=1) cmd.mview('store', nloop*seconds*fps, object=objname, state=nloop*seconds*fps) cmd.viewport(720, 720) #movie.produce('nucleophilic_displacement.mov', mode='ray')
def growProtein(): cmd.mstop() cmd.mclear() cmd.mset() glb.update() objects = cmd.get_names('all') if 'protein' in objects: cmd.bg_color('black') # create the objects to be used in this movie cmd.create('helix', 'ss h and protein') cmd.create('sheets', 'ss s and protein') cmd.create('surface', objects[0]) cmd.mset('1', '1400') # dna and rna will be represented as sticks # to make them stand out from the protein if 'dna' in objects: glb.procolor('dna','sticks','cpk',None) if 'rna' in objects: glb.procolor('rna','sticks','cpk',None) # coloring the protein and secondary structures cmd.color('white', 'protein') cmd.color('purple', 'helix') cmd.color('teal', 'sheets') cmd.cartoon('loop', 'protein') cmd.cartoon('automatic', 'helix') cmd.cartoon('automatic', 'sheets') cmd.hide('all') cmd.show('cartoon', 'protein') #cmd.mdo(1,'hide cartoon, helix; hide cartoon, sheets;') cmd.util.mrock('2', '200', '90', '1', '1') cmd.mdo(201,'show cartoon, helix;') cmd.util.mrock('202', '400', '90', '1', '1') cmd.mdo(401,'show cartoon, sheets;') cmd.util.mrock('402', '600', '90', '1', '1') if 'ligands' in objects: cmd.color('hotpink', 'ligands') cmd.mdo(600, 'show spheres, ligands; show sticks, ligands;'+ ' set sphere_transparency = 0.5, ligands;') cmd.util.mroll('601', '800', '1', axis = "x") cmd.color('blue', 'surface') cmd.mview('store', '800') cmd.turn('z', 180) cmd.mview('store' , '1000') cmd.turn('z', 180) cmd.mdo(800, 'show surface, surface; '+ 'set transparency = 0.8, surface;') cmd.mdo(850,'set transparency = 0.7, surface;') cmd.mdo(900,'set transparency = 0.6, surface;') cmd.mdo(950,'set transparency = 0.5, surface;') cmd.mdo(1000,'set transparency = 0.4, surface;') cmd.mdo(1050,'set transparency = 0.3, surface;') cmd.mdo(1100,'set transparency = 0.2, surface;') cmd.mdo(1150,'set transparency = 0.1, surface;') cmd.mdo(1200,'set transparency = 0.0, surface;') cmd.mview('store', '1200') cmd.util.mrock('1201', '1399', '180', '1', '1') cmd.hide('everything', 'surface') cmd.hide('everything', 'helix') cmd.hide('everything', 'sheets') cmd.reset() cmd.orient() cmd.mdo(1400,'hide everything, all; show cartoon, protein;') cmd.mdo(1400,'mstop') cmd.mview('interpolate') cmd.rewind()
def init_movie(): cmd.mdelete() cmd.mview('reset') frames = duration * 30 cmd.mset(f'1x{frames}') return frames
def cheese(render_type, savefile=None, duration=5, mode='ray', width=1920, height=1080): """ DESCRIPTION loads nice settings for rendering and take a picture or records a movie of the trajectory. Before running, position the camera to have a good point of view. USAGE cheese render_type [, savefile [, duration [, mode [, width [, height]]]]] ARGUMENTS render_type = one of: - set: only load render settings - snap: take a snapshot of the current view - traj: record the whole trajectory - bullettime: make a whole revolution around the z axis savefile = file name to use to save the movie, without extension. If not given, the movie won't be save but only shown (default=None) duration = duration in seconds of the final movie (default=5) mode = set to 'draw' to disable ray tracing (default='ray') width = width of the movie in pixel (default=1920) height = height of the movie in pixel (default=1080) """ duration = int(duration) # # store settings for later restoration # store_settings.load() # cmd.sync() # settings_file = '/tmp/stir_settings.py' # cmd.do(f'store_settings {settings_file}') # load nice settings for rendering config.rendering() cmd.sync() def init_movie(): cmd.mdelete() cmd.mview('reset') frames = duration * 30 cmd.mset(f'1x{frames}') return frames # only load settings if render_type == 'set': return # take a simple picture elif render_type == 'snap': cmd.ray(width=width, height=height) # make a still movie of the whole trajectory elif render_type == 'traj': frames = init_movie() cmd.mview('store', 1, state=1) cmd.sync() states = cmd.count_states() cmd.mview('store', frames, state=states) cmd.sync() cmd.mview('reinterpolate') cmd.sync() # make a movie rotating 360 around the z axis elif render_type == 'bullettime': frames = init_movie() cmd.mview('store', 1) cmd.mview('store', frames) # TODO: moving objects seems a bit hacky. Any better solution? for obj in cmd.get_object_list(): cmd.mview('store', object=obj) cmd.sync() for i in range(4): frame = int(frames * (i + 1) / 4) cmd.frame(frame) cmd.sync() for obj in cmd.get_object_list(): cmd.rotate('z', angle=-90, camera=0, object=obj) cmd.sync() cmd.mview('store', object=obj) cmd.sync() cmd.mview('reinterpolate', object=obj, power=1) cmd.sync() cmd.mview('reinterpolate') cmd.sync() else: raise ValueError( f'{render_type} is not a valid argument. See `help cheese`.') # save if required, otherwise just play it if savefile: if render_type in ( 'traj', 'bullettime', ): cmd.viewport(width, height) movie.produce(f'{savefile}.mp4', mode=mode, encoder='ffmpeg', quality=100) elif render_type in ('snap', ): cmd.png(f'{savefile}.png', dpi=300) cmd.sync() else: if render_type in ( 'traj', 'bullettime', ): cmd.mplay() elif render_type in ('snap', ): pass
def highlight_chains(): cmd.mstop() cmd.mclear() cmd.mset() glb.update() colors = ['blue', 'orange', 'silver', 'green', 'yellow', 'purple', 'brightorange', 'lightblue', 'lightorange', 'pink', 'forest', 'firebrick', 'paleyellow', 'salmon', 'ruby', 'wheat', 'lightmagenta', 'nitblue'] chains = [] numChains = 0 objects = cmd.get_names('all') for obj in objects: split = obj.split('Chain-') if len(split) == 2: chains.append(split[1]) numChains += 1 numFrames = (numChains*200)+70 cmd.mset('1', numFrames) cmd.mdo(1,'color red, all; hide cartoon, all') cmd.orient() cmd.mview('store', '1') colorCount = 0 frameCount = 1 for i in chains: cmd.orient('chain ' + i) cmd.mview('store', frameCount+59) cmd.mview('store', frameCount+115) flash_chain(i, frameCount+59, 'red', colors[colorCount]) cmd.orient() cmd.turn('x', '270') cmd.turn('y', '180') cmd.mview('store', frameCount+150) cmd.mview('store', frameCount+170) colorCount += 1 frameCount += 200 if(frameCount > numFrames-100): cmd.orient() cmd.mdo(numFrames,'mstop') cmd.mview('store', (numChains*200)+70) cmd.mview('interpolate') cmd.show('ribbon') cmd.color('red', 'all')
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') cmd.mview() cmd.frame(60) cmd.set_view( (-0.175534308, -0.331560850, -0.926960170, 0.541812420, 0.753615797, -0.372158051, 0.821965039, -0.567564785, 0.047358301, 0.000000000, 0.000000000, -249.619018555, 58.625568390, 15.602619171, 77.781631470, 196.801528931, 302.436492920, -20.000000000)) cmd.mview() cmd.frame(90) cmd.set_view( (-0.175534308, -0.331560850, -0.926960170, 0.541812420, 0.753615797, -0.372158051, 0.821965039, -0.567564785, 0.047358301, -0.000067875, 0.000017881, -249.615447998, 54.029174805, 26.956727982, 77.124832153, 196.801528931, 302.436492920, -20.000000000)) cmd.mview()
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
cmd.show("cartoon") cmd.hide("lines") for resi in designed_residues: string = "chain H and resi " + str(resi) cmd.color("red",string) cmd.show("sticks",string) string ="" for g in designed_residues: for i in range(1,101): string += ("%s x1 ")%i cmd.mset(string) cmd.frame("1") cmd.orient() cmd.mview("store") #util.mroll(1,500,1) string="" frame=100 for resi in designed_residues: resi_behind = int(resi) -2 resi_ahead = int(resi) + 2 cmd.frame(frame) string = "chain H and resi "+str(resi_behind) + "+"+ str(resi)+ "+"+str(resi_ahead) print string cmd.orient(string) cmd.mview("store") frame += 100 #cmd.color("blue", string) #cmd.zoom(string,"7.5") #frame += 500
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 #frame_stop = (i + 1) * n_frame_per_obj cmd.scene(key=obj + '_scene', action='recall') cmd.mview(action='store', first=frame_start) # Set the last frame to avoid cycle cmd.mview(action='store', first=n_frame_per_obj * len(objs))
) # 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.
for file in file_list: cmd.load(file,"A_movie") util.color_chains() cmd.show("cartoon") cmd.hide("lines") for resi in designed_residues: string = "chain H and resi " + str(resi) cmd.color("red",string) cmd.show("sticks",string) string ="1 x500 " for g in designed_residues: for i in range(1,100): string += ("%s x5 ")%i cmd.mset(string) cmd.mview('store') util.mroll(1,500,1) frame=501 string="" for resi in designed_residues: cmd.frame(frame) string = "chain H and resi " + str(resi) #cmd.color("blue", string) cmd.zoom(string,"7.5") frame += 500 cmd.mview("store")