31#include <boost/graph/adjacency_list.hpp>
32#include <boost/smart_ptr.hpp>
33#include <boost/dynamic_bitset.hpp>
35#ifdef RDK_USE_BOOST_SERIALIZATION
36#include <boost/serialization/split_member.hpp>
55typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
64template <
class T1,
class T2>
69template <
class T1,
class T2>
71template <
class T1,
class T2>
73template <
class T1,
class T2>
75template <
class T1,
class T2>
115template <
class Graph,
class Vertex,
116 class Iterator =
typename Graph::vertex_iterator,
117 bool CheckedAtoms =
false,
bool CheckedBonds =
false>
136 if constexpr (CheckedAtoms) {
138 throw std::runtime_error(
"molecule modified during iteration");
141 if constexpr (CheckedBonds) {
143 throw std::runtime_error(
"molecule modified during iteration");
151 if constexpr (CheckedAtoms) {
154 if constexpr (CheckedBonds) {
228 return !(*
this == other);
247 std::ranges::random_access_range<CXXAtomIterator<MolGraph, Atom *>>
248 and std::ranges::sized_range<CXXAtomIterator<MolGraph, Atom *>>
252template <
class Graph,
class Edge,
253 class Iterator =
typename Graph::edge_iterator,
bool Checked =
false>
271 if constexpr (Checked) {
273 throw std::runtime_error(
"molecule modified during iteration");
281 if constexpr (Checked) {
317 return !(*
this == other);
322 auto vs = boost::edges(*
graph);
342 std::ranges::bidirectional_range<CXXBondIterator<MolGraph, Bond *>>);
353 typedef MolGraph::vertex_descriptor vertex_descriptor;
354 typedef MolGraph::edge_descriptor edge_descriptor;
356 typedef MolGraph::edge_iterator EDGE_ITER;
357 typedef MolGraph::out_edge_iterator OEDGE_ITER;
358 typedef MolGraph::vertex_iterator VERTEX_ITER;
359 typedef MolGraph::adjacency_iterator ADJ_ITER;
360 typedef std::pair<EDGE_ITER, EDGE_ITER> BOND_ITER_PAIR;
361 typedef std::pair<OEDGE_ITER, OEDGE_ITER> OBOND_ITER_PAIR;
362 typedef std::pair<VERTEX_ITER, VERTEX_ITER> ATOM_ITER_PAIR;
363 typedef std::pair<ADJ_ITER, ADJ_ITER> ADJ_ITER_PAIR;
365 typedef std::vector<Atom *> ATOM_PTR_VECT;
366 typedef ATOM_PTR_VECT::iterator ATOM_PTR_VECT_I;
367 typedef ATOM_PTR_VECT::const_iterator ATOM_PTR_VECT_CI;
368 typedef std::vector<Bond *> BOND_PTR_VECT;
369 typedef BOND_PTR_VECT::iterator BOND_PTR_VECT_I;
370 typedef BOND_PTR_VECT::const_iterator BOND_PTR_VECT_CI;
372 typedef std::list<Atom *> ATOM_PTR_LIST;
373 typedef ATOM_PTR_LIST::iterator ATOM_PTR_LIST_I;
374 typedef ATOM_PTR_LIST::const_iterator ATOM_PTR_LIST_CI;
375 typedef std::list<Bond *> BOND_PTR_LIST;
376 typedef BOND_PTR_LIST::iterator BOND_PTR_LIST_I;
377 typedef BOND_PTR_LIST::const_iterator BOND_PTR_LIST_CI;
380 typedef std::list<CONFORMER_SPTR> CONF_SPTR_LIST;
381 typedef CONF_SPTR_LIST::iterator CONF_SPTR_LIST_I;
382 typedef CONF_SPTR_LIST::const_iterator CONF_SPTR_LIST_CI;
383 typedef std::pair<CONF_SPTR_LIST_I, CONF_SPTR_LIST_I> CONFS_I_PAIR;
386 typedef std::map<int, ATOM_PTR_LIST> ATOM_BOOKMARK_MAP;
387 typedef std::map<int, BOND_PTR_LIST> BOND_BOOKMARK_MAP;
395 ConstAromaticAtomIterator;
398 ConstHeteroatomIterator;
401 ConstQueryAtomIterator;
404 ConstMatchingAtomIterator;
406 typedef CONF_SPTR_LIST_I ConformerIterator;
407 typedef CONF_SPTR_LIST_CI ConstConformerIterator;
442 return {&d_graph, pr.first, pr.second};
448 return {&d_graph, pr.first, pr.second};
454 return {&d_graph, pr.first, pr.second};
460 return {&d_graph, pr.first, pr.second};
469 return {&d_graph, pr.first, pr.second};
475 return {&d_graph, pr.first, pr.second};
484 return {&d_graph, pr.first, pr.second};
490 return {&d_graph, pr.first, pr.second};
532 ROMol(
const ROMol &other,
bool quickCopy =
false,
int confId = -1)
534 dp_ringInfo =
nullptr;
535 initFromOther(other, quickCopy, confId);
541 ROMol(
const std::string &binStr,
unsigned int propertyFlags);
545 d_graph(std::move(o.d_graph)),
546 d_atomBookmarks(std::move(o.d_atomBookmarks)),
547 d_bondBookmarks(std::move(o.d_bondBookmarks)),
548 d_confs(std::move(o.d_confs)),
549 d_sgroups(std::move(o.d_sgroups)),
550 d_stereo_groups(std::move(o.d_stereo_groups)),
552 for (
auto atom :
atoms()) {
553 atom->setOwningMol(
this);
555 for (
auto bond :
bonds()) {
556 bond->setOwningMol(
this);
558 for (
auto conf : d_confs) {
559 conf->setOwningMol(
this);
561 for (
auto &sg : d_sgroups) {
562 sg.setOwningMol(
this);
566 dp_ringInfo = std::exchange(o.dp_ringInfo,
nullptr);
567 dp_delAtoms = std::exchange(o.dp_delAtoms,
nullptr);
568 dp_delBonds = std::exchange(o.dp_delBonds,
nullptr);
577 dp_ringInfo = std::exchange(o.dp_ringInfo,
nullptr);
579 d_graph = std::move(o.d_graph);
580 d_atomBookmarks = std::move(o.d_atomBookmarks);
581 d_bondBookmarks = std::move(o.d_bondBookmarks);
583 d_confs = std::move(o.d_confs);
584 d_sgroups = std::move(o.d_sgroups);
585 d_stereo_groups = std::move(o.d_stereo_groups);
586 dp_delAtoms = std::exchange(o.dp_delAtoms,
nullptr);
587 dp_delBonds = std::exchange(o.dp_delBonds,
nullptr);
591 for (
auto atom :
atoms()) {
592 atom->setOwningMol(
this);
594 for (
auto bond :
bonds()) {
595 bond->setOwningMol(
this);
597 for (
auto conf : d_confs) {
598 conf->setOwningMol(
this);
600 for (
auto &sg : d_sgroups) {
601 sg.setOwningMol(
this);
666 template <
class U,
class V>
672 template <
class U,
class V>
685 d_atomBookmarks[mark].push_back(at);
689 d_atomBookmarks[mark].clear();
690 d_atomBookmarks[mark].push_back(at);
713 d_bondBookmarks[mark].push_back(bond);
934 bool (*query)(
const Atom *))
const;
945 return d_confs.begin();
948 inline ConstConformerIterator
endConformers()
const {
return d_confs.end(); }
994 return d_stereo_groups;
1006#ifdef RDK_USE_BOOST_SERIALIZATION
1009 template <
class Archive>
1010 void save(Archive &ar,
const unsigned int version)
const;
1011 template <
class Archive>
1012 void load(Archive &ar,
const unsigned int version);
1013 BOOST_SERIALIZATION_SPLIT_MEMBER()
1019 ATOM_BOOKMARK_MAP d_atomBookmarks;
1020 BOND_BOOKMARK_MAP d_bondBookmarks;
1022 CONF_SPTR_LIST d_confs;
1023 std::vector<SubstanceGroup> d_sgroups;
1024 std::vector<StereoGroup> d_stereo_groups;
1025 std::unique_ptr<boost::dynamic_bitset<>> dp_delAtoms =
nullptr;
1026 std::unique_ptr<boost::dynamic_bitset<>> dp_delBonds =
nullptr;
1032 void clearSubstanceGroups() { d_sgroups.clear(); }
1041 virtual void destroy();
1053 unsigned int addAtom(
Atom *atom,
bool updateLabel =
true,
1054 bool takeOwnership =
false);
1064 unsigned int addBond(
Bond *bond,
bool takeOwnership =
false);
1076 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...
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...
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
CXXAtomIterator< const MolGraph, Atom *const > atoms() const
void clearAtomBookmark(int mark)
removes a bookmark from our collection
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
Atom * getAtomWithIdx(unsigned int idx)
returns a pointer to a particular Atom
unsigned int getNumConformers() const
AtomIterator endAtoms()
get an AtomIterator pointing at the end of our Atoms
BOND_PTR_LIST & getAllBondsWithBookmark(int mark)
returns all bonds associated with the bookmark provided
const std::vector< StereoGroup > & getStereoGroups() const
Gets a reference to the groups of atoms with relative stereochemistry.
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
Atom * getAtomWithIdx(const U idx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
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 & operator=(ROMol &&o) noexcept
ROMol(const ROMol &other, bool quickCopy=false, int confId=-1)
copy constructor with a twist
ROMol & operator=(const ROMol &)=delete
Bond * getUniqueBondWithBookmark(int mark)
CXXBondIterator< const MolGraph, Bond *const, MolGraph::edge_iterator, true > checkedBonds() const
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
CXXBondIterator< const MolGraph, Bond *const, MolGraph::out_edge_iterator, true > checkedAtomBonds(Atom const *at) const
CXXAtomIterator< MolGraph, Atom * > atoms()
C++11 Range iterator.
CXXAtomIterator< MolGraph, Atom *, MolGraph::vertex_iterator, true > checkedAtoms()
CXXBondIterator< MolGraph, Bond *, MolGraph::out_edge_iterator, true > checkedAtomBonds(Atom const *at)
Atom * getAtomWithBookmark(int mark)
returns the first Atom associated with the bookmark provided
CXXAtomIterator< const MolGraph, Atom *const, MolGraph::adjacency_iterator > atomNeighbors(Atom const *at) const
BOND_BOOKMARK_MAP * getBondBookmarks()
returns a pointer to all of our bond bookmarks
Conformer & getConformer(int id=-1)
QueryAtomIterator endQueryAtoms()
get an AtomIterator pointing at the end of our Atoms
const Conformer & getConformer(int id=-1) const
unsigned int addConformer(Conformer *conf, bool assignId=false)
Add a new conformation to the molecule.
const Atom * operator[](const vertex_descriptor &v) const
bool hasQuery() const
if the Mol has any Query atoms or bonds
void clearAllBondBookmarks()
blows out all bond bookmarks
const Atom * getAtomWithIdx(const U idx) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
CXXBondIterator< MolGraph, Bond * > bonds()
ATOM_ITER_PAIR getVertices()
returns an iterator pair for looping over all Atoms
friend RDKIT_GRAPHMOL_EXPORT std::vector< SubstanceGroup > & getSubstanceGroups(ROMol &)
BOND_ITER_PAIR getEdges() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void clearComputedProps(bool includeRings=true) const
clears all of our computed properties
const Bond * getBondWithIdx(const U idx) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
ATOM_PTR_LIST & getAllAtomsWithBookmark(int mark)
returns all Atoms associated with the bookmark provided
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...
ROMol(const std::string &binStr, unsigned int propertyFlags)
construct a molecule from a pickle string
Bond * getBondWithIdx(const U idx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
ATOM_BOOKMARK_MAP * getAtomBookmarks()
returns a pointer to all of our atom bookmarks
ConstAtomIterator beginAtoms() 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...
CXXAtomIterator< MolGraph, Atom *, MolGraph::adjacency_iterator > atomNeighbors(Atom const *at)
void debugMol(std::ostream &str) const
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...
std::string getName() const
void setAtomBookmark(Atom *at, int mark)
associates an Atom pointer with a bookmark
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...
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...
void clearPropertyCache()
void replaceAtomBookmark(Atom *at, int mark)
associates an Atom pointer with a bookmark
Bond * getBondWithBookmark(int mark)
returns the first Bond associated with the bookmark provided
CXXAtomIterator< MolGraph, Atom *, MolGraph::adjacency_iterator, true, true > checkedAtomNeighbors(Atom const *at)
CXXBondIterator< const MolGraph, Bond *const, MolGraph::out_edge_iterator > atomBonds(Atom const *at) const
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.
CXXBondIterator< MolGraph, Bond *, MolGraph::out_edge_iterator > atomBonds(Atom const *at)
AromaticAtomIterator endAromaticAtoms()
get an AtomIterator pointing at the end of our Atoms
RingInfo * getRingInfo() const
CXXBondIterator< MolGraph, Bond *, MolGraph::edge_iterator, true > checkedBonds()
void clearAllAtomBookmarks()
blows out all atomic bookmarks
const Bond * operator[](const edge_descriptor &e) const
Bond * operator[](const edge_descriptor &e)
Bond * getBondWithIdx(unsigned int idx)
returns a pointer to a particular Bond
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
CXXAtomIterator< const MolGraph, Atom *const, MolGraph::adjacency_iterator, true, true > checkedAtomNeighbors(Atom const *at) const
HeteroatomIterator endHeteros()
get an AtomIterator pointing at the end of our Atoms
ROMol(ROMol &&o) noexcept
Bond * getBondBetweenAtoms(const U idx1, const V idx2)
This is an overloaded member function, provided for convenience. It differs from the above function o...
ConstConformerIterator beginConformers() const
void clearBondBookmark(int mark, const Bond *bond)
removes a particular Bond from the list associated with the bookmark
MatchingAtomIterator beginMatchingAtoms(bool(*query)(Atom *))
get an AtomIterator pointing at our first Atom that matches query
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
bool hasBondBookmark(int mark) const
queries whether or not any bonds are associated with a bookmark
const Bond * getBondWithIdx(unsigned int idx) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
AtomIterator beginAtoms()
get an AtomIterator pointing at our first Atom
const Atom * getAtomWithIdx(unsigned int idx) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void removeConformer(unsigned int id)
Delete the conformation with the specified ID.
AromaticAtomIterator beginAromaticAtoms()
get an AtomIterator pointing at our first aromatic Atom
Atom * operator[](const vertex_descriptor &v)
ConstHeteroatomIterator beginHeteros() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setName(const std::string &name) const
sets the molecule name/title; equivalent to setting the _Name property
ConformerIterator endConformers()
ATOM_ITER_PAIR getVertices() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
friend RDKIT_GRAPHMOL_EXPORT const std::vector< SubstanceGroup > & getSubstanceGroups(const ROMol &)
CXXAtomIterator< const MolGraph, Atom *const, MolGraph::vertex_iterator, true > checkedAtoms() const
void clearBondBookmark(int mark)
removes a bookmark from our collection
HeteroatomIterator beginHeteros()
get an AtomIterator pointing at our first hetero Atom
Bond * getBondBetweenAtoms(unsigned int idx1, unsigned int idx2)
returns a pointer to the bond between two atoms, Null on failure
CXXBondIterator< const MolGraph, Bond *const > bonds() const
RWMol is a molecule class that is intended to be edited.
The class for representing SubstanceGroups.
#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
const_reference operator*() const
CXXAtomIter(Graph *graph, Iterator pos)
bool operator>(const CXXAtomIter &other) const
CXXAtomIter & operator--()
CXXAtomIter operator++(int)
void checkIterator() const
CXXAtomIter operator-(difference_type n) const
CXXAtomIter & operator-=(difference_type n)
CXXAtomIter & operator++()
bool operator<=(const CXXAtomIter &other) const
Vertex const & const_reference
bool operator==(const CXXAtomIter &other) const
bool operator!=(const CXXAtomIter &other) const
CXXAtomIter & operator+=(difference_type n)
bool operator>=(const CXXAtomIter &other) const
std::random_access_iterator_tag iterator_category
friend CXXAtomIter operator+(difference_type n, const CXXAtomIter &it)
const_reference operator[](difference_type n) const
CXXAtomIter operator+(difference_type n) const
bool operator<(const CXXAtomIter &other) const
difference_type operator-(const CXXAtomIter &other) const
std::ptrdiff_t difference_type
CXXAtomIter operator--(int)
CXXAtomIterator(Graph *graph)
CXXAtomIterator(Graph *graph, Iterator start, Iterator end)
CXXBondIter operator--(int)
CXXBondIter operator++(int)
void checkIterator() const
std::ptrdiff_t difference_type
bool operator==(const CXXBondIter &other) const
bool operator!=(const CXXBondIter &other) const
Edge const & const_reference
std::bidirectional_iterator_tag iterator_category
const_reference operator*() const
CXXBondIter & operator++()
CXXBondIter(Graph *graph, Iterator pos)
CXXBondIter & operator--()
CXXBondIterator(Graph *graph)
CXXBondIterator(Graph *graph, Iterator start, Iterator end)