00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00056
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
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
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
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
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
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
00154 typedef typename std::iterator_traits<AtomIterator>::value_type InputT;
00155 boost::function_requires<boost::ConvertibleConcept<InputT,PDBAtom> >();
00156
00157
00158
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
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
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