ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimSetup.cpp
Revision: 1204
Committed: Thu May 27 19:26:42 2004 UTC (20 years, 11 months ago) by gezelter
File size: 56727 byte(s)
Log Message:
bugfix in simsetup?

File Contents

# Content
1 #include <algorithm>
2 #include <stdlib.h>
3 #include <iostream>
4 #include <math.h>
5 #include <string>
6 #include <sprng.h>
7 #include "SimSetup.hpp"
8 #include "ReadWrite.hpp"
9 #include "parse_me.h"
10 #include "Integrator.hpp"
11 #include "simError.h"
12 #include "RigidBody.hpp"
13 //#include "ConjugateMinimizer.hpp"
14 #include "OOPSEMinimizer.hpp"
15
16 #ifdef IS_MPI
17 #include "mpiBASS.h"
18 #include "mpiSimulation.hpp"
19 #endif
20
21 // some defines for ensemble and Forcefield cases
22
23 #define NVE_ENS 0
24 #define NVT_ENS 1
25 #define NPTi_ENS 2
26 #define NPTf_ENS 3
27 #define NPTxyz_ENS 4
28
29
30 #define FF_DUFF 0
31 #define FF_LJ 1
32 #define FF_EAM 2
33 #define FF_H2O 3
34
35 using namespace std;
36
37 /**
38 * Check whether dividend is divisble by divisor or not
39 */
40 bool isDivisible(double dividend, double divisor){
41 double tolerance = 0.000001;
42 double quotient;
43 double diff;
44 int intQuotient;
45
46 quotient = dividend / divisor;
47
48 if (quotient < 0)
49 quotient = -quotient;
50
51 intQuotient = int (quotient + tolerance);
52
53 diff = fabs(fabs(dividend) - intQuotient * fabs(divisor));
54
55 if (diff <= tolerance)
56 return true;
57 else
58 return false;
59 }
60
61 SimSetup::SimSetup(){
62
63 initSuspend = false;
64 isInfoArray = 0;
65 nInfo = 1;
66
67 stamps = new MakeStamps();
68 globals = new Globals();
69
70
71 #ifdef IS_MPI
72 strcpy(checkPointMsg, "SimSetup creation successful");
73 MPIcheckPoint();
74 #endif // IS_MPI
75 }
76
77 SimSetup::~SimSetup(){
78 delete stamps;
79 delete globals;
80 }
81
82 void SimSetup::setSimInfo(SimInfo* the_info, int theNinfo){
83 info = the_info;
84 nInfo = theNinfo;
85 isInfoArray = 1;
86 initSuspend = true;
87 }
88
89
90 void SimSetup::parseFile(char* fileName){
91 #ifdef IS_MPI
92 if (worldRank == 0){
93 #endif // is_mpi
94
95 inFileName = fileName;
96 set_interface_stamps(stamps, globals);
97
98 #ifdef IS_MPI
99 mpiEventInit();
100 #endif
101
102 yacc_BASS(fileName);
103
104 #ifdef IS_MPI
105 throwMPIEvent(NULL);
106 }
107 else{
108 receiveParse();
109 }
110 #endif
111
112 }
113
114 #ifdef IS_MPI
115 void SimSetup::receiveParse(void){
116 set_interface_stamps(stamps, globals);
117 mpiEventInit();
118 MPIcheckPoint();
119 mpiEventLoop();
120 }
121
122 #endif // is_mpi
123
124 void SimSetup::createSim(void){
125
126 // gather all of the information from the Bass file
127
128 gatherInfo();
129
130 // creation of complex system objects
131
132 sysObjectsCreation();
133
134 // check on the post processing info
135
136 finalInfoCheck();
137
138 // initialize the system coordinates
139
140 if ( !initSuspend ){
141 initSystemCoords();
142
143 if( !(globals->getUseInitTime()) )
144 info[0].currentTime = 0.0;
145 }
146
147 // make the output filenames
148
149 makeOutNames();
150
151 #ifdef IS_MPI
152 mpiSim->mpiRefresh();
153 #endif
154
155 // initialize the Fortran
156
157 initFortran();
158
159 if (globals->haveMinimizer())
160 // make minimizer
161 makeMinimizer();
162 else
163 // make the integrator
164 makeIntegrator();
165
166 }
167
168
169 void SimSetup::makeMolecules(void){
170 int i, j, k;
171 int exI, exJ, exK, exL, slI, slJ;
172 int tempI, tempJ, tempK, tempL;
173 int molI;
174 int stampID, atomOffset, rbOffset;
175 molInit molInfo;
176 DirectionalAtom* dAtom;
177 RigidBody* myRB;
178 StuntDouble* mySD;
179 LinkedAssign* extras;
180 LinkedAssign* current_extra;
181 AtomStamp* currentAtom;
182 BondStamp* currentBond;
183 BendStamp* currentBend;
184 TorsionStamp* currentTorsion;
185 RigidBodyStamp* currentRigidBody;
186 CutoffGroupStamp* currentCutoffGroup;
187 CutoffGroup* myCutoffGroup;
188 int nCutoffGroups;// number of cutoff group of a molecule defined in mdl file
189 set<int> cutoffAtomSet; //atoms belong to cutoffgroup defined at mdl file
190
191 bond_pair* theBonds;
192 bend_set* theBends;
193 torsion_set* theTorsions;
194
195 set<int> skipList;
196
197 double phi, theta, psi;
198 char* molName;
199 char rbName[100];
200
201 //init the forceField paramters
202
203 the_ff->readParams();
204
205 // init the atoms
206
207 int nMembers, nNew, rb1, rb2;
208
209 for (k = 0; k < nInfo; k++){
210 the_ff->setSimInfo(&(info[k]));
211
212 atomOffset = 0;
213
214 for (i = 0; i < info[k].n_mol; i++){
215 stampID = info[k].molecules[i].getStampID();
216 molName = comp_stamps[stampID]->getID();
217
218 molInfo.nAtoms = comp_stamps[stampID]->getNAtoms();
219 molInfo.nBonds = comp_stamps[stampID]->getNBonds();
220 molInfo.nBends = comp_stamps[stampID]->getNBends();
221 molInfo.nTorsions = comp_stamps[stampID]->getNTorsions();
222 molInfo.nRigidBodies = comp_stamps[stampID]->getNRigidBodies();
223
224 nCutoffGroups = comp_stamps[stampID]->getNCutoffGroups();
225
226 molInfo.myAtoms = &(info[k].atoms[atomOffset]);
227
228 if (molInfo.nBonds > 0)
229 molInfo.myBonds = new Bond*[molInfo.nBonds];
230 else
231 molInfo.myBonds = NULL;
232
233 if (molInfo.nBends > 0)
234 molInfo.myBends = new Bend*[molInfo.nBends];
235 else
236 molInfo.myBends = NULL;
237
238 if (molInfo.nTorsions > 0)
239 molInfo.myTorsions = new Torsion *[molInfo.nTorsions];
240 else
241 molInfo.myTorsions = NULL;
242
243 theBonds = new bond_pair[molInfo.nBonds];
244 theBends = new bend_set[molInfo.nBends];
245 theTorsions = new torsion_set[molInfo.nTorsions];
246
247 // make the Atoms
248
249 for (j = 0; j < molInfo.nAtoms; j++){
250 currentAtom = comp_stamps[stampID]->getAtom(j);
251
252 if (currentAtom->haveOrientation()){
253 dAtom = new DirectionalAtom((j + atomOffset),
254 info[k].getConfiguration());
255 info[k].n_oriented++;
256 molInfo.myAtoms[j] = dAtom;
257
258 // Directional Atoms have standard unit vectors which are oriented
259 // in space using the three Euler angles. We assume the standard
260 // unit vector was originally along the z axis below.
261
262 phi = currentAtom->getEulerPhi() * M_PI / 180.0;
263 theta = currentAtom->getEulerTheta() * M_PI / 180.0;
264 psi = currentAtom->getEulerPsi()* M_PI / 180.0;
265
266 dAtom->setUnitFrameFromEuler(phi, theta, psi);
267
268 }
269 else{
270
271 molInfo.myAtoms[j] = new Atom((j + atomOffset), info[k].getConfiguration());
272
273 }
274
275 molInfo.myAtoms[j]->setType(currentAtom->getType());
276 #ifdef IS_MPI
277
278 molInfo.myAtoms[j]->setGlobalIndex(globalAtomIndex[j + atomOffset]);
279
280 #endif // is_mpi
281 }
282
283 // make the bonds
284 for (j = 0; j < molInfo.nBonds; j++){
285 currentBond = comp_stamps[stampID]->getBond(j);
286 theBonds[j].a = currentBond->getA() + atomOffset;
287 theBonds[j].b = currentBond->getB() + atomOffset;
288
289 tempI = theBonds[j].a;
290 tempJ = theBonds[j].b;
291
292 #ifdef IS_MPI
293 exI = info[k].atoms[tempI]->getGlobalIndex() + 1;
294 exJ = info[k].atoms[tempJ]->getGlobalIndex() + 1;
295 #else
296 exI = tempI + 1;
297 exJ = tempJ + 1;
298 #endif
299
300 info[k].excludes->addPair(exI, exJ);
301 }
302
303 //make the bends
304 for (j = 0; j < molInfo.nBends; j++){
305 currentBend = comp_stamps[stampID]->getBend(j);
306 theBends[j].a = currentBend->getA() + atomOffset;
307 theBends[j].b = currentBend->getB() + atomOffset;
308 theBends[j].c = currentBend->getC() + atomOffset;
309
310 if (currentBend->haveExtras()){
311 extras = currentBend->getExtras();
312 current_extra = extras;
313
314 while (current_extra != NULL){
315 if (!strcmp(current_extra->getlhs(), "ghostVectorSource")){
316 switch (current_extra->getType()){
317 case 0:
318 theBends[j].ghost = current_extra->getInt() + atomOffset;
319 theBends[j].isGhost = 1;
320 break;
321
322 case 1:
323 theBends[j].ghost = (int) current_extra->getDouble() +
324 atomOffset;
325 theBends[j].isGhost = 1;
326 break;
327
328 default:
329 sprintf(painCave.errMsg,
330 "SimSetup Error: ghostVectorSource was neither a "
331 "double nor an int.\n"
332 "-->Bend[%d] in %s\n",
333 j, comp_stamps[stampID]->getID());
334 painCave.isFatal = 1;
335 simError();
336 }
337 }
338 else{
339 sprintf(painCave.errMsg,
340 "SimSetup Error: unhandled bend assignment:\n"
341 " -->%s in Bend[%d] in %s\n",
342 current_extra->getlhs(), j, comp_stamps[stampID]->getID());
343 painCave.isFatal = 1;
344 simError();
345 }
346
347 current_extra = current_extra->getNext();
348 }
349 }
350
351 if (theBends[j].isGhost) {
352
353 tempI = theBends[j].a;
354 tempJ = theBends[j].b;
355
356 #ifdef IS_MPI
357 exI = info[k].atoms[tempI]->getGlobalIndex() + 1;
358 exJ = info[k].atoms[tempJ]->getGlobalIndex() + 1;
359 #else
360 exI = tempI + 1;
361 exJ = tempJ + 1;
362 #endif
363 info[k].excludes->addPair(exI, exJ);
364
365 } else {
366
367 tempI = theBends[j].a;
368 tempJ = theBends[j].b;
369 tempK = theBends[j].c;
370
371 #ifdef IS_MPI
372 exI = info[k].atoms[tempI]->getGlobalIndex() + 1;
373 exJ = info[k].atoms[tempJ]->getGlobalIndex() + 1;
374 exK = info[k].atoms[tempK]->getGlobalIndex() + 1;
375 #else
376 exI = tempI + 1;
377 exJ = tempJ + 1;
378 exK = tempK + 1;
379 #endif
380
381 info[k].excludes->addPair(exI, exK);
382 info[k].excludes->addPair(exI, exJ);
383 info[k].excludes->addPair(exJ, exK);
384 }
385 }
386
387 for (j = 0; j < molInfo.nTorsions; j++){
388 currentTorsion = comp_stamps[stampID]->getTorsion(j);
389 theTorsions[j].a = currentTorsion->getA() + atomOffset;
390 theTorsions[j].b = currentTorsion->getB() + atomOffset;
391 theTorsions[j].c = currentTorsion->getC() + atomOffset;
392 theTorsions[j].d = currentTorsion->getD() + atomOffset;
393
394 tempI = theTorsions[j].a;
395 tempJ = theTorsions[j].b;
396 tempK = theTorsions[j].c;
397 tempL = theTorsions[j].d;
398
399 #ifdef IS_MPI
400 exI = info[k].atoms[tempI]->getGlobalIndex() + 1;
401 exJ = info[k].atoms[tempJ]->getGlobalIndex() + 1;
402 exK = info[k].atoms[tempK]->getGlobalIndex() + 1;
403 exL = info[k].atoms[tempL]->getGlobalIndex() + 1;
404 #else
405 exI = tempI + 1;
406 exJ = tempJ + 1;
407 exK = tempK + 1;
408 exL = tempL + 1;
409 #endif
410
411 info[k].excludes->addPair(exI, exJ);
412 info[k].excludes->addPair(exI, exK);
413 info[k].excludes->addPair(exI, exL);
414 info[k].excludes->addPair(exJ, exK);
415 info[k].excludes->addPair(exJ, exL);
416 info[k].excludes->addPair(exK, exL);
417 }
418
419
420 molInfo.myRigidBodies.clear();
421
422 for (j = 0; j < molInfo.nRigidBodies; j++){
423
424 currentRigidBody = comp_stamps[stampID]->getRigidBody(j);
425 nMembers = currentRigidBody->getNMembers();
426
427 // Create the Rigid Body:
428
429 myRB = new RigidBody();
430
431 sprintf(rbName,"%s_RB_%d", molName, j);
432 myRB->setType(rbName);
433
434 for (rb1 = 0; rb1 < nMembers; rb1++) {
435
436 // molI is atom numbering inside this molecule
437 molI = currentRigidBody->getMember(rb1);
438
439 // tempI is atom numbering on local processor
440 tempI = molI + atomOffset;
441
442 // currentAtom is the AtomStamp (which we need for
443 // rigid body reference positions)
444 currentAtom = comp_stamps[stampID]->getAtom(molI);
445
446 // When we add to the rigid body, add the atom itself and
447 // the stamp info:
448
449 myRB->addAtom(info[k].atoms[tempI], currentAtom);
450
451 // Add this atom to the Skip List for the integrators
452 #ifdef IS_MPI
453 slI = info[k].atoms[tempI]->getGlobalIndex();
454 #else
455 slI = tempI;
456 #endif
457 skipList.insert(slI);
458
459 }
460
461 for(rb1 = 0; rb1 < nMembers - 1; rb1++) {
462 for(rb2 = rb1+1; rb2 < nMembers; rb2++) {
463
464 tempI = currentRigidBody->getMember(rb1);
465 tempJ = currentRigidBody->getMember(rb2);
466
467 // Some explanation is required here.
468 // Fortran indexing starts at 1, while c indexing starts at 0
469 // Also, in parallel computations, the GlobalIndex is
470 // used for the exclude list:
471
472 #ifdef IS_MPI
473 exI = molInfo.myAtoms[tempI]->getGlobalIndex() + 1;
474 exJ = molInfo.myAtoms[tempJ]->getGlobalIndex() + 1;
475 #else
476 exI = molInfo.myAtoms[tempI]->getIndex() + 1;
477 exJ = molInfo.myAtoms[tempJ]->getIndex() + 1;
478 #endif
479
480 info[k].excludes->addPair(exI, exJ);
481
482 }
483 }
484
485 molInfo.myRigidBodies.push_back(myRB);
486 info[k].rigidBodies.push_back(myRB);
487 }
488
489
490 //create cutoff group for molecule
491
492 cutoffAtomSet.clear();
493 molInfo.myCutoffGroups.clear();
494
495 for (j = 0; j < nCutoffGroups; j++){
496
497 currentCutoffGroup = comp_stamps[stampID]->getCutoffGroup(j);
498 nMembers = currentCutoffGroup->getNMembers();
499
500 myCutoffGroup = new CutoffGroup();
501
502 for (int cg = 0; cg < nMembers; cg++) {
503
504 // molI is atom numbering inside this molecule
505 molI = currentCutoffGroup->getMember(cg);
506
507 // tempI is atom numbering on local processor
508 tempI = molI + atomOffset;
509
510 myCutoffGroup->addAtom(info[k].atoms[tempI]);
511
512 cutoffAtomSet.insert(tempI);
513 }
514
515 molInfo.myCutoffGroups.push_back(myCutoffGroup);
516 }//end for (j = 0; j < molInfo.nCutoffGroups; j++)
517
518 //creat a cutoff group for every atom in current molecule which does not belong to cutoffgroup defined at mdl file
519
520 for(j = 0; j < molInfo.nAtoms; j++){
521
522 if(cutoffAtomSet.find(molInfo.myAtoms[j]->getIndex()) == cutoffAtomSet.end()){
523 myCutoffGroup = new CutoffGroup();
524 myCutoffGroup->addAtom(molInfo.myAtoms[j]);
525 molInfo.myCutoffGroups.push_back(myCutoffGroup);
526 }
527
528 }
529
530
531
532
533 // After this is all set up, scan through the atoms to
534 // see if they can be added to the integrableObjects:
535
536 molInfo.myIntegrableObjects.clear();
537
538
539 for (j = 0; j < molInfo.nAtoms; j++){
540
541 #ifdef IS_MPI
542 slJ = molInfo.myAtoms[j]->getGlobalIndex();
543 #else
544 slJ = j+atomOffset;
545 #endif
546
547 // if they aren't on the skip list, then they can be integrated
548
549 if (skipList.find(slJ) == skipList.end()) {
550 mySD = (StuntDouble *) molInfo.myAtoms[j];
551 info[k].integrableObjects.push_back(mySD);
552 molInfo.myIntegrableObjects.push_back(mySD);
553 }
554 }
555
556 // all rigid bodies are integrated:
557
558 for (j = 0; j < molInfo.nRigidBodies; j++) {
559 mySD = (StuntDouble *) molInfo.myRigidBodies[j];
560 info[k].integrableObjects.push_back(mySD);
561 molInfo.myIntegrableObjects.push_back(mySD);
562 }
563
564
565 // send the arrays off to the forceField for init.
566
567 the_ff->initializeAtoms(molInfo.nAtoms, molInfo.myAtoms);
568 the_ff->initializeBonds(molInfo.nBonds, molInfo.myBonds, theBonds);
569 the_ff->initializeBends(molInfo.nBends, molInfo.myBends, theBends);
570 the_ff->initializeTorsions(molInfo.nTorsions, molInfo.myTorsions,
571 theTorsions);
572
573 info[k].molecules[i].initialize(molInfo);
574
575
576 atomOffset += molInfo.nAtoms;
577 delete[] theBonds;
578 delete[] theBends;
579 delete[] theTorsions;
580 }
581 }
582
583 #ifdef IS_MPI
584 sprintf(checkPointMsg, "all molecules initialized succesfully");
585 MPIcheckPoint();
586 #endif // is_mpi
587
588 }
589
590 void SimSetup::initFromBass(void){
591 int i, j, k;
592 int n_cells;
593 double cellx, celly, cellz;
594 double temp1, temp2, temp3;
595 int n_per_extra;
596 int n_extra;
597 int have_extra, done;
598
599 double vel[3];
600 vel[0] = 0.0;
601 vel[1] = 0.0;
602 vel[2] = 0.0;
603
604 temp1 = (double) tot_nmol / 4.0;
605 temp2 = pow(temp1, (1.0 / 3.0));
606 temp3 = ceil(temp2);
607
608 have_extra = 0;
609 if (temp2 < temp3){
610 // we have a non-complete lattice
611 have_extra = 1;
612
613 n_cells = (int) temp3 - 1;
614 cellx = info[0].boxL[0] / temp3;
615 celly = info[0].boxL[1] / temp3;
616 cellz = info[0].boxL[2] / temp3;
617 n_extra = tot_nmol - (4 * n_cells * n_cells * n_cells);
618 temp1 = ((double) n_extra) / (pow(temp3, 3.0) - pow(n_cells, 3.0));
619 n_per_extra = (int) ceil(temp1);
620
621 if (n_per_extra > 4){
622 sprintf(painCave.errMsg,
623 "SimSetup error. There has been an error in constructing"
624 " the non-complete lattice.\n");
625 painCave.isFatal = 1;
626 simError();
627 }
628 }
629 else{
630 n_cells = (int) temp3;
631 cellx = info[0].boxL[0] / temp3;
632 celly = info[0].boxL[1] / temp3;
633 cellz = info[0].boxL[2] / temp3;
634 }
635
636 current_mol = 0;
637 current_comp_mol = 0;
638 current_comp = 0;
639 current_atom_ndx = 0;
640
641 for (i = 0; i < n_cells ; i++){
642 for (j = 0; j < n_cells; j++){
643 for (k = 0; k < n_cells; k++){
644 makeElement(i * cellx, j * celly, k * cellz);
645
646 makeElement(i * cellx + 0.5 * cellx, j * celly + 0.5 * celly, k * cellz);
647
648 makeElement(i * cellx, j * celly + 0.5 * celly, k * cellz + 0.5 * cellz);
649
650 makeElement(i * cellx + 0.5 * cellx, j * celly, k * cellz + 0.5 * cellz);
651 }
652 }
653 }
654
655 if (have_extra){
656 done = 0;
657
658 int start_ndx;
659 for (i = 0; i < (n_cells + 1) && !done; i++){
660 for (j = 0; j < (n_cells + 1) && !done; j++){
661 if (i < n_cells){
662 if (j < n_cells){
663 start_ndx = n_cells;
664 }
665 else
666 start_ndx = 0;
667 }
668 else
669 start_ndx = 0;
670
671 for (k = start_ndx; k < (n_cells + 1) && !done; k++){
672 makeElement(i * cellx, j * celly, k * cellz);
673 done = (current_mol >= tot_nmol);
674
675 if (!done && n_per_extra > 1){
676 makeElement(i * cellx + 0.5 * cellx, j * celly + 0.5 * celly,
677 k * cellz);
678 done = (current_mol >= tot_nmol);
679 }
680
681 if (!done && n_per_extra > 2){
682 makeElement(i * cellx, j * celly + 0.5 * celly,
683 k * cellz + 0.5 * cellz);
684 done = (current_mol >= tot_nmol);
685 }
686
687 if (!done && n_per_extra > 3){
688 makeElement(i * cellx + 0.5 * cellx, j * celly,
689 k * cellz + 0.5 * cellz);
690 done = (current_mol >= tot_nmol);
691 }
692 }
693 }
694 }
695 }
696
697 for (i = 0; i < info[0].n_atoms; i++){
698 info[0].atoms[i]->setVel(vel);
699 }
700 }
701
702 void SimSetup::makeElement(double x, double y, double z){
703 int k;
704 AtomStamp* current_atom;
705 DirectionalAtom* dAtom;
706 double rotMat[3][3];
707 double pos[3];
708
709 for (k = 0; k < comp_stamps[current_comp]->getNAtoms(); k++){
710 current_atom = comp_stamps[current_comp]->getAtom(k);
711 if (!current_atom->havePosition()){
712 sprintf(painCave.errMsg,
713 "SimSetup:initFromBass error.\n"
714 "\tComponent %s, atom %s does not have a position specified.\n"
715 "\tThe initialization routine is unable to give a start"
716 " position.\n",
717 comp_stamps[current_comp]->getID(), current_atom->getType());
718 painCave.isFatal = 1;
719 simError();
720 }
721
722 pos[0] = x + current_atom->getPosX();
723 pos[1] = y + current_atom->getPosY();
724 pos[2] = z + current_atom->getPosZ();
725
726 info[0].atoms[current_atom_ndx]->setPos(pos);
727
728 if (info[0].atoms[current_atom_ndx]->isDirectional()){
729 dAtom = (DirectionalAtom *) info[0].atoms[current_atom_ndx];
730
731 rotMat[0][0] = 1.0;
732 rotMat[0][1] = 0.0;
733 rotMat[0][2] = 0.0;
734
735 rotMat[1][0] = 0.0;
736 rotMat[1][1] = 1.0;
737 rotMat[1][2] = 0.0;
738
739 rotMat[2][0] = 0.0;
740 rotMat[2][1] = 0.0;
741 rotMat[2][2] = 1.0;
742
743 dAtom->setA(rotMat);
744 }
745
746 current_atom_ndx++;
747 }
748
749 current_mol++;
750 current_comp_mol++;
751
752 if (current_comp_mol >= components_nmol[current_comp]){
753 current_comp_mol = 0;
754 current_comp++;
755 }
756 }
757
758
759 void SimSetup::gatherInfo(void){
760 int i;
761
762 ensembleCase = -1;
763 ffCase = -1;
764
765 // set the easy ones first
766
767 for (i = 0; i < nInfo; i++){
768 info[i].target_temp = globals->getTargetTemp();
769 info[i].dt = globals->getDt();
770 info[i].run_time = globals->getRunTime();
771 }
772 n_components = globals->getNComponents();
773
774
775 // get the forceField
776
777 strcpy(force_field, globals->getForceField());
778
779 if (!strcasecmp(force_field, "DUFF")){
780 ffCase = FF_DUFF;
781 }
782 else if (!strcasecmp(force_field, "LJ")){
783 ffCase = FF_LJ;
784 }
785 else if (!strcasecmp(force_field, "EAM")){
786 ffCase = FF_EAM;
787 }
788 else if (!strcasecmp(force_field, "WATER")){
789 ffCase = FF_H2O;
790 }
791 else{
792 sprintf(painCave.errMsg, "SimSetup Error. Unrecognized force field -> %s\n",
793 force_field);
794 painCave.isFatal = 1;
795 simError();
796 }
797
798 // get the ensemble
799
800 strcpy(ensemble, globals->getEnsemble());
801
802 if (!strcasecmp(ensemble, "NVE")){
803 ensembleCase = NVE_ENS;
804 }
805 else if (!strcasecmp(ensemble, "NVT")){
806 ensembleCase = NVT_ENS;
807 }
808 else if (!strcasecmp(ensemble, "NPTi") || !strcasecmp(ensemble, "NPT")){
809 ensembleCase = NPTi_ENS;
810 }
811 else if (!strcasecmp(ensemble, "NPTf")){
812 ensembleCase = NPTf_ENS;
813 }
814 else if (!strcasecmp(ensemble, "NPTxyz")){
815 ensembleCase = NPTxyz_ENS;
816 }
817 else{
818 sprintf(painCave.errMsg,
819 "SimSetup Warning. Unrecognized Ensemble -> %s \n"
820 "\treverting to NVE for this simulation.\n",
821 ensemble);
822 painCave.isFatal = 0;
823 simError();
824 strcpy(ensemble, "NVE");
825 ensembleCase = NVE_ENS;
826 }
827
828 for (i = 0; i < nInfo; i++){
829 strcpy(info[i].ensemble, ensemble);
830
831 // get the mixing rule
832
833 strcpy(info[i].mixingRule, globals->getMixingRule());
834 info[i].usePBC = globals->getPBC();
835 }
836
837 // get the components and calculate the tot_nMol and indvidual n_mol
838
839 the_components = globals->getComponents();
840 components_nmol = new int[n_components];
841
842
843 if (!globals->haveNMol()){
844 // we don't have the total number of molecules, so we assume it is
845 // given in each component
846
847 tot_nmol = 0;
848 for (i = 0; i < n_components; i++){
849 if (!the_components[i]->haveNMol()){
850 // we have a problem
851 sprintf(painCave.errMsg,
852 "SimSetup Error. No global NMol or component NMol given.\n"
853 "\tCannot calculate the number of atoms.\n");
854 painCave.isFatal = 1;
855 simError();
856 }
857
858 tot_nmol += the_components[i]->getNMol();
859 components_nmol[i] = the_components[i]->getNMol();
860 }
861 }
862 else{
863 sprintf(painCave.errMsg,
864 "SimSetup error.\n"
865 "\tSorry, the ability to specify total"
866 " nMols and then give molfractions in the components\n"
867 "\tis not currently supported."
868 " Please give nMol in the components.\n");
869 painCave.isFatal = 1;
870 simError();
871 }
872
873 //check whether sample time, status time, thermal time and reset time are divisble by dt
874 if (globals->haveSampleTime() && !isDivisible(globals->getSampleTime(), globals->getDt())){
875 sprintf(painCave.errMsg,
876 "Sample time is not divisible by dt.\n"
877 "\tThis will result in samples that are not uniformly\n"
878 "\tdistributed in time. If this is a problem, change\n"
879 "\tyour sampleTime variable.\n");
880 painCave.isFatal = 0;
881 simError();
882 }
883
884 if (globals->haveStatusTime() && !isDivisible(globals->getStatusTime(), globals->getDt())){
885 sprintf(painCave.errMsg,
886 "Status time is not divisible by dt.\n"
887 "\tThis will result in status reports that are not uniformly\n"
888 "\tdistributed in time. If this is a problem, change \n"
889 "\tyour statusTime variable.\n");
890 painCave.isFatal = 0;
891 simError();
892 }
893
894 if (globals->haveThermalTime() && !isDivisible(globals->getThermalTime(), globals->getDt())){
895 sprintf(painCave.errMsg,
896 "Thermal time is not divisible by dt.\n"
897 "\tThis will result in thermalizations that are not uniformly\n"
898 "\tdistributed in time. If this is a problem, change \n"
899 "\tyour thermalTime variable.\n");
900 painCave.isFatal = 0;
901 simError();
902 }
903
904 if (globals->haveResetTime() && !isDivisible(globals->getResetTime(), globals->getDt())){
905 sprintf(painCave.errMsg,
906 "Reset time is not divisible by dt.\n"
907 "\tThis will result in integrator resets that are not uniformly\n"
908 "\tdistributed in time. If this is a problem, change\n"
909 "\tyour resetTime variable.\n");
910 painCave.isFatal = 0;
911 simError();
912 }
913
914 // set the status, sample, and thermal kick times
915
916 for (i = 0; i < nInfo; i++){
917 if (globals->haveSampleTime()){
918 info[i].sampleTime = globals->getSampleTime();
919 info[i].statusTime = info[i].sampleTime;
920 }
921 else{
922 info[i].sampleTime = globals->getRunTime();
923 info[i].statusTime = info[i].sampleTime;
924 }
925
926 if (globals->haveStatusTime()){
927 info[i].statusTime = globals->getStatusTime();
928 }
929
930 if (globals->haveThermalTime()){
931 info[i].thermalTime = globals->getThermalTime();
932 } else {
933 info[i].thermalTime = globals->getRunTime();
934 }
935
936 info[i].resetIntegrator = 0;
937 if( globals->haveResetTime() ){
938 info[i].resetTime = globals->getResetTime();
939 info[i].resetIntegrator = 1;
940 }
941
942 // check for the temperature set flag
943
944 if (globals->haveTempSet())
945 info[i].setTemp = globals->getTempSet();
946
947 // check for the extended State init
948
949 info[i].useInitXSstate = globals->getUseInitXSstate();
950 info[i].orthoTolerance = globals->getOrthoBoxTolerance();
951
952 // check for thermodynamic integration
953 if (globals->getUseThermInt()) {
954 if (globals->haveThermIntLambda() && globals->haveThermIntK()) {
955 info[i].useThermInt = globals->getUseThermInt();
956 info[i].thermIntLambda = globals->getThermIntLambda();
957 info[i].thermIntK = globals->getThermIntK();
958
959 Restraints *myRestraint = new Restraints(tot_nmol, info[i].thermIntLambda, info[i].thermIntK);
960 info[i].restraint = myRestraint;
961 }
962 else {
963 sprintf(painCave.errMsg,
964 "SimSetup Error:\n"
965 "\tKeyword useThermInt was set to 'true' but\n"
966 "\tthermodynamicIntegrationLambda (and/or\n"
967 "\tthermodynamicIntegrationK) was not specified.\n"
968 "\tPlease provide a lambda value and k value in your .bass file.\n");
969 painCave.isFatal = 1;
970 simError();
971 }
972 }
973 else if(globals->haveThermIntLambda() || globals->haveThermIntK()){
974 sprintf(painCave.errMsg,
975 "SimSetup Warning: If you want to use Thermodynamic\n"
976 "\tIntegration, set useThermInt to 'true' in your .bass file.\n"
977 "\tThe useThermInt keyword is 'false' by default, so your\n"
978 "\tlambda and/or k values are being ignored.\n");
979 painCave.isFatal = 0;
980 simError();
981 }
982 }
983
984 //setup seed for random number generator
985 int seedValue;
986
987 if (globals->haveSeed()){
988 seedValue = globals->getSeed();
989
990 if(seedValue / 1E9 == 0){
991 sprintf(painCave.errMsg,
992 "Seed for sprng library should contain at least 9 digits\n"
993 "OOPSE will generate a seed for user\n");
994 painCave.isFatal = 0;
995 simError();
996
997 //using seed generated by system instead of invalid seed set by user
998 #ifndef IS_MPI
999 seedValue = make_sprng_seed();
1000 #else
1001 if (worldRank == 0){
1002 seedValue = make_sprng_seed();
1003 }
1004 MPI_Bcast(&seedValue, 1, MPI_INT, 0, MPI_COMM_WORLD);
1005 #endif
1006 }
1007 }//end of if branch of globals->haveSeed()
1008 else{
1009
1010 #ifndef IS_MPI
1011 seedValue = make_sprng_seed();
1012 #else
1013 if (worldRank == 0){
1014 seedValue = make_sprng_seed();
1015 }
1016 MPI_Bcast(&seedValue, 1, MPI_INT, 0, MPI_COMM_WORLD);
1017 #endif
1018 }//end of globals->haveSeed()
1019
1020 for (int i = 0; i < nInfo; i++){
1021 info[i].setSeed(seedValue);
1022 }
1023
1024 #ifdef IS_MPI
1025 strcpy(checkPointMsg, "Successfully gathered all information from Bass\n");
1026 MPIcheckPoint();
1027 #endif // is_mpi
1028 }
1029
1030
1031 void SimSetup::finalInfoCheck(void){
1032 int index;
1033 int usesDipoles;
1034 int usesCharges;
1035 int i;
1036
1037 for (i = 0; i < nInfo; i++){
1038 // check electrostatic parameters
1039
1040 index = 0;
1041 usesDipoles = 0;
1042 while ((index < info[i].n_atoms) && !usesDipoles){
1043 usesDipoles = (info[i].atoms[index])->hasDipole();
1044 index++;
1045 }
1046 index = 0;
1047 usesCharges = 0;
1048 while ((index < info[i].n_atoms) && !usesCharges){
1049 usesCharges= (info[i].atoms[index])->hasCharge();
1050 index++;
1051 }
1052 #ifdef IS_MPI
1053 int myUse = usesDipoles;
1054 MPI_Allreduce(&myUse, &usesDipoles, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
1055 #endif //is_mpi
1056
1057 double theRcut, theRsw;
1058
1059 if (globals->haveRcut()) {
1060 theRcut = globals->getRcut();
1061
1062 if (globals->haveRsw())
1063 theRsw = globals->getRsw();
1064 else
1065 theRsw = theRcut;
1066
1067 info[i].setDefaultRcut(theRcut, theRsw);
1068
1069 } else {
1070
1071 the_ff->calcRcut();
1072 theRcut = info[i].getRcut();
1073
1074 if (globals->haveRsw())
1075 theRsw = globals->getRsw();
1076 else
1077 theRsw = theRcut;
1078
1079 info[i].setDefaultRcut(theRcut, theRsw);
1080 }
1081
1082 if (globals->getUseRF()){
1083 info[i].useReactionField = 1;
1084
1085 if (!globals->haveRcut()){
1086 sprintf(painCave.errMsg,
1087 "SimSetup Warning: No value was set for the cutoffRadius.\n"
1088 "\tOOPSE will use a default value of 15.0 angstroms"
1089 "\tfor the cutoffRadius.\n");
1090 painCave.isFatal = 0;
1091 simError();
1092 theRcut = 15.0;
1093 }
1094 else{
1095 theRcut = globals->getRcut();
1096 }
1097
1098 if (!globals->haveRsw()){
1099 sprintf(painCave.errMsg,
1100 "SimSetup Warning: No value was set for switchingRadius.\n"
1101 "\tOOPSE will use a default value of\n"
1102 "\t0.95 * cutoffRadius for the switchingRadius\n");
1103 painCave.isFatal = 0;
1104 simError();
1105 theRsw = 0.95 * theRcut;
1106 }
1107 else{
1108 theRsw = globals->getRsw();
1109 }
1110
1111 info[i].setDefaultRcut(theRcut, theRsw);
1112
1113 if (!globals->haveDielectric()){
1114 sprintf(painCave.errMsg,
1115 "SimSetup Error: No Dielectric constant was set.\n"
1116 "\tYou are trying to use Reaction Field without"
1117 "\tsetting a dielectric constant!\n");
1118 painCave.isFatal = 1;
1119 simError();
1120 }
1121 info[i].dielectric = globals->getDielectric();
1122 }
1123 else{
1124 if (usesDipoles || usesCharges){
1125
1126 if (!globals->haveRcut()){
1127 sprintf(painCave.errMsg,
1128 "SimSetup Warning: No value was set for the cutoffRadius.\n"
1129 "\tOOPSE will use a default value of 15.0 angstroms"
1130 "\tfor the cutoffRadius.\n");
1131 painCave.isFatal = 0;
1132 simError();
1133 theRcut = 15.0;
1134 }
1135 else{
1136 theRcut = globals->getRcut();
1137 }
1138
1139 if (!globals->haveRsw()){
1140 sprintf(painCave.errMsg,
1141 "SimSetup Warning: No value was set for switchingRadius.\n"
1142 "\tOOPSE will use a default value of\n"
1143 "\t0.95 * cutoffRadius for the switchingRadius\n");
1144 painCave.isFatal = 0;
1145 simError();
1146 theRsw = 0.95 * theRcut;
1147 }
1148 else{
1149 theRsw = globals->getRsw();
1150 }
1151
1152 info[i].setDefaultRcut(theRcut, theRsw);
1153
1154 }
1155 }
1156 }
1157 #ifdef IS_MPI
1158 strcpy(checkPointMsg, "post processing checks out");
1159 MPIcheckPoint();
1160 #endif // is_mpi
1161
1162 // clean up the forcefield
1163 the_ff->cleanMe();
1164 }
1165
1166 void SimSetup::initSystemCoords(void){
1167 int i;
1168
1169 char* inName;
1170
1171 (info[0].getConfiguration())->createArrays(info[0].n_atoms);
1172
1173 for (i = 0; i < info[0].n_atoms; i++)
1174 info[0].atoms[i]->setCoords();
1175
1176 if (globals->haveInitialConfig()){
1177 InitializeFromFile* fileInit;
1178 #ifdef IS_MPI // is_mpi
1179 if (worldRank == 0){
1180 #endif //is_mpi
1181 inName = globals->getInitialConfig();
1182 fileInit = new InitializeFromFile(inName);
1183 #ifdef IS_MPI
1184 }
1185 else
1186 fileInit = new InitializeFromFile(NULL);
1187 #endif
1188 fileInit->readInit(info); // default velocities on
1189
1190 delete fileInit;
1191 }
1192 else{
1193
1194 // no init from bass
1195
1196 sprintf(painCave.errMsg,
1197 "Cannot intialize a simulation without an initial configuration file.\n");
1198 painCave.isFatal = 1;;
1199 simError();
1200
1201 }
1202
1203 #ifdef IS_MPI
1204 strcpy(checkPointMsg, "Successfully read in the initial configuration");
1205 MPIcheckPoint();
1206 #endif // is_mpi
1207 }
1208
1209
1210 void SimSetup::makeOutNames(void){
1211 int k;
1212
1213
1214 for (k = 0; k < nInfo; k++){
1215 #ifdef IS_MPI
1216 if (worldRank == 0){
1217 #endif // is_mpi
1218
1219 if (globals->haveFinalConfig()){
1220 strcpy(info[k].finalName, globals->getFinalConfig());
1221 }
1222 else{
1223 strcpy(info[k].finalName, inFileName);
1224 char* endTest;
1225 int nameLength = strlen(info[k].finalName);
1226 endTest = &(info[k].finalName[nameLength - 5]);
1227 if (!strcmp(endTest, ".bass")){
1228 strcpy(endTest, ".eor");
1229 }
1230 else if (!strcmp(endTest, ".BASS")){
1231 strcpy(endTest, ".eor");
1232 }
1233 else{
1234 endTest = &(info[k].finalName[nameLength - 4]);
1235 if (!strcmp(endTest, ".bss")){
1236 strcpy(endTest, ".eor");
1237 }
1238 else if (!strcmp(endTest, ".mdl")){
1239 strcpy(endTest, ".eor");
1240 }
1241 else{
1242 strcat(info[k].finalName, ".eor");
1243 }
1244 }
1245 }
1246
1247 // make the sample and status out names
1248
1249 strcpy(info[k].sampleName, inFileName);
1250 char* endTest;
1251 int nameLength = strlen(info[k].sampleName);
1252 endTest = &(info[k].sampleName[nameLength - 5]);
1253 if (!strcmp(endTest, ".bass")){
1254 strcpy(endTest, ".dump");
1255 }
1256 else if (!strcmp(endTest, ".BASS")){
1257 strcpy(endTest, ".dump");
1258 }
1259 else{
1260 endTest = &(info[k].sampleName[nameLength - 4]);
1261 if (!strcmp(endTest, ".bss")){
1262 strcpy(endTest, ".dump");
1263 }
1264 else if (!strcmp(endTest, ".mdl")){
1265 strcpy(endTest, ".dump");
1266 }
1267 else{
1268 strcat(info[k].sampleName, ".dump");
1269 }
1270 }
1271
1272 strcpy(info[k].statusName, inFileName);
1273 nameLength = strlen(info[k].statusName);
1274 endTest = &(info[k].statusName[nameLength - 5]);
1275 if (!strcmp(endTest, ".bass")){
1276 strcpy(endTest, ".stat");
1277 }
1278 else if (!strcmp(endTest, ".BASS")){
1279 strcpy(endTest, ".stat");
1280 }
1281 else{
1282 endTest = &(info[k].statusName[nameLength - 4]);
1283 if (!strcmp(endTest, ".bss")){
1284 strcpy(endTest, ".stat");
1285 }
1286 else if (!strcmp(endTest, ".mdl")){
1287 strcpy(endTest, ".stat");
1288 }
1289 else{
1290 strcat(info[k].statusName, ".stat");
1291 }
1292 }
1293
1294 strcpy(info[k].rawPotName, inFileName);
1295 nameLength = strlen(info[k].rawPotName);
1296 endTest = &(info[k].rawPotName[nameLength - 5]);
1297 if (!strcmp(endTest, ".bass")){
1298 strcpy(endTest, ".raw");
1299 }
1300 else if (!strcmp(endTest, ".BASS")){
1301 strcpy(endTest, ".raw");
1302 }
1303 else{
1304 endTest = &(info[k].rawPotName[nameLength - 4]);
1305 if (!strcmp(endTest, ".bss")){
1306 strcpy(endTest, ".raw");
1307 }
1308 else if (!strcmp(endTest, ".mdl")){
1309 strcpy(endTest, ".raw");
1310 }
1311 else{
1312 strcat(info[k].rawPotName, ".raw");
1313 }
1314 }
1315
1316 #ifdef IS_MPI
1317
1318 }
1319 #endif // is_mpi
1320 }
1321 }
1322
1323
1324 void SimSetup::sysObjectsCreation(void){
1325 int i, k;
1326
1327 // create the forceField
1328
1329 createFF();
1330
1331 // extract componentList
1332
1333 compList();
1334
1335 // calc the number of atoms, bond, bends, and torsions
1336
1337 calcSysValues();
1338
1339 #ifdef IS_MPI
1340 // divide the molecules among the processors
1341
1342 mpiMolDivide();
1343 #endif //is_mpi
1344
1345 // create the atom and SRI arrays. Also initialize Molecule Stamp ID's
1346
1347 makeSysArrays();
1348
1349 // make and initialize the molecules (all but atomic coordinates)
1350
1351 makeMolecules();
1352
1353 for (k = 0; k < nInfo; k++){
1354 info[k].identArray = new int[info[k].n_atoms];
1355 for (i = 0; i < info[k].n_atoms; i++){
1356 info[k].identArray[i] = info[k].atoms[i]->getIdent();
1357 }
1358 }
1359 }
1360
1361
1362 void SimSetup::createFF(void){
1363 switch (ffCase){
1364 case FF_DUFF:
1365 the_ff = new DUFF();
1366 break;
1367
1368 case FF_LJ:
1369 the_ff = new LJFF();
1370 break;
1371
1372 case FF_EAM:
1373 the_ff = new EAM_FF();
1374 break;
1375
1376 case FF_H2O:
1377 the_ff = new WATER();
1378 break;
1379
1380 default:
1381 sprintf(painCave.errMsg,
1382 "SimSetup Error. Unrecognized force field in case statement.\n");
1383 painCave.isFatal = 1;
1384 simError();
1385 }
1386
1387 #ifdef IS_MPI
1388 strcpy(checkPointMsg, "ForceField creation successful");
1389 MPIcheckPoint();
1390 #endif // is_mpi
1391 }
1392
1393
1394 void SimSetup::compList(void){
1395 int i;
1396 char* id;
1397 LinkedMolStamp* headStamp = new LinkedMolStamp();
1398 LinkedMolStamp* currentStamp = NULL;
1399 comp_stamps = new MoleculeStamp * [n_components];
1400 bool haveCutoffGroups;
1401
1402 haveCutoffGroups = false;
1403
1404 // make an array of molecule stamps that match the components used.
1405 // also extract the used stamps out into a separate linked list
1406
1407 for (i = 0; i < nInfo; i++){
1408 info[i].nComponents = n_components;
1409 info[i].componentsNmol = components_nmol;
1410 info[i].compStamps = comp_stamps;
1411 info[i].headStamp = headStamp;
1412 }
1413
1414
1415 for (i = 0; i < n_components; i++){
1416 id = the_components[i]->getType();
1417 comp_stamps[i] = NULL;
1418
1419 // check to make sure the component isn't already in the list
1420
1421 comp_stamps[i] = headStamp->match(id);
1422 if (comp_stamps[i] == NULL){
1423 // extract the component from the list;
1424
1425 currentStamp = stamps->extractMolStamp(id);
1426 if (currentStamp == NULL){
1427 sprintf(painCave.errMsg,
1428 "SimSetup error: Component \"%s\" was not found in the "
1429 "list of declared molecules\n",
1430 id);
1431 painCave.isFatal = 1;
1432 simError();
1433 }
1434
1435 headStamp->add(currentStamp);
1436 comp_stamps[i] = headStamp->match(id);
1437 }
1438
1439 if(comp_stamps[i]->getNCutoffGroups() > 0)
1440 haveCutoffGroups = true;
1441 }
1442
1443 for (i = 0; i < nInfo; i++)
1444 info[i].haveCutoffGroups = haveCutoffGroups;
1445
1446 #ifdef IS_MPI
1447 strcpy(checkPointMsg, "Component stamps successfully extracted\n");
1448 MPIcheckPoint();
1449 #endif // is_mpi
1450 }
1451
1452 void SimSetup::calcSysValues(void){
1453 int i, j;
1454 int ncutgroups, atomsingroups, ngroupsinstamp;
1455
1456 int* molMembershipArray;
1457 CutoffGroupStamp* cg;
1458
1459 tot_atoms = 0;
1460 tot_bonds = 0;
1461 tot_bends = 0;
1462 tot_torsions = 0;
1463 tot_rigid = 0;
1464 tot_groups = 0;
1465 for (i = 0; i < n_components; i++){
1466 tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms();
1467 tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds();
1468 tot_bends += components_nmol[i] * comp_stamps[i]->getNBends();
1469 tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions();
1470 tot_rigid += components_nmol[i] * comp_stamps[i]->getNRigidBodies();
1471
1472 ncutgroups = comp_stamps[i]->getNCutoffGroups();
1473 atomsingroups = 0;
1474 for (j=0; j < ncutgroups; j++) {
1475 cg = comp_stamps[i]->getCutoffGroup(j);
1476 atomsingroups += cg->getNMembers();
1477 }
1478 ngroupsinstamp = comp_stamps[i]->getNAtoms() - atomsingroups + ncutgroups;
1479 tot_groups += components_nmol[i] * ngroupsinstamp;
1480 }
1481
1482 tot_SRI = tot_bonds + tot_bends + tot_torsions;
1483 molMembershipArray = new int[tot_atoms];
1484
1485 for (i = 0; i < nInfo; i++){
1486 info[i].n_atoms = tot_atoms;
1487 info[i].n_bonds = tot_bonds;
1488 info[i].n_bends = tot_bends;
1489 info[i].n_torsions = tot_torsions;
1490 info[i].n_SRI = tot_SRI;
1491 info[i].n_mol = tot_nmol;
1492 info[i].ngroup = tot_groups;
1493 info[i].molMembershipArray = molMembershipArray;
1494 }
1495 }
1496
1497 #ifdef IS_MPI
1498
1499 void SimSetup::mpiMolDivide(void){
1500 int i, j, k;
1501 int localMol, allMol;
1502 int local_atoms, local_bonds, local_bends, local_torsions, local_SRI;
1503 int local_rigid, local_groups;
1504 vector<int> globalMolIndex;
1505 int ncutgroups, atomsingroups, ngroupsinstamp;
1506 CutoffGroupStamp* cg;
1507
1508 mpiSim = new mpiSimulation(info);
1509
1510 mpiSim->divideLabor();
1511 globalAtomIndex = mpiSim->getGlobalAtomIndex();
1512 //globalMolIndex = mpiSim->getGlobalMolIndex();
1513
1514 // set up the local variables
1515
1516 mol2proc = mpiSim->getMolToProcMap();
1517 molCompType = mpiSim->getMolComponentType();
1518
1519 allMol = 0;
1520 localMol = 0;
1521 local_atoms = 0;
1522 local_bonds = 0;
1523 local_bends = 0;
1524 local_torsions = 0;
1525 local_rigid = 0;
1526 local_groups = 0;
1527 globalAtomCounter = 0;
1528
1529 for (i = 0; i < n_components; i++){
1530 for (j = 0; j < components_nmol[i]; j++){
1531 if (mol2proc[allMol] == worldRank){
1532 local_atoms += comp_stamps[i]->getNAtoms();
1533 local_bonds += comp_stamps[i]->getNBonds();
1534 local_bends += comp_stamps[i]->getNBends();
1535 local_torsions += comp_stamps[i]->getNTorsions();
1536 local_rigid += comp_stamps[i]->getNRigidBodies();
1537
1538 ncutgroups = comp_stamps[i]->getNCutoffGroups();
1539 atomsingroups = 0;
1540 for (k=0; k < ncutgroups; k++) {
1541 cg = comp_stamps[i]->getCutoffGroup(k);
1542 atomsingroups += cg->getNMembers();
1543 }
1544 ngroupsinstamp = comp_stamps[i]->getNAtoms() - atomsingroups +
1545 ncutgroups;
1546 local_groups += ngroupsinstamp;
1547
1548 localMol++;
1549 }
1550 for (k = 0; k < comp_stamps[i]->getNAtoms(); k++){
1551 info[0].molMembershipArray[globalAtomCounter] = allMol;
1552 globalAtomCounter++;
1553 }
1554
1555 allMol++;
1556 }
1557 }
1558 local_SRI = local_bonds + local_bends + local_torsions;
1559
1560 info[0].n_atoms = mpiSim->getNAtomsLocal();
1561
1562 if (local_atoms != info[0].n_atoms){
1563 sprintf(painCave.errMsg,
1564 "SimSetup error: mpiSim's localAtom (%d) and SimSetup's\n"
1565 "\tlocalAtom (%d) are not equal.\n",
1566 info[0].n_atoms, local_atoms);
1567 painCave.isFatal = 1;
1568 simError();
1569 }
1570
1571 info[0].ngroup = mpiSim->getNGroupsLocal();
1572 if (local_groups != info[0].ngroup){
1573 sprintf(painCave.errMsg,
1574 "SimSetup error: mpiSim's localGroups (%d) and SimSetup's\n"
1575 "\tlocalGroups (%d) are not equal.\n",
1576 info[0].ngroup, local_groups);
1577 painCave.isFatal = 1;
1578 simError();
1579 }
1580
1581 info[0].n_bonds = local_bonds;
1582 info[0].n_bends = local_bends;
1583 info[0].n_torsions = local_torsions;
1584 info[0].n_SRI = local_SRI;
1585 info[0].n_mol = localMol;
1586
1587 strcpy(checkPointMsg, "Passed nlocal consistency check.");
1588 MPIcheckPoint();
1589 }
1590
1591 #endif // is_mpi
1592
1593
1594 void SimSetup::makeSysArrays(void){
1595
1596 #ifndef IS_MPI
1597 int k, j;
1598 #endif // is_mpi
1599 int i, l;
1600
1601 Atom** the_atoms;
1602 Molecule* the_molecules;
1603
1604 for (l = 0; l < nInfo; l++){
1605 // create the atom and short range interaction arrays
1606
1607 the_atoms = new Atom * [info[l].n_atoms];
1608 the_molecules = new Molecule[info[l].n_mol];
1609 int molIndex;
1610
1611 // initialize the molecule's stampID's
1612
1613 #ifdef IS_MPI
1614
1615
1616 molIndex = 0;
1617 for (i = 0; i < mpiSim->getNMolGlobal(); i++){
1618 if (mol2proc[i] == worldRank){
1619 the_molecules[molIndex].setStampID(molCompType[i]);
1620 the_molecules[molIndex].setMyIndex(molIndex);
1621 the_molecules[molIndex].setGlobalIndex(i);
1622 molIndex++;
1623 }
1624 }
1625
1626 #else // is_mpi
1627
1628 molIndex = 0;
1629 globalAtomCounter = 0;
1630 for (i = 0; i < n_components; i++){
1631 for (j = 0; j < components_nmol[i]; j++){
1632 the_molecules[molIndex].setStampID(i);
1633 the_molecules[molIndex].setMyIndex(molIndex);
1634 the_molecules[molIndex].setGlobalIndex(molIndex);
1635 for (k = 0; k < comp_stamps[i]->getNAtoms(); k++){
1636 info[l].molMembershipArray[globalAtomCounter] = molIndex;
1637 globalAtomCounter++;
1638 }
1639 molIndex++;
1640 }
1641 }
1642
1643
1644 #endif // is_mpi
1645
1646 info[l].globalExcludes = new int;
1647 info[l].globalExcludes[0] = 0;
1648
1649 // set the arrays into the SimInfo object
1650
1651 info[l].atoms = the_atoms;
1652 info[l].molecules = the_molecules;
1653 info[l].nGlobalExcludes = 0;
1654
1655 the_ff->setSimInfo(info);
1656 }
1657 }
1658
1659 void SimSetup::makeIntegrator(void){
1660 int k;
1661
1662 NVE<RealIntegrator>* myNVE = NULL;
1663 NVT<RealIntegrator>* myNVT = NULL;
1664 NPTi<NPT<RealIntegrator> >* myNPTi = NULL;
1665 NPTf<NPT<RealIntegrator> >* myNPTf = NULL;
1666 NPTxyz<NPT<RealIntegrator> >* myNPTxyz = NULL;
1667
1668 for (k = 0; k < nInfo; k++){
1669 switch (ensembleCase){
1670 case NVE_ENS:
1671 if (globals->haveZconstraints()){
1672 setupZConstraint(info[k]);
1673 myNVE = new ZConstraint<NVE<RealIntegrator> >(&(info[k]), the_ff);
1674 }
1675 else{
1676 myNVE = new NVE<RealIntegrator>(&(info[k]), the_ff);
1677 }
1678
1679 info->the_integrator = myNVE;
1680 break;
1681
1682 case NVT_ENS:
1683 if (globals->haveZconstraints()){
1684 setupZConstraint(info[k]);
1685 myNVT = new ZConstraint<NVT<RealIntegrator> >(&(info[k]), the_ff);
1686 }
1687 else
1688 myNVT = new NVT<RealIntegrator>(&(info[k]), the_ff);
1689
1690 myNVT->setTargetTemp(globals->getTargetTemp());
1691
1692 if (globals->haveTauThermostat())
1693 myNVT->setTauThermostat(globals->getTauThermostat());
1694 else{
1695 sprintf(painCave.errMsg,
1696 "SimSetup error: If you use the NVT\n"
1697 "\tensemble, you must set tauThermostat.\n");
1698 painCave.isFatal = 1;
1699 simError();
1700 }
1701
1702 info->the_integrator = myNVT;
1703 break;
1704
1705 case NPTi_ENS:
1706 if (globals->haveZconstraints()){
1707 setupZConstraint(info[k]);
1708 myNPTi = new ZConstraint<NPTi<NPT <RealIntegrator> > >(&(info[k]), the_ff);
1709 }
1710 else
1711 myNPTi = new NPTi<NPT<RealIntegrator> >(&(info[k]), the_ff);
1712
1713 myNPTi->setTargetTemp(globals->getTargetTemp());
1714
1715 if (globals->haveTargetPressure())
1716 myNPTi->setTargetPressure(globals->getTargetPressure());
1717 else{
1718 sprintf(painCave.errMsg,
1719 "SimSetup error: If you use a constant pressure\n"
1720 "\tensemble, you must set targetPressure in the BASS file.\n");
1721 painCave.isFatal = 1;
1722 simError();
1723 }
1724
1725 if (globals->haveTauThermostat())
1726 myNPTi->setTauThermostat(globals->getTauThermostat());
1727 else{
1728 sprintf(painCave.errMsg,
1729 "SimSetup error: If you use an NPT\n"
1730 "\tensemble, you must set tauThermostat.\n");
1731 painCave.isFatal = 1;
1732 simError();
1733 }
1734
1735 if (globals->haveTauBarostat())
1736 myNPTi->setTauBarostat(globals->getTauBarostat());
1737 else{
1738 sprintf(painCave.errMsg,
1739 "SimSetup error: If you use an NPT\n"
1740 "\tensemble, you must set tauBarostat.\n");
1741 painCave.isFatal = 1;
1742 simError();
1743 }
1744
1745 info->the_integrator = myNPTi;
1746 break;
1747
1748 case NPTf_ENS:
1749 if (globals->haveZconstraints()){
1750 setupZConstraint(info[k]);
1751 myNPTf = new ZConstraint<NPTf<NPT <RealIntegrator> > >(&(info[k]), the_ff);
1752 }
1753 else
1754 myNPTf = new NPTf<NPT <RealIntegrator> >(&(info[k]), the_ff);
1755
1756 myNPTf->setTargetTemp(globals->getTargetTemp());
1757
1758 if (globals->haveTargetPressure())
1759 myNPTf->setTargetPressure(globals->getTargetPressure());
1760 else{
1761 sprintf(painCave.errMsg,
1762 "SimSetup error: If you use a constant pressure\n"
1763 "\tensemble, you must set targetPressure in the BASS file.\n");
1764 painCave.isFatal = 1;
1765 simError();
1766 }
1767
1768 if (globals->haveTauThermostat())
1769 myNPTf->setTauThermostat(globals->getTauThermostat());
1770
1771 else{
1772 sprintf(painCave.errMsg,
1773 "SimSetup error: If you use an NPT\n"
1774 "\tensemble, you must set tauThermostat.\n");
1775 painCave.isFatal = 1;
1776 simError();
1777 }
1778
1779 if (globals->haveTauBarostat())
1780 myNPTf->setTauBarostat(globals->getTauBarostat());
1781
1782 else{
1783 sprintf(painCave.errMsg,
1784 "SimSetup error: If you use an NPT\n"
1785 "\tensemble, you must set tauBarostat.\n");
1786 painCave.isFatal = 1;
1787 simError();
1788 }
1789
1790 info->the_integrator = myNPTf;
1791 break;
1792
1793 case NPTxyz_ENS:
1794 if (globals->haveZconstraints()){
1795 setupZConstraint(info[k]);
1796 myNPTxyz = new ZConstraint<NPTxyz<NPT <RealIntegrator> > >(&(info[k]), the_ff);
1797 }
1798 else
1799 myNPTxyz = new NPTxyz<NPT <RealIntegrator> >(&(info[k]), the_ff);
1800
1801 myNPTxyz->setTargetTemp(globals->getTargetTemp());
1802
1803 if (globals->haveTargetPressure())
1804 myNPTxyz->setTargetPressure(globals->getTargetPressure());
1805 else{
1806 sprintf(painCave.errMsg,
1807 "SimSetup error: If you use a constant pressure\n"
1808 "\tensemble, you must set targetPressure in the BASS file.\n");
1809 painCave.isFatal = 1;
1810 simError();
1811 }
1812
1813 if (globals->haveTauThermostat())
1814 myNPTxyz->setTauThermostat(globals->getTauThermostat());
1815 else{
1816 sprintf(painCave.errMsg,
1817 "SimSetup error: If you use an NPT\n"
1818 "\tensemble, you must set tauThermostat.\n");
1819 painCave.isFatal = 1;
1820 simError();
1821 }
1822
1823 if (globals->haveTauBarostat())
1824 myNPTxyz->setTauBarostat(globals->getTauBarostat());
1825 else{
1826 sprintf(painCave.errMsg,
1827 "SimSetup error: If you use an NPT\n"
1828 "\tensemble, you must set tauBarostat.\n");
1829 painCave.isFatal = 1;
1830 simError();
1831 }
1832
1833 info->the_integrator = myNPTxyz;
1834 break;
1835
1836 default:
1837 sprintf(painCave.errMsg,
1838 "SimSetup Error. Unrecognized ensemble in case statement.\n");
1839 painCave.isFatal = 1;
1840 simError();
1841 }
1842 }
1843 }
1844
1845 void SimSetup::initFortran(void){
1846 info[0].refreshSim();
1847
1848 if (!strcmp(info[0].mixingRule, "standard")){
1849 the_ff->initForceField(LB_MIXING_RULE);
1850 }
1851 else if (!strcmp(info[0].mixingRule, "explicit")){
1852 the_ff->initForceField(EXPLICIT_MIXING_RULE);
1853 }
1854 else{
1855 sprintf(painCave.errMsg, "SimSetup Error: unknown mixing rule -> \"%s\"\n",
1856 info[0].mixingRule);
1857 painCave.isFatal = 1;
1858 simError();
1859 }
1860
1861
1862 #ifdef IS_MPI
1863 strcpy(checkPointMsg, "Successfully intialized the mixingRule for Fortran.");
1864 MPIcheckPoint();
1865 #endif // is_mpi
1866 }
1867
1868 void SimSetup::setupZConstraint(SimInfo& theInfo){
1869 int nZConstraints;
1870 ZconStamp** zconStamp;
1871
1872 if (globals->haveZconstraintTime()){
1873 //add sample time of z-constraint into SimInfo's property list
1874 DoubleData* zconsTimeProp = new DoubleData();
1875 zconsTimeProp->setID(ZCONSTIME_ID);
1876 zconsTimeProp->setData(globals->getZconsTime());
1877 theInfo.addProperty(zconsTimeProp);
1878 }
1879 else{
1880 sprintf(painCave.errMsg,
1881 "ZConstraint error: If you use a ZConstraint,\n"
1882 "\tyou must set zconsTime.\n");
1883 painCave.isFatal = 1;
1884 simError();
1885 }
1886
1887 //push zconsTol into siminfo, if user does not specify
1888 //value for zconsTol, a default value will be used
1889 DoubleData* zconsTol = new DoubleData();
1890 zconsTol->setID(ZCONSTOL_ID);
1891 if (globals->haveZconsTol()){
1892 zconsTol->setData(globals->getZconsTol());
1893 }
1894 else{
1895 double defaultZConsTol = 0.01;
1896 sprintf(painCave.errMsg,
1897 "ZConstraint Warning: Tolerance for z-constraint method is not specified.\n"
1898 "\tOOPSE will use a default value of %f.\n"
1899 "\tTo set the tolerance, use the zconsTol variable.\n",
1900 defaultZConsTol);
1901 painCave.isFatal = 0;
1902 simError();
1903
1904 zconsTol->setData(defaultZConsTol);
1905 }
1906 theInfo.addProperty(zconsTol);
1907
1908 //set Force Subtraction Policy
1909 StringData* zconsForcePolicy = new StringData();
1910 zconsForcePolicy->setID(ZCONSFORCEPOLICY_ID);
1911
1912 if (globals->haveZconsForcePolicy()){
1913 zconsForcePolicy->setData(globals->getZconsForcePolicy());
1914 }
1915 else{
1916 sprintf(painCave.errMsg,
1917 "ZConstraint Warning: No force subtraction policy was set.\n"
1918 "\tOOPSE will use PolicyByMass.\n"
1919 "\tTo set the policy, use the zconsForcePolicy variable.\n");
1920 painCave.isFatal = 0;
1921 simError();
1922 zconsForcePolicy->setData("BYMASS");
1923 }
1924
1925 theInfo.addProperty(zconsForcePolicy);
1926
1927 //set zcons gap
1928 DoubleData* zconsGap = new DoubleData();
1929 zconsGap->setID(ZCONSGAP_ID);
1930
1931 if (globals->haveZConsGap()){
1932 zconsGap->setData(globals->getZconsGap());
1933 theInfo.addProperty(zconsGap);
1934 }
1935
1936 //set zcons fixtime
1937 DoubleData* zconsFixtime = new DoubleData();
1938 zconsFixtime->setID(ZCONSFIXTIME_ID);
1939
1940 if (globals->haveZConsFixTime()){
1941 zconsFixtime->setData(globals->getZconsFixtime());
1942 theInfo.addProperty(zconsFixtime);
1943 }
1944
1945 //set zconsUsingSMD
1946 IntData* zconsUsingSMD = new IntData();
1947 zconsUsingSMD->setID(ZCONSUSINGSMD_ID);
1948
1949 if (globals->haveZConsUsingSMD()){
1950 zconsUsingSMD->setData(globals->getZconsUsingSMD());
1951 theInfo.addProperty(zconsUsingSMD);
1952 }
1953
1954 //Determine the name of ouput file and add it into SimInfo's property list
1955 //Be careful, do not use inFileName, since it is a pointer which
1956 //point to a string at master node, and slave nodes do not contain that string
1957
1958 string zconsOutput(theInfo.finalName);
1959
1960 zconsOutput = zconsOutput.substr(0, zconsOutput.rfind(".")) + ".fz";
1961
1962 StringData* zconsFilename = new StringData();
1963 zconsFilename->setID(ZCONSFILENAME_ID);
1964 zconsFilename->setData(zconsOutput);
1965
1966 theInfo.addProperty(zconsFilename);
1967
1968 //setup index, pos and other parameters of z-constraint molecules
1969 nZConstraints = globals->getNzConstraints();
1970 theInfo.nZconstraints = nZConstraints;
1971
1972 zconStamp = globals->getZconStamp();
1973 ZConsParaItem tempParaItem;
1974
1975 ZConsParaData* zconsParaData = new ZConsParaData();
1976 zconsParaData->setID(ZCONSPARADATA_ID);
1977
1978 for (int i = 0; i < nZConstraints; i++){
1979 tempParaItem.havingZPos = zconStamp[i]->haveZpos();
1980 tempParaItem.zPos = zconStamp[i]->getZpos();
1981 tempParaItem.zconsIndex = zconStamp[i]->getMolIndex();
1982 tempParaItem.kRatio = zconStamp[i]->getKratio();
1983 tempParaItem.havingCantVel = zconStamp[i]->haveCantVel();
1984 tempParaItem.cantVel = zconStamp[i]->getCantVel();
1985 zconsParaData->addItem(tempParaItem);
1986 }
1987
1988 //check the uniqueness of index
1989 if(!zconsParaData->isIndexUnique()){
1990 sprintf(painCave.errMsg,
1991 "ZConstraint Error: molIndex is not unique!\n");
1992 painCave.isFatal = 1;
1993 simError();
1994 }
1995
1996 //sort the parameters by index of molecules
1997 zconsParaData->sortByIndex();
1998
1999 //push data into siminfo, therefore, we can retrieve later
2000 theInfo.addProperty(zconsParaData);
2001 }
2002
2003 void SimSetup::makeMinimizer(){
2004
2005 OOPSEMinimizer* myOOPSEMinimizer;
2006 MinimizerParameterSet* param;
2007 char minimizerName[100];
2008
2009 for (int i = 0; i < nInfo; i++){
2010
2011 //prepare parameter set for minimizer
2012 param = new MinimizerParameterSet();
2013 param->setDefaultParameter();
2014
2015 if (globals->haveMinimizer()){
2016 param->setFTol(globals->getMinFTol());
2017 }
2018
2019 if (globals->haveMinGTol()){
2020 param->setGTol(globals->getMinGTol());
2021 }
2022
2023 if (globals->haveMinMaxIter()){
2024 param->setMaxIteration(globals->getMinMaxIter());
2025 }
2026
2027 if (globals->haveMinWriteFrq()){
2028 param->setMaxIteration(globals->getMinMaxIter());
2029 }
2030
2031 if (globals->haveMinWriteFrq()){
2032 param->setWriteFrq(globals->getMinWriteFrq());
2033 }
2034
2035 if (globals->haveMinStepSize()){
2036 param->setStepSize(globals->getMinStepSize());
2037 }
2038
2039 if (globals->haveMinLSMaxIter()){
2040 param->setLineSearchMaxIteration(globals->getMinLSMaxIter());
2041 }
2042
2043 if (globals->haveMinLSTol()){
2044 param->setLineSearchTol(globals->getMinLSTol());
2045 }
2046
2047 strcpy(minimizerName, globals->getMinimizer());
2048
2049 if (!strcasecmp(minimizerName, "CG")){
2050 myOOPSEMinimizer = new PRCGMinimizer(&(info[i]), the_ff, param);
2051 }
2052 else if (!strcasecmp(minimizerName, "SD")){
2053 //myOOPSEMinimizer = MinimizerFactory.creatMinimizer("", &(info[i]), the_ff, param);
2054 myOOPSEMinimizer = new SDMinimizer(&(info[i]), the_ff, param);
2055 }
2056 else{
2057 sprintf(painCave.errMsg,
2058 "SimSetup error: Unrecognized Minimizer, use Conjugate Gradient \n");
2059 painCave.isFatal = 0;
2060 simError();
2061
2062 myOOPSEMinimizer = new PRCGMinimizer(&(info[i]), the_ff, param);
2063 }
2064 info[i].the_integrator = myOOPSEMinimizer;
2065
2066 //store the minimizer into simInfo
2067 info[i].the_minimizer = myOOPSEMinimizer;
2068 info[i].has_minimizer = true;
2069 }
2070
2071 }