Package rdkit :: Package Chem :: Package FeatMaps :: Module FeatMapPoint
[hide private]
[frames] | no frames]

Source Code for Module rdkit.Chem.FeatMaps.FeatMapPoint

  1  # $Id$ 
  2  # 
  3  # Copyright (C) 2006 Greg Landrum 
  4  # 
  5  #   @@ All Rights Reserved @@ 
  6  #  This file is part of the RDKit. 
  7  #  The contents are covered by the terms of the BSD license 
  8  #  which is included in the file license.txt, found at the root 
  9  #  of the RDKit source tree. 
 10  # 
 11  from rdkit import Geometry 
 12  from rdkit import Chem 
 13  from rdkit.Chem import ChemicalFeatures 
 14   
15 -class FeatMapPoint(ChemicalFeatures.FreeChemicalFeature):
16 weight=0.0 17 featDirs = None
18 - def __init__(self,*args,**kwargs):
19 ChemicalFeatures.FreeChemicalFeature.__init__(self,*args,**kwargs) 20 self.featDirs=[]
21
22 - def initFromFeat(self,feat):
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
50 - def GetDist2(self,other):
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
64 - def GetDirMatch(self,other,useBest=True):
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 # doctest boilerplate 119 #
120 -def _test():
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