13 #include <boost/lexical_cast.hpp>
14 #include <boost/tokenizer.hpp>
15 #include <boost/format.hpp>
18 typedef boost::tokenizer<boost::char_separator<char>>
tokenizer;
21 namespace MolEnumerator {
27 std::vector<std::pair<unsigned int, unsigned int>>
bondAtoms;
32 const ROMol &mol,
bool strict =
true,
33 const std::map<unsigned, Atom *> *atomIdxMap =
nullptr) {
34 std::vector<LinkNode> res;
39 std::vector<int> mapping;
41 boost::char_separator<char> pipesep(
"|");
42 boost::char_separator<char> spacesep(
" ");
43 for (
auto linknodetext :
tokenizer(pval, pipesep)) {
46 std::vector<unsigned int> data;
48 std::transform(tokens.begin(), tokens.end(), std::back_inserter(data),
49 [](
const std::string &token) ->
unsigned int {
50 return boost::lexical_cast<unsigned int>(token);
52 }
catch (boost::bad_lexical_cast &) {
53 std::ostringstream errout;
54 errout <<
"Cannot convert values in LINKNODE '" << linknodetext
55 <<
"' to unsigned ints";
65 if (data.size() < 5 || data.size() < 3 + 2 * data[2]) {
66 std::ostringstream errout;
67 errout <<
"not enough values in LINKNODE '" << linknodetext <<
"'";
79 std::ostringstream errout;
80 errout <<
"bad counts in LINKNODE '" << linknodetext <<
"'";
92 "only link nodes with 2 bonds are currently supported");
95 <<
"only link nodes with 2 bonds are currently supported"
101 if (data[3] != data[5]) {
102 std::ostringstream errout;
103 errout <<
"bonds don't start at the same atom for LINKNODE '"
104 << linknodetext <<
"'";
115 for (
unsigned int i = 3; i <= 6; ++i) {
116 const auto aidx = atomIdxMap->find(data[i] - 1);
117 if (aidx == atomIdxMap->end()) {
118 std::ostringstream errout;
119 errout <<
"atom index " << data[i]
120 <<
" cannot be found in molecule for LINKNODE '"
121 << linknodetext <<
"'";
129 data[i] = aidx->second->getIdx();
133 for (
unsigned int i = 3; i <= 6; ++i) {
137 node.
bondAtoms.push_back(std::make_pair(data[3], data[4]));
138 node.
bondAtoms.push_back(std::make_pair(data[5], data[6]));
141 std::ostringstream errout;
142 errout <<
"bond not found between atoms in LINKNODE '" << linknodetext
151 res.push_back(std::move(node));
#define UNDER_CONSTRUCTION(fn)
boost::tokenizer< boost::char_separator< char > > tokenizer
#define BOOST_LOG(__arg__)
RDKIT_RDGENERAL_EXPORT RDLogger rdWarningLog
bool getPropIfPresent(const std::string &key, T &res) const
Bond * getBondBetweenAtoms(unsigned int idx1, unsigned int idx2)
returns a pointer to the bond between two atoms, Null on failure
Class to allow us to throw a ValueError from C++ and have it make it back to Python.
std::vector< LinkNode > getMolLinkNodes(const ROMol &mol, bool strict=true, const std::map< unsigned, Atom * > *atomIdxMap=nullptr)
RDKIT_RDGENERAL_EXPORT const std::string molFileLinkNodes
std::vector< std::pair< unsigned int, unsigned int > > bondAtoms