From 894bc7ad7f9444e991111af588efa1e8766c6dd4 Mon Sep 17 00:00:00 2001
From: Niklaus Johner <niklaus.johner@unibas.ch>
Date: Tue, 6 Sep 2016 16:34:57 +0200
Subject: [PATCH] Added function to set the unit cell size of a frame in a
 CoordGroup

---
 modules/mol/base/pymod/export_coord_group.cc |  1 +
 modules/mol/base/src/coord_group.cc          | 10 ++++++++++
 modules/mol/base/src/coord_group.hh          |  3 +++
 modules/mol/base/src/coord_source.cc         |  6 ++++++
 modules/mol/base/src/coord_source.hh         |  1 +
 5 files changed, 21 insertions(+)

diff --git a/modules/mol/base/pymod/export_coord_group.cc b/modules/mol/base/pymod/export_coord_group.cc
index 790337cb1..46a435ad4 100644
--- a/modules/mol/base/pymod/export_coord_group.cc
+++ b/modules/mol/base/pymod/export_coord_group.cc
@@ -58,6 +58,7 @@ void export_CoordGroup()
     .add_property("frame_count",&CoordGroupHandle::GetFrameCount)
     .def("GetFramePositions",&CoordGroupHandle::GetFramePositions)
     .def("SetFramePositions",&CoordGroupHandle::SetFramePositions)
+    .def("SetFrameCellSize",&CoordGroupHandle::SetFrameCellSize)
     .def("SetAtomPos",&CoordGroupHandle::SetAtomPos)
     .def("GetAtomPos",&CoordGroupHandle::GetAtomPos)
     .def("CopyFrame",&CoordGroupHandle::CopyFrame)
diff --git a/modules/mol/base/src/coord_group.cc b/modules/mol/base/src/coord_group.cc
index 49c9f4512..53f31d9ae 100644
--- a/modules/mol/base/src/coord_group.cc
+++ b/modules/mol/base/src/coord_group.cc
@@ -91,6 +91,16 @@ void CoordGroupHandle::SetStartTime(float t)
   source_->SetStartTime(t);
 }
 
+void CoordGroupHandle::SetFrameCellSize(uint frame, const geom::Vec3& size)
+{
+  this->CheckValidity();  
+  if (source_->IsMutable()) {
+    source_->SetFrameCellSize(frame, size);
+  } else {
+    throw IntegrityError("Can't add set frame cell size in immutable CoordGroup");
+  }
+}
+
 void CoordGroupHandle::SetFramePositions(uint frame, 
                                          const geom::Vec3List& clist)
 {
diff --git a/modules/mol/base/src/coord_group.hh b/modules/mol/base/src/coord_group.hh
index d72cf12e7..edce072cb 100644
--- a/modules/mol/base/src/coord_group.hh
+++ b/modules/mol/base/src/coord_group.hh
@@ -71,6 +71,9 @@ public:
   ///      initial atomlist
   void SetFramePositions(uint frame, const geom::Vec3List& clist);
 
+  /// \brief set cell size for the given frame
+  void SetFrameCellSize(uint frame, const geom::Vec3& size);
+
   /// \brief get the positions of all the atoms in the given frame
   geom::Vec3List GetFramePositions(uint frame);  
   
diff --git a/modules/mol/base/src/coord_source.cc b/modules/mol/base/src/coord_source.cc
index 8d07abb40..f3c0e13c9 100644
--- a/modules/mol/base/src/coord_source.cc
+++ b/modules/mol/base/src/coord_source.cc
@@ -82,6 +82,12 @@ void CoordSource::Capture()
   this->AddFrame(coords);
 }
 
+void CoordSource::SetFrameCellSize(uint frame, const geom::Vec3& size)
+{
+  CoordFrame& fp=*(GetFrame(frame));
+  fp.SetCellSize(size);
+}
+
 void CoordSource::SetFramePositions(uint frame, const std::vector<geom::Vec3>& clist)
 {
   CoordFrame& fp=*(GetFrame(frame));
diff --git a/modules/mol/base/src/coord_source.hh b/modules/mol/base/src/coord_source.hh
index 7c3ce96a2..b58e3e98c 100644
--- a/modules/mol/base/src/coord_source.hh
+++ b/modules/mol/base/src/coord_source.hh
@@ -81,6 +81,7 @@ public:
   void CaptureInto(int pos);
   void Capture(uint f);
   void SetFramePositions(uint frame, const std::vector<geom::Vec3>& clist);
+  void SetFrameCellSize(uint frame, const geom::Vec3& size);
 
   virtual void AddFrame(const std::vector<geom::Vec3>& coords) = 0;
   virtual void AddFrame(const std::vector<geom::Vec3>& coords,const geom::Vec3& cell_size,const geom::Vec3& cell_angles) = 0;
-- 
GitLab