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

Molecule.h

Go to the documentation of this file.
00001 
00007 /*
00008    This class is used to store all of the structural       
00009    information for a simulation.  It reas in this information 
00010    from a .psf file, cross checks and obtains some information
00011    from the Parameters object that is passed in, and then     
00012    stores all this information for later use. 
00013 */
00014 
00015 
00016 #ifndef MOLECULE_H
00017 
00018 #define MOLECULE_H
00019 
00020 #include "parm.h"
00021 
00022 #include "common.h"
00023 #include "NamdTypes.h"
00024 #include "structures.h"
00025 #include "ConfigList.h"
00026 #include "Vector.h"
00027 #include "UniqueSet.h"
00028 #include "Hydrogen.h"
00029 #include "GromacsTopFile.h"
00030 /* BEGIN gf */
00031 #include "GridForceGrid.h"
00032 #include "Tensor.h"
00033 /* END gf */
00034 
00035 #include "molfile_plugin.h"
00036 
00037 #include <vector>
00038 using namespace std;
00039 
00040 class SimParameters;
00041 class Parameters;
00042 class ConfigList;
00043 class PDB;
00044 class MIStream;
00045 class MOStream;
00046 
00047 class ExclElem;
00048 class BondElem;
00049 class AngleElem;
00050 class DihedralElem;
00051 class ImproperElem;
00052 class CrosstermElem;
00053 class ResidueLookupElem;
00054 template<class Type> class ObjectArena;
00055 
00056 class ExclusionCheck {
00057 public:
00058   int32 min,max;
00059   char *flags;
00060 
00061   ExclusionCheck(){
00062       min=0;
00063       max=-1;
00064       flags = NULL;
00065   }
00066   ExclusionCheck(const ExclusionCheck& chk){
00067       min = chk.min;
00068       max = chk.max;
00069       if(max>min){ 
00070         flags = new char[max-min+1];
00071         memcpy(flags, chk.flags, sizeof(char)*(max-min+1));
00072       }
00073   }
00074   ExclusionCheck &operator=(const ExclusionCheck& chk){
00075     min = chk.min;
00076     max = chk.max;
00077     if(flags) delete [] flags;
00078     flags = NULL;
00079     if(max>min){
00080         flags = new char[max-min+1];
00081         memcpy(flags, chk.flags, sizeof(char)*(max-min+1));
00082     }
00083     return *this;
00084   }
00085   ~ExclusionCheck(){
00086       if(flags) delete [] flags;
00087   }
00088 };
00089 #define EXCHCK_FULL 1
00090 #define EXCHCK_MOD 2
00091 
00092 //only used for compressing the molecule information
00093 typedef struct seg_resid
00094 {
00095     char segname[11];
00096     int resid;
00097 }AtomSegResInfo;
00098 
00099 // List maintaining the global atom indicies sorted by helix groups.
00100 class Molecule
00101 {
00102 typedef struct constraint_params
00103 {
00104    Real k;    //  Force constant
00105    Vector refPos; //  Reference position for restraint
00106 } ConstraintParams;
00107 
00108 
00109 
00110 /* BEGIN gf */
00111 typedef struct gridfrc_params
00112 {
00113     Real k;     // force multiplier
00114     Charge q;   // charge
00115 } GridforceParams;
00116 /* END gf */
00117 
00118 
00119 typedef struct stir_params
00120 {
00121   Real startTheta;
00122   Vector refPos;  //  Reference position for stirring
00123 } StirParams;
00124 
00125 typedef struct movdrag_params
00126 {
00127   Vector v;            //  Linear velocity (A/step)
00128 } MovDragParams;
00129 
00130 
00131 typedef struct rotdrag_params
00132 {
00133    Real v;              //  Angular velocity (deg/step)
00134    Vector a;            //  Rotation axis
00135    Vector p;            //  Rotation pivot point
00136 } RotDragParams;
00137 
00138 typedef struct constorque_params
00139 {
00140    Real v;              //  "Torque" value (Kcal/(mol*A^2))
00141    Vector a;            //  Rotation axis
00142    Vector p;            //  Rotation pivot point
00143 } ConsTorqueParams;
00144 
00145 friend class ExclElem;
00146 friend class BondElem;
00147 friend class AngleElem;
00148 friend class DihedralElem;
00149 friend class ImproperElem;
00150 friend class CrosstermElem;
00151 
00152 private:
00153   void initialize(SimParameters *, Parameters *param);
00154             // Sets most data to zero
00155 
00156   #ifdef MEM_OPT_VERSION 
00157   //Indexing to constant pools to save space
00158   AtomCstInfo *atoms;
00159   Index *eachAtomMass; //after initialization, this could be freed (possibly)
00160   Index *eachAtomCharge; //after initialization, this could be freed (possibly)
00161   AtomNameIdx *atomNames;
00162   ObjectArena<char> *nameArena; //the space for names to be allocated  
00163   #else
00164   Atom *atoms;    //  Array of atom structures
00165   ObjectArena<char> *nameArena;
00166   AtomNameInfo *atomNames;//  Array of atom name info.  Only maintained on node 0 for VMD interface
00167   #endif
00168 
00169   ResidueLookupElem *resLookup; // find residues by name
00170 
00171   AtomSegResInfo *atomSegResids; //only used for generating compressed molecule info
00172 
00173   #ifndef MEM_OPT_VERSION
00174   //replaced by atom signatures
00175   Bond *bonds;    //  Array of bond structures
00176   Angle *angles;    //  Array of angle structures
00177   Dihedral *dihedrals;  //  Array of dihedral structures
00178   Improper *impropers;  //  Array of improper structures                          
00179   Crossterm *crossterms;  //  Array of cross-term structures
00180   #endif
00181   
00182   Bond *donors;         //  Array of hydrogen bond donor structures
00183   Bond *acceptors;  //  Array of hydrogen bond acceptor
00184 
00185   #ifndef MEM_OPT_VERSION
00186   //These will be replaced by exclusion signatures
00187   Exclusion *exclusions;  //  Array of exclusion structures
00188   UniqueSet<Exclusion> exclusionSet;  //  Used for building
00189   #endif
00190 
00191   // DRUDE
00192   DrudeConst *drudeConsts;  // supplement Atom data (length of Atom array)
00193   Aniso *anisos;            // anisotropic terms
00194   Lphost *lphosts;          // lone pair hosts
00195   int32 *lphostIndexes;     // index for each LP into lphosts array
00196   // DRUDE
00197 
00198   int32 *consIndexes; //  Constraint indexes for each atom
00199   ConstraintParams *consParams;
00200 
00201 /* BEGIN gf */
00202   int32 **gridfrcIndexes;
00203   GridforceParams **gridfrcParams;
00204   GridforceGrid **gridfrcGrid;
00205 /* END gf */
00206 
00207         //  Parameters for each atom constrained
00208   int32 *stirIndexes; //Stirring indexes for each atoms
00209   StirParams *stirParams;
00210                           // Paramters for each atoms stirred
00211   int32 *movDragIndexes;  //  Moving drag indexes for each atom
00212   MovDragParams *movDragParams;
00213                                 //  Parameters for each atom moving-dragged
00214   int32 *rotDragIndexes;  //  Rotating drag indexes for each atom
00215   RotDragParams *rotDragParams;
00216                                 //  Parameters for each atom rotation-dragged
00217 
00218   Real *langevinParams;   //  b values for langevin dynamics
00219   int32 *fixedAtomFlags;  //  1 for fixed, -1 for fixed group, else 0
00220   int32 *exPressureAtomFlags; // 1 for excluded, -1 for excluded group.
00221 
00222   #ifdef MEM_OPT_VERSION  
00223   //A generally true assumption: all atoms are arranged in the order of clusters. In other words,
00224   //all atoms for a cluster must appear before/after any atoms in other clusters
00225   //The first atom in the cluster (which has the lowest atom id) stores the cluster size
00226   //other atoms in the cluster stores -1
00227   int32 *clusterSigs;
00228   int32 numClusters;
00229   //indicate whether the atom ids of a cluster are contiguous. If not, then
00230   //the general true assumption above mentioned will not hold. 
00231   int32 isClusterContiguous;
00232   #else
00233         int32 *cluster;   //  first atom of connected cluster
00234   #endif
00235   //In the memory optimized version: it will be NULL if the general
00236   //true assumption mentioned above holds. If not, its size is numClusters.
00237   //In the ordinary version: its size is numAtoms, and indicates the size
00238   //of connected cluster or 0.
00239   int32 *clusterSize;
00240                             // 
00241         Real *rigidBondLengths;  //  if H, length to parent or 0. or
00242         //  if not H, length between children or 0.
00243 //fepb
00244         unsigned char *fepAtomFlags; 
00245 //fepe
00246 
00247 #ifndef MEM_OPT_VERSION
00248   ObjectArena<int32> *tmpArena;
00249   int32 **bondsWithAtom;  //  List of bonds involving each atom
00250   ObjectArena<int32> *arena;
00251 #endif
00252 
00253 #ifdef MEM_OPT_VERSION
00254   Index *eachAtomSig;
00255   Index *eachAtomExclSig;
00256 #else
00257 //function is replaced by atom signatures
00258   int32 **bondsByAtom;  //  List of bonds owned by each atom
00259   int32 **anglesByAtom;     //  List of angles owned by each atom
00260   int32 **dihedralsByAtom;  //  List of dihedrals owned by each atom
00261   int32 **impropersByAtom;  //  List of impropers owned by each atom
00262   int32 **crosstermsByAtom;  //  List of crossterms owned by each atom
00263     
00264   int32 **exclusionsByAtom; //  List of exclusions owned by each atom
00265   int32 **fullExclusionsByAtom; //  List of atoms excluded for each atom
00266   int32 **modExclusionsByAtom; //  List of atoms modified for each atom
00267   ObjectArena<char> *exclArena;
00268   ExclusionCheck *all_exclusions;
00269 #endif
00270 
00271 
00272   //occupancy and bfactor data from plugin-based IO implementation of loading structures
00273   float *occupancy;
00274   float *bfactor;
00275 
00276         //  List of all exclusions, including
00277         //  explicit exclusions and those calculated
00278         //  from the bonded structure based on the
00279         //  exclusion policy.  Also includes 1-4's.
00280 
00281   void build_lists_by_atom();
00282         //  Build the list of structures by atom
00283   
00284 
00285   void read_atoms(FILE *, Parameters *);
00286         //  Read in atom info from .psf
00287   void read_bonds(FILE *, Parameters *);
00288         //  Read in bond info from .psf
00289   void read_angles(FILE *, Parameters *);
00290         //  Read in angle info from .psf
00291   void read_dihedrals(FILE *, Parameters *);
00292         //  Read in dihedral info from .psf
00293   void read_impropers(FILE *, Parameters *);
00294         //  Read in improper info from .psf
00295   void read_crossterms(FILE *, Parameters *);
00296         //  Read in cross-term info from .psf
00297   void read_donors(FILE *);
00298         //  Read in hydrogen bond donors from .psf
00299   void read_acceptors(FILE *);
00300         //  Read in hydrogen bond acceptors from .psf
00301   void read_exclusions(FILE *);
00302         //  Read in exclusion info from .psf
00303 
00304   // DRUDE: PSF reading
00305   void read_lphosts(FILE *);
00306         //  Read in lone pair hosts from Drude PSF
00307   void read_anisos(FILE *);
00308         //  Read in anisotropic terms from Drude PSF
00309   // DRUDE
00310 
00311   //pluginIO-based loading atoms' structure
00312   void plgLoadAtomBasics(molfile_atom_t *atomarray);
00313   void plgLoadBonds(int *from, int *to); //atom index is 1-based in the parameters
00314   void plgLoadAngles(int *plgAngles);
00315   void plgLoadDihedrals(int *plgDihedrals);
00316   void plgLoadImpropers(int *plgImpropers);
00317   void plgLoadCrossterms(int *plgCterms);
00318 
00319 
00320   void build12excl(void);
00321   void build13excl(void);
00322   void build14excl(int);
00323   void stripHGroupExcl(void);
00324 
00325   // DRUDE: extend exclusions for Drude and LP
00326   void build_inherited_excl(void);
00327   // DRUDE
00328   #ifdef MEM_OPT_VERSION
00329   void stripFepFixedExcl(void);
00330   #else
00331   void stripFepExcl(void);
00332   #endif
00333 
00334   void build_exclusions();
00335 
00336   // analyze the atoms, and determine which are oxygen, hb donors, etc.
00337   // this is called after a molecule is sent our (or received in)
00338   void build_atom_status(void);
00339 
00340   // added during the trasition from 1x to 2
00341   SimParameters *simParams;
00342   Parameters *params;
00343 
00344   void read_parm(const GromacsTopFile *);  
00345 
00346 public:
00347   // DRUDE: flag for reading Drude PSF
00348   int is_drude_psf;
00349   // DRUDE
00350 
00351   // data for TIP4P
00352   Real r_om;
00353   Real r_ohc;
00354 
00355   // data for tail corrections
00356   BigReal tail_corr_ener;
00357   BigReal tail_corr_virial;
00358 
00359 
00360 
00361 #ifdef MEM_OPT_VERSION
00362   AtomCstInfo *getAtoms() const { return atoms; }
00363   AtomNameIdx *getAtomNames() const { return atomNames; }
00364 #else
00365   Atom *getAtoms () const { return atoms; }
00366   AtomNameInfo *getAtomNames() const { return atomNames; }
00367 #endif
00368 
00369   AtomSegResInfo *getAtomSegResInfo() const { return atomSegResids; }
00370   
00371   // return number of fixed atoms, guarded by SimParameters
00372   int num_fixed_atoms() const {
00373     // local variables prefixed by s_
00374     int s_NumFixedAtoms = (simParams->fixedAtomsOn ? numFixedAtoms : 0);
00375     return s_NumFixedAtoms;  // value is "turned on" SimParameters
00376   }
00377 
00378   int num_fixed_groups() const {
00379     // local variables prefixed by s_
00380     int s_NumFixedAtoms = num_fixed_atoms();
00381     int s_NumFixedGroups = (s_NumFixedAtoms ? numFixedGroups : 0);
00382     return s_NumFixedGroups;  // value is "turned on" SimParameters
00383   }
00384 
00385   int num_group_deg_freedom() const {
00386     // local variables prefixed by s_
00387     int s_NumGroupDegFreedom = 3 * numHydrogenGroups;
00388     int s_NumFixedAtoms = num_fixed_atoms();
00389     int s_NumFixedGroups = num_fixed_groups();
00390     if (s_NumFixedGroups) s_NumGroupDegFreedom -= 3 * s_NumFixedGroups;
00391     if ( ! (s_NumFixedAtoms || numConstraints
00392           || simParams->comMove || simParams->langevinOn) ) {
00393       s_NumGroupDegFreedom -= 3;
00394     }
00395     return s_NumGroupDegFreedom;
00396   }
00397 
00398   int num_deg_freedom(int isInitialReport = 0) const {
00399     // local variables prefixed by s_
00400     int s_NumDegFreedom = 3 * numAtoms;
00401     int s_NumFixedAtoms = num_fixed_atoms();
00402     if (s_NumFixedAtoms) s_NumDegFreedom -= 3 * s_NumFixedAtoms;
00403     if (numLonepairs) s_NumDegFreedom -= 3 * numLonepairs;
00404     if ( ! (s_NumFixedAtoms || numConstraints
00405           || simParams->comMove || simParams->langevinOn) ) {
00406       s_NumDegFreedom -= 3;
00407     }
00408     if ( ! isInitialReport && simParams->pairInteractionOn) {
00409       //
00410       // DJH: a kludge?  We want to initially report system degrees of freedom
00411       //
00412       // this doesn't attempt to deal with fixed atoms or constraints
00413       s_NumDegFreedom = 3 * numFepInitial;
00414     }
00415     int s_NumFixedRigidBonds = 
00416       (simParams->fixedAtomsOn ? numFixedRigidBonds : 0);
00417     // numLonepairs is subtracted here because all lonepairs have a rigid bond
00418     // to oxygen, but all of the LP degrees of freedom are dealt with above
00419     s_NumDegFreedom -= (numRigidBonds - s_NumFixedRigidBonds - numLonepairs);
00420     return s_NumDegFreedom;
00421   }
00422 
00423   int numAtoms;   //  Number of atoms                   
00424 
00425   int numRealBonds;   //  Number of bonds for exclusion determination
00426   int numBonds;   //  Number of bonds calculated, including extras
00427   int numAngles;    //  Number of angles
00428   int numDihedrals; //  Number of dihedrals
00429   int suspiciousAlchBonds;    //  angles dropped due to crossing FEP partitions
00430   int alchDroppedAngles;    //  angles dropped due to crossing FEP partitions
00431   int alchDroppedDihedrals; //  dihedrals dropped due to crossing FEP partitions
00432   int alchDroppedImpropers; //  impropers dropped due to crossing FEP partitions
00433   int numImpropers; //  Number of impropers
00434   int numCrossterms; //  Number of cross-terms
00435   int numDonors;          //  Number of hydrogen bond donors
00436   int numAcceptors; //  Number of hydrogen bond acceptors
00437   int numExclusions;  //  Number of exclusions
00438   int numTotalExclusions; //  Real Total Number of Exclusions // hack
00439 
00440   // DRUDE
00441   int numLonepairs; // Number of lone pairs
00442   int numDrudeAtoms;  // Number of Drude particles
00443   int numAnisos;  // Number of anisotropic terms
00444   int numLphosts;  // Number of lone pair hosts
00445   // DRUDE
00446   
00447   int numConstraints; //  Number of atoms constrained
00448 /* BEGIN gf */
00449   int numGridforceGrids;//  Number of gridforce grids
00450   int *numGridforces;   //  Number of atoms in gridforce file (array, one per grid)
00451 /* END gf */
00452   int numMovDrag;         //  Number of atoms moving-dragged
00453   int numRotDrag;         //  Number of atoms rotating-dragged
00454   int numConsTorque;  //  Number of atoms "constant"-torqued
00455   int numFixedAtoms;  //  Number of fixed atoms
00456   int numStirredAtoms;  //  Number of stirred atoms
00457   int numExPressureAtoms; //  Number of atoms excluded from pressure
00458   int numHydrogenGroups;  //  Number of hydrogen groups
00459   int numFixedGroups; //  Number of totally fixed hydrogen groups
00460   int numRigidBonds;  //  Number of rigid bonds
00461   int numFixedRigidBonds; //  Number of rigid bonds between fixed atoms
00462 //fepb
00463         int numFepInitial;  // no. of fep atoms with initial flag
00464         int numFepFinal;  // no. of fep atoms with final flag
00465 //fepe
00466 
00467   int numConsForce; //  Number of atoms that have constant force applied
00468   int32 *consForceIndexes;//  Constant force indexes for each atom
00469   Vector *consForce;  //  Constant force array
00470 
00471   int32 *consTorqueIndexes; //  "Constant" torque indexes for each atom
00472   ConsTorqueParams *consTorqueParams;
00473                                 //  Parameters for each atom "constant"-torqued
00474 
00475   // The following are needed for error checking because we
00476   // eliminate bonds, etc. which involve only fixed atoms
00477   int numCalcBonds; //  Number of bonds requiring calculation
00478   int numCalcAngles;  //  Number of angles requiring calculation
00479   int numCalcDihedrals; //  Number of dihedrals requiring calculation
00480   int numCalcImpropers; //  Number of impropers requiring calculation
00481   int numCalcCrossterms; //  Number of cross-terms requiring calculation
00482   int numCalcExclusions;  //  Number of exclusions requiring calculation
00483 
00484   //  Number of dihedrals with multiple periodicity
00485   int numMultipleDihedrals; 
00486   //  Number of impropers with multiple periodicity
00487   int numMultipleImpropers; 
00488   // indexes of "atoms" sorted by hydrogen groups
00489   HydrogenGroup hydrogenGroup;
00490   int waterIndex;
00491 
00492   Molecule(SimParameters *, Parameters *param);
00493   Molecule(SimParameters *, Parameters *param, char *filename, ConfigList *cfgList=NULL);  
00494   Molecule(SimParameters *simParams, Parameters *param, molfile_plugin_t *pIOHdl, void *pIOFileHdl, int natoms);
00495   
00496   Molecule(SimParameters *, Parameters *, Ambertoppar *);
00497   void read_parm(Ambertoppar *);
00498 
00499   Molecule(SimParameters *, Parameters *, const GromacsTopFile *);
00500 
00501   ~Molecule();    //  Destructor
00502 
00503   void read_psf_file(char *, Parameters *);
00504         //  Read in a .psf file given
00505         //  the filename and the parameter
00506         //  object to use  
00507 
00508   void send_Molecule(MOStream *);
00509         //  send the molecular structure 
00510         //  from the master to the clients
00511   void receive_Molecule(MIStream *);
00512         //  receive the molecular structure
00513         //  from the master on a client
00514   
00515   void build_constraint_params(StringList *, StringList *, StringList *,
00516              PDB *, char *);
00517         //  Build the set of harmonic constraint 
00518         // parameters
00519 
00520 /* BEGIN gf */
00521   void build_gridforce_params(StringList *, StringList *, StringList *, StringList *, PDB *, char *);
00522         //  Build the set of gridForce-style force pars
00523 /* END gf */
00524 
00525   void build_movdrag_params(StringList *, StringList *, StringList *, 
00526           PDB *, char *);
00527         //  Build the set of moving drag pars
00528 
00529   void build_rotdrag_params(StringList *, StringList *, StringList *,
00530           StringList *, StringList *, StringList *,
00531           PDB *, char *);
00532         //  Build the set of rotating drag pars
00533 
00534   void build_constorque_params(StringList *, StringList *, StringList *,
00535              StringList *, StringList *, StringList *,
00536              PDB *, char *);
00537         //  Build the set of "constant" torque pars
00538 
00539 
00540   void build_constant_forces(char *);
00541         //  Build the set of constant forces
00542 
00543   void build_langevin_params(BigReal coupling, Bool doHydrogen);
00544   void build_langevin_params(StringList *, StringList *, PDB *, char *);
00545         //  Build the set of langevin dynamics parameters
00546 
00547   void build_fixed_atoms(StringList *, StringList *, PDB *, char *);
00548         //  Determine which atoms are fixed (if any)
00549 
00550   void build_stirred_atoms(StringList *, StringList *, PDB *, char *);
00551         //  Determine which atoms are stirred (if any)
00552 
00553   void build_extra_bonds(Parameters *parameters, StringList *file);
00554 
00555 //fepb
00556         void build_fep_flags(StringList *, StringList *, PDB *, char *);
00557                                // selection of the mutant atoms
00558         void delete_alch_bonded(void);
00559 //fepe
00560 
00561   void build_exPressure_atoms(StringList *, StringList *, PDB *, char *);
00562         //  Determine which atoms are excluded from
00563                                 //  pressure (if any)
00564 
00565   void reloadCharges(float charge[], int n);
00566 
00567         Bool is_lp(int);     // return true if atom is a lone pair
00568         Bool is_drude(int);     // return true if atom is a Drude particle
00569         Bool is_hydrogen(int);     // return true if atom is hydrogen
00570         Bool is_oxygen(int);       // return true if atom is oxygen
00571   Bool is_hydrogenGroupParent(int); // return true if atom is group parent
00572   Bool is_water(int);        // return true if atom is part of water 
00573   int  get_groupSize(int);     // return # atoms in (hydrogen) group
00574         int get_mother_atom(int);  // return mother atom of a hydrogen
00575 
00576   #ifdef MEM_OPT_VERSION
00577   //the way to get the cluster size if the atom ids of the cluster are
00578   //contiguous. The input parameter is the atom id that leads the cluster.
00579   int get_cluster_size_con(int aid) const { return clusterSigs[aid]; }  
00580   //the way to get the cluster size if the atoms ids of the cluster are
00581   //not contiguous. The input parameter is the cluster index.
00582   int get_cluster_size_uncon(int cIdx) const { return clusterSize[cIdx]; }
00583   int get_cluster_idx(int aid) const { return clusterSigs[aid]; }
00584   int get_num_clusters() const { return numClusters; }
00585   int get_cluster_contiguity() { return isClusterContiguous; }
00586   #else
00587   int get_cluster(int anum) const { return cluster[anum]; }
00588   int get_clusterSize(int anum) const { return clusterSize[anum]; }
00589   #endif
00590 
00591   const float *getOccupancyData() { return (const float *)occupancy; }
00592   void setOccupancyData(molfile_atom_t *atomarray);
00593   void freeOccupancyData() { delete [] occupancy; occupancy=NULL; }
00594 
00595   const float *getBFactorData() { return (const float *)bfactor; }
00596   void setBFactorData(molfile_atom_t *atomarray);
00597   void freeBFactorData() { delete [] bfactor; bfactor=NULL; }
00598 
00599   #ifdef CHARMIZE_NAMD
00600   Atom *getAllAtoms() {
00601       return atoms;
00602   }
00603   #endif
00604 
00605   //  Get the mass of an atom
00606   Real atommass(int anum) const
00607   {
00608     #ifdef MEM_OPT_VERSION
00609     return atomMassPool[eachAtomMass[anum]];
00610     #else
00611     return(atoms[anum].mass);
00612     #endif
00613   }
00614 
00615   //  Get the charge of an atom
00616   Real atomcharge(int anum) const
00617   {
00618     #ifdef MEM_OPT_VERSION
00619     return atomChargePool[eachAtomCharge[anum]];
00620     #else
00621     return(atoms[anum].charge);
00622     #endif
00623   }
00624   
00625   //  Get the vdw type of an atom
00626   Index atomvdwtype(int anum) const
00627   {      
00628       return(atoms[anum].vdw_type);
00629   }
00630 
00631   #ifndef MEM_OPT_VERSION
00632   //  Retrieve a bond structure
00633   Bond *get_bond(int bnum) const {return (&(bonds[bnum]));}
00634 
00635   //  Retrieve an angle structure
00636   Angle *get_angle(int anum) const {return (&(angles[anum]));}
00637 
00638   //  Retrieve an improper strutcure
00639   Improper *get_improper(int inum) const {return (&(impropers[inum]));}
00640 
00641   //  Retrieve a dihedral structure
00642   Dihedral *get_dihedral(int dnum) const {return (&(dihedrals[dnum]));}
00643 
00644   //  Retrieve a cross-term strutcure
00645   Crossterm *get_crossterm(int inum) const {return (&(crossterms[inum]));}
00646 
00647   // DRUDE: retrieve lphost structure
00648   Lphost *get_lphost(int atomid) const {
00649     int index = lphostIndexes[atomid];
00650     return (index != -1 ? &(lphosts[index]) : NULL);
00651   }
00652   // DRUDE
00653 
00654   Bond *getAllBonds() const {return bonds;}
00655   Angle *getAllAngles() const {return angles;}
00656   Improper *getAllImpropers() const {return impropers;}
00657   Dihedral *getAllDihedrals() const {return dihedrals;}
00658   Crossterm *getAllCrossterms() const {return crossterms;}
00659 
00660   // DRUDE: retrieve entire lphosts array
00661   Lphost *getAllLphosts() const { return lphosts; }
00662   // DRUDE
00663   #endif
00664 
00665   //  Retrieve a hydrogen bond donor structure
00666   Bond *get_donor(int dnum) const {return (&(donors[dnum]));}  
00667 
00668   //  Retrieve a hydrogen bond acceptor structure
00669   Bond *get_acceptor(int dnum) const {return (&(acceptors[dnum]));} 
00670 
00671   Bond *getAllDonors() const {return donors;}
00672   Bond *getAllAcceptors() const {return acceptors;}
00673 
00674   //  Retrieve an exclusion structure
00675   #ifndef MEM_OPT_VERSION
00676   Exclusion *get_exclusion(int ex) const {return (&(exclusions[ex]));}
00677   #endif
00678 
00679   //  Retrieve an atom type
00680   const char *get_atomtype(int anum) const
00681   {
00682     if (atomNames == NULL)
00683     {
00684       NAMD_die("Tried to find atom type on node other than node 0");
00685     }
00686 
00687     #ifdef MEM_OPT_VERSION    
00688     return atomTypePool[atomNames[anum].atomtypeIdx];
00689     #else
00690     return(atomNames[anum].atomtype);
00691     #endif
00692   }
00693 
00694   //  Lookup atom id from segment, residue, and name
00695   int get_atom_from_name(const char *segid, int resid, const char *aname) const;
00696 
00697   //  Lookup number of atoms in residue from segment and residue
00698   int get_residue_size(const char *segid, int resid) const;
00699 
00700   //  Lookup atom id from segment, residue, and index in residue
00701   int get_atom_from_index_in_residue(const char *segid, int resid, int index) const;
00702 
00703   
00704   //  The following routines are used to get the list of bonds
00705   //  for a given atom.  This is used when creating the bond lists
00706   //  for the force objects  
00707 
00708   #ifndef MEM_OPT_VERSION
00709   int32 *get_bonds_for_atom(int anum)
00710       { return bondsByAtom[anum]; } 
00711   int32 *get_angles_for_atom(int anum) 
00712       { return anglesByAtom[anum]; }
00713   int32 *get_dihedrals_for_atom(int anum) 
00714       { return dihedralsByAtom[anum]; }
00715   int32 *get_impropers_for_atom(int anum) 
00716       { return impropersByAtom[anum]; }  
00717   int32 *get_crossterms_for_atom(int anum) 
00718       { return crosstermsByAtom[anum]; }  
00719   int32 *get_exclusions_for_atom(int anum)
00720       { return exclusionsByAtom[anum]; }
00721   const int32 *get_full_exclusions_for_atom(int anum) const
00722       { return fullExclusionsByAtom[anum]; }
00723   const int32 *get_mod_exclusions_for_atom(int anum) const
00724       { return modExclusionsByAtom[anum]; }
00725   #endif
00726   
00727   //  Check for exclusions, either explicit or bonded.
00728         //  Returns 1 for full, 2 for 1-4 exclusions.
00729   #ifdef MEM_OPT_VERSION
00730   int checkExclByIdx(int idx1, int atom1, int atom2) const;
00731   const ExclusionCheck *get_excl_check_for_idx(int idx) const{      
00732       return &exclChkSigPool[idx];
00733   }
00734   #else
00735   int checkexcl(int atom1, int atom2) const;
00736 
00737   const ExclusionCheck *get_excl_check_for_atom(int anum) const{      
00738       return &all_exclusions[anum];             
00739   }
00740   #endif
00741 
00742 /* BEGIN gf */
00743   // Return true or false based on whether or not the atom
00744   // is subject to grid force
00745   Bool is_atom_gridforced(int atomnum, int gridnum) const
00746   {
00747       if (numGridforceGrids)
00748       {
00749           return(gridfrcIndexes[gridnum][atomnum] != -1);
00750       }
00751       else
00752       {
00753           return(FALSE);
00754       }
00755   }
00756 /* END gf */
00757 
00758   //  Return true or false based on whether the specified atom
00759   //  is constrained or not.
00760   Bool is_atom_constrained(int atomnum) const
00761   {
00762     if (numConstraints)
00763     {
00764       //  Check the index to see if it is constrained
00765       return(consIndexes[atomnum] != -1);
00766     }
00767     else
00768     {
00769       //  No constraints at all, so just return FALSE
00770       return(FALSE);
00771     }
00772   }
00773 
00774   //  Return true or false based on whether the specified atom
00775   //  is moving-dragged or not.
00776   Bool is_atom_movdragged(int atomnum) const
00777   {
00778     if (numMovDrag)
00779     {
00780       //  Check the index to see if it is constrained
00781       return(movDragIndexes[atomnum] != -1);
00782     }
00783     else
00784     {
00785       //  No constraints at all, so just return FALSE
00786       return(FALSE);
00787     }
00788   }
00789 
00790   //  Return true or false based on whether the specified atom
00791   //  is rotating-dragged or not.
00792   Bool is_atom_rotdragged(int atomnum) const
00793   {
00794     if (numRotDrag)
00795     {
00796       //  Check the index to see if it is constrained
00797       return(rotDragIndexes[atomnum] != -1);
00798     }
00799     else
00800     {
00801       //  No constraints at all, so just return FALSE
00802       return(FALSE);
00803     }
00804   }
00805 
00806   //  Return true or false based on whether the specified atom
00807   //  is "constant"-torqued or not.
00808   Bool is_atom_constorqued(int atomnum) const
00809   {
00810     if (numConsTorque)
00811     {
00812       //  Check the index to see if it is constrained
00813       return(consTorqueIndexes[atomnum] != -1);
00814     }
00815     else
00816     {
00817       //  No constraints at all, so just return FALSE
00818       return(FALSE);
00819     }
00820   }
00821 
00822   //  Get the harmonic constraints for a specific atom
00823   void get_cons_params(Real &k, Vector &refPos, int atomnum) const
00824   {
00825     k = consParams[consIndexes[atomnum]].k;
00826     refPos = consParams[consIndexes[atomnum]].refPos;
00827   }
00828 
00829 /* BEGIN gf */
00830   void get_gridfrc_params(Real &k, Charge &q, int atomnum, int gridnum) const
00831   {
00832       k = gridfrcParams[gridnum][gridfrcIndexes[gridnum][atomnum]].k;
00833       q = gridfrcParams[gridnum][gridfrcIndexes[gridnum][atomnum]].q;
00834   }
00835   
00836   GridforceGrid* get_gridfrc_grid(int gridnum) const
00837   {
00838       return gridfrcGrid[gridnum];
00839   }
00840 /* END gf */
00841 
00842   Real langevin_param(int atomnum) const
00843   {
00844     return(langevinParams[atomnum]);
00845   }
00846 
00847   //  Get the stirring constraints for a specific atom
00848   void get_stir_refPos(Vector &refPos, int atomnum) const
00849   {
00850     refPos = stirParams[stirIndexes[atomnum]].refPos;
00851   }
00852 
00853 
00854   void put_stir_startTheta(Real theta, int atomnum) const
00855   {
00856     stirParams[stirIndexes[atomnum]].startTheta = theta;
00857   }
00858 
00859 
00860   Real get_stir_startTheta(int atomnum) const
00861   {
00862     return stirParams[stirIndexes[atomnum]].startTheta;
00863   }
00864  
00865 
00866   //  Get the moving drag factor for a specific atom
00867   void get_movdrag_params(Vector &v, int atomnum) const
00868   {
00869     v = movDragParams[movDragIndexes[atomnum]].v;
00870   }
00871 
00872   //  Get the rotating drag pars for a specific atom
00873   void get_rotdrag_params(BigReal &v, Vector &a, Vector &p, 
00874         int atomnum) const
00875   {
00876     v = rotDragParams[rotDragIndexes[atomnum]].v;
00877     a = rotDragParams[rotDragIndexes[atomnum]].a;
00878     p = rotDragParams[rotDragIndexes[atomnum]].p;
00879   }
00880 
00881   //  Get the "constant" torque pars for a specific atom
00882   void get_constorque_params(BigReal &v, Vector &a, Vector &p, 
00883         int atomnum) const
00884   {
00885     v = consTorqueParams[consTorqueIndexes[atomnum]].v;
00886     a = consTorqueParams[consTorqueIndexes[atomnum]].a;
00887     p = consTorqueParams[consTorqueIndexes[atomnum]].p;
00888   }
00889 
00890 //fepb
00891         unsigned char get_fep_type(int anum) const
00892         {
00893                 return(fepAtomFlags[anum]);
00894         }
00895 //fepe
00896 
00897   Bool is_atom_fixed(int atomnum) const
00898   {
00899     return (numFixedAtoms && fixedAtomFlags[atomnum]);
00900   }
00901 
00902         
00903   Bool is_atom_stirred(int atomnum) const
00904   {
00905     if (numStirredAtoms)
00906     {
00907       //  Check the index to see if it is constrained
00908       return(stirIndexes[atomnum] != -1);
00909     }
00910     else
00911     {
00912       //  No constraints at all, so just return FALSE
00913       return(FALSE);
00914     }
00915   }
00916   
00917 
00918   Bool is_group_fixed(int atomnum) const
00919   {
00920     return (numFixedAtoms && (fixedAtomFlags[atomnum] == -1));
00921   }
00922   Bool is_atom_exPressure(int atomnum) const
00923   {
00924     return (numExPressureAtoms && exPressureAtomFlags[atomnum]);
00925   }
00926   // 0 if not rigid or length to parent, for parent refers to H-H length
00927   // < 0 implies MOLLY but not SHAKE, > 1 implies both if MOLLY is on
00928   Real rigid_bond_length(int atomnum) const
00929   {
00930     return(rigidBondLengths[atomnum]);
00931   }
00932 
00933   void print_atoms(Parameters *); 
00934         //  Print out list of atoms
00935   void print_bonds(Parameters *); 
00936         //  Print out list of bonds
00937   void print_exclusions();//  Print out list of exclusions
00938 
00939 private:
00940   //Read in a compressed .psf file (whose format is not standard) for
00941   //the sake of very very large simulations (say, 100M atoms system)
00942   void read_compressed_psf_file(char *, Parameters *, ConfigList *cfgList);   
00943 
00944 #ifdef MEM_OPT_VERSION
00945 public:  
00946   int atomSigPoolSize;
00947   AtomSignature *atomSigPool;
00948 
00949   /* All the following are temporary variables for reading the compressed psf file */
00950   //declarations for atoms' constant information  
00951   int segNamePoolSize; //Its value is usually less than 5
00952   char **segNamePool; //This seems not to be important, but it only occupied very little space.
00953 
00954   int resNamePoolSize;
00955   char **resNamePool;
00956 
00957   int atomNamePoolSize;
00958   char **atomNamePool;
00959 
00960   int atomTypePoolSize;
00961   char **atomTypePool;
00962 
00963   int chargePoolSize;
00964   Real *atomChargePool;
00965 
00966   int massPoolSize;
00967   Real *atomMassPool;
00968 
00969   AtomSigID getAtomSigId(int aid) {
00970       return eachAtomSig[aid]; 
00971   }
00972   ExclSigID getAtomExclSigId(int aid) const {
00973       return eachAtomExclSig[aid];
00974   }
00975 
00976   //Indicates the size of both exclSigPool and exclChkSigPool
00977   int exclSigPoolSize;
00978   //this will be deleted after build_lists_by_atom
00979   ExclusionSignature *exclSigPool;
00980   //This is the final data structure we want to store  
00981   ExclusionCheck *exclChkSigPool;
00982 
00983   void addNewExclSigPool(const vector<ExclusionSignature>&);
00984 
00985   void build_excl_check_signatures();
00986 
00987   void delEachAtomSigs(){    
00988       //for NAMD-smp version, only one Molecule object is held
00989       //on each node, therefore, only one deletion operation should
00990       //be taken on a node, otherwise, there possibly would be some
00991       //wierd memory problems. The same reason applies to other deletion
00992       //operations inside the Molecule object.   
00993       if(CmiMyRank()) return;
00994 
00995       delete [] eachAtomSig;
00996       delete [] eachAtomExclSig;
00997       eachAtomSig = NULL;
00998       eachAtomExclSig = NULL;
00999   }
01000 
01001   void delChargeSpace(){
01002       if(CmiMyRank()) return;
01003 
01004       delete [] atomChargePool;
01005       delete [] eachAtomCharge;
01006       atomChargePool = NULL;
01007       eachAtomCharge = NULL;
01008   }
01009   
01010   void delMassSpace(){
01011       if(CmiMyRank()) return;
01012 
01013       delete [] atomMassPool;
01014       delete [] eachAtomMass;
01015       atomMassPool = NULL;
01016       eachAtomMass = NULL;
01017   }
01018   
01019   void delClusterSigs() {
01020       if(CmiMyRank()) return;      
01021 
01022       delete [] clusterSigs;
01023       clusterSigs = NULL;
01024   }
01025 
01026   void delOtherEachAtomStructs();
01027 
01028 
01029 private:
01030   Index insert_new_mass(Real newMass);
01031   //void markClusterIdx(int curClusterIdx, int startAtomID);  
01032 
01033   //This function checks whether the exclusion (atom1 and atom2) will
01034   //be stripped by the original stripFepExcl function and by the fixed atoms.
01035   //When stripping exclusions in the stripHGroupExcl function (where we actually
01036   //not performing stripping but only deducting numCalcExclusions), we use
01037   //this function to avoid the repeated deduction. Only exclusions that are only
01038   //stripped due to hydrogen group is counted
01039   int exclStrippedByFepOrFixedAtoms(int atom1, int atom2);
01040 #endif
01041 
01042 };
01043 
01044 #endif
01045 

Generated on Sat Nov 7 04:07:48 2009 for NAMD by  doxygen 1.3.9.1