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