Package rdkit :: Package DataStructs :: Module BitEnsembleDb

[hide private]
[frames] | no frames]

# Source Code for Module rdkit.DataStructs.BitEnsembleDb

     1  # $Id$
     2  #
     3  # Copyright (C) 2003-2006 greg Landrum and Rational Discovery LLC
     4  #
     5  #   @@ All Rights Reserved @@
     6  #  This file is part of the RDKit.
     7  #  The contents are covered by the terms of the BSD license
     8  #  which is included in the file license.txt, found at the root
     9  #  of the RDKit source tree.
    10  #
    11  """ This functionality gets mixed into the BitEnsemble class
    12
    13  """
    14  from rdkit.DataStructs.BitEnsemble import BitEnsemble
    15
    16 -def _InitScoreTable(self,dbConn,tableName,idInfo='',actInfo=''):
    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