1
2
3
4
5
6
7
8
9
10
11 """ This functionality gets mixed into the BitEnsemble class
12
13 """
14 from rdkit.DataStructs.BitEnsemble import BitEnsemble
15
17 """ inializes a db table to store our scores
18
19 idInfo and actInfo should be strings with the definitions of the id and
20 activity columns of the table (when desired)
21
22 """
23 if idInfo:
24 cols = [idInfo]
25 else:
26 cols = []
27 for bit in self.GetBits():
28 cols.append('Bit_%d smallint'%(bit))
29 if actInfo :
30 cols.append(actInfo)
31 dbConn.AddTable(tableName,','.join(cols))
32 self._dbTableName=tableName
33
34 -def _ScoreToDb(self,sig,dbConn,tableName=None,id=None,act=None):
35 """ scores the "signature" that is passed in and puts the
36 results in the db table
37
38 """
39 if tableName is None:
40 try:
41 tableName = self._dbTableName
42 except AttributeError:
43 raise ValueError('table name not set in BitEnsemble pre call to ScoreToDb()')
44 if id is not None:
45 cols = [id]
46 else:
47 cols = []
48 score = 0
49 for bit in self.GetBits():
50 b = sig[bit]
51 cols.append(b)
52 score += b
53 if act is not None:
54 cols.append(act)
55 dbConn.InsertData(tableName,cols)
56
57 BitEnsemble.InitScoreTable = _InitScoreTable
58 BitEnsemble.ScoreToDb = _ScoreToDb
59