annotate tools/rdock/bin/sdrmsd @ 0:bc03dbb6eb37 draft

planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
author marpiech
date Mon, 29 Aug 2016 03:38:13 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
1 #! /usr/bin/env python
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
2 #
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
3 # Calculate SMART RMSD with or without molecular superposition (FIT or NOFIT)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
4 # Script distributed under GNU LGPL 3.0 along rDock software.
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
5 #
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
6 # This algorithm takes into account molecular automorphism. That is, it identifies
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
7 # molecules which are the same but might have atom orders changed and still be able to
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
8 # match the pairs and correctly calculate the RMSD.
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
9 #
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
10 # Author: Daniel Alvarez-Garcia
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
11 # Date: 08-11-2013
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
12
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
13 import math
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
14 import pybel
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
15 import numpy as npy
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
16 import optparse
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
17
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
18 def superpose3D(ref, target, weights=None,refmask=None,targetmask=None,returnRotMat=False):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
19 """superpose3D performs 3d superposition using a weighted Kabsch algorithm : http://dx.doi.org/10.1107%2FS0567739476001873 & doi: 10.1529/biophysj.105.066654
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
20 definition : superpose3D(ref, target, weights,refmask,targetmask)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
21 @parameter 1 : ref - xyz coordinates of the reference structure (the ligand for instance)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
22 @type 1 : float64 numpy array (nx3)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
23 ---
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
24 @parameter 2 : target - theoretical target positions to which we should move (does not need to be physically relevant.
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
25 @type 2 : float 64 numpy array (nx3)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
26 ---
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
27 @parameter 3: weights - numpy array of atom weights (usuallly between 0 and 1)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
28 @type 3 : float 64 numpy array (n)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
29 @parameter 4: mask - a numpy boolean mask for designating atoms to include
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
30 Note ref and target positions must have the same dimensions -> n*3 numpy arrays where n is the number of points (or atoms)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
31 Returns a set of new coordinates, aligned to the target state as well as the rmsd
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
32 """
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
33 if weights == None :
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
34 weights=1.0
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
35 if refmask == None :
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
36 refmask=npy.ones(len(ref),"bool")
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
37 if targetmask == None :
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
38 targetmask=npy.ones(len(target),"bool")
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
39 #first get the centroid of both states
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
40 ref_centroid = npy.mean(ref[refmask]*weights,axis=0)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
41 #print ref_centroid
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
42 refCenteredCoords=ref-ref_centroid
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
43 #print refCenteredCoords
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
44 target_centroid=npy.mean(target[targetmask]*weights,axis=0)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
45 targetCenteredCoords=target-target_centroid
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
46 #print targetCenteredCoords
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
47 #the following steps come from : http://www.pymolwiki.org/index.php/OptAlign#The_Code and http://en.wikipedia.org/wiki/Kabsch_algorithm
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
48 # Initial residual, see Kabsch.
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
49 E0 = npy.sum( npy.sum(refCenteredCoords[refmask] * refCenteredCoords[refmask]*weights,axis=0),axis=0) + npy.sum( npy.sum(targetCenteredCoords[targetmask] * targetCenteredCoords[targetmask]*weights,axis=0),axis=0)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
50 reftmp=npy.copy(refCenteredCoords[refmask])
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
51 targettmp=npy.copy(targetCenteredCoords[targetmask])
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
52 #print refCenteredCoords[refmask]
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
53 #single value decomposition of the dotProduct of both position vectors
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
54 try:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
55 dotProd = npy.dot( npy.transpose(reftmp), targettmp* weights)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
56 V, S, Wt = npy.linalg.svd(dotProd )
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
57 except Exception:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
58 try:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
59 dotProd = npy.dot( npy.transpose(reftmp), targettmp)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
60 V, S, Wt = npy.linalg.svd(dotProd )
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
61 except Exception:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
62 print >> sys.stderr,"Couldn't perform the Single Value Decomposition, skipping alignment"
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
63 return ref, 0
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
64 # we already have our solution, in the results from SVD.
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
65 # we just need to check for reflections and then produce
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
66 # the rotation. V and Wt are orthonormal, so their det's
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
67 # are +/-1.
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
68 reflect = float(str(float(npy.linalg.det(V) * npy.linalg.det(Wt))))
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
69 if reflect == -1.0:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
70 S[-1] = -S[-1]
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
71 V[:,-1] = -V[:,-1]
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
72 rmsd = E0 - (2.0 * sum(S))
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
73 rmsd = npy.sqrt(abs(rmsd / len(ref[refmask]))) #get the rmsd
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
74 #U is simply V*Wt
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
75 U = npy.dot(V, Wt) #get the rotation matrix
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
76 # rotate and translate the molecule
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
77 new_coords = npy.dot((refCenteredCoords), U)+ target_centroid #translate & rotate
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
78 #new_coords=(refCenteredCoords + target_centroid)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
79 #print U
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
80 if returnRotMat :
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
81 return new_coords,rmsd, U
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
82 return new_coords,rmsd
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
83
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
84
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
85 def squared_distance(coordsA, coordsB):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
86 """Find the squared distance between two 3-tuples"""
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
87 sqrdist = sum( (a-b)**2 for a, b in zip(coordsA, coordsB) )
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
88 return sqrdist
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
89
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
90 def rmsd(allcoordsA, allcoordsB):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
91 """Find the RMSD between two lists of 3-tuples"""
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
92 deviation = sum(squared_distance(atomA, atomB) for
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
93 (atomA, atomB) in zip(allcoordsA, allcoordsB))
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
94 return math.sqrt(deviation / float(len(allcoordsA)))
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
95
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
96 def mapToCrystal(xtal, pose):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
97 """Some docking programs might alter the order of the atoms in the output (like Autodock Vina does...)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
98 this will mess up the rmsd calculation with OpenBabel"""
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
99 query = pybel.ob.CompileMoleculeQuery(xtal.OBMol)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
100 mapper=pybel.ob.OBIsomorphismMapper.GetInstance(query)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
101 mappingpose = pybel.ob.vvpairUIntUInt()
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
102 exit=mapper.MapUnique(pose.OBMol,mappingpose)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
103 return mappingpose[0]
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
104
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
105 def parseArguments():
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
106 optparse.OptionParser.format_epilog = lambda self, formatter: self.epilog
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
107 epilog = """Args:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
108 reference.sdf SDF file with the reference molecule.
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
109 input.sdf SDF file with the molecules to be compared to reference.\n"""
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
110 parser = optparse.OptionParser("usage: %prog [options] reference.sdf input.sdf", epilog=epilog)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
111 parser.add_option("-f", "--fit",dest="fit", action="store_true", default=False,
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
112 help="Superpose molecules before RMSD calculation")
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
113 parser.add_option("--threshold","-t",dest="threshold", action="store", nargs=1,
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
114 help="Discard poses with RMSD < THRESHOLD with respect previous poses which where not rejected based on same principle. A Population SDField will be added to output SD with the population number.", type=float)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
115 parser.add_option("-o","--out", dest="outfilename", metavar="FILE", default=False,
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
116 help="If declared, write an output SDF file with the input molecules with a new sdfield <RMSD>. If molecule was fitted, the fitted molecule coordinates will be saved.")
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
117 (options, args) = parser.parse_args()
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
118
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
119 #Check we have two arguments
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
120 if len(args) < 2:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
121 parser.error("Incorrect number of arguments. Use -h or --help options to print help.")
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
122
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
123 return options, args
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
124
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
125 def updateCoords(obmol, newcoords):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
126 "Update OBMol coordinates. newcoords is a numpy array"
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
127 for i,atom in enumerate(obmol):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
128 atom.OBAtom.SetVector(*newcoords[i])
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
129
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
130 def getAutomorphRMSD(target, molec, fit=False):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
131 """
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
132 Use Automorphism to reorder target coordinates to match ref coordinates atom order
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
133 for correct RMSD comparison. Only the lowest RMSD will be returned.
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
134
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
135 Returns:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
136 If fit=False: bestRMSD (float) RMSD of the best matching mapping.
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
137 If fit=True: (bestRMSD, molecCoordinates) (float, npy.array) RMSD of best match and its molecule fitted coordinates.
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
138 """
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
139 mappings = pybel.ob.vvpairUIntUInt()
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
140 bitvec = pybel.ob.OBBitVec()
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
141 lookup = []
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
142 for i, atom in enumerate(target):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
143 lookup.append(i)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
144 success = pybel.ob.FindAutomorphisms(target.OBMol, mappings)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
145 targetcoords = [atom.coords for atom in target]
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
146 mappose = npy.array(mapToCrystal(target, molec))
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
147 mappose = mappose[npy.argsort(mappose[:,0])][:,1]
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
148 posecoords = npy.array([atom.coords for atom in molec])[mappose]
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
149 resultrmsd = 999999999999
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
150 for mapping in mappings:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
151 automorph_coords = [None] * len(targetcoords)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
152 for x, y in mapping:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
153 automorph_coords[lookup.index(x)] = targetcoords[lookup.index(y)]
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
154 mapping_rmsd = rmsd(posecoords, automorph_coords)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
155 if mapping_rmsd < resultrmsd:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
156 resultrmsd = mapping_rmsd
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
157 fitted_result = False
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
158 if fit:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
159 fitted_pose, fitted_rmsd = superpose3D(npy.array(automorph_coords), npy.array(posecoords))
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
160 if fitted_rmsd < resultrmsd:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
161 resultrmsd = fitted_rmsd
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
162 fitted_result = fitted_pose
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
163
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
164 if fit:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
165 return (resultrmsd, fitted_pose)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
166 else:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
167 return resultrmsd
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
168
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
169 def saveMolecWithRMSD(outsdf, molec, rmsd, population=False):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
170 newData = pybel.ob.OBPairData()
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
171 newData.SetAttribute("RMSD")
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
172 newData.SetValue('%.3f'%rmsd)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
173
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
174 if population:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
175 popData = pybel.ob.OBPairData()
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
176 popData.SetAttribute("Population")
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
177 popData.SetValue('%i'%population)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
178 molec.OBMol.CloneData(popData)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
179
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
180 molec.OBMol.CloneData(newData) # Add new data
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
181 outsdf.write(molec)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
182
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
183 if __name__ == "__main__":
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
184 import sys, os
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
185
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
186 (opts, args) = parseArguments()
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
187
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
188 xtal = args[0]
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
189 poses = args[1]
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
190
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
191 if not os.path.exists(xtal) or not os.path.exists(poses):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
192 sys.exit("Input files not found. Please check the path given is correct.")
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
193
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
194 fit = opts.fit
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
195 outfname = opts.outfilename
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
196 threshold = opts.threshold
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
197
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
198 # Read crystal pose
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
199 crystal = next(pybel.readfile("sdf", xtal))
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
200 crystal.removeh()
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
201 crystalnumatoms = len(crystal.atoms)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
202
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
203 #If outfname is defined, prepare an output SDF sink to write molecules
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
204 if outfname:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
205 outsdf = pybel.Outputfile('sdf', outfname, overwrite=True)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
206
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
207 # Find the RMSD between the crystal pose and each docked pose
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
208 dockedposes = pybel.readfile("sdf", poses)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
209 if fit: print "POSE\tRMSD_FIT"
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
210 else: print "POSE\tRMSD_NOFIT"
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
211 skipped = []
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
212 moleclist = {} # Save all poses with their dockid
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
213 population = {} # Poses to be written
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
214 outlist = {}
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
215 for docki, dockedpose in enumerate(dockedposes):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
216 dockedpose.removeh()
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
217 natoms = len(dockedpose.atoms)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
218 if natoms != crystalnumatoms:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
219 skipped.append(docki+1)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
220 continue
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
221 if fit:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
222 resultrmsd, fitted_result = getAutomorphRMSD(crystal, dockedpose, fit=True)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
223 updateCoords(dockedpose, fitted_result)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
224 else:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
225 resultrmsd = getAutomorphRMSD(crystal, dockedpose, fit=False)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
226
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
227 if threshold:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
228 # Calculate RMSD between all previous poses
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
229 # Discard if rmsd < FILTER threshold
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
230 if moleclist:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
231 match = None
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
232 bestmatchrmsd = 999999
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
233 for did,prevmol in moleclist.iteritems():
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
234 tmprmsd = getAutomorphRMSD(prevmol, dockedpose)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
235 if tmprmsd < threshold:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
236 if tmprmsd < bestmatchrmsd:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
237 bestmatchrmsd = tmprmsd
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
238 match = did
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
239
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
240 if match != None:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
241 # Do not write this one
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
242 # sum one up to the matching previous molecule id
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
243 print >> sys.stderr, "Pose %i matches pose %i with %.3f RMSD"%(docki+1, match+1, bestmatchrmsd)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
244 population[match] += 1
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
245 else:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
246 # There's no match. Print info for this one and write to outsdf if needed
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
247 # Save this one!
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
248 if outfname: outlist[docki] = (dockedpose, resultrmsd)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
249 print "%d\t%.2f"%((docki+1),resultrmsd)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
250 moleclist[docki] = dockedpose
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
251 population[docki] = 1
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
252 else:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
253 # First molecule in list. Append for sure
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
254 moleclist[docki] = dockedpose
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
255 population[docki] = 1
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
256 if outfname: outlist[docki] = (dockedpose, resultrmsd)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
257 else:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
258 # Just write best rmsd found and the molecule to outsdf if demanded
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
259 if outfname: saveMolecWithRMSD(outsdf, dockedpose, resultrmsd)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
260 print "%d\t%.2f"%((docki+1),resultrmsd)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
261
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
262 if outlist:
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
263 # Threshold applied and outlist need to be written
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
264 for docki in sorted(outlist.iterkeys()):
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
265 molrmsd = outlist[docki]
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
266 # Get number of matchs in thresholding operation
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
267 pop = population.get(docki)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
268 if not pop: pop = 1
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
269 # Save molecule
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
270 saveMolecWithRMSD(outsdf, molrmsd[0], molrmsd[1], pop)
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
271
bc03dbb6eb37 planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff changeset
272 if skipped: print >> sys.stderr, "SKIPPED input molecules due to number of atom missmatch: %s"%skipped