def frag(state=state, obj=obj): pwd, mutations, orig_sequence = setup(obj) #get_positions_in_selection(sub, distance) # Run over all sites where to mutate, optionally add and retain hydrogens. for site in mutations.keys(): variants = mutations[site] # Run over all variants. for variant in variants: cmd.load(obj) cmd.do('wizard mutagenesis') cmd.do('refresh_wizard') cmd.get_wizard().set_hyd("keep") cmd.get_wizard().set_mode(variant) #cmd.get_wizard().do_select(site + '/') # Get the number of available rotamers at that site. # Introduce a condition here to check if rotamers are requested. # <<OPTIONAL>> nRots = getRots(site, variant) #if nRots > 3: # nRots = 3 nRots=1 cmd.rewind() for i in range(1, nRots + 1): cmd.get_wizard().do_select("(" + site + "/)") cmd.frame(i) cmd.get_wizard().apply() # Optimize the mutated sidechain #<<OPTION>> #print "Sculpting." local_sculpt(obj, variant, site) # Protonation of the N. #cmd.do("select n%d, name n and %d/" % (int(site), int(site))) #cmd.edit("n%d" % int(site), None, None, None, pkresi=0, pkbond=0) #cmd.do("h_fill") # Protonation of the C. #cmd.do("select c%d, name c and %d/" % (int(site), int(site))) #cmd.edit("c%d" % int(site), None, None, None, pkresi=0, pkbond=0) #cmd.do("h_fill") # Definition of saveString #saveString = '%s/' % pwd #saveString += 'frag-' + get_one(orig_sequence[site]).lower() +\ # site + get_one(variant).lower() + '-%s.pdb, ' % state +\ # '((%s/))' % site save_string_rot = '%s/' % pwd save_string_rot += 'frag-' + get_one(orig_sequence[site]).lower() +\ site + get_one(variant).lower() + '-%02d-%s.pdb, ' % (i, state) +\ '((%s/))' % site #print saveString #cmd.do('save %s' % saveString.lower()) cmd.do('save %s' % save_string_rot.lower()) cmd.do('delete all') cmd.set_wizard('done')
def testRewind(self): self.prep_movie() cmd.frame(30) self.assertEquals(cmd.get_frame(), 30) cmd.rewind() self.assertEquals(cmd.get_frame(), 1)
def load(): cmd.set("valence") r = 0 list = glob("pdb/*/*") # while list[0]!="pdb/f8/pdb1f8u": # list.pop(0) for file in list: try: cmd.delete('pdb') cmd.load(file,'pdb') cmd.set_title('pdb',1,os.path.split(file)[-1]) cmd.rewind() cmd.orient('pdb') cmd.refresh() cmd.show_as("ribbon") cmd.refresh() cmd.show_as("sticks") cmd.refresh() sys.__stderr__.write(".") sys.__stderr__.flush() n = cmd.count_states() if n>1: cmd.rewind() sys.__stderr__.write(file+"\n") sys.__stderr__.flush() for a in range(1,n+1): cmd.forward() cmd.refresh() except: traceback.print_exc()
def load(): cmd.set("valence") r = 0 list = glob("pdb/*/*") # while list[0]!="pdb/f8/pdb1f8u": # list.pop(0) for file in list: try: cmd.delete('pdb') cmd.load(file,'pdb') cmd.set_title('pdb',1,os.path.split(file)[-1]) cmd.rewind() cmd.orient('pdb') cmd.refresh() cmd.zoom('center',16) cmd.label("polymer and (name ca or elem P)","'//%s/%s/%s`%s/%s'%(segi,chain,resn,resi,name)") cmd.refresh() sys.__stderr__.write(".") sys.__stderr__.flush() n = cmd.count_states() if n>1: cmd.rewind() sys.__stderr__.write(file+"\n") sys.__stderr__.flush() for a in range(1,n+1): cmd.forward() cmd.refresh() except: traceback.print_exc()
def load(): cmd.set("valence") r = 0 list = glob("pdb/*/*") # while list[0]!="pdb/f8/pdb1f8u": # list.pop(0) for file in list: try: cmd.delete('pdb') cmd.load(file, 'pdb') cmd.set_title('pdb', 1, os.path.split(file)[-1]) cmd.rewind() cmd.orient('pdb') cmd.refresh() cmd.show_as("ribbon") cmd.refresh() cmd.show_as("sticks") cmd.refresh() sys.__stderr__.write(".") sys.__stderr__.flush() n = cmd.count_states() if n > 1: cmd.rewind() sys.__stderr__.write(file + "\n") sys.__stderr__.flush() for a in range(1, n + 1): cmd.forward() cmd.refresh() except: traceback.print_exc()
def load(): global last1, last2 list = glob("pdb/*/*") list = map(lambda x: (random.random(), x), list) list.sort() list = map(lambda x: x[1], list) l = len(list) c = 0 for file in list: c = c + 1 try: cmd.set("suspend_updates", "1") cmd.delete("pdb") print file, last1, last2, c, "of", l last2 = last1 last1 = file cmd.load(file, "pdb") cmd.set_title("pdb", 1, os.path.split(file)[-1]) cmd.rewind() # cmd.refresh() # cmd.hide() cmd.show("cartoon") cmd.color("auto", "ss h") cmd.color("auto", "ss s") cmd.orient("pdb") cmd.color("auto", "organic and elem c") cmd.show("spheres", "organic") cmd.move("z", -50.0) sys.__stderr__.write(".") sys.__stderr__.flush() n = cmd.count_states() finally: cmd.set("suspend_updates", "0") if cmd.count_atoms(): start = time.time() if n > 1: while (time.time() - start) < cycle_time: for a in range(1, n + 1): cmd.refresh() cmd.frame(a) cmd.move("z", 2) cmd.turn("y", 1) time.sleep(0.025) sys.__stderr__.write(" %d of %d" % (c, l)) sys.__stderr__.write("\n") sys.__stderr__.flush() else: cmd.refresh() while (time.time() - start) < cycle_time: for a in range(1, n + 1): time.sleep(0.05) cmd.move("z", 1.0) cmd.turn("y", 1)
def load(): global last1, last2 list = glob("pdb/*/*") list = map(lambda x: (random.random(), x), list) list.sort() list = map(lambda x: x[1], list) l = len(list) c = 0 for file in list: c = c + 1 try: cmd.set("suspend_updates", "1") cmd.delete('pdb') print file, last1, last2, c, "of", l last2 = last1 last1 = file cmd.load(file, 'pdb') cmd.set_title('pdb', 1, os.path.split(file)[-1]) cmd.rewind() # cmd.refresh() # cmd.hide() cmd.show('cartoon') cmd.color('auto', 'ss h') cmd.color('auto', 'ss s') cmd.orient('pdb') cmd.color('auto', 'organic and elem c') cmd.show('spheres', 'organic') cmd.move('z', -50.0) sys.__stderr__.write(".") sys.__stderr__.flush() n = cmd.count_states() finally: cmd.set("suspend_updates", "0") if cmd.count_atoms(): start = time.time() if n > 1: while (time.time() - start) < cycle_time: for a in range(1, n + 1): cmd.refresh() cmd.frame(a) cmd.move('z', 2) cmd.turn('y', 1) time.sleep(0.025) sys.__stderr__.write(" %d of %d" % (c, l)) sys.__stderr__.write("\n") sys.__stderr__.flush() else: cmd.refresh() while (time.time() - start) < cycle_time: for a in range(1, n + 1): time.sleep(0.05) cmd.move('z', 1.0) cmd.turn('y', 1)
def set_browse(self,browse): # allow user to focus on only a subset of the compounds self.browse = browse if self.browse == 1: print(" Filter: Browsing all compounds.") cmd.mset() # all states visible elif self.object is None: print(" Filter-Error: please choose an object first") else: self.check_object_dict() if self.browse == 2: print(" Filter: Browsing accepted compounds.") target = accept_str elif self.browse == 3: print(" Filter: Browsing rejected compounds.") target = reject_str elif self.browse == 4: print(" Filter: Browsing deferred compounds.") target = defer_str lst = [] sd = self.state_dict sdo = self.dict[self.object] if self.browse<5: for a in list(sdo.keys()): if sdo[a]==target: lst.append(sd[a]) else: print(" Filter: Browsing remaining compounds") for a in sd.keys(): if a not in sdo: lst.append(sd[a]) lst.sort() if len(lst)==0: print(" Filter-Error: No matching compounds.") cmd.mset(' '.join(map(str,lst))) cmd.rewind() cmd.refresh_wizard()
def set_browse(self,browse): # allow user to focus on only a subset of the compounds self.browse = browse if self.browse == 1: print " Filter: Browsing all compounds." cmd.mset() # all states visible elif self.object==None: print " Filter-Error: please choose an object first" else: self.check_object_dict() if self.browse == 2: print " Filter: Browsing accepted compounds." target = accept_str elif self.browse == 3: print " Filter: Browsing rejected compounds." target = reject_str elif self.browse == 4: print " Filter: Browsing deferred compounds." target = defer_str lst = [] sd = self.state_dict sdo = self.dict[self.object] if self.browse<5: for a in sdo.keys(): if sdo[a]==target: lst.append(sd[a]) else: print " Filter: Browsing remaining compounds" for a in sd.keys(): if not sdo.has_key(a): lst.append(sd[a]) lst.sort() if len(lst)==0: print " Filter-Error: No matching compounds." cmd.mset(' '.join(map(str,lst))) cmd.rewind() cmd.refresh_wizard()
""" Generate a movie from atom-by-atom proposal PMF and placement PDB files. Run with `run movie.py` in PyMOL """ iteration = 6 from pymol import cmd, movie #cmd.mclear() #cmd.mset('1') cmd.set('sphere_scale', 0.02) cmd.rewind() cmd.delete('all') cmd.load('geometry-%d-forward-proposal.pdb' % iteration) cmd.hide('all') cmd.show('spheres', 'name Ar') cmd.spectrum(expression='b', selection='name Ar', palette='blue_white_red', minimum=0, maximum=6) cmd.load('geometry-%d-forward-stages.pdb' % iteration) nframes = 30 specification = '' for i in range(15): specification += '%d x%d ' % (i, nframes) cmd.mset(specification) frame = 0 for i in range(15): movie.rock(frame, frame+nframes) frame += nframes
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.
def frag(state=state, obj=obj): pwd, mutations, orig_sequence = setup(obj) # Add and retain hydrogens cmd.get_wizard().set_hyd("keep") # Run over all sites where to mutate for site in mutations.keys(): variants = mutations[site] # Run over all variants. for variant in variants: cmd.load(obj) cmd.do("wizard mutagenesis") cmd.do("refresh_wizard") cmd.get_wizard().set_mode(variant) cmd.get_wizard().do_select(site + "/") # Get the number of available rotamers at that site # Introduce a condition here to check if # rotamers are requested. # <<OPTION>> # nRots = getRots(site, variant) # if nRots > 3: # nRots = 3 nRots = 1 cmd.rewind() for i in range(1, nRots + 1): cmd.get_wizard().do_select("(" + site + "/)") cmd.frame(i) cmd.get_wizard().apply() # Optimize the mutated sidechain # <<OPTION>> # print "Sculpting." # localSculpt(obj, site) # Protonation of the N. cmd.do("select n%d, name n and %d/" % (int(site), int(site))) cmd.edit("n%d" % int(site), None, None, None, pkresi=0, pkbond=0) cmd.do("h_fill") # Protonation of the C. cmd.do("select c%d, name c and %d/" % (int(site), int(site))) cmd.edit("c%d" % int(site), None, None, None, pkresi=0, pkbond=0) cmd.do("h_fill") # Definition of saveString # saveString = '%s/' % pwd # saveString += 'frag-' + getOne(orig_sequence[site]).lower() +\ # site + getOne(variant).lower() + '-%s.pdb, ' % state +\ # '((%s/))' % site saveStringRot = "%s/" % pwd saveStringRot += ( "frag-" + getOne(orig_sequence[site]).lower() + site + getOne(variant).lower() + "-%02d-%s.pdb, " % (i, state) + "((%s/))" % site ) # print saveString # cmd.do('save %s' % saveString.lower()) cmd.do("save %s" % saveStringRot.lower()) cmd.do("delete all") cmd.set_wizard("done")
def rewind(): cmd.mstop() cmd.rewind()
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 frag(state=state, obj=obj3): pwd, orig_sequence = setup(obj) stored.rotamerDict = {} # Add and retain hydrogens cmd.get_wizard().set_hyd("keep") # Run over all sites where to mutate for site in mutations.keys(): variants = mutations[site] # Run over all variants. for variant in variants: cmd.load(obj) cmd.do('wizard mutagenesis') cmd.do('refresh_wizard') cmd.get_wizard().do_select("(%s/)" % site) cmd.do("cmd.get_wizard().set_mode('%s')"%variant) # Get the number of available rotamers at that site # Introduce a condition here to check if # rotamers are requested. # <<OPTION>> print variant, "variant" nRots = getRots(site, variant) nRots = 2 stored.rotamerDict[str(site)+getOne(variant)] = nRots cmd.rewind() for i in range(1, nRots + 1): cmd.get_wizard().do_select("(" + site + "/)") cmd.frame(i) cmd.get_wizard().apply() # Optimize the mutated sidechain #<<OPTION>> print "Sculpting." localSculpt(obj, site) # Protonation of the N. cmd.do("select n%d, name n and %d/" % (int(site), int(site))) cmd.edit("n%d" % int(site), None, None, None, pkresi=0, pkbond=0) cmd.do("h_fill") # Protonation of the C. cmd.do("select c%d, name c and %d/" % (int(site), int(site))) cmd.edit("c%d" % int(site), None, None, None, pkresi=0, pkbond=0) cmd.do("h_fill") # Definition of saveString saveString = '%s/' % pwd saveString += 'frag-' + getOne(orig_sequence[site]).lower() +\ site + getOne(variant).lower() + '-rot%i-%s.pdb, ' \ % (i,state) +'((%s/))' % site #print saveString cmd.do('save %s' % saveString) cmd.do('delete all') cmd.set_wizard('done') print "Frag is all done"
#import __main__ #__main__.pymol_argv = [ 'pymol', '-qc'] #import pymol #pymol.finish_launching() # DEBUG: ANALYSIS PATH IS HARD-CODED FOR NOW source_directory = 'experiments' reference_pdbfile = 'setup/systems/Abl-STI/complex.pdb' phase = 'complex' replica = 0 # replica index to render #replica = 15 # replica index to render # Load PDB file. cmd.rewind() cmd.delete('all') cmd.reset() cmd.load(reference_pdbfile, 'complex') cmd.remove('resn WAT') # remove waters cmd.select('receptor', '(not resn MOL) and (not resn WAT) and (not hydrogen)') cmd.select('ligand', 'resn MOL and not hydrogen') cmd.select('ions', 'resn Na\+ or resn Cl\-') cmd.deselect() cmd.hide('all') cmd.show('cartoon', 'receptor') cmd.show('spheres', 'ligand') cmd.show('spheres', 'ions') util.cbay('ligand') cmd.color('green', 'receptor')
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