Loading...
Searching...
No Matches
Validate.h
Go to the documentation of this file.
//
// 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 <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
Atom.h
Defines the Atom class and associated typedefs.
RDKitBase.h
pulls in the core RDKit functionality
ROMol.h
Defines the primary molecule class ROMol as well as associated typedefs.
RDKit::Conformer
The class for representing 2D or 3D conformation of a molecule.
Definition Conformer.h:46
RDKit::MolStandardize::AllowedAtomsValidation::AllowedAtomsValidation
AllowedAtomsValidation(std::vector< std::shared_ptr< Atom > > atoms)
Definition Validate.h:177
RDKit::MolStandardize::AllowedAtomsValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:182
RDKit::MolStandardize::AllowedAtomsValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::CompositeValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:64
RDKit::MolStandardize::CompositeValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::CompositeValidation::CompositeValidation
CompositeValidation(const std::vector< std::shared_ptr< ValidationMethod > > &validations)
Definition Validate.h:57
RDKit::MolStandardize::DisallowedAtomsValidation::DisallowedAtomsValidation
DisallowedAtomsValidation(std::vector< std::shared_ptr< Atom > > atoms)
Definition Validate.h:195
RDKit::MolStandardize::DisallowedAtomsValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::DisallowedAtomsValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:200
RDKit::MolStandardize::DisallowedRadicalValidation
Definition Validate.h:212
RDKit::MolStandardize::DisallowedRadicalValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::DisallowedRadicalValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:217
RDKit::MolStandardize::FeaturesValidation::allowEnhancedStereo
bool allowEnhancedStereo
Definition Validate.h:242
RDKit::MolStandardize::FeaturesValidation::FeaturesValidation
FeaturesValidation(bool allowEnhancedStereo=false, bool allowAromaticBondType=false, bool allowDativeBondType=false, bool allowQueries=false, bool allowDummies=false, bool allowAtomAliases=false)
Definition Validate.h:226
RDKit::MolStandardize::FeaturesValidation::allowQueries
bool allowQueries
Definition Validate.h:245
RDKit::MolStandardize::FeaturesValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:239
RDKit::MolStandardize::FeaturesValidation::allowAromaticBondType
bool allowAromaticBondType
Definition Validate.h:243
RDKit::MolStandardize::FeaturesValidation::allowDativeBondType
bool allowDativeBondType
Definition Validate.h:244
RDKit::MolStandardize::FeaturesValidation::allowAtomAliases
bool allowAtomAliases
Definition Validate.h:247
RDKit::MolStandardize::FeaturesValidation::allowDummies
bool allowDummies
Definition Validate.h:246
RDKit::MolStandardize::FeaturesValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::FragmentValidation
The FragmentValidation class logs if certain fragments are present.
Definition Validate.h:112
RDKit::MolStandardize::FragmentValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:117
RDKit::MolStandardize::FragmentValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::Is2DValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::Is2DValidation::threshold
double threshold
Definition Validate.h:263
RDKit::MolStandardize::Is2DValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:259
RDKit::MolStandardize::Is2DValidation::Is2DValidation
Is2DValidation(double threshold=1.e-3)
Definition Validate.h:256
RDKit::MolStandardize::IsotopeValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:147
RDKit::MolStandardize::IsotopeValidation::strict
bool strict
Definition Validate.h:151
RDKit::MolStandardize::IsotopeValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::IsotopeValidation::IsotopeValidation
IsotopeValidation(bool strict=false)
Definition Validate.h:143
RDKit::MolStandardize::Layout2DValidation::clashLimit
double clashLimit
Definition Validate.h:289
RDKit::MolStandardize::Layout2DValidation::Layout2DValidation
Layout2DValidation(double clashLimit=0.15, double bondLengthLimit=25., bool allowLongBondsInRings=true, bool allowAtomBondClashExemption=true, double minMedianBondLength=1e-3)
Definition Validate.h:271
RDKit::MolStandardize::Layout2DValidation::allowAtomBondClashExemption
bool allowAtomBondClashExemption
Definition Validate.h:292
RDKit::MolStandardize::Layout2DValidation::minMedianBondLength
double minMedianBondLength
Definition Validate.h:293
RDKit::MolStandardize::Layout2DValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:282
RDKit::MolStandardize::Layout2DValidation::allowLongBondsInRings
bool allowLongBondsInRings
Definition Validate.h:291
RDKit::MolStandardize::Layout2DValidation::bondLengthLimit
double bondLengthLimit
Definition Validate.h:290
RDKit::MolStandardize::Layout2DValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::Layout2DValidation::squaredMedianBondLength
static double squaredMedianBondLength(const ROMol &mol, const Conformer &conf)
RDKit::MolStandardize::MolVSValidation::MolVSValidation
MolVSValidation(const std::vector< std::shared_ptr< ValidationMethod > > &validations)
overloaded constructor to take in a user-defined list of ValidationMethod
RDKit::MolStandardize::MolVSValidation::MolVSValidation
MolVSValidation()
RDKit::MolStandardize::MolVSValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:167
RDKit::MolStandardize::NeutralValidation
The NeutralValidation class logs if not an overall neutral system.
Definition Validate.h:123
RDKit::MolStandardize::NeutralValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::NeutralValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:128
RDKit::MolStandardize::NoAtomValidation
MolVS Validations.
Definition Validate.h:101
RDKit::MolStandardize::NoAtomValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:106
RDKit::MolStandardize::NoAtomValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::RDKitValidation::RDKitValidation
RDKitValidation(bool allowEmptyMolecules=false)
Definition Validate.h:82
RDKit::MolStandardize::RDKitValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::RDKitValidation::allowEmptyMolecules
bool allowEmptyMolecules
Definition Validate.h:92
RDKit::MolStandardize::RDKitValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:88
RDKit::MolStandardize::StereoValidation
Definition Validate.h:301
RDKit::MolStandardize::StereoValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::StereoValidation::copy
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:305
RDKit::MolStandardize::ValidationMethod::copy
virtual std::shared_ptr< ValidationMethod > copy() const =0
RDKit::MolStandardize::ValidationMethod::validate
virtual std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const =0
RDKit::MolStandardize::ValidationMethod::~ValidationMethod
virtual ~ValidationMethod()=default
RDKit::MolStandardize::ValidationMethod::ValidationMethod
ValidationMethod()=default
RDKit::ROMol
Definition ROMol.h:285
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
export.h
RDKIT_MOLSTANDARDIZE_EXPORT
#define RDKIT_MOLSTANDARDIZE_EXPORT
Definition export.h:377
RDKit::MolStandardize
Definition AcidBaseCatalogEntry.h:22
RDKit::MolStandardize::validateSmiles
RDKIT_MOLSTANDARDIZE_EXPORT std::vector< ValidationErrorInfo > validateSmiles(const std::string &smiles)
A convenience function for quickly validating a single SMILES string.
RDKit::MolStandardize::ValidationErrorInfo
std::string ValidationErrorInfo
Definition Validate.h:38
RDKit
Std stuff.
Definition Abbreviations.h:19