diff --git a/modules/mol/base/src/CMakeLists.txt b/modules/mol/base/src/CMakeLists.txt index 8bb7187ebe9d229fe4aad338a71e53674e22ae3f..8d206d3c61b193deb48942e563baadb31c4c5aa4 100644 --- a/modules/mol/base/src/CMakeLists.txt +++ b/modules/mol/base/src/CMakeLists.txt @@ -83,6 +83,7 @@ sec_structure.hh spatial_organizer.hh surface.hh surface_builder.hh +builder.hh surface_handle.hh surface_prop.hh torsion_handle.hh diff --git a/modules/mol/base/src/builder.hh b/modules/mol/base/src/builder.hh new file mode 100644 index 0000000000000000000000000000000000000000..0a652a8b010ac97182a50e79591c00f6c3c6b81d --- /dev/null +++ b/modules/mol/base/src/builder.hh @@ -0,0 +1,77 @@ + +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2011 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +#ifndef OST_MOL_BASE_BUILDER_HH +#define OST_MOL_BASE_BUILDER_HH + +#include "module_config.hh" + +#include "atom_handle.hh" +#include "residue_handle.hh" +#include "chain_handle.hh" +#include "entity_handle.hh" +#include "xcs_editor.hh" + + +namespace ost { namespace mol { + +// a helper class to easily create entities +class DLLEXPORT Builder { +public: + Builder(): ent_(CreateEntity()), edi_(ent_.EditXCS(BUFFERED_EDIT)) { + } + + // conversion to entity handle + operator EntityHandle() { return ent_; } + + Builder& Chain(const String& name) { + chain_ = edi_.InsertChain(name); + res_ = ResidueHandle(); + atom_ = AtomHandle(); + return *this; + } + + Builder& Residue(const String& name) { + res_ = edi_.AppendResidue(chain_, name); + atom_ = AtomHandle(); + return *this; + } + + Builder& OneLetterCode(char olc) { + res_.SetOneLetterCode(olc); + return *this; + } + + Builder& Atom(const String& name, const geom::Vec3& pos=geom::Vec3()) { + edi_.InsertAtom(res_, name, pos); + return *this; + } +private: + EntityHandle ent_; + ChainHandle chain_; + ResidueHandle res_; + AtomHandle atom_; + XCSEditor edi_; + + +}; + +}} +#endif + diff --git a/modules/mol/base/tests/CMakeLists.txt b/modules/mol/base/tests/CMakeLists.txt index 5085b0b10b257fab18361001a1cb7a55b796769d..176f6ad2421f1d381eaf4800c4f2ec3ad2419325 100644 --- a/modules/mol/base/tests/CMakeLists.txt +++ b/modules/mol/base/tests/CMakeLists.txt @@ -3,6 +3,7 @@ set(OST_MOL_BASE_UNIT_TESTS test_chain.cc test_conn.cc test_coord_group.cc + test_builder.cc test_delete.cc test_entity.cc test_ics.cc diff --git a/modules/mol/base/tests/test_builder.cc b/modules/mol/base/tests/test_builder.cc new file mode 100644 index 0000000000000000000000000000000000000000..f9128bca409ca2df578c9829eb1acb2fea99615a --- /dev/null +++ b/modules/mol/base/tests/test_builder.cc @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2011 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +/* + * Authors: Marco Biasini, Juergen Haas + */ +#include <ost/mol/builder.hh> + +#define BOOST_TEST_DYN_LINK +#include <boost/test/unit_test.hpp> +#include <boost/test/auto_unit_test.hpp> + +using namespace ost; +using namespace ost::mol; + +BOOST_AUTO_TEST_SUITE( mol_base_builder ); + +BOOST_AUTO_TEST_CASE(inserts_chains) +{ + EntityHandle ent = Builder() + .Chain("A") + .Chain("B"); + + BOOST_CHECK_EQUAL(2, ent.GetChainCount()); + BOOST_CHECK(ent.FindChain("A").IsValid()); + BOOST_CHECK(ent.FindChain("B").IsValid()); +} + + +BOOST_AUTO_TEST_CASE(appends_residues) { + EntityHandle ent = Builder() + .Chain("A") + .Residue("GLY") + .Residue("GLN"); + + BOOST_CHECK_EQUAL(1, ent.GetChainCount()); + BOOST_CHECK_EQUAL(ent.GetResidueCount(), 2); + BOOST_CHECK(ent.FindResidue("A", 1).IsValid()); + BOOST_CHECK(ent.FindResidue("A", 2).IsValid()); +} + +BOOST_AUTO_TEST_CASE(inserts_atoms) { + EntityHandle ent = Builder() + .Chain("A") + .Residue("GLY") + .Atom("N") + .Atom("CA") + .Atom("C") + .Atom("O") + ; + + BOOST_CHECK_EQUAL(ent.GetAtomCount(), 4); + BOOST_CHECK(ent.FindAtom("A", 1, "N").IsValid()); + BOOST_CHECK(ent.FindAtom("A", 1, "CA").IsValid()); + BOOST_CHECK(ent.FindAtom("A", 1, "C").IsValid()); + BOOST_CHECK(ent.FindAtom("A", 1, "O").IsValid()); +} + +BOOST_AUTO_TEST_SUITE_END();