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