Skip to content
Snippets Groups Projects
Commit 6a70d5bc authored by Bienchen's avatar Bienchen
Browse files

Added functions ChainTypeFromString, ChainTypeFromString, StringFromChainType...

Added functions ChainTypeFromString, ChainTypeFromString, StringFromChainType for handling ChainType, with tests and documentation.
parent 10c30d1c
No related branches found
No related tags found
No related merge requests found
......@@ -94,7 +94,7 @@ The basic functionality of editors is implemented in the EditorBase class.
:param chain: Must be a valid chain
:param type: Must be a value of enum ChainType
(see :attr:`ChainHandle.chain_type`)
(see :attr:`ChainHandle.type`)
.. method:: SetChainDescription(chain, description)
......
......@@ -287,16 +287,7 @@ The Handle Classes
.. attribute:: type
Describes the type of the chain. Is one of enum ChainType:
``CHAINTYPE_POLY``, ``CHAINTYPE_NON_POLY``, ``CHAINTYPE_WATER``,
``CHAINTYPE_POLY_PEPTIDE_D``, ``CHAINTYPE_POLY_PEPTIDE_L``,
``CHAINTYPE_POLY_DN``, ``CHAINTYPE_POLY_RN``, ``CHAINTYPE_POLY_SAC_D``,
``CHAINTYPE_POLY_SAC_L``, ``CHAINTYPE_POLY_DN_RN``,
``CHAINTYPE_UNKNOWN``, ``CHAINTYPE_N_CHAINTYPES``
Where ``CHAINTYPE_N_CHAINTYPES`` holds the number of different types
available.
Describes the type of the chain. See :ref:`chaintype`.
.. attribute:: description
......@@ -1546,3 +1537,59 @@ Other Entity-Related Functions
encountered
:returns: :class:`EntityView`
.. _chaintype:
ChainType
--------------------------------------------------------------------------------
A ChainType fills the :attr:`ChainHandle.type` attribute. Different types are
described in the :ref:`ChainType enum <chaintype_enum>`. Functions for setting
a type belong to the :class:`EditorBase` class, getting is provided by the
:class:`ChainHandle` class, further convenience functions are described here.
.. _chaintype_enum:
The ChainType enum
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The ChainType enum enumerates all types defined by the PDB for the MMCif file
format. Following values are supported:
``CHAINTYPE_POLY``, ``CHAINTYPE_NON_POLY``, ``CHAINTYPE_WATER``,
``CHAINTYPE_POLY_PEPTIDE_D``, ``CHAINTYPE_POLY_PEPTIDE_L``,
``CHAINTYPE_POLY_DN``, ``CHAINTYPE_POLY_RN``, ``CHAINTYPE_POLY_SAC_D``,
``CHAINTYPE_POLY_SAC_L``, ``CHAINTYPE_POLY_DN_RN``,
``CHAINTYPE_UNKNOWN``, ``CHAINTYPE_N_CHAINTYPES``
Where ``CHAINTYPE_N_CHAINTYPES`` holds the number of different types available.
Setter & Getter functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
:func:`EditorBase.SetChainType`, :func:`ChainHandle.GetType`
ChainType functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. function:: ChainTypeFromString(identifier)
Create a ChainType item for a given string.
:param identifier: String to request a type for.
:type identifier: :class:`str`
:raises: :class:`runtime_error` if **identifier** is unrecognised.
:returns: :class:`ChainType`
.. function:: StringFromChainType(type)
Return the String identifier for a given **type**.
:param type: To be translated
:type type: :class:`ChainType`
:raises: :class:`runtime_error` if **type** is unrecognised.
:returns: :class:`str`
......@@ -13,4 +13,4 @@ The mol module implements data structures to work with molecular datasets. At it
editors
query
surface
traj
\ No newline at end of file
traj
......@@ -39,7 +39,9 @@ namespace {
typedef EntityView (ChainHandle::*QueryMethod)(const Query&, uint) const;
typedef EntityView (ChainHandle::*StringMethod)(const String&, uint) const;
QueryMethod select_query=&ChainHandle::Select;
StringMethod select_string=&ChainHandle::Select;
StringMethod select_string=&ChainHandle::Select;
ChainType (*ChainTypeFromStringPtr)(const String& identifier) =
&ChainTypeFromString;
}
void export_Chain()
......@@ -126,4 +128,7 @@ void export_Chain()
.export_values()
;
}
def("ChainTypeFromString", ChainTypeFromStringPtr);
def("StringFromChainType", &StringFromChainType);
}
......@@ -8,6 +8,7 @@ bond_handle.cc
chain_base.cc
chain_handle.cc
chain_view.cc
chain_type.cc
coord_frame.cc
coord_group.cc
editor_base.cc
......
//------------------------------------------------------------------------------
// 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
//------------------------------------------------------------------------------
#include <stdexcept>
#include "chain_type.hh"
namespace ost { namespace mol {
ChainType ChainTypeFromString(StringRef identifier)
{
// chain types as found in the entity category of a mmcif file
if(StringRef("polymer", 7) == identifier) {
return CHAINTYPE_POLY;
}else if(StringRef("non-polymer", 11) == identifier) {
return CHAINTYPE_NON_POLY;
}else if(StringRef("water", 5) == identifier) {
return CHAINTYPE_WATER;
// chain types as found in the entity_poly category of a mmcif file
} else if(StringRef("polypeptide(D)", 14) == identifier) {
return CHAINTYPE_POLY_PEPTIDE_D;
} else if(StringRef("polypeptide(L)", 14) == identifier) {
return CHAINTYPE_POLY_PEPTIDE_L;
} else if(StringRef("polydeoxyribonucleotide", 23) == identifier) {
return CHAINTYPE_POLY_DN;
} else if(StringRef("polyribonucleotide", 18) == identifier) {
return CHAINTYPE_POLY_RN;
} else if(StringRef("polysaccharide(D)", 17) == identifier) {
return CHAINTYPE_POLY_SAC_D;
} else if(StringRef("polysaccharide(L)", 17) == identifier) {
return CHAINTYPE_POLY_SAC_L;
} else if(StringRef("polydeoxyribonucleotide/polyribonucleotide hybrid",
49) == identifier) {
return CHAINTYPE_POLY_DN_RN;
} else if(StringRef("other", 5) == identifier) {
return CHAINTYPE_UNKNOWN;
}
throw std::runtime_error("Unrecognised chain type descriptor found: '" +
identifier.str() +"'!");
}
ChainType ChainTypeFromString(const String& identifier)
{
return ChainTypeFromString(StringRef(identifier.c_str(),
identifier.length()));
}
String StringFromChainType(ChainType type)
{
// chain types as found in the entity category of a mmcif file
if (CHAINTYPE_POLY == type) {
return "polymer";
} else if (CHAINTYPE_NON_POLY == type) {
return "non-polymer";
} else if (CHAINTYPE_WATER == type) {
return "water";
// chain types as found in the entity_poly category of a mmcif file
} else if (CHAINTYPE_POLY_PEPTIDE_D == type) {
return "polypeptide(D)";
} else if (CHAINTYPE_POLY_PEPTIDE_L == type) {
return "polypeptide(L)";
} else if (CHAINTYPE_POLY_DN == type) {
return "polydeoxyribonucleotide";
} else if (CHAINTYPE_POLY_RN == type) {
return "polyribonucleotide";
} else if (CHAINTYPE_POLY_SAC_D == type) {
return "polysaccharide(D)";
} else if (CHAINTYPE_POLY_SAC_L == type) {
return "polysaccharide(L)";
} else if (CHAINTYPE_POLY_DN_RN == type) {
return "polydeoxyribonucleotide/polyribonucleotide hybrid";
} else if (CHAINTYPE_UNKNOWN == type) {
return "other";
}
std::stringstream ss("Unknonw ChainType item found: '");
ss << type << "'!";
throw std::runtime_error(ss.str());
}
}} //ns
......@@ -19,6 +19,11 @@
#ifndef OST_CHAIN_TYPE_HH
#define OST_CHAIN_TYPE_HH
#include <ost/base.hh>
#include <ost/string_ref.hh>
namespace ost { namespace mol {
/// \enum different kinds of chains
typedef enum {
CHAINTYPE_POLY, ///< polymer
......@@ -35,5 +40,30 @@ typedef enum {
CHAINTYPE_N_CHAINTYPES ///< no. of chain types
} ChainType;
/// \brief Create a ChainType item for a given string
///
/// \param identifier StringRef to be translated
///
/// \return The ChainType corresponding to the input, throws a
/// std::runtime_error on unknown type
ChainType ChainTypeFromString(const StringRef identifier);
/// \brief Create a ChainType item for a given string
///
/// \param identifier String to be translated
///
/// \return The ChainType corresponding to the input, throws a
/// std::runtime_error on unknown type
ChainType ChainTypeFromString(const String& identifier);
/// \brief Return the String identifier for a given type
///
/// \param type ChainType to be translated
///
/// \return String corresponding to the input, throws a std::runtime_error on
/// unknown type
String StringFromChainType(ChainType type);
}} //ns
#endif
......@@ -208,6 +208,7 @@ BOOST_AUTO_TEST_CASE(chain_type)
XCSEditor e = eh.EditXCS();
ChainHandle ch1 = e.InsertChain("A");
// setting/ getting
BOOST_CHECK(ch1.GetType() == CHAINTYPE_UNKNOWN);
e.SetChainType(ch1, CHAINTYPE_POLY);
BOOST_CHECK(ch1.GetType() == CHAINTYPE_POLY);
......@@ -233,6 +234,50 @@ BOOST_AUTO_TEST_CASE(chain_type)
BOOST_CHECK(ch1.GetType() == CHAINTYPE_N_CHAINTYPES);
e.SetChainType(ch1, CHAINTYPE_UNKNOWN);
BOOST_CHECK(ch1.GetType() == CHAINTYPE_UNKNOWN);
// string -> chain type
BOOST_CHECK(ChainTypeFromString("polymer") == CHAINTYPE_POLY);
BOOST_CHECK(ChainTypeFromString("non-polymer") == CHAINTYPE_NON_POLY);
BOOST_CHECK(ChainTypeFromString("water") == CHAINTYPE_WATER);
BOOST_CHECK(ChainTypeFromString("polypeptide(D)") ==
CHAINTYPE_POLY_PEPTIDE_D);
BOOST_CHECK(ChainTypeFromString("polypeptide(L)") ==
CHAINTYPE_POLY_PEPTIDE_L);
BOOST_CHECK(ChainTypeFromString("polydeoxyribonucleotide") ==
CHAINTYPE_POLY_DN);
BOOST_CHECK(ChainTypeFromString("polyribonucleotide") ==
CHAINTYPE_POLY_RN);
BOOST_CHECK(ChainTypeFromString("polysaccharide(D)") ==
CHAINTYPE_POLY_SAC_D);
BOOST_CHECK(ChainTypeFromString("polysaccharide(L)") ==
CHAINTYPE_POLY_SAC_L);
BOOST_CHECK(ChainTypeFromString(
"polydeoxyribonucleotide/polyribonucleotide hybrid") ==
CHAINTYPE_POLY_DN_RN);
BOOST_CHECK(ChainTypeFromString("other") == CHAINTYPE_UNKNOWN);
BOOST_CHECK_THROW(ChainTypeFromString("supposed to fail"),
std::runtime_error);
// chain type -> string
BOOST_CHECK(StringFromChainType(CHAINTYPE_POLY) == "polymer");
BOOST_CHECK(StringFromChainType(CHAINTYPE_NON_POLY) == "non-polymer");
BOOST_CHECK(StringFromChainType(CHAINTYPE_WATER) == "water");
BOOST_CHECK(StringFromChainType(CHAINTYPE_POLY_PEPTIDE_D) ==
"polypeptide(D)");
BOOST_CHECK(StringFromChainType(CHAINTYPE_POLY_PEPTIDE_L) ==
"polypeptide(L)");
BOOST_CHECK(StringFromChainType(CHAINTYPE_POLY_DN) ==
"polydeoxyribonucleotide");
BOOST_CHECK(StringFromChainType(CHAINTYPE_POLY_RN) == "polyribonucleotide");
BOOST_CHECK(StringFromChainType(CHAINTYPE_POLY_SAC_D) ==
"polysaccharide(D)");
BOOST_CHECK(StringFromChainType(CHAINTYPE_POLY_SAC_L) ==
"polysaccharide(L)");
BOOST_CHECK(StringFromChainType(CHAINTYPE_POLY_DN_RN) ==
"polydeoxyribonucleotide/polyribonucleotide hybrid");
BOOST_CHECK(StringFromChainType(CHAINTYPE_UNKNOWN) == "other");
BOOST_CHECK_THROW(StringFromChainType(CHAINTYPE_N_CHAINTYPES),
std::runtime_error);
}
BOOST_AUTO_TEST_CASE(chain_description)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment