1
2
3
4
5
6
7
8
9 import exceptions
11 """ used to signal problems generating descriptor values """
12 pass
14 """ used to signal problems generating predictions """
15 pass
16
18 """ a container class to package a composite model with a descriptor
19 calculator so that objects needing predictions (compounds, molecules, etc.)
20 can be passed directly in without worrying about generating descriptors
21
22 """
23 - def __init__(self,descCalc=None,model=None,dataSet=None,notes=''):
24 self._descCalc = descCalc
25 self._model = model
26 self._notes = notes
27 self._dataSet = dataSet
28 self._initialized = 0
29 self._supplementalData = []
30
35
40
45
50
52 self._supplementalData = suppD
54 if not hasattr(self,'_supplementalData'):
55 self._supplementalData = []
56 return self._supplementalData
58 if not hasattr(self,'_supplementalData'):
59 self._supplementalData = []
60 self._supplementalData.append(data)
61
62 - def Classify(self,obj,label='',threshold=0):
63 if not self._initialized:
64 self.Init()
65 try:
66 descs = self._descCalc.CalcDescriptors(obj)
67 except:
68 raise DescriptorCalculationError,'problems encountered generating descriptors'
69
70 argVect = [label]+list(descs)+[0]
71 try:
72 res = self._model.ClassifyExample(argVect,threshold=threshold,appendExample=0)
73 except:
74 import traceback
75 traceback.print_exc()
76 raise ClassificationError,'problems encountered generating prediction'
77
78 return res
79
81 if self._model is None or self._descCalc is None:
82 return
83
84 nms = self._model.GetDescriptorNames()
85 lbl = nms[0]
86 act = nms[-1]
87 descs = self._descCalc.GetDescriptorNames()
88 order = [lbl] + list(descs) + [act]
89 self._model.SetInputOrder(order)
90
91 self._initialized = 1
92