RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
Chirality.h
Go to the documentation of this file.
1//
2// Copyright (C) 2008-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 Chirality.h
11
12*/
13#include <RDGeneral/export.h>
14#ifndef RD_CHIRALITY_20AUG2008_H
15#define RD_CHIRALITY_20AUG2008_H
16#include <RDGeneral/types.h>
17#include <GraphMol/Atom.h> /* for Atom:ChiralType enum */
18#include <GraphMol/Bond.h> /* for Bond::BondDir enum */
19#include <boost/dynamic_bitset.hpp>
20#include <limits>
21
22namespace RDKit {
23class Atom;
24class Bond;
25class ROMol;
26class Conformer;
27
28namespace Chirality {
29
30//! double bond stereo will be ignored/removed for rings smaller than this:
31constexpr unsigned int minRingSizeForDoubleBondStereo = 8;
32
33constexpr auto nonTetrahedralStereoEnvVar = "RDK_ENABLE_NONTETRAHEDRAL_STEREO";
34constexpr auto useLegacyStereoEnvVar = "RDK_USE_LEGACY_STEREO_PERCEPTION";
36 true; //!< whether or not nontetrahedral stereo is perceived by default
38 true; //!< whether or not the legacy stereo perception code is used by
39 //!< default
40
43
46
48
49RDKIT_GRAPHMOL_EXPORT extern bool
50 useLegacyStereoPerception; //!< Toggle usage of the legacy stereo
51 //!< perception code
52
53RDKIT_GRAPHMOL_EXPORT extern bool
54 useLegacyStereoPerception; //!< Toggle usage of the legacy stereo
55 //!< perception code
56
57/// @cond
58/*!
59 \param mol the molecule to be altered
60 \param ranks used to return the set of ranks.
61 Should be at least mol.getNumAtoms() long.
62
63 <b>Notes:</b>
64 - All atoms gain a property common_properties::_CIPRank with their overall
65 CIP ranking.
66
67*/
70
72
73/**
74 * Returns the first neighboring bond that can be found which has a stereo
75 * bond direction set. If no such bond can be found, it returns null. No
76 * checks are made to ensure there aren't any other conflicting directed bonds.
77 */
79 const Atom *atom);
80
81/**
82 * This just translates the labels, setting/translating StereoAtoms or the
83 * label is not the responsibility of this function. If the passed label is not
84 * E/Z, it will be returned unchanged.
85 */
87 Bond::BondStereo label);
88/// @endcond
89
90enum class StereoType {
96 Bond_Double, // single double bond and odd-numbered cumulenes
97 Bond_Cumulene_Even, // even-numbered cumulenes
99};
100
102 None,
103 Tet_CW,
104 Tet_CCW,
105 Bond_Cis,
109};
110
111enum class StereoSpecified {
112 Unspecified, // no information provided
113 Specified,
114 Unknown // deliberately marked as unknown
115};
116
118 // REVIEW: absolute stereo data member?
119#ifdef _MSC_VER
120 static const unsigned NOATOM =
121 std::numeric_limits<unsigned>::max(); // used to mark missing atoms
122#else
123 static const unsigned NOATOM; // used to mark missing atoms
124#endif
125 StereoType type = StereoType::Unspecified;
126 StereoSpecified specified = StereoSpecified::Unspecified;
127 unsigned centeredOn = NOATOM;
128 StereoDescriptor descriptor = StereoDescriptor::None;
129 unsigned permutation = 0; // for the non-tetrahedral stereo cases
130 std::vector<unsigned> controllingAtoms; // all atoms around the atom or bond.
131 // Order is important
132 bool operator==(const StereoInfo &other) const {
133 return type == other.type && specified == other.specified &&
134 centeredOn == other.centeredOn && descriptor == other.descriptor &&
135 permutation == other.permutation &&
136 controllingAtoms == other.controllingAtoms;
137 }
138 bool operator!=(const StereoInfo &other) const { return !(*this == other); }
139};
140
141//! identifies potential stereoatoms and stereobonds in a molecule
142/*!
143 Note that this function is still somewhat experimental and the API
144 and results may change in a future release.
145
146 \param mol the molecule to look for stereo in
147 \param cleanIt remove chirality/stereo specifications from atoms/bonds that
148 cannot be chiral/stereo
149*/
151 ROMol &mol, bool cleanIt, bool flagPossible = true);
152//! overload
154 const ROMol &mol);
155
156//! removes atoms without specified chirality from stereo groups
158
159//! calls the approximate legacy code for assigning CIP labels
161 ROMol &mol, bool flagPossibleStereoCenters = false);
162
163/// @cond
164namespace detail {
166 const Atom *atom);
173 const Atom *atom);
174RDKIT_GRAPHMOL_EXPORT unsigned int getAtomNonzeroDegree(const Atom *atom);
175
177 const Atom *atom);
178
179} // namespace detail
180/// @endcond
181
183
184//! \name Non-tetrahedral stereochemistry
185//! @{
188 const Bond *qry);
190 const Atom *qry);
192 const Bond *qry);
194 const Atom *qry);
195//! \param which: if this is -1 then the second axial bond will be returned,
196//! otherwise the first
198 int which = 0);
200 int which = 0);
201
202//! \returns 1 if it's the first axial atom, -1 if it's the second
204 const Bond *qry);
206 const Atom *qry);
207
209 const Atom *lig1,
210 const Atom *lig2);
211
213
214//
215// Get the chiral permutation from the storage order of bonds on an atom
216// to the desired output order (probe). Missing/implicit neihgbors can be
217// represented with (-1). To get the inverse order, i.e. from the probe to the
218// current storage order set (inverse=true)
219//
221 const INT_LIST &probe,
222 bool inverse = false);
223//! @}
224
225RDKIT_GRAPHMOL_EXPORT std::ostream &operator<<(std::ostream &oss,
226 const StereoSpecified &s);
227RDKIT_GRAPHMOL_EXPORT std::ostream &operator<<(std::ostream &oss,
228 const StereoType &s);
229
231 bool wedgeTwoBondsIfPossible =
232 false; //!< If this is enabled then two bonds will be wedged at chiral
233 //!< centers subject to the following constraints:
234 //!< 1. ring bonds will not be wedged
235 //!< 2. bonds to chiral centers will not be wedged
236 //!< 3. bonds separated by more than 120 degrees will not be
237 //!< wedged
238};
239
244
246 public:
248 virtual ~WedgeInfoBase() {};
249
250 virtual WedgeInfoType getType() const = 0;
251 virtual Bond::BondDir getDir() const = 0;
252
253 int getIdx() const { return idx; }
254
255 private:
256 int idx = -1;
257};
258
260 public:
263
267 Bond::BondDir getDir() const override {
268 throw std::runtime_error(
269 "BondDir is not stored/used in Chiral type WedgInfos");
270 }
271};
272
289
290namespace detail {
292 const Bond *bond, unsigned int fromAtomIdx, const Conformer *conf);
294 const Bond *bond,
295 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
296 &wedgeBonds,
297 const Conformer *conf);
298
299RDKIT_GRAPHMOL_EXPORT std::pair<bool, INT_VECT> countChiralNbrs(
300 const ROMol &mol, int noNbrs);
302 const Atom *atom, const ROMol &mol, const INT_VECT &nChiralNbrs,
303 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
304 &resSoFar,
305 int noNbrs);
306
307//! If useCXSmilesOrdering is true, the stereo will be assigned relative to the
308/// lowest-numbered neighbor of each double bond atom.
309/// Otherwise it uses the lowest-numbered neighbor on the lower-numbered atom of
310/// the double bond and the highest-numbered neighbor on the higher-numbered
311/// atom
314 bool useCXSmilesOrdering = false);
315} // namespace detail
316
317//! picks the bonds which should be wedged
318/// returns a map from bond idx -> controlling atom idx
320std::map<int, std::unique_ptr<Chirality::WedgeInfoBase>> pickBondsToWedge(
321 const ROMol &mol, const BondWedgingParameters *params = nullptr);
322
324std::map<int, std::unique_ptr<Chirality::WedgeInfoBase>> pickBondsToWedge(
325 const ROMol &mol, const BondWedgingParameters *params,
326 const Conformer *conf);
327
329 ROMol &mol, const Conformer *conf = nullptr,
330 const BondWedgingParameters *params = nullptr);
332 const Conformer *conf);
333
334//! Returns true for double bonds which should be shown as a crossed bonds.
335// It always returns false if any adjacent bond is a squiggle bond.
337
338//! Clears existing bond wedging and forces use of atom wedging from MolBlock.
339/*!
340 \param mol: molecule to have its wedges altered
341 \param allBondTypes: reapply the wedging also on bonds other than single and
342 aromatic ones
343 */
345 bool allBondTypes = true);
346//! Remove MolBlock bond wedging information from molecule.
347/*!
348 \param mol: molecule to modify
349 */
351//! Invert bond wedging information read from a mol block (if present).
352/*!
353 \param mol: molecule to modify
354 */
356
357//! gets stereo info for a bond
358/*!
359 \param bond: bond to check
360 \param wedgeBonds - the list of bonds to have wedges
361 \param conf - Conformer to use
362 \param dirCode - receives the dircode for the bond
363 \param reverse - receives the reverse flag
364 only returned if it was exlicility set witha wiggle bond
365 */
366
368 const Bond *bond,
369 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
370 &wedgeBonds,
371 const Conformer *conf, int &dirCode, bool &reverse);
372
374 const Bond *bond,
375 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
376 &wedgeBonds,
377 const Conformer *conf, Bond::BondDir &dir, bool &reverse);
378
379//! add R/S, relative stereo, and E/Z annotations to atoms and bonds
380/*!
381 \param mol: molecule to modify
382 \param absLabel: label for atoms in an ABS stereo group
383 \param orLabel: label for atoms in an OR stereo group
384 \param andLabel: label for atoms in an AND stereo group
385 \param cipLabel: label for chiral atoms that aren't in a stereo group.
386 \param bondLabel: label for CIP stereochemistry on bonds
387
388 If any label is empty, the corresponding annotations will not be added.
389
390 The labels can contain the following placeholders:
391 {id} - the stereo group's index
392 {cip} - the atom or bond's CIP stereochemistry
393
394 Note that CIP labels will only be added if CIP stereochemistry has been
395 assigned to the molecule.
396
397 */
399 ROMol &mol, std::string absLabel = "abs ({cip})",
400 std::string orLabel = "or{id}", std::string andLabel = "and{id}",
401 std::string cipLabel = "({cip})", std::string bondLabel = "({cip})");
402
403//! simplifies the stereochemical representation of a molecule where all
404//! specified stereocenters are in the same StereoGroup
405/*!
406 \param mol: molecule to modify
407 \param removeAffectedStereoGroups: if set then the affected StereoGroups will
408 be removed
409
410If all specified stereocenters are in the same AND or OR stereogroup, a
411moleculeNote property will be set on the molecule with the value "AND
412enantiomer" or "OR enantiomer". CIP labels, if present, are removed.
413
414*/
416 ROMol &mol, bool removeAffectedStereoGroups = true);
417
418//! returns the meso centers in a molecule (if any)
419/*!
420 \param mol: molecule to work with
421
422*/
423RDKIT_GRAPHMOL_EXPORT std::vector<std::pair<unsigned int, unsigned int>>
424findMesoCenters(const ROMol &mol, bool includeIsotopes = true,
425 bool includeAtomMaps = false);
426
427} // namespace Chirality
428} // namespace RDKit
429#endif
Defines the Atom class and associated typedefs.
The class for representing atoms.
Definition Atom.h:75
ChiralType
store type of chirality
Definition Atom.h:101
class for representing a bond
Definition Bond.h:47
BondDir
the bond's direction (for chirality)
Definition Bond.h:83
@ NONE
no special style
Definition Bond.h:84
BondStereo
the nature of the bond's stereochem (for cis/trans)
Definition Bond.h:95
WedgeInfoType getType() const override
Definition Chirality.h:283
WedgeInfoAtropisomer(int bondId, RDKit::Bond::BondDir dirInit)
Definition Chirality.h:275
Bond::BondDir getDir() const override
Definition Chirality.h:287
virtual Bond::BondDir getDir() const =0
virtual WedgeInfoType getType() const =0
Bond::BondDir getDir() const override
Definition Chirality.h:267
WedgeInfoType getType() const override
Definition Chirality.h:264
The class for representing 2D or 3D conformation of a molecule.
Definition Conformer.h:46
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:233
RDKIT_GRAPHMOL_EXPORT std::pair< bool, INT_VECT > countChiralNbrs(const ROMol &mol, int noNbrs)
RDKIT_GRAPHMOL_EXPORT void setStereoForBond(ROMol &mol, Bond *bond, Bond::BondStereo stereo, bool useCXSmilesOrdering=false)
RDKIT_GRAPHMOL_EXPORT int pickBondToWedge(const Atom *atom, const ROMol &mol, const INT_VECT &nChiralNbrs, const std::map< int, std::unique_ptr< RDKit::Chirality::WedgeInfoBase > > &resSoFar, int noNbrs)
RDKIT_GRAPHMOL_EXPORT Bond::BondDir determineBondWedgeState(const Bond *bond, unsigned int fromAtomIdx, const Conformer *conf)
RDKIT_GRAPHMOL_EXPORT bool getUseLegacyStereoPerception()
RDKIT_GRAPHMOL_EXPORT int isTrigonalBipyramidalAxialAtom(const Atom *center, const Atom *qry)
RDKIT_GRAPHMOL_EXPORT unsigned int getChiralPermutation(const Atom *center, const INT_LIST &probe, bool inverse=false)
RDKIT_GRAPHMOL_EXPORT bool getAllowNontetrahedralChirality()
RDKIT_GRAPHMOL_EXPORT void wedgeMolBonds(ROMol &mol, const Conformer *conf=nullptr, const BondWedgingParameters *params=nullptr)
RDKIT_GRAPHMOL_EXPORT unsigned int getMaxNbors(const Atom::ChiralType tag)
RDKIT_GRAPHMOL_EXPORT Atom * getTrigonalBipyramidalAxialAtom(const Atom *center, int which=0)
RDKIT_GRAPHMOL_EXPORT void invertMolBlockWedgingInfo(ROMol &mol)
Invert bond wedging information read from a mol block (if present).
RDKIT_GRAPHMOL_EXPORT void setUseLegacyStereoPerception(bool val)
RDKIT_GRAPHMOL_EXPORT std::vector< std::pair< unsigned int, unsigned int > > findMesoCenters(const ROMol &mol, bool includeIsotopes=true, bool includeAtomMaps=false)
returns the meso centers in a molecule (if any)
RDKIT_GRAPHMOL_EXPORT void simplifyEnhancedStereo(ROMol &mol, bool removeAffectedStereoGroups=true)
RDKIT_GRAPHMOL_EXPORT bool shouldBeACrossedBond(const Bond *bond)
Returns true for double bonds which should be shown as a crossed bonds.
constexpr unsigned int minRingSizeForDoubleBondStereo
double bond stereo will be ignored/removed for rings smaller than this:
Definition Chirality.h:31
constexpr bool useLegacyStereoDefaultVal
Definition Chirality.h:37
RDKIT_GRAPHMOL_EXPORT void reapplyMolBlockWedging(ROMol &mol, bool allBondTypes=true)
Clears existing bond wedging and forces use of atom wedging from MolBlock.
RDKIT_GRAPHMOL_EXPORT void GetMolFileBondStereoInfo(const Bond *bond, const std::map< int, std::unique_ptr< RDKit::Chirality::WedgeInfoBase > > &wedgeBonds, const Conformer *conf, int &dirCode, bool &reverse)
gets stereo info for a bond
RDKIT_GRAPHMOL_EXPORT Atom * getChiralAcrossAtom(const Atom *center, const Bond *qry)
RDKIT_GRAPHMOL_EXPORT void setAllowNontetrahedralChirality(bool val)
RDKIT_GRAPHMOL_EXPORT Bond * getTrigonalBipyramidalAxialBond(const Atom *center, int which=0)
constexpr auto nonTetrahedralStereoEnvVar
Definition Chirality.h:33
RDKIT_GRAPHMOL_EXPORT void removeNonExplicit3DChirality(ROMol &mol)
constexpr auto useLegacyStereoEnvVar
Definition Chirality.h:34
RDKIT_GRAPHMOL_EXPORT bool useLegacyStereoPerception
Definition Chirality.h:54
RDKIT_GRAPHMOL_EXPORT std::ostream & operator<<(std::ostream &oss, const StereoSpecified &s)
RDKIT_GRAPHMOL_EXPORT void wedgeBond(Bond *bond, unsigned int fromAtomIdx, const Conformer *conf)
RDKIT_GRAPHMOL_EXPORT std::map< int, std::unique_ptr< Chirality::WedgeInfoBase > > pickBondsToWedge(const ROMol &mol, const BondWedgingParameters *params=nullptr)
RDKIT_GRAPHMOL_EXPORT std::vector< StereoInfo > findPotentialStereo(ROMol &mol, bool cleanIt, bool flagPossible=true)
identifies potential stereoatoms and stereobonds in a molecule
RDKIT_GRAPHMOL_EXPORT void addStereoAnnotations(ROMol &mol, std::string absLabel="abs ({cip})", std::string orLabel="or{id}", std::string andLabel="and{id}", std::string cipLabel="({cip})", std::string bondLabel="({cip})")
add R/S, relative stereo, and E/Z annotations to atoms and bonds
RDKIT_GRAPHMOL_EXPORT bool hasNonTetrahedralStereo(const Atom *center)
RDKIT_GRAPHMOL_EXPORT int isTrigonalBipyramidalAxialBond(const Atom *center, const Bond *qry)
RDKIT_GRAPHMOL_EXPORT double getIdealAngleBetweenLigands(const Atom *center, const Atom *lig1, const Atom *lig2)
RDKIT_GRAPHMOL_EXPORT void cleanupStereoGroups(ROMol &mol)
removes atoms without specified chirality from stereo groups
RDKIT_GRAPHMOL_EXPORT Bond * getChiralAcrossBond(const Atom *center, const Bond *qry)
constexpr bool nonTetrahedralStereoDefaultVal
whether or not nontetrahedral stereo is perceived by default
Definition Chirality.h:35
RDKIT_GRAPHMOL_EXPORT void clearMolBlockWedgingInfo(ROMol &mol)
Remove MolBlock bond wedging information from molecule.
RDKIT_GRAPHMOL_EXPORT INT_VECT findStereoAtoms(const Bond *bond)
RDKIT_GRAPHMOL_EXPORT void assignLegacyCIPLabels(ROMol &mol, bool flagPossibleStereoCenters=false)
calls the approximate legacy code for assigning CIP labels
Std stuff.
std::list< int > INT_LIST
Definition types.h:298
std::vector< int > INT_VECT
Definition types.h:292
bool rdvalue_is(const RDValue_cast_t)
std::vector< UINT > UINT_VECT
Definition types.h:311
static const unsigned NOATOM
Definition Chirality.h:123
std::vector< unsigned > controllingAtoms
Definition Chirality.h:130
StereoSpecified specified
Definition Chirality.h:126
StereoDescriptor descriptor
Definition Chirality.h:128
bool operator!=(const StereoInfo &other) const
Definition Chirality.h:138
bool operator==(const StereoInfo &other) const
Definition Chirality.h:132