From a7f6f2121d777061fd45b19af155fd59e30dc65c Mon Sep 17 00:00:00 2001
From: Pilar Cossio <pilar.cossio@biophys.mpg.de>
Date: Thu, 17 Dec 2015 14:48:14 +0100
Subject: [PATCH] check quat range

---
 param.cpp | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/param.cpp b/param.cpp
index 8ad74cc..7c564ca 100644
--- a/param.cpp
+++ b/param.cpp
@@ -564,6 +564,13 @@ int bioem_param::forprintBest(const char* fileinput)
           angles[0].pos[2] = atof(token);
           cout << "Best Q3 " <<  angles[0].pos[2] << "\n";
         }
+            else if (strcmp(token, "BEST_Q4") == 0)
+        {
+          token = strtok(NULL, " ");
+          angles[0].quat4= atof(token);
+          cout << "Best Q3 " <<  angles[0].quat4 << "\n";
+        }
+
       else if (strcmp(token, "USE_PSF") == 0)
         {
           usepsf=true;
@@ -668,7 +675,12 @@ int bioem_param::forprintBest(const char* fileinput)
 
     }
 
-  if(doquater)angles[0].quat4=sqrt(1.f-angles[0].pos[0]*angles[0].pos[0]-angles[0].pos[1]*angles[0].pos[1]-angles[0].pos[2]*angles[0].pos[2]);
+  if(doquater){
+            if(angles[0].quat4*angles[0].quat4>1){cout << " Problem with quaternion "<< angles[0].quat4 << "\n";exit(1);}
+	    if(angles[0].pos[0]*angles[0].pos[0]>1){cout << " Problem with quaternion "<< angles[0].pos[0] << "\n";exit(1);}
+	    if(angles[0].pos[1]*angles[0].pos[1]>1){cout << " Problem with quaternion "<< angles[0].pos[1] << "\n";exit(1);}
+	    if(angles[0].pos[2]*angles[0].pos[2]>1){cout << " Problem with quaternion "<< angles[0].pos[2] << "\n";exit(1);}
+	}
 
   input.close();
 
-- 
GitLab