Skip to content
Snippets Groups Projects
Commit bfc47bd7 authored by Marco Biasini's avatar Marco Biasini
Browse files

added MergeCoordGroup function

parent e8c8e382
No related branches found
No related tags found
No related merge requests found
...@@ -18,4 +18,18 @@ ...@@ -18,4 +18,18 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
from _mol import * from _mol import *
import ost.geom as _geom import ost.geom as _geom
from ost.mol import alg from ost.mol import alg
\ No newline at end of file
def MergeCoordGroups(*coord_groups):
"""
Merge several separate coord groups into one. The coord groups must have the
same number of atoms. In case no coord group is supplied, None will be
returned.
"""
if len(coord_groups)==0:
return None
cg=CreateCoordGroup(coord_groups[0].atoms)
for coord_group in coord_groups:
cg.AddFrames(coord_group)
return cg
\ No newline at end of file
...@@ -46,11 +46,13 @@ void export_CoordGroup() ...@@ -46,11 +46,13 @@ void export_CoordGroup()
.def("IsValid",&CoordGroupHandle::IsValid) .def("IsValid",&CoordGroupHandle::IsValid)
.def("GetEntity",&CoordGroupHandle::GetEntity) .def("GetEntity",&CoordGroupHandle::GetEntity)
.def("GetAtomCount",&CoordGroupHandle::GetAtomCount) .def("GetAtomCount",&CoordGroupHandle::GetAtomCount)
.def("AddFrames", &CoordGroupHandle::AddFrames)
.def("GetFrameCount",&CoordGroupHandle::GetFrameCount) .def("GetFrameCount",&CoordGroupHandle::GetFrameCount)
.def("SetFramePositions",&CoordGroupHandle::SetFramePositions) .def("SetFramePositions",&CoordGroupHandle::SetFramePositions)
.def("SetAtomPos",&CoordGroupHandle::SetAtomPos) .def("SetAtomPos",&CoordGroupHandle::SetAtomPos)
.def("GetAtomPos",&CoordGroupHandle::GetAtomPos) .def("GetAtomPos",&CoordGroupHandle::GetAtomPos)
.def("CopyFrame",&CoordGroupHandle::CopyFrame) .def("CopyFrame",&CoordGroupHandle::CopyFrame)
.add_property("atoms", &CoordGroupHandle::GetAtomList)
.def("IsValid", &CoordGroupHandle::IsValid) .def("IsValid", &CoordGroupHandle::IsValid)
.def("Capture", capture1) .def("Capture", capture1)
.def("Capture", capture2) .def("Capture", capture2)
......
...@@ -93,6 +93,21 @@ void CoordGroupHandle::AddFrame(const std::vector<geom::Vec3>& clist) ...@@ -93,6 +93,21 @@ void CoordGroupHandle::AddFrame(const std::vector<geom::Vec3>& clist)
} }
} }
void CoordGroupHandle::AddFrames(const CoordGroupHandle& cg)
{
this->CheckValidity();
if (source_->IsMutable()) {
if (cg.GetAtomCount()!=this->GetAtomCount()) {
throw IntegrityError("Atom number don't match");
}
for (size_t i=0; i<cg.GetFrameCount(); ++i) {
source_->AddFrame(*cg.GetFrame(i));
}
} else {
throw IntegrityError("Can't add frame to immutable CoordGroup");
}
}
void CoordGroupHandle::CheckValidity() const void CoordGroupHandle::CheckValidity() const
{ {
if (!source_) { if (!source_) {
......
...@@ -67,6 +67,7 @@ public: ...@@ -67,6 +67,7 @@ public:
/// \brief add frame /// \brief add frame
void AddFrame(const std::vector<geom::Vec3>& clist); void AddFrame(const std::vector<geom::Vec3>& clist);
void AddFrames(const CoordGroupHandle& cg);
/// \brief set an indidivial atom position in the given frame /// \brief set an indidivial atom position in the given frame
void SetAtomPos(uint frame, AtomHandle atom, const geom::Vec3& pos); void SetAtomPos(uint frame, AtomHandle atom, const geom::Vec3& pos);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment