Validate.h
Go to the documentation of this file.
//
// Copyright (C) 2018 Susan H. Leung
//
// @@ 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 <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(const std::string &msg) : d_msg(msg) {
BOOST_LOG(rdInfoLog) << d_msg << std::endl;
};
const char *message() const { return d_msg.c_str(); };
~ValidationErrorInfo() throw(){};
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:
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
virtual 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
virtual 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
virtual 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
virtual 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();
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(const std::vector<std::shared_ptr<Atom>> &atoms)
: d_allowedList(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(const std::vector<std::shared_ptr<Atom>> &atoms)
: d_disallowedList(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
BOOST_LOG
#define BOOST_LOG(__arg__)
Definition: RDLog.h:88
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::AllowedAtomsValidation::AllowedAtomsValidation
AllowedAtomsValidation(const std::vector< std::shared_ptr< Atom >> &atoms)
Definition: Validate.h:164
ROMol.h
Defines the primary molecule class ROMol as well as associated typedefs.
RDKit::MolStandardize::FragmentValidation::copy
virtual boost::shared_ptr< MolVSValidations > copy() const override
Definition: Validate.h:107
RDKit::MolStandardize::RDKitValidation
The RDKitValidation class throws an error when there are no atoms in the.
Definition: Validate.h:65
RDKit::MolStandardize::ValidationErrorInfo::~ValidationErrorInfo
~ValidationErrorInfo()
Definition: Validate.h:43
RDKit::MolStandardize::ValidationErrorInfo::message
const char * message() const
Definition: Validate.h:42
RDKit::MolStandardize::NoAtomValidation
The NoAtomValidation class throws an error if no atoms are present in the.
Definition: Validate.h:87
RDKit::MolStandardize::ValidationMethod
The ValidationMethod class is the abstract base class upon which all the.
Definition: Validate.h:51
Atom.h
Defines the Atom class and associated typedefs.
RDKit::MolStandardize::IsotopeValidation
The IsotopeValidation class logs if molecule contains isotopes.
Definition: Validate.h:126
RDKit::ROMol
Definition: ROMol.h:171
RDKit::MolStandardize::DisallowedAtomsValidation::DisallowedAtomsValidation
DisallowedAtomsValidation(const std::vector< std::shared_ptr< Atom >> &atoms)
Definition: Validate.h:179
RDKitBase.h
pulls in the core RDKit functionality
RDKit::MolStandardize::NoAtomValidation::copy
virtual boost::shared_ptr< MolVSValidations > copy() const override
Definition: Validate.h:94
RDKit::MolStandardize::AllowedAtomsValidation
Definition: Validate.h:161
RDKit::MolStandardize::ValidationErrorInfo::ValidationErrorInfo
ValidationErrorInfo(const std::string &msg)
Definition: Validate.h:39
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::MolStandardize::MolVSValidation
The MolVSValidation class can be used to perform all MolVSValidions.
Definition: Validate.h:141
rdInfoLog
RDKIT_RDGENERAL_EXPORT std::shared_ptr< boost::logging::rdLogger > rdInfoLog
RDKit::MolStandardize::NeutralValidation
The NeutralValidation class logs if not an overall neutral system.
Definition: Validate.h:113
RDKit::MolStandardize::MolVSValidations
The MolVSValidations class includes most of the same validations as.
Definition: Validate.h:78
RDKit::MolStandardize::ValidationErrorInfo
The ValidationErrorInfo class is used to store the information returned by a.
Definition: Validate.h:37
RDKit::MolStandardize::DisallowedAtomsValidation
Definition: Validate.h:176
RDKit::MolStandardize::IsotopeValidation::copy
virtual boost::shared_ptr< MolVSValidations > copy() const override
Definition: Validate.h:133
RDKit::MolStandardize::FragmentValidation
The FragmentValidation class logs if certain fragments are present.
Definition: Validate.h:100
RDKIT_MOLSTANDARDIZE_EXPORT
#define RDKIT_MOLSTANDARDIZE_EXPORT
Definition: export.h:437
RDKit::MolStandardize::NeutralValidation::copy
virtual boost::shared_ptr< MolVSValidations > copy() const override
Definition: Validate.h:120
export.h