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

polymer.hpp

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) 2003, Tim Robertson <kid50@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 #include "pdb_atom.h"
00022 
00023 #include <boost/concept_check.hpp>
00024 
00025 #include <iostream>
00026 #include <iterator>
00027 
00028 template <typename MonomerType>
00029 BTK::Polymer<MonomerType>::
00030 Polymer(size_type s,
00031         build_strategy_t build_strategy) 
00032   : base_type(s), 
00033     _molecule(),
00034     _build_strategy(build_strategy)
00035 {
00036   sync_molecule_to_monomers();
00037   if( _build_strategy) _build_strategy(atom_begin(),atom_end());
00038 }
00039 
00040 template <typename MonomerType>
00041 template <typename AtomIterator>
00042 BTK::Polymer<MonomerType>::
00043 Polymer(AtomIterator first,
00044         AtomIterator last,
00045         build_strategy_t build_strategy) 
00046   : base_type(), 
00047     _molecule(),
00048     _build_strategy(build_strategy)
00049 {
00050   create_monomers(first,last);
00051   sync_molecule_to_monomers();
00052   if(_build_strategy) _build_strategy(atom_begin(),atom_end());
00053 }
00054 
00055 // for now the build-strategy doesn't copy until I figure out how
00056 // to make the cross atom case work
00057 //
00058 template <typename MonomerType>
00059 BTK::Polymer<MonomerType>::
00060 Polymer(const self_type& source) 
00061   : base_type(source), 
00062     _molecule(),
00063     _build_strategy(0)
00064   // _build_strategy(source.build_strategy()) 
00065 {
00066   _molecule.set_chain_id(source.chain_id());
00067   _molecule.set_name(source.name());
00068   sync_molecule_to_monomers();
00069 }
00070 
00071 template <typename MonomerType>
00072 template <typename T2>
00073 BTK::Polymer<MonomerType>::
00074 Polymer(const Polymer<T2>& source) 
00075   : base_type(source), 
00076     _molecule(),
00077     _build_strategy(0)
00078     // _build_strategy(source.build_strategy())
00079 {
00080   _molecule.set_chain_id(source.chain_id());
00081   _molecule.set_name(source.name());
00082   sync_molecule_to_monomers();
00083 }
00084 
00085 
00086 template <typename MonomerType>
00087 typename BTK::Polymer<MonomerType>::self_type&
00088 BTK::Polymer<MonomerType>::
00089 operator=(const self_type& rhs)
00090 {
00091   if (&rhs == this) return *this;
00092   base_type::operator=(rhs);
00093   set_chain_id(rhs.chain_id());
00094   set_name(rhs.name());
00096   _build_strategy=0;
00097   //_build_strategy=rhs.build_strategy();
00098   sync_molecule_to_monomers();  
00099   return *this;
00100 }
00101 
00102 template <typename MonomerType>
00103 template <typename T2>
00104 typename BTK::Polymer<MonomerType>::self_type&
00105 BTK::Polymer<MonomerType>::
00106 operator=(const Polymer<T2>& rhs)
00107 {
00108   base_type::operator=(rhs);
00109   set_chain_id(rhs.chain_id());
00110   set_name(rhs.name());
00111   _build_strategy=0;
00112   //  _build_strategy=rhs.build_strategy();
00113   sync_molecule_to_monomers();  
00114   return *this;
00115 }
00116 
00117 template <typename MonomerType>
00118 void
00119 BTK::Polymer<MonomerType>::
00120 sync_molecule_to_monomers()
00121 {
00122   _molecule.clear();
00123   const_iterator m=this->monomer_begin(),m_end=this->monomer_end();
00124   for(;m!=m_end;++m){
00125     _molecule.shallow_insert(atom_end(),m->atom_begin(),m->atom_end());
00126   }
00127 }
00128 
00129 
00130 template <typename MonomerType>
00131 template <typename AtomIterator>
00132 void
00133 BTK::Polymer<MonomerType>::
00134 add_monomer(AtomIterator first,
00135             AtomIterator last,
00136             const AtomGroupConcept::group_variant_container_t& modifiers)
00137 {
00138   // iterator requirements: InputIterator
00139   monomer_type* m_ptr = 0;
00140   if(this->monomer_end()!= this->monomer_begin()) {
00141     m_ptr = &(back());
00142   }
00143   shallow_push_back(new monomer_type(first,last,m_ptr,0,modifiers));
00144 }
00145 
00146 template <typename MonomerType>
00147 template <typename AtomIterator>
00148 void
00149 BTK::Polymer<MonomerType>::
00150 create_monomers(AtomIterator first,
00151                 AtomIterator last)
00152 {
00153   // iterator requirements: InputIterator
00154   typedef typename std::iterator_traits<AtomIterator>::value_type InputT;
00155   boost::function_requires<boost::ConvertibleConcept<InputT,PDBAtom> >();
00156 
00157   // until a more complete modifier system is in place, start with
00158   // empty sets here and shove the NTERM and CTERM in
00159   //
00160 
00161   AtomIterator group_begin = first;
00162   int current_group_num = first->group_num();
00163   AtomGroupConcept::group_variant_container_t current_group_modifier;
00164   current_group_modifier.insert(GROUP_VARIANT::NTER);
00165   
00166   // group atoms into monomers by group number
00167   //
00168   for (;first!=last;++first) {
00169     if (first->group_num() != current_group_num) {
00170       add_monomer(group_begin,first,current_group_modifier);
00171       current_group_modifier.clear();
00172       group_begin = first;
00173       current_group_num = first->group_num();
00174     }
00175   }
00176 
00177   // add the last monomer
00178   if (group_begin != first) { 
00179     current_group_modifier.insert(GROUP_VARIANT::CTER);
00180     add_monomer(group_begin,first,current_group_modifier);
00181   }
00182 }
00183 
00184 template <typename MonomerType>
00185 std::ostream& operator<<(std::ostream& os,
00186                          const BTK::Polymer<MonomerType>& p)
00187 {
00188   unsigned atom = 1;
00189   typedef typename BTK::Polymer<MonomerType>::const_atom_iterator citer;
00190   citer i=p.atom_begin(),i_end=p.atom_end();
00191   for (;i!=i_end;++i) {
00192     i->print_pdb_line(atom++,p.chain_id(),os);
00193   }  
00194   os << "TER\n";
00195   
00196   return os;
00197 }
00198 
00199 

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