| 1 |
#ifndef _INTEGRATOR_H_ |
| 2 |
#define _INTEGRATOR_H_ |
| 3 |
|
| 4 |
#include <string> |
| 5 |
#include <vector> |
| 6 |
#include "Atom.hpp" |
| 7 |
#include "Molecule.hpp" |
| 8 |
#include "SRI.hpp" |
| 9 |
#include "AbstractClasses.hpp" |
| 10 |
#include "SimInfo.hpp" |
| 11 |
#include "ForceFields.hpp" |
| 12 |
#include "Thermo.hpp" |
| 13 |
#include "ReadWrite.hpp" |
| 14 |
#include "ZConsWriter.hpp" |
| 15 |
|
| 16 |
using namespace std; |
| 17 |
const double kB = 8.31451e-7;// boltzmann constant amu*Ang^2*fs^-2/K |
| 18 |
const double eConvert = 4.184e-4; // converts kcal/mol -> amu*A^2/fs^2 |
| 19 |
const double p_convert = 1.63882576e8; //converts amu*fs^-2*Ang^-1 -> atm |
| 20 |
const int maxIteration = 300; |
| 21 |
const double tol = 1.0e-6; |
| 22 |
|
| 23 |
|
| 24 |
template<typename T = BaseIntegrator> class Integrator : public T { |
| 25 |
|
| 26 |
public: |
| 27 |
Integrator( SimInfo *theInfo, ForceFields* the_ff ); |
| 28 |
virtual ~Integrator(); |
| 29 |
void integrate( void ); |
| 30 |
|
| 31 |
|
| 32 |
protected: |
| 33 |
|
| 34 |
virtual void integrateStep( int calcPot, int calcStress ); |
| 35 |
virtual void preMove( void ); |
| 36 |
virtual void moveA( void ); |
| 37 |
virtual void moveB( void ); |
| 38 |
virtual void constrainA( void ); |
| 39 |
virtual void constrainB( void ); |
| 40 |
virtual int readyCheck( void ) { return 1; } |
| 41 |
|
| 42 |
void checkConstraints( void ); |
| 43 |
void rotate( int axes1, int axes2, double angle, double j[3], |
| 44 |
double A[3][3] ); |
| 45 |
|
| 46 |
|
| 47 |
ForceFields* myFF; |
| 48 |
|
| 49 |
SimInfo *info; // all the info we'll ever need |
| 50 |
int nAtoms; /* the number of atoms */ |
| 51 |
int oldAtoms; |
| 52 |
Atom **atoms; /* array of atom pointers */ |
| 53 |
Molecule* molecules; |
| 54 |
int nMols; |
| 55 |
|
| 56 |
int isConstrained; // boolean to know whether the systems contains |
| 57 |
// constraints. |
| 58 |
int nConstrained; // counter for number of constraints |
| 59 |
int *constrainedA; // the i of a constraint pair |
| 60 |
int *constrainedB; // the j of a constraint pair |
| 61 |
double *constrainedDsqr; // the square of the constraint distance |
| 62 |
|
| 63 |
int* moving; // tells whether we are moving atom i |
| 64 |
int* moved; // tells whether we have moved atom i |
| 65 |
double* oldPos; // pre constrained positions |
| 66 |
|
| 67 |
short isFirst; /*boolean for the first time integrate is called */ |
| 68 |
|
| 69 |
double dt; |
| 70 |
double dt2; |
| 71 |
|
| 72 |
Thermo *tStats; |
| 73 |
StatWriter* statOut; |
| 74 |
DumpWriter* dumpOut; |
| 75 |
|
| 76 |
}; |
| 77 |
|
| 78 |
typedef Integrator<BaseIntegrator> RealIntegrator; |
| 79 |
|
| 80 |
template<typename T> class NVE : public T { |
| 81 |
|
| 82 |
public: |
| 83 |
NVE ( SimInfo *theInfo, ForceFields* the_ff ): |
| 84 |
T( theInfo, the_ff ){} |
| 85 |
virtual ~NVE(){} |
| 86 |
}; |
| 87 |
|
| 88 |
|
| 89 |
template<typename T> class NVT : public T { |
| 90 |
|
| 91 |
public: |
| 92 |
|
| 93 |
NVT ( SimInfo *theInfo, ForceFields* the_ff); |
| 94 |
virtual ~NVT() {} |
| 95 |
|
| 96 |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
| 97 |
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
| 98 |
|
| 99 |
protected: |
| 100 |
|
| 101 |
virtual void moveA( void ); |
| 102 |
virtual void moveB( void ); |
| 103 |
|
| 104 |
virtual int readyCheck(); |
| 105 |
|
| 106 |
// chi is a propagated degree of freedom. |
| 107 |
|
| 108 |
double chi; |
| 109 |
|
| 110 |
// targetTemp must be set. tauThermostat must also be set; |
| 111 |
|
| 112 |
double targetTemp; |
| 113 |
double tauThermostat; |
| 114 |
|
| 115 |
short int have_tau_thermostat, have_target_temp; |
| 116 |
|
| 117 |
}; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
template<typename T> class NPTi : public T{ |
| 122 |
|
| 123 |
public: |
| 124 |
|
| 125 |
NPTi ( SimInfo *theInfo, ForceFields* the_ff); |
| 126 |
virtual ~NPTi() {}; |
| 127 |
|
| 128 |
virtual void integrateStep( int calcPot, int calcStress ){ |
| 129 |
calcStress = 1; |
| 130 |
T::integrateStep( calcPot, calcStress ); |
| 131 |
} |
| 132 |
|
| 133 |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
| 134 |
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
| 135 |
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
| 136 |
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
| 137 |
|
| 138 |
protected: |
| 139 |
|
| 140 |
virtual void moveA( void ); |
| 141 |
virtual void moveB( void ); |
| 142 |
|
| 143 |
virtual int readyCheck(); |
| 144 |
|
| 145 |
// chi and eta are the propagated degrees of freedom |
| 146 |
|
| 147 |
double chi; |
| 148 |
double eta; |
| 149 |
double NkBT; |
| 150 |
|
| 151 |
// targetTemp, targetPressure, and tauBarostat must be set. |
| 152 |
// One of qmass or tauThermostat must be set; |
| 153 |
|
| 154 |
double targetTemp; |
| 155 |
double targetPressure; |
| 156 |
double tauThermostat; |
| 157 |
double tauBarostat; |
| 158 |
|
| 159 |
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
| 160 |
short int have_target_pressure; |
| 161 |
|
| 162 |
}; |
| 163 |
|
| 164 |
template<typename T> class NPTim : public T{ |
| 165 |
|
| 166 |
public: |
| 167 |
|
| 168 |
NPTim ( SimInfo *theInfo, ForceFields* the_ff); |
| 169 |
virtual ~NPTim() {}; |
| 170 |
|
| 171 |
virtual void integrateStep( int calcPot, int calcStress ){ |
| 172 |
calcStress = 1; |
| 173 |
T::integrateStep( calcPot, calcStress ); |
| 174 |
} |
| 175 |
|
| 176 |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
| 177 |
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
| 178 |
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
| 179 |
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
| 180 |
|
| 181 |
protected: |
| 182 |
|
| 183 |
virtual void moveA( void ); |
| 184 |
virtual void moveB( void ); |
| 185 |
|
| 186 |
virtual int readyCheck(); |
| 187 |
|
| 188 |
Molecule* myMolecules; |
| 189 |
Atom** myAtoms; |
| 190 |
|
| 191 |
// chi and eta are the propagated degrees of freedom |
| 192 |
|
| 193 |
double chi; |
| 194 |
double eta; |
| 195 |
double NkBT; |
| 196 |
|
| 197 |
// targetTemp, targetPressure, and tauBarostat must be set. |
| 198 |
// One of qmass or tauThermostat must be set; |
| 199 |
|
| 200 |
double targetTemp; |
| 201 |
double targetPressure; |
| 202 |
double tauThermostat; |
| 203 |
double tauBarostat; |
| 204 |
|
| 205 |
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
| 206 |
short int have_target_pressure; |
| 207 |
|
| 208 |
}; |
| 209 |
|
| 210 |
template<typename T> class NPTf : public T{ |
| 211 |
|
| 212 |
public: |
| 213 |
|
| 214 |
NPTf ( SimInfo *theInfo, ForceFields* the_ff); |
| 215 |
virtual ~NPTf() {}; |
| 216 |
|
| 217 |
virtual void integrateStep( int calcPot, int calcStress ){ |
| 218 |
calcStress = 1; |
| 219 |
T::integrateStep( calcPot, calcStress ); |
| 220 |
} |
| 221 |
|
| 222 |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
| 223 |
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
| 224 |
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
| 225 |
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
| 226 |
|
| 227 |
protected: |
| 228 |
|
| 229 |
virtual void moveA( void ); |
| 230 |
virtual void moveB( void ); |
| 231 |
|
| 232 |
virtual int readyCheck(); |
| 233 |
|
| 234 |
// chi and eta are the propagated degrees of freedom |
| 235 |
|
| 236 |
double chi; |
| 237 |
double eta[3][3]; |
| 238 |
double NkBT; |
| 239 |
|
| 240 |
// targetTemp, targetPressure, and tauBarostat must be set. |
| 241 |
// One of qmass or tauThermostat must be set; |
| 242 |
|
| 243 |
double targetTemp; |
| 244 |
double targetPressure; |
| 245 |
double tauThermostat; |
| 246 |
double tauBarostat; |
| 247 |
|
| 248 |
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
| 249 |
short int have_target_pressure; |
| 250 |
|
| 251 |
}; |
| 252 |
|
| 253 |
template<typename T> class NPTfm : public T{ |
| 254 |
|
| 255 |
public: |
| 256 |
|
| 257 |
NPTfm ( SimInfo *theInfo, ForceFields* the_ff); |
| 258 |
virtual ~NPTfm() {}; |
| 259 |
|
| 260 |
virtual void integrateStep( int calcPot, int calcStress ){ |
| 261 |
calcStress = 1; |
| 262 |
T::integrateStep( calcPot, calcStress ); |
| 263 |
} |
| 264 |
|
| 265 |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
| 266 |
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
| 267 |
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
| 268 |
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
| 269 |
|
| 270 |
protected: |
| 271 |
|
| 272 |
virtual void moveA( void ); |
| 273 |
virtual void moveB( void ); |
| 274 |
|
| 275 |
virtual int readyCheck(); |
| 276 |
|
| 277 |
Molecule* myMolecules; |
| 278 |
Atom** myAtoms; |
| 279 |
|
| 280 |
// chi and eta are the propagated degrees of freedom |
| 281 |
|
| 282 |
double chi; |
| 283 |
double eta[3][3]; |
| 284 |
double NkBT; |
| 285 |
|
| 286 |
// targetTemp, targetPressure, and tauBarostat must be set. |
| 287 |
// One of qmass or tauThermostat must be set; |
| 288 |
|
| 289 |
double targetTemp; |
| 290 |
double targetPressure; |
| 291 |
double tauThermostat; |
| 292 |
double tauBarostat; |
| 293 |
|
| 294 |
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
| 295 |
short int have_target_pressure; |
| 296 |
|
| 297 |
}; |
| 298 |
|
| 299 |
template<typename T> class ZConstraint : public T { |
| 300 |
|
| 301 |
public: |
| 302 |
|
| 303 |
ZConstraint( SimInfo *theInfo, ForceFields* the_ff); |
| 304 |
~ZConstraint(); |
| 305 |
|
| 306 |
virtual void integrateStep( int calcPot, int calcStress ); |
| 307 |
|
| 308 |
|
| 309 |
void setZConsTime(double time) {this->zconsTime = time;} |
| 310 |
void getZConsTime() {return zconsTime;} |
| 311 |
|
| 312 |
void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;} |
| 313 |
void getIndexOfAllZConsMols() {return indexOfAllZConsMols;} |
| 314 |
|
| 315 |
void setZConsOutput(const char * fileName) {zconsOutput = fileName;} |
| 316 |
string getZConsOutput() {return zconsOutput;} |
| 317 |
|
| 318 |
#ifdef IS_MPI |
| 319 |
virtual void update(); //which is called to indicate the molecules' migration |
| 320 |
#endif |
| 321 |
|
| 322 |
protected: |
| 323 |
|
| 324 |
double zconsTime; |
| 325 |
|
| 326 |
void resetZ(void); |
| 327 |
|
| 328 |
vector<Molecule*> zconsMols; |
| 329 |
vector<double> massOfZConsMols; |
| 330 |
|
| 331 |
vector<Molecule*> unconsMols; |
| 332 |
vector<double> massOfUnconsMols; |
| 333 |
double totalMassOfUncons; |
| 334 |
|
| 335 |
vector<double> allRefZ; |
| 336 |
vector<double> refZ; |
| 337 |
|
| 338 |
vector<int> indexOfAllZConsMols; //index of All Z-Constraint Molecuels |
| 339 |
int* indexOfZConsMols; //index of local Z-Constraint Molecules |
| 340 |
|
| 341 |
double* fz; |
| 342 |
|
| 343 |
private: |
| 344 |
|
| 345 |
int isZConstraintMol(Molecule* mol); |
| 346 |
string zconsOutput; |
| 347 |
ZConsWriter* fzOut; |
| 348 |
}; |
| 349 |
|
| 350 |
#endif |