Package Chem :: Package Pharm2D :: Module SigFactory
[hide private]
[frames] | no frames]

Source Code for Module Chem.Pharm2D.SigFactory

 1  # $Id: SigFactory.py 2 2006-05-06 22:54:39Z glandrum $ 
 2  # 
 3  # Copyright (C) 2003-2006 greg Landrum and Rational Discovery LLC 
 4  # 
 5  #   @@ All Rights Reserved  @@ 
 6  # 
 7  """ contains factory class for producing signatures 
 8   
 9   
10  """ 
11  from Chem.Pharm2D.Signature import Pharm2DSig as Signature 
12   
13 -class SigFactory(object):
14 """ 15 16 SigFactory's are used by creating one, setting the relevant 17 parameters, then calling the GetSignature() method each time a 18 signature is required. 19 20 """
21 - def __init__(self):
22 self._patts = None 23 self._lables = None 24 self._bins = None 25 self._minCnt = 2 26 self._maxCnt = 4 27 self._shortestPathsOnly = 1 28 self._includeBondOrder = 0 29 self._labels = None
30
31 - def SetPatterns(self,patts):
32 self._patts = patts[:]
33 - def SetPatternsFromSmarts(self,smarts):
34 import Chem 35 self._patts = [None]*len(smarts) 36 for i in range(len(smarts)): 37 p = Chem.MolFromSmarts(smarts[i]) 38 self._patts[i] = p
39 - def GetPatterns(self):
40 return self._patts
41 - def GetNumPatterns(self):
42 return len(self._patts)
43
44 - def SetLabels(self,labels):
45 self._labels = labels[:]
46 - def GetLabel(self,which):
47 return self._labels[which]
48 - def GetLabels(self):
49 return self._labels
50
51 - def SetBins(self,bins):
52 """ bins should be a list of 2-tuples """ 53 self._bins = bins[:]
54 - def GetBins(self):
55 return self._bins
56 - def GetNumBins(self):
57 return len(self._bins)
58
59 - def SetMinCount(self,min):
60 self._minCnt = min
61 - def GetMinCount(self):
62 return self._minCnt
63
64 - def SetMaxCount(self,max):
65 self._maxCnt = max
66 - def GetMaxCount(self):
67 return self._maxCnt
68
69 - def SetShortestPathsOnly(self,val):
70 if not val: 71 raise ValueError,'only shortest paths signatures are currently supported' 72 self._shortestPathsOnly = val
73 - def GetShortestPathsOnly(self):
74 return self._shortestPathsOnly
75
76 - def SetIncludeBondOrder(self,val):
77 self._includeBondOrder = val
78 - def GetIncludeBondOrder(self):
79 return self._includeBondOrder
80 81
82 - def GetSignature(self,initialize=1):
83 sig = Signature(patts=self.GetPatterns(), 84 bins=self.GetBins(), 85 labels = self.GetLabels(), 86 minCnt=self.GetMinCount(), 87 maxCnt=self.GetMaxCount(), 88 shortestPathsOnly=self.GetShortestPathsOnly(), 89 includeBondOrder=self.GetIncludeBondOrder()) 90 if initialize: 91 sig.Init() 92 return sig
93