diff --git a/modules/conop/doc/compoundlib.rst b/modules/conop/doc/compoundlib.rst index caca8445b454408a8b103e96129e847e71045d55..41f859e7a8787499553fad1b1639e0827379c60c 100644 --- a/modules/conop/doc/compoundlib.rst +++ b/modules/conop/doc/compoundlib.rst @@ -45,7 +45,7 @@ build the compound library manually. write mode, the programs can deadlock. :type readonly: :class:`bool` - :returns: The loaded compound lib + :returns: The loaded compound lib or None if it failed. .. staticmethod:: Create(database) diff --git a/modules/conop/src/rule_based.cc b/modules/conop/src/rule_based.cc index 6e8b712fe63fdff02fec5836fd39316583dacc35..fe2013e254b80f5b4ff5b52474ff672873adb72c 100644 --- a/modules/conop/src/rule_based.cc +++ b/modules/conop/src/rule_based.cc @@ -19,6 +19,7 @@ #include <limits> #include <ost/log.hh> #include <ost/profile.hh> +#include <ost/message.hh> #include <ost/mol/xcs_editor.hh> #include <ost/mol/bond_handle.hh> #include <ost/mol/torsion_handle.hh> @@ -30,8 +31,6 @@ namespace ost { namespace conop { - - void RuleBasedProcessor::DoProcess(DiagnosticsPtr diags, mol::EntityHandle ent) const { @@ -199,6 +198,11 @@ String RuleBasedProcessor::ToString() const { return ss.str(); } - +void RuleBasedProcessor::_CheckLib() const { + if (!lib_) { + throw Error("Cannot initialize RuleBasedProcessor without a valid " + "CompoundLib object!"); + } +} }} diff --git a/modules/conop/src/rule_based.hh b/modules/conop/src/rule_based.hh index 3b91771a29c027f9cbd503c3927f3a13b58add34..719ba78030003cae44dfa881d8339757b3008102 100644 --- a/modules/conop/src/rule_based.hh +++ b/modules/conop/src/rule_based.hh @@ -40,13 +40,19 @@ public: lib_(compound_lib), fix_element_(true), strict_hydrogens_(false), unk_res_treatment_(CONOP_WARN), unk_atom_treatment_(CONOP_WARN) { + _CheckLib(); } - RuleBasedProcessor(CompoundLibPtr compound_lib, bool fe, bool sh, ConopAction ur, - ConopAction ua, bool bf, bool at, bool cn, bool aa, ConopAction zo): + RuleBasedProcessor(CompoundLibPtr compound_lib, bool fe, bool sh, + ConopAction ur, ConopAction ua, bool bf, bool at, bool cn, + bool aa, ConopAction zo): Processor(bf, at, cn, aa, zo), lib_(compound_lib), fix_element_(fe), strict_hydrogens_(sh), unk_res_treatment_(ur), - unk_atom_treatment_(ua) {} + unk_atom_treatment_(ua) + { + _CheckLib(); + } + ConopAction GetUnkResidueTreatment() const { return unk_res_treatment_; } @@ -91,6 +97,8 @@ protected: virtual void DoProcess(DiagnosticsPtr diags, mol::EntityHandle ent) const; private: + void _CheckLib() const; + CompoundLibPtr lib_; bool fix_element_; bool strict_hydrogens_; diff --git a/modules/conop/tests/test_rule_based_conop.cc b/modules/conop/tests/test_rule_based_conop.cc index 6444695d9f85cece9e06c9b4c6153ec8645963ba..1ce4ebe2436ff5f3d148a6272d3cb7b73cefb481 100644 --- a/modules/conop/tests/test_rule_based_conop.cc +++ b/modules/conop/tests/test_rule_based_conop.cc @@ -50,9 +50,24 @@ CompoundLibPtr load_lib() BOOST_AUTO_TEST_SUITE(conop); +BOOST_AUTO_TEST_CASE(rule_based_init_check) +{ + CompoundLibPtr lib; // null ptr is return value when library loading failed + BOOST_CHECK_THROW(RuleBasedProcessor rbc1(lib), ost::Error); + BOOST_CHECK_THROW(RuleBasedProcessor rbc2(lib, true, false, CONOP_WARN, + CONOP_WARN, false, true, true, true, + CONOP_WARN), ost::Error); + lib = load_lib(); + if (!lib) { return; } + BOOST_CHECK_NO_THROW(RuleBasedProcessor rbc3(lib)); + BOOST_CHECK_NO_THROW(RuleBasedProcessor rbc4(lib, true, false, CONOP_WARN, + CONOP_WARN, false, true, true, + true, CONOP_WARN)); +} + BOOST_AUTO_TEST_CASE(rule_based_set_get_flags) { - CompoundLibPtr lib=load_lib(); + CompoundLibPtr lib = load_lib(); if (!lib) { return; } RuleBasedProcessor rbc(lib); // check the defaults @@ -76,7 +91,7 @@ BOOST_AUTO_TEST_CASE(rule_based_set_get_flags) BOOST_AUTO_TEST_CASE(rule_based_connect) { - CompoundLibPtr lib=load_lib(); + CompoundLibPtr lib = load_lib(); if (!lib) { return; } RuleBasedProcessor rbc(lib); EntityHandle ent = CreateEntity(); @@ -94,7 +109,7 @@ BOOST_AUTO_TEST_CASE(rule_based_connect) BOOST_AUTO_TEST_CASE(rule_based_unk_atoms) { - CompoundLibPtr lib = load_lib(); + CompoundLibPtr lib = load_lib(); if (!lib) { return; } RuleBasedProcessor rbc(lib); EntityHandle ent = CreateEntity(); @@ -125,7 +140,7 @@ BOOST_AUTO_TEST_CASE(rule_based_unk_atoms) BOOST_AUTO_TEST_CASE(guesses_elements_of_unknown_atoms) { - CompoundLibPtr lib = load_lib(); + CompoundLibPtr lib = load_lib(); if (!lib) { return; } RuleBasedProcessor rbc(lib); EntityHandle ent = CreateEntity(); @@ -142,7 +157,7 @@ BOOST_AUTO_TEST_CASE(guesses_elements_of_unknown_atoms) BOOST_AUTO_TEST_CASE(fills_properties_of_unknown_residues) { - CompoundLibPtr lib = load_lib(); + CompoundLibPtr lib = load_lib(); if (!lib) { return; } RuleBasedProcessor rbc(lib); EntityHandle ent = CreateEntity(); @@ -160,7 +175,7 @@ BOOST_AUTO_TEST_CASE(fills_properties_of_unknown_residues) BOOST_AUTO_TEST_CASE(connects_atoms_of_unknown_residues_based_on_distance) { - CompoundLibPtr lib = load_lib(); + CompoundLibPtr lib = load_lib(); if (!lib) { return; } RuleBasedProcessor rbc(lib); EntityHandle ent = CreateEntity(); @@ -177,7 +192,7 @@ BOOST_AUTO_TEST_CASE(connects_atoms_of_unknown_residues_based_on_distance) BOOST_AUTO_TEST_CASE(rule_based_unk_res) { - CompoundLibPtr lib = load_lib(); + CompoundLibPtr lib = load_lib(); if (!lib) { return; } RuleBasedProcessor rbc(lib); EntityHandle ent = CreateEntity();