RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
MolOps.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2026 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#include <RDGeneral/export.h>
11#ifndef RD_MOL_OPS_H
12#define RD_MOL_OPS_H
13
14#include <vector>
15#include <map>
16#include <list>
17#include <string_view>
19#include <boost/smart_ptr.hpp>
20#include <boost/dynamic_bitset.hpp>
22#include <RDGeneral/types.h>
24#include "SanitException.h"
26
27RDKIT_GRAPHMOL_EXPORT extern const int ci_LOCAL_INF;
28namespace RDKit {
29class ROMol;
30class RWMol;
31class Atom;
32class Bond;
33class Conformer;
34typedef std::vector<double> INVAR_VECT;
35typedef INVAR_VECT::iterator INVAR_VECT_I;
36typedef INVAR_VECT::const_iterator INVAR_VECT_CI;
37
38//! \brief Groups a variety of molecular query and transformation operations.
39namespace MolOps {
40
41//! return the number of electrons available on an atom to donate for
42/// aromaticity
43/*!
44 The result is determined using the default valency, number of lone pairs,
45 number of bonds and the formal charge. Note that the atom may not donate
46 all of these electrons to a ring for aromaticity (also used in Conjugation
47 and hybridization code).
48
49 \param at the atom of interest
50
51 \return the number of electrons
52*/
54
55//! sums up all atomic formal charges and returns the result
57
58//! returns whether or not the given Atom is involved in a conjugated bond
60
61//! find fragments (disconnected components of the molecular graph)
62/*!
63
64 \param mol the molecule of interest
65 \param mapping used to return the mapping of Atoms->fragments.
66 On return \c mapping will be <tt>mol->getNumAtoms()</tt> long
67 and will contain the fragment assignment for each Atom
68
69 \return the number of fragments found.
70
71*/
72RDKIT_GRAPHMOL_EXPORT unsigned int getMolFrags(const ROMol &mol,
73 std::vector<int> &mapping);
74//! find fragments (disconnected components of the molecular graph)
75/*!
76
77 \param mol the molecule of interest
78 \param frags used to return the Atoms in each fragment
79 On return \c mapping will be \c numFrags long, and each entry
80 will contain the indices of the Atoms in that fragment.
81
82 \return the number of fragments found.
83
84*/
86 const ROMol &mol, std::vector<std::vector<int>> &frags);
87
88//! splits a molecule into its component fragments
89/// (disconnected components of the molecular graph)
90/*!
91
92 \param mol the molecule of interest
93 \param molFrags used to return the disconnected fragments as molecules.
94 Any contents on input will be cleared.
95 \param sanitizeFrags toggles sanitization of the fragments after
96 they are built
97 \param frags used to return the mapping of Atoms->fragments.
98 if provided, \c frags will be <tt>mol->getNumAtoms()</tt> long
99 on return and will contain the fragment assignment for each Atom.
100 \param fragsMolAtomMapping used to return the Atoms in each fragment
101 On return \c mapping will be \c numFrags long, and each entry
102 will contain the indices of the Atoms in that fragment.
103 \param copyConformers toggles copying conformers of the fragments after
104 they are built
105 \return the number of fragments found.
106
107*/
109 const ROMol &mol, std::vector<std::unique_ptr<ROMol>> &molFrags,
110 bool sanitizeFrags = true, std::vector<int> *frags = nullptr,
111 std::vector<std::vector<int>> *fragsMolAtomMapping = nullptr,
112 bool copyConformers = true);
113
114//! splits a molecule into its component fragments
115/// (disconnected components of the molecular graph)
116/*!
117
118 \param mol the molecule of interest
119 \param sanitizeFrags toggles sanitization of the fragments after
120 they are built
121 \param frags used to return the mapping of Atoms->fragments.
122 if provided, \c frags will be <tt>mol->getNumAtoms()</tt> long
123 on return and will contain the fragment assignment for each Atom
124 \param fragsMolAtomMapping used to return the Atoms in each fragment
125 On return \c mapping will be \c numFrags long, and each entry
126 will contain the indices of the Atoms in that fragment.
127 \param copyConformers toggles copying conformers of the fragments after
128 they are built
129 \return a vector of the fragments as smart pointers to ROMols
130
131*/
132RDKIT_GRAPHMOL_EXPORT std::vector<boost::shared_ptr<ROMol>> getMolFrags(
133 const ROMol &mol, bool sanitizeFrags = true,
134 std::vector<int> *frags = nullptr,
135 std::vector<std::vector<int>> *fragsMolAtomMapping = nullptr,
136 bool copyConformers = true);
137
138//! splits a molecule into pieces based on labels assigned using a query
139/*!
140
141 \param mol the molecule of interest
142 \param query the query used to "label" the molecule for fragmentation
143 \param sanitizeFrags toggles sanitization of the fragments after
144 they are built
145 \param whiteList if provided, only labels in the list will be kept
146 \param negateList if true, the white list logic will be inverted: only labels
147 not in the list will be kept
148
149 \return a map of the fragments and their labels
150
151*/
152
153template <typename T>
154RDKIT_GRAPHMOL_EXPORT std::map<T, boost::shared_ptr<ROMol>>
155getMolFragsWithQuery(const ROMol &mol, T (*query)(const ROMol &, const Atom *),
156 bool sanitizeFrags = true,
157 const std::vector<T> *whiteList = nullptr,
158 bool negateList = false);
159//! splits a molecule into pieces based on labels assigned using a query,
160//! putting them into a map of std::unique_ptr<ROMol>.
161/*!
162
163 \param mol the molecule of interest
164 \param query the query used to "label" the molecule for fragmentation
165 \param molFrags used to return the disconnected fragments as molecules.
166 Any contents on input will be cleared.
167 \param sanitizeFrags toggles sanitization of the fragments after
168 they are built
169 \param whiteList if provided, only labels in the list will be kept
170 \param negateList if true, the white list logic will be inverted: only labels
171 not in the list will be kept
172
173 \return the number of fragments
174
175*/
176template <typename T>
178 const ROMol &mol, T (*query)(const ROMol &, const Atom *),
179 std::map<T, std::unique_ptr<ROMol>> &molFrags, bool sanitizeFrags = true,
180 const std::vector<T> *whiteList = nullptr, bool negateList = false);
181
182//! \name Dealing with hydrogens
183//{@
184
186 bool explicitOnly = false; /**< only add explicit Hs */
187 bool addCoords = false; /**< add coordinates for the Hs */
188 bool addResidueInfo = false; /**< add residue info to the Hs */
190 false; /**< do not add Hs to query atoms or atoms with query bonds */
191};
192//! adds Hs to a molecule as explicit Atoms
193/*!
194 \param mol the molecule to add Hs to
195 \param params parameters controlling which Hs are added.
196 \param onlyOnAtoms (optional) if provided, this should be a vector of
197 IDs of the atoms that will be considered for H addition.
198
199 <b>Notes:</b>
200 - it makes no sense to use the \c addCoords option if the molecule's
201 heavy atoms don't already have coordinates.
202 - the molecule is modified
203 */
205 const UINT_VECT *onlyOnAtoms = nullptr);
206
207//! returns a copy of a molecule with hydrogens added in as explicit Atoms
208/*!
209 \param mol the molecule to add Hs to
210 \param explicitOnly (optional) if this \c true, only explicit Hs will be
211 added
212 \param addCoords (optional) If this is true, estimates for the atomic
213 coordinates
214 of the added Hs will be used.
215 \param onlyOnAtoms (optional) if provided, this should be a vector of
216 IDs of the atoms that will be considered for H addition.
217 \param addResidueInfo (optional) if this is true, add residue info to
218 hydrogen atoms (useful for PDB files).
219
220 \return the new molecule
221
222 <b>Notes:</b>
223 - it makes no sense to use the \c addCoords option if the molecule's
224 heavy
225 atoms don't already have coordinates.
226 - the caller is responsible for <tt>delete</tt>ing the pointer this
227 returns.
228 */
229inline ROMol *addHs(const ROMol &mol, bool explicitOnly = false,
230 bool addCoords = false,
231 const UINT_VECT *onlyOnAtoms = nullptr,
232 bool addResidueInfo = false) {
233 AddHsParameters ps{explicitOnly, addCoords, addResidueInfo};
234 std::unique_ptr<RWMol> res{new RWMol(mol)};
235 addHs(*res, ps, onlyOnAtoms);
236 return static_cast<ROMol *>(res.release());
237}
238//! \overload
239/// modifies the molecule in place
240inline void addHs(RWMol &mol, bool explicitOnly = false, bool addCoords = false,
241 const UINT_VECT *onlyOnAtoms = nullptr,
242 bool addResidueInfo = false) {
243 AddHsParameters ps{explicitOnly, addCoords, addResidueInfo};
244 addHs(mol, ps, onlyOnAtoms);
245}
246
247//! Sets Cartesian coordinates for a terminal atom.
248//! Useful for growing an atom off a molecule with sensible
249//! coordinates based on the geometry of the neighbor.
250/*!
251 NOTE: this sets appropriate coordinates in all of the molecule's
252 conformers.
253
254 \param mol the molecule the atoms belong to
255 \param idx index of the terminal atom whose coordinates are set
256 \param otherIdx index of the bonded neighbor atom
257*/
258
260 unsigned int otherIdx);
261
262//! returns a copy of a molecule with hydrogens removed
263/*!
264 \param mol the molecule to remove Hs from
265 \param implicitOnly if this \c true, only implicit Hs will be
266 removed
267 \param updateExplicitCount (optional) If this is \c true, when explicit
268 Hs are removed from the graph, the heavy atom to which they are bound will
269 have its counter of explicit Hs increased.
270 \param sanitize: (optional) If this is \c true, the final molecule will be
271 sanitized
272
273 \return the new molecule
274
275 <b>Notes:</b>
276 - Hydrogens which aren't connected to a heavy atom will not be
277 removed. This prevents molecules like <tt>"[H][H]"</tt> from having
278 all atoms removed.
279 - Labelled hydrogen (e.g. atoms with atomic number=1, but mass > 1),
280 will not be removed.
281 - two coordinate Hs, like the central H in C[H-]C, will not be removed
282 - Hs connected to dummy atoms will not be removed
283 - Hs that are part of the definition of double bond Stereochemistry
284 will not be removed
285 - Hs that are not connected to anything else will not be removed
286 - Hs that have a query defined (i.e. hasQuery() returns true) will not
287 be removed
288
289 - the caller is responsible for <tt>delete</tt>ing the pointer this
290 returns.
291*/
292[[deprecated(
293 "Please use the version with RemoveHsParameters")]] RDKIT_GRAPHMOL_EXPORT ROMol *
294removeHs(const ROMol &mol, bool implicitOnly, bool updateExplicitCount = false,
295 bool sanitize = true);
296//! \overload
297/// modifies the molecule in place
298[[deprecated(
299 "Please use the version with RemoveHsParameters")]] RDKIT_GRAPHMOL_EXPORT void
300removeHs(RWMol &mol, bool implicitOnly, bool updateExplicitCount = false,
301 bool sanitize = true);
303 bool removeDegreeZero = false; /**< hydrogens that have no bonds */
304 bool removeHigherDegrees = false; /**< hydrogens with two (or more) bonds */
306 false; /**< hydrogens with bonds only to other hydrogens */
307 bool removeIsotopes = false; /**< hydrogens with non-default isotopes */
308 bool removeAndTrackIsotopes = false; /**< removes hydrogens with non-default
309 isotopes and keeps track of the heavy atom the isotopes were attached to in
310 the private _isotopicHs atom property, so they are re-added by AddHs() as
311 the original isotopes if possible*/
313 false; /**< hydrogens with at least one dummy-atom neighbor */
315 false; /**< hydrogens defining bond stereochemistry */
316 bool removeWithWedgedBond = true; /**< hydrogens with wedged bonds to them */
317 bool removeWithQuery = false; /**< hydrogens with queries defined */
318 bool removeMapped = true; /**< mapped hydrogens */
319 bool removeInSGroups = true; /**< part of a SubstanceGroup.
320 An H atom will only be removed if it doesn't cause any SGroup to become empty,
321 and if it doesn't play a special role in the SGroup (XBOND, attach point
322 or a CState) */
323 bool showWarnings = true; /**< display warnings for Hs that are not removed */
324 bool removeNonimplicit = true; /**< DEPRECATED equivalent of !implicitOnly */
326 false; /**< DEPRECATED equivalent of updateExplicitCount */
327 bool removeHydrides = false; /**< Removing Hydrides */
329 false; /**< remove Hs which are bonded to atoms with specified
330 non-tetrahedral stereochemistry */
331};
332
333//! \overload
334/// modifies the molecule in place
336 RWMol &mol, const RemoveHsParameters &ps = RemoveHsParameters(),
337 bool sanitize = true);
338//! \overload
339/// The caller owns the pointer this returns
341 const ROMol &mol, const RemoveHsParameters &ps = RemoveHsParameters(),
342 bool sanitize = true);
343
344//! removes all Hs from a molecule
345RDKIT_GRAPHMOL_EXPORT void removeAllHs(RWMol &mol, bool sanitize = true);
346//! \overload
347/// The caller owns the pointer this returns
349 bool sanitize = true);
350
351//! returns a copy of a molecule with hydrogens removed and added as queries
352//! to the heavy atoms to which they are bound.
353/*!
354 This is really intended to be used with molecules that contain QueryAtoms
355
356 \param mol the molecule to remove Hs from
357
358 \return the new molecule
359
360 <b>Notes:</b>
361 - Atoms that do not already have hydrogen count queries will have one
362 added, other H-related queries will not be touched. Examples:
363 - C[H] -> [C;!H0]
364 - [C;H1][H] -> [C;H1]
365 - [C;H2][H] -> [C;H2]
366 - Hydrogens which aren't connected to a heavy atom will not be
367 removed. This prevents molecules like <tt>"[H][H]"</tt> from having
368 all atoms removed.
369 - the caller is responsible for <tt>delete</tt>ing the pointer this
370 returns.
371 - By default all hydrogens are removed, however if
372 mergeUnmappedOnly is true, any hydrogen participating
373 in an atom map will be retained
374
375*/
377 bool mergeUnmappedOnly = false,
378 bool mergeIsotopes = false);
379//! \overload
380/// modifies the molecule in place
382 bool mergeUnmappedOnly = false,
383 bool mergeIsotopes = false);
384
385//! returns a pair of booleans (hasQueryHs, hasUnmergaebleQueryHs)
386/*!
387 This is really intended to be used with molecules that contain QueryAtoms
388 such as when checking smarts patterns for explicit hydrogens
389
390
391 \param mol the molecule to check for query Hs from
392 \return std::pair if pair.first is true if the molecule has query
393 hydrogens, if pair.second is true, the queryHs cannot be removed my
394 mergeQueryHs
395*/
396RDKIT_GRAPHMOL_EXPORT std::pair<bool, bool> hasQueryHs(const ROMol &mol);
397
407
408//! Parameters controlling the behavior of MolOps::adjustQueryProperties
409/*!
410
411 Note that some of the options here are either directly contradictory or make
412 no sense when combined with each other. We generally assume that client code
413 is doing something sensible and don't attempt to detect possible conflicts
414 or problems.
415
416*/
418 bool adjustDegree = true; /**< add degree queries */
420
421 bool adjustRingCount = false; /**< add ring-count queries */
422 std::uint32_t adjustRingCountFlags =
424
425 bool makeDummiesQueries = true; /**< convert dummy atoms without isotope
426 labels to any-atom queries */
427
428 bool aromatizeIfPossible = true; /**< perceive and set aromaticity */
429
431 false; /**< convert bonds to generic queries (any bonds) */
433
435 false; /**< convert atoms to generic queries (any atoms) */
437
438 bool adjustHeavyDegree = false; /**< adjust the heavy-atom degree instead of
439 overall degree */
442
443 bool adjustRingChain = false; /**< add ring-chain queries */
445
447 false; /**< remove stereochemistry info from double bonds that do not
448 have the stereoCare property set */
449
451 false; /**< sets bond queries in conjugated five-rings to
452 SINGLE|DOUBLE|AROMATIC */
453
455 false; /**< uses the 5-ring aromaticity behavior of the (former) MDL
456 software as documented in the Chemical Representation Guide */
457
459 false; /**< sets single bonds between aromatic or conjugated atoms and
460 degree one neighbors to SINGLE|AROMATIC */
461
463 false; /**< sets non-ring single bonds between two aromatic or
464 conjugated atoms to SINGLE|AROMATIC */
465
466 //! \brief returns an AdjustQueryParameters object with all adjustments
467 //! disabled
470 res.adjustDegree = false;
471 res.makeDummiesQueries = false;
472 res.aromatizeIfPossible = false;
473 return res;
474 }
476};
477
478//! updates an AdjustQueryParameters object from a JSON string
480 MolOps::AdjustQueryParameters &p, const std::string &json);
481
482//! returns a copy of a molecule with query properties adjusted
483/*!
484 \param mol the molecule to adjust
485 \param params controls the adjustments made
486
487 \return the new molecule, the caller owns the memory
488*/
490 const ROMol &mol, const AdjustQueryParameters *params = nullptr);
491//! \overload
492/// modifies the molecule in place
494 RWMol &mol, const AdjustQueryParameters *params = nullptr);
495
496//! returns a copy of a molecule with the atoms renumbered
497/*!
498
499 \param mol the molecule to work with
500 \param newOrder the new ordering of the atoms (should be numAtoms long)
501 for example: if newOrder is [3,2,0,1], then atom 3 in the original
502 molecule will be atom 0 in the new one
503
504 \return the new molecule
505
506 <b>Notes:</b>
507 - the caller is responsible for <tt>delete</tt>ing the pointer this
508 returns.
509
510*/
512 const ROMol &mol, const std::vector<unsigned int> &newOrder);
513
514//! @}
515
516//! \name Sanitization
517/// {
518
519// clang-format off
520BETTER_ENUM(SanitizeFlags, unsigned int,
521 SANITIZE_NONE = 0x0,
522 SANITIZE_CLEANUP = 0x1,
523 SANITIZE_PROPERTIES = 0x2,
524 SANITIZE_SYMMRINGS = 0x4,
525 SANITIZE_KEKULIZE = 0x8,
526 SANITIZE_FINDRADICALS = 0x10,
527 SANITIZE_SETAROMATICITY = 0x20,
528 SANITIZE_SETCONJUGATION = 0x40,
529 SANITIZE_SETHYBRIDIZATION = 0x80,
530 SANITIZE_CLEANUPCHIRALITY = 0x100,
531 SANITIZE_ADJUSTHS = 0x200,
532 SANITIZE_CLEANUP_ORGANOMETALLICS = 0x400,
533 SANITIZE_CLEANUPATROPISOMERS = 0x800,
534 SANITIZE_ALL = 0xFFFFFFF
535);
536// clang-format on
537
538//! \brief carries out a collection of tasks for cleaning up a molecule and
539//! ensuring that it makes "chemical sense"
540/*!
541 This functions calls the following in sequence
542 -# MolOps::cleanUp()
543 -# mol.updatePropertyCache()
544 -# MolOps::Kekulize()
545 -# MolOps::symmetrizeSSSR()
546 -# MolOps::assignRadicals()
547 -# MolOps::setAromaticity()
548 -# MolOps::setConjugation()
549 -# MolOps::setHybridization()
550 -# MolOps::cleanupChirality()
551 -# MolOps::adjustHs()
552 -# mol.updatePropertyCache()
553
554 \param mol : the RWMol to be cleaned
555
556 \param operationThatFailed : the first (if any) sanitization operation that
557 fails is set here.
558 The values are taken from the \c SanitizeFlags
559 enum. On success, the value is \c
560 SanitizeFlags::SANITIZE_NONE
561
562 \param sanitizeOps : the bits here are used to set which sanitization
563 operations are carried out. The elements of the \c
564 SanitizeFlags enum define the operations.
565
566 <b>Notes:</b>
567 - If there is a failure in the sanitization, a \c MolSanitizeException
568 will be thrown.
569 - in general the user of this function should cast the molecule following
570 this function to a ROMol, so that new atoms and bonds cannot be added to
571 the molecule and screw up the sanitizing that has been done here
572*/
574 RWMol &mol, unsigned int &operationThatFailed,
575 unsigned int sanitizeOps = SanitizeFlags::SANITIZE_ALL);
576//! \overload
578
579//! \brief Identifies chemistry problems (things that don't make chemical
580//! sense) in a molecule
581/*!
582 This functions uses the operations in sanitizeMol but does not change
583 the input structure and returns a list of the problems encountered instead
584 of stopping at the first failure,
585
586 The problems this looks for come from the sanitization operations:
587 -# mol.updatePropertyCache() : Unreasonable valences
588 -# MolOps::Kekulize() : Unkekulizable ring systems, aromatic atoms not
589 in rings, aromatic bonds to non-aromatic atoms.
590
591 \param mol : the ROMol to be cleaned
592
593 \param sanitizeOps : the bits here are used to set which sanitization
594 operations are carried out. The elements of the \c
595 SanitizeFlags enum define the operations.
596
597 \return a vector of \c MolSanitizeException values that indicate what
598 problems were encountered
599
600*/
602std::vector<std::unique_ptr<MolSanitizeException>> detectChemistryProblems(
603 const ROMol &mol, unsigned int sanitizeOps = SanitizeFlags::SANITIZE_ALL);
604
605//! Possible aromaticity models
606/*!
607- \c AROMATICITY_DEFAULT at the moment always uses \c AROMATICITY_RDKIT
608- \c AROMATICITY_RDKIT is the standard RDKit model (as documented in the RDKit
609Book)
610- \c AROMATICITY_SIMPLE only considers 5- and 6-membered simple rings (it
611does not consider the outer envelope of fused rings)
612- \c AROMATICITY_MDL
613- \c AROMATICIT_MMFF94 the aromaticity model used by the MMFF94 force field
614- \c AROMATICITY_CUSTOM uses a caller-provided function
615*/
616typedef enum {
617 AROMATICITY_DEFAULT = 0x0, ///< future proofing
622 AROMATICITY_CUSTOM = 0xFFFFFFF ///< use a function
624
625//! sets the aromaticity model for a molecule to MMFF94
627
628//! Sets up the aromaticity for a molecule
629/*!
630
631 This is what happens here:
632 -# find all the simple rings by calling the findSSSR function
633 -# loop over all the Atoms in each ring and mark them if they are
634 candidates
635 for aromaticity. A ring atom is a candidate if it can spare electrons
636 to the ring and if it's from the first two rows of the periodic table.
637 -# based on the candidate atoms, mark the rings to be either candidates
638 or non-candidates. A ring is a candidate only if all its atoms are
639 candidates
640 -# apply Hueckel rule to each of the candidate rings to check if the ring
641 can be
642 aromatic
643
644 \param mol the RWMol of interest
645 \param model the aromaticity model to use
646 \param func a custom function for assigning aromaticity (only used when
647 model=\c AROMATICITY_CUSTOM)
648
649 \return >0 on success, <= 0 otherwise
650
651 <b>Assumptions:</b>
652 - Kekulization has been done (i.e. \c MolOps::Kekulize() has already
653 been called)
654
655*/
658 int (*func)(RWMol &) = nullptr);
659
660//! Designed to be called by the sanitizer to handle special cases before
661/// anything is done.
662/*!
663
664 Currently this:
665 - modifies nitro groups, so that the nitrogen does not have an
666 unreasonable valence of 5, as follows:
667 - the nitrogen gets a positive charge
668 - one of the oxygens gets a negative charge and the double bond to
669 this oxygen is changed to a single bond The net result is that nitro groups
670 can be counted on to be: \c "[N+](=O)[O-]"
671 - modifies halogen-oxygen containing species as follows:
672 \c [Cl,Br,I](=O)(=O)(=O)O -> [X+3]([O-])([O-])([O-])O
673 \c [Cl,Br,I](=O)(=O)O -> [X+3]([O-])([O-])O
674 \c [Cl,Br,I](=O)O -> [X+]([O-])O
675 - converts the substructure [N,C]=P(=O)-* to [N,C]=[P+](-[O-])-*
676
677 \param mol the molecule of interest
678
679*/
681
682//! Designed to be called by the sanitizer to handle special cases for
683//! organometallic species before valence is perceived
684/*!
685
686 \b Note that this function is experimental and may either change in
687 behavior or be replaced with something else in future releases.
688
689 Currently this:
690 - replaces single bonds between "hypervalent" organic atoms and metals
691 with dative bonds (this is following an IUPAC recommendation:
692 https://iupac.qmul.ac.uk/tetrapyrrole/TP8.html)
693
694 \param mol the molecule of interest
695
696*/
698
699//! Called by the sanitizer to assign radical counts to atoms
701
702//! adjust the number of implicit and explicit Hs for special cases
703/*!
704
705 Currently this:
706 - modifies aromatic nitrogens so that, when appropriate, they have an
707 explicit H marked (e.g. so that we get things like \c "c1cc[nH]cc1"
708
709 \param mol the molecule of interest
710
711 <b>Assumptions</b>
712 - this is called after the molecule has been sanitized,
713 aromaticity has been perceived, and the implicit valence of
714 everything has been calculated.
715
716*/
718
719//! Kekulizes the molecule
720/*!
721
722 \param mol the molecule of interest
723
724 \param markAtomsBonds if this is set to true, \c isAromatic boolean
725 settings on both the Bonds and Atoms are turned to false following the
726 Kekulization, otherwise they are left alone in their original state.
727
728 \param canonical controls atom traversal order during kekulization:
729 - \c false (the default): traverses atoms in atom-index order
730 (std::iota). Fast, but the resulting Kekulé bond assignment depends on
731 the order atoms appear in the molecule.
732 - \c true: uses canonical atom ranking (Canon::rankFragmentAtoms with a
733 wedge-end heuristic) so that the Kekulé bond assignment is independent
734 of atom ordering. Use this in output writers and any code that requires
735 a reproducible, chemistry-based Kekulé form.
736
737 \note <b>Behavioural difference from releases prior to 2026.03.1:</b>
738 Before the \c canonical parameter was added (i.e. in 2025.09.1 and
739 earlier), Kekulize traversed atoms in an order determined by the SSSR
740 ring-membership and adjacency-list iteration order — neither pure
741 atom-index order (\c canonical=false) nor rank-based order
742 (\c canonical=true). Tests and expected outputs written against those
743 releases may differ from both new modes; \c canonical=true is the closest
744 match for output-writer use cases, while \c canonical=false gives a
745 deterministic but potentially different Kekulé form from the old default.
746
747 Note that the canonical mode only really makes sense when the molecule's
748 chemistry is sane, like after sanitization. If stereochemistry hasn't
749 been perceived, the chemistry of the molecule is inconsistent, and
750 "canonical" atom ranks are only a technical artifact.
751
752 \param maxBackTracks the maximum number of attempts at back-tracking. The
753 algorithm uses a back-tracking procedure to revisit a previous setting of
754 double bond if we hit a wall in the kekulization process
755
756 <b>Notes:</b>
757 - this does not modify query bonds which have bond type queries (like
758 those which come from SMARTS) or rings containing them.
759 - even if \c markAtomsBonds is \c false the \c BondType for all modified
760 aromatic bonds will be changed from \c RDKit::Bond::AROMATIC to \c
761 RDKit::Bond::SINGLE or RDKit::Bond::DOUBLE during Kekulization.
762
763*/
764RDKIT_GRAPHMOL_EXPORT void Kekulize(RWMol &mol, bool markAtomsBonds = true,
765 bool canonical = true,
766 unsigned int maxBackTracks = 100);
767//! Kekulizes the molecule if possible. If the kekulization fails the molecule
768//! will not be modified
769/*!
770
771 \param mol the molecule of interest
772
773 \param markAtomsBonds if this is set to true, \c isAromatic boolean
774 settings on both the Bonds and Atoms are turned to false following the
775 Kekulization, otherwise they are left alone in their original state.
776
777 \param canonical controls atom traversal order; see the full description
778 on \c Kekulize() for the three-way distinction between \c canonical=false
779 (atom-index order, default), \c canonical=true (rank-based, order-
780 independent), and the pre-PR master behaviour.
781
782 \param maxBackTracks the maximum number of attempts at back-tracking. The
783 algorithm uses a back-tracking procedure to revisit a previous setting of
784 double bond if we hit a wall in the kekulization process
785
786 \returns whether or not the kekulization succeeded
787
788 <b>Notes:</b>
789 - even if \c markAtomsBonds is \c false the \c BondType for all aromatic
790 bonds will be changed from \c RDKit::Bond::AROMATIC to \c
791 RDKit::Bond::SINGLE or RDKit::Bond::DOUBLE during Kekulization.
792
793*/
795 bool markAtomsBonds = true,
796 bool canonical = true,
797 unsigned int maxBackTracks = 100);
798
799//! flags the molecule's conjugated bonds
801
802//! calculates and sets the hybridization of all a molecule's Stoms
804
805//! @}
806
807//! \name Ring finding and SSSR
808//! @{
809
810constexpr auto useLegacyRingFindingEnvVar = "RDK_USE_LEGACY_RING_FINDING";
812 false; //!< whether or not the legacy symmetric SSSR code is used during
813 //!< sanitization
814//! \brief sets whether or not the legacy symmetric SSSR code is used
816//! \brief returns whether or not the legacy symmetric SSSR code is used during
817//! sanitization
819
820//! finds a molecule's Smallest Set of Smallest Rings
821/*!
822 Currently this implements a modified form of Figueras algorithm
823 (JCICS - Vol. 36, No. 5, 1996, 986-991)
824
825 \param mol the molecule of interest
826 \param res used to return the vector of rings. Each entry is a vector with
827 atom indices. This information is also stored in the molecule's
828 RingInfo structure, so this argument is optional (see overload)
829 \param includeDativeBonds - determines whether or not dative bonds are used
830 in the ring finding.
831 \param includeHydrogenBonds - determines whether or not hydrogen bonds are
832 used in the ring finding.
833
834 \return number of smallest rings found
835
836 Base algorithm:
837 - The original algorithm starts by finding representative degree 2
838 nodes.
839 - Representative because if a series of deg 2 nodes are found only
840 one of them is picked.
841 - The smallest ring around each of them is found.
842 - The bonds that connect to this degree 2 node are them chopped off,
843 yielding
844 new deg two nodes
845 - The process is repeated on the new deg 2 nodes.
846 - If no deg 2 nodes are found, a deg 3 node is picked. The smallest ring
847 with it is found. A bond from this is "carefully" (look in the paper)
848 selected and chopped, yielding deg 2 nodes. The process is same as
849 above once this is done.
850
851 Our Modifications:
852 - If available, more than one smallest ring around a representative deg 2
853 node will be computed and stored
854 - Typically 3 rings are found around a degree 3 node (when no deg 2s are
855 available)
856 and all the bond to that node are chopped.
857 - The extra rings that were found in this process are removed after all
858 the nodes have been covered.
859
860 These changes were motivated by several factors:
861 - We believe the original algorithm fails to find the correct SSSR
862 (finds the correct number of them but the wrong ones) on some sample
863 mols
864 - Since SSSR may not be unique, a post-SSSR step to symmetrize may be
865 done. The extra rings this process adds can be quite useful.
866*/
868 std::vector<std::vector<int>> &res,
869 bool includeDativeBonds = false,
870 bool includeHydrogenBonds = false);
871//! \overload
873 std::vector<std::vector<int>> *res = nullptr,
874 bool includeDativeBonds = false,
875 bool includeHydrogenBonds = false);
876
877//! use a DFS algorithm to identify ring bonds and atoms in a molecule
878/*!
879 \b NOTE: though the RingInfo structure is populated by this function,
880 the only really reliable calls that can be made are to check if
881 mol.getRingInfo().numAtomRings(idx) or mol.getRingInfo().numBondRings(idx)
882 return values >0
883*/
885
887 bool includeDativeBonds = false,
888 bool includeHydrogenBonds = false);
889
895
896//! symmetrize the molecule's Smallest Set of Smallest Rings
897/*!
898 SSSR rings obtained from "findSSSR" can be non-unique in some case.
899 For example, cubane has five SSSR rings, not six as one would hope.
900
901 This function adds additional rings to the SSSR list if necessary
902 to make the list symmetric, e.g. all atoms in cubane will be part of the
903 same number of SSSRs. This function choses these extra rings from the extra
904 rings computed and discarded during findSSSR. The new ring are chosen such
905 that:
906 - replacing a same sized ring in the SSSR list with an extra ring yields
907 the same union of bond IDs as the original SSSR list
908
909 \param mol - the molecule of interest
910 \param res used to return the vector of rings. Each entry is a vector with
911 atom indices. This information is also stored in the molecule's
912 RingInfo structure, so this argument is optional (see overload)
913 \param algorithm - determines which algorithm is used to find the rings and
914 do the symmetrization
915 \param recalcSSSR - if set, the SSSR set will be recalculated, otherwise if
916 there is an existing SSSR set, it will be used
917 \param includeDativeBonds - determines whether or not dative bonds are used
918 in the ring finding.
919 \param includeHydrogenBonds - determines whether or not hydrogen bonds are
920 used in the ring finding.
921
922 \return the total number of rings = (new rings + old SSSRs)
923
924 <b>Notes:</b>
925 - if no SSSR rings are found on the molecule - MolOps::findSSSR() is called
926 first
927*/
929 ROMol &mol, std::vector<std::vector<int>> &res,
931 bool recalcSSSR = true, bool includeDativeBonds = false,
932 bool includeHydrogenBonds = false);
933//! \overload
934inline int symmetrizeSSSR(
935 ROMol &mol,
937 bool recalcSSSR = true, bool includeDativeBonds = false,
938 bool includeHydrogenBonds = false) {
939 std::vector<std::vector<int>> res;
940 return symmetrizeSSSR(mol, res, algorithm, recalcSSSR, includeDativeBonds,
941 includeHydrogenBonds);
942}
943
944//! \overload
945inline int symmetrizeSSSR(ROMol &mol, std::vector<std::vector<int>> &res,
946 bool includeDativeBonds,
947 bool includeHydrogenBonds = false) {
948 bool recalcSSSR = true;
949 return symmetrizeSSSR(mol, res, SymmetrizeSSSRAlgorithm::DEFAULT, recalcSSSR,
950 includeDativeBonds, includeHydrogenBonds);
951}
952//! \overload
953inline int symmetrizeSSSR(ROMol &mol, bool includeDativeBonds,
954 bool includeHydrogenBonds = false) {
955 std::vector<std::vector<int>> res;
956 bool recalcSSSR = true;
957 return symmetrizeSSSR(mol, res, SymmetrizeSSSRAlgorithm::DEFAULT, recalcSSSR,
958 includeDativeBonds, includeHydrogenBonds);
959}
960
961//! @}
962
963//! \name Shortest paths and other matrices
964//! @{
965
966//! returns a molecule's adjacency matrix
967/*!
968 \param mol the molecule of interest
969 \param useBO toggles use of bond orders in the matrix
970 \param emptyVal sets the empty value (for non-adjacent atoms)
971 \param force forces calculation of the matrix, even if already
972 computed
973 \param propNamePrefix used to set the cached property name
974 \param bondsToUse used to limit which bonds are considered
975
976 \return the adjacency matrix.
977
978 <b>Notes</b>
979 - The result of this is cached in the molecule's local property
980 dictionary, which will handle deallocation. The caller should <b>not</b> \c
981 delete this pointer.
982
983*/
985 const ROMol &mol, bool useBO = false, int emptyVal = 0, bool force = false,
986 const char *propNamePrefix = nullptr,
987 const boost::dynamic_bitset<> *bondsToUse = nullptr);
988
989//! Computes the molecule's topological distance matrix
990/*!
991 Uses the Floyd-Warshall all-pairs-shortest-paths algorithm.
992
993 \param mol the molecule of interest
994 \param useBO toggles use of bond orders in the matrix
995 \param useAtomWts sets the diagonal elements of the result to
996 6.0/(atomic number) so that the matrix can be used to calculate
997 Balaban J values. This does not affect the bond weights.
998 \param force forces calculation of the matrix, even if already
999 computed
1000 \param propNamePrefix used to set the cached property name
1001
1002 \return the distance matrix.
1003
1004 <b>Notes</b>
1005 - The result of this is cached in the molecule's local property
1006 dictionary, which will handle deallocation. The caller should <b>not</b> \c
1007 delete this pointer.
1008
1009
1010*/
1012 const ROMol &mol, bool useBO = false, bool useAtomWts = false,
1013 bool force = false, const char *propNamePrefix = nullptr);
1014
1015//! Computes the molecule's topological distance matrix
1016/*!
1017 Uses the Floyd-Warshall all-pairs-shortest-paths algorithm.
1018
1019 \param mol the molecule of interest
1020 \param activeAtoms only elements corresponding to these atom indices
1021 will be included in the calculation
1022 \param bonds only bonds found in this list will be included in the
1023 calculation
1024 \param useBO toggles use of bond orders in the matrix
1025 \param useAtomWts sets the diagonal elements of the result to
1026 6.0/(atomic number) so that the matrix can be used to calculate
1027 Balaban J values. This does not affect the bond weights.
1028
1029 \return the distance matrix.
1030
1031 <b>Notes</b>
1032 - The results of this call are not cached, the caller <b>should</b> \c
1033 delete
1034 this pointer.
1035
1036
1037*/
1039 const ROMol &mol, const std::vector<int> &activeAtoms,
1040 const std::vector<const Bond *> &bonds, bool useBO = false,
1041 bool useAtomWts = false);
1042
1043//! Computes the molecule's 3D distance matrix
1044/*!
1045
1046 \param mol the molecule of interest
1047 \param confId the conformer to use
1048 \param useAtomWts sets the diagonal elements of the result to
1049 6.0/(atomic number)
1050 \param force forces calculation of the matrix, even if already
1051 computed
1052 \param propNamePrefix used to set the cached property name
1053 (if set to an empty string, the matrix will not be
1054 cached)
1055
1056 \return the distance matrix.
1057
1058 <b>Notes</b>
1059 - If propNamePrefix is not empty the result of this is cached in the
1060 molecule's local property dictionary, which will handle deallocation.
1061 In other cases the caller is responsible for freeing the memory.
1062
1063*/
1065 const ROMol &mol, int confId = -1, bool useAtomWts = false,
1066 bool force = false, const char *propNamePrefix = nullptr);
1067
1068//! Find the shortest path between two atoms
1069/*!
1070 Uses the Bellman-Ford algorithm
1071
1072 \param mol molecule of interest
1073 \param aid1 index of the first atom
1074 \param aid2 index of the second atom
1075
1076 \return an std::list with the indices of the atoms along the shortest
1077 path
1078
1079 <b>Notes:</b>
1080 - the starting and end atoms are included in the path
1081 - if no path is found, an empty path is returned
1082
1083*/
1084RDKIT_GRAPHMOL_EXPORT std::list<int> getShortestPath(const ROMol &mol, int aid1,
1085 int aid2);
1086
1087//! @}
1088
1089//! \name Stereochemistry
1090//! @{
1091
1092// class to hold hybridizations
1093
1095 public:
1097 throw FileParseException("not to be called without a mol parameter");
1098 };
1101 throw FileParseException("not to be called without a mol parameter");
1102 };
1103
1104 ~Hybridizations() = default;
1105
1107 return static_cast<Atom::HybridizationType>(d_hybridizations[idx]);
1108 }
1109 // Atom::HybridizationType &operator[](unsigned int idx) {
1110 // return static_cast<Atom::HybridizationType>(d_hybridizations[idx]);
1111 // d_hybridizations[d_hybridizations[idx]];
1112 // }
1113
1114 // // void clear() { d_hybridizations.clear(); }
1115 // // void resize(unsigned int sz) { d_hybridizations.resize(sz); }
1116 unsigned int size() const { return d_hybridizations.size(); }
1117
1118 private:
1119 std::vector<int> d_hybridizations;
1120};
1121
1122//! removes bogus chirality markers (e.g. tetrahedral flags on non-sp3
1123//! centers):
1125
1126//! removes bogus atropisomeric markers (e.g. those without sp2 begin and end
1127//! atoms):
1129 Hybridizations &hybridizations);
1130//! \overload
1132
1133//! \brief Uses a conformer to assign ChiralTypes to a molecule's atoms
1134/*!
1135 \param mol the molecule of interest
1136 \param confId the conformer to use
1137 \param replaceExistingTags if this flag is true, any existing atomic chiral
1138 tags will be replaced
1139
1140 If the conformer provided is not a 3D conformer, nothing will be done.
1141
1142
1143 NOTE that this does not check to see if atoms are chiral centers (i.e. all
1144 substituents are different), it merely sets the chiral type flags based on
1145 the coordinates and atom ordering. Use \c assignStereochemistryFrom3D() if
1146 you want chiral flags only on actual stereocenters.
1147*/
1149 ROMol &mol, int confId = -1, bool replaceExistingTags = true);
1150
1151//! \brief Uses a conformer to assign ChiralTypes to a molecule's atoms and
1152//! stereo flags to its bonds
1153/*!
1154
1155 \param mol the molecule of interest
1156 \param confId the conformer to use
1157 \param replaceExistingTags if this flag is true, any existing info about
1158 stereochemistry will be replaced
1159
1160 If the conformer provided is not a 3D conformer, nothing will be done.
1161*/
1163 ROMol &mol, int confId = -1, bool replaceExistingTags = true);
1164
1165//! \brief Use bond directions to assign ChiralTypes to a molecule's atoms
1166/*!
1167
1168 \param mol the molecule of interest
1169 \param confId the conformer to use
1170 \param replaceExistingTags if this flag is true, any existing info about
1171 stereochemistry will be replaced
1172*/
1174 ROMol &mol, int confId = -1, bool replaceExistingTags = true);
1175
1176//! \deprecated: this function will be removed in a future release. Use
1177//! setDoubleBondNeighborDirections() instead
1179 int confId = -1);
1180//! Sets bond directions based on double bond stereochemistry
1182 ROMol &mol, const Conformer *conf = nullptr);
1183//! removes directions from single bonds. The property _UnknownStereo will be
1184//! set on wiggly bonds
1186 bool onlyWedgeFlags = false);
1187
1188//! removes directions from all bonds. The property _UnknownStereo will be set
1189//! on wiggly bonds
1191//! removes directions from all bonds. The property _UnknownStereo will be set
1192//! on wiggly bonds
1194 bool onlyWedgeFlags = false);
1195
1196//! Assign CIS/TRANS bond stereochemistry tags based on neighboring
1197//! directions
1199
1200//! Assign stereochemistry tags to atoms and bonds.
1201/*!
1202 If useLegacyStereoPerception is true, it also does the CIP stereochemistry
1203 assignment for the molecule's atoms (R/S) and double bonds (Z/E).
1204 This assignment is based on legacy code which is fast, but is
1205 known to incorrectly assign CIP labels in some cases.
1206 instead, to assign CIP labels based on an accurate, though slower,
1207 implementation of the CIP rules, call CIPLabeler::assignCIPLabels().
1208 Chiral atoms will have a property '_CIPCode' indicating their chiral code.
1209
1210 \param mol the molecule to use
1211 \param cleanIt if true, any existing values of the property `_CIPCode`
1212 will be cleared, atoms with a chiral specifier that aren't
1213 actually chiral (e.g. atoms with duplicate
1214 substituents or only 2 substituents, etc.) will have
1215 their chiral code set to CHI_UNSPECIFIED. Bonds with
1216 STEREOCIS/STEREOTRANS specified that have duplicate
1217 substituents based upon the CIP atom ranks will be
1218 marked STEREONONE.
1219 \param force causes the calculation to be repeated even if it has
1220 already been done
1221 \param flagPossibleStereoCenters set the _ChiralityPossible property on
1222 atoms that are possible stereocenters
1223
1224 <b>Notes:M</b>
1225 - Throughout we assume that we're working with a hydrogen-suppressed
1226 graph.
1227
1228*/
1230 ROMol &mol, bool cleanIt = false, bool force = false,
1231 bool flagPossibleStereoCenters = false);
1232//! Removes all stereochemistry information from atoms (i.e. R/S) and bonds
1233/// i.e. Z/E)
1234/*!
1235
1236 \param mol the molecule of interest
1237*/
1239
1240//! \brief finds bonds that could be cis/trans in a molecule and mark them as
1241//! Bond::STEREOANY.
1242/*!
1243 \param mol the molecule of interest
1244 \param cleanIt toggles removal of stereo flags from double bonds that can
1245 not have stereochemistry
1246
1247 This function finds any double bonds that can potentially be part of
1248 a cis/trans system. No attempt is made here to mark them cis or
1249 trans. No attempt is made to detect double bond stereo in ring systems.
1250
1251 This function is useful in the following situations:
1252 - when parsing a mol file; for the bonds marked here, coordinate
1253 information on the neighbors can be used to identify cis or trans
1254 states
1255 - when writing a mol file; bonds that can be cis/trans but not marked as
1256 either need to be specially marked in the mol file
1257 - finding double bonds with unspecified stereochemistry so they
1258 can be enumerated for downstream 3D tools
1259
1260 The CIPranks on the neighboring atoms are checked in this function. The
1261 _CIPCode property if set to any on the double bond.
1262*/
1264 bool cleanIt = false);
1265//! \brief Uses the molParity atom property to assign ChiralType to a
1266//! molecule's atoms
1267/*!
1268 \param mol the molecule of interest
1269 \param replaceExistingTags if this flag is true, any existing atomic chiral
1270 tags will be replaced
1271*/
1273 ROMol &mol, bool replaceExistingTags = true);
1274
1275//! @}
1276
1277//! returns the number of atoms which have a particular property set
1279 const ROMol &mol, const std::string_view &prop);
1280
1281//! returns whether or not a molecule needs to have Hs added to it.
1283
1284//! \brief Replaces haptic bond with explicit dative bonds.
1285/*!
1286 *
1287 * @param mol the molecule of interest
1288 *
1289 * One way of showing haptic bonds (such as cyclopentadiene to iron in
1290 * ferrocene) is to use a dummy atom with a dative bond to the iron atom with
1291 * the bond labelled with the atoms involved in the organic end of the bond.
1292 * Another way is to have explicit dative bonds from the atoms of the haptic
1293 * group to the metal atom. This function converts the former representation
1294 * to the latter.
1295 */
1297
1298//! \overload modifies molecule in place.
1300
1301//! \brief Replaces explicit dative bonds with haptic.
1302/*!
1303 *
1304 * @param mol the molecule of interest
1305 *
1306 * Does the reverse of hapticBondsToDative. If there are multiple contiguous
1307 * atoms attached by dative bonds to an atom (probably a metal atom), the
1308 * dative bonds will be replaced by a dummy atom in their centre attached to
1309 * the (metal) atom by a dative bond, which is labelled with ENDPTS of the
1310 * atoms that had the original dative bonds.
1311 */
1313
1314//! \overload modifies molecule in place.
1316
1317/*!
1318 Calculates a molecule's average molecular weight
1319
1320 \param mol the molecule of interest
1321 \param onlyHeavy (optional) if this is true (the default is false),
1322 only heavy atoms will be included in the MW calculation
1323
1324 \return the AMW
1325*/
1327 bool onlyHeavy = false);
1328/*!
1329 Calculates a molecule's exact molecular weight
1330
1331 \param mol the molecule of interest
1332 \param onlyHeavy (optional) if this is true (the default is false),
1333 only heavy atoms will be included in the MW calculation
1334
1335 \return the exact MW
1336*/
1338 bool onlyHeavy = false);
1339
1340/*!
1341 Calculates a molecule's formula
1342
1343 \param mol the molecule of interest
1344 \param separateIsotopes if true, isotopes will show up separately in the
1345 formula. So C[13CH2]O will give the formula: C[13C]H6O
1346 \param abbreviateHIsotopes if true, 2H and 3H will be represented as
1347 D and T instead of [2H] and [3H]. This only applies if \c
1348 separateIsotopes is true
1349
1350 \return the formula as a string
1351*/
1353 const ROMol &mol, bool separateIsotopes = false,
1354 bool abbreviateHIsotopes = true);
1355
1356namespace details {
1357//! not recommended for use in other code
1359 RWMol &mol, const boost::dynamic_bitset<> &atomsToUse,
1360 boost::dynamic_bitset<> bondsToUse, bool markAtomsBonds = true,
1361 bool canonical = true, unsigned int maxBackTracks = 100);
1362
1363// If the bond is dative, and it has a common_properties::MolFileBondEndPts
1364// prop, returns a vector of the indices of the atoms mentioned in the prop.
1365RDKIT_GRAPHMOL_EXPORT std::vector<int> hapticBondEndpoints(const Bond *bond);
1366
1367} // namespace details
1368
1369//! attachment points encoded as attachPt properties are added to the graph as
1370/// dummy atoms
1371/*!
1372 *
1373 * @param mol the molecule of interest
1374 * @param addAsQueries if true, the dummy atoms will be added as null queries
1375 * (i.e. they will match any atom in a substructure search)
1376 * @param addCoords if true and the molecule has one or more conformers,
1377 * positions for the attachment points will be added to the conformer(s).
1378 *
1379 */
1381 bool addAsQueries = true,
1382 bool addCoords = true);
1383//! dummy atoms in the graph are removed and replaced with attachment point
1384//! annotations on the attached atoms
1385/*!
1386 *
1387 * @param mol the molecule of interest
1388 * @param markedOnly if true, only dummy atoms with the _fromAttachPoint
1389 * property or a valid _AP<n> atom label will be collapsed. The numeric
1390 * suffix of an atom label is an identifier, not an MDL ATTCHPT position.
1391 *
1392 * In order for a dummy atom to be considered for collapsing it must have:
1393 * - degree 1 with a single or unspecified bond
1394 * - the bond to it can not be wedged
1395 * - either no query or be an AtomNullQuery
1396 *
1397 */
1399 bool markedOnly = true);
1400
1401//! prefix used for numbered explicit attachment-point atom labels
1402inline constexpr std::string_view attachmentPointLabelPrefix = "_AP";
1403
1404//! returns the positive integer from a valid _AP<n> attachment-point label
1405/*!
1406 * The atom must be a degree-one dummy atom whose atomLabel consists of
1407 * attachmentPointLabelPrefix followed by a positive decimal integer. Returns
1408 * 0 if the atom does not have a valid numbered attachment-point label.
1409 *
1410 * This number is a label identifier, not an MDL ATTCHPT position.
1411 *
1412 * @param atom the atom to inspect
1413 */
1415 const Atom *atom);
1416
1417//! returns whether an atom is a marked explicit attachment point
1418/*!
1419 * A marked explicit attachment point is a degree-one dummy atom with the
1420 * _fromAttachPoint property or a valid _AP<n> atom label, where n is a
1421 * positive decimal integer. This checks attachment-point identity only; it
1422 * does not check whether the atom can currently be collapsed. In particular,
1423 * an attachment point connected by a wedged bond is still considered marked.
1424 *
1425 * @param atom the atom to inspect
1426 */
1428
1429namespace details {
1430//! attachment points encoded as attachPt properties are added to the graph as
1431/// dummy atoms
1432/*!
1433 *
1434 * @param mol the molecule of interest
1435 * @param atomIdx the index of the atom to which the attachment point should
1436 * be added
1437 * @param val the attachment point value. Should be 1 or 2
1438 * @param addAsQueries if true, the dummy atoms will be added as null queries
1439 * (i.e. they will match any atom in a substructure search)
1440 * @param addCoords if true and the molecule has one or more conformers,
1441 * positions for the attachment points will be added to the conformer(s).
1442 *
1443 */
1445 RWMol &mol, unsigned int atomIdx, unsigned int val, bool addAsQuery = true,
1446 bool addCoords = true);
1447
1448//! returns whether an atom is eligible to be collapsed as an attachment point
1449/*!
1450 *
1451 * @param atom the atom to inspect
1452 * @param markedOnly if true, only marked attachment points will be collapsed
1453 *
1454 * In order for a dummy atom to be considered for collapsing it must have:
1455 * - degree 1 with a single or unspecified bond
1456 * - the bond to it can not be wedged
1457 * - either no query or be an AtomNullQuery
1458 *
1459 */
1461 bool markedOnly = true);
1462
1463} // namespace details
1464
1465} // namespace MolOps
1466} // namespace RDKit
1467
1468#endif
#define BETTER_ENUM(Enum, Underlying,...)
Definition BetterEnums.h:17
RDKIT_GRAPHMOL_EXPORT const int ci_LOCAL_INF
The class for representing atoms.
Definition Atom.h:75
HybridizationType
store hybridization
Definition Atom.h:93
class for representing a bond
Definition Bond.h:48
The class for representing 2D or 3D conformation of a molecule.
Definition Conformer.h:46
used by various file parsing classes to indicate a parse error
unsigned int size() const
Definition MolOps.h:1116
Atom::HybridizationType operator[](int idx)
Definition MolOps.h:1106
Hybridizations(const Hybridizations &)
Definition MolOps.h:1100
Hybridizations(const ROMol &mol)
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:321
RDKIT_GRAPHMOL_EXPORT std::vector< int > hapticBondEndpoints(const Bond *bond)
RDKIT_GRAPHMOL_EXPORT bool isAttachmentPoint(const Atom *atom, bool markedOnly=true)
returns whether an atom is eligible to be collapsed as an attachment point
RDKIT_GRAPHMOL_EXPORT void KekulizeFragment(RWMol &mol, const boost::dynamic_bitset<> &atomsToUse, boost::dynamic_bitset<> bondsToUse, bool markAtomsBonds=true, bool canonical=true, unsigned int maxBackTracks=100)
not recommended for use in other code
RDKIT_GRAPHMOL_EXPORT unsigned int addExplicitAttachmentPoint(RWMol &mol, unsigned int atomIdx, unsigned int val, bool addAsQuery=true, bool addCoords=true)
Groups a variety of molecular query and transformation operations.
Definition MolOps.h:39
RDKIT_GRAPHMOL_EXPORT void cleanUp(RWMol &mol)
RDKIT_GRAPHMOL_EXPORT void assignStereochemistry(ROMol &mol, bool cleanIt=false, bool force=false, bool flagPossibleStereoCenters=false)
Assign stereochemistry tags to atoms and bonds.
RDKIT_GRAPHMOL_EXPORT void findRingFamilies(const ROMol &mol, bool includeDativeBonds=false, bool includeHydrogenBonds=false)
RDKIT_GRAPHMOL_EXPORT ROMol * renumberAtoms(const ROMol &mol, const std::vector< unsigned int > &newOrder)
returns a copy of a molecule with the atoms renumbered
RDKIT_GRAPHMOL_EXPORT std::string getMolFormula(const ROMol &mol, bool separateIsotopes=false, bool abbreviateHIsotopes=true)
RDKIT_GRAPHMOL_EXPORT void cleanupAtropisomers(RWMol &mol, Hybridizations &hybridizations)
RDKIT_GRAPHMOL_EXPORT void assignChiralTypesFromBondDirs(ROMol &mol, int confId=-1, bool replaceExistingTags=true)
Use bond directions to assign ChiralTypes to a molecule's atoms.
RDKIT_GRAPHMOL_EXPORT int setAromaticity(RWMol &mol, AromaticityModel model=AROMATICITY_DEFAULT, int(*func)(RWMol &)=nullptr)
Sets up the aromaticity for a molecule.
RDKIT_GRAPHMOL_EXPORT void sanitizeMol(RWMol &mol, unsigned int &operationThatFailed, unsigned int sanitizeOps=SanitizeFlags::SANITIZE_ALL)
carries out a collection of tasks for cleaning up a molecule and ensuring that it makes "chemical sen...
RDKIT_GRAPHMOL_EXPORT double getExactMolWt(const ROMol &mol, bool onlyHeavy=false)
RDKIT_GRAPHMOL_EXPORT bool needsHs(const ROMol &mol)
returns whether or not a molecule needs to have Hs added to it.
RDKIT_GRAPHMOL_EXPORT void fastFindRings(const ROMol &mol)
use a DFS algorithm to identify ring bonds and atoms in a molecule
RDKIT_GRAPHMOL_EXPORT std::pair< bool, bool > hasQueryHs(const ROMol &mol)
returns a pair of booleans (hasQueryHs, hasUnmergaebleQueryHs)
RDKIT_GRAPHMOL_EXPORT std::map< T, boost::shared_ptr< ROMol > > getMolFragsWithQuery(const ROMol &mol, T(*query)(const ROMol &, const Atom *), bool sanitizeFrags=true, const std::vector< T > *whiteList=nullptr, bool negateList=false)
splits a molecule into pieces based on labels assigned using a query
constexpr auto useLegacyRingFindingEnvVar
Definition MolOps.h:810
RDKIT_GRAPHMOL_EXPORT int getFormalCharge(const ROMol &mol)
sums up all atomic formal charges and returns the result
AromaticityModel
Possible aromaticity models.
Definition MolOps.h:616
@ AROMATICITY_RDKIT
Definition MolOps.h:618
@ AROMATICITY_MDL
Definition MolOps.h:620
@ AROMATICITY_CUSTOM
use a function
Definition MolOps.h:622
@ AROMATICITY_DEFAULT
future proofing
Definition MolOps.h:617
@ AROMATICITY_MMFF94
Definition MolOps.h:621
@ AROMATICITY_SIMPLE
Definition MolOps.h:619
RDKIT_GRAPHMOL_EXPORT void cleanUpOrganometallics(RWMol &mol)
RDKIT_GRAPHMOL_EXPORT double * getDistanceMat(const ROMol &mol, bool useBO=false, bool useAtomWts=false, bool force=false, const char *propNamePrefix=nullptr)
Computes the molecule's topological distance matrix.
SymmetrizeSSSRAlgorithm
Definition MolOps.h:890
RDKIT_GRAPHMOL_EXPORT ROMol * hapticBondsToDative(const ROMol &mol)
Replaces haptic bond with explicit dative bonds.
RDKIT_GRAPHMOL_EXPORT void setTerminalAtomCoords(ROMol &mol, unsigned int idx, unsigned int otherIdx)
RDKIT_GRAPHMOL_EXPORT bool getUseLegacyRingFinding()
returns whether or not the legacy symmetric SSSR code is used during sanitization
RDKIT_GRAPHMOL_EXPORT void removeStereochemistry(ROMol &mol)
RDKIT_GRAPHMOL_EXPORT void clearSingleBondDirFlags(ROMol &mol, bool onlyWedgeFlags=false)
RDKIT_GRAPHMOL_EXPORT ROMol * adjustQueryProperties(const ROMol &mol, const AdjustQueryParameters *params=nullptr)
returns a copy of a molecule with query properties adjusted
RDKIT_GRAPHMOL_EXPORT unsigned getNumAtomsWithDistinctProperty(const ROMol &mol, const std::string_view &prop)
returns the number of atoms which have a particular property set
RDKIT_GRAPHMOL_EXPORT void assignChiralTypesFromMolParity(ROMol &mol, bool replaceExistingTags=true)
Uses the molParity atom property to assign ChiralType to a molecule's atoms.
RDKIT_GRAPHMOL_EXPORT ROMol * mergeQueryHs(const ROMol &mol, bool mergeUnmappedOnly=false, bool mergeIsotopes=false)
RDKIT_GRAPHMOL_EXPORT void expandAttachmentPoints(RWMol &mol, bool addAsQueries=true, bool addCoords=true)
RDKIT_GRAPHMOL_EXPORT unsigned int getMolFrags(const ROMol &mol, std::vector< int > &mapping)
find fragments (disconnected components of the molecular graph)
RDKIT_GRAPHMOL_EXPORT void adjustHs(RWMol &mol)
adjust the number of implicit and explicit Hs for special cases
RDKIT_GRAPHMOL_EXPORT ROMol * dativeBondsToHaptic(const ROMol &mol)
Replaces explicit dative bonds with haptic.
RDKIT_GRAPHMOL_EXPORT void assignStereochemistryFrom3D(ROMol &mol, int confId=-1, bool replaceExistingTags=true)
Uses a conformer to assign ChiralTypes to a molecule's atoms and stereo flags to its bonds.
RDKIT_GRAPHMOL_EXPORT bool KekulizeIfPossible(RWMol &mol, bool markAtomsBonds=true, bool canonical=true, unsigned int maxBackTracks=100)
RDKIT_GRAPHMOL_EXPORT int countAtomElec(const Atom *at)
RDKIT_GRAPHMOL_EXPORT void detectBondStereochemistry(ROMol &mol, int confId=-1)
RDKIT_GRAPHMOL_EXPORT void setMMFFAromaticity(RWMol &mol)
sets the aromaticity model for a molecule to MMFF94
RDKIT_GRAPHMOL_EXPORT ROMol * removeHs(const ROMol &mol, bool implicitOnly, bool updateExplicitCount=false, bool sanitize=true)
returns a copy of a molecule with hydrogens removed
RDKIT_GRAPHMOL_EXPORT void parseAdjustQueryParametersFromJSON(MolOps::AdjustQueryParameters &p, const std::string &json)
updates an AdjustQueryParameters object from a JSON string
RDKIT_GRAPHMOL_EXPORT void removeAllHs(RWMol &mol, bool sanitize=true)
removes all Hs from a molecule
RDKIT_GRAPHMOL_EXPORT void clearAllBondDirFlags(ROMol &mol)
RDKIT_GRAPHMOL_EXPORT void setUseLegacyRingFinding(bool val)
sets whether or not the legacy symmetric SSSR code is used
RDKIT_GRAPHMOL_EXPORT void setBondStereoFromDirections(ROMol &mol)
RDKIT_GRAPHMOL_EXPORT unsigned int getAttachmentPointLabelNumber(const Atom *atom)
returns the positive integer from a valid _AP<n> attachment-point label
RDKIT_GRAPHMOL_EXPORT double * get3DDistanceMat(const ROMol &mol, int confId=-1, bool useAtomWts=false, bool force=false, const char *propNamePrefix=nullptr)
Computes the molecule's 3D distance matrix.
RDKIT_GRAPHMOL_EXPORT bool atomHasConjugatedBond(const Atom *at)
returns whether or not the given Atom is involved in a conjugated bond
RDKIT_GRAPHMOL_EXPORT int symmetrizeSSSR(ROMol &mol, std::vector< std::vector< int > > &res, SymmetrizeSSSRAlgorithm algorithm=SymmetrizeSSSRAlgorithm::DEFAULT, bool recalcSSSR=true, bool includeDativeBonds=false, bool includeHydrogenBonds=false)
symmetrize the molecule's Smallest Set of Smallest Rings
RDKIT_GRAPHMOL_EXPORT std::vector< std::unique_ptr< MolSanitizeException > > detectChemistryProblems(const ROMol &mol, unsigned int sanitizeOps=SanitizeFlags::SANITIZE_ALL)
Identifies chemistry problems (things that don't make chemical sense) in a molecule.
RDKIT_GRAPHMOL_EXPORT void clearDirFlags(ROMol &mol, bool onlyWedgeFlags=false)
constexpr bool useLegacyRingFindingDefaultVal
Definition MolOps.h:811
RDKIT_GRAPHMOL_EXPORT void cleanupChirality(RWMol &mol)
RDKIT_GRAPHMOL_EXPORT double * getAdjacencyMatrix(const ROMol &mol, bool useBO=false, int emptyVal=0, bool force=false, const char *propNamePrefix=nullptr, const boost::dynamic_bitset<> *bondsToUse=nullptr)
returns a molecule's adjacency matrix
RDKIT_GRAPHMOL_EXPORT void assignRadicals(RWMol &mol)
Called by the sanitizer to assign radical counts to atoms.
RDKIT_GRAPHMOL_EXPORT void findPotentialStereoBonds(ROMol &mol, bool cleanIt=false)
finds bonds that could be cis/trans in a molecule and mark them as Bond::STEREOANY.
RDKIT_GRAPHMOL_EXPORT void addHs(RWMol &mol, const AddHsParameters &params, const UINT_VECT *onlyOnAtoms=nullptr)
adds Hs to a molecule as explicit Atoms
RDKIT_GRAPHMOL_EXPORT void setHybridization(ROMol &mol)
calculates and sets the hybridization of all a molecule's Stoms
constexpr std::string_view attachmentPointLabelPrefix
prefix used for numbered explicit attachment-point atom labels
Definition MolOps.h:1402
RDKIT_GRAPHMOL_EXPORT int findSSSR(const ROMol &mol, std::vector< std::vector< int > > &res, bool includeDativeBonds=false, bool includeHydrogenBonds=false)
finds a molecule's Smallest Set of Smallest Rings
RDKIT_GRAPHMOL_EXPORT void collapseAttachmentPoints(RWMol &mol, bool markedOnly=true)
RDKIT_GRAPHMOL_EXPORT bool isMarkedAttachmentPoint(const Atom *atom)
returns whether an atom is a marked explicit attachment point
RDKIT_GRAPHMOL_EXPORT void assignChiralTypesFrom3D(ROMol &mol, int confId=-1, bool replaceExistingTags=true)
Uses a conformer to assign ChiralTypes to a molecule's atoms.
RDKIT_GRAPHMOL_EXPORT std::list< int > getShortestPath(const ROMol &mol, int aid1, int aid2)
Find the shortest path between two atoms.
RDKIT_GRAPHMOL_EXPORT double getAvgMolWt(const ROMol &mol, bool onlyHeavy=false)
RDKIT_GRAPHMOL_EXPORT void setConjugation(ROMol &mol)
flags the molecule's conjugated bonds
RDKIT_GRAPHMOL_EXPORT void setDoubleBondNeighborDirections(ROMol &mol, const Conformer *conf=nullptr)
Sets bond directions based on double bond stereochemistry.
RDKIT_GRAPHMOL_EXPORT void Kekulize(RWMol &mol, bool markAtomsBonds=true, bool canonical=true, unsigned int maxBackTracks=100)
Kekulizes the molecule.
AdjustQueryWhichFlags
Definition MolOps.h:398
@ ADJUST_IGNORERINGS
Definition MolOps.h:401
@ ADJUST_IGNORENONE
Definition MolOps.h:399
@ ADJUST_IGNOREMAPPED
Definition MolOps.h:404
@ ADJUST_IGNORENONDUMMIES
Definition MolOps.h:403
@ ADJUST_IGNOREDUMMIES
Definition MolOps.h:402
@ ADJUST_IGNORECHAINS
Definition MolOps.h:400
@ ADJUST_IGNOREALL
Definition MolOps.h:405
Std stuff.
std::vector< double > INVAR_VECT
Definition MolOps.h:34
INVAR_VECT::iterator INVAR_VECT_I
Definition MolOps.h:35
INVAR_VECT::const_iterator INVAR_VECT_CI
Definition MolOps.h:36
std::vector< UINT > UINT_VECT
Definition types.h:242
Parameters controlling the behavior of MolOps::adjustQueryProperties.
Definition MolOps.h:417
static AdjustQueryParameters noAdjustments()
returns an AdjustQueryParameters object with all adjustments disabled
Definition MolOps.h:468