rdkit.DataStructs.BitEnsemble

Package rdkit :: Package DataStructs :: Module BitEnsemble |
[hide private]
[frames] | no frames]

# Source Code for Module rdkit.DataStructs.BitEnsemble

     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  """ #DOC
    12
    13
    14  """
    15
    16
    17 -class BitEnsemble(object):
    18    """  used to store a collection of bits and score
    19    BitVects (or signatures) against them.
    20
    21    """
    22
    23 -  def __init__(self, bits=None):
    24      if bits is not None:
    25        self._bits = list(bits)
    26      else:
    27        self._bits = []
    28
    29 -  def SetBits(self, bits):
    30      self._bits = list(bits)
    31
    32 -  def AddBit(self, bit):
    33      self._bits.append(bit)
    34
    35 -  def GetBits(self):
    36      return tuple(self._bits)
    37
    38 -  def GetNumBits(self):
    39      return len(self._bits)
    40
    41 -  def ScoreWithOnBits(self, other):
    42      """ other must support GetOnBits() """
    43      obl = other.GetOnBits()
    44      cnt = 0
    45      for bit in self.GetBits():
    46        if bit in obl:
    47          cnt += 1
    48      return cnt
    49
    50 -  def ScoreWithIndex(self, other):
    51      """ other must support __getitem__() """
    52      cnt = 0
    53      for bit in self.GetBits():
    54        if other[bit]:
    55          cnt += 1
    56      return cnt
    57
    58
    59  if __name__ == '__main__':
    60
    61    pass
    62