Mercurial > repos > marpiech > norwich_tools
annotate tools/rdock/bin/sdtether @ 0:bc03dbb6eb37 draft
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
author | marpiech |
---|---|
date | Mon, 29 Aug 2016 03:38:13 -0400 |
parents | |
children |
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 # Substitute for rbtether of rDock. Will align input molecules to a reference fragment defined by a smarts string, |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
4 # it will add a TETHERED ATOM property field to the output SDF that is correctly understood by rDock |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
5 # rDock will restrain the matching atom positions to the reference molecule coordinates. |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
6 # |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
7 # Initially implemented with a conformational search algorithm to better match target coordinates. |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
8 # But had problems with OBabel FF generating non-sense conformers. So in this version the conformer search is commented out. |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
9 # Now if the input molecule do not have a good conformation, might not align well with the target. This effect will be |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
10 # dimished or even vanish if the SMARTS string is defined for a rigid region (like a ring). |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
11 # I'm still trying to incorporate somehow this conformational search. |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
12 # |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
13 # Script distributed under GNU LGPL 3.0 along rDock software. |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
14 # |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
15 # Author: Daniel Alvarez-Garcia |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
16 # Date: 08-11-2013 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
17 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
18 import math |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
19 import pybel |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
20 import numpy as npy |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
21 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
22 def superpose3D(ref, target, weights=None,refmask=None,targetmask=None,returnRotMat=False): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
23 """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
|
24 definition : superpose3D(ref, target, weights,refmask,targetmask) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
25 @parameter 1 : ref - xyz coordinates of the reference structure (the ligand for instance) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
26 @type 1 : float64 numpy array (nx3) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
27 --- |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
28 @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
|
29 @type 2 : float 64 numpy array (nx3) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
30 --- |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
31 @parameter 3: weights - numpy array of atom weights (usuallly between 0 and 1) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
32 @type 3 : float 64 numpy array (n) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
33 @parameter 4: mask - a numpy boolean mask for designating atoms to include |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
34 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
|
35 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
|
36 """ |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
37 if weights == None : |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
38 weights=1.0 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
39 if refmask == None : |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
40 refmask=npy.ones(len(ref),"bool") |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
41 if targetmask == None : |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
42 targetmask=npy.ones(len(target),"bool") |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
43 #first get the centroid of both states |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
44 ref_centroid = npy.mean(ref[refmask]*weights,axis=0) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
45 #print ref_centroid |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
46 refCenteredCoords=ref-ref_centroid |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
47 #print refCenteredCoords |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
48 target_centroid=npy.mean(target[targetmask]*weights,axis=0) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
49 targetCenteredCoords=target-target_centroid |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
50 #print targetCenteredCoords |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
51 #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
|
52 # Initial residual, see Kabsch. |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
53 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
|
54 reftmp=npy.copy(refCenteredCoords[refmask]) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
55 targettmp=npy.copy(targetCenteredCoords[targetmask]) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
56 #print refCenteredCoords[refmask] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
57 #single value decomposition of the dotProduct of both position vectors |
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* weights) |
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 try: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
63 dotProd = npy.dot( npy.transpose(reftmp), targettmp) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
64 V, S, Wt = npy.linalg.svd(dotProd ) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
65 except Exception: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
66 print >> sys.stderr,"Couldn't perform the Single Value Decomposition, skipping alignment" |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
67 return ref, 0 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
68 # we already have our solution, in the results from SVD. |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
69 # we just need to check for reflections and then produce |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
70 # the rotation. V and Wt are orthonormal, so their det's |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
71 # are +/-1. |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
72 reflect = float(str(float(npy.linalg.det(V) * npy.linalg.det(Wt)))) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
73 if reflect == -1.0: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
74 S[-1] = -S[-1] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
75 V[:,-1] = -V[:,-1] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
76 rmsd = E0 - (2.0 * sum(S)) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
77 rmsd = npy.sqrt(abs(rmsd / len(ref[refmask]))) #get the rmsd |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
78 #U is simply V*Wt |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
79 U = npy.dot(V, Wt) #get the rotation matrix |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
80 # rotate and translate the molecule |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
81 new_coords = npy.dot((refCenteredCoords), U)+ target_centroid #translate & rotate |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
82 #new_coords=(refCenteredCoords + target_centroid) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
83 #print U |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
84 if returnRotMat : |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
85 return U, ref_centroid, target_centroid, rmsd |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
86 return new_coords,rmsd |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
87 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
88 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
89 def squared_distance(coordsA, coordsB): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
90 """Find the squared distance between two 3-tuples""" |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
91 sqrdist = sum( (a-b)**2 for a, b in zip(coordsA, coordsB) ) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
92 return sqrdist |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
93 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
94 def rmsd(allcoordsA, allcoordsB): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
95 """Find the RMSD between two lists of 3-tuples""" |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
96 deviation = sum(squared_distance(atomA, atomB) for |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
97 (atomA, atomB) in zip(allcoordsA, allcoordsB)) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
98 return math.sqrt(deviation / float(len(allcoordsA))) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
99 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
100 def mapToCrystal(xtal, pose): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
101 """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
|
102 this will mess up the rmsd calculation with OpenBabel""" |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
103 query = pybel.ob.CompileMoleculeQuery(xtal.OBMol) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
104 mapper=pybel.ob.OBIsomorphismMapper.GetInstance(query) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
105 mappingpose = pybel.ob.vvpairUIntUInt() |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
106 exit=mapper.MapUnique(pose.OBMol,mappingpose) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
107 return mappingpose[0] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
108 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
109 def takeCoords(obmol): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
110 """Take coordinates of an OBMol as a npy array""" |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
111 return npy.array([atom.coords for atom in obmol]) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
112 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
113 def updateCoords(obmol, newcoords): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
114 "Update OBMol coordinates. newcoords is a numpy array" |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
115 for i,atom in enumerate(obmol): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
116 atom.OBAtom.SetVector(*newcoords[i]) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
117 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
118 def prepareAtomString(idlist): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
119 s = "" |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
120 n = len(idlist) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
121 for i, id in enumerate(idlist): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
122 s += "%i"%id |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
123 if (i+1) == n: s+="\n" |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
124 elif (i+1)%35 == 0: s+=",\n" |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
125 else: s+="," |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
126 return s |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
127 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
128 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
129 if __name__ == "__main__": |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
130 import sys |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
131 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
132 if len(sys.argv) != 5: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
133 sys.exit("USAGE: %s reference.sdf input.sdf output.sdf 'SMARTS'"%sys.argv[0]) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
134 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
135 refsdf = sys.argv[1] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
136 molsdf = sys.argv[2] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
137 outsdf = sys.argv[3] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
138 smarts = pybel.Smarts(sys.argv[4]) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
139 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
140 # Read reference pose and get atom list matching smarts query |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
141 # if more than 1 match, take the first one |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
142 ref = next(pybel.readfile("sdf", refsdf)) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
143 refMatchIds = smarts.findall(ref) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
144 numRefMatchs = len(refMatchIds) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
145 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
146 if not numRefMatchs: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
147 sys.exit("No match found in the reference structure and the SMARTS string given. Please check it.") |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
148 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
149 if numRefMatchs > 1: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
150 print "More than one match in the reference molecule for the SMARTS string given. Will tether each input molecule all possible ways." |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
151 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
152 refIndxPerMatch = [npy.array(rmi) - 1 for rmi in refMatchIds] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
153 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
154 # Take coordinates for the reference matched atoms |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
155 refCoords = takeCoords(ref) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
156 refMatchCoords = [npy.take(refCoords, refIndx, axis=0) for refIndx in refIndxPerMatch] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
157 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
158 # Do the same for molecule in molsdf |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
159 out=pybel.Outputfile('sdf', outsdf, overwrite=True) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
160 molSupp = pybel.readfile("sdf", molsdf) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
161 ff = pybel.ob.OBForceField_FindForceField('MMFF94') |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
162 for i,mol in enumerate(molSupp): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
163 print "## Molecule %i"%(i+1), |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
164 mol.OBMol.DeleteNonPolarHydrogens() |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
165 molMatchAllIds = smarts.findall(mol) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
166 numMatchs = len(molMatchAllIds) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
167 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
168 if numMatchs == 0: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
169 print "No_Match", |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
170 continue |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
171 elif numMatchs ==1: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
172 print "Match", |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
173 elif numMatchs > 1: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
174 print "Multiple_Match SMART Matches for this molecule (%d)"%numMatchs, |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
175 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
176 # If more than one match, write an output of the same molecule for each match |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
177 # Start a default bestcoord and rmsd for later looping for each pose |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
178 bestCoordPerMatch = [[0 for i in range(numMatchs)] for i in range(numRefMatchs)] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
179 bestRMSPerMatch = [[999 for i in range(numMatchs)] for i in range(numRefMatchs)] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
180 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
181 # Will do a randomrotorsearch to find conformer with the lower rmsd when superposing |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
182 # At least 20 when possible |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
183 #ff.Setup(mol.OBMol) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
184 #numats = mol.OBMol.NumAtoms() |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
185 #numrot = mol.OBMol.NumRotors() |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
186 #print "Atoms: %i, Rotors: %i"%(numats, numrot) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
187 #geomopt = 300 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
188 #genconf = 100 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
189 # increase iterations if bigger molecule or bigger number of rotatable bonds |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
190 # for allowing better sampling |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
191 #if numats > 40 and numrot > 5: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
192 # geomopt = 300 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
193 # genconf = 150 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
194 #if numats > 55 and numrot > 7: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
195 # genconf = 100 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
196 # geomopt = 500 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
197 #print "\tDoing conformational search with WeightedRotorSearch (%i, %i)..."%(genconf, geomopt), |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
198 #ff.SteepestDescent(500, 1.0e-4) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
199 #ff.WeightedRotorSearch(genconf,geomopt) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
200 #ff.ConjugateGradients(500, 1.0e-6) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
201 #ff.GetConformers(mol.OBMol) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
202 #numconf = mol.OBMol.NumConformers() |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
203 numconf = 1 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
204 #print "%i conformers generated"%numconf |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
205 if numconf > 1: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
206 # Doing conf search |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
207 #for i in range(numconf): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
208 # mol.OBMol.SetConformer(i) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
209 # confCoords = takeCoords(mol) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
210 # print 'coord:',confCoords[0,:] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
211 # |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
212 # for imatch, molMatchIds in enumerate(molMatchAllIds): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
213 # molMatchIndx = npy.array(molMatchIds) - 1 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
214 # confMatchCoords = npy.take(confCoords, molMatchIndx, axis=0) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
215 # |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
216 # # Align: Get rotation matrix between the two sets of coords |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
217 # # Apply rotation to the whole target molecule |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
218 # rotMat, targetCentroid, refCentroid, rmsd = superpose3D(confMatchCoords, refMatchCoords, returnRotMat=True) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
219 # if rmsd < bestRMSPerMatch[imatch]: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
220 # newcoords = npy.dot((confCoords - targetCentroid), rotMat) + refCentroid |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
221 # bestRMSPerMatch[imatch] = rmsd |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
222 # bestCoordPerMatch[imatch] = newcoords |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
223 # #if bestrms < 0.01: break |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
224 pass |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
225 else: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
226 molCoords = takeCoords(mol) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
227 for imatch, molMatchIds in enumerate(molMatchAllIds): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
228 # loop in each matching way for the input molecule |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
229 molMatchIndx = npy.array(molMatchIds) - 1 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
230 molMatchCoords = npy.take(molCoords, molMatchIndx, axis=0) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
231 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
232 # Loop over the reference matches |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
233 # Align: Get rotation matrix between the two sets of coords |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
234 # Apply rotation to the whole target molecule |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
235 for ir, refMatchCoord in enumerate(refMatchCoords): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
236 rotMat, targetCentroid, refCentroid, rmsd = superpose3D(molMatchCoords, refMatchCoord, returnRotMat=True) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
237 if rmsd < bestRMSPerMatch[ir][imatch]: |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
238 newcoords = npy.dot((molCoords - targetCentroid), rotMat) + refCentroid |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
239 bestRMSPerMatch[ir][imatch] = rmsd |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
240 bestCoordPerMatch[ir][imatch] = newcoords |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
241 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
242 # Finally update molecule coordinates with the best matching coordinates found |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
243 # change molecule coordinates, set TETHERED ATOMS property and save |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
244 for imatch in range(numMatchs): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
245 for irefmatch in range(numRefMatchs): |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
246 bestCoord = bestCoordPerMatch[irefmatch][imatch] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
247 bestRMS = bestRMSPerMatch[irefmatch][imatch] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
248 print "\tBest RMSD reached (match %d, refmatch %d): %s"%(imatch, irefmatch, bestRMS) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
249 molMatchID = molMatchAllIds[imatch] |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
250 updateCoords(mol, bestCoord) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
251 newData = pybel.ob.OBPairData() |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
252 newData.SetAttribute("TETHERED ATOMS") |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
253 newData.SetValue(prepareAtomString(molMatchID)) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
254 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
255 mol.OBMol.DeleteData("TETHERED ATOMS") # Remove Previous DATA |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
256 mol.OBMol.CloneData(newData) # Add new data |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
257 out.write(mol) |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
258 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
259 out.close() |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
260 |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
261 print "DONE" |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
262 sys.stdout.close() |
bc03dbb6eb37
planemo upload commit 781926e52355f7805db8d9a4ccafeff397b19aa4-dirty
marpiech
parents:
diff
changeset
|
263 sys.stderr.close() |