Difference between revisions of "ShowLigandWaters"

From PyMOLWiki
Jump to navigation Jump to search
 
(10 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
|type      = script
 
|type      = script
 
|download  =  
 
|download  =  
|author    = [[User:PietroGattiLafranconi|Pietro Gatti-Lafranconi]]
+
|author    = [[User:GianlucaTomasello|Gianluca Tomasello]]
 
|license  = [http://creativecommons.org/licenses/by-nc-sa/3.0 CC BY-NC-SA]
 
|license  = [http://creativecommons.org/licenses/by-nc-sa/3.0 CC BY-NC-SA]
 
}}
 
}}
  
This is a test page##
+
 
  
 
== Introduction ==
 
== Introduction ==
Given any two selections, this script calculates and returns the pairwise distances between all atoms that fall within a defined distance.
+
This script detects waters molecules within a specified distance from the ligand.<br>
 +
Detected water molecules are shown as spheres.<br>
 +
Distances between water molecules and O or N atoms of ligand (potential H-bonds) are shown by dotted lines.<br>
 +
An output file containing a list of distance between waters and ligand atoms and the number of interactions is written in the main PyMol folder.
  
Can be used to measure distances within the same chain, between different chains or different objects.
 
 
Distances can be restricted to sidechain atoms only and the outputs either displayed on screen or printed on file.
 
  
  
 
== Usage ==
 
== Usage ==
pairwise_dist sel1, sel2, max_dist, [output=S/P/N, [sidechain=N/Y, [show=Y/N]]]
+
waters [ligand name, distance]
  
  
 
== Required Arguments ==
 
== Required Arguments ==
* '''sel1''' = first selection
+
* '''ligand name''' = the ligand residue name
* '''sel2''' = second selection
+
* '''distance''' = max distance in Angstroms
* '''max_dist''' = max distance in Angstroms
 
 
 
 
 
== Optional Arguments ==
 
* '''output''' = accepts Screen/Print/None (default N)
 
* '''sidechain''' = limits (Y) results to sidechain atoms (default N)
 
* '''show''' = shows (Y) individual distances in pymol menu (default=N)
 
  
  
 
== Examples ==
 
== Examples ==
'''example #1'''
+
'''example #1 on PDB structure (1C0L)'''
 
<source lang="python">
 
<source lang="python">
PyMOL>pairwise_dist 1efa and chain D, 1efa and chain B, 3, output=S, show=Y
+
PyMOL>waters FAD, 2.8
 +
</source>
 +
Output in GUI of PyMol:
 +
 
 +
Total number of water molecules at 2.8 A from ligand FAD: 3
 +
Number of water molecules that interact with ligand: 3
 +
Number of interactions between water molecules and ligand: 4
 
   
 
   
1efa/D/DC/13/OP1 to 1efa/B/TYR/47/OH: 2.765
+
output file: waters.txt
1efa/D/DC/13/OP2 to 1efa/B/LEU/6/N: 2.983
+
 
1efa/D/DC/13/OP2 to 1efa/B/LEU/6/CB: 2.928
+
HOH residue 2002 -- and -- ['FAD', '1363', 'O1P']  --->  2.611289 A
1efa/D/DT/14/O4' to 1efa/B/ALA/57/CB: 2.827
+
HOH residue 2002 -- and -- ['FAD', '1363', 'O5B']  --->  3.592691 A
1efa/D/DT/14/OP1 to 1efa/B/ASN/25/OD1: 2.858
+
HOH residue 2008 -- and -- ['FAD', '1363', 'O1A']  --->  2.678604 A
1efa/D/DT/14/OP1 to 1efa/B/GLN/54/NE2: 2.996
+
HOH residue 2009 -- and -- ['FAD', '1363', 'O2P']  --->  2.643039 A
1efa/D/DT/14/OP2 to 1efa/B/SER/21/OG: 2.517
+
-------------------------------------------------------------
1efa/D/DC/15/N4 to 1efa/B/GLN/18/NE2: 2.723
+
Total number of water molecules at 2.8 A from ligand FAD: 3
1efa/D/DA/16/N6 to 1efa/B/GLN/18/NE2: 2.931
+
Number of water molecules that interact with ligand: 3
+
Number of interactions between water molecules and ligand: 4
Number of distances calculated: 9
 
