rdkit.DataStructs.BitEnsembleDb

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
    17 -def _InitScoreTable(self, dbConn, tableName, idInfo='', actInfo=''):
    18    """ inializes a db table to store our scores
    19
    20      idInfo and actInfo should be strings with the definitions of the id and
    21      activity columns of the table (when desired)
    22
    23    """
    24    if idInfo:
    25      cols = [idInfo]
    26    else:
    27      cols = []
    28    for bit in self.GetBits():
    29      cols.append('Bit_%d smallint' % (bit))
    30    if actInfo:
    31      cols.append(actInfo)
    32    dbConn.AddTable(tableName, ','.join(cols))
    33    self._dbTableName = tableName
    34
    35
    36 -def _ScoreToDb(self, sig, dbConn, tableName=None, id=None, act=None):
    37    """ scores the "signature" that is passed in and puts the
    38    results in the db table
    39
    40    """
    41    if tableName is None:
    42      try:
    43        tableName = self._dbTableName
    44      except AttributeError:
    45        raise ValueError('table name not set in BitEnsemble pre call to ScoreToDb()')
    46    if id is not None:
    47      cols = [id]
    48    else:
    49      cols = []
    50    score = 0
    51    for bit in self.GetBits():
    52      b = sig[bit]
    53      cols.append(b)
    54      score += b
    55    if act is not None:
    56      cols.append(act)
    57    dbConn.InsertData(tableName, cols)
    58
    59
    60  BitEnsemble.InitScoreTable = _InitScoreTable
    61  BitEnsemble.ScoreToDb = _ScoreToDb
    62