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 const Conformer *conf = nullptr);
306
308 ROMol &mol, const Conformer *conf = nullptr,
309 const BondWedgingParameters *params = nullptr);
311 const Conformer *conf);
312
313//! Returns true for double bonds which should be shown as a crossed bonds.
314// It always returns false if any adjacent bond is a squiggle bond.
316
317//! Clears existing bond wedging and forces use of atom wedging from MolBlock.
318/*!
319 \param mol: molecule to have its wedges altered
320 */
322//! Remove MolBlock bond wedging information from molecule.
323/*!
324 \param mol: molecule to modify
325 */
327//! Invert bond wedging information read from a mol block (if present).
328/*!
329 \param mol: molecule to modify
330 */
332
333//! gets stereo info for a bond
334/*!
335 \param bond: bond to check
336 \param wedgeBonds - the list of bonds to have wedges
337 \param conf - Conformer to use
338 \param dirCode - receives the dircode for the bond
339 \param reverse - receives the reverse flag
340 only returned if it was exlicility set witha wiggle bond
341 */
342
344 const Bond *bond,
345 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
346 &wedgeBonds,
347 const Conformer *conf, int &dirCode, bool &reverse);
348
350 const Bond *bond,
351 const std::map<int, std::unique_ptr<RDKit::Chirality::WedgeInfoBase>>
352 &wedgeBonds,
353 const Conformer *conf, Bond::BondDir &dir, bool &reverse);
354
355//! add R/S, relative stereo, and E/Z annotations to atoms and bonds
356/*!
357 \param mol: molecule to modify
358 \param absLabel: label for atoms in an ABS stereo group
359 \param orLabel: label for atoms in an OR stereo group
360 \param andLabel: label for atoms in an AND stereo group
361 \param cipLabel: label for chiral atoms that aren't in a stereo group.
362 \param bondLabel: label for CIP stereochemistry on bonds
363
364 If any label is empty, the corresponding annotations will not be added.
365
366 The labels can contain the following placeholders:
367 {id} - the stereo group's index
368 {cip} - the atom or bond's CIP stereochemistry
369
370 Note that CIP labels will only be added if CIP stereochemistry has been
371 assigned to the molecule.
372
373 */
375 ROMol &mol, std::string absLabel = "abs ({cip})",
376 std::string orLabel = "or{id}", std::string andLabel = "and{id}",
377 std::string cipLabel = "({cip})", std::string bondLabel = "({cip})");
378
379} // namespace Chirality
380} // namespace RDKit
381#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 void reapplyMolBlockWedging(ROMol &mol)
Clears existing bond wedging and forces use of atom wedging from MolBlock.
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 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 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::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 std::map< int, std::unique_ptr< Chirality::WedgeInfoBase > > pickBondsToWedge(const ROMol &mol, const BondWedgingParameters *params=nullptr, const Conformer *conf=nullptr)
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:290
std::vector< int > INT_VECT
Definition types.h:284
bool rdvalue_is(const RDValue_cast_t)
std::vector< UINT > UINT_VECT
Definition types.h:303
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