</source>
 
  
[[File:pairwise1.png|450px|example #1]]
+
[[File:Example 1 FAD 1C0L.png|450px|example #1]]
  
  
'''example #2'''
 
<source lang="python">
 
PyMOL>pairwise_dist 2w8s and chain a, 2W8s and chain b, 3, sidechain=Y, output=S, show=Y
 
 
2W8S/A/GLN/432/OE1 to 2W8S/B/ARG/503/NH2: 2.758
 
2W8S/A/ASP/434/OD1 to 2W8S/B/SER/493/OG: 2.444
 
2W8S/A/TYR/447/OH to 2W8S/B/GLN/485/NE2: 2.878
 
2W8S/A/HIS/449/NE2 to 2W8S/B/SER/489/OG: 2.686
 
2W8S/A/GLN/485/OE1 to 2W8S/B/TYR/447/OH: 2.971
 
2W8S/A/SER/489/OG to 2W8S/B/HIS/449/NE2: 2.913
 
2W8S/A/SER/493/OG to 2W8S/B/ASP/434/OD1: 2.491
 
2W8S/A/ARG/503/NH2 to 2W8S/B/GLN/432/OE1: 2.653
 
 
Number of distances calculated: 8
 
</source>
 
  
[[File:pairwise2.png|450px|example #2]]
+
== The Code ==
  
 +
Copy the following text and save it as waters.py
  
'''example #3'''
 
 
<source lang="python">
 
<source lang="python">
PyMOL>pairwise_dist 1FOS and chain H and resi 290:300, 1FOS and chain G, 4, sidechain=Y, show=Y, output=P
+
# -*- coding: cp1252 -*-
+
"""
Results saved in IntAtoms_4.txt
+
This script detects waters molecules within a specified distance from the ligand.
Number of distances calculated: 24
+
Water molecules are shown.
</source>
+
Distance between water molecules and O or N atoms of ligand are shown.
 +
 
 +
Author: Gianluca Tomasello, Gianluca Molla
 +
University of Insubria, Varese, Italy
 +
09/02/2013
 +
gianluca.molla@uninsubria.it
  
[[File:pairwise3.png|450px|example #3]]
+
Usage
 +
waters, [ligand name, distance]
  
 +
Parameters
  
 +
ligand : the ligand residue name
  
== The Code ==
+
distance : a float number that specify the maximum distance from the ligand to consider the water molecule
 +
         
 +
Output
 +
-A file is produced containing a list of distance between waters and ligand atoms and the number of interactions
 +
-A graphic output show the water molecules interacting whith the ligand atoms by showing the distances between them
 +
"""
  
Copy the following text and save it as pairwisedistances.py
+
from pymol import cmd,stored
 +
#define function: waters
 +
def waters(ligand, distance):
 +
    stored.HOH = []
 +
    cmd.set('label_color','white')
 +
    cmd.delete ("sele")
 +
    cmd.hide ("everything")
 +
    cmd.show_as ("sticks", "resn %s" % ligand)
 +
    #iterate all water molecules nearby the ligand
 +
    cmd.iterate('resn %s around %s and resn HOH' % (ligand,distance),'stored.HOH.append(resi)')
 +
    f = open("waters.txt","a")
 +
    count=0
 +
    count_int=0
 +
   
 +
    for i in range(0,len(stored.HOH)):       
 +
        cmd.distance('dist_HOH_FAD', 'resi ' + stored.HOH[i], '(resn %s and n. O*+N*) w. 3.6 of resi %s'% (ligand, stored.HOH[i]))
 +
        stored.name = []
 +
        #iterate all ligand atoms within a predetermined distance from the water molecule
 +
        cmd.iterate('(resn %s and n. O*+N*) w. 3.6 of resi %s'% (ligand, stored.HOH[i]),'stored.name.append([resn,resi,name])')
  
<source lang="python">
+
        if stored.name:         
from pymol import cmd, stored, math
+
            count = count+1
 +
            count_int = count_int+len(stored.name)
  
def pairwise_dist(sel1, sel2, max_dist, output="N", sidechain="N", show="N"):
+
        for j in range(0,len(stored.name)):          
"""
+
            cmd.select('base', 'resi ' + stored.HOH[i])
usage: pairwise_dist sel1, sel2, max_dist, [output=S/P/N, [sidechain=N/Y, [show=Y/N]]]
+
            cmd.select('var','resn '+ligand+ ' and n. ' + stored.name[j][2])  
sel1 and sel2 can be any to pre-existing or newly defined selections
+
            #calculate the distance between a specific atom and the water molecule
max_dist: maximum distance in Angstrom between atoms in the two selections
+
            dist = cmd.get_distance('base','var')          
--optional settings:
+
            f.write('HOH residue %s -- and -- %s  --->  %f A\n'%(stored.HOH[i],stored.name[j], dist))
output: accepts Screen/Print/None (default N)
 
sidechain: limits (Y) results to sidechain atoms (default N)
 
show: shows (Y) individual distances in pymol menu (default=N)
 
"""
 
print ""
 
cmd.delete ("dist*")
 
extra=""
 
if sidechain=="Y": extra=" and not name c+o+n"
 
 
#builds models
 
m1=cmd.get_model(sel2+" around "+str(max_dist)+" and "+sel1+extra)
 
m1o=cmd.get_object_list(sel1)
 
m2=cmd.get_model(sel1+" around "+str(max_dist)+" and "+sel2+extra)
 
m2o=cmd.get_object_list(sel2)
 
  
#defines selections
+
    cmd.select ("waters","resn %s around %s and resn HOH" % (ligand,distance))
cmd.select("__tsel1a", sel1+" around "+str(max_dist)+" and "+sel2+extra)
+
    cmd.show_as ("spheres", "waters")
cmd.select("__tsel1", "__tsel1a and "+sel2+extra)
+
    cmd.zoom ("visible")
cmd.select("__tsel2a", sel2+" around "+str(max_dist)+" and "+sel1+extra)
+
    num_atm = cmd.count_atoms ("waters")
cmd.select("__tsel2", "__tsel2a and "+sel1+extra)
+
    print ("Total number of water molecules at %s A from ligand %s: %s \n" % (distance,ligand,num_atm))
cmd.select("IntAtoms_"+max_dist, "__tsel1 or __tsel2")
+
    print ("Number of water molecules that interact with ligand: %d\n" % (count))
cmd.select("IntRes_"+max_dist, "byres IntAtoms_"+max_dist)
+
    print ("Number of interactions between water molecules and ligand: %d\n" % count_int)
+
    f.write('-------------------------------------------------------------\n')
#controlers-1
+
    f.write("Total number of water molecules at %s A from ligand %s: %s \n" % (distance,ligand,num_atm))
if len(m1o)==0:
+
    f.write("Number of water molecules that interact with ligand: %d\n" % count)
print "warning, '"+sel1+extra+"' does not contain any atoms."
+
    f.write("Number of interactions between water molecules and ligand: %d\n\n\n\n" % count_int)
return
+
    f.close()
if len(m2o)==0:
+
    cmd.delete ("waters")
print "warning, '"+sel2+extra+"' does not contain any atoms."
+
   
return
+
cmd.extend("waters",waters)
 
#measures distances
 
s=""
 
counter=0
 
for c1 in range(len(m1.atom)):
 
for c2 in range(len(m2.atom)):
 
distance=math.sqrt(sum(map(lambda f: (f[0]-f[1])**2, zip(m1.atom[c1].coord,m2.atom[c2].coord))))
 
if distance<float(max_dist):
 
s+="%s/%s/%s/%s/%s to %s/%s/%s/%s/%s: %.3f\n" % (m1o[0],m1.atom[c1].chain,m1.atom[c1].resn,m1.atom[c1].resi,m1.atom[c1].name,m2o[0],m2.atom[c2].chain,m2.atom[c2].resn,m2.atom[c2].resi,m2.atom[c2].name, distance)
 
counter+=1
 
if show=="Y": cmd.distance (m1o[0]+" and "+m1.atom[c1].chain+"/"+m1.atom[c1].resi+"/"+m1.atom[c1].name, m2o[0]+" and "+m2.atom[c2].chain+"/"+m2.atom[c2].resi+"/"+m2.atom[c2].name)
 
  
#controler-2
 
if counter==0:
 
print "warning, no distances were measured! Check your selections/max_dist value"
 
return
 
 
#outputs
 
if output=="S": print s
 
if output=="P":
 
f=open('IntAtoms_'+max_dist+'.txt','w')
 
f.write("Number of distances calculated: %s\n" % (counter))
 
f.write(s)
 
f.close()
 
print "Results saved in IntAtoms_%s.txt" % max_dist
 
print "Number of distances calculated: %s" % (counter)
 
cmd.hide("lines", "IntRes_*")
 
if show=="Y": cmd.show("lines","IntRes_"+max_dist)
 
cmd.deselect()
 
 
 
cmd.extend("pairwise_dist", pairwise_dist)
 
 
</source>
 
</source>
  

Latest revision as of 05:54, 2 September 2013

Type Python Script
Download
Author(s) Gianluca Tomasello
License CC BY-NC-SA


Introduction

This script detects waters molecules within a specified distance from the ligand.
Detected water molecules are shown as spheres.
Distances between water molecules and O or N atoms of ligand (potential H-bonds) are shown by dotted lines.
An output file containing a list of distance between waters and ligand atoms and the number of interactions is written in the main PyMol folder.


Usage

waters [ligand name, distance]


Required Arguments

  • ligand name = the ligand residue name
  • distance = max distance in Angstroms


Examples

example #1 on PDB structure (1C0L)

PyMOL>waters FAD, 2.8

Output in GUI of PyMol:

Total number of water molecules at 2.8 A from ligand FAD: 3 Number of water molecules that interact with ligand: 3 Number of interactions between water molecules and ligand: 4

output file: waters.txt

HOH residue 2002 -- and -- ['FAD', '1363', 'O1P'] ---> 2.611289 A HOH residue 2002 -- and -- ['FAD', '1363', 'O5B'] ---> 3.592691 A HOH residue 2008 -- and -- ['FAD', '1363', 'O1A'] ---> 2.678604 A HOH residue 2009 -- and -- ['FAD', '1363', 'O2P'] ---> 2.643039 A


Total number of water molecules at 2.8 A from ligand FAD: 3 Number of water molecules that interact with ligand: 3 Number of interactions between water molecules and ligand: 4

example #1


The Code

Copy the following text and save it as waters.py

# -*- coding: cp1252 -*-
"""
This script detects waters molecules within a specified distance from the ligand.
Water molecules are shown.
Distance between water molecules and O or N atoms of ligand are shown.

Author: Gianluca Tomasello, Gianluca Molla
University of Insubria, Varese, Italy
09/02/2013
gianluca.molla@uninsubria.it

Usage
waters, [ligand name, distance]

Parameters

ligand : the ligand residue name 

distance : a float number that specify the maximum distance from the ligand to consider the water molecule
           
Output
-A file is produced containing a list of distance between waters and ligand atoms and the number of interactions
-A graphic output show the water molecules interacting whith the ligand atoms by showing the distances between them
"""

from pymol import cmd,stored
#define function: waters
def waters(ligand, distance):
    stored.HOH = [] 
    cmd.set('label_color','white') 
    cmd.delete ("sele")
    cmd.hide ("everything")
    cmd.show_as ("sticks", "resn %s" % ligand)
    #iterate all water molecules nearby the ligand
    cmd.iterate('resn %s around %s and resn HOH' % (ligand,distance),'stored.HOH.append(resi)') 
    f = open("waters.txt","a")
    count=0
    count_int=0
    
    for i in range(0,len(stored.HOH)):        
        cmd.distance('dist_HOH_FAD', 'resi ' + stored.HOH[i], '(resn %s and n. O*+N*) w. 3.6 of resi %s'% (ligand, stored.HOH[i]))
        stored.name = []
        #iterate all ligand atoms within a predetermined distance from the water molecule
        cmd.iterate('(resn %s and n. O*+N*) w. 3.6 of resi %s'% (ligand, stored.HOH[i]),'stored.name.append([resn,resi,name])') 

        if stored.name:           
            count = count+1
            count_int = count_int+len(stored.name)

        for j in range(0,len(stored.name)):            
            cmd.select('base', 'resi ' + stored.HOH[i])
            cmd.select('var','resn '+ligand+ ' and n. ' + stored.name[j][2]) 
            #calculate the distance between a specific atom and the water molecule
            dist = cmd.get_distance('base','var')            
            f.write('HOH residue %s -- and -- %s  --->  %f A\n'%(stored.HOH[i],stored.name[j], dist))  

    cmd.select ("waters","resn %s around %s and resn HOH" % (ligand,distance))
    cmd.show_as ("spheres", "waters")
    cmd.zoom ("visible")
    num_atm = cmd.count_atoms ("waters")
    print ("Total number of water molecules at %s A from ligand %s: %s \n" % (distance,ligand,num_atm))
    print ("Number of water molecules that interact with ligand: %d\n" % (count))
    print ("Number of interactions between water molecules and ligand: %d\n" % count_int)
    f.write('-------------------------------------------------------------\n')
    f.write("Total number of water molecules at %s A from ligand %s: %s \n" % (distance,ligand,num_atm))
    f.write("Number of water molecules that interact with ligand: %d\n" % count)
    f.write("Number of interactions between water molecules and ligand: %d\n\n\n\n" % count_int)
    f.close()
    cmd.delete ("waters")
    
cmd.extend("waters",waters)