1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
//
// Copyright (C) 2018-2021 Susan H. Leung and other RDKit contributors
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
/*! \file Validate.h
\brief Defines the ValidationErrorInfo class and four different
validation methods: RDKitValidation, MolVSValidation, AllowedAtomsValidation,
DisallowedAtomsValidation.
*/
#include <RDGeneral/export.h>
#ifndef RD_VALIDATE_H
#define RD_VALIDATE_H
#include <GraphMol/RDKitBase.h>
#include <GraphMol/ROMol.h>
#include <GraphMol/Atom.h>
#include <iostream>
#include <exception>
#include <string>
#include <utility>
#include <vector>
namespace RDKit {
class RWMol;
class ROMol;
class Conformer;
namespace MolStandardize {
//! The ValidationErrorInfo class is used to store the information returned by a
/// ValidationMethod validate.
using ValidationErrorInfo = std::string;
//! The ValidationMethod class is the abstract base class upon which all the
/// four different ValidationMethods inherit from.
class RDKIT_MOLSTANDARDIZE_EXPORT ValidationMethod {
public:
ValidationMethod() = default;
virtual ~ValidationMethod() = default;
virtual std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const = 0;
virtual std::shared_ptr<ValidationMethod> copy() const = 0;
};
//! The CompositeValidation class provides a simple way to apply a collection of
// ValidationMethod instances in sequence
class RDKIT_MOLSTANDARDIZE_EXPORT CompositeValidation
: public ValidationMethod {
public:
CompositeValidation(
const std::vector<std::shared_ptr<ValidationMethod>> &validations)
: validations(validations) {};
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<CompositeValidation>(*this);
}
private:
std::vector<std::shared_ptr<ValidationMethod>> validations;
};
//! The RDKitValidation class throws an error when there are no atoms in the
/// molecule or when there is incorrect atom valency.
/*!
<b>Notes:</b>
- RDKit automatically throws up atom valency issues but this class was made
for completeness of the project.
*/
class RDKIT_MOLSTANDARDIZE_EXPORT RDKitValidation : public ValidationMethod {
public:
RDKitValidation(bool allowEmptyMolecules = false)
: allowEmptyMolecules(allowEmptyMolecules) {};
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<RDKitValidation>(*this);
}
bool allowEmptyMolecules;
};
//////////////////////////////
/// MolVS Validations
//
//! The NoAtomValidation class throws an error if no atoms are present in the
/// molecule.
class RDKIT_MOLSTANDARDIZE_EXPORT NoAtomValidation : public ValidationMethod {
public:
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<NoAtomValidation>(*this);
}
};
//! The FragmentValidation class logs if certain fragments are present.
class RDKIT_MOLSTANDARDIZE_EXPORT FragmentValidation : public ValidationMethod {
public:
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<FragmentValidation>(*this);
}
};
//! The NeutralValidation class logs if not an overall neutral system.
class RDKIT_MOLSTANDARDIZE_EXPORT NeutralValidation : public ValidationMethod {
public:
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<NeutralValidation>(*this);
}
};
//! The IsotopeValidation class logs if molecule contains isotopes.
/*!
<b>Notes:</b>
- By default, this class will return an error every time an isotopic
number is specified. When the `strict` constructor parameter is passed a
`true` argument, an error is returned only if the specified isotopic number
is not found in the RDKit periodic table.
*/
class RDKIT_MOLSTANDARDIZE_EXPORT IsotopeValidation : public ValidationMethod {
public:
IsotopeValidation(bool strict = false) : strict(strict) {};
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<IsotopeValidation>(*this);
}
bool strict;
};
////////////////////////////////
//! The MolVSValidation class includes most of the same validations as
/// molvs.validations, namely NoAtomValidation, FragmentValidation,
/// NeutralValidation, IsotopeValidation. MolVS also has IsNoneValidation and
/// DichloroethaneValidation but these were not included here (yet).
class RDKIT_MOLSTANDARDIZE_EXPORT MolVSValidation : public CompositeValidation {
public:
// constructor
MolVSValidation();
//! overloaded constructor to take in a user-defined list of ValidationMethod
MolVSValidation(
const std::vector<std::shared_ptr<ValidationMethod>> &validations);
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<MolVSValidation>(*this);
}
};
//! The AllowedAtomsValidation class lets the user input a list of atoms,
//! anything not on the list throws an error.
class RDKIT_MOLSTANDARDIZE_EXPORT AllowedAtomsValidation
: public ValidationMethod {
public:
AllowedAtomsValidation(std::vector<std::shared_ptr<Atom>> atoms)
: d_allowedList(std::move(atoms)) {}
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<AllowedAtomsValidation>(*this);
}
private:
std::vector<std::shared_ptr<Atom>> d_allowedList;
};
//! The DisallowedAtomsValidation class lets the user input a list of atoms and
//! as long as there are no atoms from the list it is deemed acceptable.
class RDKIT_MOLSTANDARDIZE_EXPORT DisallowedAtomsValidation
: public ValidationMethod {
public:
DisallowedAtomsValidation(std::vector<std::shared_ptr<Atom>> atoms)
: d_disallowedList(std::move(atoms)) {}
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<DisallowedAtomsValidation>(*this);
}
private:
std::vector<std::shared_ptr<Atom>> d_disallowedList;
};
//! The DisallowedRadicalValidation class reports an error if any
/// unstable radical atoms are found.
/// The allowed radicals are [N]=O and [O]-N.
class RDKIT_MOLSTANDARDIZE_EXPORT DisallowedRadicalValidation
: public ValidationMethod {
public:
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<DisallowedRadicalValidation>(*this);
}
};
//! The FeaturesValidation class reports an error if the input
/// molecule representation includes any undesired features.
class RDKIT_MOLSTANDARDIZE_EXPORT FeaturesValidation : public ValidationMethod {
public:
FeaturesValidation(bool allowEnhancedStereo = false,
bool allowAromaticBondType = false,
bool allowDativeBondType = false,
bool allowQueries = false, bool allowDummies = false,
bool allowAtomAliases = false)
: allowEnhancedStereo(allowEnhancedStereo),
allowAromaticBondType(allowAromaticBondType),
allowDativeBondType(allowDativeBondType),
allowQueries(allowQueries),
allowDummies(allowDummies),
allowAtomAliases(allowAtomAliases) {};
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<FeaturesValidation>(*this);
}
bool allowEnhancedStereo;
bool allowAromaticBondType;
bool allowDativeBondType;
bool allowQueries;
bool allowDummies;
bool allowAtomAliases;
};
//! The Is2DValidation class reports an error if the input
/// molecule representation is designated as 3D or if it includes
/// non-null Z coordinates, and in case all atoms are assigned the
/// same coordinates.
class RDKIT_MOLSTANDARDIZE_EXPORT Is2DValidation : public ValidationMethod {
public:
Is2DValidation(double threshold = 1.e-3) : threshold(threshold) {};
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<Is2DValidation>(*this);
}
double threshold;
};
//! The Layout2DValidation class reports an error if any atoms are
/// too close to any other atoms or bonds, and in case any bonds are
/// too long.
class RDKIT_MOLSTANDARDIZE_EXPORT Layout2DValidation : public ValidationMethod {
public:
Layout2DValidation(double clashLimit = 0.15, double bondLengthLimit = 25.,
bool allowLongBondsInRings = true,
bool allowAtomBondClashExemption = true,
double minMedianBondLength = 1e-3)
: clashLimit(clashLimit),
bondLengthLimit(bondLengthLimit),
allowLongBondsInRings(allowLongBondsInRings),
allowAtomBondClashExemption(allowAtomBondClashExemption),
minMedianBondLength(minMedianBondLength) {};
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<Layout2DValidation>(*this);
}
static double squaredMedianBondLength(const ROMol &mol,
const Conformer &conf);
double clashLimit;
double bondLengthLimit;
bool allowLongBondsInRings;
bool allowAtomBondClashExemption;
double minMedianBondLength;
};
//! The StereoValidation class checks various "syntactic" constraints
/// related to the usage of stereo bonds on centers with 4 or 3 substituents,
/// in an attempt to ensure that the associated stereochemical configuration
/// can be interpreted unambiguously.
/// These validation criteria were ported from the AvalonTools STRUCHK software.
class RDKIT_MOLSTANDARDIZE_EXPORT StereoValidation : public ValidationMethod {
public:
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
std::shared_ptr<ValidationMethod> copy() const override {
return std::make_shared<StereoValidation>(*this);
}
};
//! A convenience function for quickly validating a single SMILES string.
RDKIT_MOLSTANDARDIZE_EXPORT std::vector<ValidationErrorInfo> validateSmiles(
const std::string &smiles);
} // namespace MolStandardize
} // namespace RDKit
#endif
|