RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
Validate.h
Go to the documentation of this file.
1//
2// Copyright (C) 2018-2021 Susan H. Leung and other RDKit contributors
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/*! \file Validate.h
11
12 \brief Defines the ValidationErrorInfo class and four different
13 validation methods: RDKitValidation, MolVSValidation, AllowedAtomsValidation,
14 DisallowedAtomsValidation.
15
16*/
17#include <RDGeneral/export.h>
18#ifndef RD_VALIDATE_H
19#define RD_VALIDATE_H
20
21#include <GraphMol/RDKitBase.h>
22#include <GraphMol/ROMol.h>
23#include <GraphMol/Atom.h>
24#include <iostream>
25#include <exception>
26#include <string>
27#include <utility>
28#include <vector>
29
30namespace RDKit {
31class RWMol;
32class ROMol;
33
34namespace MolStandardize {
35
36//! The ValidationErrorInfo class is used to store the information returned by a
37/// ValidationMethod validate.
38using ValidationErrorInfo = std::string;
39
40//! The ValidationMethod class is the abstract base class upon which all the
41/// four different ValidationMethods inherit from.
43 public:
44 ValidationMethod() = default;
45 virtual ~ValidationMethod() = default;
46
47 virtual std::vector<ValidationErrorInfo> validate(
48 const ROMol &mol, bool reportAllFailures) const = 0;
49 virtual std::shared_ptr<ValidationMethod> copy() const = 0;
50};
51
52//! The CompositeValidation class provides a simple way to apply a collection of
53// ValidationMethod instances in sequence
55 public:
57 const std::vector<std::shared_ptr<ValidationMethod>> & validations)
58 : validations(validations) {};
59
60 std::vector<ValidationErrorInfo> validate(
61 const ROMol &mol, bool reportAllFailures) const override;
62
63 std::shared_ptr<ValidationMethod> copy() const override {
64 return std::make_shared<CompositeValidation>(*this);
65 }
66
67 private:
68 std::vector<std::shared_ptr<ValidationMethod>> validations;
69};
70
71//! The RDKitValidation class throws an error when there are no atoms in the
72/// molecule or when there is incorrect atom valency.
73/*!
74
75 <b>Notes:</b>
76 - RDKit automatically throws up atom valency issues but this class was made
77 for completeness of the project.
78*/
80 public:
81 std::vector<ValidationErrorInfo> validate(
82 const ROMol &mol, bool reportAllFailures) const override;
83
84 std::shared_ptr<ValidationMethod> copy() const override {
85 return std::make_shared<RDKitValidation>(*this);
86 }
87};
88
89//////////////////////////////
90/// MolVS Validations
91//
92
93//! The NoAtomValidation class throws an error if no atoms are present in the
94/// molecule.
96 public:
97 std::vector<ValidationErrorInfo> validate(
98 const ROMol &mol, bool reportAllFailures) const override;
99
100 std::shared_ptr<ValidationMethod> copy() const override {
101 return std::make_shared<NoAtomValidation>(*this);
102 }
103};
104
105//! The FragmentValidation class logs if certain fragments are present.
107 public:
108 std::vector<ValidationErrorInfo> validate(
109 const ROMol &mol, bool reportAllFailures) const override;
110
111 std::shared_ptr<ValidationMethod> copy() const override {
112 return std::make_shared<FragmentValidation>(*this);
113 }
114};
115
116//! The NeutralValidation class logs if not an overall neutral system.
118 public:
119 std::vector<ValidationErrorInfo> validate(
120 const ROMol &mol, bool reportAllFailures) const override;
121
122 std::shared_ptr<ValidationMethod> copy() const override {
123 return std::make_shared<NeutralValidation>(*this);
124 }
125};
126
127//! The IsotopeValidation class logs if molecule contains isotopes.
129 public:
130 std::vector<ValidationErrorInfo> validate(
131 const ROMol &mol, bool reportAllFailures) const override;
132
133 std::shared_ptr<ValidationMethod> copy() const override {
134 return std::make_shared<IsotopeValidation>(*this);
135 }
136};
137
138////////////////////////////////
139//! The MolVSValidation class includes most of the same validations as
140/// molvs.validations, namely NoAtomValidation, FragmentValidation,
141/// NeutralValidation, IsotopeValidation. MolVS also has IsNoneValidation and
142/// DichloroethaneValidation but these were not included here (yet).
144 public:
145 // constructor
147 //! overloaded constructor to take in a user-defined list of ValidationMethod
149 const std::vector<std::shared_ptr<ValidationMethod>> & validations);
150
151 std::shared_ptr<ValidationMethod> copy() const override {
152 return std::make_shared<MolVSValidation>(*this);
153 }
154};
155
156//! The AllowedAtomsValidation class lets the user input a list of atoms,
157//! anything not on
158/// the list throws an error.
160 : public ValidationMethod {
161 public:
162 AllowedAtomsValidation(std::vector<std::shared_ptr<Atom>> atoms)
163 : d_allowedList(std::move(atoms)) {}
164 std::vector<ValidationErrorInfo> validate(
165 const ROMol &mol, bool reportAllFailures) const override;
166
167 std::shared_ptr<ValidationMethod> copy() const override {
168 return std::make_shared<AllowedAtomsValidation>(*this);
169 }
170
171 private:
172 std::vector<std::shared_ptr<Atom>> d_allowedList;
173};
174
175//! The DisallowedAtomsValidation class lets the user input a list of atoms and
176//! as long
177/// as there are no atoms from the list it is deemed acceptable.
179 : public ValidationMethod {
180 public:
181 DisallowedAtomsValidation(std::vector<std::shared_ptr<Atom>> atoms)
182 : d_disallowedList(std::move(atoms)) {}
183 std::vector<ValidationErrorInfo> validate(
184 const ROMol &mol, bool reportAllFailures) const override;
185
186 std::shared_ptr<ValidationMethod> copy() const override {
187 return std::make_shared<DisallowedAtomsValidation>(*this);
188 }
189
190 private:
191 std::vector<std::shared_ptr<Atom>> d_disallowedList;
192};
193
194//! A convenience function for quickly validating a single SMILES string.
195RDKIT_MOLSTANDARDIZE_EXPORT std::vector<ValidationErrorInfo> validateSmiles(
196 const std::string &smiles);
197
198} // namespace MolStandardize
199} // namespace RDKit
200
201#endif
Defines the Atom class and associated typedefs.
pulls in the core RDKit functionality
Defines the primary molecule class ROMol as well as associated typedefs.
AllowedAtomsValidation(std::vector< std::shared_ptr< Atom > > atoms)
Definition Validate.h:162
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:167
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
The CompositeValidation class provides a simple way to apply a collection of.
Definition Validate.h:54
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:63
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
CompositeValidation(const std::vector< std::shared_ptr< ValidationMethod > > &validations)
Definition Validate.h:56
DisallowedAtomsValidation(std::vector< std::shared_ptr< Atom > > atoms)
Definition Validate.h:181
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:186
The FragmentValidation class logs if certain fragments are present.
Definition Validate.h:106
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:111
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
The IsotopeValidation class logs if molecule contains isotopes.
Definition Validate.h:128
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:133
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
MolVSValidation(const std::vector< std::shared_ptr< ValidationMethod > > &validations)
overloaded constructor to take in a user-defined list of ValidationMethod
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:151
The NeutralValidation class logs if not an overall neutral system.
Definition Validate.h:117
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:122
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:100
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const override
std::shared_ptr< ValidationMethod > copy() const override
Definition Validate.h:84
virtual std::shared_ptr< ValidationMethod > copy() const =0
virtual std::vector< ValidationErrorInfo > validate(const ROMol &mol, bool reportAllFailures) const =0
#define RDKIT_MOLSTANDARDIZE_EXPORT
Definition export.h:337
RDKIT_MOLSTANDARDIZE_EXPORT std::vector< ValidationErrorInfo > validateSmiles(const std::string &smiles)
A convenience function for quickly validating a single SMILES string.
std::string ValidationErrorInfo
Definition Validate.h:38
Std stuff.