https://pymolwiki.org/api.php?action=feedcontributions&user=MartinChristen&feedformat=atomPyMOLWiki - User contributions [en]2024-03-29T06:46:27ZUser contributionsMediaWiki 1.35.7https://pymolwiki.org/index.php?title=Set_name&diff=11354Set name2013-07-11T09:12:52Z<p>MartinChristen: added an example to batch-rename multiple objects</p>
<hr />
<div>'''set_name''' can be used to change the name of an object or selection.<br />
<br />
Not only can you simply rename an object or selection, but this command is also a powerful tool for those who deal with multiple structures in one file --- say a collection of NMR models. The user can execute the [[Split_States]] command and then rename the molecule of choice in the state of choice. For example, if one loads an NMR structure (with, say, 20 states) and aligns it to another structure, the balance of the alignment will (most likely) be off due to the weighting of the 19 other structures you probably don't see. To overcome this problem, one simply executes [[Split_States]] and then renames one of the states and then aligns that newly renamed object.<br />
<br />
===USAGE===<br />
set_name old_name, new_name<br />
<br />
===PYMOL API===<br />
<source lang="python"><br />
cmd.set_name(string old_name, string new_name) <br />
</source><br />
<br />
<br />
==User Comments/Examples==<br />
<source lang="python"><br />
cmd.set_name("example", "nicename")<br />
</source><br />
<br />
As the order of arguments is different from, for example, the [[Select]] command (where the desired name for the selection is the first argument), it may be helpful to think of this as similar to the 'mv' shell command, where the existing object is listed first and the destination second.<br />
<br />
<br />
To batch-rename several objects with an appended number at once, use:<br />
<source lang="python"><br />
for a in range(1,999):cmd.set_name("example"+str(a), "nicename"+str(a))<br />
</source><br />
<br />
<br />
[[Category:Commands|Set Name]]<br />
[[Category:States|Set Name]]</div>MartinChristenhttps://pymolwiki.org/index.php?title=Contact_Surface&diff=10991Contact Surface2013-02-15T15:11:59Z<p>MartinChristen: /* The Code */</p>
<hr />
<div>= Overview =<br />
This script calculates individual or global contact areas between a receptor molecule and a (multimodel) bundle of docked ligand structures.<br />
The exact contact surface area values (in Angstrom^2) are printed to the screen and also appended to a file called contactareas.txt.<br />
If only a single global contact surface is calculated, a selection named "contact" is created that includes all receptor atoms within 3.9A of any ligand atom to illustrate the ''approximate'' contact surface.<br />
<br />
<br />
The parameters are:<br />
<br />
'''receptor''' ''(string)''<br />
:: The name of the selection/object representing the receptor protein<br />
<br />
'''ligand''' ''(string)''<br />
:: The name of the selection/object representing the ligand<br />
:: Note that this may be another protein!<br />
<br />
'''states''' ''(integer)'', default:0<br />
:: Calculate contact surface between the receptor and the first n states of the ligand.<br />
:: If states = 0, the script calculates a global contact surface which takes all possible ligand states into account.<br />
<br />
<br />
= Usage =<br />
<source lang="python"><br />
contact_surface receptor, ligand, [states=0]<br />
</source><br />
<br />
<br />
= The Code =<br />
<source lang="python"><br />
#contact_surface v.3.0<br />
#Copyleft Martin Christen, 2013<br />
<br />
from pymol import cmd,stored<br />
def contact_surface(receptor,ligand,states=0):<br />
<br />
"""<br />
AUTHOR<br />
Martin Christen<br />
<br />
DESCRIPTION<br />
This script calculates individual or global contact surfaces between a<br />
receptor molecule and a bundle of docked ligand structures (which have<br />
to be loaded into PyMOL as a multimodel object).<br />
<br />
The exact contact surface area values (in Angstrom^2) are printed to<br />
the screen and also appended to a file called contactareas.txt<br />
<br />
If only a single global contact surface is calculated, a selection<br />
named "contact" is created that includes all receptor atoms within<br />
3.9A of any ligand atom.<br />
<br />
USAGE<br />
contact_surface receptor, ligand, [states=0]<br />
<br />
PARAMETERS<br />
<br />
receptor (string)<br />
The name of the selection/object representing the receptor protein<br />
<br />
ligand (string)<br />
The name of the selection/object representing the ligand.<br />
Note that this may be another protein!<br />
<br />
states (integer)<br />
Calculate contact surface between the receptor and the first n states<br />
of the ligand. If states = 0 (default), the script calculates a global<br />
contact surface which takes all possible ligand states into account.<br />
"""<br />
# sanity check the number of states<br />
states = abs(int(states))<br />
<br />
# make sure all atoms within an object occlude one another<br />
cmd.flag('ignore','none')<br />
<br />
# use solvent-accessible surface with high sampling density<br />
cmd.set('dot_solvent','1')<br />
cmd.set('dot_density','3')<br />
<br />
#if the 'states' parameter = 0 create a superposition of all ligand states<br />
if states == 0:<br />
cmd.split_states(ligand)<br />
cmd.group('ligandtemp',ligand+"_*")<br />
cmd.create(ligand+"_all",'ligandtemp')<br />
cmd.delete('ligandtemp')<br />
<br />
#create complex<br />
cmd.create('complextemp',ligand+"_all "+receptor)<br />
<br />
#measure area<br />
ligand_area=cmd.get_area(ligand+"_all")<br />
receptor_area=cmd.get_area(receptor)<br />
complex_area=cmd.get_area('complextemp')<br />
#normalize since the area is counted TWICE (once on receptor and once on ligand)<br />
contact_area=((ligand_area + receptor_area) - complex_area) / 2<br />
#delete complex<br />
cmd.delete('complextemp')<br />
<br />
#create the contact surface<br />
cmd.select('contact',"("+receptor+" and ("+ligand+"_all around 3.9))")<br />
<br />
#print contact surface area<br />
f=open('contactareas.txt','a')<br />
print "%s - %s : " % (receptor,ligand),<br />
print >>f, "%-s\t%-s\t" % (receptor,ligand),<br />
print >>f, "%-s" % (contact_area)<br />
print contact_area<br />
f.close()<br />
print "The GLOBAL contact area between "+receptor+ " and "+ligand+" is (A^2):"<br />
print ((ligand_area + receptor_area) - complex_area) / 2<br />
<br />
#If 'states' <> 0 calculate the contact areas to the first 'states' ligand states.<br />
#No individual contact surface objects are created to avoid overloading PyMOL.<br />
else:<br />
#create an object for each ligand state<br />
cmd.split_states(ligand)<br />
<br />
#sanity check: do not exceed that maximum number of states<br />
if states > cmd.count_states(ligand):<br />
states = cmd.count_states(ligand)<br />
<br />
#calculate contact surface area<br />
print "The contact areas between "+receptor+" and "+ligand+" [states 1 - "+str(states)+"] are (A^2):"<br />
#start looping<br />
for s in range(1,states+1):<br />
#create complex<br />
cmd.create("tmp",ligand,s,1)<br />
cmd.create('complextemp',"tmp "+receptor)<br />
#measure areas<br />
ligand_area=cmd.get_area('tmp')<br />
receptor_area=cmd.get_area(receptor)<br />
complex_area=cmd.get_area('complextemp')<br />
#normalize since the area is counted TWICE (once on receptor and once on ligand)<br />
contact_area=((ligand_area + receptor_area) - complex_area)/2<br />
#delete temporary files<br />
cmd.delete('tmp')<br />
cmd.delete(ligand+"_*")<br />
cmd.delete('complextemp')<br />
#print contact surface area<br />
f=open('contactareas.txt','a')<br />
print "%s - %s_%-5s: " % (receptor,ligand,s),<br />
print >>f, "%-s\t%-s_%-5s\t" % (receptor,ligand,s),<br />
print >>f, "%-s" % (contact_area)<br />
print contact_area<br />
f.close()<br />
<br />
cmd.extend("contact_surface",contact_surface)<br />
</source><br />
<br />
[[Category:Script_Library]]<br />
[[Category:Math_Scripts]]<br />
[[Category:Structural_Biology_Scripts]]</div>MartinChristenhttps://pymolwiki.org/index.php?title=Contact_Surface&diff=10990Contact Surface2013-02-15T15:11:12Z<p>MartinChristen: </p>
<hr />
<div>= Overview =<br />
This script calculates individual or global contact areas between a receptor molecule and a (multimodel) bundle of docked ligand structures.<br />
The exact contact surface area values (in Angstrom^2) are printed to the screen and also appended to a file called contactareas.txt.<br />
If only a single global contact surface is calculated, a selection named "contact" is created that includes all receptor atoms within 3.9A of any ligand atom to illustrate the ''approximate'' contact surface.<br />
<br />
<br />
The parameters are:<br />
<br />
'''receptor''' ''(string)''<br />
:: The name of the selection/object representing the receptor protein<br />
<br />
'''ligand''' ''(string)''<br />
:: The name of the selection/object representing the ligand<br />
:: Note that this may be another protein!<br />
<br />
'''states''' ''(integer)'', default:0<br />
:: Calculate contact surface between the receptor and the first n states of the ligand.<br />
:: If states = 0, the script calculates a global contact surface which takes all possible ligand states into account.<br />
<br />
<br />
= Usage =<br />
<source lang="python"><br />
contact_surface receptor, ligand, [states=0]<br />
</source><br />
<br />
<br />
= The Code =<br />
<source lang="python"><br />
#contact_surface v.3.0<br />
#Copyleft Martin Christen, 2013<br />
<br />
from pymol import cmd,stored<br />
def contact_surface(receptor,ligand,states=0):<br />
<br />
"""<br />
AUTHOR<br />
Martin Christen<br />
<br />
DESCRIPTION<br />
This script calculates individual or global contact surfaces between a<br />
receptor molecule and a bundle of docked ligand structures (which have<br />
to be loaded into PyMOL as a multimodel object).<br />
<br />
The exact contact surface area values (in Angstrom^2) are printed to<br />
the screen and also appended to a file called contactareas.txt<br />
<br />
If only a single global contact surface is calculated, a selection<br />
named "contact" is created that includes all receptor atoms within<br />
3.9A of any ligand atom.<br />
<br />
USAGE<br />
contact_surface receptor, ligand, [states=0]<br />
<br />
PARAMETERS<br />
<br />
receptor (string)<br />
The name of the selection/object representing the receptor protein<br />
<br />
ligand (string)<br />
The name of the selection/object representing the ligand.<br />
Note that this may be another protein!<br />
<br />
states (integer)<br />
Calculate contact surface between the receptor and the first n states<br />
of the ligand. If states = 0 (default), the script calculates a global<br />
contact surface which takes all possible ligand states into account.<br />
"""<br />
# sanity check the number of states<br />
states = abs(int(states))<br />
<br />
# make sure all atoms within an object occlude one another<br />
cmd.flag('ignore','none')<br />
<br />
# use solvent-accessible surface with high sampling density<br />
cmd.set('dot_solvent','1')<br />
cmd.set('dot_density','3')<br />
<br />
#if the 'states' parameter = 0 create a superposition of all ligand states<br />
if states == 0:<br />
cmd.split_states(ligand)<br />
cmd.group('ligandtemp',ligand+"_*")<br />
cmd.create(ligand+"_all",'ligandtemp')<br />
cmd.delete('ligandtemp')<br />
<br />
#create complex<br />
cmd.create('complextemp',ligand+"_all "+receptor)<br />
<br />
#measure area<br />
ligand_area=cmd.get_area(ligand+"_all")<br />
receptor_area=cmd.get_area(receptor)<br />
complex_area=cmd.get_area('complextemp')<br />
#normalize since the area is counted TWICE (once on receptor and once on ligand)<br />
contact_area=((ligand_area + receptor_area) - complex_area) / 2<br />
#delete complex<br />
cmd.delete('complextemp')<br />
<br />
#create the contact surface<br />
cmd.select('contact',"("+receptor+" and ("+ligand+"_all around 3.9))")<br />
<br />
#print contact surface area<br />
f=open('contactareas.txt','a')<br />
print "%s - %s : " % (receptor,ligand),<br />
print >>f, "%-s\t%-s\t" % (receptor,ligand),<br />
print >>f, "%-s" % (contact_area)<br />
print contact_area<br />
f.close()<br />
print "The GLOBAL contact area between "+receptor+ " and "+ligand+" is (A^2):"<br />
print ((ligand_area + receptor_area) - complex_area) / 2<br />
<br />
#If 'states' <> 0 calculate the contact areas to the first 'states' ligand states.<br />
#No individual contact surface objects are created to avoid overloading PyMOL.<br />
else:<br />
#create an object for each ligand state<br />
cmd.split_states(ligand)<br />
<br />
#sanity check: do not exceed that maximum number of states<br />
if states > cmd.count_states(ligand):<br />
states = cmd.count_states(ligand)<br />
<br />
#calculate contact surface area<br />
print "The contact areas between "+receptor+" and "+ligand+" [states 1 - "+str(states)+"] are (A^2):"<br />
#start looping<br />
#for s in range(1,cmd.count_states(ligand)+1):<br />
for s in range(1,states+1):<br />
#create complex<br />
cmd.create("tmp",ligand,s,1)<br />
cmd.create('complextemp',"tmp "+receptor)<br />
#measure areas<br />
ligand_area=cmd.get_area('tmp')<br />
receptor_area=cmd.get_area(receptor)<br />
complex_area=cmd.get_area('complextemp')<br />
#normalize since the area is counted TWICE (once on receptor and once on ligand)<br />
contact_area=((ligand_area + receptor_area) - complex_area)/2<br />
#delete temporary files<br />
cmd.delete('tmp')<br />
cmd.delete(ligand+"_*")<br />
cmd.delete('complextemp')<br />
#print contact surface area<br />
f=open('contactareas.txt','a')<br />
print "%s - %s_%-5s: " % (receptor,ligand,s),<br />
print >>f, "%-s\t%-s_%-5s\t" % (receptor,ligand,s),<br />
print >>f, "%-s" % (contact_area)<br />
print contact_area<br />
f.close()<br />
<br />
cmd.extend("contact_surface",contact_surface)<br />
</source><br />
<br />
[[Category:Script_Library]]<br />
[[Category:Math_Scripts]]<br />
[[Category:Structural_Biology_Scripts]]</div>MartinChristenhttps://pymolwiki.org/index.php?title=Contact_Surface&diff=10989Contact Surface2013-02-15T15:10:45Z<p>MartinChristen: </p>
<hr />
<div>= Overview =<br />
This script calculates individual or global contact areas between a receptor molecule and a (multimodel) bundle of docked ligand structures.<br />
The exact contact surface area values (in Angstrom^2) are printed to the screen and also appended to a file called contactareas.txt.<br />
If only a single global contact surface is calculated, a selection named "contact" is created that includes all receptor atoms within 3.9A of any ligand atom to illustrate the ''approximate'' contact surface.<br />
<br />
<br />
The parameters are:<br />
<br />
'''receptor''' ''(string)''<br />
:: The name of the selection/object representing the receptor protein<br />
<br />
'''ligand''' ''(string)''<br />
:: The name of the selection/object representing the ligand<br />
:: Note that this may be another protein!<br />
<br />
'''receptor''' ''(string)''<br />
:: The name of the selection/object representing the receptor protein<br />
<br />
'''states''' ''(integer)'', default:0<br />
:: Calculate contact surface between the receptor and the first n states of the ligand.<br />
:: If states = 0, the script calculates a global contact surface which takes all possible ligand states into account.<br />
<br />
<br />
= Usage =<br />
<source lang="python"><br />
contact_surface receptor, ligand, [states=0]<br />
</source><br />
<br />
<br />
= The Code =<br />
<source lang="python"><br />
#contact_surface v.3.0<br />
#Copyleft Martin Christen, 2013<br />
<br />
from pymol import cmd,stored<br />
def contact_surface(receptor,ligand,states=0):<br />
<br />
"""<br />
AUTHOR<br />
Martin Christen<br />
<br />
DESCRIPTION<br />
This script calculates individual or global contact surfaces between a<br />
receptor molecule and a bundle of docked ligand structures (which have<br />
to be loaded into PyMOL as a multimodel object).<br />
<br />
The exact contact surface area values (in Angstrom^2) are printed to<br />
the screen and also appended to a file called contactareas.txt<br />
<br />
If only a single global contact surface is calculated, a selection<br />
named "contact" is created that includes all receptor atoms within<br />
3.9A of any ligand atom.<br />
<br />
USAGE<br />
contact_surface receptor, ligand, [states=0]<br />
<br />
PARAMETERS<br />
<br />
receptor (string)<br />
The name of the selection/object representing the receptor protein<br />
<br />
ligand (string)<br />
The name of the selection/object representing the ligand.<br />
Note that this may be another protein!<br />
<br />
states (integer)<br />
Calculate contact surface between the receptor and the first n states<br />
of the ligand. If states = 0 (default), the script calculates a global<br />
contact surface which takes all possible ligand states into account.<br />
"""<br />
# sanity check the number of states<br />
states = abs(int(states))<br />
<br />
# make sure all atoms within an object occlude one another<br />
cmd.flag('ignore','none')<br />
<br />
# use solvent-accessible surface with high sampling density<br />
cmd.set('dot_solvent','1')<br />
cmd.set('dot_density','3')<br />
<br />
#if the 'states' parameter = 0 create a superposition of all ligand states<br />
if states == 0:<br />
cmd.split_states(ligand)<br />
cmd.group('ligandtemp',ligand+"_*")<br />
cmd.create(ligand+"_all",'ligandtemp')<br />
cmd.delete('ligandtemp')<br />
<br />
#create complex<br />
cmd.create('complextemp',ligand+"_all "+receptor)<br />
<br />
#measure area<br />
ligand_area=cmd.get_area(ligand+"_all")<br />
receptor_area=cmd.get_area(receptor)<br />
complex_area=cmd.get_area('complextemp')<br />
#normalize since the area is counted TWICE (once on receptor and once on ligand)<br />
contact_area=((ligand_area + receptor_area) - complex_area) / 2<br />
#delete complex<br />
cmd.delete('complextemp')<br />
<br />
#create the contact surface<br />
cmd.select('contact',"("+receptor+" and ("+ligand+"_all around 3.9))")<br />
<br />
#print contact surface area<br />
f=open('contactareas.txt','a')<br />
print "%s - %s : " % (receptor,ligand),<br />
print >>f, "%-s\t%-s\t" % (receptor,ligand),<br />
print >>f, "%-s" % (contact_area)<br />
print contact_area<br />
f.close()<br />
print "The GLOBAL contact area between "+receptor+ " and "+ligand+" is (A^2):"<br />
print ((ligand_area + receptor_area) - complex_area) / 2<br />
<br />
#If 'states' <> 0 calculate the contact areas to the first 'states' ligand states.<br />
#No individual contact surface objects are created to avoid overloading PyMOL.<br />
else:<br />
#create an object for each ligand state<br />
cmd.split_states(ligand)<br />
<br />
#sanity check: do not exceed that maximum number of states<br />
if states > cmd.count_states(ligand):<br />
states = cmd.count_states(ligand)<br />
<br />
#calculate contact surface area<br />
print "The contact areas between "+receptor+" and "+ligand+" [states 1 - "+str(states)+"] are (A^2):"<br />
#start looping<br />
#for s in range(1,cmd.count_states(ligand)+1):<br />
for s in range(1,states+1):<br />
#create complex<br />
cmd.create("tmp",ligand,s,1)<br />
cmd.create('complextemp',"tmp "+receptor)<br />
#measure areas<br />
ligand_area=cmd.get_area('tmp')<br />
receptor_area=cmd.get_area(receptor)<br />
complex_area=cmd.get_area('complextemp')<br />
#normalize since the area is counted TWICE (once on receptor and once on ligand)<br />
contact_area=((ligand_area + receptor_area) - complex_area)/2<br />
#delete temporary files<br />
cmd.delete('tmp')<br />
cmd.delete(ligand+"_*")<br />
cmd.delete('complextemp')<br />
#print contact surface area<br />
f=open('contactareas.txt','a')<br />
print "%s - %s_%-5s: " % (receptor,ligand,s),<br />
print >>f, "%-s\t%-s_%-5s\t" % (receptor,ligand,s),<br />
print >>f, "%-s" % (contact_area)<br />
print contact_area<br />
f.close()<br />
<br />
cmd.extend("contact_surface",contact_surface)<br />
</source><br />
<br />
[[Category:Script_Library]]<br />
[[Category:Math_Scripts]]<br />
[[Category:Structural_Biology_Scripts]]</div>MartinChristenhttps://pymolwiki.org/index.php?title=Contact_Surface&diff=10988Contact Surface2013-02-15T15:10:05Z<p>MartinChristen: Script to calculate and display the contact surface area between a receptor and one or more ligand molecules. ~~~~</p>
<hr />
<div>= Overview =<br />
This script calculates individual or global contact areas between a receptor molecule and a (multimodel) bundle of docked ligand structures.<br />
The exact contact surface area values (in Angstrom^2) are printed to the screen and also appended to a file called contactareas.txt<br />
If only a single global contact surface is calculated, a selection named "contact" is created that includes all receptor atoms within 3.9A of any ligand atom to illustrate the ''approximate'' contact surface.<br />
<br />
<br />
The parameters are:<br />
<br />
'''receptor''' ''(string)''<br />
:: The name of the selection/object representing the receptor protein<br />
<br />
'''ligand''' ''(string)''<br />
:: The name of the selection/object representing the ligand<br />
:: Note that this may be another protein!<br />
<br />
'''receptor''' ''(string)''<br />
:: The name of the selection/object representing the receptor protein<br />
<br />
'''states''' ''(integer)'', default:0<br />
:: Calculate contact surface between the receptor and the first n states of the ligand.<br />
:: If states = 0, the script calculates a global contact surface which takes all possible ligand states into account.<br />
<br />
<br />
= Usage =<br />
<source lang="python"><br />
contact_surface receptor, ligand, [states=0]<br />
</source><br />
<br />
<br />
= The Code =<br />
<source lang="python"><br />
#contact_surface v.3.0<br />
#Copyleft Martin Christen, 2013<br />
<br />
from pymol import cmd,stored<br />
def contact_surface(receptor,ligand,states=0):<br />
<br />
"""<br />
AUTHOR<br />
Martin Christen<br />
<br />
DESCRIPTION<br />
This script calculates individual or global contact surfaces between a<br />
receptor molecule and a bundle of docked ligand structures (which have<br />
to be loaded into PyMOL as a multimodel object).<br />
<br />
The exact contact surface area values (in Angstrom^2) are printed to<br />
the screen and also appended to a file called contactareas.txt<br />
<br />
If only a single global contact surface is calculated, a selection<br />
named "contact" is created that includes all receptor atoms within<br />
3.9A of any ligand atom.<br />
<br />
USAGE<br />
contact_surface receptor, ligand, [states=0]<br />
<br />
PARAMETERS<br />
<br />
receptor (string)<br />
The name of the selection/object representing the receptor protein<br />
<br />
ligand (string)<br />
The name of the selection/object representing the ligand.<br />
Note that this may be another protein!<br />
<br />
states (integer)<br />
Calculate contact surface between the receptor and the first n states<br />
of the ligand. If states = 0 (default), the script calculates a global<br />
contact surface which takes all possible ligand states into account.<br />
"""<br />
# sanity check the number of states<br />
states = abs(int(states))<br />
<br />
# make sure all atoms within an object occlude one another<br />
cmd.flag('ignore','none')<br />
<br />
# use solvent-accessible surface with high sampling density<br />
cmd.set('dot_solvent','1')<br />
cmd.set('dot_density','3')<br />
<br />
#if the 'states' parameter = 0 create a superposition of all ligand states<br />
if states == 0:<br />
cmd.split_states(ligand)<br />
cmd.group('ligandtemp',ligand+"_*")<br />
cmd.create(ligand+"_all",'ligandtemp')<br />
cmd.delete('ligandtemp')<br />
<br />
#create complex<br />
cmd.create('complextemp',ligand+"_all "+receptor)<br />
<br />
#measure area<br />
ligand_area=cmd.get_area(ligand+"_all")<br />
receptor_area=cmd.get_area(receptor)<br />
complex_area=cmd.get_area('complextemp')<br />
#normalize since the area is counted TWICE (once on receptor and once on ligand)<br />
contact_area=((ligand_area + receptor_area) - complex_area) / 2<br />
#delete complex<br />
cmd.delete('complextemp')<br />
<br />
#create the contact surface<br />
cmd.select('contact',"("+receptor+" and ("+ligand+"_all around 3.9))")<br />
<br />
#print contact surface area<br />
f=open('contactareas.txt','a')<br />
print "%s - %s : " % (receptor,ligand),<br />
print >>f, "%-s\t%-s\t" % (receptor,ligand),<br />
print >>f, "%-s" % (contact_area)<br />
print contact_area<br />
f.close()<br />
print "The GLOBAL contact area between "+receptor+ " and "+ligand+" is (A^2):"<br />
print ((ligand_area + receptor_area) - complex_area) / 2<br />
<br />
#If 'states' <> 0 calculate the contact areas to the first 'states' ligand states.<br />
#No individual contact surface objects are created to avoid overloading PyMOL.<br />
else:<br />
#create an object for each ligand state<br />
cmd.split_states(ligand)<br />
<br />
#sanity check: do not exceed that maximum number of states<br />
if states > cmd.count_states(ligand):<br />
states = cmd.count_states(ligand)<br />
<br />
#calculate contact surface area<br />
print "The contact areas between "+receptor+" and "+ligand+" [states 1 - "+str(states)+"] are (A^2):"<br />
#start looping<br />
#for s in range(1,cmd.count_states(ligand)+1):<br />
for s in range(1,states+1):<br />
#create complex<br />
cmd.create("tmp",ligand,s,1)<br />
cmd.create('complextemp',"tmp "+receptor)<br />
#measure areas<br />
ligand_area=cmd.get_area('tmp')<br />
receptor_area=cmd.get_area(receptor)<br />
complex_area=cmd.get_area('complextemp')<br />
#normalize since the area is counted TWICE (once on receptor and once on ligand)<br />
contact_area=((ligand_area + receptor_area) - complex_area)/2<br />
#delete temporary files<br />
cmd.delete('tmp')<br />
cmd.delete(ligand+"_*")<br />
cmd.delete('complextemp')<br />
#print contact surface area<br />
f=open('contactareas.txt','a')<br />
print "%s - %s_%-5s: " % (receptor,ligand,s),<br />
print >>f, "%-s\t%-s_%-5s\t" % (receptor,ligand,s),<br />
print >>f, "%-s" % (contact_area)<br />
print contact_area<br />
f.close()<br />
<br />
cmd.extend("contact_surface",contact_surface)<br />
</source><br />
<br />
[[Category:Script_Library]]<br />
[[Category:Math_Scripts]]<br />
[[Category:Structural_Biology_Scripts]]</div>MartinChristenhttps://pymolwiki.org/index.php?title=Cluster_Count&diff=10986Cluster Count2013-02-14T11:30:54Z<p>MartinChristen: New script to get statistics on b-factors ~~~~</p>
<hr />
<div>= Overview =<br />
This script calculates statistics on the B-values for all atoms in the selected object, prints the information on screen and appends it to a file called "cluster_count.txt".<br />
<br />
<br />
= Usage =<br />
<source lang="python"><br />
cluster_count object<br />
</source><br />
<br />
<br />
= Example =<br />
<source lang="python"><br />
cluster_count 1ubq<br />
<br />
#output on screen:<br />
<br />
Number of atoms in ' 1ubq ': 602<br />
Minimum and Maximum B-values: 2.0 42.75<br />
Average B-value: 13.4131063029<br />
Standard deviation of the B-values: 8.70767140923<br />
This data will be appended to cluster_count.txt<br />
<br />
#output in file cluster_count.txt; the format is:<br />
#objectname N minB maxB aveB stdevB<br />
1ubq 602 2.000 42.750 13.413 8.708<br />
</source><br />
<br />
<br />
= The Code =<br />
<source lang="python"><br />
<br />
# Script: cluster_count.py<br />
# Copyleft 2010 Martin Christen<br />
<br />
from pymol import cmd,stored<br />
def cluster_count(selection):<br />
<br />
"""<br />
AUTHOR<br />
<br />
Martin Christen<br />
<br />
DESCRIPTION<br />
<br />
This script calculates statistics on the B-values for all atoms in<br />
the selected object, prints the information on screen and appends<br />
it to the file "cluster_count.txt".<br />
<br />
Output format on screen:<br />
------------------------<br />
Number of atoms in 'selection': 0<br />
Minimum and Maximum B-values: 0.0<br />
Average B-value : 0.0<br />
Standard deviation of the B-values (best): 0.0 (0.0)<br />
This data will be appended to cluster_count.txt<br />
<br />
Output format in cluster_count.txt:<br />
-----------------------------------<br />
selection N minB maxB aveB stdevB<br />
<br />
EXAMPLE<br />
<br />
cluster_count 1ubq<br />
<br />
Number of atoms in ' 1ubq ': 602<br />
Minimum and Maximum B-values: 2.0 42.75<br />
Average B-value: 13.4131063029<br />
Standard deviation of the B-values: 8.70767140923<br />
This data will be appended to cluster_count.txt<br />
<br />
(in cluster_count.txt:)<br />
1ubq 602 2.000 42.750 13.413 8.708<br />
<br />
USAGE<br />
<br />
cluster_count selection<br />
<br />
"""<br />
<br />
# get list of B-factors from selection<br />
m = cmd.get_model(selection)<br />
sel = []<br />
b_list = []<br />
dummy = []<br />
for i in range(len(m.atom)):<br />
b_list.append(m.atom[i].b)<br />
<br />
#determine min and max<br />
try: max_b = max(b_list)<br />
except ValueError: max_b=0<br />
try: min_b = min(b_list)<br />
except ValueError: min_b=0<br />
<br />
#determine average<br />
try: average_b= float(sum(b_list)) / len(b_list)<br />
except ZeroDivisionError: average_b=0<br />
<br />
#determine standard deviation<br />
for i in range(len(m.atom)):<br />
if m.atom[i]>average_b:<br />
dummy.append((m.atom[i].b-average_b)**2)<br />
if m.atom[i]<average_b:<br />
dummy.append((average_b-m.atom[i].b)**2)<br />
try: stdev_b= (sum(dummy) / (len(m.atom)-1))**(1/2.0)<br />
except ZeroDivisionError: stdev_b=0<br />
<br />
#print values on screen<br />
print "Number of atoms in '", selection,"': ", len(b_list)<br />
print "Minimum and Maximum B-values: ", min_b, max_b<br />
print "Average B-value: ", average_b<br />
print "Standard deviation of the B-values: ", stdev_b<br />
print "This data will be appended to cluster_count.txt"<br />
<br />
#write information to cluster_count.txt<br />
f=open('cluster_count.txt','a')<br />
print >>f, '%-10s %8d %8.3f %8.3f %8.3f %8.3f' % (selection, len(m.atom), min_b, max_b, average_b, stdev_b)<br />
f.close()<br />
cmd.extend("cluster_count",cluster_count)<br />
</source><br />
<br />
[[Category:Script_Library]]<br />
[[Category:ObjSel_Scripts]]</div>MartinChristenhttps://pymolwiki.org/index.php?title=Make_Figures&diff=10985Make Figures2013-02-13T16:56:46Z<p>MartinChristen: New script to easily create figures. ~~~~</p>
<hr />
<div>= Overview =<br />
This script will aid you in making publication quality figures for the currently displayed scene.<br />
It understands a variety of preset "modes" and sizes.<br />
<br />
<br />
= Usage =<br />
<source lang="python"><br />
make_figure filename [, mode] [, size (default=900 pixels)] [,opaque]<br />
</source><br />
<br />
The parameters are:<br />
<br />
'''filename''' : The name of the resulting image file.<br />
::''The extension '''.png''' is added automatically.''<br />
<br />
<br />
<br />
''NOTE'': if no further arguments are given, the script generates quick figures for general use:<br />
::* figures are not ray-traced<br />
::* TWO figures at 300 x 300 px, 72 dpi<br />
::* views are rotated 180° about y (front and back view)<br />
::* _front_quick and _back_quick are appended to the filename<br />
<br />
<br />
<br />
'''mode''' : Type of figure desired. Possible values are as follows:<br />
<br />
<br />
::'''''single''''' = "single view"<br />
::* one ray-traced 300 dpi figure of the current view<br />
<br />
<br />
::'''''fb''''' = "front and back view"<br />
::* TWO ray-traced 300 dpi figures<br />
::* views are rotated 180° about y<br />
::* _front and _back are appended to the filename<br />
<br />
<br />
::'''''sides''''' = "four side views"<br />
::* FOUR ray-traced 300 dpi figures<br />
::* view is incrementally rotated by 90° about y<br />
::* _1, _2, _3, and _4 are appended to the filename<br />
<br />
<br />
::'''''stereo''''' = "stereoview"<br />
::* TWO ray-traced 300 dpi figures<br />
::* views are shifted by +/- 3 degrees<br />
::* image dimensions are fixed at 750 x 750 pixels (size arguments are ignored)<br />
::* _L and _R are appended to the filename<br />
::* the output files are meant to be combined side by side to generate a stereo image<br />
<br />
<br />
<br />
'''size''' : Size of the figure(s) in pixels or in "panels"<br />
::* DEFAULT = 900 pixels if a mode is specified<br />
::* if size is 12 or smaller, the script interprets it as a number of "panels" to make.<br />
::* panel sizes in pixels are hardcoded in the source but can easily be modified.<br />
<br />
<br />
<br />
'''opaque''' : Create an opaque background.<br />
::* By default the figure background is 100% transparent.<br />
<br />
<br />
= Examples =<br />
<source lang="python"><br />
<br />
#quick 'n' dirty front and back views of the scene<br />
#300x300 pixels at 72 dpi, transparent background<br />
# filenames will be output_front_quick.png and output_back_quick.png<br />
make_figure output<br />
<br />
# one ray-traced PNG file 975x975 pixels at 300dpi, with opaque background<br />
# filename will be output.png<br />
make_figure output, single, 975, opaque<br />
<br />
# two panels (1350x1350 px each at 300dpi) of the "front" and "back" view on transparent background<br />
# filenames will be output_front.png and output_back.png<br />
make_figure output, fb, 2<br />
<br />
# four panels (900x900 px each) where the view is incrementally rotated by 90° about y, transparent background<br />
# filenames will be output_1.png, output_2.png, output_3.png and output_4.png<br />
make_figure output, sides,4<br />
<br />
#stereoview of the current scene with opaque background<br />
#size is fixed to 2x 750x750px<br />
# filenames will be output_L.png and output_R.png<br />
make_figure output, stereo, opaque<br />
</source><br />
<br />
<br />
= The Code =<br />
<source lang="python"><br />
#make_figure v.3.0<br />
#Copyleft Martin Christen, 2010<br />
<br />
from pymol import cmd<br />
def make_figure(output='', mode='',size=900,opaque='transparent'):<br />
<br />
"""<br />
<br />
AUTHOR<br />
<br />
Martin Christen<br />
<br />
<br />
DESCRIPTION<br />
<br />
"make_figure" creates publication-quality figures of the current scene.<br />
It understands several predefined "modes" and sizes.<br />
<br />
<br />
USAGE<br />
<br />
make_figure filename [, mode] [, size (default=900 pixels)] [,opaque]<br />
<br />
<br />
ARGUMENTS<br />
<br />
mode = string: type of desired figure (single, fb, sides, stereo or -nothing-)<br />
size = integer: size of the figure in pixels OR # panels (if <= 12)<br />
opaque = specify an opaque background.<br />
By default, the script makes the background transparent.<br />
EXAMPLES<br />
<br />
make_figure output<br />
make_figure output, single, 975, opaque<br />
make_figure output, fb, 2<br />
make_figure output, sides,4<br />
make_figure output, stereo<br />
<br />
<br />
NOTES<br />
<br />
"single" mode makes a single 300 dpi figure<br />
<br />
"fb" mode makes TWO 300 dpi figure<br />
("front" and "back", rotating by 180 degrees about y)<br />
<br />
"sides" mode makes FOUR 300 dpi figures<br />
("front" "left" "right" and back, rotating by 90 degrees clockwise about y)<br />
<br />
"stereo" generates two 300 dpi, 750 px figures<br />
("L" and "R", to be combined as a stereo image)<br />
If you specify the stereo mode, the size argument is IGNORED.<br />
<br />
If no mode argument is given, the script generates quick figures<br />
for general use: TWO figures (front and back) at 300 x 300 px, 72 dpi.<br />
<br />
Size is interpreted as pixels, except if the number is ridiculously small<br />
(<=12), in which case the script as "number of panels" to make.<br />
<br />
Edit the script manually to define corresponding values.<br />
<br />
"""<br />
<br />
#define sizes here (in pixels)<br />
panel1 = 1800<br />
panel2 = 1350<br />
panel3 = 900<br />
panel4 = 900<br />
panel5 = 750<br />
panel6 = 750<br />
panel7 = 675<br />
panel8 = 675<br />
panel9 = 600<br />
panel10 = 585<br />
panel11 = 585<br />
panel12 = 585<br />
<br />
#verify size is an integer number and convert to pixels<br />
size = int(size)<br />
if size > 12:<br />
pixels = size<br />
<br />
elif size == 1:<br />
pixels = panel1<br />
<br />
elif size == 2:<br />
pixels = panel2<br />
<br />
elif size == 3:<br />
pixels = panel3<br />
<br />
elif size == 4:<br />
pixels = panel4<br />
<br />
elif size == 5:<br />
pixels = panel5<br />
<br />
elif size == 6:<br />
pixels = panel6<br />
<br />
elif size == 7:<br />
pixels = panel7<br />
<br />
elif size == 8:<br />
pixels = panel8<br />
<br />
elif size == 9:<br />
pixels = panel9<br />
<br />
elif size == 10:<br />
pixels = panel10<br />
<br />
elif size == 11:<br />
pixels = panel11<br />
<br />
elif size == 3:<br />
pixels = panel12<br />
<br />
#change background<br />
cmd.unset('opaque_background')<br />
if opaque == 'opaque':<br />
cmd.set('opaque_background')<br />
<br />
#apply mode<br />
if output == '':<br />
print 'no output filename defined\n'<br />
print 'try: \'make_figure filename\''<br />
return -1<br />
# abort if no output file name given<br />
<br />
if mode =='':<br />
cmd.set('surface_quality',1)<br />
cmd.set('opaque_background')<br />
cmd.png(output+"_back_quick",300,300,dpi=72)<br />
cmd.turn('y',180)<br />
cmd.png(output+"_front_quick",300,300,dpi=72)<br />
cmd.turn('y',180)<br />
cmd.set('surface_quality',0)<br />
# make front and back figures for quick mode<br />
<br />
elif mode == 'single':<br />
cmd.set('surface_quality',1)<br />
cmd.set('ray_shadow',0)<br />
cmd.ray(pixels, pixels)<br />
cmd.png(output, dpi=300)<br />
cmd.set('surface_quality',0)<br />
# make a figure for single mode<br />
<br />
elif mode == 'fb':<br />
cmd.set('surface_quality',1)<br />
cmd.set('ray_shadow',0)<br />
cmd.ray(pixels, pixels)<br />
cmd.png(output+"_front", dpi=300)<br />
cmd.turn('y',180)<br />
cmd.ray(pixels, pixels)<br />
cmd.png(output+"_back", dpi=300)<br />
cmd.turn('y',180)<br />
cmd.set('surface_quality',0)<br />
# make front and back figures for single mode<br />
<br />
elif mode == 'sides':<br />
cmd.set('surface_quality',1)<br />
cmd.set('ray_shadow',0)<br />
cmd.ray(pixels, pixels)<br />
cmd.png(output+"_1", dpi=300)<br />
cmd.turn('y',90)<br />
cmd.ray(pixels, pixels)<br />
cmd.png(output+"_2", dpi=300)<br />
cmd.turn('y',90)<br />
cmd.ray(pixels, pixels)<br />
cmd.png(output+"_3", dpi=300)<br />
cmd.turn('y',90)<br />
cmd.ray(pixels, pixels)<br />
cmd.png(output+"_4", dpi=300)<br />
cmd.turn('y',90)<br />
cmd.set('surface_quality',0)<br />
# make front and back figures for single mode<br />
<br />
elif mode == 'stereo':<br />
cmd.set('surface_quality',1)<br />
cmd.set('ray_shadow',0)<br />
cmd.ray(750, 750, angle=-3)<br />
cmd.png(output+"_R", dpi=300)<br />
cmd.ray(750, 750, angle=3)<br />
cmd.png(output+"_L", dpi=300)<br />
# make stereo figure (for more control use stereo_ray)<br />
<br />
cmd.extend('make_figure',make_figure)<br />
</source><br />
<br />
<br />
[[Category:Script_Library]]<br />
[[Category:UI_Scripts]]</div>MartinChristen