ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimSetup.cpp
Revision: 424
Committed: Thu Mar 27 20:36:16 2003 UTC (21 years, 3 months ago) by mmeineke
File size: 27444 byte(s)
Log Message:
fixing some compile time bugs

File Contents

# Content
1 #include <cstdlib>
2 #include <iostream>
3 #include <cmath>
4
5 #include "SimSetup.hpp"
6 #include "parse_me.h"
7 #include "Integrator.hpp"
8 #include "simError.h"
9
10 #ifdef IS_MPI
11 #include "mpiBASS.h"
12 #include "mpiSimulation.hpp"
13 #endif
14
15 SimSetup::SimSetup(){
16 stamps = new MakeStamps();
17 globals = new Globals();
18
19 #ifdef IS_MPI
20 strcpy( checkPointMsg, "SimSetup creation successful" );
21 MPIcheckPoint();
22 #endif // IS_MPI
23 }
24
25 SimSetup::~SimSetup(){
26 delete stamps;
27 delete globals;
28 }
29
30 void SimSetup::parseFile( char* fileName ){
31
32 #ifdef IS_MPI
33 if( worldRank == 0 ){
34 #endif // is_mpi
35
36 inFileName = fileName;
37 set_interface_stamps( stamps, globals );
38
39 #ifdef IS_MPI
40 mpiEventInit();
41 #endif
42
43 yacc_BASS( fileName );
44
45 #ifdef IS_MPI
46 throwMPIEvent(NULL);
47 }
48 else receiveParse();
49 #endif
50
51 }
52
53 #ifdef IS_MPI
54 void SimSetup::receiveParse(void){
55
56 set_interface_stamps( stamps, globals );
57 mpiEventInit();
58 MPIcheckPoint();
59 mpiEventLoop();
60
61 }
62
63 #endif // is_mpi
64
65 void SimSetup::createSim( void ){
66
67 MakeStamps *the_stamps;
68 Globals* the_globals;
69 int i, j;
70
71 // get the stamps and globals;
72 the_stamps = stamps;
73 the_globals = globals;
74
75 // set the easy ones first
76 simnfo->target_temp = the_globals->getTargetTemp();
77 simnfo->dt = the_globals->getDt();
78 simnfo->run_time = the_globals->getRunTime();
79
80 // get the ones we know are there, yet still may need some work.
81 n_components = the_globals->getNComponents();
82 strcpy( force_field, the_globals->getForceField() );
83 strcpy( ensemble, the_globals->getEnsemble() );
84 strcpy( simnfo->ensemble, ensemble );
85
86 strcpy( simnfo->mixingRule, the_globals->getMixingRule() );
87 simnfo->usePBC = the_globals->getPBC();
88
89
90
91 if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF();
92 else if( !strcmp( force_field, "LJ" ) ) the_ff = new LJ_FF();
93 else{
94 sprintf( painCave.errMsg,
95 "SimSetup Error. Unrecognized force field -> %s\n",
96 force_field );
97 painCave.isFatal = 1;
98 simError();
99 }
100
101 #ifdef IS_MPI
102 strcpy( checkPointMsg, "ForceField creation successful" );
103 MPIcheckPoint();
104 #endif // is_mpi
105
106
107
108 // get the components and calculate the tot_nMol and indvidual n_mol
109 the_components = the_globals->getComponents();
110 components_nmol = new int[n_components];
111 comp_stamps = new MoleculeStamp*[n_components];
112
113 if( !the_globals->haveNMol() ){
114 // we don't have the total number of molecules, so we assume it is
115 // given in each component
116
117 tot_nmol = 0;
118 for( i=0; i<n_components; i++ ){
119
120 if( !the_components[i]->haveNMol() ){
121 // we have a problem
122 sprintf( painCave.errMsg,
123 "SimSetup Error. No global NMol or component NMol"
124 " given. Cannot calculate the number of atoms.\n" );
125 painCave.isFatal = 1;
126 simError();
127 }
128
129 tot_nmol += the_components[i]->getNMol();
130 components_nmol[i] = the_components[i]->getNMol();
131 }
132 }
133 else{
134 sprintf( painCave.errMsg,
135 "SimSetup error.\n"
136 "\tSorry, the ability to specify total"
137 " nMols and then give molfractions in the components\n"
138 "\tis not currently supported."
139 " Please give nMol in the components.\n" );
140 painCave.isFatal = 1;
141 simError();
142
143
144 // tot_nmol = the_globals->getNMol();
145
146 // //we have the total number of molecules, now we check for molfractions
147 // for( i=0; i<n_components; i++ ){
148
149 // if( !the_components[i]->haveMolFraction() ){
150
151 // if( !the_components[i]->haveNMol() ){
152 // //we have a problem
153 // std::cerr << "SimSetup error. Neither molFraction nor "
154 // << " nMol was given in component
155
156 }
157
158 #ifdef IS_MPI
159 strcpy( checkPointMsg, "Have the number of components" );
160 MPIcheckPoint();
161 #endif // is_mpi
162
163 // make an array of molecule stamps that match the components used.
164 // also extract the used stamps out into a separate linked list
165
166 simnfo->nComponents = n_components;
167 simnfo->componentsNmol = components_nmol;
168 simnfo->compStamps = comp_stamps;
169 simnfo->headStamp = new LinkedMolStamp();
170
171 char* id;
172 LinkedMolStamp* headStamp = simnfo->headStamp;
173 LinkedMolStamp* currentStamp = NULL;
174 for( i=0; i<n_components; i++ ){
175
176 id = the_components[i]->getType();
177 comp_stamps[i] = NULL;
178
179 // check to make sure the component isn't already in the list
180
181 comp_stamps[i] = headStamp->match( id );
182 if( comp_stamps[i] == NULL ){
183
184 // extract the component from the list;
185
186 currentStamp = the_stamps->extractMolStamp( id );
187 if( currentStamp == NULL ){
188 sprintf( painCave.errMsg,
189 "SimSetup error: Component \"%s\" was not found in the "
190 "list of declared molecules\n",
191 id );
192 painCave.isFatal = 1;
193 simError();
194 }
195
196 headStamp->add( currentStamp );
197 comp_stamps[i] = headStamp->match( id );
198 }
199 }
200
201 #ifdef IS_MPI
202 strcpy( checkPointMsg, "Component stamps successfully extracted\n" );
203 MPIcheckPoint();
204 #endif // is_mpi
205
206
207
208
209 // caclulate the number of atoms, bonds, bends and torsions
210
211 tot_atoms = 0;
212 tot_bonds = 0;
213 tot_bends = 0;
214 tot_torsions = 0;
215 for( i=0; i<n_components; i++ ){
216
217 tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms();
218 tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds();
219 tot_bends += components_nmol[i] * comp_stamps[i]->getNBends();
220 tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions();
221 }
222
223 tot_SRI = tot_bonds + tot_bends + tot_torsions;
224
225 simnfo->n_atoms = tot_atoms;
226 simnfo->n_bonds = tot_bonds;
227 simnfo->n_bends = tot_bends;
228 simnfo->n_torsions = tot_torsions;
229 simnfo->n_SRI = tot_SRI;
230 simnfo->n_mol = tot_nmol;
231
232
233 #ifdef IS_MPI
234
235 // divide the molecules among processors here.
236
237 mpiSim = new mpiSimulation( simnfo );
238
239
240
241 globalIndex = mpiSim->divideLabor();
242
243
244
245 // set up the local variables
246
247 int localMol, allMol;
248 int local_atoms, local_bonds, local_bends, local_torsions, local_SRI;
249
250 int* mol2proc = mpiSim->getMolToProcMap();
251 int* molCompType = mpiSim->getMolComponentType();
252
253 allMol = 0;
254 localMol = 0;
255 local_atoms = 0;
256 local_bonds = 0;
257 local_bends = 0;
258 local_torsions = 0;
259 for( i=0; i<n_components; i++ ){
260
261 for( j=0; j<components_nmol[i]; j++ ){
262
263 if( mol2proc[j] == worldRank ){
264
265 local_atoms += comp_stamps[i]->getNAtoms();
266 local_bonds += comp_stamps[i]->getNBonds();
267 local_bends += comp_stamps[i]->getNBends();
268 local_torsions += comp_stamps[i]->getNTorsions();
269 localMol++;
270 }
271 allMol++;
272 }
273 }
274 local_SRI = local_bonds + local_bends + local_torsions;
275
276
277 simnfo->n_atoms = mpiSim->getMyNlocal();
278
279 if( local_atoms != simnfo->n_atoms ){
280 sprintf( painCave.errMsg,
281 "SimSetup error: mpiSim's localAtom (%d) and SimSetup's"
282 " localAtom (%d) are not equal.\n",
283 simnfo->n_atoms,
284 local_atoms );
285 painCave.isFatal = 1;
286 simError();
287 }
288
289 simnfo->n_bonds = local_bonds;
290 simnfo->n_bends = local_bends;
291 simnfo->n_torsions = local_torsions;
292 simnfo->n_SRI = local_SRI;
293 simnfo->n_mol = localMol;
294
295 strcpy( checkPointMsg, "Passed nlocal consistency check." );
296 MPIcheckPoint();
297
298
299 #endif // is_mpi
300
301
302 // create the atom and short range interaction arrays
303
304 Atom::createArrays(simnfo->n_atoms);
305 the_atoms = new Atom*[simnfo->n_atoms];
306 the_molecules = new Molecule[simnfo->n_mol];
307 int molIndex;
308
309 // initialize the molecule's stampID's
310
311 #ifdef IS_MPI
312
313
314 molIndex = 0;
315 for(i=0; i<mpiSim->getTotNmol(); i++){
316
317 if(mol2proc[i] == worldRank ){
318 the_molecules[molIndex].setStampID( molCompType[i] );
319 molIndex++;
320 }
321 }
322
323 #else // is_mpi
324
325 molIndex = 0;
326 for(i=0; i<n_components; i++){
327 for(j=0; j<components_nmol[i]; j++ ){
328 the_molecules[molIndex].setStampID( i );
329 molIndex++;
330 }
331 }
332
333
334 #endif // is_mpi
335
336
337 if( simnfo->n_SRI ){
338 Exclude::createArray(simnfo->n_SRI);
339 the_excludes = new Exclude*[simnfo->n_SRI];
340 simnfo->globalExcludes = new int;
341 simnfo->n_exclude = tot_SRI;
342 }
343 else{
344
345 Exclude::createArray( 1 );
346 the_excludes = new Exclude*;
347 the_excludes[0] = new Exclude(0);
348 the_excludes[0]->setPair( 0,0 );
349 simnfo->globalExcludes = new int;
350 simnfo->globalExcludes[0] = 0;
351 simnfo->n_exclude = 0;
352 }
353
354 // set the arrays into the SimInfo object
355
356 simnfo->atoms = the_atoms;
357 simnfo->nGlobalExcludes = 0;
358 simnfo->excludes = the_excludes;
359
360
361 // get some of the tricky things that may still be in the globals
362
363
364 if( the_globals->haveBox() ){
365 simnfo->box_x = the_globals->getBox();
366 simnfo->box_y = the_globals->getBox();
367 simnfo->box_z = the_globals->getBox();
368 }
369 else if( the_globals->haveDensity() ){
370
371 double vol;
372 vol = (double)tot_nmol / the_globals->getDensity();
373 simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) );
374 simnfo->box_y = simnfo->box_x;
375 simnfo->box_z = simnfo->box_x;
376 }
377 else{
378 if( !the_globals->haveBoxX() ){
379 sprintf( painCave.errMsg,
380 "SimSetup error, no periodic BoxX size given.\n" );
381 painCave.isFatal = 1;
382 simError();
383 }
384 simnfo->box_x = the_globals->getBoxX();
385
386 if( !the_globals->haveBoxY() ){
387 sprintf( painCave.errMsg,
388 "SimSetup error, no periodic BoxY size given.\n" );
389 painCave.isFatal = 1;
390 simError();
391 }
392 simnfo->box_y = the_globals->getBoxY();
393
394 if( !the_globals->haveBoxZ() ){
395 sprintf( painCave.errMsg,
396 "SimSetup error, no periodic BoxZ size given.\n" );
397 painCave.isFatal = 1;
398 simError();
399 }
400 simnfo->box_z = the_globals->getBoxZ();
401 }
402
403 #ifdef IS_MPI
404 strcpy( checkPointMsg, "Box size set up" );
405 MPIcheckPoint();
406 #endif // is_mpi
407
408
409 // initialize the arrays
410
411 the_ff->setSimInfo( simnfo );
412
413 makeMolecules();
414 simnfo->identArray = new int[simnfo->n_atoms];
415 for(i=0; i<simnfo->n_atoms; i++){
416 simnfo->identArray[i] = the_atoms[i]->getIdent();
417 }
418
419 if (the_globals->getUseRF() ) {
420 simnfo->useReactionField = 1;
421
422 if( !the_globals->haveECR() ){
423 sprintf( painCave.errMsg,
424 "SimSetup Warning: using default value of 1/2 the smallest "
425 "box length for the electrostaticCutoffRadius.\n"
426 "I hope you have a very fast processor!\n");
427 painCave.isFatal = 0;
428 simError();
429 double smallest;
430 smallest = simnfo->box_x;
431 if (simnfo->box_y <= smallest) smallest = simnfo->box_y;
432 if (simnfo->box_z <= smallest) smallest = simnfo->box_z;
433 simnfo->ecr = 0.5 * smallest;
434 } else {
435 simnfo->ecr = the_globals->getECR();
436 }
437
438 if( !the_globals->haveEST() ){
439 sprintf( painCave.errMsg,
440 "SimSetup Warning: using default value of 0.05 * the "
441 "electrostaticCutoffRadius for the electrostaticSkinThickness\n"
442 );
443 painCave.isFatal = 0;
444 simError();
445 simnfo->est = 0.05 * simnfo->ecr;
446 } else {
447 simnfo->est = the_globals->getEST();
448 }
449
450 if(!the_globals->haveDielectric() ){
451 sprintf( painCave.errMsg,
452 "SimSetup Error: You are trying to use Reaction Field without"
453 "setting a dielectric constant!\n"
454 );
455 painCave.isFatal = 1;
456 simError();
457 }
458 simnfo->dielectric = the_globals->getDielectric();
459 } else {
460 if (simnfo->n_dipoles) {
461
462 if( !the_globals->haveECR() ){
463 sprintf( painCave.errMsg,
464 "SimSetup Warning: using default value of 1/2 the smallest"
465 "box length for the electrostaticCutoffRadius.\n"
466 "I hope you have a very fast processor!\n");
467 painCave.isFatal = 0;
468 simError();
469 double smallest;
470 smallest = simnfo->box_x;
471 if (simnfo->box_y <= smallest) smallest = simnfo->box_y;
472 if (simnfo->box_z <= smallest) smallest = simnfo->box_z;
473 simnfo->ecr = 0.5 * smallest;
474 } else {
475 simnfo->ecr = the_globals->getECR();
476 }
477
478 if( !the_globals->haveEST() ){
479 sprintf( painCave.errMsg,
480 "SimSetup Warning: using default value of 5% of the"
481 "electrostaticCutoffRadius for the "
482 "electrostaticSkinThickness\n"
483 );
484 painCave.isFatal = 0;
485 simError();
486 simnfo->est = 0.05 * simnfo->ecr;
487 } else {
488 simnfo->est = the_globals->getEST();
489 }
490 }
491 }
492
493 #ifdef IS_MPI
494 strcpy( checkPointMsg, "electrostatic parameters check out" );
495 MPIcheckPoint();
496 #endif // is_mpi
497
498 if( the_globals->haveInitialConfig() ){
499
500 InitializeFromFile* fileInit;
501 #ifdef IS_MPI // is_mpi
502 if( worldRank == 0 ){
503 #endif //is_mpi
504 fileInit = new InitializeFromFile( the_globals->getInitialConfig() );
505 #ifdef IS_MPI
506 }else fileInit = new InitializeFromFile( NULL );
507 #endif
508 fileInit->read_xyz( simnfo ); // default velocities on
509
510 delete fileInit;
511 }
512 else{
513
514 #ifdef IS_MPI
515
516 // no init from bass
517
518 sprintf( painCave.errMsg,
519 "Cannot intialize a parallel simulation without an initial configuration file.\n" );
520 painCave.isFatal;
521 simError();
522
523 #else
524
525 initFromBass();
526
527
528 #endif
529 }
530
531 #ifdef IS_MPI
532 strcpy( checkPointMsg, "Successfully read in the initial configuration" );
533 MPIcheckPoint();
534 #endif // is_mpi
535
536
537
538
539
540
541
542 #ifdef IS_MPI
543 if( worldRank == 0 ){
544 #endif // is_mpi
545
546 if( the_globals->haveFinalConfig() ){
547 strcpy( simnfo->finalName, the_globals->getFinalConfig() );
548 }
549 else{
550 strcpy( simnfo->finalName, inFileName );
551 char* endTest;
552 int nameLength = strlen( simnfo->finalName );
553 endTest = &(simnfo->finalName[nameLength - 5]);
554 if( !strcmp( endTest, ".bass" ) ){
555 strcpy( endTest, ".eor" );
556 }
557 else if( !strcmp( endTest, ".BASS" ) ){
558 strcpy( endTest, ".eor" );
559 }
560 else{
561 endTest = &(simnfo->finalName[nameLength - 4]);
562 if( !strcmp( endTest, ".bss" ) ){
563 strcpy( endTest, ".eor" );
564 }
565 else if( !strcmp( endTest, ".mdl" ) ){
566 strcpy( endTest, ".eor" );
567 }
568 else{
569 strcat( simnfo->finalName, ".eor" );
570 }
571 }
572 }
573
574 // make the sample and status out names
575
576 strcpy( simnfo->sampleName, inFileName );
577 char* endTest;
578 int nameLength = strlen( simnfo->sampleName );
579 endTest = &(simnfo->sampleName[nameLength - 5]);
580 if( !strcmp( endTest, ".bass" ) ){
581 strcpy( endTest, ".dump" );
582 }
583 else if( !strcmp( endTest, ".BASS" ) ){
584 strcpy( endTest, ".dump" );
585 }
586 else{
587 endTest = &(simnfo->sampleName[nameLength - 4]);
588 if( !strcmp( endTest, ".bss" ) ){
589 strcpy( endTest, ".dump" );
590 }
591 else if( !strcmp( endTest, ".mdl" ) ){
592 strcpy( endTest, ".dump" );
593 }
594 else{
595 strcat( simnfo->sampleName, ".dump" );
596 }
597 }
598
599 strcpy( simnfo->statusName, inFileName );
600 nameLength = strlen( simnfo->statusName );
601 endTest = &(simnfo->statusName[nameLength - 5]);
602 if( !strcmp( endTest, ".bass" ) ){
603 strcpy( endTest, ".stat" );
604 }
605 else if( !strcmp( endTest, ".BASS" ) ){
606 strcpy( endTest, ".stat" );
607 }
608 else{
609 endTest = &(simnfo->statusName[nameLength - 4]);
610 if( !strcmp( endTest, ".bss" ) ){
611 strcpy( endTest, ".stat" );
612 }
613 else if( !strcmp( endTest, ".mdl" ) ){
614 strcpy( endTest, ".stat" );
615 }
616 else{
617 strcat( simnfo->statusName, ".stat" );
618 }
619 }
620
621 #ifdef IS_MPI
622 }
623 #endif // is_mpi
624
625 // set the status, sample, and themal kick times
626
627 if( the_globals->haveSampleTime() ){
628 simnfo->sampleTime = the_globals->getSampleTime();
629 simnfo->statusTime = simnfo->sampleTime;
630 simnfo->thermalTime = simnfo->sampleTime;
631 }
632 else{
633 simnfo->sampleTime = the_globals->getRunTime();
634 simnfo->statusTime = simnfo->sampleTime;
635 simnfo->thermalTime = simnfo->sampleTime;
636 }
637
638 if( the_globals->haveStatusTime() ){
639 simnfo->statusTime = the_globals->getStatusTime();
640 }
641
642 if( the_globals->haveThermalTime() ){
643 simnfo->thermalTime = the_globals->getThermalTime();
644 }
645
646 // check for the temperature set flag
647
648 if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet();
649
650
651 // // make the longe range forces and the integrator
652
653 // new AllLong( simnfo );
654
655 if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo, the_ff );
656 if( !strcmp( force_field, "LJ" ) ) new Verlet( *simnfo, the_ff );
657
658
659
660 // initialize the Fortran
661
662 simnfo->refreshSim();
663
664 if( !strcmp( simnfo->mixingRule, "standard") ){
665 the_ff->initForceField( LB_MIXING_RULE );
666 }
667 else if( !strcmp( simnfo->mixingRule, "explicit") ){
668 the_ff->initForceField( EXPLICIT_MIXING_RULE );
669 }
670 else{
671 sprintf( painCave.errMsg,
672 "SimSetup Error: unknown mixing rule -> \"%s\"\n",
673 simnfo->mixingRule );
674 painCave.isFatal = 1;
675 simError();
676 }
677
678
679 #ifdef IS_MPI
680 strcpy( checkPointMsg,
681 "Successfully intialized the mixingRule for Fortran." );
682 MPIcheckPoint();
683 #endif // is_mpi
684 }
685
686
687 void SimSetup::makeMolecules( void ){
688
689 int i, j, exI, exJ, tempEx, stampID, atomOffset, excludeOffset;
690 molInit info;
691 DirectionalAtom* dAtom;
692 LinkedAssign* extras;
693 LinkedAssign* current_extra;
694 AtomStamp* currentAtom;
695 BondStamp* currentBond;
696 BendStamp* currentBend;
697 TorsionStamp* currentTorsion;
698
699 //init the forceField paramters
700
701 the_ff->readParams();
702
703
704 // init the molecules
705
706 atomOffset = 0;
707 excludeOffset = 0;
708 for(i=0; i<simnfo->n_mol; i++){
709
710 stampID = the_molecules[i].getStampID();
711
712 info.nAtoms = comp_stamps[stampID]->getNAtoms();
713 info.nBonds = comp_stamps[stampID]->getNBonds();
714 info.nBends = comp_stamps[stampID]->getNBends();
715 info.nTorsions = comp_stamps[stampID]->getNTorsions();
716 info.nExcludes = info.nBonds + info.nBends + info.nTorsions;
717
718 info.myAtoms = &the_atoms[atomOffset];
719 info.myExcludes = &the_excludes[excludeOffset];
720 info.myBonds = new Bond*[info.nBonds];
721 info.myBends = new Bend*[info.nBends];
722 info.myTorsions = new Torsions*[info.nTorsions];
723
724 theBonds = new bond_pair[info.nBonds];
725 theBends = new bend_set[info.nBends];
726 theTorsions = new torsion_set[info.nTorsions];
727
728 // make the Atoms
729
730 for(j=0; j<info.nAtoms; j++){
731
732 currentAtom = theComponents[stampID]->getAtom( j );
733 if( currentAtom->haveOrientation() ){
734
735 dAtom = new DirectionalAtom(j + atomOffset);
736 simnfo->n_oriented++;
737 info.myAtoms[j] = dAtom;
738
739 ux = currentAtom->getOrntX();
740 uy = currentAtom->getOrntY();
741 uz = currentAtom->getOrntZ();
742
743 uSqr = (ux * ux) + (uy * uy) + (uz * uz);
744
745 u = sqrt( uSqr );
746 ux = ux / u;
747 uy = uy / u;
748 uz = uz / u;
749
750 dAtom->setSUx( ux );
751 dAtom->setSUy( uy );
752 dAtom->setSUz( uz );
753 }
754 else{
755 info.myAtoms[j] = new GeneralAtom(j + atomOffset);
756 }
757 info.myAtoms[j]->setType( currentAtom->getType() );
758
759 #ifdef IS_MPI
760
761 info.myAtoms[j]->setGlobalIndex( globalIndex[j+atomOffset] );
762
763 #endif // is_mpi
764 }
765
766 // make the bonds
767 for(j=0; j<info.nBonds; j++){
768
769 currentBond = comp_stamps[stampID]->getBond( j );
770 theBonds[j].a = currentBond->getA() + atomOffset;
771 theBonds[j].b = currentBond->getB() + atomOffset;
772
773 exI = theBonds[i].a;
774 exJ = theBonds[i].b;
775
776 // exclude_I must always be the smaller of the pair
777 if( exI > exJ ){
778 tempEx = exI;
779 exI = exJ;
780 exJ = tempEx;
781 }
782 #ifdef IS_MPI
783 tempEx = exI;
784 exI = the_atoms[tempEx]->getGlobalIndex() + 1;
785 tempEx = exJ;
786 exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
787
788 the_excludes[j+excludeOffset]->setPair( exI, exJ );
789 #else // isn't MPI
790 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
791 #endif //is_mpi
792 }
793 excludeOffset += info.nBonds;
794
795 //make the bends
796 for(j=0; j<info.nBends; j++){
797
798 currentBend = comp_stamps[stampID]->getBend( j );
799 theBends[j].a = currentBend->getA() + atomOffset;
800 theBends[j].b = currentBend->getB() + atomOffset;
801 theBends[j].c = currentBend->getC() + atomOffset;
802
803 if( currentBend->haveExtras() ){
804
805 extras = current_bend->getExtras();
806 current_extra = extras;
807
808 while( current_extra != NULL ){
809 if( !strcmp( current_extra->getlhs(), "ghostVectorSource" )){
810
811 switch( current_extra->getType() ){
812
813 case 0:
814 theBends[j].ghost =
815 current_extra->getInt() + atomOffset;
816 theBends[j].isGhost = 1;
817 break;
818
819 case 1:
820 theBends[j].ghost =
821 (int)current_extra->getDouble() + atomOffset;
822 theBends[j].isGhost = 1;
823 break;
824
825 default:
826 sprintf( painCave.errMsg,
827 "SimSetup Error: ghostVectorSource was neiter a "
828 "double nor an int.\n"
829 "-->Bend[%d] in %s\n",
830 j, comp_stamps[stampID]->getID() );
831 painCave.isFatal = 1;
832 simError();
833 }
834 }
835
836 else{
837
838 sprintf( painCave.errMsg,
839 "SimSetup Error: unhandled bend assignment:\n"
840 " -->%s in Bend[%d] in %s\n",
841 current_extra->getlhs(),
842 j, comp_stamps[stampID]->getID() );
843 painCave.isFatal = 1;
844 simError();
845 }
846
847 current_extra = current_extra->getNext();
848 }
849 }
850
851 if( !theBends[j].isGhost ){
852
853 exI = theBends[j].a;
854 exJ = theBends[j].c;
855 }
856 else{
857
858 exI = theBends[j].a;
859 exJ = theBends[j].b;
860 }
861
862 // exclude_I must always be the smaller of the pair
863 if( exI > exJ ){
864 tempEx = exI;
865 exI = exJ;
866 exJ = tempEx;
867 }
868 #ifdef IS_MPI
869 tempEx = exI;
870 exI = the_atoms[tempEx]->getGlobalIndex() + 1;
871 tempEx = exJ;
872 exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
873
874 the_excludes[j+excludeOffset]->setPair( exI, exJ );
875 #else // isn't MPI
876 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
877 #endif //is_mpi
878 }
879 excludeOffset += info.nBends;
880
881 for(j=0; j<info.nTorsions; j++){
882
883 currentTorsion = comp_stamps[stampID]->getTorsion( j );
884 theTorsions[j].a = currentTorsion->getA() + atomOffset;
885 theTorsions[j].b = currentTorsion->getB() + atomOffset;
886 theTorsions[j].c = currentTorsion->getC() + atomOffset;
887 theTorsions[j].d = currentTorsion->getD() + atomOffset;
888
889 exI = theTorsions[j].a;
890 exJ = theTorsions[j].d;
891
892 // exclude_I must always be the smaller of the pair
893 if( exI > exJ ){
894 tempEx = exI;
895 exI = exJ;
896 exJ = tempEx;
897 }
898 #ifdef IS_MPI
899 tempEx = exI;
900 exI = the_atoms[tempEx]->getGlobalIndex() + 1;
901 tempEx = exJ;
902 exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
903
904 the_excludes[j+excludeOffset]->setPair( exI, exJ );
905 #else // isn't MPI
906 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
907 #endif //is_mpi
908 }
909 excludeOffset += info.nTorsions;
910
911
912 // send the arrays off to the forceField for init.
913
914 the_ff->initializeAtoms( info.nAtoms, info.myAtoms );
915 the_ff->initializeBonds( info.nBonds, info.myBonds, theBonds );
916 the_ff->initializeBends( info.nBends, info.myBends, theBends );
917 the_ff->initializeTorsions( info.nTorsions, info.myTorsions, theTorsions );
918
919
920 the_molecules[i].initialize( info );
921 atomOffset += info.nAtoms;
922 }
923
924 // clean up the forcefield
925 the_ff->calcRcut();
926 the_ff->cleanMe();
927 }
928
929 void SimSetup::initFromBass( void ){
930
931 int i, j, k;
932 int n_cells;
933 double cellx, celly, cellz;
934 double temp1, temp2, temp3;
935 int n_per_extra;
936 int n_extra;
937 int have_extra, done;
938
939 temp1 = (double)tot_nmol / 4.0;
940 temp2 = pow( temp1, ( 1.0 / 3.0 ) );
941 temp3 = ceil( temp2 );
942
943 have_extra =0;
944 if( temp2 < temp3 ){ // we have a non-complete lattice
945 have_extra =1;
946
947 n_cells = (int)temp3 - 1;
948 cellx = simnfo->box_x / temp3;
949 celly = simnfo->box_y / temp3;
950 cellz = simnfo->box_z / temp3;
951 n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells );
952 temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) );
953 n_per_extra = (int)ceil( temp1 );
954
955 if( n_per_extra > 4){
956 sprintf( painCave.errMsg,
957 "SimSetup error. There has been an error in constructing"
958 " the non-complete lattice.\n" );
959 painCave.isFatal = 1;
960 simError();
961 }
962 }
963 else{
964 n_cells = (int)temp3;
965 cellx = simnfo->box_x / temp3;
966 celly = simnfo->box_y / temp3;
967 cellz = simnfo->box_z / temp3;
968 }
969
970 current_mol = 0;
971 current_comp_mol = 0;
972 current_comp = 0;
973 current_atom_ndx = 0;
974
975 for( i=0; i < n_cells ; i++ ){
976 for( j=0; j < n_cells; j++ ){
977 for( k=0; k < n_cells; k++ ){
978
979 makeElement( i * cellx,
980 j * celly,
981 k * cellz );
982
983 makeElement( i * cellx + 0.5 * cellx,
984 j * celly + 0.5 * celly,
985 k * cellz );
986
987 makeElement( i * cellx,
988 j * celly + 0.5 * celly,
989 k * cellz + 0.5 * cellz );
990
991 makeElement( i * cellx + 0.5 * cellx,
992 j * celly,
993 k * cellz + 0.5 * cellz );
994 }
995 }
996 }
997
998 if( have_extra ){
999 done = 0;
1000
1001 int start_ndx;
1002 for( i=0; i < (n_cells+1) && !done; i++ ){
1003 for( j=0; j < (n_cells+1) && !done; j++ ){
1004
1005 if( i < n_cells ){
1006
1007 if( j < n_cells ){
1008 start_ndx = n_cells;
1009 }
1010 else start_ndx = 0;
1011 }
1012 else start_ndx = 0;
1013
1014 for( k=start_ndx; k < (n_cells+1) && !done; k++ ){
1015
1016 makeElement( i * cellx,
1017 j * celly,
1018 k * cellz );
1019 done = ( current_mol >= tot_nmol );
1020
1021 if( !done && n_per_extra > 1 ){
1022 makeElement( i * cellx + 0.5 * cellx,
1023 j * celly + 0.5 * celly,
1024 k * cellz );
1025 done = ( current_mol >= tot_nmol );
1026 }
1027
1028 if( !done && n_per_extra > 2){
1029 makeElement( i * cellx,
1030 j * celly + 0.5 * celly,
1031 k * cellz + 0.5 * cellz );
1032 done = ( current_mol >= tot_nmol );
1033 }
1034
1035 if( !done && n_per_extra > 3){
1036 makeElement( i * cellx + 0.5 * cellx,
1037 j * celly,
1038 k * cellz + 0.5 * cellz );
1039 done = ( current_mol >= tot_nmol );
1040 }
1041 }
1042 }
1043 }
1044 }
1045
1046
1047 for( i=0; i<simnfo->n_atoms; i++ ){
1048 simnfo->atoms[i]->set_vx( 0.0 );
1049 simnfo->atoms[i]->set_vy( 0.0 );
1050 simnfo->atoms[i]->set_vz( 0.0 );
1051 }
1052 }
1053
1054 void SimSetup::makeElement( double x, double y, double z ){
1055
1056 int k;
1057 AtomStamp* current_atom;
1058 DirectionalAtom* dAtom;
1059 double rotMat[3][3];
1060
1061 for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){
1062
1063 current_atom = comp_stamps[current_comp]->getAtom( k );
1064 if( !current_atom->havePosition() ){
1065 sprintf( painCave.errMsg,
1066 "SimSetup:initFromBass error.\n"
1067 "\tComponent %s, atom %s does not have a position specified.\n"
1068 "\tThe initialization routine is unable to give a start"
1069 " position.\n",
1070 comp_stamps[current_comp]->getID(),
1071 current_atom->getType() );
1072 painCave.isFatal = 1;
1073 simError();
1074 }
1075
1076 the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() );
1077 the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() );
1078 the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() );
1079
1080 if( the_atoms[current_atom_ndx]->isDirectional() ){
1081
1082 dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx];
1083
1084 rotMat[0][0] = 1.0;
1085 rotMat[0][1] = 0.0;
1086 rotMat[0][2] = 0.0;
1087
1088 rotMat[1][0] = 0.0;
1089 rotMat[1][1] = 1.0;
1090 rotMat[1][2] = 0.0;
1091
1092 rotMat[2][0] = 0.0;
1093 rotMat[2][1] = 0.0;
1094 rotMat[2][2] = 1.0;
1095
1096 dAtom->setA( rotMat );
1097 }
1098
1099 current_atom_ndx++;
1100 }
1101
1102 current_mol++;
1103 current_comp_mol++;
1104
1105 if( current_comp_mol >= components_nmol[current_comp] ){
1106
1107 current_comp_mol = 0;
1108 current_comp++;
1109 }
1110 }