From 5c668e4ec5b82bc4a545c4b1409619556b1f8f1f Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@stud.unibas.ch> Date: Fri, 7 Jun 2013 15:54:10 +0200 Subject: [PATCH] ost crashed, if not enough atoms fulfilled the distance threshold to build superposable subsets. At least three atoms are required. This scenario gets now checked and an error is thrown. --- modules/mol/alg/src/svd_superpose.cc | 7 +++++++ modules/mol/alg/tests/test_superposition.cc | 23 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/mol/alg/src/svd_superpose.cc b/modules/mol/alg/src/svd_superpose.cc index a1181ba29..fbc69cd1d 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 3196c5d9f..e3c88d647 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); } -- GitLab