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);
308} // namespace detail
309
310//! picks the bonds which should be wedged
311/// returns a map from bond idx -> controlling atom idx
313std::map<int, std::unique_ptr<Chirality::WedgeInfoBase>> pickBondsToWedge(
314 const ROMol &mol, const BondWedgingParameters *params = nullptr);
315
316
318std::map<int, std::unique_ptr<Chirality::WedgeInfoBase>> pickBondsToWedge(
319 const ROMol &mol, const BondWedgingParameters *params,
320 const Conformer *conf);
321
323 ROMol &mol, const Conformer *conf = nullptr,
324 const BondWedgingParameters *params = nullptr);
326 const Conformer *conf);
327
328//! Returns true for double bonds which should be shown as a crossed bonds.
329// It always returns false if any adjacent bond is a squiggle bond.
331
332//! Clears existing bond wedging and forces use of atom wedging from MolBlock.
333/*!
334 \param mol: molecule to have its wedges altered
335 \param allBondTypes: reapply the wedging also on bonds other than single and
336 aromatic ones
337 */
339 bool allBondTypes = true);
340//! Remove MolBlock bond wedging information from molecule.
341/*!
342 \param mol: molecule to modify
343 */
345//! Invert bond wedging information read from a mol block (if present).
346/*!
347 \param mol: molecule to modify
348 */
350
351//! gets stereo info for a bond
352/*!
353 \param bond: bond to check
354 \param wedgeBonds - the list of bonds to have wedges
355 \param conf - Conformer to use
356 \param dirCode - receives the dircode for the bond
357 \param reverse - receives the reverse flag
358 only returned if it was exlicility set witha wiggle bond
359 */
360
362 const Bond *bond,
363 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
364 &wedgeBonds,
365 const Conformer *conf, int &dirCode, bool &reverse);
366
368 const Bond *bond,
369 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
370 &wedgeBonds,
371 const Conformer *conf, Bond::BondDir &dir, bool &reverse);
372
373//! add R/S, relative stereo, and E/Z annotations to atoms and bonds
374/*!
375 \param mol: molecule to modify
376 \param absLabel: label for atoms in an ABS stereo group
377 \param orLabel: label for atoms in an OR stereo group
378 \param andLabel: label for atoms in an AND stereo group
379 \param cipLabel: label for chiral atoms that aren't in a stereo group.
380 \param bondLabel: label for CIP stereochemistry on bonds
381
382 If any label is empty, the corresponding annotations will not be added.
383
384 The labels can contain the following placeholders:
385 {id} - the stereo group's index
386 {cip} - the atom or bond's CIP stereochemistry
387
388 Note that CIP labels will only be added if CIP stereochemistry has been
389 assigned to the molecule.
390
391 */
393 ROMol &mol, std::string absLabel = "abs ({cip})",
394 std::string orLabel = "or{id}", std::string andLabel = "and{id}",
395 std::string cipLabel = "({cip})", std::string bondLabel = "({cip})");
396
397//! simplifies the stereochemical representation of a molecule where all
398//! specified stereocenters are in the same StereoGroup
399/*!
400 \param mol: molecule to modify
401 \param removeAffectedStereoGroups: if set then the affected StereoGroups will
402 be removed
403
404If all specified stereocenters are in the same AND or OR stereogroup, a
405moleculeNote property will be set on the molecule with the value "AND
406enantiomer" or "OR enantiomer". CIP labels, if present, are removed.
407
408*/
410 ROMol &mol, bool removeAffectedStereoGroups = true);
411
412//! returns the meso centers in a molecule (if any)
413/*!
414 \param mol: molecule to work with
415
416*/
417RDKIT_GRAPHMOL_EXPORT std::vector<std::pair<unsigned int, unsigned int>>
418findMesoCenters(const ROMol &mol, bool includeIsotopes = true,
419 bool includeAtomMaps = false);
420
421} // namespace Chirality
422} // namespace RDKit
423#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:99
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 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 void setStereoForBond(ROMol &mol, Bond *bond, Bond::BondStereo stereo)
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:297
std::vector< int > INT_VECT
Definition types.h:291
bool rdvalue_is(const RDValue_cast_t)
std::vector< UINT > UINT_VECT
Definition types.h:310
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