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 class Communicate;
00030 class StringList;
00031 
00032 //  The class Parameters is used to store and query the parameters for
00033 //  bonds and atoms.  If the Parameter object resides on the master
00034 //  process, it is responsible for reading in all the parameters and
00035 //  then communicating them to the other processors.  To do this, first
00036 //  the routine read_paramter_file is called to read in each parameter
00037 //  file.  The information that is read in is stored in binary trees
00038 //  for vdw, bond, and angle information and in linked lists for 
00039 //  dihedrals and impropers.  Once all of the files have been read
00040 //  in, the routine done_reading_files is called.  At this point, all
00041 //  of the data that has been read in is copied to arrays.  This is
00042 //  so that each bond and atom can be assigned an index into these
00043 //  arrays to retreive the parameters in constant time.
00044 //
00045 //  Then the psf file is read in.  Each bond and atom is assigned an
00046 //  index into the parameter lists using the functions assign_*_index.
00047 //  Once the psf file has been read in, then the routine 
00048 //  done_reading_structre is called to tell the object that it no
00049 //  longer needs to store the binary trees and linked lists that were
00050 //  used to query the parameters based on atom type.  From this point
00051 //  on, only the indexes will be used.
00052 //
00053 //  The master node then uses send_parameters to send all of these
00054 //  parameters to the other nodes and the objects on all of the other
00055 //  nodes use receive_parameters to accept these parameters.
00056 //
00057 //  From this point on, all of the parameter data is static and the
00058 //  functions get_*_params are used to retrieve the parameter data
00059 //  that is desired.
00060 
00061 //  Define the number of Multiples that a Dihedral or Improper
00062 //  bond can have with the Charm22 parameter set
00063 #define MAX_MULTIPLICITY        6
00064 
00065 //  Number of characters maximum allowed for storing atom type names
00066 #define MAX_ATOMTYPE_CHARS      6
00067 
00068 //****** BEGIN CHARMM/XPLOR type changes
00069 //  Define the numbers associated with each possible parameter-file 
00070 //  type (format) NAMD can handle.
00071 #define paraXplor               0
00072 #define paraCharmm              1
00073 //****** END CHARMM/XPLOR type changes
00074 
00075 
00076 class BondValue {
00077 public:
00078         Real k;         //  Force constant for the bond
00079         Real x0;        //  Rest distance for the bond
00080 };
00081 
00082 class AngleValue {
00083 public:
00084         Real k;         //  Force constant for angle
00085         Real theta0;    //  Rest angle for angle
00086         Real k_ub;      //  Urey-Bradley force constant
00087         Real r_ub;      //  Urey-Bradley distance
00088   int normal; // Whether we use harmonic (0) or cos-based (1) angle terms
00089 };
00090 
00091 typedef struct four_body_consts
00092 {
00093         Real k;         //  Force constant
00094         int n;          //  Periodicity
00095         Real delta;     //  Phase shift
00096 } FourBodyConsts;
00097 
00098 class DihedralValue {
00099 public:
00100         int multiplicity;
00101         FourBodyConsts values[MAX_MULTIPLICITY];
00102 };
00103 
00104 class ImproperValue {
00105 public:
00106         int multiplicity;
00107         FourBodyConsts values[MAX_MULTIPLICITY];
00108 };
00109 
00110 struct CrosstermData { BigReal d00,d01,d10,d11; };
00111 
00112 class CrosstermValue {
00113 public:
00114         enum {dim=25};
00115         CrosstermData c[dim][dim];  // bicubic interpolation coefficients
00116 };
00117 
00118 class NonbondedExclValue {
00119 public:
00120         // need to put parameters here...
00121         // for now, copy bond
00122         Real k;         //  Force constant for the bond
00123         Real x0;        //  Rest distance for the bond
00124 };
00125 
00126 typedef struct vdw_val
00127 {
00128         Real sigma;     //  Sigma value
00129         Real epsilon;   //  Epsilon value
00130         Real sigma14;   //  Sigma value for 1-4 interactions
00131         Real epsilon14; //  Epsilon value for 1-4 interactions
00132 } VdwValue;
00133 
00134 //  IndexedVdwPair is used to form a binary search tree that is
00135 //  indexed by vwd_type index.  This is the tree that will be
00136 //  used to search during the actual simulation
00137 
00138 typedef struct indexed_vdw_pair
00139 {
00140         Index ind1;             //  Index for first atom type
00141         Index ind2;             //  Index for second atom type
00142         Real A;                 //  Parameter A for this pair
00143         Real A14;               //  Parameter A for 1-4 interactions
00144         Real B;                 //  Parameter B for this pair
00145         Real B14;               //  Parameter B for 1-4 interactions
00146         struct indexed_vdw_pair *right;  //  Right child
00147         struct indexed_vdw_pair *left;   //  Left child
00148 } IndexedVdwPair;
00149 
00150 //  Structures that are defined in Parameters.C
00151 struct bond_params;
00152 struct angle_params;
00153 struct improper_params;
00154 struct dihedral_params;
00155 struct crossterm_params;
00156 struct vdw_params;
00157 struct vdw_pair_params;
00158 
00159 class Parameters
00160 {
00161 private:
00162         void initialize();                      //  zeros out pointers
00163 
00164         char *atomTypeNames;                    //  Names of atom types
00165         Bool AllFilesRead;                      //  Flag TRUE imples that all
00166                                                 //  of the parameter files
00167                                                 //  have been read in and
00168                                                 //  the arrays have been
00169                                                 //  created.
00170 //****** BEGIN CHARMM/XPLOR type changes
00171         int paramType;                          //  Type (format) of parameter-file
00172 //****** END CHARMM/XPLOR type changes
00173   bool cosAngles; // True if some angles may be cos-based
00174         struct bond_params *bondp;              //  Binary tree of bond params
00175         struct angle_params *anglep;            //  Binary tree of angle params
00176         struct improper_params *improperp;      //  Linked list of improper par.
00177         struct dihedral_params *dihedralp;      //  Linked list of dihedral par.
00178         struct crossterm_params *crosstermp;    //  Linked list of cross-term par.
00179         struct vdw_params *vdwp;                //  Binary tree of vdw params
00180         struct vdw_pair_params *vdw_pairp;      //  Binary tree of vdw pairs
00181 public:
00182         BondValue *bond_array;                  //  Array of bond params
00183         AngleValue *angle_array;                //  Array of angle params
00184         DihedralValue *dihedral_array;          //  Array of dihedral params
00185         ImproperValue *improper_array;          //  Array of improper params
00186         CrosstermValue *crossterm_array;        //  Array of crossterm params
00187         VdwValue *vdw_array;                    //  Array of vdw params
00188         IndexedVdwPair *vdw_pair_tree;          //  Tree of vdw pair params
00189         int NumBondParams;                      //  Number of bond parameters
00190         int NumAngleParams;                     //  Number of angle parameters
00191   int NumCosAngles;       // Number of cosine-based angles
00192         int NumDihedralParams;                  //  Number of dihedral params
00193         int NumImproperParams;                  //  Number of improper params
00194         int NumCrosstermParams;                 //  Number of cross-term params
00195 private:
00196         int NumVdwParams;                       //  Number of vdw parameters
00197         int NumVdwParamsAssigned;               //  Number actually assigned
00198         int NumVdwPairParams;                   //  Number of vdw_pair params
00199         ResizeArray<char *> error_msgs;         //  Avoids repeating warnings
00200 
00201         int *maxDihedralMults;                  //  Max multiplicity for
00202                                                 //  dihedral bonds
00203         int *maxImproperMults;                  //  Max multiplicity for
00204                                                 //  improper bonds
00205 
00206         void skip_stream_read(char *, FILE *);  // skip part of stream file
00207 
00208         void add_bond_param(char *);            //  Add a bond parameter
00209         struct bond_params *add_to_bond_tree(struct bond_params * , 
00210                                      struct bond_params *);
00211 
00212         void add_angle_param(char *);           //  Add an angle parameter
00213         struct angle_params *add_to_angle_tree(struct angle_params * , 
00214                                      struct angle_params *);
00215 
00216         void add_dihedral_param(char *, FILE *); //  Add a dihedral parameter
00217         void add_to_dihedral_list(struct dihedral_params *);
00218         void add_to_charmm_dihedral_list(struct dihedral_params *);
00219 
00220         void add_improper_param(char *, FILE *); //  Add an improper parameter
00221         void add_to_improper_list(struct improper_params *);
00222 
00223         void add_crossterm_param(char *, FILE *); //  Add an cross-term parameter
00224         void add_to_crossterm_list(struct crossterm_params *);
00225 
00226         void add_vdw_param(char *);             //  Add a vdw parameter
00227         struct vdw_params *add_to_vdw_tree(struct vdw_params *, 
00228                                      struct vdw_params *);
00229 
00230         void add_vdw_pair_param(char *);        //  Add a vdw pair parameter
00231         void add_to_vdw_pair_list(struct vdw_pair_params *);
00232 
00233         void add_hb_pair_param(char *); //  Add a hydrogen bond pair parameter
00234 
00235         //  All of the traverse routines are used for debugging purposes
00236         //  to print out the appropriate list of parameters
00237         void traverse_vdw_pair_params(struct vdw_pair_params *);
00238         void traverse_vdw_params(struct vdw_params *);
00239         void traverse_dihedral_params(struct dihedral_params *);
00240         void traverse_improper_params(struct improper_params *);
00241         void traverse_crossterm_params(struct crossterm_params *);
00242         void traverse_angle_params(struct angle_params *);
00243         void traverse_bond_params(struct bond_params *);
00244 
00245         //  The index_* routines are used to index each of 
00246         //  the parameters and build the arrays that will be used
00247         //  for constant time access
00248         Index index_bonds(struct bond_params *, Index);
00249         Index index_angles(struct angle_params *, Index);
00250         Index index_vdw(struct vdw_params *, Index);
00251         void index_dihedrals();
00252         void index_impropers();
00253         void index_crossterms();
00254         
00255         void convert_vdw_pairs();
00256         IndexedVdwPair *add_to_indexed_vdw_pairs(IndexedVdwPair *, IndexedVdwPair *);
00257         
00258         int vdw_pair_to_arrays(int *, int *, Real *, Real *, Real *, Real *, 
00259                                int, IndexedVdwPair *);
00260 
00261         //  The free_* routines are used by the destructor to deallocate
00262         //  memory
00263         void free_bond_tree(struct bond_params *);
00264         void free_angle_tree(struct angle_params *);
00265         void free_dihedral_list(struct dihedral_params *);
00266         void free_improper_list(struct improper_params *);
00267         void free_crossterm_list(struct crossterm_params *);
00268         void free_vdw_tree(struct vdw_params *);
00269         void free_vdw_pair_tree(IndexedVdwPair *);
00270         void free_vdw_pair_list();
00271 
00272         /* does the actual initialization, once the variables have all
00273            been given default values.  See Parameters() below */
00274         void read_parm(const GromacsTopFile *, Bool min);
00275 public:
00276         //****** BEGIN CHARMM/XPLOR type changes
00278         Parameters();
00279         Parameters(SimParameters *, StringList *f);
00280         //****** END CHARMM/XPLOR type changes
00281         
00282         Parameters(Ambertoppar *, BigReal);
00283         void read_parm(Ambertoppar *, BigReal);
00284 
00285         /* initializes this to hold the set of parameters in the
00286            GROMACS topology file <gf>.  If the parameter <min> is on,
00287            this assumes that we are going to do minimization and
00288            therefore can't have atoms with zero VDW - it will add a
00289            small repulsive term to these. */
00290         Parameters(const GromacsTopFile *gf, Bool min);
00291         
00292         ~Parameters();                          //  Destructor
00293 
00294         // return a string for the Nth atom type.  This can only be
00295         // called after all the param files have been read and the type
00296         // names have been indexed.  The Nth atom type refers to the same
00297         // index of the Nth vdw parameter (i.e. there are NumVdwParams names).
00298         char *atom_type_name(Index a) {
00299           return (atomTypeNames + (a * (MAX_ATOMTYPE_CHARS + 1)));
00300         }
00301 
00302         //  Read a parameter file
00303         void read_parameter_file(char *);
00304 
00305         //****** BEGIN CHARMM/XPLOR type changes
00306         void read_charmm_parameter_file(char *);
00307         //****** END CHARMM/XPLOR type changes
00308 
00309         //  Signal the parameter object that all of
00310         //  the parameter files have been read in
00311         void done_reading_files();
00312 
00313         //  Signal the parameter object that the
00314         //  structure file has been read in
00315         void done_reading_structure();
00316     
00317         //  The assign_*_index routines are used to assign
00318         //  an index to atoms or bonds.  If an specific atom
00319         //  or bond type can't be found, then the program 
00320         //  terminates
00321     #ifdef MEM_OPT_VERSION
00322     void assign_vdw_index(char *, AtomCstInfo *);
00323     #else
00324         void assign_vdw_index(char *, Atom *);  //  Assign a vdw index to
00325     #endif
00326                                                 //  an atom
00327         void assign_bond_index(char *, char *, Bond *); 
00328                                                 //  Assign a bond index
00329                                                 //  to a bond
00330         void assign_angle_index(char *, char *, char *, Angle *);
00331                                                 //  Assign an angle index
00332                                                 //  to an angle
00333         void assign_dihedral_index(char *, char*, char*, char *, Dihedral *, int);
00334                                                 //  Assign a dihedral index
00335                                                 //  to a dihedral
00336         void assign_improper_index(char *, char*, char*, char *, Improper *, int);
00337                                                 //  Assign an improper index
00338                                                 //  to an improper
00339         void assign_crossterm_index(char *, char*, char*, char *, char *, char*, char*, char *, Crossterm *);
00340 
00341         //  send_parameters is used by the master process to
00342         //  communicate the paramters to all the other processors
00343         void send_Parameters(Communicate *);
00344 
00345         //  receive_parameters is used by all the child processes
00346         //  to receive the parameters from the master process
00347         void receive_Parameters(MIStream *);
00348 
00349         //  The get_*_params routines are the routines that really
00350         //  do all the work for this object.  Given an index, they
00351         //  access the parameters and return the relevant information
00352         void get_bond_params(Real *k, Real *x0, Index index)
00353         {
00354                 *k = bond_array[index].k;
00355                 *x0 = bond_array[index].x0;
00356         }
00357 
00358         void get_angle_params(Real *k, Real *theta0, Real *k_ub, Real *r_ub,
00359                               Index index)
00360         {
00361                 *k = angle_array[index].k;
00362                 *theta0 = angle_array[index].theta0;
00363                 *k_ub = angle_array[index].k_ub;
00364                 *r_ub = angle_array[index].r_ub;
00365         }
00366 
00367         int get_improper_multiplicity(Index index)
00368         {
00369                 return(improper_array[index].multiplicity);
00370         }
00371 
00372         int get_dihedral_multiplicity(Index index)
00373         {
00374                 return(dihedral_array[index].multiplicity);
00375         }
00376 
00377         void get_improper_params(Real *k, int *n, Real *delta, 
00378                                  Index index, int mult)
00379         {
00380                 if ( (mult<0) || (mult>MAX_MULTIPLICITY) )
00381                 {
00382                         NAMD_die("Bad mult index in Parameters::get_improper_params");
00383                 }
00384 
00385                 *k = improper_array[index].values[mult].k;
00386                 *n = improper_array[index].values[mult].n;
00387                 *delta = improper_array[index].values[mult].delta;
00388         }
00389 
00390         void get_dihedral_params(Real *k, int *n, Real *delta, 
00391                                  Index index, int mult)
00392         {
00393                 if ( (mult<0) || (mult>MAX_MULTIPLICITY) )
00394                 {
00395                         NAMD_die("Bad mult index in Parameters::get_dihedral_params");
00396                 }
00397 
00398                 *k = dihedral_array[index].values[mult].k;
00399                 *n = dihedral_array[index].values[mult].n;
00400                 *delta = dihedral_array[index].values[mult].delta;
00401         }
00402 
00403         void get_vdw_params(Real *sigma, Real *epsilon, Real *sigma14, 
00404                             Real *epsilon14, Index index)
00405         {
00406             if ( vdw_array ) {
00407                 *sigma = vdw_array[index].sigma;
00408                 *epsilon = vdw_array[index].epsilon;
00409                 *sigma14 = vdw_array[index].sigma14;
00410                 *epsilon14 = vdw_array[index].epsilon14;
00411             } else {
00412                 *sigma = 0.;
00413                 *epsilon = 0.;
00414                 *sigma14 = 0.;
00415                 *epsilon14 = 0.;
00416             }
00417         }
00418 
00419         int get_vdw_pair_params(Index ind1, Index ind2, Real *, Real *, Real *, Real *);
00420                                                 //  Find a vwd_pair parameter
00421 
00422         int get_num_vdw_params(void) { return NumVdwParamsAssigned; }
00423 
00424         //  The print_*_params are provided for debugging purposes
00425         void print_bond_params();               //  Print bonds params
00426         void print_angle_params();              //  Print angle params
00427         void print_dihedral_params();           //  Print dihedral params
00428         void print_improper_params();           //  Print improper params
00429         void print_crossterm_params();          //  Print cross-term params
00430         void print_vdw_params();                //  Print vdw params
00431         void print_vdw_pair_params();           //  Print vdw_pair params
00432         void print_param_summary();             //  Print a summary of params
00433 };
00434 
00435 #endif
00436 

Generated on Fri Sep 5 04:07:15 2008 for NAMD by  doxygen 1.3.9.1