diff --git a/modules/mol/base/doc/editors.rst b/modules/mol/base/doc/editors.rst index 574f6b18ccef97cb4922871d3942c70674f42be0..be0a1d3ca907f3764ab4030ad09066eae886bc60 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 1ee9e6bdae35cce7abfe51d84e0315a354bc25da..cf00a6b5e5069ce005a6c7b13776ee95becbe4ea 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 8a4cb355258454f90c0588cba0f17cb432da9b29..3361c5fa3ca7e0510018800870c5dcea5e4fb219 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 34d3a7fe8960cba5019702873fca197995f22eb0..61ea42cebadeae960658336b13dd860a6b4d362d 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 b11b6e54c28389f77a429affc569470c14499ae4..22bda6d3551a31fe8d26eeae19c200b2bc2499c8 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 a82f8c05b92d0028396375c087176bc4571e3cda..4147ed5322abccca4cc904563c34786e3c67ff01 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 4a904a2a87e67e72b015deb7d643ebe8df5f8804..ca9e45724ac13f929a166d2f461913e846dbb63f 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 0000000000000000000000000000000000000000..b5961e846a29b9cb02361c33614156b73f708e29 --- /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 7718234673d7e35c33aee25b113a33e1c2dc2d54..b959d23ea693bec300aa31c9e40b537fc8aa66b7 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 48bf067bd19ea8c1957d60fe3ba3c439f86b4917..cb009474c698fe73fa488a24e8415c8b88ea744b 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 421f98dd4a43bafb12537e1649b51aba49abb9d3..558eb2c526df71e9e076a98d709ecc6e5987a728 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 d7d2ca64beeb0f464263c8ddedd9f3da8be5a2ae..4758297b06dc4bab7efaab60af17047468129d2e 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 a2bdda81f87a8fb3b703a5489b232e8bd0ae00eb..da1e627b37232fd7fb16651066aaa7ea4f44f78f 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()