def cache(action='optimize', scenes='', state=-1, quiet=1, _self=cmd): ''' DESCRIPTION "cache" manages storage of precomputed results, such as molecular surfaces. USAGE cache action [, scenes [, state ]] ARGUMENTS action = string: enable, disable, read_only, clear, or optimize scenes = string: a space-separated list of scene names (default: '') state = integer: state index (default: -1) EXAMPLES cache enable cache optimize cache optimize, F1 F2 F5 NOTES "cache optimize" will iterate through the list of scenes provided (or all defined scenes), compute any missing surfaces, and store them in the cache for later reuse. PYMOL API cmd.cache(string action, string scenes, int state, int quiet) ''' r = DEFAULT_ERROR action = cache_action_dict[cache_action_sc.auto_err( str(action), 'action')] quiet = int(quiet) if action == 0: # enable r = _self.set('cache_mode', 2, quiet=quiet) elif action == 1: # disable r = _self.set('cache_mode', 0, quiet=quiet) elif action == 2: # read_only r = _self.set('cache_mode', 1, quiet=quiet) elif action == 3: # clear r = _self._cache_clear(_self=_self) elif action == 4: # optimize r = DEFAULT_SUCCESS _self._cache_mark(_self=_self) cur_scene = _self.get('scene_current_name') cache_max = int(_self.get('cache_max')) if cache_max > 0: # allow double memory for an optimized cache _self.set('cache_max', cache_max * 2) scenes = str(scenes) scene_list = string.split(scenes) cache_mode = int(_self.get('cache_mode')) _self.set('cache_mode', 2) if not len(scene_list): scene_list = _self.get_scene_list() for scene in scene_list: scene = string.strip(scene) if not quiet: print " cache: optimizing scene '%s'." % scene cmd.scene(scene, animate=0) cmd.rebuild() cmd.refresh() if len(cur_scene): cmd.scene(cur_scene, animate=0) else: scene_list = _self.get_scene_list() if len(scene_list): cmd.scene(scene_list[0], animate=0) else: if not quiet: print " cache: no scenes defined -- optimizing current display." cmd.rebuild() cmd.refresh() usage = _self._cache_purge(-1, _self=_self) if cache_mode: _self.set('cache_mode', cache_mode) else: _self.set('cache_mode', 2) # hmm... could use 1 here instead. _self.set('cache_max', cache_max) # restore previous limits if not quiet: print " cache: optimization complete (~%0.1f MB)." % ( usage * 4 / 1000000.0) try: _self.lock(_self) finally: _self.unlock(r, _self) if _self._raising(r, _self): raise QuietException return r
def cache(action='optimize', scenes='',state=-1, quiet=1, _self=cmd): ''' DESCRIPTION "cache" manages storage of precomputed results, such as molecular surfaces. USAGE cache action [, scenes [, state ]] ARGUMENTS action = string: enable, disable, read_only, clear, or optimize scenes = string: a space-separated list of scene names (default: '') state = integer: state index (default: -1) EXAMPLES cache enable cache optimize cache optimize, F1 F2 F5 NOTES "cache optimize" will iterate through the list of scenes provided (or all defined scenes), compute any missing surfaces, and store them in the cache for later reuse. PYMOL API cmd.cache(string action, string scenes, int state, int quiet) ''' r = DEFAULT_ERROR action = cache_action_dict[cache_action_sc.auto_err(str(action),'action')] quiet = int(quiet) if action == 0: # enable r = _self.set('cache_mode',2,quiet=quiet) elif action == 1: # disable r =_self.set('cache_mode',0,quiet=quiet) elif action == 2: # read_only r =_self.set('cache_mode',1,quiet=quiet) elif action == 3: # clear r =_self._cache_clear(_self=_self) elif action == 4: # optimize r = DEFAULT_SUCCESS _self._cache_mark(_self=_self) cur_scene = _self.get('scene_current_name') cache_max = int(_self.get('cache_max')) if cache_max>0: # allow double memory for an optimized cache _self.set('cache_max',cache_max*2) scenes = str(scenes) scene_list = string.split(scenes) cache_mode = int(_self.get('cache_mode')) _self.set('cache_mode',2) if not len(scene_list): scene_list = _self.get_scene_list() for scene in scene_list: scene = string.strip(scene) if not quiet: print " cache: optimizing scene '%s'."%scene cmd.scene(scene,animate=0) cmd.rebuild() cmd.refresh() if len(cur_scene): cmd.scene(cur_scene,animate=0) else: scene_list = _self.get_scene_list() if len(scene_list): cmd.scene(scene_list[0],animate=0) else: if not quiet: print " cache: no scenes defined -- optimizing current display." cmd.rebuild() cmd.refresh() usage = _self._cache_purge(-1,_self=_self) if cache_mode: _self.set('cache_mode',cache_mode) else: _self.set('cache_mode',2) # hmm... could use 1 here instead. _self.set('cache_max',cache_max) # restore previous limits if not quiet: print " cache: optimization complete (~%0.1f MB)."%(usage*4/1000000.0) try: _self.lock(_self) finally: _self.unlock(r,_self) if _self._raising(r,_self): raise QuietException return r
def colorByRMSD(objSel1, objSel2, doAlign="True", doPretty=None): """ colorByRMSD -- align two structures and show the structural deviations in color to more easily see variable regions. PARAMS objSel1 (valid PyMOL object or selection) The first object to align. objSel2 (valid PyMOL object or selection) The second object to align doAlign (boolean, either True or False) Should this script align your proteins or just leave them as is? If doAlign=True then your original proteins are aligned. If False, then they are not. Regardless, the B-factors are changed. DEFAULT: True doPretty (boolean, either True or False) If doPretty=True then a simple representation is created to highlight the differences. If False, then no changes are made. DEFAULT: False RETURNS None. SIDE-EFFECTS Modifies the B-factor columns in your original structures. """ # First create backup copies; names starting with __ (underscores) are # normally hidden by PyMOL tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln" if strTrue(doAlign): # perform the alignment cmd.create( tObj1, objSel1 ) cmd.create( tObj2, objSel2 ) cmd.super( tObj1, tObj2, object=aln ) cmd.matrix_copy(tObj1, objSel1) else: # perform the alignment cmd.create( tObj1, objSel1 ) cmd.create( tObj2, objSel2 ) cmd.super( tObj1, tObj2, object=aln ) # Modify the B-factor columns of the original objects, # in order to identify the residues NOT used for alignment, later on cmd.alter( objSel1 + " or " + objSel2, "b=-10") cmd.alter( tObj1 + " or " + tObj2, "chain='A'") cmd.alter( tObj1 + " or " + tObj2, "segi='A'") # Update pymol internal representations; one of these should do the trick cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2) # Create lists for storage stored.alnAres, stored.alnBres = [], [] # Get the residue identifiers from the alignment object "aln" cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAres.append(resi)") cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBres.append(resi)") # Change the B-factors for EACH object rmsUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres) # Store the NEW B-factors stored.alnAnb, stored.alnBnb = [], [] cmd.iterate(tObj1 + " and n. CA and " + aln, "stored.alnAnb.append(b)" ) cmd.iterate(tObj2 + " and n. CA and " + aln, "stored.alnBnb.append(b)" ) # Get rid of all intermediate objects and clean up cmd.delete(tObj1) cmd.delete(tObj2) cmd.delete(aln) # Assign the just stored NEW B-factors to the original objects for x in range(len(stored.alnAres)): cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x])) for x in range(len(stored.alnBres)): cmd.alter(objSel2 + " and n. CA and i. " + str(stored.alnBres[x]), "b = " + str(stored.alnBnb[x])) cmd.rebuild(); cmd.refresh(); cmd.sort(objSel1); cmd.sort(objSel2) # Provide some useful information stored.allRMSDval = [] stored.allRMSDval = stored.alnAnb + stored.alnBnb print "\nColorByRMSD completed successfully." print "The MINIMUM RMSD value is: "+str(min(stored.allRMSDval)) print "The MAXIMUM RMSD value is: "+str(max(stored.allRMSDval)) if doPretty!=None: # Showcase what we did cmd.orient() cmd.hide("all") cmd.show_as("cartoon", objSel1 + " or " + objSel2) # Select the residues not used for alignment; they still have their B-factors as "-10" cmd.select("notUsedForAln", "b < 0") # White-wash the residues not used for alignment cmd.color("white", "notUsedForAln") # Color the residues used for alignment according to their B-factors (RMSD values) cmd.spectrum("b", 'rainbow', "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln") # Delete the selection of atoms not used for alignment # If you would like to keep this selection intact, # just comment "cmd.delete" line and # uncomment the "cmd.disable" line below. cmd.delete("notUsedForAln") # cmd.disable("notUsedForAln") print "\nObjects are now colored by C-alpha RMS deviation." print "All residues with RMSD values greater than the maximum are colored white..."
def ColorByDisplacementCA(objSel1, objSel2, super1='all', super2='all', doColor="True", doAlign="True", AlignedWhite='yes'): ### First create backup copies; names starting with __ (underscores) are normally hidden by PyMOL tObj1, tObj2, aln = "__tempObj1", "__tempObj2", "__aln" if strTrue(doAlign): ### Create temp objects cmd.create( tObj1, objSel1 ) cmd.create( tObj2, objSel2 ) ### Align and make create an object aln which indicates which atoms were paired between the two structures ### Super is must faster than align http://www.pymolwiki.org/index.php/Super cmd.super(tObj1 + ' and ' + str(super1), tObj2 + ' and ' + str(super2), object=aln) ### Modify the original matrix of object1 from the alignment cmd.matrix_copy(tObj1, objSel1) else: ### Create temp objects cmd.create( tObj1, objSel1 ) cmd.create( tObj2, objSel2 ) ### Align and make create an object aln which indicates which atoms were paired between the two structures ### Super is must faster than align http://www.pymolwiki.org/index.php/Super cmd.super(tObj1 + ' and ' + str(super1), tObj2 + ' and ' + str(super2), object=aln) ### Modify the B-factor columns of the original objects, ### in order to identify the residues NOT used for alignment, later on cmd.alter( objSel1 + " or " + objSel2, "b=-0.2") cmd.alter( tObj1 + " or " + tObj2, "chain='A'") cmd.alter( tObj1 + " or " + tObj2, "segi='A'") ### Update pymol internal representations; one of these should do the trick cmd.refresh(); cmd.rebuild(); cmd.sort(tObj1); cmd.sort(tObj2) ### Create lists for storage stored.alnAres, stored.alnBres = [], [] ### Iterate over objects if AlignedWhite=='yes': cmd.iterate(tObj1 + " and n. CA and not " + aln, "stored.alnAres.append(resi)") cmd.iterate(tObj2 + " and n. CA and not " + aln, "stored.alnBres.append(resi)") else: cmd.iterate(tObj1 + " and n. CA", "stored.alnAres.append(resi)") cmd.iterate(tObj2 + " and n. CA", "stored.alnBres.append(resi)") ### Change the B-factors for EACH object displacementUpdateB(tObj1,stored.alnAres,tObj2,stored.alnBres) ### Store the NEW B-factors stored.alnAnb, stored.alnBnb = [], [] ### Iterate over objects and get b if AlignedWhite=='yes': ### Iterate over objects which is not aligned cmd.iterate(tObj1 + " and n. CA and not " + aln, "stored.alnAnb.append(b)" ) cmd.iterate(tObj2 + " and n. CA and not " + aln, "stored.alnBnb.append(b)" ) else: ### Or Iterate over all objects with CA cmd.iterate(tObj1 + " and n. CA", "stored.alnAnb.append(b)" ) cmd.iterate(tObj2 + " and n. CA", "stored.alnBnb.append(b)" ) ### Get rid of all intermediate objects and clean up cmd.delete(tObj1) cmd.delete(tObj2) cmd.delete(aln) ### Assign the just stored NEW B-factors to the original objects for x in range(len(stored.alnAres)): cmd.alter(objSel1 + " and n. CA and i. " + str(stored.alnAres[x]), "b = " + str(stored.alnAnb[x])) for x in range(len(stored.alnBres)): cmd.alter(objSel2 + " and n. CA and i. " + str(stored.alnBres[x]), "b = " + str(stored.alnBnb[x])) cmd.rebuild(); cmd.refresh(); cmd.sort(objSel1); cmd.sort(objSel2) ### Provide some useful information stored.allRMSDval = [] stored.allRMSDval = stored.alnAnb + stored.alnBnb print "\nColorByDisplacementCA completed successfully." print "The MAXIMUM Displacement is: "+str(max(stored.allRMSDval)) +" residue "+str(stored.alnAres[int(stored.allRMSDval.index(max(stored.allRMSDval)))]) if strTrue(doColor): ### Showcase what we did #cmd.orient() #cmd.hide("all") cmd.show("cartoon", objSel1 + " or " + objSel2) ### Select the residues not used for alignment; they still have their B-factors as "-0.2" cmd.select("notUsedForAln", "b = -0.2") ### White-wash the residues not used for alignment cmd.color("white", "notUsedForAln") ### Select the residues not in both pdb files; they have their B-factors as "-0. 01" cmd.select("ResNotInBothPDB", "b = -0.01") ### White-wash the residues not used for alignment cmd.color("black", "ResNotInBothPDB") ### Color the residues used for alignment according to their B-factors (Displacment values) # cmd.spectrum("b", 'rainbow', "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not notUsedForAln+ResNotInBothPDB") cmd.spectrum("b", 'rainbow', "((" + objSel1 + " and n. CA) or (n. CA and " + objSel2 +" )) and not (notUsedForAln or ResNotInBothPDB)") ### Delete the selection of atoms not used for alignment ### If you would like to keep this selection intact, ### just comment "cmd.delete" line and ### uncomment the "cmd.disable" line abowe. cmd.disable("notUsedForAln") cmd.delete("notUsedForAln") cmd.disable("ResNotInBothPDB") cmd.delete("ResNotInBothPDB") print "\nObjects are now colored by C-alpha displacement deviation." print "Blue is minimum and red is maximum..." print "White is those residues used in the alignment algorithm. Can be turned off in top of algorithm." print "Black is residues that does not exist in both files..."