diff --git a/modules/mol/alg/src/svd_superpose.cc b/modules/mol/alg/src/svd_superpose.cc index a1181ba2913c1fcfc1ce8ba30469fd75940c5a58..fbc69cd1df4bf5a0c0b65709311bad34318cf735 100644 --- a/modules/mol/alg/src/svd_superpose.cc +++ b/modules/mol/alg/src/svd_superpose.cc @@ -289,6 +289,13 @@ SuperpositionResult MeanSquareMinimizerImpl::IterativeMinimize(int max_cycles, R transformed_atoms = this->TransformEMatX(atoms1_, transformation_matrix); matching_indices = this->CreateMatchingSubsets(transformed_atoms, atoms2_, distance_threshold); + if(matching_indices.size()<3){ + std::stringstream ss; + ss<<"Failed to Converge, less than 3 superposable atoms in iteration "; + ss<<cycles<<"!"; + throw Error(ss.str()); + } + subset1 = EMatX::Zero(matching_indices.size(),3); subset2 = EMatX::Zero(matching_indices.size(),3); diff --git a/modules/mol/alg/tests/test_superposition.cc b/modules/mol/alg/tests/test_superposition.cc index 3196c5d9fe39ed30c3f2ff7012ad799bea9eb88d..e3c88d647141532e5b782e50011971a0aca73b62 100644 --- a/modules/mol/alg/tests/test_superposition.cc +++ b/modules/mol/alg/tests/test_superposition.cc @@ -25,7 +25,8 @@ #include <boost/test/unit_test.hpp> #include <boost/test/auto_unit_test.hpp> #include <ost/mol/mol.hh> - #include <ost/mol/builder.hh> +#include <ost/mol/builder.hh> +#include <ost/message.hh> using namespace ost; using namespace ost::mol; @@ -96,6 +97,26 @@ BOOST_AUTO_TEST_CASE(iterative_superposition_svd) BOOST_CHECK(res_1.fraction_superposed==1.0); BOOST_CHECK(res_2.fraction_superposed==7.0/8.0); BOOST_CHECK(res_3.ncycles==3); + + EntityHandle eh_2_atoms = Builder() + .Chain("A") + .Residue("D") + .Atom("A",geom::Vec3(0,0,0)) + .Atom("B",geom::Vec3(0,0,0)); + + //Error, that has to be thrown during initialization of superposition object + BOOST_CHECK_THROW(IterativeSuperposeSVD(eh_2_atoms.CreateFullView(), + eh_2_atoms.CreateFullView(), + 1,5.0,false), Error); + + //forces an error, since there won't be enough atoms within the distance + //threshold after the first superposition. + ed.SetAtomPos(atoms[0],geom::Vec3(50,50,50)); + ed.SetAtomPos(atoms[1],geom::Vec3(50,50,50)); + ed.SetAtomPos(atoms[2],geom::Vec3(50,50,50)); + ed.SetAtomPos(atoms[3],geom::Vec3(50,50,50)); + + BOOST_CHECK_THROW(IterativeSuperposeSVD(ev1, ev2, 5, 5.0, false), Error); }