RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
ROMol.h
Go to the documentation of this file.
1//
2// Copyright (C) 2003-2022 Greg Landrum and other RDKit contributors
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10/*! \file ROMol.h
11
12 \brief Defines the primary molecule class \c ROMol as well as associated
13 typedefs
14
15*/
16
17#include <RDGeneral/export.h>
18#ifndef RD_ROMOL_H
19#define RD_ROMOL_H
20
21/// Std stuff
22#include <cstddef>
23#include <iterator>
24#include <utility>
25#include <map>
26
27// boost stuff
29#include <boost/graph/adjacency_list.hpp>
30#include <boost/smart_ptr.hpp>
31#include <boost/dynamic_bitset.hpp>
32
33#ifdef RDK_USE_BOOST_SERIALIZATION
34#include <boost/serialization/split_member.hpp>
35#endif
37
38// our stuff
39#include <RDGeneral/types.h>
40#include <RDGeneral/RDProps.h>
41#include "Atom.h"
42#include "Bond.h"
43#include "Conformer.h"
44#include "SubstanceGroup.h"
45#include "StereoGroup.h"
46#include "RingInfo.h"
47
48namespace RDKit {
49class SubstanceGroup;
50class Atom;
51class Bond;
52//! This is the BGL type used to store the topology:
53typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
54 Atom *, Bond *>
56class MolPickler;
57class RWMol;
58class QueryAtom;
59class QueryBond;
60class RingInfo;
61
62template <class T1, class T2>
63class AtomIterator_;
64class BondIterator_;
66
67template <class T1, class T2>
69template <class T1, class T2>
71template <class T1, class T2>
73template <class T1, class T2>
75
79
80//! ROMol is a molecule class that is intended to have a fixed topology
81/*!
82 This is the primary class for most molecule operations.
83
84 If you need to be manipulating the molecule (e.g. adding or deleting
85 atoms or bonds, use an RWMol instead.
86
87 <b>Notes:</b>
88 - each ROMol maintains a Dict of \c properties:
89 - Each \c property is keyed by name and can store an
90 arbitrary type.
91 - \c Properties can be marked as \c calculated, in which case
92 they will be cleared when the \c clearComputedProps() method
93 is called.
94 - Because they have no impact upon chemistry, all \c property
95 operations are \c const, this allows extra flexibility for
96 clients who need to store extra data on ROMol objects.
97
98 - each ROMol has collections of \c bookmarks for Atoms and Bonds:
99 - the Atom bookmarks and Bond bookmarks are stored separately
100 from each other
101 - each \c bookmark, an integer, can map to more than one
102 Atom or Bond
103 - these are currently used in molecule construction, but
104 could also be useful for reaction mapping and the like
105
106 - information about rings (SSSR and the like) is stored in the
107 molecule's RingInfo pointer.
108
109 */
110
111//! \name C++11 Iterators
112
113template <class Graph, class Vertex,
114 class Iterator = typename Graph::vertex_iterator>
116 Graph *graph;
118
119 struct CXXAtomIter {
120 using iterator_category = std::forward_iterator_tag;
121 using difference_type = std::ptrdiff_t;
123 using pointer = Vertex *;
124 using reference = Vertex &;
125
126 Graph *graph;
129
132
134 current = (*graph)[*pos];
135 return current;
136 }
138 ++pos;
139 return *this;
140 }
141 bool operator==(const CXXAtomIter &it) const { return pos == it.pos; }
142 bool operator!=(const CXXAtomIter &it) const { return pos != it.pos; }
143 };
144
146 auto vs = boost::vertices(*graph);
147 vstart = vs.first;
148 vend = vs.second;
149 }
152 CXXAtomIter begin() { return {graph, vstart}; }
153 CXXAtomIter end() { return {graph, vend}; }
154};
155
156template <class Graph, class Edge,
157 class Iterator = typename Graph::edge_iterator>
159 Graph *graph;
161
162 struct CXXBondIter {
163 using iterator_category = std::forward_iterator_tag;
164 using difference_type = std::ptrdiff_t;
165 using value_type = Edge;
166 using pointer = Edge *;
167 using reference = Edge &;
168
169 Graph *graph;
172
175
177 current = (*graph)[*pos];
178 return current;
179 }
181 ++pos;
182 return *this;
183 }
184 bool operator==(const CXXBondIter &it) const { return pos == it.pos; }
185 bool operator!=(const CXXBondIter &it) const { return pos != it.pos; }
186 };
187
189 auto vs = boost::edges(*graph);
190 vstart = vs.first;
191 vend = vs.second;
192 }
195 CXXBondIter begin() { return {graph, vstart}; }
196 CXXBondIter end() { return {graph, vend}; }
197};
198
200 public:
201 friend class MolPickler;
202 friend class RWMol;
203
204 //! \cond TYPEDEFS
205
206 //! \name typedefs
207 //! @{
208 typedef MolGraph::vertex_descriptor vertex_descriptor;
209 typedef MolGraph::edge_descriptor edge_descriptor;
210
211 typedef MolGraph::edge_iterator EDGE_ITER;
212 typedef MolGraph::out_edge_iterator OEDGE_ITER;
213 typedef MolGraph::vertex_iterator VERTEX_ITER;
214 typedef MolGraph::adjacency_iterator ADJ_ITER;
215 typedef std::pair<EDGE_ITER, EDGE_ITER> BOND_ITER_PAIR;
216 typedef std::pair<OEDGE_ITER, OEDGE_ITER> OBOND_ITER_PAIR;
217 typedef std::pair<VERTEX_ITER, VERTEX_ITER> ATOM_ITER_PAIR;
218 typedef std::pair<ADJ_ITER, ADJ_ITER> ADJ_ITER_PAIR;
219
220 typedef std::vector<Atom *> ATOM_PTR_VECT;
221 typedef ATOM_PTR_VECT::iterator ATOM_PTR_VECT_I;
222 typedef ATOM_PTR_VECT::const_iterator ATOM_PTR_VECT_CI;
223 typedef std::vector<Bond *> BOND_PTR_VECT;
224 typedef BOND_PTR_VECT::iterator BOND_PTR_VECT_I;
225 typedef BOND_PTR_VECT::const_iterator BOND_PTR_VECT_CI;
226
227 typedef std::list<Atom *> ATOM_PTR_LIST;
228 typedef ATOM_PTR_LIST::iterator ATOM_PTR_LIST_I;
229 typedef ATOM_PTR_LIST::const_iterator ATOM_PTR_LIST_CI;
230 typedef std::list<Bond *> BOND_PTR_LIST;
231 typedef BOND_PTR_LIST::iterator BOND_PTR_LIST_I;
232 typedef BOND_PTR_LIST::const_iterator BOND_PTR_LIST_CI;
233
234 // list of conformations
235 typedef std::list<CONFORMER_SPTR> CONF_SPTR_LIST;
236 typedef CONF_SPTR_LIST::iterator CONF_SPTR_LIST_I;
237 typedef CONF_SPTR_LIST::const_iterator CONF_SPTR_LIST_CI;
238 typedef std::pair<CONF_SPTR_LIST_I, CONF_SPTR_LIST_I> CONFS_I_PAIR;
239
240 // ROFIX: these will need to be readonly somehow?
241 typedef std::map<int, ATOM_PTR_LIST> ATOM_BOOKMARK_MAP;
242 typedef std::map<int, BOND_PTR_LIST> BOND_BOOKMARK_MAP;
243
244 typedef class AtomIterator_<Atom, ROMol> AtomIterator;
245 typedef class AtomIterator_<const Atom, const ROMol> ConstAtomIterator;
246 typedef class BondIterator_ BondIterator;
247 typedef class ConstBondIterator_ ConstBondIterator;
248 typedef class AromaticAtomIterator_<Atom, ROMol> AromaticAtomIterator;
249 typedef class AromaticAtomIterator_<const Atom, const ROMol>
250 ConstAromaticAtomIterator;
251 typedef class HeteroatomIterator_<Atom, ROMol> HeteroatomIterator;
252 typedef class HeteroatomIterator_<const Atom, const ROMol>
253 ConstHeteroatomIterator;
254 typedef class QueryAtomIterator_<Atom, ROMol> QueryAtomIterator;
255 typedef class QueryAtomIterator_<const Atom, const ROMol>
256 ConstQueryAtomIterator;
257 typedef class MatchingAtomIterator_<Atom, ROMol> MatchingAtomIterator;
258 typedef class MatchingAtomIterator_<const Atom, const ROMol>
259 ConstMatchingAtomIterator;
260
261 typedef CONF_SPTR_LIST_I ConformerIterator;
262 typedef CONF_SPTR_LIST_CI ConstConformerIterator;
263
264 //! @}
265 //! \endcond
266
267 //! C++11 Range iterator
268 /*!
269 <b>Usage</b>
270 \code
271 for(auto atom : mol.atoms()) {
272 atom->getIdx();
273 };
274 \endcode
275 */
276
278
280 return {&d_graph};
281 }
282
284 atomNeighbors(Atom const *at) const {
285 auto pr = getAtomNeighbors(at);
286 return {&d_graph, pr.first, pr.second};
287 }
288
290 Atom const *at) {
291 auto pr = getAtomNeighbors(at);
292 return {&d_graph, pr.first, pr.second};
293 }
294
296 atomBonds(Atom const *at) const {
297 auto pr = getAtomBonds(at);
298 return {&d_graph, pr.first, pr.second};
299 }
300
302 Atom const *at) {
303 auto pr = getAtomBonds(at);
304 return {&d_graph, pr.first, pr.second};
305 }
306
307 /*!
308 <b>Usage</b>
309 \code
310 for(auto bond : mol.bonds()) {
311 bond->getIdx();
312 };
313 \endcode
314 */
315
317
319 return {&d_graph};
320 }
321
322 ROMol() : RDProps() { initMol(); }
323
324 //! copy constructor with a twist
325 /*!
326 \param other the molecule to be copied
327 \param quickCopy (optional) if this is true, the resulting ROMol will not
328 copy any of the properties or bookmarks and conformers from \c other.
329 This can
330 make the copy substantially faster (thus the name).
331 \param confId (optional) if this is >=0, the resulting ROMol will contain
332 only
333 the specified conformer from \c other.
334 */
335 ROMol(const ROMol &other, bool quickCopy = false, int confId = -1)
336 : RDProps() {
337 dp_ringInfo = nullptr;
338 initFromOther(other, quickCopy, confId);
339 numBonds = rdcast<unsigned int>(boost::num_edges(d_graph));
340 }
341 //! construct a molecule from a pickle string
342 ROMol(const std::string &binStr);
343 //! construct a molecule from a pickle string
344 ROMol(const std::string &binStr, unsigned int propertyFlags);
345
346 ROMol(ROMol &&o) noexcept
347 : RDProps(std::move(o)),
348 d_graph(std::move(o.d_graph)),
349 d_atomBookmarks(std::move(o.d_atomBookmarks)),
350 d_bondBookmarks(std::move(o.d_bondBookmarks)),
351 d_confs(std::move(o.d_confs)),
352 d_sgroups(std::move(o.d_sgroups)),
353 d_stereo_groups(std::move(o.d_stereo_groups)),
354 numBonds(o.numBonds) {
355 for (auto atom : atoms()) {
356 atom->setOwningMol(this);
357 }
358 for (auto bond : bonds()) {
359 bond->setOwningMol(this);
360 }
361 for (auto conf : d_confs) {
362 conf->setOwningMol(this);
363 }
364 for (auto &sg : d_sgroups) {
365 sg.setOwningMol(this);
366 }
367 o.d_graph.clear();
368 o.numBonds = 0;
369 dp_ringInfo = std::exchange(o.dp_ringInfo, nullptr);
370 dp_delAtoms = std::exchange(o.dp_delAtoms, nullptr);
371 dp_delBonds = std::exchange(o.dp_delBonds, nullptr);
372 }
373 ROMol &operator=(ROMol &&o) noexcept {
374 if (this == &o) {
375 return *this;
376 }
377 RDProps::operator=(std::move(o));
378 d_graph = std::move(o.d_graph);
379 d_atomBookmarks = std::move(o.d_atomBookmarks);
380 d_bondBookmarks = std::move(o.d_bondBookmarks);
381 if (dp_ringInfo) {
382 delete dp_ringInfo;
383 }
384 dp_ringInfo = std::exchange(o.dp_ringInfo, nullptr);
385
386 d_confs = std::move(o.d_confs);
387 d_sgroups = std::move(o.d_sgroups);
388 d_stereo_groups = std::move(o.d_stereo_groups);
389 dp_delAtoms = std::exchange(o.dp_delAtoms, nullptr);
390 dp_delBonds = std::exchange(o.dp_delBonds, nullptr);
391 numBonds = o.numBonds;
392 o.numBonds = 0;
393
394 for (auto atom : atoms()) {
395 atom->setOwningMol(this);
396 }
397 for (auto bond : bonds()) {
398 bond->setOwningMol(this);
399 }
400 for (auto conf : d_confs) {
401 conf->setOwningMol(this);
402 }
403 for (auto &sg : d_sgroups) {
404 sg.setOwningMol(this);
405 }
406
407 o.d_graph.clear();
408 return *this;
409 }
410
412 delete; // disable assignment, RWMol's support assignment
413
414 virtual ~ROMol() { destroy(); }
415
416 //! @}
417 //! \name Atoms
418 //! @{
419
420 //! returns our number of atoms
421 inline unsigned int getNumAtoms() const {
422 return rdcast<unsigned int>(boost::num_vertices(d_graph));
423 }
424 unsigned int getNumAtoms(bool onlyExplicit) const;
425 //! returns our number of heavy atoms (atomic number > 1)
426 unsigned int getNumHeavyAtoms() const;
427 //! returns a pointer to a particular Atom
428 Atom *getAtomWithIdx(unsigned int idx);
429 //! \overload
430 const Atom *getAtomWithIdx(unsigned int idx) const;
431 //! \overload
432 template <class U>
433 Atom *getAtomWithIdx(const U idx) {
434 return getAtomWithIdx(rdcast<unsigned int>(idx));
435 }
436 //! \overload
437 template <class U>
438 const Atom *getAtomWithIdx(const U idx) const {
439 return getAtomWithIdx(rdcast<unsigned int>(idx));
440 }
441 //! returns the degree (number of neighbors) of an Atom in the graph
442 unsigned int getAtomDegree(const Atom *at) const;
443 //! @}
444
445 //! \name Bonds
446 //! @{
447
448 //! returns our number of Bonds
449 unsigned int getNumBonds(bool onlyHeavy = 1) const;
450 //! returns a pointer to a particular Bond
451 Bond *getBondWithIdx(unsigned int idx);
452 //! \overload
453 const Bond *getBondWithIdx(unsigned int idx) const;
454 //! \overload
455 template <class U>
456 Bond *getBondWithIdx(const U idx) {
457 return getBondWithIdx(rdcast<unsigned int>(idx));
458 }
459 //! \overload
460 template <class U>
461 const Bond *getBondWithIdx(const U idx) const {
462 return getBondWithIdx(rdcast<unsigned int>(idx));
463 }
464 //! returns a pointer to the bond between two atoms, Null on failure
465 Bond *getBondBetweenAtoms(unsigned int idx1, unsigned int idx2);
466 //! \overload
467 const Bond *getBondBetweenAtoms(unsigned int idx1, unsigned int idx2) const;
468 //! \overload
469 template <class U, class V>
470 Bond *getBondBetweenAtoms(const U idx1, const V idx2) {
471 return getBondBetweenAtoms(rdcast<unsigned int>(idx1),
472 rdcast<unsigned int>(idx2));
473 }
474 //! \overload
475 template <class U, class V>
476 const Bond *getBondBetweenAtoms(const U idx1, const V idx2) const {
477 return getBondBetweenAtoms(rdcast<unsigned int>(idx1),
478 rdcast<unsigned int>(idx2));
479 }
480
481 //! @}
482
483 //! \name Bookmarks
484 //! @{
485
486 //! associates an Atom pointer with a bookmark
487 void setAtomBookmark(Atom *at, int mark) {
488 d_atomBookmarks[mark].push_back(at);
489 }
490 //! associates an Atom pointer with a bookmark
491 void replaceAtomBookmark(Atom *at, int mark) {
492 d_atomBookmarks[mark].clear();
493 d_atomBookmarks[mark].push_back(at);
494 }
495 //! returns the first Atom associated with the \c bookmark provided
497 //! returns the Atom associated with the \c bookmark provided
498 //! a check is made to ensure it is the only atom with that bookmark
500 //! returns all Atoms associated with the \c bookmark provided
501 ATOM_PTR_LIST &getAllAtomsWithBookmark(int mark);
502 //! removes a \c bookmark from our collection
503 void clearAtomBookmark(int mark);
504 //! removes a particular Atom from the list associated with the \c bookmark
505 void clearAtomBookmark(int mark, const Atom *atom);
506
507 //! blows out all atomic \c bookmarks
508 void clearAllAtomBookmarks() { d_atomBookmarks.clear(); }
509 //! queries whether or not any atoms are associated with a \c bookmark
510 bool hasAtomBookmark(int mark) const { return d_atomBookmarks.count(mark); }
511 //! returns a pointer to all of our atom \c bookmarks
512 ATOM_BOOKMARK_MAP *getAtomBookmarks() { return &d_atomBookmarks; }
513
514 //! associates a Bond pointer with a bookmark
515 void setBondBookmark(Bond *bond, int mark) {
516 d_bondBookmarks[mark].push_back(bond);
517 }
518 //! returns the first Bond associated with the \c bookmark provided
520 //! returns the Bond associated with the \c bookmark provided
521 //! a check is made to ensure it is the only bond with that bookmark
523 //! returns all bonds associated with the \c bookmark provided
524 BOND_PTR_LIST &getAllBondsWithBookmark(int mark);
525 //! removes a \c bookmark from our collection
526 void clearBondBookmark(int mark);
527 //! removes a particular Bond from the list associated with the \c bookmark
528 void clearBondBookmark(int mark, const Bond *bond);
529
530 //! blows out all bond \c bookmarks
531 void clearAllBondBookmarks() { d_bondBookmarks.clear(); }
532 //! queries whether or not any bonds are associated with a \c bookmark
533 bool hasBondBookmark(int mark) const { return d_bondBookmarks.count(mark); }
534 //! returns a pointer to all of our bond \c bookmarks
535 BOND_BOOKMARK_MAP *getBondBookmarks() { return &d_bondBookmarks; }
536
537 //! @}
538
539 //! \name Conformers
540 //! @{
541
542 //! return the conformer with a specified ID
543 //! if the ID is negative the first conformation will be returned
544 const Conformer &getConformer(int id = -1) const;
545
546 //! return the conformer with a specified ID
547 //! if the ID is negative the first conformation will be returned
548 Conformer &getConformer(int id = -1);
549
550 //! Delete the conformation with the specified ID
551 void removeConformer(unsigned int id);
552
553 //! Clear all the conformations on the molecule
554 void clearConformers() { d_confs.clear(); }
555
556 //! Add a new conformation to the molecule
557 /*!
558 \param conf - conformation to be added to the molecule, this molecule takes
559 ownership
560 of the conformer
561 \param assignId - a unique ID will be assigned to the conformation if
562 true
563 otherwise it is assumed that the conformation already has
564 an (unique) ID set
565 */
566 unsigned int addConformer(Conformer *conf, bool assignId = false);
567
568 inline unsigned int getNumConformers() const {
569 return rdcast<unsigned int>(d_confs.size());
570 }
571
572 //! \name Topology
573 //! @{
574
575 //! returns a pointer to our RingInfo structure
576 //! <b>Note:</b> the client should not delete this.
577 RingInfo *getRingInfo() const { return dp_ringInfo; }
578
579 //! provides access to all neighbors around an Atom
580 /*!
581 \param at the atom whose neighbors we are looking for
582
583 <b>Usage</b>
584 \code
585 ... mol is a const ROMol & ...
586 ... atomPtr is a const Atom * ...
587 ... requires #include <boost/range/iterator_range.hpp>
588 for (const auto &nbri :
589 boost::make_iterator_range(m.getAtomNeighbors(atomPtr))) {
590 const auto &nbr = (*m)[nbri];
591 // nbr is an atom pointer
592 }
593
594 \endcode
595
596 */
597 ADJ_ITER_PAIR getAtomNeighbors(Atom const *at) const;
598
599 //! provides access to all Bond objects connected to an Atom
600 /*!
601 \param at the atom whose neighbors we are looking for
602
603 <b>Usage</b>
604 \code
605 ... mol is a const ROMol & ...
606 ... atomPtr is a const Atom * ...
607 ... requires #include <boost/range/iterator_range.hpp>
608 for (const auto &nbri :
609 boost::make_iterator_range(m.getAtomBonds(atomPtr))) {
610 const auto &nbr = (*m)[nbri];
611 // nbr is a bond pointer
612 }
613 \endcode
614 or, if you need a non-const Bond *:
615 \code
616 ... mol is a const ROMol & ...
617 ... atomPtr is a const Atom * ...
618 ... requires #include <boost/range/iterator_range.hpp>
619 for (const auto &nbri :
620 boost::make_iterator_range(m.getAtomBonds(atomPtr))) {
621 auto nbr = (*m)[nbri];
622 // nbr is a bond pointer
623 }
624 \endcode
625
626
627 */
628 OBOND_ITER_PAIR getAtomBonds(Atom const *at) const;
629
630 //! returns an iterator pair for looping over all Atoms
631 /*!
632
633 <b>Usage</b>
634 \code
635
636 ROMol::VERTEX_ITER atBegin,atEnd;
637 boost::tie(atBegin,atEnd) = mol.getVertices();
638 while(atBegin!=atEnd){
639 ATOM_SPTR at2=mol[*atBegin];
640 ... do something with the Atom ...
641 ++atBegin;
642 }
643 \endcode
644 */
645 ATOM_ITER_PAIR getVertices();
646 //! returns an iterator pair for looping over all Bonds
647 /*!
648
649 <b>Usage</b>
650 \code
651
652 ROMol::EDGE_ITER firstB,lastB;
653 boost::tie(firstB,lastB) = mol.getEdges();
654 while(firstB!=lastB){
655 BOND_SPTR bond = mol[*firstB];
656 ... do something with the Bond ...
657 ++firstB;
658 }
659 \endcode
660 */
661 BOND_ITER_PAIR getEdges();
662 //! \overload
663 ATOM_ITER_PAIR getVertices() const;
664 //! \overload
665 BOND_ITER_PAIR getEdges() const;
666
667 //! brief returns a pointer to our underlying BGL object
668 /*!
669 This can be useful if you need to call other BGL algorithms:
670
671 Here's an example:
672 \code
673 ... mol is a const ROMol ...
674 ... mapping is an INT_VECT ...
675 mapping.resize(mol.getNumAtoms());
676 const MolGraph &G_p = mol.getTopology();
677 int res = boost::connected_components(G_p,&mapping[0]);
678 \endcode
679 */
680 MolGraph const &getTopology() const { return d_graph; }
681 //! @}
682
683 //! \name Iterators
684 //! @{
685
686 //! get an AtomIterator pointing at our first Atom
687 AtomIterator beginAtoms();
688 //! \overload
689 ConstAtomIterator beginAtoms() const;
690 //! get an AtomIterator pointing at the end of our Atoms
691 AtomIterator endAtoms();
692 //! \overload
693 ConstAtomIterator endAtoms() const;
694 //! get a BondIterator pointing at our first Bond
695 BondIterator beginBonds();
696 //! \overload
697 ConstBondIterator beginBonds() const;
698 //! get a BondIterator pointing at the end of our Bonds
699 BondIterator endBonds();
700 //! \overload
701 ConstBondIterator endBonds() const;
702
703 //! get an AtomIterator pointing at our first aromatic Atom
704 AromaticAtomIterator beginAromaticAtoms();
705 //! \overload
706 ConstAromaticAtomIterator beginAromaticAtoms() const;
707 //! get an AtomIterator pointing at the end of our Atoms
708 AromaticAtomIterator endAromaticAtoms();
709 //! \overload
710 ConstAromaticAtomIterator endAromaticAtoms() const;
711
712 //! get an AtomIterator pointing at our first hetero Atom
713 HeteroatomIterator beginHeteros();
714 //! \overload
715 ConstHeteroatomIterator beginHeteros() const;
716 //! get an AtomIterator pointing at the end of our Atoms
717 HeteroatomIterator endHeteros();
718 //! \overload
719 ConstHeteroatomIterator endHeteros() const;
720
721 //! if the Mol has any Query atoms or bonds
722 bool hasQuery() const;
723
724 //! get an AtomIterator pointing at our first Atom that matches \c query
725 QueryAtomIterator beginQueryAtoms(QueryAtom const *query);
726 //! \overload
727 ConstQueryAtomIterator beginQueryAtoms(QueryAtom const *) const;
728 //! get an AtomIterator pointing at the end of our Atoms
729 QueryAtomIterator endQueryAtoms();
730 //! \overload
731 ConstQueryAtomIterator endQueryAtoms() const;
732
733 //! get an AtomIterator pointing at our first Atom that matches \c query
734 MatchingAtomIterator beginMatchingAtoms(bool (*query)(Atom *));
735 //! \overload
736 ConstMatchingAtomIterator beginMatchingAtoms(
737 bool (*query)(const Atom *)) const;
738 //! get an AtomIterator pointing at the end of our Atoms
739 MatchingAtomIterator endMatchingAtoms();
740 //! \overload
741 ConstMatchingAtomIterator endMatchingAtoms() const;
742
743 inline ConformerIterator beginConformers() { return d_confs.begin(); }
744
745 inline ConformerIterator endConformers() { return d_confs.end(); }
746
747 inline ConstConformerIterator beginConformers() const {
748 return d_confs.begin();
749 }
750
751 inline ConstConformerIterator endConformers() const { return d_confs.end(); }
752
753 //! @}
754
755 //! \name Properties
756 //! @{
757
758 //! clears all of our \c computed \c properties
759 void clearComputedProps(bool includeRings = true) const;
760 //! calculates any of our lazy \c properties
761 /*!
762 <b>Notes:</b>
763 - this calls \c updatePropertyCache() on each of our Atoms and Bonds
764 */
765 void updatePropertyCache(bool strict = true);
766
768
769 //! @}
770
771 //! \name Misc
772 //! @{
773 //! sends some debugging info to a stream
774 void debugMol(std::ostream &str) const;
775 //! @}
776
777 Atom *operator[](const vertex_descriptor &v) { return d_graph[v]; }
778 const Atom *operator[](const vertex_descriptor &v) const {
779 return d_graph[v];
780 }
781
782 Bond *operator[](const edge_descriptor &e) { return d_graph[e]; }
783 const Bond *operator[](const edge_descriptor &e) const { return d_graph[e]; }
784
785 //! Gets a reference to the groups of atoms with relative stereochemistry
786 /*!
787 Stereo groups are also called enhanced stereochemistry in the SDF/Mol3000
788 file format.
789 */
790 const std::vector<StereoGroup> &getStereoGroups() const {
791 return d_stereo_groups;
792 }
793
794 //! Sets groups of atoms with relative stereochemistry
795 /*!
796 \param stereo_groups the new set of stereo groups. All will be replaced.
797
798 Stereo groups are also called enhanced stereochemistry in the SDF/Mol3000
799 file format. stereo_groups should be std::move()ed into this function.
800 */
801 void setStereoGroups(std::vector<StereoGroup> stereo_groups);
802
803#ifdef RDK_USE_BOOST_SERIALIZATION
804 //! \name boost::serialization support
805 //! @{
806 template <class Archive>
807 void save(Archive &ar, const unsigned int version) const;
808 template <class Archive>
809 void load(Archive &ar, const unsigned int version);
810 BOOST_SERIALIZATION_SPLIT_MEMBER()
811 //! @}
812#endif
813
814 private:
815 MolGraph d_graph;
816 ATOM_BOOKMARK_MAP d_atomBookmarks;
817 BOND_BOOKMARK_MAP d_bondBookmarks;
818 RingInfo *dp_ringInfo = nullptr;
819 CONF_SPTR_LIST d_confs;
820 std::vector<SubstanceGroup> d_sgroups;
821 std::vector<StereoGroup> d_stereo_groups;
822 std::unique_ptr<boost::dynamic_bitset<>> dp_delAtoms = nullptr;
823 std::unique_ptr<boost::dynamic_bitset<>> dp_delBonds = nullptr;
824
825 friend RDKIT_GRAPHMOL_EXPORT std::vector<SubstanceGroup> &getSubstanceGroups(
826 ROMol &);
827 friend RDKIT_GRAPHMOL_EXPORT const std::vector<SubstanceGroup> &
829 void clearSubstanceGroups() { d_sgroups.clear(); }
830
831 protected:
832 unsigned int numBonds{0};
833#ifndef WIN32
834 private:
835#endif
836 void initMol();
837 virtual void destroy();
838 //! adds an Atom to our collection
839 /*!
840 \param atom pointer to the Atom to add
841 \param updateLabel (optional) if this is true, the new Atom will be
842 our \c activeAtom
843 \param takeOwnership (optional) if this is true, we take ownership of \c
844 atom
845 instead of copying it.
846
847 \return the index of the new atom
848 */
849 unsigned int addAtom(Atom *atom, bool updateLabel = true,
850 bool takeOwnership = false);
851 //! adds a Bond to our collection
852 /*!
853 \param bond pointer to the Bond to add
854 \param takeOwnership (optional) if this is true, we take ownership of \c
855 bond
856 instead of copying it.
857
858 \return the new number of bonds
859 */
860 unsigned int addBond(Bond *bond, bool takeOwnership = false);
861
862 //! adds a Bond to our collection
863 /*!
864 \param bond pointer to the Bond to add
865
866 \return the new number of bonds
867
868 <b>Note:</b> since this is using a smart pointer, we don't need to worry
869 about
870 issues of ownership.
871 */
872 void initFromOther(const ROMol &other, bool quickCopy, int confId);
873};
874
875typedef std::vector<ROMol> MOL_VECT;
876typedef boost::shared_ptr<ROMol> ROMOL_SPTR;
877typedef std::vector<ROMol *> MOL_PTR_VECT;
878typedef std::vector<ROMOL_SPTR> MOL_SPTR_VECT;
879
880typedef MOL_PTR_VECT::const_iterator MOL_PTR_VECT_CI;
881typedef MOL_PTR_VECT::iterator MOL_PTR_VECT_I;
882
883}; // namespace RDKit
884#endif
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.
Definition Atom.h:75
iterator for a molecule's bonds, currently BiDirectional, but it theoretically ought to be RandomAcce...
class for representing a bond
Definition Bond.h:47
The class for representing 2D or 3D conformation of a molecule.
Definition Conformer.h:46
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
Definition MolPickler.h:68
Iterate over atoms matching a query. This is bidirectional.
Class for storing atomic queries.
Definition QueryAtom.h:28
Class for storing Bond queries.
Definition QueryBond.h:28
void clear()
Definition RDProps.h:34
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
Definition ROMol.h:279
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
Definition ROMol.h:568
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.
Definition ROMol.h:790
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
Definition ROMol.h:510
Atom * getAtomWithIdx(const U idx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ROMol.h:433
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
Definition ROMol.h:421
ConstConformerIterator endConformers() const
Definition ROMol.h:751
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
Definition ROMol.h:373
ROMol(const ROMol &other, bool quickCopy=false, int confId=-1)
copy constructor with a twist
Definition ROMol.h:335
ROMol & operator=(const ROMol &)=delete
Bond * getUniqueBondWithBookmark(int mark)
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.
Definition ROMol.h:554
void setBondBookmark(Bond *bond, int mark)
associates a Bond pointer with a bookmark
Definition ROMol.h:515
void updatePropertyCache(bool strict=true)
calculates any of our lazy properties
CXXAtomIterator< MolGraph, Atom * > atoms()
C++11 Range iterator.
Definition ROMol.h:277
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
Definition ROMol.h:284
BOND_BOOKMARK_MAP * getBondBookmarks()
returns a pointer to all of our bond bookmarks
Definition ROMol.h:535
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
Definition ROMol.h:778
bool hasQuery() const
if the Mol has any Query atoms or bonds
void clearAllBondBookmarks()
blows out all bond bookmarks
Definition ROMol.h:531
const Atom * getAtomWithIdx(const U idx) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ROMol.h:438
CXXBondIterator< MolGraph, Bond * > bonds()
Definition ROMol.h:316
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...
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...
Definition ROMol.h:461
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...
Definition ROMol.h:456
ATOM_BOOKMARK_MAP * getAtomBookmarks()
returns a pointer to all of our atom bookmarks
Definition ROMol.h:512
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)
Definition ROMol.h:289
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...
Definition ROMol.h:476
void setAtomBookmark(Atom *at, int mark)
associates an Atom pointer with a bookmark
Definition ROMol.h:487
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
friend RDKIT_GRAPHMOL_EXPORT std::vector< SubstanceGroup > & getSubstanceGroups(ROMol &)
ConstHeteroatomIterator endHeteros() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void replaceAtomBookmark(Atom *at, int mark)
associates an Atom pointer with a bookmark
Definition ROMol.h:491
Bond * getBondWithBookmark(int mark)
returns the first Bond associated with the bookmark provided
CXXBondIterator< const MolGraph, Bond *const, MolGraph::out_edge_iterator > atomBonds(Atom const *at) const
Definition ROMol.h:296
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)
Definition ROMol.h:301
AromaticAtomIterator endAromaticAtoms()
get an AtomIterator pointing at the end of our Atoms
RingInfo * getRingInfo() const
Definition ROMol.h:577
void clearAllAtomBookmarks()
blows out all atomic bookmarks
Definition ROMol.h:508
const Bond * operator[](const edge_descriptor &e) const
Definition ROMol.h:783
Bond * operator[](const edge_descriptor &e)
Definition ROMol.h:782
Bond * getBondWithIdx(unsigned int idx)
returns a pointer to a particular Bond
virtual ~ROMol()
Definition ROMol.h:414
ConformerIterator beginConformers()
Definition ROMol.h:743
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
HeteroatomIterator endHeteros()
get an AtomIterator pointing at the end of our Atoms
ROMol(ROMol &&o) noexcept
Definition ROMol.h:346
Bond * getBondBetweenAtoms(const U idx1, const V idx2)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition ROMol.h:470
ConstConformerIterator beginConformers() const
Definition ROMol.h:747
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
Definition ROMol.h:680
bool hasBondBookmark(int mark) const
queries whether or not any bonds are associated with a bookmark
Definition ROMol.h:533
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)
Definition ROMol.h:777
ConstHeteroatomIterator beginHeteros() 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 &)
ConformerIterator endConformers()
Definition ROMol.h:745
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
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
Definition ROMol.h:318
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:233
Std stuff.
std::vector< ROMol > MOL_VECT
Definition ROMol.h:875
MOL_PTR_VECT::const_iterator MOL_PTR_VECT_CI
Definition ROMol.h:880
RDKIT_GRAPHMOL_EXPORT const int ci_RIGHTMOST_ATOM
RDKIT_GRAPHMOL_EXPORT const int ci_ATOM_HOLDER
bool rdvalue_is(const RDValue_cast_t)
std::vector< ROMol * > MOL_PTR_VECT
Definition ROMol.h:877
boost::shared_ptr< ROMol > ROMOL_SPTR
MOL_PTR_VECT::iterator MOL_PTR_VECT_I
Definition ROMol.h:881
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, Atom *, Bond * > MolGraph
This is the BGL type used to store the topology:
Definition ROMol.h:55
std::vector< boost::shared_ptr< ROMol > > MOL_SPTR_VECT
RDKIT_GRAPHMOL_EXPORT const int ci_LEADING_BOND
std::forward_iterator_tag iterator_category
Definition ROMol.h:120
bool operator==(const CXXAtomIter &it) const
Definition ROMol.h:141
CXXAtomIter(Graph *graph, Iterator pos)
Definition ROMol.h:130
bool operator!=(const CXXAtomIter &it) const
Definition ROMol.h:142
CXXAtomIter end()
Definition ROMol.h:153
CXXAtomIterator(Graph *graph, Iterator start, Iterator end)
Definition ROMol.h:150
CXXAtomIterator(Graph *graph)
Definition ROMol.h:145
CXXAtomIter begin()
Definition ROMol.h:152
std::forward_iterator_tag iterator_category
Definition ROMol.h:163
CXXBondIter(Graph *graph, Iterator pos)
Definition ROMol.h:173
bool operator==(const CXXBondIter &it) const
Definition ROMol.h:184
bool operator!=(const CXXBondIter &it) const
Definition ROMol.h:185
CXXBondIter begin()
Definition ROMol.h:195
CXXBondIterator(Graph *graph)
Definition ROMol.h:188
CXXBondIterator(Graph *graph, Iterator start, Iterator end)
Definition ROMol.h:193
CXXBondIter end()
Definition ROMol.h:196