Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Parameters.h

Go to the documentation of this file.
00001 
00007 /*
00008    The Parameters class is used to read in and store all of the parameters
00009    from the parameter files.  These parameters are stored and used to assign
00010    constants to bonds and atoms as they are read in from the psf file
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 //****** BEGIN CHARMM/XPLOR type changes
00024 #include "SimParameters.h"
00025 //****** END CHARMM/XPLOR type changes
00026 
00027 #include "GromacsTopFile.h"
00028 
00029 #ifndef cbrt
00030   // cbrt() not in math.h on goneril
00031   #define cbrt(x)  pow((double)x,(double)(1.0/3.0))
00032 #endif
00033 
00034 class Communicate;
00035 class StringList;
00036 
00037 //  The class Parameters is used to store and query the parameters for
00038 //  bonds and atoms.  If the Parameter object resides on the master
00039 //  process, it is responsible for reading in all the parameters and
00040 //  then communicating them to the other processors.  To do this, first
00041 //  the routine read_paramter_file is called to read in each parameter
00042 //  file.  The information that is read in is stored in binary trees
00043 //  for vdw, bond, and angle information and in linked lists for 
00044 //  dihedrals and impropers.  Once all of the files have been read
00045 //  in, the routine done_reading_files is called.  At this point, all
00046 //  of the data that has been read in is copied to arrays.  This is
00047 //  so that each bond and atom can be assigned an index into these
00048 //  arrays to retreive the parameters in constant time.
00049 //
00050 //  Then the psf file is read in.  Each bond and atom is assigned an
00051 //  index into the parameter lists using the functions assign_*_index.
00052 //  Once the psf file has been read in, then the routine 
00053 //  done_reading_structre is called to tell the object that it no
00054 //  longer needs to store the binary trees and linked lists that were
00055 //  used to query the parameters based on atom type.  From this point
00056 //  on, only the indexes will be used.
00057 //
00058 //  The master node then uses send_parameters to send all of these
00059 //  parameters to the other nodes and the objects on all of the other
00060 //  nodes use receive_parameters to accept these parameters.
00061 //
00062 //  From this point on, all of the parameter data is static and the
00063 //  functions get_*_params are used to retrieve the parameter data
00064 //  that is desired.
00065 
00066 //  Define the number of Multiples that a Dihedral or Improper
00067 //  bond can have with the Charm22 parameter set
00068 #define MAX_MULTIPLICITY        6
00069 
00070 //  Number of characters maximum allowed for storing atom type names
00071 #define MAX_ATOMTYPE_CHARS      6
00072 
00073 //****** BEGIN CHARMM/XPLOR type changes
00074 //  Define the numbers associated with each possible parameter-file 
00075 //  type (format) NAMD can handle.
00076 #define paraXplor               0
00077 #define paraCharmm              1
00078 //****** END CHARMM/XPLOR type changes
00079 
00080 
00081 class BondValue {
00082 public:
00083         Real k;         //  Force constant for the bond
00084         Real x0;        //  Rest distance for the bond
00085 };
00086 
00087 class AngleValue {
00088 public:
00089         Real k;         //  Force constant for angle
00090         Real theta0;    //  Rest angle for angle
00091         Real k_ub;      //  Urey-Bradley force constant
00092         Real r_ub;      //  Urey-Bradley distance
00093   int normal; // Whether we use harmonic (0) or cos-based (1) angle terms
00094 };
00095 
00096 typedef struct four_body_consts
00097 {
00098         Real k;         //  Force constant
00099         int n;          //  Periodicity
00100         Real delta;     //  Phase shift
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];  // bicubic interpolation coefficients
00121 };
00122 
00123 class NonbondedExclValue {
00124 public:
00125         // need to put parameters here...
00126         // for now, copy bond
00127         Real k;         //  Force constant for the bond
00128         Real x0;        //  Rest distance for the bond
00129 };
00130 
00131 typedef struct vdw_val
00132 {
00133         Real sigma;     //  Sigma value
00134         Real epsilon;   //  Epsilon value
00135         Real sigma14;   //  Sigma value for 1-4 interactions
00136         Real epsilon14; //  Epsilon value for 1-4 interactions
00137 } VdwValue;
00138 
00139 //  IndexedVdwPair is used to form a binary search tree that is
00140 //  indexed by vwd_type index.  This is the tree that will be
00141 //  used to search during the actual simulation
00142 
00143 typedef struct indexed_vdw_pair
00144 {
00145         Index ind1;             //  Index for first atom type
00146         Index ind2;             //  Index for second atom type
00147         Real A;                 //  Parameter A for this pair
00148         Real A14;               //  Parameter A for 1-4 interactions
00149         Real B;                 //  Parameter B for this pair
00150         Real B14;               //  Parameter B for 1-4 interactions
00151         struct indexed_vdw_pair *right;  //  Right child
00152         struct indexed_vdw_pair *left;   //  Left child
00153 } IndexedVdwPair;
00154 
00155 typedef struct indexed_nbthole_pair
00156 {
00157         Index ind1;             //  Index for first atom type
00158         Index ind2;             //  Index for second atom type
00159         Real alphai;           //  Parameter alpha for this pair
00160         Real alphaj;           //  Parameter alpha for this pair
00161         Real tholeij;          //  Parameter thole for this pair
00162         struct indexed_nbthole_pair *right;  //  Right child
00163         struct indexed_nbthole_pair *left;   //  Left child
00164 } IndexedNbtholePair;
00165 
00166 typedef struct nbthole_pair_value
00167 {
00168         Index ind1;             //  Index for first atom type
00169         Index ind2;             //  Index for second atom type
00170         Real alphai;           //  Parameter alpha for this pair
00171         Real alphaj;           //  Parameter alpha for this pair
00172         Real tholeij;          //  Parameter thole for this pair
00173 } NbtholePairValue;
00174 
00175 //  IndexedTablePair is used to form a binary search tree that is
00176 //  indexed by table_type index.  This is the tree that will be
00177 //  used to search during the actual simulation
00178 
00179 typedef struct indexed_table_pair
00180 {
00181         Index ind1;             //  Index for first atom type
00182         Index ind2;             //  Index for second atom type
00183         int K;                  //  number of the table type for this pair
00184         struct indexed_table_pair *right;        //  Right child
00185         struct indexed_table_pair *left;         //  Left child
00186 } IndexedTablePair;
00187 
00188 //  Structures that are defined in Parameters.C
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();                      //  zeros out pointers
00203 
00204         char *atomTypeNames;                    //  Names of atom types
00205         Bool AllFilesRead;                      //  Flag TRUE imples that all
00206                                                 //  of the parameter files
00207                                                 //  have been read in and
00208                                                 //  the arrays have been
00209                                                 //  created.
00210 //****** BEGIN CHARMM/XPLOR type changes
00211         int paramType;                          //  Type (format) of parameter-file
00212 //****** END CHARMM/XPLOR type changes
00213   bool cosAngles; // True if some angles may be cos-based
00214         struct bond_params *bondp;              //  Binary tree of bond params
00215         struct angle_params *anglep;            //  Binary tree of angle params
00216         struct improper_params *improperp;      //  Linked list of improper par.
00217         struct dihedral_params *dihedralp;      //  Linked list of dihedral par.
00218         struct crossterm_params *crosstermp;    //  Linked list of cross-term par.
00219         struct vdw_params *vdwp;                //  Binary tree of vdw params
00220         struct vdw_pair_params *vdw_pairp;      //  Binary tree of vdw pairs
00221         struct nbthole_pair_params *nbthole_pairp;      //  Binary tree of nbthole pairs
00222         struct table_pair_params *table_pairp;  //  Binary tree of table pairs
00223 public:
00224         BondValue *bond_array;                  //  Array of bond params
00225         AngleValue *angle_array;                //  Array of angle params
00226         DihedralValue *dihedral_array;          //  Array of dihedral params
00227         ImproperValue *improper_array;          //  Array of improper params
00228         CrosstermValue *crossterm_array;        //  Array of crossterm params
00229         VdwValue *vdw_array;                    //  Array of vdw params
00230         NbtholePairValue *nbthole_array;        //  Array of nbthole params
00231         int numenerentries;                     //  Number of entries for enertable
00232         int rowsize;
00233         int columnsize;
00234         BigReal* table_ener;                    //  Table for tabulated energies
00235         IndexedVdwPair *vdw_pair_tree;          //  Tree of vdw pair params
00236         IndexedNbtholePair *nbthole_pair_tree;      //  Tree of nbthole pair params
00237         IndexedTablePair *tab_pair_tree;                //  Tree of vdw pair params
00238   int tablenumtypes;
00239         int NumBondParams;                      //  Number of bond parameters
00240         int NumAngleParams;                     //  Number of angle parameters
00241   int NumCosAngles;       // Number of cosine-based angles
00242         int NumDihedralParams;                  //  Number of dihedral params
00243         int NumImproperParams;                  //  Number of improper params
00244         int NumCrosstermParams;                 //  Number of cross-term params
00245         int NumVdwParams;                       //  Number of vdw parameters
00246         int NumTableParams;                     //  Number of table parameters
00247   int NumVdwParamsAssigned;               //  Number actually assigned
00248         int NumVdwPairParams;                   //  Number of vdw_pair params
00249         int NumNbtholePairParams;                   //  Number of nbthole_pair params
00250         int NumTablePairParams;                 //  Number of vdw_pair params
00251 private:
00252         ResizeArray<char *> error_msgs;         //  Avoids repeating warnings
00253 
00254         int *maxDihedralMults;                  //  Max multiplicity for
00255                                                 //  dihedral bonds
00256         int *maxImproperMults;                  //  Max multiplicity for
00257                                                 //  improper bonds
00258 
00259         void skip_stream_read(char *, FILE *);  // skip part of stream file
00260 
00261         void add_bond_param(char *);            //  Add a bond parameter
00262         struct bond_params *add_to_bond_tree(struct bond_params * , 
00263                                      struct bond_params *);
00264 
00265         void add_angle_param(char *);           //  Add an angle parameter
00266         struct angle_params *add_to_angle_tree(struct angle_params * , 
00267                                      struct angle_params *);
00268 
00269         void add_dihedral_param(char *, FILE *); //  Add a dihedral parameter
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 *); //  Add an improper parameter
00274         void add_to_improper_list(struct improper_params *);
00275 
00276         void add_crossterm_param(char *, FILE *); //  Add an cross-term parameter
00277         void add_to_crossterm_list(struct crossterm_params *);
00278 
00279         void add_vdw_param(char *);             //  Add a vdw parameter
00280         struct vdw_params *add_to_vdw_tree(struct vdw_params *, 
00281                                      struct vdw_params *);
00282 
00283         void add_vdw_pair_param(char *);        //  Add a vdw pair parameter
00284         void add_nbthole_pair_param(char *);        //  Add a nbthole pair parameter        
00285         void add_table_pair_param(char *);      //  Add a table pair parameter
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 *); //  Add a hydrogen bond pair parameter
00291 
00292         //  All of the traverse routines are used for debugging purposes
00293         //  to print out the appropriate list of parameters
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         //  The index_* routines are used to index each of 
00304         //  the parameters and build the arrays that will be used
00305         //  for constant time access
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         //  The free_* routines are used by the destructor to deallocate
00328         //  memory
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); // Perform a linear interpolation for energy table 
00342 
00343         /* does the actual initialization, once the variables have all
00344            been given default values.  See Parameters() below */
00345         void read_parm(const GromacsTopFile *, Bool min);
00346 public:
00347         //****** BEGIN CHARMM/XPLOR type changes
00349         Parameters();
00350         Parameters(SimParameters *, StringList *f);
00351         //****** END CHARMM/XPLOR type changes
00352         
00353         Parameters(Ambertoppar *, BigReal);
00354         void read_parm(Ambertoppar *, BigReal);
00355 
00356         /* initializes this to hold the set of parameters in the
00357            GROMACS topology file <gf>.  If the parameter <min> is on,
00358            this assumes that we are going to do minimization and
00359            therefore can't have atoms with zero VDW - it will add a
00360            small repulsive term to these. */
00361         Parameters(const GromacsTopFile *gf, Bool min);
00362         
00363         ~Parameters();                          //  Destructor
00364 
00365         // return a string for the Nth atom type.  This can only be
00366         // called after all the param files have been read and the type
00367         // names have been indexed.  The Nth atom type refers to the same
00368         // index of the Nth vdw parameter (i.e. there are NumVdwParams names).
00369         char *atom_type_name(Index a) {
00370           return (atomTypeNames + (a * (MAX_ATOMTYPE_CHARS + 1)));
00371         }
00372 
00373         //  Read a parameter file
00374         void read_parameter_file(char *);
00375 
00376         //****** BEGIN CHARMM/XPLOR type changes
00377         void read_charmm_parameter_file(char *);
00378         //****** END CHARMM/XPLOR type changes
00379 
00380         //  Signal the parameter object that all of
00381         //  the parameter files have been read in
00382         void done_reading_files();
00383 
00384         //  Signal the parameter object that the
00385         //  structure file has been read in
00386         void done_reading_structure();
00387     
00388         //  The assign_*_index routines are used to assign
00389         //  an index to atoms or bonds.  If an specific atom
00390         //  or bond type can't be found, then the program 
00391         //  terminates
00392     #ifdef MEM_OPT_VERSION
00393     void assign_vdw_index(char *, AtomCstInfo *);
00394     #else
00395         void assign_vdw_index(char *, Atom *);  //  Assign a vdw index to
00396     #endif
00397                                                 //  an atom
00398         void assign_bond_index(char *, char *, Bond *); 
00399                                                 //  Assign a bond index
00400                                                 //  to a bond
00401         void assign_angle_index(char *, char *, char *, Angle *, int);
00402                                                 //  Assign an angle index
00403                                                 //  to an angle
00404         void assign_dihedral_index(char *, char*, char*, char *, Dihedral *, int, int);
00405                                                 //  Assign a dihedral index
00406                                                 //  to a dihedral
00407         void assign_improper_index(char *, char*, char*, char *, Improper *, int);
00408                                                 //  Assign an improper index
00409                                                 //  to an improper
00410         void assign_crossterm_index(char *, char*, char*, char *, char *, char*, char*, char *, Crossterm *);
00411 
00412         //  send_parameters is used by the master process to
00413         //  communicate the paramters to all the other processors
00414         void send_Parameters(MOStream *);
00415 
00416         //  receive_parameters is used by all the child processes
00417         //  to receive the parameters from the master process
00418         void receive_Parameters(MIStream *);
00419 
00420         //  The get_*_params routines are the routines that really
00421         //  do all the work for this object.  Given an index, they
00422         //  access the parameters and return the relevant information
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       // sigma and epsilon from A and B for each vdw type's interaction with itself
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                                                 //  Find a vwd_pair parameter
00507 
00508         int get_num_vdw_params(void) { return NumVdwParamsAssigned; }
00509 
00510   int get_table_pair_params(Index, Index, int*);
00511 
00512         //  The print_*_params are provided for debugging purposes
00513         void print_bond_params();               //  Print bonds params
00514         void print_angle_params();              //  Print angle params
00515         void print_dihedral_params();           //  Print dihedral params
00516         void print_improper_params();           //  Print improper params
00517         void print_crossterm_params();          //  Print cross-term params
00518         void print_vdw_params();                //  Print vdw params
00519         void print_vdw_pair_params();           //  Print vdw_pair params
00520         void print_nbthole_pair_params();           //  Print nbthole_pair params
00521         void print_param_summary();             //  Print a summary of params
00522         void read_ener_table(SimParameters*); // Read an energy table file
00523   int get_int_table_type(char*); // Return the integer type for a named table interaction
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 

Generated on Fri May 25 04:07:16 2012 for NAMD by  doxygen 1.3.9.1