ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimSetup.cpp
Revision: 431
Committed: Thu Mar 27 22:16:27 2003 UTC (21 years, 3 months ago) by mmeineke
File size: 27796 byte(s)
Log Message:
fixed a bug where excludes were not being initialized

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
339 std::cerr << "n_SRI = " << simnfo->n_SRI << "\n";
340
341 Exclude::createArray(simnfo->n_SRI);
342 the_excludes = new Exclude*[simnfo->n_SRI];
343 for( int ex=0; ex<simnfo->n_SRI; ex++) the_excludes[ex] = new Exclude(ex);
344 simnfo->globalExcludes = new int;
345 simnfo->n_exclude = tot_SRI;
346 }
347 else{
348
349 Exclude::createArray( 1 );
350 the_excludes = new Exclude*;
351 the_excludes[0] = new Exclude(0);
352 the_excludes[0]->setPair( 0,0 );
353 simnfo->globalExcludes = new int;
354 simnfo->globalExcludes[0] = 0;
355 simnfo->n_exclude = 0;
356 }
357
358 // set the arrays into the SimInfo object
359
360 simnfo->atoms = the_atoms;
361 simnfo->molecules = the_molecules;
362 simnfo->nGlobalExcludes = 0;
363 simnfo->excludes = the_excludes;
364
365
366 // get some of the tricky things that may still be in the globals
367
368
369 if( the_globals->haveBox() ){
370 simnfo->box_x = the_globals->getBox();
371 simnfo->box_y = the_globals->getBox();
372 simnfo->box_z = the_globals->getBox();
373 }
374 else if( the_globals->haveDensity() ){
375
376 double vol;
377 vol = (double)tot_nmol / the_globals->getDensity();
378 simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) );
379 simnfo->box_y = simnfo->box_x;
380 simnfo->box_z = simnfo->box_x;
381 }
382 else{
383 if( !the_globals->haveBoxX() ){
384 sprintf( painCave.errMsg,
385 "SimSetup error, no periodic BoxX size given.\n" );
386 painCave.isFatal = 1;
387 simError();
388 }
389 simnfo->box_x = the_globals->getBoxX();
390
391 if( !the_globals->haveBoxY() ){
392 sprintf( painCave.errMsg,
393 "SimSetup error, no periodic BoxY size given.\n" );
394 painCave.isFatal = 1;
395 simError();
396 }
397 simnfo->box_y = the_globals->getBoxY();
398
399 if( !the_globals->haveBoxZ() ){
400 sprintf( painCave.errMsg,
401 "SimSetup error, no periodic BoxZ size given.\n" );
402 painCave.isFatal = 1;
403 simError();
404 }
405 simnfo->box_z = the_globals->getBoxZ();
406 }
407
408 #ifdef IS_MPI
409 strcpy( checkPointMsg, "Box size set up" );
410 MPIcheckPoint();
411 #endif // is_mpi
412
413
414 // initialize the arrays
415
416 the_ff->setSimInfo( simnfo );
417
418 makeMolecules();
419 simnfo->identArray = new int[simnfo->n_atoms];
420 for(i=0; i<simnfo->n_atoms; i++){
421 simnfo->identArray[i] = the_atoms[i]->getIdent();
422 }
423
424 if (the_globals->getUseRF() ) {
425 simnfo->useReactionField = 1;
426
427 if( !the_globals->haveECR() ){
428 sprintf( painCave.errMsg,
429 "SimSetup Warning: using default value of 1/2 the smallest "
430 "box length for the electrostaticCutoffRadius.\n"
431 "I hope you have a very fast processor!\n");
432 painCave.isFatal = 0;
433 simError();
434 double smallest;
435 smallest = simnfo->box_x;
436 if (simnfo->box_y <= smallest) smallest = simnfo->box_y;
437 if (simnfo->box_z <= smallest) smallest = simnfo->box_z;
438 simnfo->ecr = 0.5 * smallest;
439 } else {
440 simnfo->ecr = the_globals->getECR();
441 }
442
443 if( !the_globals->haveEST() ){
444 sprintf( painCave.errMsg,
445 "SimSetup Warning: using default value of 0.05 * the "
446 "electrostaticCutoffRadius for the electrostaticSkinThickness\n"
447 );
448 painCave.isFatal = 0;
449 simError();
450 simnfo->est = 0.05 * simnfo->ecr;
451 } else {
452 simnfo->est = the_globals->getEST();
453 }
454
455 if(!the_globals->haveDielectric() ){
456 sprintf( painCave.errMsg,
457 "SimSetup Error: You are trying to use Reaction Field without"
458 "setting a dielectric constant!\n"
459 );
460 painCave.isFatal = 1;
461 simError();
462 }
463 simnfo->dielectric = the_globals->getDielectric();
464 } else {
465 if (simnfo->n_dipoles) {
466
467 if( !the_globals->haveECR() ){
468 sprintf( painCave.errMsg,
469 "SimSetup Warning: using default value of 1/2 the smallest"
470 "box length for the electrostaticCutoffRadius.\n"
471 "I hope you have a very fast processor!\n");
472 painCave.isFatal = 0;
473 simError();
474 double smallest;
475 smallest = simnfo->box_x;
476 if (simnfo->box_y <= smallest) smallest = simnfo->box_y;
477 if (simnfo->box_z <= smallest) smallest = simnfo->box_z;
478 simnfo->ecr = 0.5 * smallest;
479 } else {
480 simnfo->ecr = the_globals->getECR();
481 }
482
483 if( !the_globals->haveEST() ){
484 sprintf( painCave.errMsg,
485 "SimSetup Warning: using default value of 5% of the"
486 "electrostaticCutoffRadius for the "
487 "electrostaticSkinThickness\n"
488 );
489 painCave.isFatal = 0;
490 simError();
491 simnfo->est = 0.05 * simnfo->ecr;
492 } else {
493 simnfo->est = the_globals->getEST();
494 }
495 }
496 }
497
498 #ifdef IS_MPI
499 strcpy( checkPointMsg, "electrostatic parameters check out" );
500 MPIcheckPoint();
501 #endif // is_mpi
502
503 if( the_globals->haveInitialConfig() ){
504
505 InitializeFromFile* fileInit;
506 #ifdef IS_MPI // is_mpi
507 if( worldRank == 0 ){
508 #endif //is_mpi
509 fileInit = new InitializeFromFile( the_globals->getInitialConfig() );
510 #ifdef IS_MPI
511 }else fileInit = new InitializeFromFile( NULL );
512 #endif
513 fileInit->read_xyz( simnfo ); // default velocities on
514
515 delete fileInit;
516 }
517 else{
518
519 #ifdef IS_MPI
520
521 // no init from bass
522
523 sprintf( painCave.errMsg,
524 "Cannot intialize a parallel simulation without an initial configuration file.\n" );
525 painCave.isFatal;
526 simError();
527
528 #else
529
530 initFromBass();
531
532
533 #endif
534 }
535
536 #ifdef IS_MPI
537 strcpy( checkPointMsg, "Successfully read in the initial configuration" );
538 MPIcheckPoint();
539 #endif // is_mpi
540
541
542
543
544
545
546
547 #ifdef IS_MPI
548 if( worldRank == 0 ){
549 #endif // is_mpi
550
551 if( the_globals->haveFinalConfig() ){
552 strcpy( simnfo->finalName, the_globals->getFinalConfig() );
553 }
554 else{
555 strcpy( simnfo->finalName, inFileName );
556 char* endTest;
557 int nameLength = strlen( simnfo->finalName );
558 endTest = &(simnfo->finalName[nameLength - 5]);
559 if( !strcmp( endTest, ".bass" ) ){
560 strcpy( endTest, ".eor" );
561 }
562 else if( !strcmp( endTest, ".BASS" ) ){
563 strcpy( endTest, ".eor" );
564 }
565 else{
566 endTest = &(simnfo->finalName[nameLength - 4]);
567 if( !strcmp( endTest, ".bss" ) ){
568 strcpy( endTest, ".eor" );
569 }
570 else if( !strcmp( endTest, ".mdl" ) ){
571 strcpy( endTest, ".eor" );
572 }
573 else{
574 strcat( simnfo->finalName, ".eor" );
575 }
576 }
577 }
578
579 // make the sample and status out names
580
581 strcpy( simnfo->sampleName, inFileName );
582 char* endTest;
583 int nameLength = strlen( simnfo->sampleName );
584 endTest = &(simnfo->sampleName[nameLength - 5]);
585 if( !strcmp( endTest, ".bass" ) ){
586 strcpy( endTest, ".dump" );
587 }
588 else if( !strcmp( endTest, ".BASS" ) ){
589 strcpy( endTest, ".dump" );
590 }
591 else{
592 endTest = &(simnfo->sampleName[nameLength - 4]);
593 if( !strcmp( endTest, ".bss" ) ){
594 strcpy( endTest, ".dump" );
595 }
596 else if( !strcmp( endTest, ".mdl" ) ){
597 strcpy( endTest, ".dump" );
598 }
599 else{
600 strcat( simnfo->sampleName, ".dump" );
601 }
602 }
603
604 strcpy( simnfo->statusName, inFileName );
605 nameLength = strlen( simnfo->statusName );
606 endTest = &(simnfo->statusName[nameLength - 5]);
607 if( !strcmp( endTest, ".bass" ) ){
608 strcpy( endTest, ".stat" );
609 }
610 else if( !strcmp( endTest, ".BASS" ) ){
611 strcpy( endTest, ".stat" );
612 }
613 else{
614 endTest = &(simnfo->statusName[nameLength - 4]);
615 if( !strcmp( endTest, ".bss" ) ){
616 strcpy( endTest, ".stat" );
617 }
618 else if( !strcmp( endTest, ".mdl" ) ){
619 strcpy( endTest, ".stat" );
620 }
621 else{
622 strcat( simnfo->statusName, ".stat" );
623 }
624 }
625
626 #ifdef IS_MPI
627 }
628 #endif // is_mpi
629
630 // set the status, sample, and themal kick times
631
632 if( the_globals->haveSampleTime() ){
633 simnfo->sampleTime = the_globals->getSampleTime();
634 simnfo->statusTime = simnfo->sampleTime;
635 simnfo->thermalTime = simnfo->sampleTime;
636 }
637 else{
638 simnfo->sampleTime = the_globals->getRunTime();
639 simnfo->statusTime = simnfo->sampleTime;
640 simnfo->thermalTime = simnfo->sampleTime;
641 }
642
643 if( the_globals->haveStatusTime() ){
644 simnfo->statusTime = the_globals->getStatusTime();
645 }
646
647 if( the_globals->haveThermalTime() ){
648 simnfo->thermalTime = the_globals->getThermalTime();
649 }
650
651 // check for the temperature set flag
652
653 if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet();
654
655
656 // // make the longe range forces and the integrator
657
658 // new AllLong( simnfo );
659
660 if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo, the_ff );
661 if( !strcmp( force_field, "LJ" ) ) new Verlet( *simnfo, the_ff );
662
663
664
665 // initialize the Fortran
666
667 simnfo->refreshSim();
668
669 if( !strcmp( simnfo->mixingRule, "standard") ){
670 the_ff->initForceField( LB_MIXING_RULE );
671 }
672 else if( !strcmp( simnfo->mixingRule, "explicit") ){
673 the_ff->initForceField( EXPLICIT_MIXING_RULE );
674 }
675 else{
676 sprintf( painCave.errMsg,
677 "SimSetup Error: unknown mixing rule -> \"%s\"\n",
678 simnfo->mixingRule );
679 painCave.isFatal = 1;
680 simError();
681 }
682
683
684 #ifdef IS_MPI
685 strcpy( checkPointMsg,
686 "Successfully intialized the mixingRule for Fortran." );
687 MPIcheckPoint();
688 #endif // is_mpi
689 }
690
691
692 void SimSetup::makeMolecules( void ){
693
694 int i, j, exI, exJ, tempEx, stampID, atomOffset, excludeOffset;
695 molInit info;
696 DirectionalAtom* dAtom;
697 LinkedAssign* extras;
698 LinkedAssign* current_extra;
699 AtomStamp* currentAtom;
700 BondStamp* currentBond;
701 BendStamp* currentBend;
702 TorsionStamp* currentTorsion;
703
704 bond_pair* theBonds;
705 bend_set* theBends;
706 torsion_set* theTorsions;
707
708
709 //init the forceField paramters
710
711 the_ff->readParams();
712
713
714 // init the atoms
715
716 double ux, uy, uz, u, uSqr;
717
718 atomOffset = 0;
719 excludeOffset = 0;
720 for(i=0; i<simnfo->n_mol; i++){
721
722 stampID = the_molecules[i].getStampID();
723
724 info.nAtoms = comp_stamps[stampID]->getNAtoms();
725 info.nBonds = comp_stamps[stampID]->getNBonds();
726 info.nBends = comp_stamps[stampID]->getNBends();
727 info.nTorsions = comp_stamps[stampID]->getNTorsions();
728 info.nExcludes = info.nBonds + info.nBends + info.nTorsions;
729
730 info.myAtoms = &the_atoms[atomOffset];
731 info.myExcludes = &the_excludes[excludeOffset];
732 info.myBonds = new Bond*[info.nBonds];
733 info.myBends = new Bend*[info.nBends];
734 info.myTorsions = new Torsion*[info.nTorsions];
735
736 theBonds = new bond_pair[info.nBonds];
737 theBends = new bend_set[info.nBends];
738 theTorsions = new torsion_set[info.nTorsions];
739
740 // make the Atoms
741
742 for(j=0; j<info.nAtoms; j++){
743
744 currentAtom = comp_stamps[stampID]->getAtom( j );
745 if( currentAtom->haveOrientation() ){
746
747 dAtom = new DirectionalAtom(j + atomOffset);
748 simnfo->n_oriented++;
749 info.myAtoms[j] = dAtom;
750
751 ux = currentAtom->getOrntX();
752 uy = currentAtom->getOrntY();
753 uz = currentAtom->getOrntZ();
754
755 uSqr = (ux * ux) + (uy * uy) + (uz * uz);
756
757 u = sqrt( uSqr );
758 ux = ux / u;
759 uy = uy / u;
760 uz = uz / u;
761
762 dAtom->setSUx( ux );
763 dAtom->setSUy( uy );
764 dAtom->setSUz( uz );
765 }
766 else{
767 info.myAtoms[j] = new GeneralAtom(j + atomOffset);
768 }
769 info.myAtoms[j]->setType( currentAtom->getType() );
770
771 #ifdef IS_MPI
772
773 info.myAtoms[j]->setGlobalIndex( globalIndex[j+atomOffset] );
774
775 #endif // is_mpi
776 }
777
778 // make the bonds
779 for(j=0; j<info.nBonds; j++){
780
781 currentBond = comp_stamps[stampID]->getBond( j );
782 theBonds[j].a = currentBond->getA() + atomOffset;
783 theBonds[j].b = currentBond->getB() + atomOffset;
784
785 exI = theBonds[i].a;
786 exJ = theBonds[i].b;
787
788 // exclude_I must always be the smaller of the pair
789 if( exI > exJ ){
790 tempEx = exI;
791 exI = exJ;
792 exJ = tempEx;
793 }
794 #ifdef IS_MPI
795 tempEx = exI;
796 exI = the_atoms[tempEx]->getGlobalIndex() + 1;
797 tempEx = exJ;
798 exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
799
800 the_excludes[j+excludeOffset]->setPair( exI, exJ );
801 #else // isn't MPI
802 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
803 #endif //is_mpi
804 }
805 excludeOffset += info.nBonds;
806
807 //make the bends
808 for(j=0; j<info.nBends; j++){
809
810 currentBend = comp_stamps[stampID]->getBend( j );
811 theBends[j].a = currentBend->getA() + atomOffset;
812 theBends[j].b = currentBend->getB() + atomOffset;
813 theBends[j].c = currentBend->getC() + atomOffset;
814
815 if( currentBend->haveExtras() ){
816
817 extras = currentBend->getExtras();
818 current_extra = extras;
819
820 while( current_extra != NULL ){
821 if( !strcmp( current_extra->getlhs(), "ghostVectorSource" )){
822
823 switch( current_extra->getType() ){
824
825 case 0:
826 theBends[j].ghost =
827 current_extra->getInt() + atomOffset;
828 theBends[j].isGhost = 1;
829 break;
830
831 case 1:
832 theBends[j].ghost =
833 (int)current_extra->getDouble() + atomOffset;
834 theBends[j].isGhost = 1;
835 break;
836
837 default:
838 sprintf( painCave.errMsg,
839 "SimSetup Error: ghostVectorSource was neiter a "
840 "double nor an int.\n"
841 "-->Bend[%d] in %s\n",
842 j, comp_stamps[stampID]->getID() );
843 painCave.isFatal = 1;
844 simError();
845 }
846 }
847
848 else{
849
850 sprintf( painCave.errMsg,
851 "SimSetup Error: unhandled bend assignment:\n"
852 " -->%s in Bend[%d] in %s\n",
853 current_extra->getlhs(),
854 j, comp_stamps[stampID]->getID() );
855 painCave.isFatal = 1;
856 simError();
857 }
858
859 current_extra = current_extra->getNext();
860 }
861 }
862
863 if( !theBends[j].isGhost ){
864
865 exI = theBends[j].a;
866 exJ = theBends[j].c;
867 }
868 else{
869
870 exI = theBends[j].a;
871 exJ = theBends[j].b;
872 }
873
874 // exclude_I must always be the smaller of the pair
875 if( exI > exJ ){
876 tempEx = exI;
877 exI = exJ;
878 exJ = tempEx;
879 }
880 #ifdef IS_MPI
881 tempEx = exI;
882 exI = the_atoms[tempEx]->getGlobalIndex() + 1;
883 tempEx = exJ;
884 exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
885
886 the_excludes[j+excludeOffset]->setPair( exI, exJ );
887 #else // isn't MPI
888 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
889 #endif //is_mpi
890 }
891 excludeOffset += info.nBends;
892
893 for(j=0; j<info.nTorsions; j++){
894
895 currentTorsion = comp_stamps[stampID]->getTorsion( j );
896 theTorsions[j].a = currentTorsion->getA() + atomOffset;
897 theTorsions[j].b = currentTorsion->getB() + atomOffset;
898 theTorsions[j].c = currentTorsion->getC() + atomOffset;
899 theTorsions[j].d = currentTorsion->getD() + atomOffset;
900
901 exI = theTorsions[j].a;
902 exJ = theTorsions[j].d;
903
904 // exclude_I must always be the smaller of the pair
905 if( exI > exJ ){
906 tempEx = exI;
907 exI = exJ;
908 exJ = tempEx;
909 }
910 #ifdef IS_MPI
911 tempEx = exI;
912 exI = the_atoms[tempEx]->getGlobalIndex() + 1;
913 tempEx = exJ;
914 exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
915
916 the_excludes[j+excludeOffset]->setPair( exI, exJ );
917 #else // isn't MPI
918 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
919 #endif //is_mpi
920 }
921 excludeOffset += info.nTorsions;
922
923
924 // send the arrays off to the forceField for init.
925
926 the_ff->initializeAtoms( info.nAtoms, info.myAtoms );
927 the_ff->initializeBonds( info.nBonds, info.myBonds, theBonds );
928 the_ff->initializeBends( info.nBends, info.myBends, theBends );
929 the_ff->initializeTorsions( info.nTorsions, info.myTorsions, theTorsions );
930
931
932 the_molecules[i].initialize( info );
933 atomOffset += info.nAtoms;
934 delete[] theBonds;
935 delete[] theBends;
936 delete[] theTorsions;
937 }
938
939 // clean up the forcefield
940 the_ff->calcRcut();
941 the_ff->cleanMe();
942 }
943
944 void SimSetup::initFromBass( void ){
945
946 int i, j, k;
947 int n_cells;
948 double cellx, celly, cellz;
949 double temp1, temp2, temp3;
950 int n_per_extra;
951 int n_extra;
952 int have_extra, done;
953
954 temp1 = (double)tot_nmol / 4.0;
955 temp2 = pow( temp1, ( 1.0 / 3.0 ) );
956 temp3 = ceil( temp2 );
957
958 have_extra =0;
959 if( temp2 < temp3 ){ // we have a non-complete lattice
960 have_extra =1;
961
962 n_cells = (int)temp3 - 1;
963 cellx = simnfo->box_x / temp3;
964 celly = simnfo->box_y / temp3;
965 cellz = simnfo->box_z / temp3;
966 n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells );
967 temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) );
968 n_per_extra = (int)ceil( temp1 );
969
970 if( n_per_extra > 4){
971 sprintf( painCave.errMsg,
972 "SimSetup error. There has been an error in constructing"
973 " the non-complete lattice.\n" );
974 painCave.isFatal = 1;
975 simError();
976 }
977 }
978 else{
979 n_cells = (int)temp3;
980 cellx = simnfo->box_x / temp3;
981 celly = simnfo->box_y / temp3;
982 cellz = simnfo->box_z / temp3;
983 }
984
985 current_mol = 0;
986 current_comp_mol = 0;
987 current_comp = 0;
988 current_atom_ndx = 0;
989
990 for( i=0; i < n_cells ; i++ ){
991 for( j=0; j < n_cells; j++ ){
992 for( k=0; k < n_cells; k++ ){
993
994 makeElement( i * cellx,
995 j * celly,
996 k * cellz );
997
998 makeElement( i * cellx + 0.5 * cellx,
999 j * celly + 0.5 * celly,
1000 k * cellz );
1001
1002 makeElement( i * cellx,
1003 j * celly + 0.5 * celly,
1004 k * cellz + 0.5 * cellz );
1005
1006 makeElement( i * cellx + 0.5 * cellx,
1007 j * celly,
1008 k * cellz + 0.5 * cellz );
1009 }
1010 }
1011 }
1012
1013 if( have_extra ){
1014 done = 0;
1015
1016 int start_ndx;
1017 for( i=0; i < (n_cells+1) && !done; i++ ){
1018 for( j=0; j < (n_cells+1) && !done; j++ ){
1019
1020 if( i < n_cells ){
1021
1022 if( j < n_cells ){
1023 start_ndx = n_cells;
1024 }
1025 else start_ndx = 0;
1026 }
1027 else start_ndx = 0;
1028
1029 for( k=start_ndx; k < (n_cells+1) && !done; k++ ){
1030
1031 makeElement( i * cellx,
1032 j * celly,
1033 k * cellz );
1034 done = ( current_mol >= tot_nmol );
1035
1036 if( !done && n_per_extra > 1 ){
1037 makeElement( i * cellx + 0.5 * cellx,
1038 j * celly + 0.5 * celly,
1039 k * cellz );
1040 done = ( current_mol >= tot_nmol );
1041 }
1042
1043 if( !done && n_per_extra > 2){
1044 makeElement( i * cellx,
1045 j * celly + 0.5 * celly,
1046 k * cellz + 0.5 * cellz );
1047 done = ( current_mol >= tot_nmol );
1048 }
1049
1050 if( !done && n_per_extra > 3){
1051 makeElement( i * cellx + 0.5 * cellx,
1052 j * celly,
1053 k * cellz + 0.5 * cellz );
1054 done = ( current_mol >= tot_nmol );
1055 }
1056 }
1057 }
1058 }
1059 }
1060
1061
1062 for( i=0; i<simnfo->n_atoms; i++ ){
1063 simnfo->atoms[i]->set_vx( 0.0 );
1064 simnfo->atoms[i]->set_vy( 0.0 );
1065 simnfo->atoms[i]->set_vz( 0.0 );
1066 }
1067 }
1068
1069 void SimSetup::makeElement( double x, double y, double z ){
1070
1071 int k;
1072 AtomStamp* current_atom;
1073 DirectionalAtom* dAtom;
1074 double rotMat[3][3];
1075
1076 for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){
1077
1078 current_atom = comp_stamps[current_comp]->getAtom( k );
1079 if( !current_atom->havePosition() ){
1080 sprintf( painCave.errMsg,
1081 "SimSetup:initFromBass error.\n"
1082 "\tComponent %s, atom %s does not have a position specified.\n"
1083 "\tThe initialization routine is unable to give a start"
1084 " position.\n",
1085 comp_stamps[current_comp]->getID(),
1086 current_atom->getType() );
1087 painCave.isFatal = 1;
1088 simError();
1089 }
1090
1091 the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() );
1092 the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() );
1093 the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() );
1094
1095 if( the_atoms[current_atom_ndx]->isDirectional() ){
1096
1097 dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx];
1098
1099 rotMat[0][0] = 1.0;
1100 rotMat[0][1] = 0.0;
1101 rotMat[0][2] = 0.0;
1102
1103 rotMat[1][0] = 0.0;
1104 rotMat[1][1] = 1.0;
1105 rotMat[1][2] = 0.0;
1106
1107 rotMat[2][0] = 0.0;
1108 rotMat[2][1] = 0.0;
1109 rotMat[2][2] = 1.0;
1110
1111 dAtom->setA( rotMat );
1112 }
1113
1114 current_atom_ndx++;
1115 }
1116
1117 current_mol++;
1118 current_comp_mol++;
1119
1120 if( current_comp_mol >= components_nmol[current_comp] ){
1121
1122 current_comp_mol = 0;
1123 current_comp++;
1124 }
1125 }