From 929cc09bc6d67a69cb7bf9865d237ae81722f866 Mon Sep 17 00:00:00 2001 From: Stefan Bienert <stefan.bienert@unibas.ch> Date: Thu, 28 Jul 2011 14:14:07 +0200 Subject: [PATCH] Added new member/ attribute 'chain_type' to chain --- modules/mol/base/doc/editors.rst | 6 +++++ modules/mol/base/doc/entity.rst | 17 +++++++++++-- modules/mol/base/pymod/export_chain.cc | 16 +++++++++++- modules/mol/base/pymod/export_editors.cc | 1 + modules/mol/base/src/CMakeLists.txt | 1 + modules/mol/base/src/chain_base.cc | 4 +++ modules/mol/base/src/chain_base.hh | 6 +++++ modules/mol/base/src/chain_type.hh | 31 ++++++++++++++++++++++++ modules/mol/base/src/editor_base.cc | 5 ++++ modules/mol/base/src/editor_base.hh | 7 ++++++ modules/mol/base/src/impl/chain_impl.cc | 3 ++- modules/mol/base/src/impl/chain_impl.hh | 20 ++++++++++++++- modules/mol/base/tests/test_chain.cc | 17 +++++++++++++ 13 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 modules/mol/base/src/chain_type.hh diff --git a/modules/mol/base/doc/editors.rst b/modules/mol/base/doc/editors.rst index 574f6b18c..be0a1d3ca 100644 --- a/modules/mol/base/doc/editors.rst +++ b/modules/mol/base/doc/editors.rst @@ -90,6 +90,12 @@ The basic functionality of editors is implemented in the EditorBase class. :param new_name: is the new name :type new_name: string + .. method:: SetChainType(chain, type) + + :param chain: Must be a valid chain + :param type: Must be a value of enum ChainType + (see :attr:`ChainHandle.chain_type`) + .. method:: InsertAtom(residue, atom_name, pos, element="", occupancy=1.0, b_factor=0.0, is_hetatm=False) diff --git a/modules/mol/base/doc/entity.rst b/modules/mol/base/doc/entity.rst index 1ee9e6bda..cf00a6b5e 100644 --- a/modules/mol/base/doc/entity.rst +++ b/modules/mol/base/doc/entity.rst @@ -285,6 +285,16 @@ The Handle Classes :type: str + .. attribute:: chain_type + + Describes the type of the chain. Is one of enum ChainType: + + ``CHAINTYPE_POLY``, ``CHAINTYPE_AA``, ``CHAINTYPE_NT``, + ``CHAINTYPE_UNKNOWN``, ``CHAINTYPE_N_CHAINTYPES`` + + Where ``CHAINTYPE_N_CHAINTYPES`` holds the number of different types + available. + .. attribute:: residues List of all residues of this chain. The residues are sorted from N- to @@ -389,11 +399,14 @@ The Handle Classes .. method:: GetAtomList() See :attr:`atoms` - + .. method:: GetName() See :attr:`name` + .. method:: GetChainType() + + See :attr:`chain_type` .. class:: ResidueHandle @@ -1521,4 +1534,4 @@ Other Entity-Related Functions :raises: :class:`IntegrityError` if atoms of different entities are encountered - :returns: :class:`EntityView` \ No newline at end of file + :returns: :class:`EntityView` diff --git a/modules/mol/base/pymod/export_chain.cc b/modules/mol/base/pymod/export_chain.cc index 8a4cb3552..3361c5fa3 100644 --- a/modules/mol/base/pymod/export_chain.cc +++ b/modules/mol/base/pymod/export_chain.cc @@ -21,6 +21,7 @@ using namespace boost::python; #include <ost/mol/mol.hh> +#include <ost/mol/chain_type.hh> #include <ost/geom/export_helper/vector.hh> using namespace ost; using namespace ost::mol; @@ -50,6 +51,7 @@ void export_Chain() .def(self_ns::str(self)) .add_property("valid", &ChainBase::IsValid) .def("IsValid", &ChainBase::IsValid) + .def("GetChainType", &ChainBase::GetChainType) ; generic_prop_def<ChainBase>(chain_base); class_<ChainHandle, bases<ChainBase> >("ChainHandle", init<>()) @@ -78,7 +80,8 @@ void export_Chain() .def("GetAtomCount", &ChainHandle::GetAtomCount) .def("GetBondCount", &ChainHandle::GetBondCount) .add_property("residue_count", &ChainHandle::GetResidueCount) - .add_property("atom_count", &ChainHandle::GetAtomCount) + .add_property("atom_count", &ChainHandle::GetAtomCount) + .add_property("chain_type", &ChainHandle::GetChainType) .def("InSequence", &ChainHandle::InSequence) .def("Select", select_string, arg("flags")=0) .def("Select", select_query, arg("flags")=0) @@ -103,4 +106,15 @@ void export_Chain() .def(vector_indexing_suite<ChainHandleList>()) .def(geom::VectorAdditions<ChainHandleList>()) ; + + { + enum_<ChainType>("ChainType") + .value("CHAINTYPE_POLY", CHAINTYPE_POLY) + .value("CHAINTYPE_AA", CHAINTYPE_AA) + .value("CHAINTYPE_NT", CHAINTYPE_NT) + .value("CHAINTYPE_UNKNOWN", CHAINTYPE_UNKNOWN) + .value("CHAINTYPE_N_CHAINTYPES", CHAINTYPE_N_CHAINTYPES) + .export_values() + ; + } } diff --git a/modules/mol/base/pymod/export_editors.cc b/modules/mol/base/pymod/export_editors.cc index 34d3a7fe8..61ea42ceb 100644 --- a/modules/mol/base/pymod/export_editors.cc +++ b/modules/mol/base/pymod/export_editors.cc @@ -212,6 +212,7 @@ void export_Editors() .def("Connect", connect_c) .def("Connect", connect_d) .def("RenameChain", &EditorBase::RenameChain) + .def("SetChainType", &EditorBase::SetChainType) .def("RenameResidue", &EditorBase::RenameResidue) .def("RenameAtom", &EditorBase::RenameAtom) .def("AddTorsion", &EditorBase::AddTorsion) diff --git a/modules/mol/base/src/CMakeLists.txt b/modules/mol/base/src/CMakeLists.txt index b11b6e54c..22bda6d35 100644 --- a/modules/mol/base/src/CMakeLists.txt +++ b/modules/mol/base/src/CMakeLists.txt @@ -47,6 +47,7 @@ bond_table.hh chain_base.hh chain_handle.hh chain_view.hh +chain_type.hh chem_class.hh coord_group.hh coord_source.hh diff --git a/modules/mol/base/src/chain_base.cc b/modules/mol/base/src/chain_base.cc index a82f8c05b..4147ed532 100644 --- a/modules/mol/base/src/chain_base.cc +++ b/modules/mol/base/src/chain_base.cc @@ -44,6 +44,10 @@ String ChainBase::GetName() const { return impl_->GetName(); } +ChainType ChainBase::GetChainType() const { + return impl_->GetChainType(); +} + void ChainBase::CheckValidity() const { if (!impl_) throw InvalidHandle(); diff --git a/modules/mol/base/src/chain_base.hh b/modules/mol/base/src/chain_base.hh index 4a904a2a8..ca9e45724 100644 --- a/modules/mol/base/src/chain_base.hh +++ b/modules/mol/base/src/chain_base.hh @@ -22,6 +22,7 @@ #include <ost/mol/module_config.hh> #include <ost/mol/impl/chain_impl_fw.hh> +#include <ost/mol/chain_type.hh> #include <ost/generic_property.hh> namespace ost { namespace mol { @@ -59,6 +60,11 @@ public: friend class ConstGenericPropContainer<ChainBase>; String GetName() const; + /// \brief Get the type of a chain. + /// + /// \return chain type of ChainType + ChainType GetChainType() const; + const impl::ChainImplPtr& Impl() const { return impl_; } diff --git a/modules/mol/base/src/chain_type.hh b/modules/mol/base/src/chain_type.hh new file mode 100644 index 000000000..b5961e846 --- /dev/null +++ b/modules/mol/base/src/chain_type.hh @@ -0,0 +1,31 @@ +//------------------------------------------------------------------------------ +// 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_CHAIN_TYPE_HH +#define OST_CHAIN_TYPE_HH + +/// \enum different kinds of chains +typedef enum { + CHAINTYPE_POLY, ///< chain name by author as in PDB + CHAINTYPE_AA, ///< amino acid sequence + CHAINTYPE_NT, ///< nucleotides + CHAINTYPE_UNKNOWN, ///< guess what + CHAINTYPE_N_CHAINTYPES ///< no. of chain types +} ChainType; + +#endif diff --git a/modules/mol/base/src/editor_base.cc b/modules/mol/base/src/editor_base.cc index 771823467..b959d23ea 100644 --- a/modules/mol/base/src/editor_base.cc +++ b/modules/mol/base/src/editor_base.cc @@ -82,6 +82,11 @@ void EditorBase::RenameChain(ChainHandle chain, const String& new_name) ent_.Impl()->RenameChain(chain.Impl(), new_name); } +void EditorBase::SetChainType(ChainHandle chain, const ChainType type) +{ + CheckHandleValidity(chain); + chain.Impl()->SetChainType(type); +} AtomHandle EditorBase::InsertAtom(ResidueHandle res, const String& name, const geom::Vec3& pos, const String& ele, diff --git a/modules/mol/base/src/editor_base.hh b/modules/mol/base/src/editor_base.hh index 48bf067bd..cb009474c 100644 --- a/modules/mol/base/src/editor_base.hh +++ b/modules/mol/base/src/editor_base.hh @@ -155,6 +155,13 @@ public: void RenameResidue(ResidueHandle res, const String& new_name); void RenameChain(ChainHandle chain, const String& new_name); + + /// \brief Assign type of chain according to ChainType. + /// + /// \param chain chain to assign to + /// \param type type of the chain + void SetChainType(ChainHandle chain, const ChainType type); + /// \brief Delete all atoms of residue /// /// All associated torsions and bonds will also be removed diff --git a/modules/mol/base/src/impl/chain_impl.cc b/modules/mol/base/src/impl/chain_impl.cc index 421f98dd4..558eb2c52 100644 --- a/modules/mol/base/src/impl/chain_impl.cc +++ b/modules/mol/base/src/impl/chain_impl.cc @@ -36,7 +36,8 @@ ChainImpl::ChainImpl(const EntityImplPtr& e, const String& name): ent_(e), name_(name), residue_list_(), - in_sequence_(true) + in_sequence_(true), + chain_type_(CHAINTYPE_UNKNOWN) {} String ChainImpl::GetName() const diff --git a/modules/mol/base/src/impl/chain_impl.hh b/modules/mol/base/src/impl/chain_impl.hh index d7d2ca64b..4758297b0 100644 --- a/modules/mol/base/src/impl/chain_impl.hh +++ b/modules/mol/base/src/impl/chain_impl.hh @@ -25,6 +25,7 @@ #include <ost/geom/geom.hh> #include <ost/mol/residue_prop.hh> +#include <ost/mol/chain_type.hh> #include <ost/mol/impl/chain_impl_fw.hh> #include <ost/mol/impl/residue_impl_fw.hh> #include <ost/mol/impl/entity_impl_fw.hh> @@ -46,7 +47,23 @@ public: void SetName(const String& new_name); String GetName() const; - + + /// \brief Assign a type to a chain. + /// + /// \param type chain type of ChainType + void SetChainType(const ChainType type) + { + chain_type_ = type; + } + + /// \brief Get the type of a chain. + /// + /// \return chain type of ChainType + ChainType GetChainType() const + { + return chain_type_; + } + /// \brief append new residue with exactly the same parameters as res, but /// no atoms and bonds ResidueImplPtr AppendResidue(const ResidueImplPtr& res); @@ -134,6 +151,7 @@ private: /// \brief whether the residue numbers are in ascending order or not. Used /// to optimize residue by number lookup. bool in_sequence_; + ChainType chain_type_; }; }}} // ns diff --git a/modules/mol/base/tests/test_chain.cc b/modules/mol/base/tests/test_chain.cc index a2bdda81f..da1e627b3 100644 --- a/modules/mol/base/tests/test_chain.cc +++ b/modules/mol/base/tests/test_chain.cc @@ -202,4 +202,21 @@ BOOST_AUTO_TEST_CASE(rename_chain) BOOST_CHECK_EQUAL(eh.GetChainCount(), 2); } +BOOST_AUTO_TEST_CASE(chain_type) +{ + EntityHandle eh=CreateEntity(); + XCSEditor e=eh.EditXCS(); + ChainHandle ch1=e.InsertChain("A"); + + BOOST_CHECK(ch1.GetChainType() == CHAINTYPE_UNKNOWN); + e.SetChainType(ch1, CHAINTYPE_POLY); + BOOST_CHECK(ch1.GetChainType() == CHAINTYPE_POLY); + e.SetChainType(ch1, CHAINTYPE_AA); + BOOST_CHECK(ch1.GetChainType() == CHAINTYPE_AA); + e.SetChainType(ch1, CHAINTYPE_NT); + BOOST_CHECK(ch1.GetChainType() == CHAINTYPE_NT); + e.SetChainType(ch1, CHAINTYPE_UNKNOWN); + BOOST_CHECK(ch1.GetChainType() == CHAINTYPE_UNKNOWN); +} + BOOST_AUTO_TEST_SUITE_END() -- GitLab