RDKit: Composition2N.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Composition2N.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2014 Novartis Institutes for BioMedical Research
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #pragma once
11 namespace RDKit {
12 namespace FMCS {
13 typedef unsigned long long BitSet;
14 class Composition2N { // generator of 2^N-1 possible bit combinations
15 BitSet Bits, InverseBits;
16 BitSet MaxValue, ValueMask; // need for inverse bitset must be 2^N-1
17 public:
18 Composition2N(BitSet maxValue, BitSet valueMask)
19 : Bits(0), InverseBits(0), MaxValue(maxValue), ValueMask(valueMask) {}
20
21 static void compute2N(unsigned power, BitSet& value) {
22 value = 1uLL << power;
23 }
24
25 BitSet getBitSet() const {
26 return InverseBits; // inverse to generate biggest seed first and then
27 // decrease number of external bonds
28 }
29
30 bool generateNext() {
31 if ((++Bits) <= MaxValue) {
32 InverseBits = (~Bits + 1) & ValueMask;
33 return true;
34 } else
35 return false;
36 }
37 bool is2Power() const { // one bit is set only
38 BitSet bits = getBitSet();
39 unsigned n = 0;
40 while (0 == (bits & 1uLL) &&
41 ++n < sizeof(bits) * 8) // find lowest bitwise 1
42 bits >>= 1u; // shift all zero lower bits
43 if (0 != (bits & 1uLL)) bits >>= 1u; // shift first set bit too
44 return 0 == bits; // remained bits except lowest 1
45 }
46 // unused: bool nonZero() {return 0!=getBitSet();}
47 bool isSet(unsigned bit) const { return 0 != (getBitSet() & (1uLL << bit)); }
48 };
49 }
50 }
RDKit::FMCS::Composition2N::Composition2N
Composition2N(BitSet maxValue, BitSet valueMask)
Definition: Composition2N.h:18
RDKit::FMCS::Composition2N::getBitSet
BitSet getBitSet() const
Definition: Composition2N.h:25
RDKit::FMCS::Composition2N::is2Power
bool is2Power() const
Definition: Composition2N.h:37
RDKit::FMCS::Composition2N::isSet
bool isSet(unsigned bit) const
Definition: Composition2N.h:47
RDKit::FMCS::BitSet
unsigned long long BitSet
Definition: Composition2N.h:13
RDKit
Std stuff.
Definition: Atom.h:29
RDKit::FMCS::Composition2N
Definition: Composition2N.h:14
RDKit::FMCS::Composition2N::generateNext
bool generateNext()
Definition: Composition2N.h:30
RDKit::FMCS::Composition2N::compute2N
static void compute2N(unsigned power, BitSet &value)
Definition: Composition2N.h:21