17 #ifndef __RD_ROMOL_H__
18 #define __RD_ROMOL_H__
26 #include <boost/graph/adjacency_list.hpp>
27 #include <boost/smart_ptr.hpp>
40 typedef boost::shared_ptr<Atom>
ATOM_SPTR;
44 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
53 template <
class T1,
class T2>
58 template <
class T1,
class T2>
60 template <
class T1,
class T2>
62 template <
class T1,
class T2>
64 template <
class T1,
class T2>
111 typedef MolGraph::vertex_descriptor vertex_descriptor;
112 typedef MolGraph::edge_descriptor edge_descriptor;
114 typedef MolGraph::edge_iterator EDGE_ITER;
115 typedef MolGraph::out_edge_iterator OEDGE_ITER;
116 typedef MolGraph::vertex_iterator VERTEX_ITER;
117 typedef MolGraph::adjacency_iterator ADJ_ITER;
118 typedef std::pair<EDGE_ITER, EDGE_ITER> BOND_ITER_PAIR;
119 typedef std::pair<OEDGE_ITER, OEDGE_ITER> OBOND_ITER_PAIR;
120 typedef std::pair<VERTEX_ITER, VERTEX_ITER> ATOM_ITER_PAIR;
121 typedef std::pair<ADJ_ITER, ADJ_ITER> ADJ_ITER_PAIR;
123 typedef std::vector<ATOM_SPTR> ATOM_SPTR_VECT;
124 typedef ATOM_SPTR_VECT::iterator ATOM_SPTR_VECT_I;
125 typedef ATOM_SPTR_VECT::const_iterator ATOM_SPTR_VECT_CI;
126 typedef std::vector<BOND_SPTR> BOND_SPTR_VECT;
127 typedef BOND_SPTR_VECT::iterator BOND_SPTR_VECT_I;
128 typedef BOND_SPTR_VECT::const_iterator BOND_SPTR_VECT_CI;
130 typedef std::vector<Atom *> ATOM_PTR_VECT;
131 typedef ATOM_PTR_VECT::iterator ATOM_PTR_VECT_I;
132 typedef ATOM_PTR_VECT::const_iterator ATOM_PTR_VECT_CI;
133 typedef std::vector<Bond *> BOND_PTR_VECT;
134 typedef BOND_PTR_VECT::iterator BOND_PTR_VECT_I;
135 typedef BOND_PTR_VECT::const_iterator BOND_PTR_VECT_CI;
137 typedef std::list<Atom *> ATOM_PTR_LIST;
138 typedef ATOM_PTR_LIST::iterator ATOM_PTR_LIST_I;
139 typedef ATOM_PTR_LIST::const_iterator ATOM_PTR_LIST_CI;
140 typedef std::list<Bond *> BOND_PTR_LIST;
141 typedef BOND_PTR_LIST::iterator BOND_PTR_LIST_I;
142 typedef BOND_PTR_LIST::const_iterator BOND_PTR_LIST_CI;
145 typedef std::list<CONFORMER_SPTR> CONF_SPTR_LIST;
146 typedef CONF_SPTR_LIST::iterator CONF_SPTR_LIST_I;
147 typedef CONF_SPTR_LIST::const_iterator CONF_SPTR_LIST_CI;
148 typedef std::pair<CONF_SPTR_LIST_I, CONF_SPTR_LIST_I> CONFS_I_PAIR;
151 typedef std::map<int, ATOM_PTR_LIST> ATOM_BOOKMARK_MAP;
152 typedef std::map<int, BOND_PTR_LIST> BOND_BOOKMARK_MAP;
160 ConstAromaticAtomIterator;
163 ConstHeteroatomIterator;
166 ConstQueryAtomIterator;
169 ConstMatchingAtomIterator;
171 typedef CONF_SPTR_LIST_I ConformerIterator;
172 typedef CONF_SPTR_LIST_CI ConstConformerIterator;
190 ROMol(
const ROMol &other,
bool quickCopy =
false,
int confId = -1) {
193 initFromOther(other, quickCopy, confId);
196 ROMol(
const std::string &binStr);
204 unsigned int getNumAtoms(
bool onlyExplicit = 1)
const;
231 unsigned int getNumBonds(
bool onlyHeavy = 1)
const;
251 template <
class U,
class V>
254 rdcast<unsigned int>(idx2));
257 template <
class U,
class V>
260 rdcast<unsigned int>(idx2));
270 d_atomBookmarks[mark].push_back(at.get());
274 d_atomBookmarks[mark].push_back(at);
278 d_atomBookmarks[mark].clear();
279 d_atomBookmarks[mark].push_back(at.get());
283 d_atomBookmarks[mark].clear();
284 d_atomBookmarks[mark].push_back(at);
307 d_bondBookmarks[mark].push_back(bond.get());
311 d_bondBookmarks[mark].push_back(bond);
364 return rdcast<unsigned int>(d_confs.size());
535 bool (*query)(
const Atom *))
const;
546 return d_confs.begin();
549 inline ConstConformerIterator
endConformers()
const {
return d_confs.end(); }
558 bool includeComputed =
true)
const {
561 if (!includeComputed &&
566 STR_VECT::const_iterator pos = tmp.begin();
567 while (pos != tmp.end()) {
568 if ((includePrivate || (*pos)[0] !=
'_') &&
569 std::find(computed.begin(), computed.end(), *pos) == computed.end()) {
586 template <
typename T>
587 void setProp(
const char *key, T val,
bool computed =
false)
const {
588 std::string what(key);
592 template <
typename T>
593 void setProp(
const std::string &key, T val,
bool computed =
false)
const {
597 if (std::find(compLst.begin(), compLst.end(), key) == compLst.end()) {
598 compLst.push_back(key);
602 dp_props->
setVal(key, val);
621 template <
typename T>
623 dp_props->
getVal(key, res);
626 template <
typename T>
627 void getProp(
const std::string &key, T &res)
const {
628 dp_props->
getVal(key, res);
631 template <
typename T>
633 return dp_props->
getVal<T>(key);
636 template <
typename T>
638 return dp_props->
getVal<T>(key);
643 template <
typename T>
648 template <
typename T>
655 if (!dp_props)
return false;
656 return dp_props->
hasVal(key);
660 if (!dp_props)
return false;
661 return dp_props->
hasVal(key);
674 std::string what(key);
681 STR_VECT_I svi = std::find(compLst.begin(), compLst.end(), key);
682 if (svi != compLst.end()) {
706 void debugMol(std::ostream &str)
const;
709 ATOM_SPTR
operator[](
const vertex_descriptor &v) {
return d_graph[v]; };
710 const ATOM_SPTR
operator[](
const vertex_descriptor &v)
const {
714 BOND_SPTR
operator[](
const edge_descriptor &e) {
return d_graph[e]; };
721 ATOM_BOOKMARK_MAP d_atomBookmarks;
722 BOND_BOOKMARK_MAP d_bondBookmarks;
725 CONF_SPTR_LIST d_confs;
733 virtual void destroy();
745 unsigned int addAtom(
Atom *atom,
bool updateLabel =
true,
746 bool takeOwnership =
false);
761 unsigned int addAtom(ATOM_SPTR,
bool updateLabel =
true);
771 unsigned int addBond(
Bond *bond,
bool takeOwnership =
false);
782 unsigned int addBond(BOND_SPTR bsp);
794 void initFromOther(
const ROMol &other,
bool quickCopy,
int confId);
Bond * getBondWithBookmark(int mark)
returns the first Bond associated with the bookmark provided
AtomIterator endAtoms()
get an AtomIterator pointing at the end of our Atoms
boost::shared_ptr< Bond > BOND_SPTR
bool hasBondBookmark(int mark) const
queries whether or not any bonds are associated with a bookmark
ATOM_PTR_LIST & getAllAtomsWithBookmark(int mark)
returns all Atoms associated with the bookmark provided
unsigned int getNumConformers() const
void setVal(const std::string &what, T &val)
Sets the value associated with a key.
void removeConformer(unsigned int id)
Delete the conformation with the specified ID.
ATOM_ITER_PAIR getVertices()
returns an iterator pair for looping over all Atoms
const int ci_RIGHTMOST_ATOM
ATOM_BOOKMARK_MAP * getAtomBookmarks()
returns a pointer to all of our atom bookmarks
void setBondBookmark(BOND_SPTR bond, int mark)
associates a Bond pointer with a bookmark
std::vector< ROMol > MOL_VECT
void replaceAtomBookmark(Atom *at, int mark)
Iterate over aromatic atoms, this is bidirectional.
MOL_PTR_VECT::iterator MOL_PTR_VECT_I
void setBondBookmark(Bond *bond, int mark)
std::vector< ROMol * > MOL_PTR_VECT
void setAtomBookmark(Atom *at, int mark)
STR_VECT keys() const
Returns the set of keys in the dictionary.
RWMol is a molecule class that is intended to be edited.
void clearProp(const std::string &key) const
T getProp(const std::string &key) const
BondIterator endBonds()
get a BondIterator pointing at the end of our Bonds
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, ATOM_SPTR, BOND_SPTR > MolGraph
This is the BGL type used to store the topology:
Iterate over atoms matching a query. This is bidirectional.
void setProp(const std::string &key, T val, bool computed=false) const
bool getValIfPresent(const std::string &what, T &res) const
Potentially gets the value associated with a particular key returns true on success/false on failure...
void clearProp(const char *key) const
clears the value of a property
AromaticAtomIterator beginAromaticAtoms()
get an AtomIterator pointing at our first aromatic Atom
ROMol(const ROMol &other, bool quickCopy=false, int confId=-1)
copy constructor with a twist
boost::shared_ptr< Atom > ATOM_SPTR
ADJ_ITER_PAIR getAtomNeighbors(Atom const *at) const
provides access to all neighbors around an Atom
Class for storing atomic queries.
STR_VECT getPropList(bool includePrivate=true, bool includeComputed=true) const
returns a list with the names of our properties
HeteroatomIterator beginHeteros()
get an AtomIterator pointing at our first hetero Atom
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
void clearBondBookmark(int mark)
removes a bookmark from our collection
void clearComputedProps(bool includeRings=true) const
clears all of our computed properties
iterator for a molecule's bonds, currently BiDirectional, but it theoretically ought to be RandomAcce...
ROMol is a molecule class that is intended to have a fixed topology.
std::vector< boost::shared_ptr< ROMol > > MOL_SPTR_VECT
const Atom * getAtomWithIdx(const U idx) const
void clearBondBookmark(int mark, BOND_SPTR bond)
void clearVal(const std::string &what)
Clears the value associated with a particular key, removing the key from the dictionary.
QueryAtomIterator endQueryAtoms()
get an AtomIterator pointing at the end of our Atoms
const ATOM_SPTR operator[](const vertex_descriptor &v) const
const Conformer & getConformer(int id=-1) const
void getVal(const std::string &what, T &res) const
Gets the value associated with a particular key.
BOND_SPTR operator[](const edge_descriptor &e)
MOL_PTR_VECT::const_iterator MOL_PTR_VECT_CI
Bond * getBondBetweenAtoms(unsigned int idx1, unsigned int idx2)
returns a pointer to the bond between two atoms, Null on failure
bool hasProp(const char *key) const
returns whether or not we have a property with name key
QueryAtomIterator beginQueryAtoms(QueryAtom const *query)
get an AtomIterator pointing at our first Atom that matches query
const BOND_SPTR operator[](const edge_descriptor &e) const
unsigned int getNumBonds(bool onlyHeavy=1) const
returns our number of Bonds
void updatePropertyCache(bool strict=true)
calculates any of our lazy properties
const Bond * getBondBetweenAtoms(const U idx1, const V idx2) const
BOND_PTR_LIST & getAllBondsWithBookmark(int mark)
returns all bonds associated with the bookmark provided
MatchingAtomIterator endMatchingAtoms()
get an AtomIterator pointing at the end of our Atoms
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
const Bond * getBondWithIdx(const U idx) const
MatchingAtomIterator beginMatchingAtoms(bool(*query)(Atom *))
get an AtomIterator pointing at our first Atom that matches query
void debugMol(std::ostream &str) const
sends some debugging info to a stream
Bond * getBondWithIdx(unsigned int idx)
returns a pointer to a particular Bond
const iterator for a molecule's bonds, currently BiDirectional, but it theoretically ought to be Rand...
boost::shared_ptr< ROMol > ROMOL_SPTR
BOND_BOOKMARK_MAP * getBondBookmarks()
returns a pointer to all of our bond bookmarks
Includes a bunch of functionality for handling Atom and Bond queries.
A general random access iterator.
bool getPropIfPresent(const std::string &key, T &res) const
A class to store information about a molecule's rings.
T getProp(const char *key) const
void clearConformers()
Clear all the conformations on the molecule.
bool hasProp(const std::string &key) const
void replaceAtomBookmark(ATOM_SPTR at, int mark)
associates an Atom pointer with a bookmark
bool needsUpdatePropertyCache() const
const std::string computedPropName
ConstConformerIterator endConformers() const
void clearAtomBookmark(const int mark, ATOM_SPTR atom)
ATOM_SPTR operator[](const vertex_descriptor &v)
const int ci_LEADING_BOND
class for representing a bond
bool hasVal(const char *what) const
Returns whether or not the dictionary contains a particular key.
void clearAllAtomBookmarks()
blows out all atomic bookmarks
HeteroatomIterator endHeteros()
get an AtomIterator pointing at the end of our Atoms
Iterate over atoms matching a query function. This is bidirectional.
RingInfo * getRingInfo() const
BondIterator beginBonds()
get a BondIterator pointing at our first Bond
BOND_ITER_PAIR getEdges()
returns an iterator pair for looping over all Bonds
handles pickling (serializing) molecules
AtomIterator beginAtoms()
get an AtomIterator pointing at our first Atom
Atom * getAtomWithIdx(const U idx)
Bond * getBondBetweenAtoms(const U idx1, const V idx2)
ConformerIterator endConformers()
void clearAtomBookmark(const int mark)
removes a bookmark from our collection
void getProp(const char *key, T &res) const
allows retrieval of a particular property value
Atom * getAtomWithIdx(unsigned int idx)
returns a pointer to a particular Atom
Defines the Atom class and associated typedefs.
bool hasAtomBookmark(int mark) const
queries whether or not any atoms are associated with a bookmark
std::vector< std::string >::iterator STR_VECT_I
ConformerIterator beginConformers()
Atom * getAtomWithBookmark(int mark)
returns the first Atom associated with the bookmark provided
unsigned int getAtomDegree(const Atom *at) const
returns the degree (number of neighbors) of an Atom in the graph
void getProp(const std::string &key, T &res) const
void setProp(const char *key, T val, bool computed=false) const
sets a property value
bool getPropIfPresent(const char *key, T &res) const
Bond * getBondWithIdx(const U idx)
void clearAllBondBookmarks()
blows out all bond bookmarks
Class for storing Bond queries.
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
unsigned int getNumHeavyAtoms() const
returns our number of heavy atoms (atomic number > 1)
ConstConformerIterator beginConformers() const
The Dict class can be used to store objects of arbitrary type keyed by strings.
Iterate over heteroatoms, this is bidirectional.
The class for representing atoms.
std::vector< std::string > STR_VECT
AromaticAtomIterator endAromaticAtoms()
get an AtomIterator pointing at the end of our Atoms
void setAtomBookmark(ATOM_SPTR at, int mark)
associates an Atom pointer with a bookmark
unsigned int addConformer(Conformer *conf, bool assignId=false)
Add a new conformation to the molecule.