00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IMPATOM_CHARMM_TOPOLOGY_H
00009 #define IMPATOM_CHARMM_TOPOLOGY_H
00010
00011 #include "IMP/Object.h"
00012 #include "IMP/container_macros.h"
00013 #include "Hierarchy.h"
00014 #include "Atom.h"
00015 #include "atom_config.h"
00016
00017 #include <string>
00018 #include <vector>
00019
00020 IMPATOM_BEGIN_NAMESPACE
00021
00022
00023
00024
00025
00026
00027
00028 class CHARMMAtomTopology {
00029 std::string name_;
00030 std::string charmm_type_;
00031 double charge_;
00032 public:
00033 CHARMMAtomTopology(std::string name) : name_(name) {};
00034
00035 CHARMMAtomTopology(std::string name, const CHARMMAtomTopology &other)
00036 : name_(name), charmm_type_(other.charmm_type_),
00037 charge_(other.charge_) {};
00038
00039 std::string get_name() const { return name_; }
00040 std::string get_charmm_type() const { return charmm_type_; }
00041 double get_charge() const { return charge_; }
00042 void set_charmm_type(std::string charmm_type) { charmm_type_ = charmm_type; }
00043 void set_charge(double charge) { charge_ = charge; }
00044 };
00045
00046 class CHARMMResidueTopology;
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 class CHARMMBondEndpoint {
00065 std::string atom_name_;
00066 CHARMMResidueTopology *residue_;
00067 public:
00068 CHARMMBondEndpoint(std::string atom_name,
00069 CHARMMResidueTopology *residue=NULL)
00070 : atom_name_(atom_name), residue_(residue) {}
00071
00072 std::string get_atom_name() const { return atom_name_; }
00073
00074
00075 Atom get_atom(const CHARMMResidueTopology *current_residue,
00076 const CHARMMResidueTopology *previous_residue,
00077 const CHARMMResidueTopology *next_residue,
00078 const std::map<const CHARMMResidueTopology *,
00079 Hierarchy> &resmap) const {
00080 if (residue_) {
00081 return IMP::atom::get_atom(resmap.find(residue_)->second.get_as_residue(),
00082 atom_name_);
00083 } else if (atom_name_[0] == '+') {
00084 if (next_residue) {
00085 return IMP::atom::get_atom(resmap.find(next_residue)->second.
00086 get_as_residue(),
00087 atom_name_.substr(1));
00088 } else {
00089 return Atom();
00090 }
00091 } else if (atom_name_[0] == '-') {
00092 if (previous_residue) {
00093 return IMP::atom::get_atom(resmap.find(previous_residue)->second.
00094 get_as_residue(),
00095 atom_name_.substr(1));
00096 } else {
00097 return Atom();
00098 }
00099 } else {
00100 return IMP::atom::get_atom(resmap.find(current_residue)->second.
00101 get_as_residue(),
00102 atom_name_);
00103 }
00104 }
00105 };
00106
00107
00108 template <unsigned int D>
00109 class CHARMMBond
00110 {
00111 std::vector<CHARMMBondEndpoint> endpoints_;
00112 public:
00113 CHARMMBond(std::vector<std::string> atoms) {
00114 IMP_INTERNAL_CHECK(atoms.size() == D, "wrong number of bond endpoints");
00115 for (std::vector<std::string>::const_iterator it = atoms.begin();
00116 it != atoms.end(); ++it) {
00117 endpoints_.push_back(CHARMMBondEndpoint(*it));
00118 }
00119 }
00120
00121 CHARMMBond(std::vector<CHARMMBondEndpoint> endpoints)
00122 : endpoints_(endpoints) {
00123 IMP_INTERNAL_CHECK(endpoints.size() == D, "wrong number of bond endpoints");
00124 }
00125
00126 const CHARMMBondEndpoint & get_endpoint(unsigned int i) const {
00127 return endpoints_[i];
00128 }
00129
00130
00131 bool contains_atom(std::string name) const {
00132 for (std::vector<CHARMMBondEndpoint>::const_iterator
00133 it = endpoints_.begin(); it != endpoints_.end(); ++it) {
00134 if (it->get_atom_name() == name) {
00135 return true;
00136 }
00137 }
00138 return false;
00139 }
00140
00141
00142 Atoms get_atoms(const CHARMMResidueTopology *current_residue,
00143 const CHARMMResidueTopology *previous_residue,
00144 const CHARMMResidueTopology *next_residue,
00145 const std::map<const CHARMMResidueTopology *,
00146 Hierarchy> &resmap) const {
00147 Atoms as;
00148 for (std::vector<CHARMMBondEndpoint>::const_iterator
00149 it = endpoints_.begin(); it != endpoints_.end(); ++it) {
00150 Atom a = it->get_atom(current_residue, previous_residue,
00151 next_residue, resmap);
00152 if (a) {
00153 as.push_back(a);
00154 } else {
00155 return Atoms();
00156 }
00157 }
00158 return as;
00159 }
00160 };
00161
00162
00163 class IMPATOMEXPORT CHARMMResidueTopologyBase {
00164 std::string type_;
00165 protected:
00166 std::vector<CHARMMAtomTopology> atoms_;
00167 std::vector<CHARMMBond<2> > bonds_;
00168 std::vector<CHARMMBond<3> > angles_;
00169 std::vector<CHARMMBond<4> > dihedrals_;
00170 std::vector<CHARMMBond<4> > impropers_;
00171
00172 CHARMMResidueTopologyBase(std::string type) : type_(type) {}
00173 public:
00174 std::string get_type() const { return type_; }
00175
00176 unsigned int get_number_of_atoms() const { return atoms_.size(); }
00177 const CHARMMAtomTopology &get_atom(unsigned int i) const { return atoms_[i]; }
00178
00179 void add_atom(const CHARMMAtomTopology &atom);
00180 CHARMMAtomTopology &get_atom(std::string name);
00181 const CHARMMAtomTopology &get_atom(AtomType type) const {
00182 return get_atom(type.get_string());
00183 }
00184
00185 #ifndef SWIG
00186 const CHARMMAtomTopology &get_atom(std::string name) const;
00187 #endif
00188
00189 unsigned int get_number_of_bonds() const { return bonds_.size(); }
00190 void add_bond(const CHARMMBond<2> &bond) {
00191 bonds_.push_back(bond);
00192 }
00193 CHARMMBond<2> &get_bond(unsigned int index) { return bonds_[index]; }
00194
00195 unsigned int get_number_of_angles() const { return angles_.size(); }
00196 void add_angle(const CHARMMBond<3> &bond) {
00197 angles_.push_back(bond);
00198 }
00199 CHARMMBond<3> &get_angle(unsigned int index) { return angles_[index]; }
00200
00201 unsigned int get_number_of_dihedrals() const { return dihedrals_.size(); }
00202 void add_dihedral(const CHARMMBond<4> &bond) {
00203 dihedrals_.push_back(bond);
00204 }
00205 CHARMMBond<4> &get_dihedral(unsigned int index) { return dihedrals_[index]; }
00206
00207 unsigned int get_number_of_impropers() const { return impropers_.size(); }
00208 void add_improper(const CHARMMBond<4> &bond) {
00209 impropers_.push_back(bond);
00210 }
00211 CHARMMBond<4> &get_improper(unsigned int index) { return impropers_[index]; }
00212
00213 #ifndef SWIG
00214 const CHARMMBond<2> &get_bond(unsigned int index) const {
00215 return bonds_[index];
00216 }
00217 const CHARMMBond<3> &get_angle(unsigned int index) const {
00218 return angles_[index];
00219 }
00220 const CHARMMBond<4> &get_dihedral(unsigned int index) const {
00221 return dihedrals_[index];
00222 }
00223 const CHARMMBond<4> &get_improper(unsigned int index) const {
00224 return impropers_[index];
00225 }
00226 #endif
00227 };
00228
00229
00230 class IMPATOMEXPORT CHARMMIdealResidueTopology
00231 : public CHARMMResidueTopologyBase {
00232 std::string default_first_patch_, default_last_patch_;
00233 public:
00234 CHARMMIdealResidueTopology(ResidueType type)
00235 : CHARMMResidueTopologyBase(type.get_string()) {}
00236
00237
00238
00239
00240 void delete_atom(std::string name);
00241
00242 void set_default_first_patch(std::string patch) {
00243 default_first_patch_ = patch;
00244 }
00245 void set_default_last_patch(std::string patch) {
00246 default_last_patch_ = patch;
00247 }
00248 std::string get_default_first_patch() const { return default_first_patch_; }
00249 std::string get_default_last_patch() const { return default_last_patch_; }
00250 };
00251
00252 class CHARMMResidueTopology;
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 class IMPATOMEXPORT CHARMMPatch : public CHARMMResidueTopologyBase {
00263 std::vector<std::string> deleted_atoms_;
00264 public:
00265 CHARMMPatch(std::string type) : CHARMMResidueTopologyBase(type) {}
00266
00267 void add_deleted_atom(std::string name) { deleted_atoms_.push_back(name); }
00268
00269
00270
00271
00272
00273
00274
00275
00276 void apply(CHARMMResidueTopology &res) const;
00277
00278
00279
00280
00281
00282
00283
00284
00285 void apply(CHARMMResidueTopology &res1, CHARMMResidueTopology &res2) const;
00286 };
00287
00288
00289 class IMPATOMEXPORT CHARMMResidueTopology
00290 : public CHARMMIdealResidueTopology, public Object {
00291 bool patched_;
00292 public:
00293
00294
00295 CHARMMResidueTopology(ResidueType type)
00296 : CHARMMIdealResidueTopology(type), patched_(false) {}
00297
00298
00299 CHARMMResidueTopology(const CHARMMIdealResidueTopology &ideal)
00300 : CHARMMIdealResidueTopology(ideal), patched_(false) {}
00301
00302 bool get_patched() const { return patched_; }
00303 void set_patched(bool patched) { patched_ = patched; }
00304
00305 IMP_OBJECT(CHARMMResidueTopology);
00306 };
00307
00308 IMP_OBJECTS(CHARMMResidueTopology);
00309
00310 class CHARMMParameters;
00311
00312
00313
00314
00315 class IMPATOMEXPORT CHARMMSegmentTopology : public Object {
00316 IMP_LIST(public, CHARMMResidueTopology, residue, CHARMMResidueTopology*,
00317 CHARMMResidueTopologys);
00318
00319 IMP_OBJECT(CHARMMSegmentTopology);
00320 public:
00321
00322
00323
00324
00325
00326 void apply_default_patches(const CHARMMParameters *ff);
00327 };
00328
00329 IMP_OBJECTS(CHARMMSegmentTopology);
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 class IMPATOMEXPORT CHARMMTopology : public Object {
00356 IMP_LIST(public, CHARMMSegmentTopology, segment, CHARMMSegmentTopology*,
00357 CHARMMSegmentTopologys);
00358
00359 IMP_OBJECT(CHARMMTopology);
00360 private:
00361 WarningContext warn_context_;
00362 typedef std::map<const CHARMMResidueTopology *, Hierarchy> ResMap;
00363
00364 void map_residue_topology_to_hierarchy(Hierarchy hierarchy,
00365 ResMap &resmap) const;
00366 public:
00367
00368 void apply_default_patches(const CHARMMParameters *ff) {
00369 for (unsigned int i = 0; i < get_number_of_segments(); ++i) {
00370 get_segment(i)->apply_default_patches(ff);
00371 }
00372 }
00373
00374
00375
00376
00377
00378
00379 Hierarchy create_hierarchy(Model *model) const;
00380
00381
00382
00383
00384
00385 void add_atom_types(Hierarchy hierarchy) const;
00386
00387
00388
00389
00390
00391 void add_charges(Hierarchy hierarchy) const;
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415 Particles add_bonds(Hierarchy hierarchy, const CHARMMParameters *ff) const;
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 Particles add_impropers(Hierarchy hierarchy,
00428 const CHARMMParameters *ff) const;
00429 };
00430
00431 IMPATOM_END_NAMESPACE
00432
00433 #endif