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