/src/rdkit/Code/GraphMol/CIPLabeler/CIPLabeler.h
Line | Count | Source |
1 | | // |
2 | | // |
3 | | // Copyright (C) 2020 Schrödinger, LLC |
4 | | // |
5 | | // @@ All Rights Reserved @@ |
6 | | // This file is part of the RDKit. |
7 | | // The contents are covered by the terms of the BSD license |
8 | | // which is included in the file license.txt, found at the root |
9 | | // of the RDKit source tree. |
10 | | // |
11 | | #pragma once |
12 | | |
13 | | #include <RDGeneral/BoostStartInclude.h> |
14 | | #include <boost/dynamic_bitset.hpp> |
15 | | #include <RDGeneral/BoostEndInclude.h> |
16 | | |
17 | | #include <RDGeneral/export.h> |
18 | | |
19 | | namespace RDKit { |
20 | | |
21 | | class ROMol; |
22 | | |
23 | | namespace CIPLabeler_detail { |
24 | | RDKIT_CIPLABELER_EXPORT bool decrementRemainingCallCountAndCheck(); |
25 | | } |
26 | | |
27 | | namespace CIPLabeler { |
28 | | |
29 | | /* |
30 | | Some very symmetrical mols can cause pseudo-infinite processing |
31 | | (e.g. dodecahedrane). To avoid this, the caller can limit the total number |
32 | | of recursive comparisons performed by assignCIPLabels. The limit applies |
33 | | across both the preliminary and full labeling passes. If the limit is |
34 | | exhausted, the following error is thrown. |
35 | | */ |
36 | | |
37 | | class RDKIT_CIPLABELER_EXPORT MaxIterationsExceeded |
38 | | : public std::runtime_error { |
39 | | public: |
40 | | explicit MaxIterationsExceeded() |
41 | | : std::runtime_error( |
42 | 0 | "Max Iterations Exceeded in CIP label calculation"){}; |
43 | | }; |
44 | | |
45 | | /** |
46 | | * Calculate Stereochemical labels based on an accurate implementation |
47 | | * of the CIP rules. |
48 | | * |
49 | | * This is a C++ port of https://github.com/SiMolecule/centres, which was |
50 | | * originally written by John Mayfield in Java. The original algorithm was |
51 | | * described in: |
52 | | * |
53 | | * Hanson, R. M., Musacchio, S., Mayfield, J. W., Vainio, M. J., Yerin, A., |
54 | | * Redkin, D. Algorithmic Analysis of Cahn--Ingold--Prelog Rules of |
55 | | * Stereochemistry: Proposals for Revised Rules and a Guide for Machine |
56 | | * Implementation. J. Chem. Inf. Model. 2018, 58, 1755-1765. |
57 | | * |
58 | | * \param mol - the molecule to be labelled. |
59 | | * |
60 | | * \note only atoms with chiral tags and double bonds with proper |
61 | | * bond directions will be labelled. |
62 | | * \note Labels will be stored under the common_properties::_CIPCode |
63 | | * property of the relevant atoms/bonds. |
64 | | * \param maxRecursiveIterations - maximum total number of recursive |
65 | | * comparisons across all labeling passes; zero means no |
66 | | * caller-specified limit. |
67 | | */ |
68 | | RDKIT_CIPLABELER_EXPORT void assignCIPLabels( |
69 | | ROMol &mol, unsigned int maxRecursiveIterations = 0); |
70 | | |
71 | | /** |
72 | | * Overload that allows selecting which atoms and/or bonds will be labeled. |
73 | | * |
74 | | * \param mol - the molecule to be labelled. |
75 | | * |
76 | | * \param atoms - bitset with the atom indexes to be labeled. |
77 | | * The bitset must have mol.getNumAtoms() bits. Unselected atom |
78 | | * configurations may still be used as auxiliary stereochemical |
79 | | * dependencies, but their primary labels are not written. |
80 | | * |
81 | | * \param bonds - bitset with the bond indexes to be labeled. |
82 | | * The bitset must have mol.getNumBonds() bits. Unselected bond |
83 | | * configurations may still be used as auxiliary stereochemical |
84 | | * dependencies, but their primary labels are not written. |
85 | | * |
86 | | * \param maxRecursiveIterations - maximum total number of recursive |
87 | | * comparisons across the preliminary and full labeling passes. A value |
88 | | * of zero means no caller-specified limit. A value of 1,250,000 takes |
89 | | * about 1 second. Most structures require fewer than 10,000 comparisons. |
90 | | * A peptide with MW~3000 took about 100 comparisons, and a 20,000 MW |
91 | | * protein took about 600 comparisons. |
92 | | * |
93 | | * \note Partial labeling does not set common_properties::_CIPComputed, |
94 | | * which denotes a complete molecule-wide calculation. |
95 | | * |
96 | | */ |
97 | | RDKIT_CIPLABELER_EXPORT void assignCIPLabels( |
98 | | ROMol &mol, const boost::dynamic_bitset<> &atoms, |
99 | | const boost::dynamic_bitset<> &bonds, |
100 | | unsigned int maxRecursiveIterations = 0); |
101 | | |
102 | | } // namespace CIPLabeler |
103 | | } // namespace RDKit |