35#ifndef __RD_SLNPARSEOPS_H__
36#define __RD_SLNPARSEOPS_H__
44#include <boost/lexical_cast.hpp>
51void 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);
72template <
typename BondType>
73void addBondToMol(RWMol *mp, BondType *bond) {
76 mp->addBond(bond,
true);
80 bond->setIsAromatic(
true);
81 bond->getBeginAtom()->setIsAromatic(
true);
82 bond->getEndAtom()->setIsAromatic(
true);
89template <
typename AtomType>
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);
115template <
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);
145template <
typename AtomType>
156template <
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) {
202template <
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) {
229 std::stringstream err;
230 err <<
"SLN Parser error: Atom ID " << bmIt->first
231 <<
" used a second time.";
234 std::stringstream err;
235 err <<
"SLN Parser error: Atom ID " << bmIt->first
236 <<
" appears *after* its ring closure.";
240 "bad atom bookmark list on branch");
242 mp->
getAtomWithIdx((*bmIt->second.begin())->getIdx() + nOrigAtoms);
248 for (ROMol::BOND_BOOKMARK_MAP::const_iterator bmIt =
252 "bad bond bookmark list on branch");
253 for (ROMol::BOND_PTR_LIST::const_iterator bondIt = bmIt->second.begin();
254 bondIt != bmIt->second.end(); ++bondIt) {
255 Bond *tgtBond = *bondIt;
273 bond->setOwningMol(mp);
274 bond->setBeginAtomIdx(activeAtomIdx);
275 bond->setEndAtomIdx(nOrigAtoms);
276 addBondToMol(mp, bond);
283 unsigned int sz = molList.size();
284 if (sz == branchIdx + 1) {
285 molList.resize(sz - 1);
291 unsigned int branchIdx) {
307 unsigned int fragIdx) {
322 std::string res = boost::lexical_cast<std::string>(val);
#define CHECK_INVARIANT(expr, mess)
#define PRECONDITION(expr, mess)
pulls in the core RDKit functionality
pulls in the RDKit Query functionality
The class for representing atoms.
unsigned int getIdx() const
returns our index within the ROMol
void setOwningMol(ROMol *other)
sets our owning molecule
class for representing a bond
void setEndAtomIdx(unsigned int what)
sets the index of our end Atom
void setOwningMol(ROMol *other)
sets our owning molecule
unsigned int getEndAtomIdx() const
returns the index of our end Atom
Atom * getAtomWithIdx(unsigned int idx)
returns a pointer to a particular Atom
bool hasAtomBookmark(int mark) const
queries whether or not any atoms are associated with a bookmark
unsigned int getNumAtoms() const
returns our number of atoms
void setBondBookmark(Bond *bond, int mark)
associates a Bond pointer with a bookmark
Atom * getAtomWithBookmark(int mark)
returns the first Atom associated with the bookmark provided
BOND_BOOKMARK_MAP * getBondBookmarks()
returns a pointer to all of our bond bookmarks
ATOM_BOOKMARK_MAP * getAtomBookmarks()
returns a pointer to all of our atom bookmarks
void setAtomBookmark(Atom *at, int mark)
associates an Atom pointer with a bookmark
bool hasBondBookmark(int mark) const
queries whether or not any bonds are associated with a bookmark
RWMol is a molecule class that is intended to be edited.
unsigned int addAtom(bool updateLabel=true)
adds an empty Atom to our collection
unsigned int addBond(unsigned int beginAtomIdx, unsigned int endAtomIdx, Bond::BondType order=Bond::UNSPECIFIED)
adds a Bond between the indicated Atoms
Atom * getActiveAtom()
returns a pointer to the "active" Atom
void setActiveAtom(Atom *atom)
sets our activeAtom
void insertMol(const ROMol &other)
insert the atoms and bonds from other into this molecule
void addAtomToMol(std::vector< RWMol * > &molList, unsigned int idx, AtomType *atom, BondType *bond, bool doingQuery)
adds an atom to a molecule
int startMol(std::vector< RWMol * > &molList, AtomType *firstAtom, bool doingQuery)
initialize a molecule
int addFragToMol(std::vector< RWMol * > &molList, unsigned int molIdx, unsigned int fragIdx)
int addBranchToMol(std::vector< RWMol * > &molList, unsigned int molIdx, unsigned int branchIdx, BondType *&bond)
std::string convertToString(T val)
convenience function to convert the argument to a string
void closeRingBond(std::vector< RWMol * > &molList, unsigned int molIdx, unsigned int ringIdx, BondType *bond, bool postponeAllowed=true)
RDKIT_RDGENERAL_EXPORT const std::string _AtomID