29 #include <boost/graph/adjacency_list.hpp>
30 #include <boost/smart_ptr.hpp>
31 #include <boost/dynamic_bitset.hpp>
33 #ifdef RDK_USE_BOOST_SERIALIZATION
34 #include <boost/serialization/split_member.hpp>
53 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
62 template <
class T1,
class T2>
67 template <
class T1,
class T2>
69 template <
class T1,
class T2>
71 template <
class T1,
class T2>
73 template <
class T1,
class T2>
113 template <
class Graph,
class Vertex,
114 class Iterator =
typename Graph::vertex_iterator>
145 auto vs = boost::vertices(*
graph);
155 template <
class Graph,
class Edge,
156 class Iterator =
typename Graph::edge_iterator>
187 auto vs = boost::edges(*
graph);
206 typedef MolGraph::vertex_descriptor vertex_descriptor;
207 typedef MolGraph::edge_descriptor edge_descriptor;
209 typedef MolGraph::edge_iterator EDGE_ITER;
210 typedef MolGraph::out_edge_iterator OEDGE_ITER;
211 typedef MolGraph::vertex_iterator VERTEX_ITER;
212 typedef MolGraph::adjacency_iterator ADJ_ITER;
213 typedef std::pair<EDGE_ITER, EDGE_ITER> BOND_ITER_PAIR;
214 typedef std::pair<OEDGE_ITER, OEDGE_ITER> OBOND_ITER_PAIR;
215 typedef std::pair<VERTEX_ITER, VERTEX_ITER> ATOM_ITER_PAIR;
216 typedef std::pair<ADJ_ITER, ADJ_ITER> ADJ_ITER_PAIR;
218 typedef std::vector<Atom *> ATOM_PTR_VECT;
219 typedef ATOM_PTR_VECT::iterator ATOM_PTR_VECT_I;
220 typedef ATOM_PTR_VECT::const_iterator ATOM_PTR_VECT_CI;
221 typedef std::vector<Bond *> BOND_PTR_VECT;
222 typedef BOND_PTR_VECT::iterator BOND_PTR_VECT_I;
223 typedef BOND_PTR_VECT::const_iterator BOND_PTR_VECT_CI;
225 typedef std::list<Atom *> ATOM_PTR_LIST;
226 typedef ATOM_PTR_LIST::iterator ATOM_PTR_LIST_I;
227 typedef ATOM_PTR_LIST::const_iterator ATOM_PTR_LIST_CI;
228 typedef std::list<Bond *> BOND_PTR_LIST;
229 typedef BOND_PTR_LIST::iterator BOND_PTR_LIST_I;
230 typedef BOND_PTR_LIST::const_iterator BOND_PTR_LIST_CI;
233 typedef std::list<CONFORMER_SPTR> CONF_SPTR_LIST;
234 typedef CONF_SPTR_LIST::iterator CONF_SPTR_LIST_I;
235 typedef CONF_SPTR_LIST::const_iterator CONF_SPTR_LIST_CI;
236 typedef std::pair<CONF_SPTR_LIST_I, CONF_SPTR_LIST_I> CONFS_I_PAIR;
239 typedef std::map<int, ATOM_PTR_LIST> ATOM_BOOKMARK_MAP;
240 typedef std::map<int, BOND_PTR_LIST> BOND_BOOKMARK_MAP;
248 ConstAromaticAtomIterator;
251 ConstHeteroatomIterator;
254 ConstQueryAtomIterator;
257 ConstMatchingAtomIterator;
259 typedef CONF_SPTR_LIST_I ConformerIterator;
260 typedef CONF_SPTR_LIST_CI ConstConformerIterator;
283 auto pr = getAtomNeighbors(at);
284 return {&d_graph, pr.first, pr.second};
289 auto pr = getAtomNeighbors(at);
290 return {&d_graph, pr.first, pr.second};
295 auto pr = getAtomBonds(at);
296 return {&d_graph, pr.first, pr.second};
301 auto pr = getAtomBonds(at);
302 return {&d_graph, pr.first, pr.second};
333 ROMol(
const ROMol &other,
bool quickCopy =
false,
int confId = -1)
335 dp_ringInfo =
nullptr;
336 initFromOther(other, quickCopy, confId);
337 numBonds = rdcast<unsigned int>(boost::num_edges(d_graph));
342 ROMol(
const std::string &binStr,
unsigned int propertyFlags);
346 d_graph(std::move(o.d_graph)),
347 d_atomBookmarks(std::move(o.d_atomBookmarks)),
348 d_bondBookmarks(std::move(o.d_bondBookmarks)),
349 d_confs(std::move(o.d_confs)),
350 d_sgroups(std::move(o.d_sgroups)),
351 d_stereo_groups(std::move(o.d_stereo_groups)),
352 numBonds(o.numBonds) {
353 for (
auto atom : atoms()) {
354 atom->setOwningMol(
this);
356 for (
auto bond : bonds()) {
357 bond->setOwningMol(
this);
359 for (
auto conf : d_confs) {
360 conf->setOwningMol(
this);
364 dp_ringInfo = std::exchange(o.dp_ringInfo,
nullptr);
365 dp_delAtoms = std::exchange(o.dp_delAtoms,
nullptr);
366 dp_delBonds = std::exchange(o.dp_delBonds,
nullptr);
373 d_graph = std::move(o.d_graph);
374 d_atomBookmarks = std::move(o.d_atomBookmarks);
375 d_bondBookmarks = std::move(o.d_bondBookmarks);
379 dp_ringInfo = std::exchange(o.dp_ringInfo,
nullptr);
381 d_confs = std::move(o.d_confs);
382 d_sgroups = std::move(o.d_sgroups);
383 d_stereo_groups = std::move(o.d_stereo_groups);
384 dp_delAtoms = std::exchange(o.dp_delAtoms,
nullptr);
385 dp_delBonds = std::exchange(o.dp_delBonds,
nullptr);
386 numBonds = o.numBonds;
389 for (
auto atom : atoms()) {
390 atom->setOwningMol(
this);
392 for (
auto bond : bonds()) {
393 bond->setOwningMol(
this);
395 for (
auto conf : d_confs) {
396 conf->setOwningMol(
this);
414 return rdcast<unsigned int>(boost::num_vertices(d_graph));
426 return getAtomWithIdx(rdcast<unsigned int>(idx));
431 return getAtomWithIdx(rdcast<unsigned int>(idx));
449 return getBondWithIdx(rdcast<unsigned int>(idx));
454 return getBondWithIdx(rdcast<unsigned int>(idx));
461 template <
class U,
class V>
463 return getBondBetweenAtoms(rdcast<unsigned int>(idx1),
464 rdcast<unsigned int>(idx2));
467 template <
class U,
class V>
469 return getBondBetweenAtoms(rdcast<unsigned int>(idx1),
470 rdcast<unsigned int>(idx2));
480 d_atomBookmarks[mark].push_back(at);
484 d_atomBookmarks[mark].clear();
485 d_atomBookmarks[mark].push_back(at);
508 d_bondBookmarks[mark].push_back(bond);
561 return rdcast<unsigned int>(d_confs.size());
726 bool (*query)(
const Atom *))
const;
737 return d_confs.begin();
740 inline ConstConformerIterator
endConformers()
const {
return d_confs.end(); }
780 return d_stereo_groups;
792 #ifdef RDK_USE_BOOST_SERIALIZATION
795 template <
class Archive>
796 void save(Archive &ar,
const unsigned int version)
const;
797 template <
class Archive>
798 void load(Archive &ar,
const unsigned int version);
799 BOOST_SERIALIZATION_SPLIT_MEMBER()
805 ATOM_BOOKMARK_MAP d_atomBookmarks;
806 BOND_BOOKMARK_MAP d_bondBookmarks;
808 CONF_SPTR_LIST d_confs;
809 std::vector<SubstanceGroup> d_sgroups;
810 std::vector<StereoGroup> d_stereo_groups;
811 std::unique_ptr<boost::dynamic_bitset<>> dp_delAtoms =
nullptr;
812 std::unique_ptr<boost::dynamic_bitset<>> dp_delBonds =
nullptr;
818 void clearSubstanceGroups() { d_sgroups.clear(); }
821 unsigned int numBonds{0};
826 virtual void destroy();
838 unsigned int addAtom(
Atom *atom,
bool updateLabel =
true,
839 bool takeOwnership =
false);
849 unsigned int addBond(
Bond *bond,
bool takeOwnership =
false);
861 void initFromOther(
const ROMol &other,
bool quickCopy,
int confId);
Defines the Atom class and associated typedefs.
Defines the class StereoGroup which stores relationships between the absolute configurations of atoms...
Defines the SubstanceGroup class.
Iterate over aromatic atoms, this is bidirectional.
A general random access iterator.
The class for representing atoms.
iterator for a molecule's bonds, currently BiDirectional, but it theoretically ought to be RandomAcce...
class for representing a bond
const iterator for a molecule's bonds, currently BiDirectional, but it theoretically ought to be Rand...
Iterate over heteroatoms, this is bidirectional.
Iterate over atoms matching a query function. This is bidirectional.
handles pickling (serializing) molecules
Iterate over atoms matching a query. This is bidirectional.
Class for storing atomic queries.
Class for storing Bond queries.
RDProps & operator=(const RDProps &rhs)
ConstAromaticAtomIterator endAromaticAtoms() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
CXXBondIterator< MolGraph, Bond * > bonds()
ADJ_ITER_PAIR getAtomNeighbors(Atom const *at) const
provides access to all neighbors around an Atom
ConstQueryAtomIterator endQueryAtoms() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Bond * operator[](const edge_descriptor &e) const
bool needsUpdatePropertyCache() const
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
unsigned int getNumBonds(bool onlyHeavy=1) const
returns our number of Bonds
CXXBondIterator< const MolGraph, Bond *const > bonds() const
void clearAtomBookmark(int mark)
removes a bookmark from our collection
Bond * getBondBetweenAtoms(const U idx1, const V idx2)
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned int getNumHeavyAtoms() const
returns our number of heavy atoms (atomic number > 1)
void clearAtomBookmark(int mark, const Atom *atom)
removes a particular Atom from the list associated with the bookmark
const Atom * getAtomWithIdx(const U idx) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned int getNumConformers() const
AtomIterator endAtoms()
get an AtomIterator pointing at the end of our Atoms
Bond * getBondWithIdx(unsigned int idx)
returns a pointer to a particular Bond
RingInfo * getRingInfo() const
ConstAtomIterator endAtoms() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
BondIterator beginBonds()
get a BondIterator pointing at our first Bond
bool hasAtomBookmark(int mark) const
queries whether or not any atoms are associated with a bookmark
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
ConstQueryAtomIterator beginQueryAtoms(QueryAtom const *) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned int getNumAtoms() const
returns our number of atoms
ConstConformerIterator endConformers() const
ConstMatchingAtomIterator beginMatchingAtoms(bool(*query)(const Atom *)) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
ROMol(const ROMol &other, bool quickCopy=false, int confId=-1)
copy constructor with a twist
ConstMatchingAtomIterator endMatchingAtoms() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
BOND_ITER_PAIR getEdges()
returns an iterator pair for looping over all Bonds
void clearConformers()
Clear all the conformations on the molecule.
void setBondBookmark(Bond *bond, int mark)
associates a Bond pointer with a bookmark
void updatePropertyCache(bool strict=true)
calculates any of our lazy properties
ROMol & operator=(const ROMol &)=delete
ATOM_PTR_LIST & getAllAtomsWithBookmark(int mark)
returns all Atoms associated with the bookmark provided
Bond * getBondWithBookmark(int mark)
returns the first Bond associated with the bookmark provided
const Bond * getBondBetweenAtoms(const U idx1, const V idx2) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
BOND_BOOKMARK_MAP * getBondBookmarks()
returns a pointer to all of our bond bookmarks
Atom * getAtomWithIdx(const U idx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Bond * getBondWithIdx(const U idx) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QueryAtomIterator endQueryAtoms()
get an AtomIterator pointing at the end of our Atoms
BOND_PTR_LIST & getAllBondsWithBookmark(int mark)
returns all bonds associated with the bookmark provided
unsigned int addConformer(Conformer *conf, bool assignId=false)
Add a new conformation to the molecule.
Bond * getBondWithIdx(const U idx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void clearAllBondBookmarks()
blows out all bond bookmarks
ATOM_ITER_PAIR getVertices()
returns an iterator pair for looping over all Atoms
BOND_ITER_PAIR getEdges() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend RDKIT_GRAPHMOL_EXPORT std::vector< SubstanceGroup > & getSubstanceGroups(ROMol &)
void clearComputedProps(bool includeRings=true) const
clears all of our computed properties
Atom * operator[](const vertex_descriptor &v)
ROMol(const std::string &binStr, unsigned int propertyFlags)
construct a molecule from a pickle string
ConstAtomIterator beginAtoms() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Bond * getBondWithIdx(unsigned int idx) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
ConstAromaticAtomIterator beginAromaticAtoms() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void debugMol(std::ostream &str) const
const Bond * getBondBetweenAtoms(unsigned int idx1, unsigned int idx2) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setAtomBookmark(Atom *at, int mark)
associates an Atom pointer with a bookmark
const std::vector< StereoGroup > & getStereoGroups() const
Gets a reference to the groups of atoms with relative stereochemistry.
MatchingAtomIterator endMatchingAtoms()
get an AtomIterator pointing at the end of our Atoms
ConstBondIterator beginBonds() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
CXXAtomIterator< MolGraph, Atom * > atoms()
C++11 Range iterator.
BondIterator endBonds()
get a BondIterator pointing at the end of our Bonds
ROMol(const std::string &binStr)
construct a molecule from a pickle string
Atom * getUniqueAtomWithBookmark(int mark)
QueryAtomIterator beginQueryAtoms(QueryAtom const *query)
get an AtomIterator pointing at our first Atom that matches query
ConstHeteroatomIterator endHeteros() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Atom * getAtomWithIdx(unsigned int idx)
returns a pointer to a particular Atom
Atom * getAtomWithBookmark(int mark)
returns the first Atom associated with the bookmark provided
CXXAtomIterator< const MolGraph, Atom *const > atoms() const
void replaceAtomBookmark(Atom *at, int mark)
associates an Atom pointer with a bookmark
CXXBondIterator< MolGraph, Bond *, MolGraph::out_edge_iterator > atomBonds(Atom const *at)
unsigned int getAtomDegree(const Atom *at) const
returns the degree (number of neighbors) of an Atom in the graph
void setStereoGroups(std::vector< StereoGroup > stereo_groups)
Sets groups of atoms with relative stereochemistry.
AromaticAtomIterator endAromaticAtoms()
get an AtomIterator pointing at the end of our Atoms
void clearAllAtomBookmarks()
blows out all atomic bookmarks
ConformerIterator beginConformers()
ConstBondIterator endBonds() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned int getNumAtoms(bool onlyExplicit) const
CXXBondIterator< const MolGraph, Bond *const, MolGraph::out_edge_iterator > atomBonds(Atom const *at) const
const Atom * operator[](const vertex_descriptor &v) const
HeteroatomIterator endHeteros()
get an AtomIterator pointing at the end of our Atoms
ROMol(ROMol &&o) noexcept
Bond * getBondBetweenAtoms(unsigned int idx1, unsigned int idx2)
returns a pointer to the bond between two atoms, Null on failure
ConstConformerIterator beginConformers() const
void clearBondBookmark(int mark, const Bond *bond)
removes a particular Bond from the list associated with the bookmark
ROMol & operator=(ROMol &&o) noexcept
Conformer & getConformer(int id=-1)
friend RDKIT_GRAPHMOL_EXPORT const std::vector< SubstanceGroup > & getSubstanceGroups(const ROMol &)
ATOM_BOOKMARK_MAP * getAtomBookmarks()
returns a pointer to all of our atom bookmarks
MatchingAtomIterator beginMatchingAtoms(bool(*query)(Atom *))
get an AtomIterator pointing at our first Atom that matches query
CXXAtomIterator< const MolGraph, Atom *const, MolGraph::adjacency_iterator > atomNeighbors(Atom const *at) const
bool hasBondBookmark(int mark) const
queries whether or not any bonds are associated with a bookmark
Bond * operator[](const edge_descriptor &e)
CXXAtomIterator< MolGraph, Atom *, MolGraph::adjacency_iterator > atomNeighbors(Atom const *at)
AtomIterator beginAtoms()
get an AtomIterator pointing at our first Atom
Bond * getUniqueBondWithBookmark(int mark)
void removeConformer(unsigned int id)
Delete the conformation with the specified ID.
AromaticAtomIterator beginAromaticAtoms()
get an AtomIterator pointing at our first aromatic Atom
ConstHeteroatomIterator beginHeteros() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Conformer & getConformer(int id=-1) const
ConformerIterator endConformers()
ATOM_ITER_PAIR getVertices() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void clearBondBookmark(int mark)
removes a bookmark from our collection
HeteroatomIterator beginHeteros()
get an AtomIterator pointing at our first hetero Atom
const Atom * getAtomWithIdx(unsigned int idx) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
RWMol is a molecule class that is intended to be edited.
A class to store information about a molecule's rings.
#define RDKIT_GRAPHMOL_EXPORT
std::vector< ROMol > MOL_VECT
MOL_PTR_VECT::const_iterator MOL_PTR_VECT_CI
RDKIT_GRAPHMOL_EXPORT const int ci_RIGHTMOST_ATOM
RDKIT_GRAPHMOL_EXPORT const int ci_ATOM_HOLDER
std::vector< ROMol * > MOL_PTR_VECT
boost::shared_ptr< ROMol > ROMOL_SPTR
MOL_PTR_VECT::iterator MOL_PTR_VECT_I
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, Atom *, Bond * > MolGraph
This is the BGL type used to store the topology:
std::vector< boost::shared_ptr< ROMol > > MOL_SPTR_VECT
RDKIT_GRAPHMOL_EXPORT const int ci_LEADING_BOND
std::forward_iterator_tag iterator_category
std::ptrdiff_t difference_type
CXXAtomIter(Graph *graph, Iterator pos)
CXXAtomIter & operator++()
bool operator!=(const CXXAtomIter &it) const
CXXAtomIterator(Graph *graph, Iterator start, Iterator end)
CXXAtomIterator(Graph *graph)
std::forward_iterator_tag iterator_category
CXXBondIter(Graph *graph, Iterator pos)
std::ptrdiff_t difference_type
bool operator!=(const CXXBondIter &it) const
CXXBondIter & operator++()
CXXBondIterator(Graph *graph)
CXXBondIterator(Graph *graph, Iterator start, Iterator end)