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/Bond.h>
18#include <boost/dynamic_bitset.hpp>
19#include <limits>
20
21namespace RDKit {
22class Atom;
23class Bond;
24class ROMol;
25class Conformer;
26
27namespace Chirality {
28
29//! double bond stereo will be ignored/removed for rings smaller than this:
30constexpr unsigned int minRingSizeForDoubleBondStereo = 8;
31
32constexpr auto nonTetrahedralStereoEnvVar = "RDK_ENABLE_NONTETRAHEDRAL_STEREO";
33constexpr auto useLegacyStereoEnvVar = "RDK_USE_LEGACY_STEREO_PERCEPTION";
35 true; //!< whether or not nontetrahedral stereo is perceived by default
37 true; //!< whether or not the legacy stereo perception code is used by
38 //!< default
39
42
45
47
48RDKIT_GRAPHMOL_EXPORT extern bool
49 useLegacyStereoPerception; //!< Toggle usage of the legacy stereo
50 //!< perception code
51
52RDKIT_GRAPHMOL_EXPORT extern bool
53 useLegacyStereoPerception; //!< Toggle usage of the legacy stereo
54 //!< perception code
55
56/// @cond
57/*!
58 \param mol the molecule to be altered
59 \param ranks used to return the set of ranks.
60 Should be at least mol.getNumAtoms() long.
61
62 <b>Notes:</b>
63 - All atoms gain a property common_properties::_CIPRank with their overall
64 CIP ranking.
65
66*/
69
71
72/**
73 * Returns the first neighboring bond that can be found which has a stereo
74 * bond direction set. If no such bond can be found, it returns null. No
75 * checks are made to ensure there aren't any other conflicting directed bonds.
76 */
78 const Atom *atom);
79
80/**
81 * This just translates the labels, setting/translating StereoAtoms or the
82 * label is not the responsibility of this function. If the passed label is not
83 * E/Z, it will be returned unchanged.
84 */
86 Bond::BondStereo label);
87/// @endcond
88
89enum class StereoType {
95 Bond_Double, // single double bond and odd-numbered cumulenes
96 Bond_Cumulene_Even, // even-numbered cumulenes
98};
99
101 None,
102 Tet_CW,
103 Tet_CCW,
104 Bond_Cis,
108};
109
110enum class StereoSpecified {
111 Unspecified, // no information provided
112 Specified,
113 Unknown // deliberately marked as unknown
114};
115
117 // REVIEW: absolute stereo data member?
118#ifdef _MSC_VER
119 static const unsigned NOATOM =
120 std::numeric_limits<unsigned>::max(); // used to mark missing atoms
121#else
122 static const unsigned NOATOM; // used to mark missing atoms
123#endif
124 StereoType type = StereoType::Unspecified;
125 StereoSpecified specified = StereoSpecified::Unspecified;
126 unsigned centeredOn = NOATOM;
127 StereoDescriptor descriptor = StereoDescriptor::None;
128 unsigned permutation = 0; // for the non-tetrahedral stereo cases
129 std::vector<unsigned> controllingAtoms; // all atoms around the atom or bond.
130 // Order is important
131 bool operator==(const StereoInfo &other) const {
132 return type == other.type && specified == other.specified &&
133 centeredOn == other.centeredOn && descriptor == other.descriptor &&
134 permutation == other.permutation &&
135 controllingAtoms == other.controllingAtoms;
136 }
137 bool operator!=(const StereoInfo &other) const { return !(*this == other); }
138};
139
140//! identifies potential stereoatoms and stereobonds in a molecule
141/*!
142 Note that this function is still somewhat experimental and the API
143 and results may change in a future release.
144
145 \param mol the molecule to look for stereo in
146 \param cleanIt remove chirality/stereo specifications from atoms/bonds that
147 cannot be chiral/stereo
148*/
150 ROMol &mol, bool cleanIt, bool flagPossible = true);
151//! overload
153 const ROMol &mol);
154
155//! removes atoms without specified chirality from stereo groups
157
158//! calls the approximate legacy code for assigning CIP labels
160 ROMol &mol, bool flagPossibleStereoCenters = false);
161
162/// @cond
163namespace detail {
165 const Atom *atom);
172 const Atom *atom);
173RDKIT_GRAPHMOL_EXPORT unsigned int getAtomNonzeroDegree(const Atom *atom);
174
176 const Atom *atom);
177
178} // namespace detail
179/// @endcond
180
182
183//! \name Non-tetrahedral stereochemistry
184//! @{
187 const Bond *qry);
189 const Atom *qry);
191 const Bond *qry);
193 const Atom *qry);
194//! \param which: if this is -1 then the second axial bond will be returned,
195//! otherwise the first
197 int which = 0);
199 int which = 0);
200
201//! \returns 1 if it's the first axial atom, -1 if it's the second
203 const Bond *qry);
205 const Atom *qry);
206
208 const Atom *lig1,
209 const Atom *lig2);
210
212 const INT_LIST &probe);
213//! @}
214
215RDKIT_GRAPHMOL_EXPORT std::ostream &operator<<(std::ostream &oss,
216 const StereoSpecified &s);
217RDKIT_GRAPHMOL_EXPORT std::ostream &operator<<(std::ostream &oss,
218 const StereoType &s);
219
221 bool wedgeTwoBondsIfPossible =
222 false; //!< If this is enabled then two bonds will be wedged at chiral
223 //!< centers subject to the following constraints:
224 //!< 1. ring bonds will not be wedged
225 //!< 2. bonds to chiral centers will not be wedged
226 //!< 3. bonds separated by more than 120 degrees will not be
227 //!< wedged
228};
229
234
236 public:
238 virtual ~WedgeInfoBase() {};
239
240 virtual WedgeInfoType getType() const = 0;
241 virtual Bond::BondDir getDir() const = 0;
242
243 int getIdx() const { return idx; }
244
245 private:
246 int idx = -1;
247};
248
250 public:
253
257 Bond::BondDir getDir() const override {
258 throw std::runtime_error(
259 "BondDir is not stored/used in Chiral type WedgInfos");
260 }
261};
262
279
280namespace detail {
282 const Bond *bond, unsigned int fromAtomIdx, const Conformer *conf);
284 const Bond *bond,
285 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
286 &wedgeBonds,
287 const Conformer *conf);
288
289RDKIT_GRAPHMOL_EXPORT std::pair<bool, INT_VECT> countChiralNbrs(
290 const ROMol &mol, int noNbrs);
292 const Atom *atom, const ROMol &mol, const INT_VECT &nChiralNbrs,
293 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
294 &resSoFar,
295 int noNbrs);
298} // namespace detail
299
300//! picks the bonds which should be wedged
301/// returns a map from bond idx -> controlling atom idx
303std::map<int, std::unique_ptr<Chirality::WedgeInfoBase>> pickBondsToWedge(
304 const ROMol &mol, const BondWedgingParameters *params = nullptr);
305
307std::map<int, std::unique_ptr<Chirality::WedgeInfoBase>> pickBondsToWedge(
308 const ROMol &mol, const BondWedgingParameters *params,
309 const Conformer *conf);
310
312 ROMol &mol, const Conformer *conf = nullptr,
313 const BondWedgingParameters *params = nullptr);
315 const Conformer *conf);
316
317//! Returns true for double bonds which should be shown as a crossed bonds.
318// It always returns false if any adjacent bond is a squiggle bond.
320
321//! Clears existing bond wedging and forces use of atom wedging from MolBlock.
322/*!
323 \param mol: molecule to have its wedges altered
324 \param allBondTypes: reapply the wedging also on bonds other than single and
325 aromatic ones
326 */
328 bool allBondTypes = true);
329//! Remove MolBlock bond wedging information from molecule.
330/*!
331 \param mol: molecule to modify
332 */
334//! Invert bond wedging information read from a mol block (if present).
335/*!
336 \param mol: molecule to modify
337 */
339
340//! gets stereo info for a bond
341/*!
342 \param bond: bond to check
343 \param wedgeBonds - the list of bonds to have wedges
344 \param conf - Conformer to use
345 \param dirCode - receives the dircode for the bond
346 \param reverse - receives the reverse flag
347 only returned if it was exlicility set witha wiggle bond
348 */
349
351 const Bond *bond,
352 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
353 &wedgeBonds,
354 const Conformer *conf, int &dirCode, bool &reverse);
355
357 const Bond *bond,
358 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
359 &wedgeBonds,
360 const Conformer *conf, Bond::BondDir &dir, bool &reverse);
361
362//! add R/S, relative stereo, and E/Z annotations to atoms and bonds
363/*!
364 \param mol: molecule to modify
365 \param absLabel: label for atoms in an ABS stereo group
366 \param orLabel: label for atoms in an OR stereo group
367 \param andLabel: label for atoms in an AND stereo group
368 \param cipLabel: label for chiral atoms that aren't in a stereo group.
369 \param bondLabel: label for CIP stereochemistry on bonds
370
371 If any label is empty, the corresponding annotations will not be added.
372
373 The labels can contain the following placeholders:
374 {id} - the stereo group's index
375 {cip} - the atom or bond's CIP stereochemistry
376
377 Note that CIP labels will only be added if CIP stereochemistry has been
378 assigned to the molecule.
379
380 */
382 ROMol &mol, std::string absLabel = "abs ({cip})",
383 std::string orLabel = "or{id}", std::string andLabel = "and{id}",
384 std::string cipLabel = "({cip})", std::string bondLabel = "({cip})");
385
386//! simplifies the stereochemical representation of a molecule where all
387//! specified stereocenters are in the same StereoGroup
388/*!
389 \param mol: molecule to modify
390 \param removeAffectedStereoGroups: if set then the affected StereoGroups will
391 be removed
392
393If all specified stereocenters are in the same AND or OR stereogroup, a
394moleculeNote property will be set on the molecule with the value "AND
395enantiomer" or "OR enantiomer". CIP labels, if present, are removed.
396
397*/
399 ROMol &mol, bool removeAffectedStereoGroups = true);
400
401//! returns the meso centers in a molecule (if any)
402/*!
403 \param mol: molecule to work with
404
405*/
406RDKIT_GRAPHMOL_EXPORT std::vector<std::pair<unsigned int, unsigned int>>
407findMesoCenters(const ROMol &mol, bool includeIsotopes = true,
408 bool includeAtomMaps = false);
409
410} // namespace Chirality
411} // namespace RDKit
412#endif
The class for representing atoms.
Definition Atom.h:75
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:273
WedgeInfoAtropisomer(int bondId, RDKit::Bond::BondDir dirInit)
Definition Chirality.h:265
Bond::BondDir getDir() const override
Definition Chirality.h:277
virtual Bond::BondDir getDir() const =0
virtual WedgeInfoType getType() const =0
Bond::BondDir getDir() const override
Definition Chirality.h:257
WedgeInfoType getType() const override
Definition Chirality.h:254
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 bool getAllowNontetrahedralChirality()
RDKIT_GRAPHMOL_EXPORT void wedgeMolBonds(ROMol &mol, const Conformer *conf=nullptr, const BondWedgingParameters *params=nullptr)
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:30
constexpr bool useLegacyStereoDefaultVal
Definition Chirality.h:36
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:32
RDKIT_GRAPHMOL_EXPORT void removeNonExplicit3DChirality(ROMol &mol)
constexpr auto useLegacyStereoEnvVar
Definition Chirality.h:33
RDKIT_GRAPHMOL_EXPORT bool useLegacyStereoPerception
Definition Chirality.h:53
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 unsigned int getChiralPermutation(const Atom *center, const INT_LIST &probe)
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:34
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:295
std::vector< int > INT_VECT
Definition types.h:289
bool rdvalue_is(const RDValue_cast_t)
std::vector< UINT > UINT_VECT
Definition types.h:308
static const unsigned NOATOM
Definition Chirality.h:122
std::vector< unsigned > controllingAtoms
Definition Chirality.h:129
StereoSpecified specified
Definition Chirality.h:125
StereoDescriptor descriptor
Definition Chirality.h:127
bool operator!=(const StereoInfo &other) const
Definition Chirality.h:137
bool operator==(const StereoInfo &other) const
Definition Chirality.h:131