1
2
3
4
5
6
7
8
9
10
11 from rdkit import Geometry
12 from rdkit import Chem
13 from rdkit.Chem import ChemicalFeatures
14
16 weight=0.0
17 featDirs = None
21
23 """
24
25 >>> sfeat = ChemicalFeatures.FreeChemicalFeature('Aromatic','Foo',Geometry.Point3D(0,0,0))
26 >>> fmp = FeatMapPoint()
27 >>> fmp.initFromFeat(sfeat)
28 >>> fmp.GetFamily()==sfeat.GetFamily()
29 True
30 >>> fmp.GetType()==sfeat.GetType()
31 True
32 >>> list(fmp.GetPos())
33 [0.0, 0.0, 0.0]
34 >>> fmp.featDirs == []
35 True
36
37 >>> sfeat.featDirs = [Geometry.Point3D(1.0,0,0)]
38 >>> fmp.initFromFeat(sfeat)
39 >>> len(fmp.featDirs)
40 1
41
42 """
43 self.SetFamily(feat.GetFamily())
44 self.SetType(feat.GetType())
45 self.SetPos(feat.GetPos())
46 if hasattr(feat,'featDirs'):
47 self.featDirs = feat.featDirs[:]
48
49
51 """
52
53 >>> sfeat = ChemicalFeatures.FreeChemicalFeature('Aromatic','Foo',Geometry.Point3D(0,0,0))
54 >>> fmp = FeatMapPoint()
55 >>> fmp.initFromFeat(sfeat)
56 >>> fmp.GetDist2(sfeat)
57 0.0
58 >>> sfeat.SetPos(Geometry.Point3D(2,0,0))
59 >>> fmp.GetDist2(sfeat)
60 4.0
61 """
62 return (self.GetPos()-other.GetPos()).LengthSq()
63
65 """
66
67 >>> sfeat = ChemicalFeatures.FreeChemicalFeature('Aromatic','Foo',Geometry.Point3D(0,0,0))
68 >>> fmp = FeatMapPoint()
69 >>> fmp.initFromFeat(sfeat)
70 >>> fmp.GetDirMatch(sfeat)
71 1.0
72
73 >>> sfeat.featDirs=[Geometry.Point3D(0,0,1),Geometry.Point3D(0,0,-1)]
74 >>> fmp.featDirs=[Geometry.Point3D(0,0,1),Geometry.Point3D(1,0,0)]
75 >>> fmp.GetDirMatch(sfeat)
76 1.0
77 >>> fmp.GetDirMatch(sfeat,useBest=True)
78 1.0
79 >>> fmp.GetDirMatch(sfeat,useBest=False)
80 0.0
81
82 >>> sfeat.featDirs=[Geometry.Point3D(0,0,1)]
83 >>> fmp.GetDirMatch(sfeat,useBest=False)
84 0.5
85
86 >>> sfeat.featDirs=[Geometry.Point3D(0,0,1)]
87 >>> fmp.featDirs=[Geometry.Point3D(0,0,-1)]
88 >>> fmp.GetDirMatch(sfeat)
89 -1.0
90 >>> fmp.GetDirMatch(sfeat,useBest=False)
91 -1.0
92
93
94 """
95 if not self.featDirs or not other.featDirs:
96 return 1.0
97
98 if not useBest:
99 accum = 0.0
100 else:
101 accum = -100000.0
102 for sDir in self.featDirs:
103 for oDir in other.featDirs:
104 d = sDir.DotProduct(oDir)
105 if useBest:
106 if d>accum:
107 accum=d
108 else:
109 accum += d
110
111 if not useBest:
112 accum /= len(self.featDirs)*len(other.featDirs)
113
114 return accum
115
116
117
118
119
121 import doctest,sys
122 return doctest.testmod(sys.modules["__main__"])
123
124 if __name__ == '__main__':
125 import sys
126 failed,tried = _test()
127 sys.exit(failed)
128