35 #ifndef __RD_SLNPARSEOPS_H__
36 #define __RD_SLNPARSEOPS_H__
44 #include <boost/lexical_cast.hpp>
51 void bookmarkAtomID(RWMol *mp, Atom *atom) {
56 if (mp->hasAtomBookmark(label)) {
57 std::stringstream err;
58 err <<
"SLN Parser error: Atom ID " << label <<
" used a second time.";
59 throw SLNParseException(err.str());
61 if (mp->hasBondBookmark(label)) {
62 std::stringstream err;
63 err <<
"SLN Parser error: Atom ID " << label
64 <<
" appears *after* its ring closure.";
65 throw SLNParseException(err.str());
67 mp->setAtomBookmark(atom, label);
72 template <
typename BondType>
73 void addBondToMol(RWMol *mp, BondType *bond) {
76 mp->addBond(bond,
true);
80 bond->setIsAromatic(
true);
81 bond->getBeginAtom()->setIsAromatic(
true);
82 bond->getEndAtom()->setIsAromatic(
true);
89 template <
typename AtomType>
90 int startMol(std::vector<RWMol *> &molList, AtomType *firstAtom,
94 mp->
addAtom(firstAtom,
true,
true);
95 bookmarkAtomID(mp, firstAtom);
101 for (
unsigned int i = 0; i < firstAtom->getNumExplicitHs(); ++i) {
105 firstAtom->setNumExplicitHs(0);
108 int sz = molList.size();
109 molList.push_back(mp);
115 template <
typename AtomType,
typename BondType>
117 AtomType *atom, BondType *bond,
bool doingQuery) {
119 RWMol *mp = molList[idx];
125 int atomIdx1 = a1->
getIdx();
126 int atomIdx2 = mp->
addAtom(atom,
true,
true);
127 bookmarkAtomID(mp, atom);
128 bond->setOwningMol(mp);
129 bond->setBeginAtomIdx(atomIdx1);
130 bond->setEndAtomIdx(atomIdx2);
131 addBondToMol(mp, bond);
137 for (
unsigned int i = 0; i < atom->getNumExplicitHs(); ++i) {
141 atom->setNumExplicitHs(0);
145 template <
typename AtomType>
147 AtomType *atom,
bool doingQuery) {
156 template <
typename BondType>
158 unsigned int ringIdx, BondType *bond,
159 bool postponeAllowed =
true) {
161 RWMol *mp = molList[molIdx];
166 if (postponeAllowed) {
168 bond->setOwningMol(mp);
173 std::stringstream err;
174 err <<
"SLN Parser error: Ring closure " << ringIdx
175 <<
" does not have a corresponding opener.";
184 bond->setBeginAtom(opener);
185 bond->setEndAtom(closer);
186 addBondToMol(mp, bond);
190 unsigned int ringIdx) {
202 template <
typename BondType>
204 unsigned int branchIdx, BondType *&bond) {
206 RWMol *mp = molList[molIdx];
209 RWMol *branch = molList[branchIdx];
222 for (ROMol::ATOM_BOOKMARK_MAP::const_iterator bmIt =
225 if (bmIt->first < 0)
continue;
227 std::stringstream err;
228 err <<
"SLN Parser error: Atom ID " << bmIt->first
229 <<
" used a second time.";
232 std::stringstream err;
233 err <<
"SLN Parser error: Atom ID " << bmIt->first
234 <<
" appears *after* its ring closure.";
238 "bad atom bookmark list on branch");
240 mp->
getAtomWithIdx((*bmIt->second.begin())->getIdx() + nOrigAtoms);
246 for (ROMol::BOND_BOOKMARK_MAP::const_iterator bmIt =
250 "bad bond bookmark list on branch");
251 for (ROMol::BOND_PTR_LIST::const_iterator bondIt = bmIt->second.begin();
252 bondIt != bmIt->second.end(); ++bondIt) {
253 Bond *tgtBond = *bondIt;
271 bond->setOwningMol(mp);
272 bond->setBeginAtomIdx(activeAtomIdx);
273 bond->setEndAtomIdx(nOrigAtoms);
274 addBondToMol(mp, bond);
281 unsigned int sz = molList.size();
282 if (sz == branchIdx + 1) {
283 molList.resize(sz - 1);
289 unsigned int branchIdx) {
305 unsigned int fragIdx) {
318 template <
typename T>
320 std::string res = boost::lexical_cast<std::string>(val);