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
const Conformer & getConformer(int id=-1) const
const ATOM_SPTR operator[](const vertex_descriptor &v) const
ATOM_PTR_LIST & getAllAtomsWithBookmark(int mark)
returns all Atoms associated with the bookmark provided
T getProp(const std::string &key) 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)
void debugMol(std::ostream &str) const
sends some debugging info to a stream
std::vector< ROMol * > MOL_PTR_VECT
void setAtomBookmark(Atom *at, int mark)
RWMol is a molecule class that is intended to be edited.
const Bond * getBondBetweenAtoms(const U idx1, const V idx2) const
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
bool hasVal(const char *what) const
Returns whether or not the dictionary contains a particular key.
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.
AromaticAtomIterator beginAromaticAtoms()
get an AtomIterator pointing at our first aromatic Atom
bool hasAtomBookmark(int mark) const
queries whether or not any atoms are associated with a bookmark
ROMol(const ROMol &other, bool quickCopy=false, int confId=-1)
copy constructor with a twist
boost::shared_ptr< Atom > ATOM_SPTR
unsigned int getNumBonds(bool onlyHeavy=1) const
returns our number of Bonds
Class for storing atomic queries.
HeteroatomIterator beginHeteros()
get an AtomIterator pointing at our first hetero Atom
const Atom * getAtomWithIdx(const U idx) const
unsigned int getNumConformers() const
bool getPropIfPresent(const char *key, T &res) const
void clearBondBookmark(int mark)
removes a bookmark from our collection
ADJ_ITER_PAIR getAtomNeighbors(Atom const *at) const
provides access to all neighbors around an Atom
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...
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
void clearBondBookmark(int mark, BOND_SPTR bond)
unsigned int getAtomDegree(const Atom *at) const
returns the degree (number of neighbors) of an Atom in the graph
void getVal(const std::string &what, T &res) const
Gets the value associated with a particular key.
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
void getProp(const std::string &key, T &res) const
BOND_SPTR operator[](const edge_descriptor &e)
RingInfo * getRingInfo() const
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 hasBondBookmark(int mark) const
queries whether or not any bonds are associated with a bookmark
QueryAtomIterator beginQueryAtoms(QueryAtom const *query)
get an AtomIterator pointing at our first Atom that matches query
void clearComputedProps(bool includeRings=true) const
clears all of our computed properties
STR_VECT getPropList(bool includePrivate=true, bool includeComputed=true) const
returns a list with the names of our properties
void updatePropertyCache(bool strict=true)
calculates any of our lazy properties
const Bond * getBondWithIdx(const U idx) 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
void setProp(const char *key, T val, bool computed=false) const
sets a property value
T getProp(const char *key) const
void clearProp(const char *key) const
clears the value of a property
void setProp(const std::string &key, T val, bool computed=false) const
MatchingAtomIterator beginMatchingAtoms(bool(*query)(Atom *))
get an AtomIterator pointing at our first Atom that matches query
ConstConformerIterator beginConformers() const
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.
const BOND_SPTR operator[](const edge_descriptor &e) const
A class to store information about a molecule's rings.
void clearProp(const std::string &key) const
STR_VECT keys() const
Returns the set of keys in the dictionary.
void clearConformers()
Clear all the conformations on the molecule.
void replaceAtomBookmark(ATOM_SPTR at, int mark)
associates an Atom pointer with a bookmark
const std::string computedPropName
void clearAtomBookmark(const int mark, ATOM_SPTR atom)
ATOM_SPTR operator[](const vertex_descriptor &v)
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
const int ci_LEADING_BOND
bool hasProp(const std::string &key) const
class for representing a bond
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.
BondIterator beginBonds()
get a BondIterator pointing at our first Bond
BOND_ITER_PAIR getEdges()
returns an iterator pair for looping over all Bonds
ConstConformerIterator endConformers() const
handles pickling (serializing) molecules
AtomIterator beginAtoms()
get an AtomIterator pointing at our first Atom
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
Atom * getAtomWithIdx(const U idx)
Bond * getBondBetweenAtoms(const U idx1, const V idx2)
void getProp(const char *key, T &res) const
allows retrieval of a particular property value
ConformerIterator endConformers()
void clearAtomBookmark(const int mark)
removes a bookmark from our collection
Atom * getAtomWithIdx(unsigned int idx)
returns a pointer to a particular Atom
Defines the Atom class and associated typedefs.
bool hasProp(const char *key) const
returns whether or not we have a property with name key
bool needsUpdatePropertyCache() const
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 getNumHeavyAtoms() const
returns our number of heavy atoms (atomic number > 1)
bool getPropIfPresent(const std::string &key, T &res) const
Bond * getBondWithIdx(const U idx)
void clearAllBondBookmarks()
blows out all bond bookmarks
Class for storing Bond queries.
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.