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