Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

polymer.h

Go to the documentation of this file.
00001 // -*- mode: c++; -*-
00002 //
00003 //The Biomolecule Toolkit (BTK) is a C++ library for use in the
00004 //modeling, analysis, and design of biological macromolecules.
00005 //Copyright (C) 2004, Christopher Saunders <ctsa@users.sourceforge.net>
00006 //
00007 //This program is free software; you can redistribute it and/or modify
00008 //it under the terms of the GNU Lesser General Public License as published
00009 //by the Free Software Foundation; either version 2.1 of the License, or (at
00010 //your option) any later version.
00011 //
00012 //This program is distributed in the hope that it will be useful,  but
00013 //WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 //Lesser General Public License for more details. 
00016 //
00017 //You should have received a copy of the GNU Lesser General Public License 
00018 //along with this program; if not, write to the Free Software Foundation, 
00019 //Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 
00025 
00026 
00027 #ifndef BTK_POLYMER_H
00028 #define BTK_POLYMER_H
00029 
00030 #include "molecule.h"
00031 #include "monomer_container.h"
00032 
00033 #include <boost/function.hpp>
00034 
00035 #include <iosfwd>
00036 #include <string>
00037 
00038 namespace BTK {
00039 
00040   // user typedefs
00041   template <typename MonomerType> class Polymer;
00042   typedef Polymer<basic_monomer> basic_polymer;
00043 
00055 template <typename MonomerType>  
00056 class Polymer : public MonomerContainer<MonomerType> {
00057   typedef MonomerContainer<MonomerType> base_type;
00058   typedef Molecule<typename MonomerType::atom_type> base_molecule_type;
00059   typedef Polymer<MonomerType> self_type;
00060 public:
00061 
00063 
00064   typedef typename base_type::value_type value_type;
00065   typedef typename base_type::reference reference;
00066   typedef typename base_type::const_reference const_reference;
00067   typedef typename base_type::pointer pointer;
00068   typedef typename base_type::const_pointer const_pointer;
00069   typedef typename base_type::size_type size_type;
00070   typedef typename base_type::iterator iterator;
00071   typedef typename base_type::const_iterator const_iterator;
00073 
00075 
00076   typedef value_type monomer_type;
00077   typedef iterator monomer_iterator;
00078   typedef const_iterator const_monomer_iterator;
00079   
00080   typedef typename base_molecule_type::value_type atom_type;
00081   typedef typename base_molecule_type::iterator atom_iterator;
00082   typedef typename base_molecule_type::const_iterator const_atom_iterator;
00083   typedef typename base_molecule_type::reference atom_reference;
00084   typedef typename base_molecule_type::const_reference const_atom_reference;
00086 
00087   typedef boost::function<void(atom_iterator,atom_iterator)> build_strategy_t; 
00088 
00089 
00090   Polymer(size_type s = 0,
00091           build_strategy_t build_strategy = 0);
00092  
00098   template <typename AtomIterator>
00099   Polymer(AtomIterator first,
00100           AtomIterator last,
00101           build_strategy_t build_strategy = 0);
00102 
00103   Polymer(const self_type& source);  
00104 
00105   template <typename T2>
00106   Polymer(const Polymer<T2>& source);  
00107 
00108   ~Polymer() {}
00109 
00110 
00115   self_type& 
00116   operator=(const self_type& rhs);
00117 
00118   template <typename T2>
00119   self_type& 
00120   operator=(const Polymer<T2>& rhs);
00121 
00123   // pull in part of molecule interface
00124   //
00125   const std::string& name() const { return _molecule.name(); }
00126   void set_name(const std::string& name) { _molecule.set_name(name); }
00127 
00128   char chain_id() const { return _molecule.chain_id(); } 
00129   void set_chain_id(char chain_id) { _molecule.set_chain_id(chain_id); }
00130 
00131   size_type atom_size() const { return _molecule.atom_size(); }
00132   
00133   atom_iterator atom_begin() { return _molecule.atom_begin(); }
00134   const_atom_iterator atom_begin() const { return _molecule.atom_begin(); }
00135   
00136   atom_iterator atom_end() { return _molecule.atom_end(); }
00137   const_atom_iterator atom_end() const { return _molecule.atom_end(); }
00138 
00139   atom_reference atom(size_type i) { return _molecule.operator[](i); }
00140   const_atom_reference atom(size_type i) const { return _molecule.operator[](i); }
00141 
00142   atom_reference atom_back() { return _molecule.atom_back(); }
00143   const_atom_reference atom_back() const { return _molecule.atom_back(); }
00144 
00145   atom_reference atom_front() { return _molecule.atom_front(); }
00146   const_atom_reference atom_front() const { return _molecule.atom_front(); }
00147 
00148 
00149 
00150   // exposing protected members of monomer_container or molecule
00151   // requires a molecule sync until a better system for shallow copy
00152   // sync can be found
00153   //
00154   void monomer_push_back(const monomer_type& m){
00155     push_back(m);
00156     sync_molecule_to_monomers();
00157   }
00158 
00159   build_strategy_t build_strategy() const { return _build_strategy; }
00160 
00161 protected:
00162 
00163   template <typename AtomIterator>
00164   void add_monomer(AtomIterator first,
00165                    AtomIterator last,
00166                    const AtomGroupConcept::group_variant_container_t& modifiers);
00167 
00168   template <typename AtomIterator>
00169   void create_monomers(AtomIterator first,
00170                        AtomIterator last);
00171 
00175   void sync_molecule_to_monomers();
00176 
00177 private:
00178   base_molecule_type _molecule; 
00179   build_strategy_t _build_strategy;
00180 };
00181 
00182 } // namespace BTK
00183 
00184 template <typename MonomerType>
00185 std::ostream& operator<<(std::ostream& os,
00186                          const BTK::Polymer<MonomerType>& p);
00187 
00188 
00189 #include "polymer.hpp"
00190 
00191 #endif 

Generated on Wed Apr 14 00:43:17 2004 for BTK by doxygen 1.3.6