RDKit: StructChecker.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

StructChecker.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2016 Novartis Institutes for BioMedical Research
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
11 /*! \file StructChecker.h
12
13 \brief Contains the public API of the StructChecker
14
15 \b Note that this should be considered beta and that the API may change in
16 future
17 releases.
18
19 */
20 #pragma once
21 #ifndef RD_STRUCTCHECKER_H_Oct2016
22 #define RD_STRUCTCHECKER_H_Oct2016
23
24 #include <string>
25 #include <vector>
26 #include "../RDKitBase.h"
27
28 namespace RDKit {
29 namespace StructureCheck {
30
31 // Flags for the return values of the StructureChecker
32
33 // TypeDefs for translating augmented atom pairs
34 static const int ANY_CHARGE = 8;
35 enum RadicalType {
36 RT_NONE = 0,
37 SINGLET = 1,
38 DOUBLET = 2,
39 TRIPLET = 3,
40 ANY_RADICAL = 0xFF
41 };
42
43 enum AABondType { // MDL CTFile bond types plus extensions
44 BT_NONE = 0, // means REMOVE Bond
45 SINGLE = 1,
46 DOUBLE = 2,
47 TRIPLE = 3,
48 AROMATIC = 4,
49 SINGLE_DOUBLE = 5,
50 SINGLE_AROMATIC = 6,
51 DOUBLE_AROMATIC = 7,
52 ANY_BOND = 8,
53 ALL_BOND_TYPES = 0xF
54 };
55
56 enum AATopology {
57 TP_NONE = 0, // Don't care
58 RING = 1, // Ring
59 CHAIN = 2 // Chain
60 };
61
62 struct Ligand {
63 std::string AtomSymbol;
64 int Charge;
65 RadicalType Radical;
66 unsigned SubstitutionCount; // substitution count 0 = don't care
67 AABondType BondType;
68 Ligand()
69 : Charge(ANY_CHARGE),
70 Radical(ANY_RADICAL),
71 SubstitutionCount(0),
72 BondType(ANY_BOND) {}
73 };
74
75 struct AugmentedAtom {
76 std::string AtomSymbol;
77 std::string ShortName;
78 int Charge;
79 RadicalType Radical;
80 AATopology Topology;
81 std::vector<Ligand> Ligands;
82
83 AugmentedAtom()
84 : Charge(ANY_CHARGE), Radical(ANY_RADICAL), Topology(TP_NONE) {}
85
86 AugmentedAtom(const std::string &symbol, const std::string &name, int charge,
87 RadicalType radical, AATopology topology)
88 : AtomSymbol(symbol),
89 ShortName(name),
90 Charge(charge),
91 Radical(radical),
92 Topology(topology) {}
93 };
94
95 struct IncEntry {
96 std::string AtomSymbol;
97 double LocalInc;
98 double AlphaInc;
99 double BetaInc;
100 double MultInc;
101
102 // Used for logging
103 int local_inc_used;
104 int alpha_inc_used;
105 int beta_inc_used;
106 int mult_inc_used;
107 };
108
109 struct PathEntry {
110 AugmentedAtom Path;
111 double Cond;
112 // Used for logging
113 int cond_used;
114 };
115 //-------------
116
117 //! Structure Check Options
118 // Holds all the user options for the StructureChecking.
119 // Can be initialized from factory functions, perhaps serialized
120 struct StructCheckerOptions {
121 double AcidityLimit;
122 bool RemoveMinorFragments;
123 int DesiredCharge;
124 bool CheckCollisions;
125 int CollisionLimitPercent;
126 unsigned MaxMolSize;
127 bool ConvertSText;
128 bool SqueezeIdentifiers;
129 bool StripZeros;
130 bool CheckStereo;
131 bool ConvertAtomTexts;
132 bool GroupsToSGroups;
133 bool Verbose;
134
135 // Internal data for struchk
136 std::vector<std::pair<AugmentedAtom, AugmentedAtom> > AugmentedAtomPairs;
137 std::vector<AugmentedAtom> AcidicAtoms;
138 std::vector<AugmentedAtom> GoodAtoms;
139 std::vector<ROMOL_SPTR> Patterns;
140 std::vector<ROMOL_SPTR> RotatePatterns;
141 std::vector<ROMOL_SPTR> StereoPatterns;
142 std::vector<ROMOL_SPTR> FromTautomer;
143 std::vector<ROMOL_SPTR> ToTautomer;
144
145 double Elneg0; // elneg_table[0].value;
146 std::map<unsigned, double> ElnegTable; // AtomicNumber -> eleng
147 std::vector<IncEntry> AtomAcidity; // atom_acidity_table[]
148 std::vector<IncEntry> ChargeIncTable;
149 // std::map AtomSymbol(or AtomicNumber) -> IncEntry
150 /* [ReadTransformation() ]
151 * The alpha, beta coefficients of the transfomation function used
152 * to stretch the preliminary pKa values to the actual predictions.
153 * The function is pKa = 7 + (pKa'-7)*beta + ((pKa'-7)*alpha)^3.
154 */
155
156 double Alpha, Beta;
157 std::vector<PathEntry> AlphaPathTable, BetaPathTable;
158
159 public:
160 StructCheckerOptions();
161
162 void clear() { *this = StructCheckerOptions(); }
163
164 bool loadAugmentedAtomTranslations(const std::string &path);
165 void setAugmentedAtomTranslations(
166 const std::vector<std::pair<AugmentedAtom, AugmentedAtom> > &aaPairs);
167
168 bool loadAcidicAugmentedAtoms(const std::string &path);
169 void setAcidicAugmentedAtoms(const std::vector<AugmentedAtom> &acidicAtoms);
170
171 bool loadGoodAugmentedAtoms(const std::string &path);
172 void setGoodAugmentedAtoms(const std::vector<AugmentedAtom> &acidicAtoms);
173
174 bool loadPatterns(const std::string &path); // file with clean patterns
175 void parsePatterns(
176 const std::vector<std::string> &smarts); // can throw RDKit exeptions
177 void setPatterns(const std::vector<ROMOL_SPTR> &p);
178
179 bool loadRotatePatterns(
180 const std::string &path); // file with rotate patterns
181 void parseRotatePatterns(
182 const std::vector<std::string> &smarts); // can throw RDKit exeptions
183 void setRotatePatterns(const std::vector<ROMOL_SPTR> &p);
184
185 bool loadStereoPatterns(
186 const std::string &path); // file with stereo patterns
187 void parseStereoPatterns(
188 const std::vector<std::string> &smarts); // can throw RDKit exeptions
189 void setStereoPatterns(const std::vector<ROMOL_SPTR> &p);
190
191 bool loadTautomerData(const std::string &path); // file path
192 void parseTautomerData(const std::vector<std::string> &smartsFrom,
193 const std::vector<std::string> &smartsTo);
194 void setTautomerData(const std::vector<ROMOL_SPTR> &from,
195 const std::vector<ROMOL_SPTR> &to);
196 bool loadChargeDataTables(const std::string &path); // file path
197 };
198
199 bool parseOptionsJSON(const std::string &json, StructCheckerOptions &op);
200
201 bool loadOptionsFromFiles(
202 StructCheckerOptions &op,
203 const std::string &augmentedAtomTranslationsFile = "",
204 // ?? AcidicAtoms;
205 // ?? GoodAtoms;
206 const std::string &patternFile = "", // file with clean patterns
207 const std::string &rotatePatternFile = "", // file with rotate patterns
208 const std::string &stereoPatternFile = "", // file with stereo patterns
209 const std::string &tautomerFile = "");
210
211 //! \brief Class for performing structure validation and cleanup
212 /*! \b NOTE: This class should be considered beta. The API may change in future
213 releases.
214
215 Examples of Usage
216
217 \code
218 StructChecker chk;
219 int flags = StructureCheck::checkMolStructure( mol ); // use defaults
220 \endcode
221
222 or
223
224 \code
225 StructureCheck::StructCheckerOptions options; // use defaults
226 // To use external data
227 StructureCheck::loadOptionsFromFiles(options, file1, file2);
228 StructChecker chk(options);
229
230 for( mol in mols ) {
231 int flags = StructureCheck::checkMolStructure( mol, &options);
232 if (0!=(flags & StructureCheck::StructureFlags::BAD_SET)) {
233 // write to error file
234 } else if (0!=(flags & StructureCheck::StructureFlags::TRANSFORMED_SET))
235 {
236 // input molecule was transformed
237 } else { // flag == NO_CHANGE
238 // no change
239 }
240 }
241 \endcode
242 */
243 class StructChecker {
244 public:
245 typedef enum StructureFlags {
246 NO_CHANGE = 0,
247 BAD_MOLECULE = 0x0001,
248 ALIAS_CONVERSION_FAILED = 0x0002,
249 STEREO_ERROR = 0x0004,
250 STEREO_FORCED_BAD = 0x0008,
251 ATOM_CLASH = 0x0010,
252 ATOM_CHECK_FAILED = 0x0020,
253 SIZE_CHECK_FAILED = 0x0040,
254 // reserved error = 0x0080,
255 TRANSFORMED = 0x0100,
256 FRAGMENTS_FOUND = 0x0200,
257 EITHER_WARNING = 0x0400,
258 DUBIOUS_STEREO_REMOVED = 0x0800,
259 RECHARGED = 0x1000,
260 STEREO_TRANSFORMED = 0x2000,
261 TEMPLATE_TRANSFORMED = 0x4000,
262 TAUTOMER_TRANSFORMED = 0x8000,
263 // mask:
264 BAD_SET = (BAD_MOLECULE | ALIAS_CONVERSION_FAILED | STEREO_ERROR |
265 STEREO_FORCED_BAD | ATOM_CLASH | ATOM_CHECK_FAILED |
266 SIZE_CHECK_FAILED),
267
268 TRANSFORMED_SET = (TRANSFORMED | FRAGMENTS_FOUND | EITHER_WARNING |
269 DUBIOUS_STEREO_REMOVED | STEREO_TRANSFORMED |
270 TEMPLATE_TRANSFORMED | TAUTOMER_TRANSFORMED | RECHARGED),
271 } StructureFlags;
272 // attributes:
273 private:
274 StructCheckerOptions Options;
275
276 public:
277 inline StructChecker() {}
278 inline StructChecker(const StructCheckerOptions &options)
279 : Options(options) {}
280
281 const StructCheckerOptions &GetOptions() const { return Options; }
282 void SetOptions(const StructCheckerOptions &options) { Options = options; }
283
284 // Check and fix (if need) molecule structure and return a set of
285 // StructureFlags
286 // that describes what have been done
287 unsigned checkMolStructure(RWMol &mol) const;
288
289 // an instance independed helper methods:
290 // Converts structure property flags to a comma seperated string
291 static std::string StructureFlagsToString(unsigned flags);
292 // Converts a comma seperated string to a StructureFlag unsigned integer
293 static unsigned StringToStructureFlags(const std::string &str);
294 // internal implementation:
295 private:
296 };
297 }
298 }
299 #endif
RDKit::StructureCheck::StructChecker
Class for performing structure validation and cleanup.
Definition: StructChecker.h:243
RDKit::StructureCheck::AugmentedAtom::Ligands
std::vector< Ligand > Ligands
Definition: StructChecker.h:81
RDKit::StructureCheck::loadOptionsFromFiles
bool loadOptionsFromFiles(StructCheckerOptions &op, const std::string &augmentedAtomTranslationsFile="", const std::string &patternFile="", const std::string &rotatePatternFile="", const std::string &stereoPatternFile="", const std::string &tautomerFile="")
RDKit::StructureCheck::StructCheckerOptions::MaxMolSize
unsigned MaxMolSize
Definition: StructChecker.h:126
RDKit::StructureCheck::StructCheckerOptions::Patterns
std::vector< ROMOL_SPTR > Patterns
Definition: StructChecker.h:139
RDKit::StructureCheck::BT_NONE
Definition: StructChecker.h:44
RDKit::StructureCheck::IncEntry::AtomSymbol
std::string AtomSymbol
Definition: StructChecker.h:96
RDKit::StructureCheck::RadicalType
RadicalType
Definition: StructChecker.h:35
RDKit::StructureCheck::StructCheckerOptions::AtomAcidity
std::vector< IncEntry > AtomAcidity
Definition: StructChecker.h:147
RDKit::StructureCheck::StructCheckerOptions::FromTautomer
std::vector< ROMOL_SPTR > FromTautomer
Definition: StructChecker.h:142
RDKit::StructureCheck::DOUBLE
Definition: StructChecker.h:46
RDKit::StructureCheck::DOUBLE_AROMATIC
Definition: StructChecker.h:51
RDKit::StructureCheck::StructChecker::GetOptions
const StructCheckerOptions & GetOptions() const
Definition: StructChecker.h:281
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:30
RDKit::StructureCheck::Ligand
Definition: StructChecker.h:62
RDKit::StructureCheck::AugmentedAtom::ShortName
std::string ShortName
Definition: StructChecker.h:77
RDKit::StructureCheck::TP_NONE
Definition: StructChecker.h:57
RDKit::StructureCheck::IncEntry::AlphaInc
double AlphaInc
Definition: StructChecker.h:98
RDKit::StructureCheck::parseOptionsJSON
bool parseOptionsJSON(const std::string &json, StructCheckerOptions &op)
RDKit::StructureCheck::StructCheckerOptions::DesiredCharge
int DesiredCharge
Definition: StructChecker.h:123
RDKit::StructureCheck::SINGLE_AROMATIC
Definition: StructChecker.h:50
RDKit::StructureCheck::StructCheckerOptions::AugmentedAtomPairs
std::vector< std::pair< AugmentedAtom, AugmentedAtom > > AugmentedAtomPairs
Definition: StructChecker.h:136
RDKit::StructureCheck::StructCheckerOptions::Beta
double Beta
Definition: StructChecker.h:156
RDKit::StructureCheck::IncEntry
Definition: StructChecker.h:95
RDKit::StructureCheck::CHAIN
Definition: StructChecker.h:59
RDKit::StructureCheck::StructChecker::StructChecker
StructChecker()
Definition: StructChecker.h:277
RDKit::StructureCheck::ANY_RADICAL
Definition: StructChecker.h:40
RDKit::StructureCheck::TRIPLE
Definition: StructChecker.h:47
RDKit::StructureCheck::Ligand::Radical
RadicalType Radical
Definition: StructChecker.h:65
RDKit::StructureCheck::StructCheckerOptions::Elneg0
double Elneg0
Definition: StructChecker.h:145
RDKit::StructureCheck::SINGLET
Definition: StructChecker.h:37
RDKit::StructureCheck::AugmentedAtom::AugmentedAtom
AugmentedAtom(const std::string &symbol, const std::string &name, int charge, RadicalType radical, AATopology topology)
Definition: StructChecker.h:86
RDKit::StructureCheck::PathEntry::Cond
double Cond
Definition: StructChecker.h:111
RDKit::StructureCheck::Ligand::SubstitutionCount
unsigned SubstitutionCount
Definition: StructChecker.h:66
RDKit::StructureCheck::AugmentedAtom::Topology
AATopology Topology
Definition: StructChecker.h:80
RDKit::StructureCheck::IncEntry::BetaInc
double BetaInc
Definition: StructChecker.h:99
RDKit::StructureCheck::StructCheckerOptions::clear
void clear()
Definition: StructChecker.h:162
RDKit::StructureCheck::SINGLE
Definition: StructChecker.h:45
RDKit::StructureCheck::AROMATIC
Definition: StructChecker.h:48
RDKit::StructureCheck::AugmentedAtom::AugmentedAtom
AugmentedAtom()
Definition: StructChecker.h:83
RDKit::StructureCheck::StructCheckerOptions::StripZeros
bool StripZeros
Definition: StructChecker.h:129
RDKit::StructureCheck::SINGLE_DOUBLE
Definition: StructChecker.h:49
RDKit::StructureCheck::StructCheckerOptions::GroupsToSGroups
bool GroupsToSGroups
Definition: StructChecker.h:132
RDKit::StructureCheck::PathEntry::cond_used
int cond_used
Definition: StructChecker.h:113
RDKit::StructureCheck::StructCheckerOptions
Structure Check Options.
Definition: StructChecker.h:120
RDKit::StructureCheck::RT_NONE
Definition: StructChecker.h:36
RDKit::StructureCheck::StructCheckerOptions::BetaPathTable
std::vector< PathEntry > BetaPathTable
Definition: StructChecker.h:157
RDKit::StructureCheck::StructCheckerOptions::RemoveMinorFragments
bool RemoveMinorFragments
Definition: StructChecker.h:122
RDKit::StructureCheck::Ligand::Ligand
Ligand()
Definition: StructChecker.h:68
RDKit::StructureCheck::StructChecker::StructChecker
StructChecker(const StructCheckerOptions &options)
Definition: StructChecker.h:278
RDKit::StructureCheck::StructCheckerOptions::GoodAtoms
std::vector< AugmentedAtom > GoodAtoms
Definition: StructChecker.h:138
RDKit::StructureCheck::IncEntry::MultInc
double MultInc
Definition: StructChecker.h:100
RDKit::StructureCheck::AugmentedAtom
Definition: StructChecker.h:75
RDKit::StructureCheck::ANY_CHARGE
static const int ANY_CHARGE
Definition: StructChecker.h:34
RDKit
Std stuff.
Definition: Atom.h:29
RDKit::StructureCheck::StructCheckerOptions::ToTautomer
std::vector< ROMOL_SPTR > ToTautomer
Definition: StructChecker.h:143
RDKit::StructureCheck::IncEntry::local_inc_used
int local_inc_used
Definition: StructChecker.h:103
RDKit::StructureCheck::StructCheckerOptions::Verbose
bool Verbose
Definition: StructChecker.h:133
RDKit::StructureCheck::StructChecker::StructureFlags
StructureFlags
Definition: StructChecker.h:245
RDKit::StructureCheck::StructCheckerOptions::StereoPatterns
std::vector< ROMOL_SPTR > StereoPatterns
Definition: StructChecker.h:141
RDKit::StructureCheck::ANY_BOND
Definition: StructChecker.h:52
RDKit::StructureCheck::AABondType
AABondType
Definition: StructChecker.h:43
RDKit::StructureCheck::StructCheckerOptions::ConvertAtomTexts
bool ConvertAtomTexts
Definition: StructChecker.h:131
RDKit::StructureCheck::StructCheckerOptions::ElnegTable
std::map< unsigned, double > ElnegTable
Definition: StructChecker.h:146
RDKit::StructureCheck::AugmentedAtom::AtomSymbol
std::string AtomSymbol
Definition: StructChecker.h:76
RDKit::StructureCheck::PathEntry
Definition: StructChecker.h:109
RDKit::StructureCheck::StructCheckerOptions::ChargeIncTable
std::vector< IncEntry > ChargeIncTable
Definition: StructChecker.h:148
RDKit::StructureCheck::Ligand::AtomSymbol
std::string AtomSymbol
Definition: StructChecker.h:63
RDKit::StructureCheck::AugmentedAtom::Charge
int Charge
Definition: StructChecker.h:78
RDKit::StructureCheck::StructCheckerOptions::CheckCollisions
bool CheckCollisions
Definition: StructChecker.h:124
RDKit::StructureCheck::StructChecker::SetOptions
void SetOptions(const StructCheckerOptions &options)
Definition: StructChecker.h:282
RDKit::StructureCheck::StructCheckerOptions::CheckStereo
bool CheckStereo
Definition: StructChecker.h:130
RDKit::StructureCheck::IncEntry::LocalInc
double LocalInc
Definition: StructChecker.h:97
RDKit::StructureCheck::DOUBLET
Definition: StructChecker.h:38
RDKit::StructureCheck::IncEntry::beta_inc_used
int beta_inc_used
Definition: StructChecker.h:105
RDKit::StructureCheck::IncEntry::alpha_inc_used
int alpha_inc_used
Definition: StructChecker.h:104
RDKit::StructureCheck::Ligand::BondType
AABondType BondType
Definition: StructChecker.h:67
RDKit::StructureCheck::StructCheckerOptions::RotatePatterns
std::vector< ROMOL_SPTR > RotatePatterns
Definition: StructChecker.h:140
RDKit::StructureCheck::StructCheckerOptions::ConvertSText
bool ConvertSText
Definition: StructChecker.h:127
RDKit::StructureCheck::PathEntry::Path
AugmentedAtom Path
Definition: StructChecker.h:110
RDKit::StructureCheck::StructCheckerOptions::CollisionLimitPercent
int CollisionLimitPercent
Definition: StructChecker.h:125
RDKit::StructureCheck::StructCheckerOptions::AcidicAtoms
std::vector< AugmentedAtom > AcidicAtoms
Definition: StructChecker.h:137
RDKit::StructureCheck::AATopology
AATopology
Definition: StructChecker.h:56
RDKit::StructureCheck::StructCheckerOptions::AcidityLimit
double AcidityLimit
Definition: StructChecker.h:121
RDKit::StructureCheck::Ligand::Charge
int Charge
Definition: StructChecker.h:64
RDKit::StructureCheck::AugmentedAtom::Radical
RadicalType Radical
Definition: StructChecker.h:79
RDKit::StructureCheck::TRIPLET
Definition: StructChecker.h:39
RDKit::StructureCheck::ALL_BOND_TYPES
Definition: StructChecker.h:53
RDKit::StructureCheck::StructCheckerOptions::SqueezeIdentifiers
bool SqueezeIdentifiers
Definition: StructChecker.h:128
RDKit::StructureCheck::IncEntry::mult_inc_used
int mult_inc_used
Definition: StructChecker.h:106
RDKit::StructureCheck::RING
Definition: StructChecker.h:58