ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Integrator.hpp
Revision: 1452
Committed: Mon Aug 23 15:11:36 2004 UTC (20 years ago) by tim
File size: 14280 byte(s)
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 mmeineke 377 #ifndef _INTEGRATOR_H_
2     #define _INTEGRATOR_H_
3    
4 tim 658 #include <string>
5     #include <vector>
6 mmeineke 377 #include "Atom.hpp"
7 gezelter 1097 #include "StuntDouble.hpp"
8 gezelter 604 #include "Molecule.hpp"
9 mmeineke 377 #include "SRI.hpp"
10     #include "AbstractClasses.hpp"
11     #include "SimInfo.hpp"
12     #include "ForceFields.hpp"
13 mmeineke 540 #include "Thermo.hpp"
14     #include "ReadWrite.hpp"
15 tim 658 #include "ZConsWriter.hpp"
16 chrisfen 1180 #include "Restraints.hpp"
17 tim 1452 #include "Quaternion.hpp"
18     #include "Mat4x4d.hpp"
19 mmeineke 377
20 tim 658 using namespace std;
21 mmeineke 561 const double kB = 8.31451e-7;// boltzmann constant amu*Ang^2*fs^-2/K
22     const double eConvert = 4.184e-4; // converts kcal/mol -> amu*A^2/fs^2
23 mmeineke 586 const double p_convert = 1.63882576e8; //converts amu*fs^-2*Ang^-1 -> atm
24 mmeineke 561 const int maxIteration = 300;
25     const double tol = 1.0e-6;
26    
27 tim 1268 class VelVerletConsFramework;
28 tim 645 template<typename T = BaseIntegrator> class Integrator : public T {
29    
30 mmeineke 377 public:
31 mmeineke 561 Integrator( SimInfo *theInfo, ForceFields* the_ff );
32 mmeineke 548 virtual ~Integrator();
33 mmeineke 377 void integrate( void );
34 tim 763 virtual double getConservedQuantity(void);
35 tim 837 virtual string getAdditionalParameters(void);
36 mmeineke 377
37 mmeineke 540 protected:
38 mmeineke 778
39 mmeineke 540 virtual void integrateStep( int calcPot, int calcStress );
40 tim 1234 //virtual void preMove( void );
41 mmeineke 540 virtual void moveA( void );
42     virtual void moveB( void );
43 tim 1234 //virtual void constrainA( void );
44     //virtual void constrainB( void );
45 mmeineke 559 virtual int readyCheck( void ) { return 1; }
46 tim 677
47 mmeineke 746 virtual void resetIntegrator( void ) { }
48 tim 837
49     virtual void calcForce( int calcPot, int calcStress );
50 tim 677 virtual void thermalize();
51 tim 837
52 tim 1108 virtual bool stopIntegrator() {return false;}
53    
54 gezelter 1097 virtual void rotationPropagation( StuntDouble* sd, double ji[3] );
55 mmeineke 778
56 tim 1234 //void checkConstraints( void );
57 tim 837 void rotate( int axes1, int axes2, double angle, double j[3],
58 tim 701 double A[3][3] );
59 tim 837
60 tim 1452 void printQuaternion(StuntDouble* sd);
61     Mat4x4d getS(const Quaternion& q);
62    
63 mmeineke 377 ForceFields* myFF;
64    
65 mmeineke 540 SimInfo *info; // all the info we'll ever need
66 gezelter 1097 vector<StuntDouble*> integrableObjects;
67 mmeineke 540 int nAtoms; /* the number of atoms */
68 mmeineke 548 int oldAtoms;
69 mmeineke 540 Atom **atoms; /* array of atom pointers */
70 mmeineke 423 Molecule* molecules;
71     int nMols;
72    
73 tim 1268 VelVerletConsFramework* consFramework;
74 tim 837
75 tim 1234 //int isConstrained; // boolean to know whether the systems contains constraints.
76     //int nConstrained; // counter for number of constraints
77     //int *constrainedA; // the i of a constraint pair
78     //int *constrainedB; // the j of a constraint pair
79     //double *constrainedDsqr; // the square of the constraint distance
80 mmeineke 548
81 tim 1234 //int* moving; // tells whether we are moving atom i
82     //int* moved; // tells whether we have moved atom i
83     //double* oldPos; // pre constrained positions
84    
85 mmeineke 540 short isFirst; /*boolean for the first time integrate is called */
86 tim 837
87 mmeineke 540 double dt;
88 mmeineke 541 double dt2;
89 gezelter 560
90 mmeineke 540 Thermo *tStats;
91     StatWriter* statOut;
92     DumpWriter* dumpOut;
93 tim 837
94 mmeineke 377 };
95    
96 tim 645 typedef Integrator<BaseIntegrator> RealIntegrator;
97 mmeineke 540
98 tim 1161 // ansi instantiation
99 gezelter 1323 // template class Integrator<BaseIntegrator>;
100 tim 1161
101 gezelter 1330
102 tim 645 template<typename T> class NVE : public T {
103    
104 mmeineke 561 public:
105     NVE ( SimInfo *theInfo, ForceFields* the_ff ):
106 tim 645 T( theInfo, the_ff ){}
107 tim 837 virtual ~NVE(){}
108 tim 645 };
109 mmeineke 555
110    
111 tim 645 template<typename T> class NVT : public T {
112 mmeineke 555
113 gezelter 560 public:
114    
115 mmeineke 561 NVT ( SimInfo *theInfo, ForceFields* the_ff);
116 tim 763 virtual ~NVT();
117 mmeineke 540
118 gezelter 560 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
119     void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
120 tim 763 void setChiTolerance(double tol) {chiTolerance = tol;}
121     virtual double getConservedQuantity(void);
122 tim 837 virtual string getAdditionalParameters(void);
123 gezelter 560
124 mmeineke 540 protected:
125 gezelter 560
126 mmeineke 561 virtual void moveA( void );
127     virtual void moveB( void );
128 mmeineke 540
129 mmeineke 561 virtual int readyCheck();
130 gezelter 560
131 mmeineke 746 virtual void resetIntegrator( void );
132    
133 gezelter 565 // chi is a propagated degree of freedom.
134 gezelter 560
135 gezelter 565 double chi;
136 gezelter 560
137 tim 763 //integral of chi(t)dt
138     double integralOfChidt;
139    
140 gezelter 565 // targetTemp must be set. tauThermostat must also be set;
141 gezelter 560
142     double targetTemp;
143     double tauThermostat;
144 tim 837
145 gezelter 565 short int have_tau_thermostat, have_target_temp;
146 gezelter 560
147 tim 763 double *oldVel;
148     double *oldJi;
149    
150     double chiTolerance;
151     short int have_chi_tolerance;
152    
153 mmeineke 540 };
154    
155    
156    
157 mmeineke 778 template<typename T> class NPT : public T{
158 tim 645
159 gezelter 560 public:
160    
161 mmeineke 778 NPT ( SimInfo *theInfo, ForceFields* the_ff);
162     virtual ~NPT();
163 tim 837
164 mmeineke 594 virtual void integrateStep( int calcPot, int calcStress ){
165     calcStress = 1;
166 tim 645 T::integrateStep( calcPot, calcStress );
167 mmeineke 594 }
168    
169 mmeineke 778 virtual double getConservedQuantity(void) = 0;
170 tim 837 virtual string getAdditionalParameters(void) = 0;
171 mmeineke 843
172     double myTauThermo( void ) { return tauThermostat; }
173     double myTauBaro( void ) { return tauBarostat; }
174    
175 gezelter 560 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
176     void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
177     void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
178     void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
179 tim 763 void setChiTolerance(double tol) {chiTolerance = tol; have_chi_tolerance = 1;}
180     void setPosIterTolerance(double tol) {posIterTolerance = tol; have_pos_iter_tolerance = 1;}
181     void setEtaTolerance(double tol) {etaTolerance = tol; have_eta_tolerance = 1;}
182 gezelter 560
183     protected:
184    
185 mmeineke 561 virtual void moveA( void );
186     virtual void moveB( void );
187 gezelter 560
188 mmeineke 561 virtual int readyCheck();
189 gezelter 560
190 mmeineke 746 virtual void resetIntegrator( void );
191    
192 mmeineke 778 virtual void getVelScaleA( double sc[3], double vel[3] ) = 0;
193     virtual void getVelScaleB( double sc[3], int index ) = 0;
194 tim 837 virtual void getPosScale(double pos[3], double COM[3],
195 mmeineke 778 int index, double sc[3]) = 0;
196    
197 mmeineke 857 virtual void calcVelScale( void ) = 0;
198    
199 mmeineke 778 virtual bool chiConverged( void );
200     virtual bool etaConverged( void ) = 0;
201 tim 837
202 mmeineke 778 virtual void evolveChiA( void );
203     virtual void evolveEtaA( void ) = 0;
204     virtual void evolveChiB( void );
205     virtual void evolveEtaB( void ) = 0;
206    
207     virtual void scaleSimBox( void ) = 0;
208    
209 tim 763 void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
210    
211 gezelter 565 // chi and eta are the propagated degrees of freedom
212 gezelter 560
213 mmeineke 778 double oldChi;
214     double prevChi;
215 gezelter 565 double chi;
216 gezelter 574 double NkBT;
217 tim 763 double fkBT;
218 gezelter 560
219 mmeineke 778 double tt2, tb2;
220     double instaTemp, instaPress, instaVol;
221 mmeineke 780 double press[3][3];
222 mmeineke 778
223 tim 763 int Nparticles;
224    
225     double integralOfChidt;
226    
227 tim 837 // targetTemp, targetPressure, and tauBarostat must be set.
228 gezelter 560 // One of qmass or tauThermostat must be set;
229    
230     double targetTemp;
231     double targetPressure;
232     double tauThermostat;
233     double tauBarostat;
234    
235     short int have_tau_thermostat, have_tau_barostat, have_target_temp;
236 gezelter 565 short int have_target_pressure;
237 gezelter 560
238 tim 763 double *oldPos;
239     double *oldVel;
240     double *oldJi;
241    
242     double chiTolerance;
243     short int have_chi_tolerance;
244     double posIterTolerance;
245     short int have_pos_iter_tolerance;
246     double etaTolerance;
247     short int have_eta_tolerance;
248    
249 gezelter 560 };
250    
251 mmeineke 778 template<typename T> class NPTi : public T{
252 tim 837
253 mmeineke 778 public:
254     NPTi( SimInfo *theInfo, ForceFields* the_ff);
255     ~NPTi();
256    
257     virtual double getConservedQuantity(void);
258     virtual void resetIntegrator(void);
259 tim 837 virtual string getAdditionalParameters(void);
260 mmeineke 778 protected:
261    
262    
263 tim 837
264 mmeineke 778 virtual void evolveEtaA(void);
265     virtual void evolveEtaB(void);
266    
267     virtual bool etaConverged( void );
268    
269     virtual void scaleSimBox( void );
270    
271     virtual void getVelScaleA( double sc[3], double vel[3] );
272     virtual void getVelScaleB( double sc[3], int index );
273 tim 837 virtual void getPosScale(double pos[3], double COM[3],
274 mmeineke 778 int index, double sc[3]);
275    
276 mmeineke 857 virtual void calcVelScale( void );
277    
278 mmeineke 778 double eta, oldEta, prevEta;
279 mmeineke 857 double vScale;
280 mmeineke 778 };
281    
282 tim 645 template<typename T> class NPTf : public T{
283 gezelter 576
284     public:
285    
286     NPTf ( SimInfo *theInfo, ForceFields* the_ff);
287 tim 767 virtual ~NPTf();
288 gezelter 576
289 tim 763 virtual double getConservedQuantity(void);
290 tim 837 virtual string getAdditionalParameters(void);
291 mmeineke 780 virtual void resetIntegrator(void);
292 mmeineke 594
293 gezelter 576 protected:
294    
295 mmeineke 780 virtual void evolveEtaA(void);
296     virtual void evolveEtaB(void);
297 gezelter 576
298 mmeineke 780 virtual bool etaConverged( void );
299 mmeineke 746
300 mmeineke 780 virtual void scaleSimBox( void );
301 gezelter 576
302 mmeineke 780 virtual void getVelScaleA( double sc[3], double vel[3] );
303     virtual void getVelScaleB( double sc[3], int index );
304 tim 837 virtual void getPosScale(double pos[3], double COM[3],
305 mmeineke 780 int index, double sc[3]);
306 tim 763
307 mmeineke 857 virtual void calcVelScale( void );
308    
309 gezelter 588 double eta[3][3];
310 mmeineke 780 double oldEta[3][3];
311     double prevEta[3][3];
312 mmeineke 857 double vScale[3][3];
313 gezelter 576 };
314    
315 mmeineke 812 template<typename T> class NPTxyz : public T{
316 mmeineke 755
317     public:
318    
319 mmeineke 812 NPTxyz ( SimInfo *theInfo, ForceFields* the_ff);
320     virtual ~NPTxyz();
321 mmeineke 755
322 mmeineke 812 virtual double getConservedQuantity(void);
323 tim 837 virtual string getAdditionalParameters(void);
324 mmeineke 812 virtual void resetIntegrator(void);
325 mmeineke 755
326     protected:
327    
328 mmeineke 812 virtual void evolveEtaA(void);
329     virtual void evolveEtaB(void);
330 mmeineke 755
331 mmeineke 812 virtual bool etaConverged( void );
332 mmeineke 755
333 mmeineke 812 virtual void scaleSimBox( void );
334 mmeineke 755
335 mmeineke 812 virtual void getVelScaleA( double sc[3], double vel[3] );
336     virtual void getVelScaleB( double sc[3], int index );
337 tim 837 virtual void getPosScale(double pos[3], double COM[3],
338 mmeineke 812 int index, double sc[3]);
339 mmeineke 755
340 mmeineke 857 virtual void calcVelScale( void );
341    
342 mmeineke 812 double eta[3][3];
343     double oldEta[3][3];
344     double prevEta[3][3];
345 mmeineke 857 double vScale[3][3];
346 mmeineke 812 };
347 mmeineke 755
348    
349 tim 658 template<typename T> class ZConstraint : public T {
350 tim 837
351     public:
352 tim 738 class ForceSubtractionPolicy{
353 tim 699 public:
354 tim 738 ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;}
355 tim 658
356 tim 837 virtual void update() = 0;
357 tim 699 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
358     virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0;
359 tim 701 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
360     virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0;
361 tim 837
362 tim 701 protected:
363 mmeineke 788 ZConstraint<T>* zconsIntegrator;
364 tim 699 };
365    
366 tim 738 class PolicyByNumber : public ForceSubtractionPolicy{
367 gezelter 747
368 tim 699 public:
369 tim 837 PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}
370     virtual void update();
371 tim 699 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
372     virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
373 tim 701 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
374     virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
375 tim 837
376 tim 699 private:
377 tim 763 int totNumOfMovingAtoms;
378 tim 699 };
379    
380 tim 738 class PolicyByMass : public ForceSubtractionPolicy{
381 gezelter 747
382 tim 699 public:
383 tim 837 PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}
384    
385     virtual void update();
386 tim 699 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
387     virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
388 tim 701 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
389     virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
390 tim 699
391 tim 701 private:
392     double totMassOfMovingAtoms;
393 tim 699 };
394    
395 tim 658 public:
396    
397     ZConstraint( SimInfo *theInfo, ForceFields* the_ff);
398     ~ZConstraint();
399 tim 837
400 tim 658 void setZConsTime(double time) {this->zconsTime = time;}
401     void getZConsTime() {return zconsTime;}
402 tim 837
403 tim 701 void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;}
404     void getIndexOfAllZConsMols() {return indexOfAllZConsMols;}
405 tim 837
406 tim 701 void setZConsOutput(const char * fileName) {zconsOutput = fileName;}
407 tim 658 string getZConsOutput() {return zconsOutput;}
408 tim 837
409 tim 677 virtual void integrate();
410 tim 658
411 tim 837
412 tim 658 #ifdef IS_MPI
413 tim 701 virtual void update(); //which is called to indicate the molecules' migration
414 mmeineke 377 #endif
415 tim 658
416 tim 837 enum ZConsState {zcsMoving, zcsFixed};
417 mmeineke 790
418     vector<Molecule*> zconsMols; //z-constraint molecules array
419     vector<ZConsState> states; //state of z-constraint molecules
420    
421    
422 tim 837
423 mmeineke 790 int totNumOfUnconsAtoms; //total number of uncontraint atoms
424     double totalMassOfUncons; //total mas of unconstraint molecules
425    
426    
427 tim 658 protected:
428    
429 mmeineke 790
430 tim 837
431     virtual void calcForce( int calcPot, int calcStress );
432 tim 677 virtual void thermalize(void);
433 tim 837
434 tim 677 void zeroOutVel();
435     void doZconstraintForce();
436 tim 1093 void doHarmonic(vector<double>& resPos);
437 tim 677 bool checkZConsState();
438    
439     bool haveFixedZMols();
440     bool haveMovingZMols();
441    
442     double calcZSys();
443    
444     int isZConstraintMol(Molecule* mol);
445    
446    
447 tim 701 double zconsTime; //sample time
448     double zconsTol; //tolerance of z-contratint
449     double zForceConst; //base force constant term
450     //which is estimate by OOPSE
451 mmeineke 790
452 tim 837
453     vector<double> massOfZConsMols; //mass of z-constraint molecule
454 tim 701 vector<double> kz; //force constant array
455 mmeineke 790
456 tim 701 vector<double> zPos; //
457 tim 837
458    
459 tim 701 vector<Molecule*> unconsMols; //unconstraint molecules array
460     vector<double> massOfUnconsMols; //mass array of unconstraint molecules
461 tim 682
462 mmeineke 790
463 tim 701 vector<ZConsParaItem>* parameters; //
464 tim 837
465 tim 658 vector<int> indexOfAllZConsMols; //index of All Z-Constraint Molecuels
466 tim 677
467 tim 1093 vector<int> indexOfZConsMols; //index of local Z-Constraint Molecules
468     vector<double> fz;
469     vector<double> curZPos;
470 tim 677
471 tim 1093 bool usingSMD;
472 tim 1141 vector<double> prevCantPos;
473 tim 1093 vector<double> cantPos;
474     vector<double> cantVel;
475    
476 tim 1091 double zconsFixTime;
477     double zconsGap;
478     bool hasZConsGap;
479     vector<double> endFixTime;
480    
481 tim 837 int whichDirection; //constraint direction
482    
483 tim 658 private:
484 tim 837
485 tim 701 string zconsOutput; //filename of zconstraint output
486     ZConsWriter* fzOut; //z-constraint writer
487 tim 677
488 tim 837 double curZconsTime;
489 tim 699
490 tim 696 double calcMovingMolsCOMVel();
491     double calcSysCOMVel();
492     double calcTotalForce();
493 tim 1091 void updateZPos();
494 tim 1093 void updateCantPos();
495    
496 gezelter 747 ForceSubtractionPolicy* forcePolicy; //force subtraction policy
497 tim 738 friend class ForceSubtractionPolicy;
498 tim 677
499 tim 658 };
500    
501 tim 1254
502     //Sympletic quaternion Scheme Integrator
503     //Reference:
504     // T.F. Miller, M. Eleftheriou, P. Pattnaik, A. Ndirango, D. Newns and G.J. Martyna
505     //Symplectic quaternion Scheme for biophysical molecular dynamics
506     //116(20), 8649, J. Chem. Phys. (2002)
507     template<typename T> class SQSIntegrator : public T{
508     public:
509 tim 1452 SQSIntegrator( SimInfo *theInfo, ForceFields* the_ff );
510 tim 1254 virtual void moveA();
511     virtual void moveB();
512     protected:
513 tim 1452 void freeRotor(double dt, Quaternion& q, Vector4d& qdot, Vector3d& I);
514     void rotate(int k, double dt, Quaternion& q, Vector4d& qdot, double Ik);
515     private:
516     Quaternion getPk(int i, const Vector4d& q);
517     Mat4x4d getS(const Quaternion& q);
518     vector<Quaternion> q;
519     vector<Vector4d> p_qua;
520     vector<double> I0;
521    
522     Vector4d p2j(const Vector4d& p, Mat4x4d& m);
523     Vector4d j2p(const Vector4d& j, Mat4x4d& m);
524 tim 1254 };
525 tim 658 #endif