ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/integrators/Integrator.hpp
Revision: 1772
Committed: Tue Nov 23 22:48:31 2004 UTC (19 years, 7 months ago) by chrisfen
File size: 13822 byte(s)
Log Message:
Improvements to restraints

File Contents

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