RDKit
Open-source cheminformatics and machine learning.
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
#include <
RDGeneral/export.h
>
11
#pragma once
12
namespace
RDKit
{
13
namespace
FMCS {
14
typedef
unsigned
long
long
BitSet
;
15
class
Composition2N
{
// generator of 2^N-1 possible bit combinations
16
BitSet
Bits, InverseBits;
17
BitSet
MaxValue, ValueMask;
// need for inverse bitset must be 2^N-1
18
public
:
19
Composition2N
(
BitSet
maxValue,
BitSet
valueMask)
20
: Bits(0), InverseBits(0), MaxValue(maxValue), ValueMask(valueMask) {}
21
22
static
void
compute2N
(
unsigned
power,
BitSet
& value) {
23
value = 1uLL << power;
24
}
25
26
BitSet
getBitSet
()
const
{
27
return
InverseBits;
// inverse to generate biggest seed first and then
28
// decrease number of external bonds
29
}
30
31
bool
generateNext
() {
32
if
((++Bits) <= MaxValue) {
33
InverseBits = (~Bits + 1) & ValueMask;
34
return
true
;
35
}
else
36
return
false
;
37
}
38
bool
is2Power
()
const
{
// one bit is set only
39
BitSet
bits =
getBitSet
();
40
unsigned
n = 0;
41
while
(0 == (bits & 1uLL) &&
42
++n <
sizeof
(bits) * 8)
// find lowest bitwise 1
43
bits >>= 1u;
// shift all zero lower bits
44
if
(0 != (bits & 1uLL)) bits >>= 1u;
// shift first set bit too
45
return
0 == bits;
// remained bits except lowest 1
46
}
47
// unused: bool nonZero() {return 0!=getBitSet();}
48
bool
isSet
(
unsigned
bit)
const
{
return
0 != (
getBitSet
() & (1uLL << bit)); }
49
};
50
}
// namespace FMCS
51
}
// namespace RDKit
RDKit::FMCS::Composition2N
Definition:
Composition2N.h:15
RDKit::FMCS::Composition2N::compute2N
static void compute2N(unsigned power, BitSet &value)
Definition:
Composition2N.h:22
RDKit::FMCS::Composition2N::isSet
bool isSet(unsigned bit) const
Definition:
Composition2N.h:48
RDKit::FMCS::Composition2N::generateNext
bool generateNext()
Definition:
Composition2N.h:31
RDKit::FMCS::BitSet
unsigned long long BitSet
Definition:
Composition2N.h:14
RDKit::FMCS::Composition2N::Composition2N
Composition2N(BitSet maxValue, BitSet valueMask)
Definition:
Composition2N.h:19
RDKit::FMCS::Composition2N::getBitSet
BitSet getBitSet() const
Definition:
Composition2N.h:26
RDKit
Std stuff.
Definition:
Atom.h:30
RDKit::FMCS::Composition2N::is2Power
bool is2Power() const
Definition:
Composition2N.h:38
export.h
GraphMol
FMCS
Composition2N.h
Generated on Fri Jun 12 2020 19:04:45 for RDKit by
1.8.17