4 |
|
#include <string> |
5 |
|
#include <vector> |
6 |
|
#include "Atom.hpp" |
7 |
+ |
#include "StuntDouble.hpp" |
8 |
|
#include "Molecule.hpp" |
9 |
|
#include "SRI.hpp" |
10 |
|
#include "AbstractClasses.hpp" |
13 |
|
#include "Thermo.hpp" |
14 |
|
#include "ReadWrite.hpp" |
15 |
|
#include "ZConsWriter.hpp" |
16 |
+ |
#include "Restraints.hpp" |
17 |
|
|
18 |
|
using namespace std; |
19 |
|
const double kB = 8.31451e-7;// boltzmann constant amu*Ang^2*fs^-2/K |
22 |
|
const int maxIteration = 300; |
23 |
|
const double tol = 1.0e-6; |
24 |
|
|
23 |
– |
|
25 |
|
template<typename T = BaseIntegrator> class Integrator : public T { |
26 |
|
|
27 |
|
public: |
29 |
|
virtual ~Integrator(); |
30 |
|
void integrate( void ); |
31 |
|
virtual double getConservedQuantity(void); |
32 |
+ |
virtual string getAdditionalParameters(void); |
33 |
|
|
34 |
|
protected: |
35 |
|
|
42 |
|
virtual int readyCheck( void ) { return 1; } |
43 |
|
|
44 |
|
virtual void resetIntegrator( void ) { } |
45 |
< |
|
46 |
< |
virtual void calcForce( int calcPot, int calcStress ); |
45 |
> |
|
46 |
> |
virtual void calcForce( int calcPot, int calcStress ); |
47 |
|
virtual void thermalize(); |
46 |
– |
|
47 |
– |
virtual void rotationPropagation( DirectionalAtom* dAtom, double ji[3] ); |
48 |
|
|
49 |
+ |
virtual bool stopIntegrator() {return false;} |
50 |
+ |
|
51 |
+ |
virtual void rotationPropagation( StuntDouble* sd, double ji[3] ); |
52 |
+ |
|
53 |
|
void checkConstraints( void ); |
54 |
< |
void rotate( int axes1, int axes2, double angle, double j[3], |
54 |
> |
void rotate( int axes1, int axes2, double angle, double j[3], |
55 |
|
double A[3][3] ); |
56 |
< |
|
56 |
> |
|
57 |
|
ForceFields* myFF; |
58 |
|
|
59 |
|
SimInfo *info; // all the info we'll ever need |
60 |
+ |
vector<StuntDouble*> integrableObjects; |
61 |
|
int nAtoms; /* the number of atoms */ |
62 |
|
int oldAtoms; |
63 |
|
Atom **atoms; /* array of atom pointers */ |
66 |
|
|
67 |
|
int isConstrained; // boolean to know whether the systems contains |
68 |
|
// constraints. |
69 |
< |
int nConstrained; // counter for number of constraints |
70 |
< |
int *constrainedA; // the i of a constraint pair |
71 |
< |
int *constrainedB; // the j of a constraint pair |
72 |
< |
double *constrainedDsqr; // the square of the constraint distance |
73 |
< |
|
69 |
> |
int nConstrained; // counter for number of constraints |
70 |
> |
int *constrainedA; // the i of a constraint pair |
71 |
> |
int *constrainedB; // the j of a constraint pair |
72 |
> |
double *constrainedDsqr; // the square of the constraint distance |
73 |
> |
|
74 |
|
int* moving; // tells whether we are moving atom i |
75 |
|
int* moved; // tells whether we have moved atom i |
76 |
< |
double* oldPos; // pre constrained positions |
76 |
> |
double* oldPos; // pre constrained positions |
77 |
|
|
78 |
|
short isFirst; /*boolean for the first time integrate is called */ |
79 |
< |
|
79 |
> |
|
80 |
|
double dt; |
81 |
|
double dt2; |
82 |
|
|
83 |
|
Thermo *tStats; |
84 |
|
StatWriter* statOut; |
85 |
|
DumpWriter* dumpOut; |
86 |
< |
|
86 |
> |
|
87 |
|
}; |
88 |
|
|
89 |
|
typedef Integrator<BaseIntegrator> RealIntegrator; |
90 |
|
|
91 |
+ |
// ansi instantiation |
92 |
+ |
template class Integrator<BaseIntegrator>; |
93 |
+ |
|
94 |
|
template<typename T> class NVE : public T { |
95 |
|
|
96 |
|
public: |
97 |
|
NVE ( SimInfo *theInfo, ForceFields* the_ff ): |
98 |
|
T( theInfo, the_ff ){} |
99 |
< |
virtual ~NVE(){} |
99 |
> |
virtual ~NVE(){} |
100 |
|
}; |
101 |
|
|
102 |
|
|
111 |
|
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
112 |
|
void setChiTolerance(double tol) {chiTolerance = tol;} |
113 |
|
virtual double getConservedQuantity(void); |
114 |
+ |
virtual string getAdditionalParameters(void); |
115 |
|
|
116 |
|
protected: |
117 |
|
|
133 |
|
|
134 |
|
double targetTemp; |
135 |
|
double tauThermostat; |
136 |
< |
|
136 |
> |
|
137 |
|
short int have_tau_thermostat, have_target_temp; |
138 |
|
|
139 |
|
double *oldVel; |
152 |
|
|
153 |
|
NPT ( SimInfo *theInfo, ForceFields* the_ff); |
154 |
|
virtual ~NPT(); |
155 |
< |
|
155 |
> |
|
156 |
|
virtual void integrateStep( int calcPot, int calcStress ){ |
157 |
|
calcStress = 1; |
158 |
|
T::integrateStep( calcPot, calcStress ); |
159 |
|
} |
160 |
|
|
161 |
|
virtual double getConservedQuantity(void) = 0; |
162 |
+ |
virtual string getAdditionalParameters(void) = 0; |
163 |
+ |
|
164 |
+ |
double myTauThermo( void ) { return tauThermostat; } |
165 |
+ |
double myTauBaro( void ) { return tauBarostat; } |
166 |
|
|
167 |
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
168 |
|
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
183 |
|
|
184 |
|
virtual void getVelScaleA( double sc[3], double vel[3] ) = 0; |
185 |
|
virtual void getVelScaleB( double sc[3], int index ) = 0; |
186 |
< |
virtual void getPosScale(double pos[3], double COM[3], |
186 |
> |
virtual void getPosScale(double pos[3], double COM[3], |
187 |
|
int index, double sc[3]) = 0; |
188 |
|
|
189 |
+ |
virtual void calcVelScale( void ) = 0; |
190 |
+ |
|
191 |
|
virtual bool chiConverged( void ); |
192 |
|
virtual bool etaConverged( void ) = 0; |
193 |
< |
|
193 |
> |
|
194 |
|
virtual void evolveChiA( void ); |
195 |
|
virtual void evolveEtaA( void ) = 0; |
196 |
|
virtual void evolveChiB( void ); |
216 |
|
|
217 |
|
double integralOfChidt; |
218 |
|
|
219 |
< |
// targetTemp, targetPressure, and tauBarostat must be set. |
219 |
> |
// targetTemp, targetPressure, and tauBarostat must be set. |
220 |
|
// One of qmass or tauThermostat must be set; |
221 |
|
|
222 |
|
double targetTemp; |
241 |
|
}; |
242 |
|
|
243 |
|
template<typename T> class NPTi : public T{ |
244 |
< |
|
244 |
> |
|
245 |
|
public: |
246 |
|
NPTi( SimInfo *theInfo, ForceFields* the_ff); |
247 |
|
~NPTi(); |
248 |
|
|
249 |
|
virtual double getConservedQuantity(void); |
250 |
|
virtual void resetIntegrator(void); |
251 |
< |
|
251 |
> |
virtual string getAdditionalParameters(void); |
252 |
|
protected: |
253 |
|
|
239 |
– |
|
254 |
|
|
255 |
+ |
|
256 |
|
virtual void evolveEtaA(void); |
257 |
|
virtual void evolveEtaB(void); |
258 |
|
|
262 |
|
|
263 |
|
virtual void getVelScaleA( double sc[3], double vel[3] ); |
264 |
|
virtual void getVelScaleB( double sc[3], int index ); |
265 |
< |
virtual void getPosScale(double pos[3], double COM[3], |
265 |
> |
virtual void getPosScale(double pos[3], double COM[3], |
266 |
|
int index, double sc[3]); |
267 |
|
|
268 |
+ |
virtual void calcVelScale( void ); |
269 |
+ |
|
270 |
|
double eta, oldEta, prevEta; |
271 |
+ |
double vScale; |
272 |
|
}; |
273 |
|
|
274 |
|
template<typename T> class NPTf : public T{ |
279 |
|
virtual ~NPTf(); |
280 |
|
|
281 |
|
virtual double getConservedQuantity(void); |
282 |
+ |
virtual string getAdditionalParameters(void); |
283 |
|
virtual void resetIntegrator(void); |
284 |
|
|
285 |
|
protected: |
293 |
|
|
294 |
|
virtual void getVelScaleA( double sc[3], double vel[3] ); |
295 |
|
virtual void getVelScaleB( double sc[3], int index ); |
296 |
< |
virtual void getPosScale(double pos[3], double COM[3], |
296 |
> |
virtual void getPosScale(double pos[3], double COM[3], |
297 |
|
int index, double sc[3]); |
298 |
|
|
299 |
+ |
virtual void calcVelScale( void ); |
300 |
+ |
|
301 |
|
double eta[3][3]; |
302 |
|
double oldEta[3][3]; |
303 |
|
double prevEta[3][3]; |
304 |
+ |
double vScale[3][3]; |
305 |
|
}; |
306 |
|
|
307 |
|
template<typename T> class NPTxyz : public T{ |
312 |
|
virtual ~NPTxyz(); |
313 |
|
|
314 |
|
virtual double getConservedQuantity(void); |
315 |
+ |
virtual string getAdditionalParameters(void); |
316 |
|
virtual void resetIntegrator(void); |
317 |
|
|
318 |
|
protected: |
326 |
|
|
327 |
|
virtual void getVelScaleA( double sc[3], double vel[3] ); |
328 |
|
virtual void getVelScaleB( double sc[3], int index ); |
329 |
< |
virtual void getPosScale(double pos[3], double COM[3], |
329 |
> |
virtual void getPosScale(double pos[3], double COM[3], |
330 |
|
int index, double sc[3]); |
331 |
|
|
332 |
+ |
virtual void calcVelScale( void ); |
333 |
+ |
|
334 |
|
double eta[3][3]; |
335 |
|
double oldEta[3][3]; |
336 |
|
double prevEta[3][3]; |
337 |
+ |
double vScale[3][3]; |
338 |
|
}; |
339 |
|
|
340 |
|
|
341 |
|
template<typename T> class ZConstraint : public T { |
342 |
< |
|
343 |
< |
public: |
342 |
> |
|
343 |
> |
public: |
344 |
|
class ForceSubtractionPolicy{ |
345 |
|
public: |
346 |
|
ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;} |
347 |
|
|
348 |
< |
virtual void update() = 0; |
348 |
> |
virtual void update() = 0; |
349 |
|
virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0; |
350 |
|
virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0; |
351 |
|
virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0; |
352 |
|
virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0; |
353 |
< |
|
353 |
> |
|
354 |
|
protected: |
355 |
|
ZConstraint<T>* zconsIntegrator; |
356 |
|
}; |
358 |
|
class PolicyByNumber : public ForceSubtractionPolicy{ |
359 |
|
|
360 |
|
public: |
361 |
< |
PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {} |
362 |
< |
virtual void update(); |
361 |
> |
PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {} |
362 |
> |
virtual void update(); |
363 |
|
virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ; |
364 |
|
virtual double getZFOfMovingMols(Atom* atom, double totalForce) ; |
365 |
|
virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce); |
366 |
|
virtual double getHFOfUnconsMols(Atom* atom, double totalForce); |
367 |
< |
|
367 |
> |
|
368 |
|
private: |
369 |
|
int totNumOfMovingAtoms; |
370 |
|
}; |
372 |
|
class PolicyByMass : public ForceSubtractionPolicy{ |
373 |
|
|
374 |
|
public: |
375 |
< |
PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {} |
376 |
< |
|
377 |
< |
virtual void update(); |
375 |
> |
PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {} |
376 |
> |
|
377 |
> |
virtual void update(); |
378 |
|
virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ; |
379 |
|
virtual double getZFOfMovingMols(Atom* atom, double totalForce) ; |
380 |
|
virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce); |
388 |
|
|
389 |
|
ZConstraint( SimInfo *theInfo, ForceFields* the_ff); |
390 |
|
~ZConstraint(); |
391 |
< |
|
391 |
> |
|
392 |
|
void setZConsTime(double time) {this->zconsTime = time;} |
393 |
|
void getZConsTime() {return zconsTime;} |
394 |
< |
|
394 |
> |
|
395 |
|
void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;} |
396 |
|
void getIndexOfAllZConsMols() {return indexOfAllZConsMols;} |
397 |
< |
|
397 |
> |
|
398 |
|
void setZConsOutput(const char * fileName) {zconsOutput = fileName;} |
399 |
|
string getZConsOutput() {return zconsOutput;} |
400 |
< |
|
400 |
> |
|
401 |
|
virtual void integrate(); |
376 |
– |
|
402 |
|
|
403 |
+ |
|
404 |
|
#ifdef IS_MPI |
405 |
|
virtual void update(); //which is called to indicate the molecules' migration |
406 |
|
#endif |
407 |
|
|
408 |
< |
enum ZConsState {zcsMoving, zcsFixed}; |
408 |
> |
enum ZConsState {zcsMoving, zcsFixed}; |
409 |
|
|
410 |
|
vector<Molecule*> zconsMols; //z-constraint molecules array |
411 |
|
vector<ZConsState> states; //state of z-constraint molecules |
412 |
|
|
387 |
– |
|
413 |
|
|
414 |
+ |
|
415 |
|
int totNumOfUnconsAtoms; //total number of uncontraint atoms |
416 |
|
double totalMassOfUncons; //total mas of unconstraint molecules |
417 |
|
|
419 |
|
protected: |
420 |
|
|
421 |
|
|
422 |
< |
|
423 |
< |
virtual void calcForce( int calcPot, int calcStress ); |
422 |
> |
|
423 |
> |
virtual void calcForce( int calcPot, int calcStress ); |
424 |
|
virtual void thermalize(void); |
425 |
< |
|
425 |
> |
|
426 |
|
void zeroOutVel(); |
427 |
|
void doZconstraintForce(); |
428 |
< |
void doHarmonic(); |
428 |
> |
void doHarmonic(vector<double>& resPos); |
429 |
|
bool checkZConsState(); |
430 |
|
|
431 |
|
bool haveFixedZMols(); |
440 |
|
double zconsTol; //tolerance of z-contratint |
441 |
|
double zForceConst; //base force constant term |
442 |
|
//which is estimate by OOPSE |
417 |
– |
|
443 |
|
|
444 |
< |
vector<double> massOfZConsMols; //mass of z-constraint molecule |
444 |
> |
|
445 |
> |
vector<double> massOfZConsMols; //mass of z-constraint molecule |
446 |
|
vector<double> kz; //force constant array |
447 |
|
|
448 |
|
vector<double> zPos; // |
449 |
< |
|
450 |
< |
|
449 |
> |
|
450 |
> |
|
451 |
|
vector<Molecule*> unconsMols; //unconstraint molecules array |
452 |
|
vector<double> massOfUnconsMols; //mass array of unconstraint molecules |
453 |
|
|
454 |
|
|
455 |
|
vector<ZConsParaItem>* parameters; // |
456 |
< |
|
456 |
> |
|
457 |
|
vector<int> indexOfAllZConsMols; //index of All Z-Constraint Molecuels |
458 |
|
|
459 |
< |
int* indexOfZConsMols; //index of local Z-Constraint Molecules |
460 |
< |
double* fz; |
461 |
< |
double* curZPos; |
436 |
< |
|
459 |
> |
vector<int> indexOfZConsMols; //index of local Z-Constraint Molecules |
460 |
> |
vector<double> fz; |
461 |
> |
vector<double> curZPos; |
462 |
|
|
463 |
+ |
bool usingSMD; |
464 |
+ |
vector<double> prevCantPos; |
465 |
+ |
vector<double> cantPos; |
466 |
+ |
vector<double> cantVel; |
467 |
|
|
468 |
< |
int whichDirection; //constraint direction |
468 |
> |
double zconsFixTime; |
469 |
> |
double zconsGap; |
470 |
> |
bool hasZConsGap; |
471 |
> |
vector<double> endFixTime; |
472 |
|
|
473 |
+ |
int whichDirection; //constraint direction |
474 |
+ |
|
475 |
|
private: |
476 |
< |
|
476 |
> |
|
477 |
|
string zconsOutput; //filename of zconstraint output |
478 |
|
ZConsWriter* fzOut; //z-constraint writer |
479 |
|
|
480 |
< |
double curZconsTime; |
480 |
> |
double curZconsTime; |
481 |
|
|
482 |
|
double calcMovingMolsCOMVel(); |
483 |
|
double calcSysCOMVel(); |
484 |
|
double calcTotalForce(); |
485 |
+ |
void updateZPos(); |
486 |
+ |
void updateCantPos(); |
487 |
|
|
488 |
|
ForceSubtractionPolicy* forcePolicy; //force subtraction policy |
489 |
|
friend class ForceSubtractionPolicy; |