1
2
3
4
5
6
8 """ used to signal problems generating descriptor values """
9 pass
10
11
13 """ used to signal problems generating predictions """
14 pass
15
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
24 - def __init__(self, descCalc=None, model=None, dataSet=None, notes=''):
25 self._descCalc = descCalc
26 self._model = model
27 self._notes = notes
28 self._dataSet = dataSet
29 self._initialized = 0
30 self._supplementalData = []
31
34
37
40
43
46
49
52
55
57 self._supplementalData = suppD
58
60 if not hasattr(self, '_supplementalData'):
61 self.SetSupplementalData([])
62 return self._supplementalData
63
65 if not hasattr(self, '_supplementalData'):
66 self.SetSupplementalData([])
67 self._supplementalData.append(data)
68
69 - def Classify(self, obj, label='', threshold=0):
70 if not self._initialized:
71 self.Init()
72 try:
73 descs = self._descCalc.CalcDescriptors(obj)
74 except Exception:
75 raise DescriptorCalculationError('problems encountered generating descriptors')
76
77 argVect = [label] + list(descs) + [0]
78 try:
79 res = self._model.ClassifyExample(argVect, threshold=threshold, appendExample=0)
80 except Exception:
81 import traceback
82 traceback.print_exc()
83 raise ClassificationError('problems encountered generating prediction')
84
85 return res
86
88 if self._model is None or self._descCalc is None:
89 return
90
91 nms = self._model.GetDescriptorNames()
92 lbl = nms[0]
93 act = nms[-1]
94 descs = self._descCalc.GetDescriptorNames()
95 order = [lbl] + list(descs) + [act]
96 self._model.SetInputOrder(order)
97
98 self._initialized = 1
99