From ab760b8d93b49693bb6c1d382fdf98cb6ba5a8e7 Mon Sep 17 00:00:00 2001 From: Alan Kerstjens <44154074+AlanKerstjens@users.noreply.github.com> Date: Sun, 8 May 2022 09:27:58 +0200 Subject: [PATCH] Allow the compiler to generate default ChemicalReaction copy assignment operator (#5265) Co-authored-by: Alan Kerstjens --- Code/GraphMol/ChemReactions/Reaction.h | 1 - Code/GraphMol/ChemReactions/testReaction.cpp | 51 ++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Code/GraphMol/ChemReactions/Reaction.h b/Code/GraphMol/ChemReactions/Reaction.h index 6e90c828ea..ebd230b537 100644 --- a/Code/GraphMol/ChemReactions/Reaction.h +++ b/Code/GraphMol/ChemReactions/Reaction.h @@ -357,7 +357,6 @@ class RDKIT_CHEMREACTIONS_EXPORT ChemicalReaction : public RDProps { bool df_needsInit{true}; bool df_implicitProperties{false}; MOL_SPTR_VECT m_reactantTemplates, m_productTemplates, m_agentTemplates; - ChemicalReaction &operator=(const ChemicalReaction &); // disable assignment }; //! tests whether or not the molecule has a substructure match diff --git a/Code/GraphMol/ChemReactions/testReaction.cpp b/Code/GraphMol/ChemReactions/testReaction.cpp index 0ee5e45b29..cfb356a20d 100644 --- a/Code/GraphMol/ChemReactions/testReaction.cpp +++ b/Code/GraphMol/ChemReactions/testReaction.cpp @@ -7712,6 +7712,56 @@ void testMultiTemplateRxnQueries() { delete rxn; } +void testChemicalReactionCopyAssignment() { + BOOST_LOG(rdInfoLog) << "-------------------------------------" << std::endl; + BOOST_LOG(rdInfoLog) << "Testing ChemicalReaction copy assignment operator" + << std::endl; + + std::string rxn_smarts1 = + "[C;$(C=O):1][OH1].[N;$(N[#6]);!$(N=*);!$([N-]);!$(N#*);!$([ND3]);!$([ND4]);!$(N[O,N]);!$(N[C,S]=[S,O,N]):2]>>[C:1][N+0:2]"; + RDKit::ChemicalReaction* rxn1 = RDKit::RxnSmartsToChemicalReaction(rxn_smarts1); + rxn1->setImplicitPropertiesFlag(true); + rxn1->initReactantMatchers(); + unsigned int nWarn, nError; + TEST_ASSERT(rxn1->validate(nWarn, nError, false)); + TEST_ASSERT(nWarn == 0 && nError == 0); + + std::string rxn_smarts2 = "[O:1]>>[N:1]"; + RDKit::ChemicalReaction* rxn2 = RDKit::RxnSmartsToChemicalReaction(rxn_smarts2); + + *rxn2 = *rxn1; + + TEST_ASSERT(rxn2->getImplicitPropertiesFlag()); + TEST_ASSERT(rxn2->isInitialized()); + + RDKit::MOL_SPTR_VECT::const_iterator it1 = rxn1->beginReactantTemplates(); + RDKit::MOL_SPTR_VECT::const_iterator it2 = rxn2->beginReactantTemplates(); + RDKit::MOL_SPTR_VECT::const_iterator end_it1 = rxn1->endReactantTemplates(); + while (it1 != end_it1) { + TEST_ASSERT(RDKit::MolToSmiles(**it1) == RDKit::MolToSmiles(**it2)); + ++it1; + ++it2; + } + + it1 = rxn1->beginProductTemplates(); + it2 = rxn2->beginProductTemplates(); + end_it1 = rxn1->endProductTemplates(); + while (it1 != end_it1) { + TEST_ASSERT(RDKit::MolToSmiles(**it1) == RDKit::MolToSmiles(**it2)); + ++it1; + ++it2; + } + + RDKit::MOL_SPTR_VECT reactants; + reactants.emplace_back(RDKit::SmilesToMol("CC(=O)O")); + reactants.emplace_back(RDKit::SmilesToMol("CCN")); + std::vector products = rxn1->runReactants(reactants); + TEST_ASSERT(RDKit::MolToSmiles(*products[0][0]) == "CCNC(C)=O"); + + delete rxn1; + delete rxn2; +} + int main() { RDLog::InitLogs(); @@ -7810,6 +7860,7 @@ int main() { testGithub4183(); testGithub4410(); testMultiTemplateRxnQueries(); + testChemicalReactionCopyAssignment(); BOOST_LOG(rdInfoLog) << "*******************************************************\n";