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_SYSTEM_HPP
00025 #define BTK_MOLECULES_SYSTEM_HPP
00026
00027 #include <ostream>
00028 #include <list>
00029 #include <iterator>
00030
00031 #include <btk/core/utility/chemically_typed_object.hpp>
00032 #include <btk/core/utility/btk_sequence.hpp>
00033 #include <btk/core/concepts/chain_iterator_concept.hpp>
00034 #include <btk/core/molecules/system_base.hpp>
00035
00036 namespace BTK {
00037 namespace MOLECULES {
00038
00057 template <typename ChainType,
00058 typename ChemicalTypeSystemType =
00059 typename ChainType::chemical_type_system,
00060 typename StorageStrategy = std::list<ChainType> >
00061 class System :
00062 public BTK::UTILITY::ChemicallyTypedObject<ChemicalTypeSystemType,
00063 typename ChemicalTypeSystemType::
00064 structure_dictionary>,
00065 public BTK::UTILITY::BTKSequence<ChainType,StorageStrategy>,
00066 public detail::PolymerSystemBase<System<ChainType,
00067 ChemicalTypeSystemType,
00068 StorageStrategy>,
00069 ChainType,
00070 typename BTK::UTILITY::BTKSequence<ChainType,
00071 StorageStrategy>::iterator,
00072 typename BTK::UTILITY::BTKSequence<ChainType,
00073 StorageStrategy>::const_iterator,
00074 detail::IsMonomerIterable<ChainType>::value>
00075 {
00076 typedef BTK::UTILITY::ChemicallyTypedObject<ChemicalTypeSystemType,
00077 typename ChemicalTypeSystemType::
00078 structure_dictionary> cto_type;
00079 typedef BTK::UTILITY::BTKSequence<ChainType,
00080 StorageStrategy> btk_seq_type;
00081 typedef System<ChainType,
00082 ChemicalTypeSystemType,
00083 StorageStrategy> self_type;
00084
00085 public:
00086 IMPORT_CHEMICALLY_TYPED_OBJECT_TYPES(cto_type);
00087 IMPORT_BTK_CONTAINER_TYPES(btk_seq_type);
00088
00090
00091 typedef value_type chain_type;
00092 typedef iterator chain_iterator;
00093 typedef const_iterator const_chain_iterator;
00094 typedef reverse_iterator reverse_chain_iterator;
00095 typedef const_reverse_iterator const_reverse_chain_iterator;
00096 typedef id_type structure_id_type;
00098
00099 BOOST_CLASS_REQUIRE(chain_type,BTK::CONCEPTS,ChainConcept);
00100 BOOST_CLASS_REQUIRE(chain_iterator,BTK::CONCEPTS,MutableChainIteratorConcept);
00101 BOOST_CLASS_REQUIRE(const_chain_iterator,BTK::CONCEPTS,ChainIteratorConcept);
00102 BOOST_CLASS_REQUIRE(reverse_chain_iterator,BTK::CONCEPTS,MutableChainIteratorConcept);
00103 BOOST_CLASS_REQUIRE(const_reverse_chain_iterator,BTK::CONCEPTS,ChainIteratorConcept);
00104
00105
00107 typedef typename chain_type::atom_type atom_type;
00108
00109 typedef typename BTK::UTILITY::
00110 GroupedElementIterator<chain_iterator,
00111 typename chain_type::atom_iterator,
00112 chain_type,
00113 atom_type> atom_iterator;
00114
00115 typedef BTK::UTILITY::
00116 GroupedElementIterator<const_chain_iterator,
00117 typename chain_type::const_atom_iterator,
00118 chain_type const,
00119 atom_type const> const_atom_iterator;
00120
00121 typedef boost::reverse_iterator<atom_iterator> reverse_atom_iterator;
00122 typedef boost::reverse_iterator<const_atom_iterator> const_reverse_atom_iterator;
00124
00126 System(chemical_type_system const & cts,
00127 id_type type = id_type()) :
00128 cto_type(cts,type), btk_seq_type() {}
00129
00131
00132 System(size_type n = 0,
00133 const_reference t = chain_type(),
00134 id_type type = id_type()):
00135 cto_type(t.get_chemical_type_system(),type), btk_seq_type(n,t) {}
00136
00137 template <typename ChainIterator>
00138 System(ChainIterator i, ChainIterator j,
00139 id_type type = id_type()) :
00140 cto_type(i->get_chemical_type_system(),type), btk_seq_type(i,j)
00141 {
00142 boost::function_requires<BTK::CONCEPTS::
00143 ChainIteratorConcept<ChainIterator> >();
00144
00145
00146
00147
00148
00149
00150 typedef typename std::iterator_traits<ChainIterator>::value_type c_t;
00151 boost::function_requires<boost::ConvertibleConcept<c_t,chain_type> >();
00152 }
00153
00154 System(self_type const & src) :
00155 cto_type(src), btk_seq_type(src) {}
00157
00158 virtual ~System() {}
00159
00161
00162 size_type num_chains() const { return btk_seq_type::size(); }
00163
00164 iterator system_begin() { return btk_seq_type::begin(); }
00165 const_iterator system_begin() const { return btk_seq_type::begin(); }
00166
00167 reverse_iterator system_rbegin() { return btk_seq_type::rbegin(); }
00168 const_reverse_iterator system_rbegin() const { return btk_seq_type::rbegin(); }
00169
00170 iterator system_end() { return btk_seq_type::end(); }
00171 const_iterator system_end() const { return btk_seq_type::end(); }
00172
00173 reverse_iterator system_rend() { return btk_seq_type::rend(); }
00174 const_reverse_iterator system_rend() const { return btk_seq_type::rend(); }
00175
00176 virtual std::ostream & print(std::ostream & os,
00177 size_type first_atom_num = 1) const
00178 {
00179 const_chain_iterator ci;
00180 size_type atom_num = first_atom_num;
00181
00182 for (ci = system_begin(); ci != system_end(); ++ci) {
00183 ci->print(os,atom_num);
00184 atom_num += ci->num_atoms();
00185 }
00186
00187 return os;
00188 }
00190
00192
00193 typename chain_type::size_type num_atoms() const
00194 {
00195 typename chain_type::size_type N = 0;
00196 const_chain_iterator ci;
00197
00198 for (ci = system_begin(); ci != system_end(); ++ci)
00199 N += ci->num_atoms();
00200
00201 return N;
00202 }
00203
00204 atom_iterator structure_begin()
00205 {
00206 return atom_iterator(system_begin(),
00207 system_end(),
00208 &chain_type::structure_begin,
00209 &chain_type::structure_end);
00210 }
00211
00212 atom_iterator structure_end()
00213 {
00214 return atom_iterator(system_begin(),
00215 system_end(),
00216 &chain_type::structure_begin,
00217 &chain_type::structure_end,
00218 true);
00219 }
00220
00221 reverse_atom_iterator structure_rbegin()
00222 {
00223 return reverse_atom_iterator(structure_end());
00224 }
00225
00226 reverse_atom_iterator structure_rend()
00227 {
00228 return reverse_atom_iterator(structure_begin());
00229 }
00230
00231 const_atom_iterator structure_begin() const
00232 {
00233 return const_atom_iterator(system_begin(),
00234 system_end(),
00235 &chain_type::structure_begin,
00236 &chain_type::structure_end);
00237 }
00238
00239 const_atom_iterator structure_end() const
00240 {
00241 return const_atom_iterator(system_begin(),
00242 system_end(),
00243 &chain_type::structure_begin,
00244 &chain_type::structure_end,
00245 true);
00246 }
00247
00248 const_reverse_atom_iterator structure_rbegin() const
00249 {
00250 return const_reverse_atom_iterator(structure_end());
00251 }
00252
00253 const_reverse_atom_iterator structure_rend() const
00254 {
00255 return const_reverse_atom_iterator(structure_begin());
00256 }
00258
00259 using cto_type::type;
00260 using cto_type::set_type;
00261 using cto_type::name;
00262 using cto_type::get_chemical_type_system;
00263
00264 virtual dictionary const & get_dictionary() const
00265 {
00266 return cto_type::get_chemical_type_system().get_structure_dictionary();
00267 }
00268
00269 virtual dictionary & get_dictionary()
00270 {
00271 return cto_type::get_chemical_type_system().get_structure_dictionary();
00272 }
00273
00275 virtual void set_chemical_type_system(chemical_type_system const & cts)
00276 {
00277
00278 cto_type::set_chemical_type_system(cts);
00279
00280
00281 for (chain_iterator ci = system_begin(); ci != system_end(); ++ci)
00282 ci->set_chemical_type_system(cts);
00283 }
00284
00286
00287 virtual void swap(self_type & b)
00288 {
00289 cto_type::swap(b);
00290 btk_seq_type::swap(b);
00291 }
00292
00293 self_type const & operator=(self_type const & rhs)
00294 {
00295 if (this == &rhs) return *this;
00296 cto_type::operator=(rhs);
00297 btk_seq_type::operator=(rhs);
00298 return *this;
00299 }
00300
00301 bool operator==(self_type const & rhs) const
00302 {
00303 return (cto_type::operator==(rhs) &&
00304 btk_seq_type::operator==(rhs));
00305 }
00306
00307 bool operator!=(self_type const & rhs) const
00308 {
00309 return !(operator==(rhs));
00310 }
00311
00312 bool operator<(self_type const & rhs) const
00313 {
00314 if (cto_type::operator<(rhs))
00315 return true;
00316 else if (cto_type::operator==(rhs))
00317 return btk_seq_type::operator<(rhs);
00318 else
00319 return false;
00320 }
00322 };
00323
00324 #define IMPORT_BTK_SYSTEM_TYPES(SysType) \
00325 IMPORT_CHEMICALLY_TYPED_OBJECT_TYPES(SysType) \
00326 IMPORT_BTK_CONTAINER_TYPES(SysType) \
00327 \
00328 typedef typename SysType::chain_type chain_type; \
00329 typedef typename SysType::chain_iterator chain_iterator; \
00330 typedef typename SysType::const_chain_iterator const_chain_iterator; \
00331 typedef typename SysType::reverse_chain_iterator reverse_chain_iterator; \
00332 typedef typename SysType::const_reverse_chain_iterator \
00333 const_reverse_chain_iterator; \
00334 typedef typename SysType::structure_id_type structure_id_type; \
00335 typedef typename SysType::atom_type atom_type; \
00336 typedef typename SysType::atom_iterator atom_iterator; \
00337 typedef typename SysType::const_atom_iterator const_atom_iterator; \
00338 typedef typename SysType::reverse_atom_iterator reverse_atom_iterator; \
00339 typedef typename SysType::const_reverse_atom_iterator \
00340 const_reverse_atom_iterator; \
00341 typedef typename SysType::monomer_type monomer_type; \
00342 typedef typename SysType::monomer_iterator monomer_iterator; \
00343 typedef typename SysType::const_monomer_iterator const_monomer_iterator; \
00344 typedef typename SysType::reverse_monomer_iterator reverse_monomer_iterator; \
00345 typedef typename SysType::const_reverse_monomer_iterator \
00346 const_reverse_monomer_iterator;
00347
00348 template <typename CH, typename CTO, typename SS>
00349 std::ostream & operator<<(std::ostream & os, System<CH,CTO,SS> const & s)
00350 {
00351 return s.print(os);
00352 }
00353
00354 }
00355 }
00356
00357 #endif