From 062268db3d06c20830aa52510666941c1470f7ae Mon Sep 17 00:00:00 2001 From: Stefan Bienert <stefan.bienert@unibas.ch> Date: Tue, 2 Aug 2011 13:21:25 +0200 Subject: [PATCH] Added new member description_ to chain. With get/ set functions and test. --- modules/io/src/mol/mmcif_reader.cc | 8 +++++++- modules/io/src/mol/mmcif_reader.hh | 4 +++- modules/mol/base/src/chain_base.cc | 4 ++++ modules/mol/base/src/chain_base.hh | 5 +++++ modules/mol/base/src/editor_base.cc | 6 ++++++ modules/mol/base/src/editor_base.hh | 6 ++++++ modules/mol/base/src/impl/chain_impl.cc | 3 ++- modules/mol/base/src/impl/chain_impl.hh | 17 +++++++++++++++++ modules/mol/base/tests/test_chain.cc | 16 +++++++++++++--- 9 files changed, 63 insertions(+), 6 deletions(-) diff --git a/modules/io/src/mol/mmcif_reader.cc b/modules/io/src/mol/mmcif_reader.cc index 3bac82e55..7fba25293 100644 --- a/modules/io/src/mol/mmcif_reader.cc +++ b/modules/io/src/mol/mmcif_reader.cc @@ -154,7 +154,8 @@ bool MMCifParser::OnBeginLoop(const StarLoopDesc& header) // mandatory items this->TryStoreIdx(E_ID, "id", header); // optional - indices_[E_TYPE] = header.GetIndex("type"); + indices_[E_TYPE] = header.GetIndex("type"); + indices_[DETAILS] = header.GetIndex("details"); return true; } /*else if (header.GetCategory()=="entity_poly") { @@ -451,6 +452,11 @@ void MMCifParser::ParseEntity(const std::vector<StringRef>& columns) store = true; } + // description + if (indices_[DETAILS] != -1) { + desc.details = columns[indices_[E_TYPE]].str(); + } + if (store) { entity_desc_map_.insert( MMCifEntityDescMap::value_type(columns[indices_[E_ID]].str(), diff --git a/modules/io/src/mol/mmcif_reader.hh b/modules/io/src/mol/mmcif_reader.hh index 529702a74..73e378aeb 100644 --- a/modules/io/src/mol/mmcif_reader.hh +++ b/modules/io/src/mol/mmcif_reader.hh @@ -186,7 +186,8 @@ private: /// \enum items of the entity category typedef enum { E_ID, ///< unique identifier - E_TYPE ///< polymer, non-polymer or water + E_TYPE, ///< polymer, non-polymer or water + DETAILS ///< special aspects of the entity } EntityItems; /// \enum categories of the mmcif format @@ -199,6 +200,7 @@ private: /// \struct keeping track of entity information typedef struct { ChainType type; ///< characterise entity + String details; ///< description of this entity } MMCifEntityDesc; typedef std::map<String, MMCifEntityDesc> MMCifEntityDescMap; diff --git a/modules/mol/base/src/chain_base.cc b/modules/mol/base/src/chain_base.cc index 4147ed532..1f5b04cd0 100644 --- a/modules/mol/base/src/chain_base.cc +++ b/modules/mol/base/src/chain_base.cc @@ -48,6 +48,10 @@ ChainType ChainBase::GetChainType() const { return impl_->GetChainType(); } +String ChainBase::GetChainDescription() const { + return impl_->GetChainDescription(); +} + 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 ca9e45724..5410ada9f 100644 --- a/modules/mol/base/src/chain_base.hh +++ b/modules/mol/base/src/chain_base.hh @@ -65,6 +65,11 @@ public: /// \return chain type of ChainType ChainType GetChainType() const; + /// \brief Get information about a chain. + /// + /// \return description + String GetChainDescription() const; + const impl::ChainImplPtr& Impl() const { return impl_; } diff --git a/modules/mol/base/src/editor_base.cc b/modules/mol/base/src/editor_base.cc index b959d23ea..c9fa92bd4 100644 --- a/modules/mol/base/src/editor_base.cc +++ b/modules/mol/base/src/editor_base.cc @@ -88,6 +88,12 @@ void EditorBase::SetChainType(ChainHandle chain, const ChainType type) chain.Impl()->SetChainType(type); } +void EditorBase::SetChainDescription(ChainHandle chain, const String desc) +{ + CheckHandleValidity(chain); + chain.Impl()->SetChainDescription(desc); +} + AtomHandle EditorBase::InsertAtom(ResidueHandle res, const String& name, const geom::Vec3& pos, const String& ele, Real occupancy, Real b_factor, diff --git a/modules/mol/base/src/editor_base.hh b/modules/mol/base/src/editor_base.hh index cb009474c..cd8c811ca 100644 --- a/modules/mol/base/src/editor_base.hh +++ b/modules/mol/base/src/editor_base.hh @@ -162,6 +162,12 @@ public: /// \param type type of the chain void SetChainType(ChainHandle chain, const ChainType type); + /// \brief Assign a description to a chain. + /// + /// \param chain chain to assign to + /// \param desc description + void SetChainDescription(ChainHandle chain, const String desc); + /// \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 558eb2c52..a96ce571c 100644 --- a/modules/mol/base/src/impl/chain_impl.cc +++ b/modules/mol/base/src/impl/chain_impl.cc @@ -37,7 +37,8 @@ ChainImpl::ChainImpl(const EntityImplPtr& e, const String& name): name_(name), residue_list_(), in_sequence_(true), - chain_type_(CHAINTYPE_UNKNOWN) + chain_type_(CHAINTYPE_UNKNOWN), + description_() {} 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 4758297b0..31bd36879 100644 --- a/modules/mol/base/src/impl/chain_impl.hh +++ b/modules/mol/base/src/impl/chain_impl.hh @@ -64,6 +64,22 @@ public: return chain_type_; } + /// \brief Assign a description to a chain. + /// + /// \param desc description + void SetChainDescription(const String desc) + { + description_ = desc; + } + + /// \brief Get information about a chain + /// + /// \return description + String GetChainDescription() const + { + return description_; + } + /// \brief append new residue with exactly the same parameters as res, but /// no atoms and bonds ResidueImplPtr AppendResidue(const ResidueImplPtr& res); @@ -152,6 +168,7 @@ private: /// to optimize residue by number lookup. bool in_sequence_; ChainType chain_type_; + String description_; ///< special aspects of the chain }; }}} // ns diff --git a/modules/mol/base/tests/test_chain.cc b/modules/mol/base/tests/test_chain.cc index 80b729d75..b866ecd00 100644 --- a/modules/mol/base/tests/test_chain.cc +++ b/modules/mol/base/tests/test_chain.cc @@ -204,9 +204,9 @@ BOOST_AUTO_TEST_CASE(rename_chain) BOOST_AUTO_TEST_CASE(chain_type) { - EntityHandle eh=CreateEntity(); - XCSEditor e=eh.EditXCS(); - ChainHandle ch1=e.InsertChain("A"); + EntityHandle eh = CreateEntity(); + XCSEditor e = eh.EditXCS(); + ChainHandle ch1 = e.InsertChain("A"); BOOST_CHECK(ch1.GetChainType() == CHAINTYPE_UNKNOWN); e.SetChainType(ch1, CHAINTYPE_POLY); @@ -235,4 +235,14 @@ BOOST_AUTO_TEST_CASE(chain_type) BOOST_CHECK(ch1.GetChainType() == CHAINTYPE_UNKNOWN); } +BOOST_AUTO_TEST_CASE(chain_description) +{ + EntityHandle eh=CreateEntity(); + XCSEditor e = eh.EditXCS(); + ChainHandle ch1 = e.InsertChain("A"); + String description = "Very important information"; + e.SetChainDescription(ch1, description); + BOOST_CHECK(ch1.GetChainDescription() == description); +} + BOOST_AUTO_TEST_SUITE_END() -- GitLab