00001
00002
00003
00004
00005
00006
00007 #ifndef IMPATOM_CHARMM_PARAMETERS_H
00008 #define IMPATOM_CHARMM_PARAMETERS_H
00009
00010 #include "internal/charmm_helpers.h"
00011 #include "ForceFieldParameters.h"
00012 #include "charmm_topology.h"
00013 #include "atom_macros.h"
00014
00015 #include <string>
00016 #include <fstream>
00017
00018
00019 IMP_BEGIN_NAMESPACE
00020 class VersionInfo;
00021 IMP_END_NAMESPACE
00022
00023 IMPATOM_BEGIN_NAMESPACE
00024
00025
00026 struct CHARMMBondParameters {
00027 double force_constant;
00028 double ideal;
00029 };
00030
00031
00032 struct CHARMMDihedralParameters {
00033 double force_constant;
00034 int multiplicity;
00035 double ideal;
00036 };
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 class IMPATOMEXPORT CHARMMParameters : public ForceFieldParameters {
00054 std::map<std::string, CHARMMIdealResidueTopology> residue_topologies_;
00055 std::map<std::string, CHARMMPatch> patches_;
00056 std::map<internal::CHARMMBondNames, CHARMMBondParameters> bond_parameters_;
00057 std::map<internal::CHARMMAngleNames, CHARMMBondParameters> angle_parameters_;
00058
00059 typedef std::vector<std::pair<internal::CHARMMDihedralNames,
00060 CHARMMDihedralParameters> > DihedralParameters;
00061 DihedralParameters dihedral_parameters_;
00062 DihedralParameters improper_parameters_;
00063
00064 DihedralParameters::const_iterator
00065 find_dihedral(DihedralParameters::const_iterator begin,
00066 DihedralParameters::const_iterator end,
00067 const internal::CHARMMDihedralNames &dihedral,
00068 bool allow_wildcards) const;
00069
00070 public:
00071
00072
00073
00074
00075
00076 CHARMMParameters(const String& topology_file_name,
00077 const String& par_file_name = std::string());
00078
00079
00080
00081
00082
00083
00084
00085 void add_residue_topology(CHARMMIdealResidueTopology &res) {
00086 residue_topologies_.insert(std::make_pair(res.get_type(), res));
00087 }
00088
00089 CHARMMIdealResidueTopology &get_residue_topology(ResidueType type) {
00090 std::map<std::string, CHARMMIdealResidueTopology>::iterator it
00091 = residue_topologies_.find(type.get_string());
00092 if (it != residue_topologies_.end()) {
00093 return it->second;
00094 } else {
00095 IMP_THROW("Residue " << type << " does not exist", ValueException);
00096 }
00097 }
00098
00099 #ifndef SWIG
00100 const CHARMMIdealResidueTopology &get_residue_topology(std::string name) const
00101 {
00102 std::map<std::string, CHARMMIdealResidueTopology>::const_iterator it
00103 = residue_topologies_.find(name);
00104 if (it != residue_topologies_.end()) {
00105 return it->second;
00106 } else {
00107 IMP_THROW("Residue " << name << " does not exist", ValueException);
00108 }
00109 }
00110 #endif
00111
00112
00113
00114
00115
00116
00117
00118 void add_patch(CHARMMPatch &patch) {
00119 patches_.insert(std::make_pair(patch.get_type(), patch));
00120 }
00121
00122 CHARMMPatch &get_patch(std::string name) {
00123 std::map<std::string, CHARMMPatch>::iterator it = patches_.find(name);
00124 if (it != patches_.end()) {
00125 return it->second;
00126 } else {
00127 IMP_THROW("Patch " << name << " does not exist", ValueException);
00128 }
00129 }
00130
00131 #ifndef SWIG
00132 const CHARMMPatch &get_patch(std::string name) const {
00133 std::map<std::string, CHARMMPatch>::const_iterator it = patches_.find(name);
00134 if (it != patches_.end()) {
00135 return it->second;
00136 } else {
00137 IMP_THROW("Patch " << name << " does not exist", ValueException);
00138 }
00139 }
00140 #endif
00141
00142
00143
00144 CHARMMTopology *create_topology(Hierarchy hierarchy) const;
00145
00146
00147
00148
00149
00150 const CHARMMBondParameters *get_bond_parameters(std::string type1,
00151 std::string type2) const {
00152 internal::CHARMMBondNames types = internal::CHARMMBondNames(type1, type2);
00153 if (bond_parameters_.find(types) != bond_parameters_.end()) {
00154 return &bond_parameters_.find(types)->second;
00155 } else {
00156 return NULL;
00157 }
00158 }
00159
00160
00161
00162
00163
00164 const CHARMMBondParameters *get_angle_parameters(std::string type1,
00165 std::string type2,
00166 std::string type3) const {
00167 internal::CHARMMAngleNames types = internal::CHARMMAngleNames(type1, type2,
00168 type3);
00169 if (angle_parameters_.find(types) != angle_parameters_.end()) {
00170 return &angle_parameters_.find(types)->second;
00171 } else {
00172 return NULL;
00173 }
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 std::vector<CHARMMDihedralParameters> get_dihedral_parameters(
00188 std::string type1, std::string type2, std::string type3,
00189 std::string type4) const {
00190 std::vector<CHARMMDihedralParameters> param;
00191 internal::CHARMMDihedralNames types = internal::CHARMMDihedralNames(
00192 type1, type2, type3, type4);
00193
00194 DihedralParameters::const_iterator match =
00195 find_dihedral(dihedral_parameters_.begin(),
00196 dihedral_parameters_.end(), types, true);
00197 if (match != dihedral_parameters_.end()) {
00198
00199
00200 param.push_back(match->second);
00201 while ((match = find_dihedral(match + 1, dihedral_parameters_.end(),
00202 match->first, false))
00203 != dihedral_parameters_.end()) {
00204 param.push_back(match->second);
00205 }
00206 }
00207 return param;
00208 }
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 const CHARMMDihedralParameters *get_improper_parameters(
00219 std::string type1, std::string type2, std::string type3,
00220 std::string type4) const {
00221 internal::CHARMMDihedralNames types = internal::CHARMMDihedralNames(
00222 type1, type2, type3, type4);
00223
00224 DihedralParameters::const_iterator it =
00225 find_dihedral(improper_parameters_.begin(),
00226 improper_parameters_.end(), types, true);
00227 if (it != improper_parameters_.end()) {
00228 return &it->second;
00229 } else {
00230 return NULL;
00231 }
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 Particles generate_angles(Particles bonds) const;
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264 Particles generate_dihedrals(Particles bonds) const;
00265
00266 IMP_FORCE_FIELD_PARAMETERS(CHARMMParameters);
00267 private:
00268
00269 virtual String get_force_field_atom_type(Atom atom) const;
00270
00271 void read_parameter_file(std::ifstream& input_file);
00272
00273 void read_topology_file(std::ifstream& input_file);
00274
00275 void add_angle(Particle *p1, Particle *p2, Particle *p3, Particles &ps) const;
00276 void add_dihedral(Particle *p1, Particle *p2, Particle *p3, Particle *p4,
00277 Particles &ps) const;
00278
00279 ResidueType parse_residue_line(const String& line);
00280 void parse_atom_line(const String& line, ResidueType curr_res_type,
00281 CHARMMResidueTopologyBase &residue);
00282 void parse_bond_line(const String& line, ResidueType curr_res_type,
00283 CHARMMResidueTopologyBase &residue);
00284
00285 void parse_nonbonded_parameters_line(String line);
00286 void parse_bonds_parameters_line(String line);
00287 void parse_angles_parameters_line(String line);
00288 void parse_dihedrals_parameters_line(String line,
00289 DihedralParameters ¶m);
00290 WarningContext warn_context_;
00291 };
00292
00293 IMPATOM_END_NAMESPACE
00294
00295 #endif