rdkit.DataStructs.BitUtils

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

# Source Code for Module rdkit.DataStructs.BitUtils

     1  # $Id$
     2  #
     3  #  Copyright (C) 2005-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 -def ConstructEnsembleBV(bv,bitsToKeep):
    12    """
    13
    14    >>> from rdkit import DataStructs
    15    >>> bv = DataStructs.ExplicitBitVect(128)
    16    >>> bv.SetBitsFromList((1,5,47,99,120))
    17    >>> r = ConstructEnsembleBV(bv,(0,1,2,3,45,46,47,48,49))
    18    >>> r.GetNumBits()
    19    9
    20    >>> r.GetBit(0)
    21    0
    22    >>> r.GetBit(1)
    23    1
    24    >>> r.GetBit(5)
    25    0
    26    >>> r.GetBit(6)  # old bit 47
    27    1
    28
    29
    30
    31    """
    32    finalSize=len(bitsToKeep)
    33    res = bv.__class__(finalSize)
    34
    35
    36    for i,bit in enumerate(bitsToKeep):
    37      if bv.GetBit(bit):
    38        res.SetBit(i)
    39    return res
    40
    41
    42  #------------------------------------
    43  #
    44  #  doctest boilerplate
    45  #
    46 -def _test():
    47    import doctest,sys
    48    return doctest.testmod(sys.modules["__main__"])
    49
    50  if __name__ == '__main__':
    51    import sys
    52    failed,tried = _test()
    53    sys.exit(failed)
    54