1
2
3
4
5 from __future__ import print_function
6
7 import copy
8 import time
9
10 from rdkit import Chem, Geometry
11 from rdkit.Chem import AllChem
12 from rdkit.Chem.Subshape import BuilderUtils
13 from rdkit.Chem.Subshape import SubshapeObjects
14 from rdkit.six.moves import cPickle
15
16
21
22
24 gridDims = (20, 15, 10)
25 gridSpacing = 0.5
26 winRad = 3.0
27 nbrCount = 7
28 terminalPtRadScale = 0.75
29 fraction = 0.25
30 stepSize = 1.0
31 featFactory = None
32
44
54
57
59 if conf and skelFromConf:
60 pts = BuilderUtils.FindTerminalPtsFromConformer(conf, self.winRad, self.nbrCount)
61 else:
62 pts = BuilderUtils.FindTerminalPtsFromShape(shape, self.winRad, self.fraction)
63 pts = BuilderUtils.ClusterTerminalPts(pts, self.winRad, self.terminalPtRadScale)
64 BuilderUtils.ExpandTerminalPts(shape, pts, self.winRad)
65 if len(pts) < 3:
66 raise ValueError('only found %d terminals, need at least 3' % len(pts))
67
68 if not terminalPtsOnly:
69 pts = BuilderUtils.AppendSkeletonPoints(shape.grid, pts, self.winRad, self.stepSize)
70 for pt in pts:
71 BuilderUtils.CalculateDirectionsAtPoint(pt, shape.grid, self.winRad)
72 if conf and self.featFactory:
73 BuilderUtils.AssignMolFeatsToPoints(pts, conf.GetOwningMol(), self.featFactory, self.winRad)
74 shape.skelPts = pts
75
87
88
89 if __name__ == '__main__':
90 from rdkit.Chem.PyMol import MolViewer
91 from rdkit.six.moves import cPickle
92 import tempfile
93
94
95
96 if 1:
97 cmpd = Chem.MolFromSmiles('C1=CC=C1C#CC1=CC=C1')
98 cmpd = Chem.AddHs(cmpd)
99 AllChem.EmbedMolecule(cmpd)
100 AllChem.UFFOptimizeMolecule(cmpd)
101 AllChem.CanonicalizeMol(cmpd)
102
103 else:
104 cmpd = Chem.MolFromMolFile('testmol.mol')
105 builder = SubshapeBuilder()
106 if 1:
107 shape = builder.GenerateSubshapeShape(cmpd)
108 v = MolViewer()
109 if 1:
110 tmpFile = tempfile.mktemp('.grd')
111 v.server.deleteAll()
112 Geometry.WriteGridToFile(shape.grid, tmpFile)
113 time.sleep(1)
114 v.ShowMol(cmpd, name='testMol', showOnly=True)
115 v.server.loadSurface(tmpFile, 'testGrid', '', 2.5)
116 v.server.resetCGO('*')
117
118 with open('subshape.pkl', 'w+') as f:
119 cPickle.dump(shape, f)
120 for i, pt in enumerate(shape.skelPts):
121 v.server.sphere(tuple(pt.location), .5, (1, 0, 1), 'Pt-%d' % i)
122 if not hasattr(pt, 'shapeDirs'):
123 continue
124 momBeg = pt.location - pt.shapeDirs[0]
125 momEnd = pt.location + pt.shapeDirs[0]
126 v.server.cylinder(tuple(momBeg), tuple(momEnd), .1, (1, 0, 1), 'v-%d' % i)
127