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 <iostream>
#include <exception>
#include <string>
#include <utility>
#include <vector>
namespace RDKit {
class RWMol;
class ROMol;
namespace MolStandardize {
//! The ValidationErrorInfo class is used to store the information returned by a
/// ValidationMethod validate.
class RDKIT_MOLSTANDARDIZE_EXPORT ValidationErrorInfo : public std::exception {
public:
ValidationErrorInfo(std::string msg) : d_msg(std::move(msg)) {
BOOST_LOG(rdInfoLog) << d_msg << std::endl;
}
const char *what() const noexcept override { return d_msg.c_str(); }
~ValidationErrorInfo() noexcept override = default;
private:
std::string d_msg;
}; // class ValidationErrorInfo
//! 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;
};
//! 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:
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
};
//////////////////////////////
/// MolVS Validations
//
//! The MolVSValidations 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 MolVSValidations {
public:
virtual void run(const ROMol &mol, bool reportAllFailures,
std::vector<ValidationErrorInfo> &errors) const = 0;
virtual boost::shared_ptr<MolVSValidations> copy() const = 0;
};
//! The NoAtomValidation class throws an error if no atoms are present in the
/// molecule.
class RDKIT_MOLSTANDARDIZE_EXPORT NoAtomValidation final
: public MolVSValidations {
public:
void run(const ROMol &mol, bool reportAllFailures,
std::vector<ValidationErrorInfo> &errors) const override;
//! makes a copy of NoAtomValidation object and returns a MolVSValidations
//! pointer to it
boost::shared_ptr<MolVSValidations> copy() const override {
return boost::make_shared<NoAtomValidation>(*this);
}
};
//! The FragmentValidation class logs if certain fragments are present.
class RDKIT_MOLSTANDARDIZE_EXPORT FragmentValidation final
: public MolVSValidations {
public:
void run(const ROMol &mol, bool reportAllFailures,
std::vector<ValidationErrorInfo> &errors) const override;
//! makes a copy of FragmentValidation object and returns a MolVSValidations
//! pointer to it
boost::shared_ptr<MolVSValidations> copy() const override {
return boost::make_shared<FragmentValidation>(*this);
}
};
//! The NeutralValidation class logs if not an overall neutral system.
class RDKIT_MOLSTANDARDIZE_EXPORT NeutralValidation final
: public MolVSValidations {
public:
void run(const ROMol &mol, bool reportAllFailures,
std::vector<ValidationErrorInfo> &errors) const override;
//! makes a copy of NeutralValidation object and returns a MolVSValidations
//! pointer to it
boost::shared_ptr<MolVSValidations> copy() const override {
return boost::make_shared<NeutralValidation>(*this);
}
};
//! The IsotopeValidation class logs if molecule contains isotopes.
class RDKIT_MOLSTANDARDIZE_EXPORT IsotopeValidation final
: public MolVSValidations {
public:
void run(const ROMol &mol, bool reportAllFailures,
std::vector<ValidationErrorInfo> &errors) const override;
//! makes a copy of IsotopeValidation object and returns a MolVSValidations
//! pointer to it
boost::shared_ptr<MolVSValidations> copy() const override {
return boost::make_shared<IsotopeValidation>(*this);
}
};
////////////////////////////////
//! The MolVSValidation class can be used to perform all MolVSValidions.
class RDKIT_MOLSTANDARDIZE_EXPORT MolVSValidation : public ValidationMethod {
public:
// constructor
MolVSValidation();
//! overloaded constructor to take in a user-defined list of MolVSValidations
MolVSValidation(
const std::vector<boost::shared_ptr<MolVSValidations>> validations);
MolVSValidation(const MolVSValidation &other);
~MolVSValidation() override;
std::vector<ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override;
private:
std::vector<boost::shared_ptr<MolVSValidations>> d_validations;
};
//! 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;
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;
private:
std::vector<std::shared_ptr<Atom>> d_disallowedList;
};
//! 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
BOOST_LOG
#define BOOST_LOG(__arg__)
Definition RDLog.h:110
rdInfoLog
RDKIT_RDGENERAL_EXPORT RDLogger rdInfoLog
ROMol.h
Defines the primary molecule class ROMol as well as associated typedefs.
RDKit::MolStandardize::AllowedAtomsValidation
Definition Validate.h:166
RDKit::MolStandardize::AllowedAtomsValidation::AllowedAtomsValidation
AllowedAtomsValidation(std::vector< std::shared_ptr< Atom > > atoms)
Definition Validate.h:168
RDKit::MolStandardize::AllowedAtomsValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::DisallowedAtomsValidation
Definition Validate.h:181
RDKit::MolStandardize::DisallowedAtomsValidation::DisallowedAtomsValidation
DisallowedAtomsValidation(std::vector< std::shared_ptr< Atom > > atoms)
Definition Validate.h:183
RDKit::MolStandardize::DisallowedAtomsValidation::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:105
RDKit::MolStandardize::FragmentValidation::run
void run(const ROMol &mol, bool reportAllFailures, std::vector< ValidationErrorInfo > &errors) const override
RDKit::MolStandardize::FragmentValidation::copy
boost::shared_ptr< MolVSValidations > copy() const override
Definition Validate.h:111
RDKit::MolStandardize::IsotopeValidation
The IsotopeValidation class logs if molecule contains isotopes.
Definition Validate.h:131
RDKit::MolStandardize::IsotopeValidation::copy
boost::shared_ptr< MolVSValidations > copy() const override
Definition Validate.h:137
RDKit::MolStandardize::IsotopeValidation::run
void run(const ROMol &mol, bool reportAllFailures, std::vector< ValidationErrorInfo > &errors) const override
RDKit::MolStandardize::MolVSValidation
The MolVSValidation class can be used to perform all MolVSValidions.
Definition Validate.h:145
RDKit::MolStandardize::MolVSValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::MolVSValidation::~MolVSValidation
~MolVSValidation() override
RDKit::MolStandardize::MolVSValidation::MolVSValidation
MolVSValidation(const std::vector< boost::shared_ptr< MolVSValidations > > validations)
overloaded constructor to take in a user-defined list of MolVSValidations
RDKit::MolStandardize::MolVSValidation::MolVSValidation
MolVSValidation(const MolVSValidation &other)
RDKit::MolStandardize::MolVSValidation::MolVSValidation
MolVSValidation()
RDKit::MolStandardize::MolVSValidations
MolVS Validations.
Definition Validate.h:82
RDKit::MolStandardize::MolVSValidations::copy
virtual boost::shared_ptr< MolVSValidations > copy() const =0
RDKit::MolStandardize::MolVSValidations::run
virtual void run(const ROMol &mol, bool reportAllFailures, std::vector< ValidationErrorInfo > &errors) const =0
RDKit::MolStandardize::NeutralValidation
The NeutralValidation class logs if not an overall neutral system.
Definition Validate.h:118
RDKit::MolStandardize::NeutralValidation::run
void run(const ROMol &mol, bool reportAllFailures, std::vector< ValidationErrorInfo > &errors) const override
RDKit::MolStandardize::NeutralValidation::copy
boost::shared_ptr< MolVSValidations > copy() const override
Definition Validate.h:124
RDKit::MolStandardize::NoAtomValidation
Definition Validate.h:92
RDKit::MolStandardize::NoAtomValidation::run
void run(const ROMol &mol, bool reportAllFailures, std::vector< ValidationErrorInfo > &errors) const override
RDKit::MolStandardize::NoAtomValidation::copy
boost::shared_ptr< MolVSValidations > copy() const override
Definition Validate.h:98
RDKit::MolStandardize::RDKitValidation
Definition Validate.h:69
RDKit::MolStandardize::RDKitValidation::validate
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
RDKit::MolStandardize::ValidationErrorInfo
Definition Validate.h:38
RDKit::MolStandardize::ValidationErrorInfo::~ValidationErrorInfo
~ValidationErrorInfo() noexcept override=default
RDKit::MolStandardize::ValidationErrorInfo::ValidationErrorInfo
ValidationErrorInfo(std::string msg)
Definition Validate.h:40
RDKit::MolStandardize::ValidationErrorInfo::what
const char * what() const noexcept override
Definition Validate.h:43
RDKit::MolStandardize::ValidationMethod
Definition Validate.h:52
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:199
export.h
RDKIT_MOLSTANDARDIZE_EXPORT
#define RDKIT_MOLSTANDARDIZE_EXPORT
Definition export.h:337
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
Std stuff.
Definition Abbreviations.h:19