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.Chem import ChemicalFeatures 
 12   
 13   
14 -class FeatMapPoint(ChemicalFeatures.FreeChemicalFeature):
15 weight = 0.0 16 featDirs = None 17
18 - def __init__(self, *args, **kwargs):
19 ChemicalFeatures.FreeChemicalFeature.__init__(self, *args, **kwargs) 20 self.featDirs = []
21
22 - def initFromFeat(self, feat):
23 """ 24 >>> from rdkit import Geometry 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 - def GetDist2(self, other):
50 """ 51 >>> from rdkit import Geometry 52 >>> sfeat = ChemicalFeatures.FreeChemicalFeature('Aromatic','Foo',Geometry.Point3D(0,0,0)) 53 >>> fmp = FeatMapPoint() 54 >>> fmp.initFromFeat(sfeat) 55 >>> fmp.GetDist2(sfeat) 56 0.0 57 >>> sfeat.SetPos(Geometry.Point3D(2,0,0)) 58 >>> fmp.GetDist2(sfeat) 59 4.0 60 """ 61 return (self.GetPos() - other.GetPos()).LengthSq()
62
63 - def GetDirMatch(self, other, useBest=True):
64 """ 65 >>> from rdkit import Geometry 66 >>> sfeat = ChemicalFeatures.FreeChemicalFeature('Aromatic','Foo',Geometry.Point3D(0,0,0)) 67 >>> fmp = FeatMapPoint() 68 >>> fmp.initFromFeat(sfeat) 69 >>> fmp.GetDirMatch(sfeat) 70 1.0 71 72 >>> sfeat.featDirs=[Geometry.Point3D(0,0,1),Geometry.Point3D(0,0,-1)] 73 >>> fmp.featDirs=[Geometry.Point3D(0,0,1),Geometry.Point3D(1,0,0)] 74 >>> fmp.GetDirMatch(sfeat) 75 1.0 76 >>> fmp.GetDirMatch(sfeat,useBest=True) 77 1.0 78 >>> fmp.GetDirMatch(sfeat,useBest=False) 79 0.0 80 81 >>> sfeat.featDirs=[Geometry.Point3D(0,0,1)] 82 >>> fmp.GetDirMatch(sfeat,useBest=False) 83 0.5 84 85 >>> sfeat.featDirs=[Geometry.Point3D(0,0,1)] 86 >>> fmp.featDirs=[Geometry.Point3D(0,0,-1)] 87 >>> fmp.GetDirMatch(sfeat) 88 -1.0 89 >>> fmp.GetDirMatch(sfeat,useBest=False) 90 -1.0 91 92 93 """ 94 if not self.featDirs or not other.featDirs: 95 return 1.0 96 97 if not useBest: 98 accum = 0.0 99 else: 100 accum = -100000.0 101 for sDir in self.featDirs: 102 for oDir in other.featDirs: 103 d = sDir.DotProduct(oDir) 104 if useBest: 105 if d > accum: 106 accum = d 107 else: 108 accum += d 109 110 if not useBest: 111 accum /= len(self.featDirs) * len(other.featDirs) 112 113 return accum
114 115 116 # ------------------------------------ 117 # 118 # doctest boilerplate 119 #
120 -def _runDoctests(verbose=None): # pragma: nocover
121 import sys 122 import doctest 123 failed, _ = doctest.testmod(optionflags=doctest.ELLIPSIS, verbose=verbose) 124 sys.exit(failed) 125 126 127 if __name__ == '__main__': # pragma: nocover 128 _runDoctests() 129