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 typedef struct indexed_nbthole_pair
00156 {
00157 Index ind1;
00158 Index ind2;
00159 Real alphai;
00160 Real alphaj;
00161 Real tholeij;
00162 struct indexed_nbthole_pair *right;
00163 struct indexed_nbthole_pair *left;
00164 } IndexedNbtholePair;
00165
00166 typedef struct nbthole_pair_value
00167 {
00168 Index ind1;
00169 Index ind2;
00170 Real alphai;
00171 Real alphaj;
00172 Real tholeij;
00173 } NbtholePairValue;
00174
00175
00176
00177
00178
00179 typedef struct indexed_table_pair
00180 {
00181 Index ind1;
00182 Index ind2;
00183 int K;
00184 struct indexed_table_pair *right;
00185 struct indexed_table_pair *left;
00186 } IndexedTablePair;
00187
00188
00189 struct bond_params;
00190 struct angle_params;
00191 struct improper_params;
00192 struct dihedral_params;
00193 struct crossterm_params;
00194 struct vdw_params;
00195 struct vdw_pair_params;
00196 struct nbthole_pair_params;
00197 struct table_pair_params;
00198
00199 class Parameters
00200 {
00201 private:
00202 void initialize();
00203
00204 char *atomTypeNames;
00205 Bool AllFilesRead;
00206
00207
00208
00209
00210
00211 int paramType;
00212
00213 bool cosAngles;
00214 struct bond_params *bondp;
00215 struct angle_params *anglep;
00216 struct improper_params *improperp;
00217 struct dihedral_params *dihedralp;
00218 struct crossterm_params *crosstermp;
00219 struct vdw_params *vdwp;
00220 struct vdw_pair_params *vdw_pairp;
00221 struct nbthole_pair_params *nbthole_pairp;
00222 struct table_pair_params *table_pairp;
00223 public:
00224 BondValue *bond_array;
00225 AngleValue *angle_array;
00226 DihedralValue *dihedral_array;
00227 ImproperValue *improper_array;
00228 CrosstermValue *crossterm_array;
00229 VdwValue *vdw_array;
00230 NbtholePairValue *nbthole_array;
00231 int numenerentries;
00232 int rowsize;
00233 int columnsize;
00234 BigReal* table_ener;
00235 IndexedVdwPair *vdw_pair_tree;
00236 IndexedNbtholePair *nbthole_pair_tree;
00237 IndexedTablePair *tab_pair_tree;
00238 int tablenumtypes;
00239 int NumBondParams;
00240 int NumAngleParams;
00241 int NumCosAngles;
00242 int NumDihedralParams;
00243 int NumImproperParams;
00244 int NumCrosstermParams;
00245 int NumVdwParams;
00246 int NumTableParams;
00247 int NumVdwParamsAssigned;
00248 int NumVdwPairParams;
00249 int NumNbtholePairParams;
00250 int NumTablePairParams;
00251 private:
00252 ResizeArray<char *> error_msgs;
00253
00254 int *maxDihedralMults;
00255
00256 int *maxImproperMults;
00257
00258
00259 void skip_stream_read(char *, FILE *);
00260
00261 void add_bond_param(char *);
00262 struct bond_params *add_to_bond_tree(struct bond_params * ,
00263 struct bond_params *);
00264
00265 void add_angle_param(char *);
00266 struct angle_params *add_to_angle_tree(struct angle_params * ,
00267 struct angle_params *);
00268
00269 void add_dihedral_param(char *, FILE *);
00270 void add_to_dihedral_list(struct dihedral_params *);
00271 void add_to_charmm_dihedral_list(struct dihedral_params *);
00272
00273 void add_improper_param(char *, FILE *);
00274 void add_to_improper_list(struct improper_params *);
00275
00276 void add_crossterm_param(char *, FILE *);
00277 void add_to_crossterm_list(struct crossterm_params *);
00278
00279 void add_vdw_param(char *);
00280 struct vdw_params *add_to_vdw_tree(struct vdw_params *,
00281 struct vdw_params *);
00282
00283 void add_vdw_pair_param(char *);
00284 void add_nbthole_pair_param(char *);
00285 void add_table_pair_param(char *);
00286 void add_to_vdw_pair_list(struct vdw_pair_params *);
00287 void add_to_nbthole_pair_list(struct nbthole_pair_params *);
00288 void add_to_table_pair_list(struct table_pair_params *);
00289
00290 void add_hb_pair_param(char *);
00291
00292
00293
00294 void traverse_vdw_pair_params(struct vdw_pair_params *);
00295 void traverse_nbthole_pair_params(struct nbthole_pair_params *);
00296 void traverse_vdw_params(struct vdw_params *);
00297 void traverse_dihedral_params(struct dihedral_params *);
00298 void traverse_improper_params(struct improper_params *);
00299 void traverse_crossterm_params(struct crossterm_params *);
00300 void traverse_angle_params(struct angle_params *);
00301 void traverse_bond_params(struct bond_params *);
00302
00303
00304
00305
00306 Index index_bonds(struct bond_params *, Index);
00307 Index index_angles(struct angle_params *, Index);
00308 Index index_vdw(struct vdw_params *, Index);
00309 void index_dihedrals();
00310 void index_impropers();
00311 void index_crossterms();
00312
00313 void convert_vdw_pairs();
00314 void convert_nbthole_pairs();
00315 void convert_table_pairs();
00316 IndexedVdwPair *add_to_indexed_vdw_pairs(IndexedVdwPair *, IndexedVdwPair *);
00317 IndexedNbtholePair *add_to_indexed_nbthole_pairs(IndexedNbtholePair *, IndexedNbtholePair *);
00318 IndexedTablePair *add_to_indexed_table_pairs(IndexedTablePair *, IndexedTablePair *);
00319
00320 int vdw_pair_to_arrays(int *, int *, Real *, Real *, Real *, Real *,
00321 int, IndexedVdwPair *);
00322
00323 int nbthole_pair_to_arrays(int *, int *, Real *, Real *, Real *, int, IndexedNbtholePair *);
00324
00325 int table_pair_to_arrays(int *, int *, int *, int, IndexedTablePair *);
00326
00327
00328
00329 void free_bond_tree(struct bond_params *);
00330 void free_angle_tree(struct angle_params *);
00331 void free_dihedral_list(struct dihedral_params *);
00332 void free_improper_list(struct improper_params *);
00333 void free_crossterm_list(struct crossterm_params *);
00334 void free_vdw_tree(struct vdw_params *);
00335 void free_vdw_pair_tree(IndexedVdwPair *);
00336 void free_nbthole_pair_tree(IndexedNbtholePair *);
00337 void free_table_pair_tree(IndexedTablePair *);
00338 void free_vdw_pair_list();
00339 void free_nbthole_pair_list();
00340
00341 BigReal interp_lin(BigReal, BigReal, BigReal, BigReal, BigReal);
00342
00343
00344
00345 void read_parm(const GromacsTopFile *, Bool min);
00346 public:
00347
00349 Parameters();
00350 Parameters(SimParameters *, StringList *f);
00351
00352
00353 Parameters(Ambertoppar *, BigReal);
00354 void read_parm(Ambertoppar *, BigReal);
00355
00356
00357
00358
00359
00360
00361 Parameters(const GromacsTopFile *gf, Bool min);
00362
00363 ~Parameters();
00364
00365
00366
00367
00368
00369 char *atom_type_name(Index a) {
00370 return (atomTypeNames + (a * (MAX_ATOMTYPE_CHARS + 1)));
00371 }
00372
00373
00374 void read_parameter_file(char *);
00375
00376
00377 void read_charmm_parameter_file(char *);
00378
00379
00380
00381
00382 void done_reading_files();
00383
00384
00385
00386 void done_reading_structure();
00387
00388
00389
00390
00391
00392 #ifdef MEM_OPT_VERSION
00393 void assign_vdw_index(char *, AtomCstInfo *);
00394 #else
00395 void assign_vdw_index(char *, Atom *);
00396 #endif
00397
00398 void assign_bond_index(char *, char *, Bond *);
00399
00400
00401 void assign_angle_index(char *, char *, char *, Angle *, int);
00402
00403
00404 void assign_dihedral_index(char *, char*, char*, char *, Dihedral *, int, int);
00405
00406
00407 void assign_improper_index(char *, char*, char*, char *, Improper *, int);
00408
00409
00410 void assign_crossterm_index(char *, char*, char*, char *, char *, char*, char*, char *, Crossterm *);
00411
00412
00413
00414 void send_Parameters(MOStream *);
00415
00416
00417
00418 void receive_Parameters(MIStream *);
00419
00420
00421
00422
00423 void get_bond_params(Real *k, Real *x0, Index index)
00424 {
00425 *k = bond_array[index].k;
00426 *x0 = bond_array[index].x0;
00427 }
00428
00429 void get_angle_params(Real *k, Real *theta0, Real *k_ub, Real *r_ub,
00430 Index index)
00431 {
00432 *k = angle_array[index].k;
00433 *theta0 = angle_array[index].theta0;
00434 *k_ub = angle_array[index].k_ub;
00435 *r_ub = angle_array[index].r_ub;
00436 }
00437
00438 int get_improper_multiplicity(Index index)
00439 {
00440 return(improper_array[index].multiplicity);
00441 }
00442
00443 int get_dihedral_multiplicity(Index index)
00444 {
00445 return(dihedral_array[index].multiplicity);
00446 }
00447
00448 void get_improper_params(Real *k, int *n, Real *delta,
00449 Index index, int mult)
00450 {
00451 if ( (mult<0) || (mult>MAX_MULTIPLICITY) )
00452 {
00453 NAMD_die("Bad mult index in Parameters::get_improper_params");
00454 }
00455
00456 *k = improper_array[index].values[mult].k;
00457 *n = improper_array[index].values[mult].n;
00458 *delta = improper_array[index].values[mult].delta;
00459 }
00460
00461 void get_dihedral_params(Real *k, int *n, Real *delta,
00462 Index index, int mult)
00463 {
00464 if ( (mult<0) || (mult>MAX_MULTIPLICITY) )
00465 {
00466 NAMD_die("Bad mult index in Parameters::get_dihedral_params");
00467 }
00468
00469 *k = dihedral_array[index].values[mult].k;
00470 *n = dihedral_array[index].values[mult].n;
00471 *delta = dihedral_array[index].values[mult].delta;
00472 }
00473
00474 void get_vdw_params(Real *sigma, Real *epsilon, Real *sigma14,
00475 Real *epsilon14, Index index)
00476 {
00477 if ( vdw_array ) {
00478 *sigma = vdw_array[index].sigma;
00479 *epsilon = vdw_array[index].epsilon;
00480 *sigma14 = vdw_array[index].sigma14;
00481 *epsilon14 = vdw_array[index].epsilon14;
00482 } else {
00483
00484 Real A; Real B; Real A14; Real B14;
00485 if (get_vdw_pair_params(index, index, &A, &B, &A14, &B14) ) {
00486 if (A && B) {
00487 *sigma = sqrt(cbrt(A)) / sqrt(cbrt(B));
00488 *epsilon = B*B / (4*A);
00489 }
00490 else {
00491 *sigma = 0; *epsilon = 0;
00492 }
00493 if (A14 && B14) {
00494 *sigma14 = sqrt(cbrt(A14)) / sqrt(cbrt(B14));
00495 *epsilon14 = B14*B14 / (4*A14);
00496 }
00497 else {
00498 *sigma14 = 0; *epsilon14 = 0;
00499 }
00500 }
00501 else {NAMD_die ("Function get_vdw_params failed to derive Lennard-Jones sigma and epsilon from A and B values\n");}
00502 }
00503 }
00504
00505 int get_vdw_pair_params(Index ind1, Index ind2, Real *, Real *, Real *, Real *);
00506
00507
00508 int get_num_vdw_params(void) { return NumVdwParamsAssigned; }
00509
00510 int get_table_pair_params(Index, Index, int*);
00511
00512
00513 void print_bond_params();
00514 void print_angle_params();
00515 void print_dihedral_params();
00516 void print_improper_params();
00517 void print_crossterm_params();
00518 void print_vdw_params();
00519 void print_vdw_pair_params();
00520 void print_nbthole_pair_params();
00521 void print_param_summary();
00522 void read_ener_table(SimParameters*);
00523 int get_int_table_type(char*);
00524
00525 int read_energy_type(FILE*, const int, BigReal*, const float, const float);
00526 int read_energy_type_cubspline(FILE*, const int, BigReal*, const float, const float);
00527 int read_energy_type_bothcubspline(FILE*, const int, BigReal*, const float, const float);
00528 };
00529
00530 #endif
00531