1
2
3
4 """ the COM server for Descriptor Calculators
5
6 """
7
8 import RDConfig
9 from ML.Descriptors import Descriptors,Parser
10 import cPickle
11 import sys
12 import winerror
13 from win32com.server import exception
14
15
17 """ exposes an interface for descriptor calculator COM servers
18
19 This interface does not support modifying the calculator, only
20 classifying new examples
21
22 **Public Methods**
23
24 - LoadCalculator
25
26 - CalcDescriptors
27
28 - GetDescriptorNames
29
30 - Close
31
32 **Public Attributes**
33
34 None
35
36 **ProgID**
37
38 RD.DescCalc
39
40 """
41 _public_methods_ = ['LoadCalculator','CalcDescriptors',
42 'GetDescriptorNames','Close']
43 _public_attrs_ = []
44 _reg_clsid_ = "{2DEC34F0-7FBA-4752-8BF7-65E4D81B46E4}"
45 _reg_progid_ = "RD.DescCalc"
46
48 """ Blows out the local calculator
49
50 **Note**
51
52 _LoadCalculator()_ must be called after this for further use of the
53 calculator.
54
55 """
56 self._descCalculator = None
57 self.propnames = None
58
60 """ Loads a (pickled) calculator from a file
61
62 **Arguments**
63
64 - fileName: the name of the file to load
65
66 """
67 try:
68 f = open(str(fileName),'rb')
69 except:
70 raise exception.COMException('The file %s could not be opened'%(fileName),
71 winerror.ERROR_FILE_NOT_FOUND)
72 try:
73 self._descCalculator = cPickle.load(f)
74 except:
75 raise exception.COMException('The calculator could not be loaded',
76 winerror.DISP_E_EXCEPTION)
77 return fileName
78
80 """ returns a list of the names of the descriptors this calculator generates
81
82 """
83 try:
84 c = self._descCalculator
85 except:
86 return ['']
87 else:
88 return self._descCalculator.GetDescriptorNames()
89
90
92 """ Calculates the descriptors for a new composition
93
94 **Arguments**
95
96 - argVect: a list of values
97
98 - colNames: the names of the columns in argVect
99
100 **Returns**
101
102 a list of descriptor values
103
104 **Note**
105
106 - colNames should include the names of all composition descriptors
107 returned by any compound descriptors in the calculator
108
109 """
110 argVect = list(argVect)
111 argVect[0] = str(argVect[0])
112 pDict = {}
113 for i in xrange(len(colNames)):
114 pDict[str(colNames[i])] = argVect[i]
115 try:
116 return self._descCalculator.CalcDescriptors(argVect,pDict)
117 except:
118 outF = open(RDConfig.RDCodeDir+'/ml/descriptors/log.txt','a+')
119 outF.write('#------------------------------\n')
120 outF.write('av: %s\n'%str(argVect))
121 outF.write('cn: %s\n'%str(colNames))
122 outF.write('pd: %s\n'%str(pDict))
123 outF.close()
124
125
126 if __name__=='__main__':
127 from win32com.server import register
128 register.UseCommandLine(DescriptorServer)
129