From 0c7d1e732c28843e78d361c1317469f8af931281 Mon Sep 17 00:00:00 2001
From: Niklaus Johner <nij2003@med.cornell.edu>
Date: Mon, 7 May 2012 18:38:49 -0400
Subject: [PATCH] In function read_frame, corrected periodic cell size and
 angles read when reading a dcd

Angles for cells with axis not along xyz should be handled carefully
as they might be wrong (couldn't find documentation for dcd format).
---
 modules/io/src/mol/dcd_io.cc | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/modules/io/src/mol/dcd_io.cc b/modules/io/src/mol/dcd_io.cc
index e5422bda6..15a290279 100644
--- a/modules/io/src/mol/dcd_io.cc
+++ b/modules/io/src/mol/dcd_io.cc
@@ -152,9 +152,23 @@ bool read_frame(std::istream& istream, const DCDHeader& header,
   //if(skip_flag) istream.seekg(14*4,std::ios_base::cur);
   if(skip_flag){
     istream.read(dummy,sizeof(dummy));
-    istream.read(reinterpret_cast<char*>(&cell_size[0]),sizeof(float)*3);
-    istream.read(reinterpret_cast<char*>(&cell_angles[0]),sizeof(float)*3);
+    double x,y,z,a,b,c;
+    istream.read(reinterpret_cast<char*>(&x),sizeof(double));
+    istream.read(reinterpret_cast<char*>(&a),sizeof(double));
+    istream.read(reinterpret_cast<char*>(&y),sizeof(double));
+    istream.read(reinterpret_cast<char*>(&b),sizeof(double));
+    istream.read(reinterpret_cast<char*>(&c),sizeof(double));
+    istream.read(reinterpret_cast<char*>(&z),sizeof(double));
     istream.read(dummy,sizeof(dummy));
+    cell_size[0]=x;
+    cell_size[1]=y;
+    cell_size[2]=z;
+    cell_angles[0]=acos(a);
+    cell_angles[1]=acos(b);
+    cell_angles[2]=acos(c);
+    if(a!=0.0||b!=0.0||c!=0.0){
+       LOG_ERROR("LoadCHARMMTraj: periodic cell not parallelepipedic, cell angles might be wrong, handle carefully")
+    }
   }
 
   // read each frame
-- 
GitLab