00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00023
00024 #ifndef BTK_MOLECULES_POLYMER_STRUCTURE_HPP
00025 #define BTK_MOLECULES_POLYMER_STRUCTURE_HPP
00026
00027 #include <ostream>
00028 #include <algorithm>
00029 #include <iterator>
00030
00031 #include <btk/core/utility/btk_sequence.hpp>
00032 #include <btk/core/utility/chemically_typed_object.hpp>
00033 #include <btk/core/concepts/monomer_concept.hpp>
00034 #include <btk/core/concepts/monomer_iterator_concept.hpp>
00035
00036 namespace BTK {
00037 namespace MOLECULES {
00038
00039 template <typename MonomerType,
00040 typename ChemicalTypeSystemType,
00041 typename DictionaryType,
00042 typename StorageStrategy>
00043 class PolymerStructure :
00044 public BTK::UTILITY::ChemicallyTypedObject<ChemicalTypeSystemType,
00045 DictionaryType>,
00046 protected BTK::UTILITY::BTKSequence<MonomerType,StorageStrategy>
00047 {
00048 typedef BTK::UTILITY::ChemicallyTypedObject<ChemicalTypeSystemType,
00049 DictionaryType> cto_type;
00050 typedef BTK::UTILITY::BTKSequence<MonomerType,
00051 StorageStrategy> btk_seq_type;
00052 typedef PolymerStructure<MonomerType,
00053 ChemicalTypeSystemType,
00054 DictionaryType,
00055 StorageStrategy> self_type;
00056
00057 public:
00058 IMPORT_CHEMICALLY_TYPED_OBJECT_TYPES(cto_type);
00059 IMPORT_BTK_CONTAINER_TYPES(btk_seq_type);
00060
00061 typedef value_type monomer_type;
00062 typedef iterator monomer_iterator;
00063 typedef reverse_iterator reverse_monomer_iterator;
00064 typedef const_iterator const_monomer_iterator;
00065 typedef const_reverse_iterator const_reverse_monomer_iterator;
00066 typedef id_type structure_id_type;
00067 typedef typename monomer_type::id_type monomer_id_type;
00068
00069 BOOST_CLASS_REQUIRE(monomer_type,BTK::CONCEPTS,MonomerConcept);
00070 BOOST_CLASS_REQUIRE(iterator,BTK::CONCEPTS,MutableMonomerIteratorConcept);
00071 BOOST_CLASS_REQUIRE(reverse_iterator,BTK::CONCEPTS,MutableMonomerIteratorConcept);
00072 BOOST_CLASS_REQUIRE(const_iterator,BTK::CONCEPTS,MonomerIteratorConcept);
00073 BOOST_CLASS_REQUIRE(const_reverse_iterator,BTK::CONCEPTS,MonomerIteratorConcept);
00074
00075
00076
00077
00078 PolymerStructure(self_type const & source) :
00079 cto_type(source), btk_seq_type(source) {}
00080
00081 virtual ~PolymerStructure() {}
00082
00083
00084
00085
00086 IMPORT_BTK_CONTAINER_METHODS(btk_seq_type);
00087
00088
00089
00090
00091 size_type num_monomers() const { return btk_seq_type::size(); }
00092
00093 monomer_iterator polymer_begin() { return btk_seq_type::begin(); }
00094 const_monomer_iterator polymer_begin() const { return btk_seq_type::begin(); }
00095
00096 reverse_monomer_iterator polymer_rbegin() { return btk_seq_type::rbegin(); }
00097 const_reverse_monomer_iterator polymer_rbegin() const
00098 { return btk_seq_type::rbegin(); }
00099
00100 monomer_iterator polymer_end() { return btk_seq_type::end(); }
00101 const_monomer_iterator polymer_end() const { return btk_seq_type::end(); }
00102
00103 reverse_monomer_iterator polymer_rend() { return btk_seq_type::rend(); }
00104 const_reverse_monomer_iterator polymer_rend() const
00105 { return btk_seq_type::rend(); }
00106
00107 using cto_type::type;
00108 using cto_type::name;
00109 using cto_type::get_chemical_type_system;
00110
00111 virtual void set_chemical_type_system(chemical_type_system const & cts)
00112 {
00113
00114 cto_type::set_chemical_type_system(cts);
00115
00116
00117 for (monomer_iterator mi = polymer_begin(); mi != polymer_end(); ++mi)
00118 mi->set_chemical_type_system(cts);
00119 }
00120
00121 virtual std::ostream & print(std::ostream & os,
00122 size_type first_atom_num = 1,
00123 size_type first_group_num = 1,
00124 char chain_id = ' ') const
00125 {
00126 const_monomer_iterator mi;
00127 size_type atom_num = first_atom_num;
00128 size_type group_num = first_group_num;
00129
00130 for (mi = polymer_begin(); mi != polymer_end(); ++mi) {
00131 mi->print(os,atom_num,group_num,chain_id);
00132 atom_num += mi->num_atoms();
00133 ++group_num;
00134 }
00135
00136 return os;
00137 }
00138
00139 virtual dictionary const & get_dictionary() const = 0;
00140 virtual dictionary & get_dictionary() = 0;
00141
00142 protected:
00143
00144
00145
00146
00147 PolymerStructure(size_type n = 0,
00148 const_reference t = value_type(),
00149 id_type type = id_type()) :
00150 cto_type(t.get_chemical_type_system(),type), btk_seq_type(n,t) {}
00151
00152 template <typename MonomerIterator>
00153 PolymerStructure(MonomerIterator i, MonomerIterator j,
00154 id_type type = id_type()) :
00155 cto_type(i->get_chemical_type_system(),type), btk_seq_type(i,j)
00156 {
00157 boost::function_requires<BTK::CONCEPTS::
00158 MonomerIteratorConcept<MonomerIterator> >();
00159
00160
00161
00162
00163
00164
00165 typedef typename std::iterator_traits<MonomerIterator>::value_type m_t;
00166 boost::function_requires<boost::ConvertibleConcept<m_t,monomer_type> >();
00167 }
00168
00169 using cto_type::set_type;
00170
00171 self_type const & operator=(self_type const & rhs)
00172 {
00173 if (this == &rhs) return *this;
00174 cto_type::operator=(rhs);
00175 btk_seq_type::operator=(rhs);
00176 return *this;
00177 }
00178
00179 void swap(self_type & b)
00180 {
00181 cto_type::swap(b);
00182 btk_seq_type::swap(b);
00183 }
00184
00185 bool operator==(self_type const & rhs) const {
00186 return (cto_type::operator==(rhs) && btk_seq_type::operator==(rhs));
00187 }
00188
00189 bool operator!=(self_type const & rhs) const {
00190 return !(operator==(rhs));
00191 }
00192
00193 bool operator<(self_type const & rhs) const {
00194 if (cto_type::operator<(rhs))
00195 return true;
00196 else if (cto_type::operator==(rhs))
00197 return btk_seq_type::operator<(rhs);
00198 else
00199 return false;
00200 }
00201 };
00202
00203 #define IMPORT_POLYMER_STRUCTURE_TYPES(PStructure) \
00204 IMPORT_CHEMICALLY_TYPED_OBJECT_TYPES(PStructure) \
00205 IMPORT_BTK_CONTAINER_TYPES(PStructure) \
00206 \
00207 typedef typename PStructure::monomer_type monomer_type; \
00208 typedef typename PStructure::monomer_iterator monomer_iterator; \
00209 typedef typename PStructure::const_monomer_iterator \
00210 const_monomer_iterator; \
00211 typedef typename PStructure::reverse_monomer_iterator \
00212 reverse_monomer_iterator; \
00213 typedef typename PStructure::const_reverse_monomer_iterator \
00214 const_reverse_monomer_iterator; \
00215 typedef typename PStructure::structure_id_type structure_id_type; \
00216 typedef typename PStructure::monomer_id_type monomer_id_type;
00217
00218 template <typename MT, typename CTO, typename DICT, typename SS>
00219 std::ostream & operator<<(std::ostream & os, PolymerStructure<MT,CTO,DICT,SS> const & p)
00220 {
00221 return p.print(os);
00222 }
00223
00224 }
00225 }
00226
00227 #endif