00001
00007
00008
00009
00010
00011
00012
00013 #ifndef PARAM_H
00014
00015 #define PARAM_H
00016
00017 #include "parm.h"
00018
00019 #include "common.h"
00020 #include "structures.h"
00021 #include "strlib.h"
00022 #include "MStream.h"
00023
00024 #include "SimParameters.h"
00025
00026
00027 #include "GromacsTopFile.h"
00028
00029 #ifndef cbrt
00030
00031 #define cbrt(x) pow((double)x,(double)(1.0/3.0))
00032 #endif
00033
00034 class Communicate;
00035 class StringList;
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #define MAX_MULTIPLICITY 6
00069
00070
00071 #define MAX_ATOMTYPE_CHARS 6
00072
00073
00074
00075
00076 #define paraXplor 0
00077 #define paraCharmm 1
00078
00079
00080
00081 class BondValue {
00082 public:
00083 Real k;
00084 Real x0;
00085 };
00086
00087 class AngleValue {
00088 public:
00089 Real k;
00090 Real theta0;
00091 Real k_ub;
00092 Real r_ub;
00093 int normal;
00094 };
00095
00096 typedef struct four_body_consts
00097 {
00098 Real k;
00099 int n;
00100 Real delta;
00101 } FourBodyConsts;
00102
00103 class DihedralValue {
00104 public:
00105 int multiplicity;
00106 FourBodyConsts values[MAX_MULTIPLICITY];
00107 };
00108
00109 class ImproperValue {
00110 public:
00111 int multiplicity;
00112 FourBodyConsts values[MAX_MULTIPLICITY];
00113 };
00114
00115 struct CrosstermData { BigReal d00,d01,d10,d11; };
00116
00117 class CrosstermValue {
00118 public:
00119 enum {dim=25};
00120 CrosstermData c[dim][dim];
00121 };
00122
00123 class NonbondedExclValue {
00124 public:
00125
00126
00127 Real k;
00128 Real x0;
00129 };
00130
00131 typedef struct vdw_val
00132 {
00133 Real sigma;
00134 Real epsilon;
00135 Real sigma14;
00136 Real epsilon14;
00137 } VdwValue;
00138
00139
00140
00141
00142
00143 typedef struct indexed_vdw_pair
00144 {
00145 Index ind1;
00146 Index ind2;
00147 Real A;
00148 Real A14;
00149 Real B;
00150 Real B14;
00151 struct indexed_vdw_pair *right;
00152 struct indexed_vdw_pair *left;
00153 } IndexedVdwPair;
00154
00155
00156
00157
00158
00159
00160 typedef struct indexed_table_pair
00161 {
00162 Index ind1;
00163 Index ind2;
00164 int K;
00165 struct indexed_table_pair *right;
00166 struct indexed_table_pair *left;
00167 } IndexedTablePair;
00168
00169
00170 struct bond_params;
00171 struct angle_params;
00172 struct improper_params;
00173 struct dihedral_params;
00174 struct crossterm_params;
00175 struct vdw_params;
00176 struct vdw_pair_params;
00177 struct table_pair_params;
00178
00179 class Parameters
00180 {
00181 private:
00182 void initialize();
00183
00184 char *atomTypeNames;
00185 Bool AllFilesRead;
00186
00187
00188
00189
00190
00191 int paramType;
00192
00193 bool cosAngles;
00194 struct bond_params *bondp;
00195 struct angle_params *anglep;
00196 struct improper_params *improperp;
00197 struct dihedral_params *dihedralp;
00198 struct crossterm_params *crosstermp;
00199 struct vdw_params *vdwp;
00200 struct vdw_pair_params *vdw_pairp;
00201 struct table_pair_params *table_pairp;
00202 public:
00203 BondValue *bond_array;
00204 AngleValue *angle_array;
00205 DihedralValue *dihedral_array;
00206 ImproperValue *improper_array;
00207 CrosstermValue *crossterm_array;
00208 VdwValue *vdw_array;
00209 int numenerentries;
00210 int rowsize;
00211 int columnsize;
00212 BigReal* table_ener;
00213 IndexedVdwPair *vdw_pair_tree;
00214 IndexedTablePair *tab_pair_tree;
00215 int tablenumtypes;
00216 int NumBondParams;
00217 int NumAngleParams;
00218 int NumCosAngles;
00219 int NumDihedralParams;
00220 int NumImproperParams;
00221 int NumCrosstermParams;
00222 int NumVdwParams;
00223 int NumTableParams;
00224 int NumVdwParamsAssigned;
00225 int NumVdwPairParams;
00226 int NumTablePairParams;
00227 private:
00228 ResizeArray<char *> error_msgs;
00229
00230 int *maxDihedralMults;
00231
00232 int *maxImproperMults;
00233
00234
00235 void skip_stream_read(char *, FILE *);
00236
00237 void add_bond_param(char *);
00238 struct bond_params *add_to_bond_tree(struct bond_params * ,
00239 struct bond_params *);
00240
00241 void add_angle_param(char *);
00242 struct angle_params *add_to_angle_tree(struct angle_params * ,
00243 struct angle_params *);
00244
00245 void add_dihedral_param(char *, FILE *);
00246 void add_to_dihedral_list(struct dihedral_params *);
00247 void add_to_charmm_dihedral_list(struct dihedral_params *);
00248
00249 void add_improper_param(char *, FILE *);
00250 void add_to_improper_list(struct improper_params *);
00251
00252 void add_crossterm_param(char *, FILE *);
00253 void add_to_crossterm_list(struct crossterm_params *);
00254
00255 void add_vdw_param(char *);
00256 struct vdw_params *add_to_vdw_tree(struct vdw_params *,
00257 struct vdw_params *);
00258
00259 void add_vdw_pair_param(char *);
00260 void add_table_pair_param(char *);
00261 void add_to_vdw_pair_list(struct vdw_pair_params *);
00262 void add_to_table_pair_list(struct table_pair_params *);
00263
00264 void add_hb_pair_param(char *);
00265
00266
00267
00268 void traverse_vdw_pair_params(struct vdw_pair_params *);
00269 void traverse_vdw_params(struct vdw_params *);
00270 void traverse_dihedral_params(struct dihedral_params *);
00271 void traverse_improper_params(struct improper_params *);
00272 void traverse_crossterm_params(struct crossterm_params *);
00273 void traverse_angle_params(struct angle_params *);
00274 void traverse_bond_params(struct bond_params *);
00275
00276
00277
00278
00279 Index index_bonds(struct bond_params *, Index);
00280 Index index_angles(struct angle_params *, Index);
00281 Index index_vdw(struct vdw_params *, Index);
00282 void index_dihedrals();
00283 void index_impropers();
00284 void index_crossterms();
00285
00286 void convert_vdw_pairs();
00287 void convert_table_pairs();
00288 IndexedVdwPair *add_to_indexed_vdw_pairs(IndexedVdwPair *, IndexedVdwPair *);
00289 IndexedTablePair *add_to_indexed_table_pairs(IndexedTablePair *, IndexedTablePair *);
00290
00291 int vdw_pair_to_arrays(int *, int *, Real *, Real *, Real *, Real *,
00292 int, IndexedVdwPair *);
00293
00294 int table_pair_to_arrays(int *, int *, int *, int, IndexedTablePair *);
00295
00296
00297
00298 void free_bond_tree(struct bond_params *);
00299 void free_angle_tree(struct angle_params *);
00300 void free_dihedral_list(struct dihedral_params *);
00301 void free_improper_list(struct improper_params *);
00302 void free_crossterm_list(struct crossterm_params *);
00303 void free_vdw_tree(struct vdw_params *);
00304 void free_vdw_pair_tree(IndexedVdwPair *);
00305 void free_table_pair_tree(IndexedTablePair *);
00306 void free_vdw_pair_list();
00307
00308 BigReal interp_lin(BigReal, BigReal, BigReal, BigReal, BigReal);
00309
00310
00311
00312 void read_parm(const GromacsTopFile *, Bool min);
00313 public:
00314
00316 Parameters();
00317 Parameters(SimParameters *, StringList *f);
00318
00319
00320 Parameters(Ambertoppar *, BigReal);
00321 void read_parm(Ambertoppar *, BigReal);
00322
00323
00324
00325
00326
00327
00328 Parameters(const GromacsTopFile *gf, Bool min);
00329
00330 ~Parameters();
00331
00332
00333
00334
00335
00336 char *atom_type_name(Index a) {
00337 return (atomTypeNames + (a * (MAX_ATOMTYPE_CHARS + 1)));
00338 }
00339
00340
00341 void read_parameter_file(char *);
00342
00343
00344 void read_charmm_parameter_file(char *);
00345
00346
00347
00348
00349 void done_reading_files();
00350
00351
00352
00353 void done_reading_structure();
00354
00355
00356
00357
00358
00359 #ifdef MEM_OPT_VERSION
00360 void assign_vdw_index(char *, AtomCstInfo *);
00361 #else
00362 void assign_vdw_index(char *, Atom *);
00363 #endif
00364
00365 void assign_bond_index(char *, char *, Bond *);
00366
00367
00368 void assign_angle_index(char *, char *, char *, Angle *);
00369
00370
00371 void assign_dihedral_index(char *, char*, char*, char *, Dihedral *, int);
00372
00373
00374 void assign_improper_index(char *, char*, char*, char *, Improper *, int);
00375
00376
00377 void assign_crossterm_index(char *, char*, char*, char *, char *, char*, char*, char *, Crossterm *);
00378
00379
00380
00381 void send_Parameters(MOStream *);
00382
00383
00384
00385 void receive_Parameters(MIStream *);
00386
00387
00388
00389
00390 void get_bond_params(Real *k, Real *x0, Index index)
00391 {
00392 *k = bond_array[index].k;
00393 *x0 = bond_array[index].x0;
00394 }
00395
00396 void get_angle_params(Real *k, Real *theta0, Real *k_ub, Real *r_ub,
00397 Index index)
00398 {
00399 *k = angle_array[index].k;
00400 *theta0 = angle_array[index].theta0;
00401 *k_ub = angle_array[index].k_ub;
00402 *r_ub = angle_array[index].r_ub;
00403 }
00404
00405 int get_improper_multiplicity(Index index)
00406 {
00407 return(improper_array[index].multiplicity);
00408 }
00409
00410 int get_dihedral_multiplicity(Index index)
00411 {
00412 return(dihedral_array[index].multiplicity);
00413 }
00414
00415 void get_improper_params(Real *k, int *n, Real *delta,
00416 Index index, int mult)
00417 {
00418 if ( (mult<0) || (mult>MAX_MULTIPLICITY) )
00419 {
00420 NAMD_die("Bad mult index in Parameters::get_improper_params");
00421 }
00422
00423 *k = improper_array[index].values[mult].k;
00424 *n = improper_array[index].values[mult].n;
00425 *delta = improper_array[index].values[mult].delta;
00426 }
00427
00428 void get_dihedral_params(Real *k, int *n, Real *delta,
00429 Index index, int mult)
00430 {
00431 if ( (mult<0) || (mult>MAX_MULTIPLICITY) )
00432 {
00433 NAMD_die("Bad mult index in Parameters::get_dihedral_params");
00434 }
00435
00436 *k = dihedral_array[index].values[mult].k;
00437 *n = dihedral_array[index].values[mult].n;
00438 *delta = dihedral_array[index].values[mult].delta;
00439 }
00440
00441 void get_vdw_params(Real *sigma, Real *epsilon, Real *sigma14,
00442 Real *epsilon14, Index index)
00443 {
00444 if ( vdw_array ) {
00445 *sigma = vdw_array[index].sigma;
00446 *epsilon = vdw_array[index].epsilon;
00447 *sigma14 = vdw_array[index].sigma14;
00448 *epsilon14 = vdw_array[index].epsilon14;
00449 } else {
00450
00451 Real A; Real B; Real A14; Real B14;
00452 if (get_vdw_pair_params(index, index, &A, &B, &A14, &B14) ) {
00453 if (A && B) {
00454 *sigma = sqrt(cbrt(A)) / sqrt(cbrt(B));
00455 *epsilon = B*B / (4*A);
00456 }
00457 else {
00458 *sigma = 0; *epsilon = 0;
00459 }
00460 if (A14 && B14) {
00461 *sigma14 = sqrt(cbrt(A14)) / sqrt(cbrt(B14));
00462 *epsilon14 = B14*B14 / (4*A14);
00463 }
00464 else {
00465 *sigma14 = 0; *epsilon14 = 0;
00466 }
00467 }
00468 else {NAMD_die ("Function get_vdw_params failed to derive Lennard-Jones sigma and epsilon from A and B values\n");}
00469 }
00470 }
00471
00472 int get_vdw_pair_params(Index ind1, Index ind2, Real *, Real *, Real *, Real *);
00473
00474
00475 int get_num_vdw_params(void) { return NumVdwParamsAssigned; }
00476
00477 int get_table_pair_params(Index, Index, int*);
00478
00479
00480 void print_bond_params();
00481 void print_angle_params();
00482 void print_dihedral_params();
00483 void print_improper_params();
00484 void print_crossterm_params();
00485 void print_vdw_params();
00486 void print_vdw_pair_params();
00487 void print_param_summary();
00488 void read_ener_table(SimParameters*);
00489 int get_int_table_type(char*);
00490
00491 int read_energy_type(FILE*, const int, BigReal*, const float, const float);
00492 int read_energy_type_cubspline(FILE*, const int, BigReal*, const float, const float);
00493 int read_energy_type_bothcubspline(FILE*, const int, BigReal*, const float, const float);
00494 };
00495
00496 #endif
00497