Skip to content
Snippets Groups Projects
Commit 2f14bd97 authored by Studer Gabriel's avatar Studer Gabriel
Browse files

Editor functionality to delete residues/chains that don't contain any atoms

parent c7dfb42e
Branches
Tags
No related merge requests found
......@@ -360,6 +360,10 @@ The basic functionality of editors is implemented in the EditorBase class.
:type atom2: :class:`AtomHandle`
:param bond_order: bond order (e.g. 1=single, 2=double, 3=triple)
:type bond_order: :class:`int`
.. method:: Prune()
Removes residues and chains that don't contain any atoms.
Editor for the External Coordinate System
......
......@@ -267,6 +267,7 @@ void export_Editors()
.def("RenumberAllResidues",&EditorBase::RenumberAllResidues)
.def("RenumberChain",renumber_chain_a)
.def("RenumberChain",renumber_chain_b)
.def("Prune", &EditorBase::Prune)
;
void (XCSEditor::*apply_transform1)(const geom::Mat4&) = &XCSEditor::ApplyTransform;
......
......@@ -298,6 +298,22 @@ TorsionHandle EditorBase::AddTorsion(const String& name, const AtomHandle& a1,
a3.Impl(), a4.Impl()));
}
void EditorBase::Prune() {
ost::mol::ResidueHandleList res_list = ent_.GetResidueList();
for(ost::mol::ResidueHandleList::iterator it = res_list.begin();
it != res_list.end(); ++it) {
if(it->GetAtomCount() == 0) {
this->DeleteResidue(*it);
}
}
ost::mol::ChainHandleList chain_list = ent_.GetChainList();
for(ost::mol::ChainHandleList::iterator it = chain_list.begin();
it != chain_list.end(); ++it) {
if(it->GetResidueCount() == 0) {
this->DeleteChain(*it);
}
}
}
void EditorBase::UpdateTrace()
{
......
......@@ -328,6 +328,11 @@ public:
/// \brief change the name of the atom to the new name
void RenameAtom(AtomHandle atom, const String& new_name);
/// \brief Removes all residues and chains in the attached entity that don't
/// contain any atoms
void Prune();
protected:
EditorBase(const EntityHandle& ent, EditMode mode);
void UpdateTrace();
......
......@@ -441,4 +441,57 @@ BOOST_AUTO_TEST_CASE(minmax)
BOOST_CHECK_EQUAL(minmax.second, 7.0);
}
BOOST_AUTO_TEST_CASE(prune) {
EntityHandle ent=mol::CreateEntity();
XCSEditor edi = ent.EditXCS();
ChainHandle ch1 = edi.InsertChain("A");
ChainHandle ch2 = edi.InsertChain("B");
ResidueHandle res1_1 = edi.AppendResidue(ch1, "DUMMY");
ResidueHandle res1_2 = edi.AppendResidue(ch1, "DUMMY");
AtomHandle atom1_1_1 = edi.InsertAtom(res1_1, "X", geom::Vec3(1,2,3), "C");
AtomHandle atom1_2_1 = edi.InsertAtom(res1_2, "X", geom::Vec3(1,2,3), "C");
ResidueHandle res2_1 = edi.AppendResidue(ch2, "DUMMY");
ResidueHandle res2_2 = edi.AppendResidue(ch2, "DUMMY");
AtomHandle atom2_1_1 = edi.InsertAtom(res2_1, "X", geom::Vec3(1,2,3), "C");
AtomHandle atom2_2_1 = edi.InsertAtom(res2_2, "X", geom::Vec3(1,2,3), "C");
BOOST_CHECK_EQUAL(ent.GetChainCount(), 2);
BOOST_CHECK_EQUAL(ent.GetResidueCount(), 4);
BOOST_CHECK_EQUAL(ent.GetAtomCount(), 4);
// shouldn't do anything
edi.Prune();
BOOST_CHECK_EQUAL(ent.GetChainCount(), 2);
BOOST_CHECK_EQUAL(ent.GetResidueCount(), 4);
BOOST_CHECK_EQUAL(ent.GetAtomCount(), 4);
// remove one atom, the subsequent prune call should then remove the
// according residue but the number of chains should remain the same
edi.DeleteAtom(atom1_1_1);
edi.Prune();
BOOST_CHECK_EQUAL(ent.GetChainCount(), 2);
BOOST_CHECK_EQUAL(ent.GetResidueCount(), 3);
BOOST_CHECK_EQUAL(ent.GetAtomCount(), 3);
// remove the second atom from the first chain, the whole chain should then
// be removed by Prune
edi.DeleteAtom(atom1_2_1);
edi.Prune();
BOOST_CHECK_EQUAL(ent.GetChainCount(), 1);
BOOST_CHECK_EQUAL(ent.GetResidueCount(), 2);
BOOST_CHECK_EQUAL(ent.GetAtomCount(), 2);
// remove both residues from the second chain. The entity should be empty
// afterwards
edi.DeleteResidue(res2_1);
edi.DeleteResidue(res2_2);
edi.Prune();
BOOST_CHECK_EQUAL(ent.GetChainCount(), 0);
BOOST_CHECK_EQUAL(ent.GetResidueCount(), 0);
BOOST_CHECK_EQUAL(ent.GetAtomCount(), 0);
}
BOOST_AUTO_TEST_SUITE_END();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment