From c1c194cea5b763ef21d3a8f54fd4568861284af1 Mon Sep 17 00:00:00 2001 From: Niklaus Johner <niklaus.johner@unibas.ch> Date: Mon, 29 Aug 2016 14:29:02 +0200 Subject: [PATCH] Implemented SetFramPositions function --- modules/mol/base/src/coord_group.cc | 14 +++++++++++--- modules/mol/base/src/coord_group.hh | 2 +- modules/mol/base/src/coord_source.cc | 13 +++++++++++++ modules/mol/base/src/coord_source.hh | 3 ++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/modules/mol/base/src/coord_group.cc b/modules/mol/base/src/coord_group.cc index 3ab9ec3db..49c9f4512 100644 --- a/modules/mol/base/src/coord_group.cc +++ b/modules/mol/base/src/coord_group.cc @@ -92,10 +92,14 @@ void CoordGroupHandle::SetStartTime(float t) } void CoordGroupHandle::SetFramePositions(uint frame, - const std::vector<geom::Vec3>& clist) + const geom::Vec3List& clist) { this->CheckValidity(); - //source_->SetFramePositions(frame, clist); + if (source_->IsMutable()) { + source_->SetFramePositions(frame, clist); + } else { + throw IntegrityError("Can't add set frame positions in immutable CoordGroup"); + } } @@ -164,7 +168,11 @@ void CoordGroupHandle::CheckValidity() const void CoordGroupHandle::SetAtomPos(uint frame, AtomHandle atom, const geom::Vec3& pos) { this->CheckValidity(); - source_->SetAtomPos(frame,atom,pos); + if (source_->IsMutable()) { + source_->SetAtomPos(frame,atom,pos); + } else { + throw IntegrityError("Can't set atom position in immutable CoordGroup"); + } } geom::Vec3 CoordGroupHandle::GetAtomPos(uint frame, AtomHandle atom) const diff --git a/modules/mol/base/src/coord_group.hh b/modules/mol/base/src/coord_group.hh index 754330d6c..d72cf12e7 100644 --- a/modules/mol/base/src/coord_group.hh +++ b/modules/mol/base/src/coord_group.hh @@ -69,7 +69,7 @@ public: /// \brief assign positions to the given frame - order and count must match /// initial atomlist - void SetFramePositions(uint frame, const std::vector<geom::Vec3>& clist); + void SetFramePositions(uint frame, const geom::Vec3List& clist); /// \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 fa58ce041..8d07abb40 100644 --- a/modules/mol/base/src/coord_source.cc +++ b/modules/mol/base/src/coord_source.cc @@ -82,6 +82,19 @@ void CoordSource::Capture() this->AddFrame(coords); } +void CoordSource::SetFramePositions(uint frame, const std::vector<geom::Vec3>& clist) +{ + CoordFrame& fp=*(GetFrame(frame)); + if(fp.size()!=clist.size()) { + throw Error("atom count and length of position vector are not equal"); + return; + } + unsigned int count=0; + for (std::vector<geom::Vec3>::const_iterator i=clist.begin(); i!=clist.end(); ++i) { + fp[count++]=*i; + } +} + void CoordSource::CaptureInto(int pos) { std::vector<geom::Vec3> coords; diff --git a/modules/mol/base/src/coord_source.hh b/modules/mol/base/src/coord_source.hh index 3f83e5a3e..7c3ce96a2 100644 --- a/modules/mol/base/src/coord_source.hh +++ b/modules/mol/base/src/coord_source.hh @@ -80,7 +80,8 @@ public: void Capture(); void CaptureInto(int pos); void Capture(uint f); - + void SetFramePositions(uint frame, const std::vector<geom::Vec3>& clist); + 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; virtual void InsertFrame(int pos, const std::vector<geom::Vec3>& coords) = 0; -- GitLab