Skip to content

Commit

Permalink
Allow the compiler to generate default ChemicalReaction copy assignme…
Browse files Browse the repository at this point in the history
…nt operator (#5265)

Co-authored-by: Alan Kerstjens <alan.kerstjens@uantwerpen.be>
  • Loading branch information
AlanKerstjens and Alan Kerstjens committed May 8, 2022
1 parent a354f2d commit ab760b8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
1 change: 0 additions & 1 deletion Code/GraphMol/ChemReactions/Reaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions Code/GraphMol/ChemReactions/testReaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<RDKit::MOL_SPTR_VECT> products = rxn1->runReactants(reactants);
TEST_ASSERT(RDKit::MolToSmiles(*products[0][0]) == "CCNC(C)=O");

delete rxn1;
delete rxn2;
}

int main() {
RDLog::InitLogs();

Expand Down Expand Up @@ -7810,6 +7860,7 @@ int main() {
testGithub4183();
testGithub4410();
testMultiTemplateRxnQueries();
testChemicalReactionCopyAssignment();

BOOST_LOG(rdInfoLog)
<< "*******************************************************\n";
Expand Down

0 comments on commit ab760b8

Please sign in to comment.