mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-04 21:54:27 +08:00
* short test file for MolVS standardize_sm * short test file for MolVS fragment * short test file for MolVS metals * short test file for MolVS normalize * short test file for MolVS reionize * short test file for MolVS tautomer * short test file for MolVS validate * long test file for MolVS standardize smiles * long test file for MolVS fragment * long test file for MolVS metals * long test file for MolVS normalize * long test file for MolVS reionize * long test file for MolVS tautomer * long test file for MolVS validate * Unit tests for MolVS steps * dropping support for Python2 * molvs/__init__.py * molvs/charge.py * molvs/errors.py * molvs/fragment.py * molvs/metal.py * molvs/normalize.py * molvs/resonance.py * molvs/standardize.py * molvs/tautomer.py * molvs/utils.py * molvs/validate.py * molvs/validations.py * molvs/cli.py * adapted and renamed molvs/cli.py to work within $RDBASE/Contrib/MolVS/ * setup MolStandardize directories, source with empty cleanup function, header, CMake files * corrections to empty source, header and test1.cpp * adding empty functions and initializers to MolStandardize * empty Metal source, header and added test * added most of Metal.cpp functionality and made some more tests * empty functions and initializers to Normalize * empty functions and initializers to Validate * added most code for RDKitDefault mode, along with some tests * restructure for abstract base class ValidateMethod * written in isNoneValidation for MolVSValidation * took out isNoneValidation, put in noAtomValidation, neutralValidation, isotopeValidation for MolVSValidation * added in AllowedAtoms * added in disallowedAtoms * corrections to Validate * added code for FragmentRemover * extended fragment functionality to include choose largest fragment, added in tests for fragment catalog, fragment remover. Also added fragmentValidation method in MolStandardize * added another test to testValidate test_fragment * corrections to fragment * corrections to Metal * added code for Normalize * added normalize member function to MolStandardize and added tests * added multi fragment functionality to Normalize.cpp and additional tests * TransformCatalog * tests for Normalize.cpp * first bit of cleanup * added most of Charge functionality and some tests * some corrections to Charge.cpp and some more tests to testCharge.cpp * corrections to Charge.cpp * start of Tautomer Enumerate with some tests * added BondType option to Tautomer Enumeration * correcting for some memory leakage * a few alterations to formatting * sorting out some memory leaks * sorting out some memory leaks * some corrections for PCS test set * redo tests with updated RDKit * fixing memory leak * more fixes after 100kPCS set testing * using tab as delimiter in CSVs rather than comma * tutorial for MolStandardize * still working on Tautomer enumeration * deleted some empty tests * starting writing tautomer canonicalize * rename test_data -> data (the source still needs to be updated) * automatic source reformatting * adjust to directory rename * move the fragment catalog test into the MolStandardize directory do not create separate library for FragmentCatalog * stop building separate libraries for the catalogs * move the CleanupParameters into the MolStandardize namespace * first pass at python wrapper * move the py module to the correct dir; add some python tests; add standardizeSmiles to python wrapper * disabling the compareMolVSTest since that requires command line arguments to run * get this building on windows * put the python lib in the right place * further work on python wrapper for rdMolStandardize * added get and set functions to Metal and wrapped them * added get and set functions to Metal and wrapped them * changed construstor of Reionizer class and input args for reionize, wrapped this default * overload Reionizer constructor so user can input own AcidBaseFile from python * added Uncharger class to Charge and added test for Uncharger * wrapped Fragment, fixed some memory leakage, changed some args and return types, added some tests * wrapped Normalized and changed how Normalizer class is initiated * changing MolVSValidation structure so user can choose which MolVS submethod they want * starting to write Wrap for Validate * now it compiles with Wrap/Validate.cpp * a couple refactorings around validate * move the validate code into the rdMolStandardize module * make sure a valid pointer is returned for standardizeSmiles * rdMolStandardize.MolVSValidation done and tests added * half way through AllowedAtomsValidation * finished AllowedAtomsValidation and DisallowedAtomsValidation * moved charge, fragment, metal, normalize into the rdMolStandardize module * changed tutorial to use wrapped code * added copyrights * added copyrights * move the data files * modify source files to adjust to the move * added validateSmiles functionality * removed std::cout * redid some of the 100k PCS tests * working on the tutorial * adding some documentation * deleting some comment lines * some changes after pull review * More changes after pull review * start of trying to make java wrap * remove some warnings, add some questions * additional warning removals, a bit more reporting * some test cleanups * enable testing of the java code
199 lines
6.4 KiB
C++
199 lines
6.4 KiB
C++
//
|
|
// 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 used to test memory leakage
|
|
|
|
#include "MolStandardize.h"
|
|
#include "Validate.h"
|
|
#include "Metal.h"
|
|
#include "Normalize.h"
|
|
#include "Charge.h"
|
|
#include <GraphMol/RDKitBase.h>
|
|
#include <RDGeneral/Invariant.h>
|
|
#include <GraphMol/SmilesParse/SmilesParse.h>
|
|
#include <GraphMol/SmilesParse/SmilesWrite.h>
|
|
#include <GraphMol/ROMol.h>
|
|
|
|
#include <iostream>
|
|
|
|
using namespace RDKit;
|
|
using namespace MolStandardize;
|
|
|
|
void test1() {
|
|
BOOST_LOG(rdInfoLog) << "-----------------------\n test1" << std::endl;
|
|
|
|
MolStandardize::CleanupParameters params;
|
|
|
|
std::string smi1 = "C1=CC=CC=C1";
|
|
// std::shared_ptr<RWMol> m1( SmilesToMol(smi1) );
|
|
std::unique_ptr<RWMol> m1(SmilesToMol(smi1));
|
|
std::unique_ptr<RWMol> res(cleanup(*m1, params));
|
|
TEST_ASSERT(MolToSmiles(*res) == "c1ccccc1");
|
|
|
|
// std::string smi1 = "CCC(=O)O[Na]";
|
|
//// std::shared_ptr<RWMol> m1( SmilesToMol(smi1) );
|
|
// RWMol *m1 = SmilesToMol(smi1);
|
|
// cleanup(*m1, params);
|
|
// TEST_ASSERT(MolToSmiles(*m1) == "CCC(=O)[O-].[Na+]");
|
|
BOOST_LOG(rdInfoLog) << "Finished" << std::endl;
|
|
}
|
|
|
|
void testMetal() {
|
|
BOOST_LOG(rdInfoLog) << "-----------------------\n test metal" << std::endl;
|
|
MetalDisconnector md;
|
|
|
|
std::string smi1 = "CCC(=O)O[Na]";
|
|
std::unique_ptr<RWMol> m1(SmilesToMol(smi1));
|
|
TEST_ASSERT(m1);
|
|
md.disconnect(*m1);
|
|
TEST_ASSERT(MolToSmiles(*m1) == "CCC(=O)[O-].[Na+]");
|
|
BOOST_LOG(rdInfoLog) << "Finished" << std::endl;
|
|
}
|
|
|
|
void testValidate() {
|
|
BOOST_LOG(rdInfoLog) << "-----------------------\n test validate"
|
|
<< std::endl;
|
|
RDKitValidation vm;
|
|
|
|
// testing RDKitDefault
|
|
std::string smi1 = "CO(C)C";
|
|
std::unique_ptr<ROMol> m1(SmilesToMol(smi1, 0, false));
|
|
std::vector<ValidationErrorInfo> errout1 = vm.validate(*m1, true);
|
|
for (auto &query : errout1) {
|
|
std::string msg = query.message();
|
|
TEST_ASSERT(msg ==
|
|
"INFO: [ValenceValidation] Explicit valence for atom # 1 O, 3, "
|
|
"is greater than permitted");
|
|
}
|
|
//**************************
|
|
MolVSValidation vm2;
|
|
std::string smi2 = "O=C([O-])c1ccccc1";
|
|
std::unique_ptr<ROMol> m2(SmilesToMol(smi2, 0, false));
|
|
std::vector<ValidationErrorInfo> errout2 = vm2.validate(*m2, true);
|
|
for (auto &query : errout2) {
|
|
std::string msg = query.message();
|
|
TEST_ASSERT(msg ==
|
|
"INFO: [NeutralValidation] Not an overall neutral system (-1)");
|
|
}
|
|
// ************************
|
|
std::vector<unsigned int> atoms = {6, 7, 8};
|
|
std::vector<std::shared_ptr<Atom>> atomList;
|
|
|
|
for (auto &atom : atoms) {
|
|
std::shared_ptr<Atom> a(new Atom(atom));
|
|
atomList.push_back(a);
|
|
}
|
|
|
|
AllowedAtomsValidation vm3(atomList);
|
|
|
|
std::string smi3 = "CC(=O)CF";
|
|
std::unique_ptr<ROMol> m3(SmilesToMol(smi3));
|
|
std::vector<ValidationErrorInfo> errout3 = vm3.validate(*m3, true);
|
|
for (auto &query : errout3) {
|
|
std::string msg = query.message();
|
|
TEST_ASSERT(
|
|
msg ==
|
|
"INFO: [AllowedAtomsValidation] Atom F is not in allowedAtoms list");
|
|
}
|
|
//********************************
|
|
std::vector<unsigned int> atoms2 = {9, 17, 35};
|
|
std::vector<std::shared_ptr<Atom>> atomList2;
|
|
|
|
for (auto &atom : atoms2) {
|
|
std::shared_ptr<Atom> a(new Atom(atom));
|
|
atomList2.push_back(a);
|
|
}
|
|
|
|
DisallowedAtomsValidation vm4(atomList2);
|
|
|
|
std::string smi4 = "CC(=O)CF";
|
|
std::unique_ptr<ROMol> m4(SmilesToMol(smi4));
|
|
std::vector<ValidationErrorInfo> errout4 = vm4.validate(*m4, true);
|
|
for (auto &query : errout4) {
|
|
std::string msg = query.message();
|
|
TEST_ASSERT(
|
|
msg ==
|
|
"INFO: [DisallowedAtomsValidation] Atom F is in disallowedAtoms list");
|
|
}
|
|
//********************************
|
|
MolVSValidation vm5;
|
|
|
|
// testing MolVSValidation fragmentValidation
|
|
// FragmentValidation should identify 1,2-dichloroethane.
|
|
std::string smi5 = "ClCCCl.c1ccccc1O";
|
|
std::unique_ptr<ROMol> m5(SmilesToMol(smi5, 0, false));
|
|
std::vector<ValidationErrorInfo> errout5 = vm5.validate(*m5, true);
|
|
for (auto &query : errout5) {
|
|
std::string msg = query.message();
|
|
TEST_ASSERT(msg ==
|
|
"INFO: [FragmentValidation] 1,2-dichloroethane is present");
|
|
}
|
|
BOOST_LOG(rdInfoLog) << "Finished" << std::endl;
|
|
}
|
|
|
|
void testCharge() {
|
|
BOOST_LOG(rdInfoLog) << "-----------------------\n test charge" << std::endl;
|
|
|
|
Reionizer reionizer;
|
|
|
|
// Test table salt.
|
|
std::string smi1 = "[Na].[Cl]";
|
|
std::shared_ptr<ROMol> m1(SmilesToMol(smi1));
|
|
ROMOL_SPTR reionized(reionizer.reionize(*m1));
|
|
TEST_ASSERT(MolToSmiles(*reionized) == "[Cl-].[Na+]");
|
|
//*******************************
|
|
MolStandardize::CleanupParameters params;
|
|
// initialize CleanupParameters with preferOrganic=true
|
|
MolStandardize::CleanupParameters params_preferorg;
|
|
params_preferorg.preferOrganic = true;
|
|
|
|
// Test neutralization of ionized acids and bases.
|
|
std::string smi2 = "C(C(=O)[O-])(Cc1n[n-]nn1)(C[NH3+])(C[N+](=O)[O-])";
|
|
std::unique_ptr<RWMol> m2(SmilesToMol(smi2));
|
|
std::unique_ptr<RWMol> res2(MolStandardize::chargeParent(*m2, params));
|
|
TEST_ASSERT(MolToSmiles(*res2) == "NCC(Cc1nn[nH]n1)(C[N+](=O)[O-])C(=O)O");
|
|
//**********************************
|
|
// Testing MolStandardize::reionize
|
|
|
|
std::string smi3 = "C1=C(C=CC(=C1)[S]([O-])=O)[S](O)(=O)=O";
|
|
std::unique_ptr<RWMol> m3(SmilesToMol(smi3));
|
|
std::unique_ptr<RWMol> res3(MolStandardize::reionize(m3.get(), params));
|
|
TEST_ASSERT(MolToSmiles(*res3) == "O=S(O)c1ccc(S(=O)(=O)[O-])cc1");
|
|
BOOST_LOG(rdInfoLog) << "Finished" << std::endl;
|
|
}
|
|
|
|
void testNormalize() {
|
|
BOOST_LOG(rdInfoLog) << "-----------------------\n test normalize"
|
|
<< std::endl;
|
|
|
|
Normalizer normalizer;
|
|
|
|
// Test sulfoxide normalization.
|
|
std::string smi1 = "CS(C)=O";
|
|
std::shared_ptr<ROMol> m1(SmilesToMol(smi1));
|
|
ROMOL_SPTR normalized(normalizer.normalize(*m1));
|
|
TEST_ASSERT(MolToSmiles(*normalized) == "C[S+](C)[O-]");
|
|
|
|
// normalize sulfone.
|
|
std::string smi2 = "C[S+2]([O-])([O-])C";
|
|
std::shared_ptr<ROMol> m2(SmilesToMol(smi2));
|
|
ROMOL_SPTR normalized2(normalizer.normalize(*m2));
|
|
TEST_ASSERT(MolToSmiles(*normalized2) == "CS(C)(=O)=O");
|
|
BOOST_LOG(rdInfoLog) << "Finished" << std::endl;
|
|
}
|
|
|
|
int main() {
|
|
test1(); // cleanup test
|
|
testMetal();
|
|
testValidate();
|
|
testCharge(); // TODO
|
|
testNormalize();
|
|
return 0;
|
|
}
|