rdkit.DataStructs.BitUtils

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

# Source Code for Module rdkit.DataStructs.BitUtils

     1  # $Id: BitUtils.py 997 2009-02-25 06:12:43Z glandrum $
     2  #
     3  #  Copyright (C) 2005-2006  greg Landrum and Rational Discovery LLC
     4  #
     5  #   @@ All Rights Reserved  @@
     6  #
     7 -def ConstructEnsembleBV(bv,bitsToKeep):
     8    """
     9
    10    >>> from rdkit import DataStructs
    11    >>> bv = DataStructs.ExplicitBitVect(128)
    12    >>> bv.SetBitsFromList((1,5,47,99,120))
    13    >>> r = ConstructEnsembleBV(bv,(0,1,2,3,45,46,47,48,49))
    14    >>> r.GetNumBits()
    15    9
    16    >>> r.GetBit(0)
    17    0
    18    >>> r.GetBit(1)
    19    1
    20    >>> r.GetBit(5)
    21    0
    22    >>> r.GetBit(6)  # old bit 47
    23    1
    24
    25
    26
    27    """
    28    finalSize=len(bitsToKeep)
    29    res = bv.__class__(finalSize)
    30
    31
    32    for i,bit in enumerate(bitsToKeep):
    33      if bv.GetBit(bit):
    34        res.SetBit(i)
    35    return res
    36
    37
    38  #------------------------------------
    39  #
    40  #  doctest boilerplate
    41  #
    42 -def _test():
    43    import doctest,sys
    44    return doctest.testmod(sys.modules["__main__"])
    45
    46  if __name__ == '__main__':
    47    import sys
    48    failed,tried = _test()
    49    sys.exit(failed)
    50