From 38ae521317f0afe299385ceb5ce2e9d5c29e85db Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Tue, 10 Jul 2018 17:25:59 +0200
Subject: [PATCH] Check for number of atoms in CalculateRMSD

This function assumes the user knows what he's doing, this is also clearly
stated in the documentation:
"RMSD of atom positions (taken blindly in the order in
which the atoms appear) in the two given views."
This check at least avoids a segfault when the number of atoms does not
match. The result would be completely wrong anyway...
---
 modules/mol/alg/src/svd_superpose.cc | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/modules/mol/alg/src/svd_superpose.cc b/modules/mol/alg/src/svd_superpose.cc
index 59adf6141..b8f775939 100644
--- a/modules/mol/alg/src/svd_superpose.cc
+++ b/modules/mol/alg/src/svd_superpose.cc
@@ -113,6 +113,13 @@ Real CalculateRMSD(const mol::EntityView& ev1,
                    const mol::EntityView& ev2,
                    const geom::Mat4& transformation) {
 
+  if(ev1.GetAtomCount() != ev2.GetAtomCount()) {
+    std::stringstream ss;
+    ss << "Number of atoms in input views must be consistent! ";
+    ss << ev1.GetAtomCount() << " vs. " << ev2.GetAtomCount();
+    throw Error(ss.str());
+  }
+
   return calc_rmsd_for_atom_lists(ev1.GetAtomList(), ev2.GetAtomList(), 
                                   transformation);
 }
-- 
GitLab