00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00023
00024 #ifndef BTK_ATOMS_ATOM_HPP
00025 #define BTK_ATOMS_ATOM_HPP
00026
00027 #include <string>
00028 #include <ostream>
00029 #include <cstdio>
00030
00031 #include <btk/core/math/btk_vector.hpp>
00032 #include <btk/core/io/default_type_system.hpp>
00033 #include <btk/core/utility/chemically_typed_object.hpp>
00034
00035 namespace BTK {
00036 namespace ATOMS {
00037
00053 template <typename TS = BTK::IO::DefaultTypeSystem>
00054 class Atom :
00055 public BTK::UTILITY::ChemicallyTypedObject<TS,typename TS::atom_dictionary>
00056 {
00057 typedef Atom<TS> self_type;
00058 typedef BTK::UTILITY::
00059 ChemicallyTypedObject<TS,typename TS::atom_dictionary> base_type;
00060
00061 public:
00063
00064
00065 typedef TS chemical_type_system;
00067 typedef typename base_type::dictionary dictionary;
00069 typedef typename base_type::id_type id_type;
00071
00073 typedef typename base_type::dictionary atom_dictionary;
00075 typedef id_type atom_id_type;
00076
00078 typedef typename chemical_type_system::element_dictionary element_dictionary;
00080 typedef typename chemical_type_system::element_id_type element_id_type;
00081
00083 Atom() : base_type(), _pos(),_number(0), _element_type(), _selected(false) {}
00084
00091 Atom(BTK::MATH::BTKVector const & pos,
00092 atom_id_type type,
00093 element_id_type etype,
00094 int number = 0,
00095 chemical_type_system const & ts = chemical_type_system()) :
00096 base_type(ts,type),
00097 _pos(pos), _number(number), _element_type(etype), _selected(false) {}
00098
00100 Atom(self_type const & src) :
00101 base_type(src), _pos(src._pos), _number(src._number),
00102 _element_type(src._element_type), _selected(src._selected) {}
00103
00104 virtual ~Atom() {};
00105
00106 using base_type::set_type;
00107 using base_type::set_chemical_type_system;
00108
00109 virtual dictionary const & get_dictionary() const
00110 {
00111 return base_type::get_chemical_type_system().get_atom_dictionary();
00112 }
00113
00114 virtual dictionary & get_dictionary()
00115 {
00116 return base_type::get_chemical_type_system().get_atom_dictionary();
00117 }
00118
00120 element_id_type element_type() const { return _element_type; }
00121
00123 void set_element_type(element_id_type et) { _element_type = et; }
00124
00126 std::string element_name() const
00127 {
00128 typename element_dictionary::const_iterator i =
00129 base_type::get_chemical_type_system().
00130 get_element_dictionary().find(_element_type);
00131
00132 if (i != base_type::
00133 get_chemical_type_system().get_element_dictionary().end())
00134 return i->second;
00135 else
00136 return "";
00137 }
00138
00140 int number() const { return _number; }
00142 void set_number(int number) { _number = number; }
00143
00145 BTK::MATH::BTKVector const & position() const {return _pos;}
00147 void set_position(BTK::MATH::BTKVector const & position) {_pos = position;}
00148
00150 bool selected() const { return _selected; }
00152 void select(bool s = true) const { _selected = s; }
00153
00161 virtual std::ostream & print(std::ostream & os,
00162 int atom_number = 1,
00163 int group_number = 1,
00164 char chain_id = ' ',
00165 std::string const & group_name = "",
00166 bool is_hetatom = false,
00167 char alt_loc = ' ',
00168 char i_code = ' ',
00169 double occupancy = 1.0,
00170 double b_factor = 1.0,
00171 std::string const & seg_id = "",
00172 std::string const & element_name = "",
00173 std::string const & charge = "") const
00174 {
00175 char buf[81];
00176 const char * leading_int_atom_format =
00177 "%-6.6s%5d %-4.4s%c%3.3s %c%4d%c %8.3f%8.3f%8.3f%6.2f%6.2f %4.4s%2.2s%2.2s";
00178 const char * leading_char_atom_format =
00179 "%-6.6s%5d %-3.3s%c%3.3s %c%4d%c %8.3f%8.3f%8.3f%6.2f%6.2f %4.4s%2.2s%2.2s";
00180 const char * format = leading_char_atom_format;
00181
00182 const char * record_type;
00183
00184 if (is_hetatom) record_type = "HETATM";
00185 else record_type = "ATOM";
00186
00187 std::string el_name(element_name);
00188
00189 if (el_name == "") {
00190 el_name = Atom::element_name();
00191 }
00192
00193 std::string atom_name = Atom::name();
00194
00195 if (atom_name.size() && isdigit(atom_name[0])) {
00196 format = leading_int_atom_format;
00197 }
00198
00199 snprintf(buf,81,format,
00200 record_type,
00201 atom_number,
00202 atom_name.c_str(),
00203 alt_loc,
00204 group_name.c_str(),
00205 chain_id,
00206 group_number,
00207 i_code,
00208 position()[0],
00209 position()[1],
00210 position()[2],
00211 occupancy,
00212 b_factor,
00213 seg_id.c_str(),
00214 el_name.c_str(),
00215 charge.c_str());
00216
00217 os << buf << std::endl;
00218
00219 return os;
00220 }
00221
00225 self_type const & operator=(self_type const & src)
00226 {
00227 if (this == &src) return *this;
00228
00229 base_type::operator=(src);
00230 _pos = src._pos;
00231 _number = src._number;
00232 _element_type = src._element_type;
00233 _selected = src._selected;
00234 return *this;
00235 }
00236
00239 bool operator==(self_type const & rhs) const
00240 {
00241 return (_element_type == rhs._element_type &&
00242 _number == rhs._number &&
00243 _pos == rhs._pos &&
00244 base_type::operator==(rhs));
00245 }
00246
00248 bool operator!=(self_type const & rhs) const
00249 {
00250 return !(*this == rhs);
00251 }
00252
00253 private:
00254 MATH::BTKVector _pos;
00255 int _number;
00256 element_id_type _element_type;
00257
00258 mutable bool _selected;
00259 };
00260
00261 template <typename TS>
00262 std::ostream & operator<<(std::ostream & os, Atom<TS> const & a)
00263 {
00264 return a.print(os);
00265 }
00266
00267 #define IMPORT_ATOM_TYPES(AT) \
00268 typedef typename AT::chemical_type_system chemical_type_system; \
00269 typedef typename AT::dictionary dictionary; \
00270 typedef typename AT::id_type id_type; \
00271 typedef typename AT::atom_dictionary atom_dictionary; \
00272 typedef typename AT::element_dictionary element_dictionary; \
00273 typedef typename AT::atom_id_type atom_id_type; \
00274 typedef typename AT::element_id_type element_id_type;
00275
00276 }
00277 }
00278
00279 #endif // BTK_ATOMS_ATOM_HPP