pdb_atom_decorator.hpp

Go to the documentation of this file.
00001 // -*- mode: c++; indent-tabs-mode: nil; -*-
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) 2006, 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 
00023 
00024 #ifndef BTK_ATOMS_PDB_ATOM_DECORATOR_HPP
00025 #define BTK_ATOMS_PDB_ATOM_DECORATOR_HPP
00026 
00027 #include <string>
00028 #include <ostream>
00029 
00030 #include <btk/core/atoms/atom.hpp>
00031 #include <btk/core/elements/element_types.hpp>
00032 #include <btk/core/io/default_type_system.hpp>
00033 
00034 namespace BTK {
00035 namespace ATOMS {
00036 
00048 template <typename BaseAtomType = BTK::ATOMS::Atom<> >
00049 class PDBAtomDecorator : public BaseAtomType
00050 {
00051   typedef BaseAtomType base_type;
00052   typedef PDBAtomDecorator<base_type> self_type;
00053  public:
00054   IMPORT_ATOM_TYPES(base_type);
00055   typedef typename chemical_type_system::monomer_id_type monomer_id_type;
00056   
00058 
00059 
00061   PDBAtomDecorator() : 
00062     base_type(), _res_num(1), _res_type(),
00063     _chain_id(' '), _alt_loc(' '), _insert_code(' '),
00064     _occupancy(1), _b_factor(0), _segment_id(), _charge(),
00065     _is_hetatom(false) {}
00066 
00068   PDBAtomDecorator(::BTK::MATH::BTKVector const & pos,
00069                    atom_id_type type,
00070                    element_id_type element_type,
00071                    int number = 0,
00072                    chemical_type_system const & cts = chemical_type_system()) :
00073     base_type(pos,type,element_type,number,cts),
00074     _res_num(1), _res_type(), _chain_id(' '), _alt_loc(' '), 
00075     _insert_code(' '), _occupancy(1), _b_factor(0), _segment_id(), _charge(), 
00076     _is_hetatom(false) {}
00077 
00079     
00081   PDBAtomDecorator(chemical_type_system const & cts,
00082                    bool is_hetatom,
00083                    int atom_number,
00084                    atom_id_type atom_type,
00085                    char alt_loc,
00086                    monomer_id_type res_type,
00087                    char chain_id,
00088                    int res_number,
00089                    char insert_code,
00090                    ::BTK::MATH::BTKVector const & position,
00091                    double occupancy = 1.0,
00092                    double b_factor = 1.0,
00093                    std::string const & segment_id = "",
00094                    element_id_type element_type = element_id_type(), // fix me! 
00095                    std::string charge = "") :
00096     base_type(position,
00097               atom_type,
00098               element_type,
00099               atom_number,
00100               cts),
00101     _res_num(res_number), _res_type(res_type),
00102     _chain_id(chain_id), _alt_loc(alt_loc), _insert_code(insert_code),
00103     _occupancy(occupancy), _b_factor(b_factor),
00104     _segment_id(segment_id), _charge(charge),
00105     _is_hetatom(is_hetatom)
00106   {
00107   }
00108  
00113 
00114 
00117   PDBAtomDecorator(self_type const & src) :
00118     base_type(src), _res_num(src._res_num), _res_type(src._res_type),
00119     _chain_id(src._chain_id), _alt_loc(src._alt_loc),
00120     _insert_code(src._insert_code), _occupancy(src._occupancy),
00121     _b_factor(src._b_factor), _segment_id(src._segment_id),
00122     _charge(src._charge), _is_hetatom(src._is_hetatom) {}
00123     
00126   template <typename AtomType>
00127   PDBAtomDecorator(PDBAtomDecorator<AtomType> const & src) :
00128     base_type(src),
00129     _res_num(src.res_number()), _res_type(),
00130     _chain_id(src.chain_id()), _alt_loc(src.alt_loc()),
00131     _insert_code(src.insert_code()), _occupancy(src.occupancy()),
00132     _b_factor(src.b_factor()), _segment_id(src.segment_id()),
00133     _charge(src.charge()), _is_hetatom(src.is_hetatom()) 
00134   {
00135     // If we're using this constructor, the source atom doesn't have the same
00136     // base atom type as this class.  Thus, there's no guarantee that the 
00137     // monomer_id_type of the source class is the same as the monomer_id_type
00138     // of this class.  For this reason, look up the residue type using the
00139     // source atom's residue name.
00140     typename chemical_type_system::monomer_dictionary::const_iterator i =
00141       base_type::get_chemical_type_system().get_monomer_dictionary().find(src.res_name());
00142     
00143     if (i != base_type::get_chemical_type_system().get_monomer_dictionary().end())
00144       _res_type = i->first;
00145     else
00146       _res_type = BTK::UTILITY::TypeIDTraits<monomer_id_type>::unknown();
00147   }
00149 
00151 
00152   int res_number() const { return _res_num; }
00153   void set_res_number(int num) { _res_num = num; }
00154 
00155   monomer_id_type res_type() const { return _res_type; }
00156   void set_res_type(monomer_id_type type) { _res_type = type; }
00157 
00158   std::string res_name() const
00159   {
00160     typename chemical_type_system::monomer_dictionary::const_iterator i =
00161       base_type::get_chemical_type_system().get_monomer_dictionary().find(_res_type);
00162 
00163     if (i != base_type::get_chemical_type_system().get_monomer_dictionary().end()) 
00164       return i->second;
00165     else 
00166       return "";
00167   }
00168 
00169   char chain_id() const { return _chain_id; }
00170   void set_chain_id(char id) { _chain_id = id; }
00171 
00172   char alt_loc() const { return _alt_loc; }
00173   void set_alt_loc(char altloc) { _alt_loc = altloc; }
00174 
00175   char insert_code() const { return _insert_code; }
00176   void set_insert_code(char code) { _insert_code = code; }
00177 
00178   double occupancy() const { return _occupancy; }
00179   void set_occupancy(double occ) { _occupancy = occ; }
00180 
00181   double b_factor() const { return _b_factor; }
00182   void set_b_factor(double bfactor) { _b_factor = bfactor; }
00183   
00184   std::string const & segment_id() const { return _segment_id; }
00185   void set_segment_id(std::string const & s_id) { _segment_id = s_id; }
00186 
00187   std::string const & charge() const { return _charge; }
00188   void set_charge(std::string const & charge) { _charge = charge; }
00189   
00190   bool is_hetatom() const { return _is_hetatom; }
00191   void set_hetatom_flag(bool h) { _is_hetatom = h; }
00193 
00194   virtual std::ostream & print(std::ostream & os,
00195                                int atom_number,
00196                                int group_number,
00197                                char chain_id,
00198                                std::string const & group_name) const
00199   {
00200     return base_type::print(os,
00201                             atom_number,
00202                             group_number,
00203                             chain_id,
00204                             group_name,
00205                             is_hetatom(),
00206                             alt_loc(),
00207                             insert_code(),
00208                             occupancy(),
00209                             b_factor(),
00210                             segment_id(),
00211                             base_type::element_name(),
00212                             charge());
00213   }
00214 
00215   virtual std::ostream & print(std::ostream & os) const
00216   {
00217     return print(os,
00218                  base_type::number(),
00219                  res_number(),
00220                  chain_id(),
00221                  res_name());
00222   }
00223 
00224   self_type const & operator=(self_type const & rhs)
00225     {
00226       base_type::operator=(rhs);
00227       
00228       _res_num = rhs._res_num;
00229       _res_type = rhs._res_type;
00230       _chain_id = rhs._chain_id;
00231       _alt_loc = rhs._alt_loc;
00232       _insert_code = rhs._insert_code;
00233       _occupancy = rhs._occupancy;
00234       _b_factor = rhs._b_factor;
00235       _segment_id = rhs._segment_id;
00236       _charge = rhs._charge;
00237       _is_hetatom = rhs._is_hetatom;
00238       
00239       return *this;
00240     }
00241   
00242   bool operator==(self_type const & rhs) const 
00243   {
00244     if (base_type::operator!=(rhs)) return false;
00245 
00246     return (_res_num == rhs._res_num &&
00247             _res_type == rhs._res_type &&
00248             _chain_id == rhs._chain_id &&
00249             _alt_loc == rhs._alt_loc &&
00250             _insert_code == rhs._insert_code &&
00251             _occupancy == rhs._occupancy &&
00252             _b_factor == rhs._b_factor &&
00253             _segment_id == rhs._segment_id &&
00254             _charge == rhs._charge &&
00255             _is_hetatom == rhs._is_hetatom);
00256   }
00257 
00258   bool operator!=(self_type const & rhs) const 
00259   {
00260     return !(*this == rhs);
00261   }
00262 
00263  private:
00264   int _res_num;
00265   monomer_id_type _res_type;
00266   char _chain_id, _alt_loc, _insert_code;
00267   double _occupancy, _b_factor;
00268   std::string _segment_id, _charge;
00269   bool _is_hetatom;
00270 };
00271 
00272 template <typename AT>
00273 std::ostream & operator<<(std::ostream & os, 
00274                           PDBAtomDecorator<AT> const & pdb_atom)
00275 {
00276   return pdb_atom.print(os);
00277 }
00278 
00279 } // namespace ATOMS
00280 } // namespace BTK
00281 
00282 #endif // BTK_ATOMS_PDB_ATOM_DECORATOR_HPP

Generated on Sun Jul 15 20:46:26 2007 for BTK Core by  doxygen 1.5.1