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

added CoordGroupHandle.Filter(sel)

The method filters a trajectory by only keeping the positions of atoms
present in "sel".
parent 7101ae69
Branches
Tags
No related merge requests found
...@@ -58,6 +58,7 @@ void export_CoordGroup() ...@@ -58,6 +58,7 @@ void export_CoordGroup()
.def("GetAtomList",&CoordGroupHandle::GetAtomList) .def("GetAtomList",&CoordGroupHandle::GetAtomList)
.def("__getitem__",cg_getitem) .def("__getitem__",cg_getitem)
.def("__setitem__",cg_setitem) .def("__setitem__",cg_setitem)
.def("Filter", &CoordGroupHandle::Filter)
; ;
def("CreateCoordGroup",CreateCoordGroup); def("CreateCoordGroup",CreateCoordGroup);
......
...@@ -18,10 +18,10 @@ ...@@ -18,10 +18,10 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#include <ost/invalid_handle.hh> #include <ost/invalid_handle.hh>
#include <ost/integrity_error.hh> #include <ost/integrity_error.hh>
#include <ost/log.hh>
#include <ost/mol/in_mem_coord_source.hh> #include <ost/mol/in_mem_coord_source.hh>
#include <ost/mol/entity_handle.hh> #include <ost/mol/view_op.hh>
#include <ost/mol/mol.hh>
#include "coord_group.hh" #include "coord_group.hh"
namespace ost { namespace mol { namespace ost { namespace mol {
...@@ -154,4 +154,39 @@ void CoordGroupHandle::Capture(uint frame) ...@@ -154,4 +154,39 @@ void CoordGroupHandle::Capture(uint frame)
} }
} }
CoordGroupHandle CoordGroupHandle::Filter(const EntityView& selected) const
{
this->CheckValidity();
std::vector<unsigned long> indices;
EntityHandle new_ent;
if (!selected.IsValid()) {
indices.reserve(this->GetAtomCount());
for (size_t i=0;i<this->GetAtomCount(); ++i) {
indices.push_back(i);
}
new_ent=this->GetEntity().Copy();
} else {
AtomViewList atoms=selected.GetAtomList();
indices.reserve(atoms.size());
for (AtomViewList::const_iterator i=atoms.begin(),
e=atoms.end(); i!=e; ++i) {
indices.push_back(i->GetIndex());
}
new_ent=CreateEntityFromView(selected, false);
}
CoordGroupHandle filtered_cg=CreateCoordGroup(new_ent.GetAtomList());
std::vector<geom::Vec3> vecs(indices.size());
for (size_t i=0; i<this->GetFrameCount(); ++i) {
LOG_INFO("Filtering frame " << i << "/" << this->GetFrameCount());
CoordFramePtr frame=this->GetFrame(i);
for (std::vector<unsigned long>::const_iterator
j=indices.begin(), e2=indices.end(); j!=e2; ++j) {
vecs[j-indices.begin()]=(*frame)[*j];
}
filtered_cg.AddFrame(vecs);
}
return filtered_cg;
}
}} // ns }} // ns
...@@ -82,6 +82,10 @@ public: ...@@ -82,6 +82,10 @@ public:
AtomHandleList GetAtomList() const; AtomHandleList GetAtomList() const;
CoordFramePtr GetFrame(uint frame) const; CoordFramePtr GetFrame(uint frame) const;
/// \brief return a filtered coord group, containing only the atoms in the
/// view
CoordGroupHandle Filter(const EntityView& selected) const;
CoordGroupHandle(CoordSourcePtr source); CoordGroupHandle(CoordSourcePtr source);
private: private:
void CheckValidity() const; void CheckValidity() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment