ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimSetup.cpp
Revision: 412
Committed: Wed Mar 26 21:50:33 2003 UTC (21 years, 3 months ago) by mmeineke
File size: 34732 byte(s)
Log Message:
still working on the SimSetup routine. also fixed some things in Exclude.hpp

File Contents

# User Rev Content
1 mmeineke 377 #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" ) ) the_ff = new TraPPEFF();
92     else if( !strcmp( force_field, "DipoleTest" ) ) the_ff = new DipoleTestFF();
93     else if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF();
94     else if( !strcmp( force_field, "LJ" ) ) the_ff = new LJ_FF();
95     else{
96     sprintf( painCave.errMsg,
97     "SimSetup Error. Unrecognized force field -> %s\n",
98     force_field );
99     painCave.isFatal = 1;
100     simError();
101     }
102    
103     #ifdef IS_MPI
104     strcpy( checkPointMsg, "ForceField creation successful" );
105     MPIcheckPoint();
106     #endif // is_mpi
107    
108    
109    
110     // get the components and calculate the tot_nMol and indvidual n_mol
111     the_components = the_globals->getComponents();
112     components_nmol = new int[n_components];
113     comp_stamps = new MoleculeStamp*[n_components];
114    
115     if( !the_globals->haveNMol() ){
116     // we don't have the total number of molecules, so we assume it is
117     // given in each component
118    
119     tot_nmol = 0;
120     for( i=0; i<n_components; i++ ){
121    
122     if( !the_components[i]->haveNMol() ){
123     // we have a problem
124     sprintf( painCave.errMsg,
125     "SimSetup Error. No global NMol or component NMol"
126     " given. Cannot calculate the number of atoms.\n" );
127     painCave.isFatal = 1;
128     simError();
129     }
130    
131     tot_nmol += the_components[i]->getNMol();
132     components_nmol[i] = the_components[i]->getNMol();
133     }
134     }
135     else{
136     sprintf( painCave.errMsg,
137     "SimSetup error.\n"
138     "\tSorry, the ability to specify total"
139     " nMols and then give molfractions in the components\n"
140     "\tis not currently supported."
141     " Please give nMol in the components.\n" );
142     painCave.isFatal = 1;
143     simError();
144    
145    
146     // tot_nmol = the_globals->getNMol();
147    
148     // //we have the total number of molecules, now we check for molfractions
149     // for( i=0; i<n_components; i++ ){
150    
151     // if( !the_components[i]->haveMolFraction() ){
152    
153     // if( !the_components[i]->haveNMol() ){
154     // //we have a problem
155     // std::cerr << "SimSetup error. Neither molFraction nor "
156     // << " nMol was given in component
157    
158     }
159    
160     #ifdef IS_MPI
161     strcpy( checkPointMsg, "Have the number of components" );
162     MPIcheckPoint();
163     #endif // is_mpi
164    
165     // make an array of molecule stamps that match the components used.
166     // also extract the used stamps out into a separate linked list
167    
168     simnfo->nComponents = n_components;
169     simnfo->componentsNmol = components_nmol;
170     simnfo->compStamps = comp_stamps;
171     simnfo->headStamp = new LinkedMolStamp();
172    
173     char* id;
174     LinkedMolStamp* headStamp = simnfo->headStamp;
175     LinkedMolStamp* currentStamp = NULL;
176     for( i=0; i<n_components; i++ ){
177    
178     id = the_components[i]->getType();
179     comp_stamps[i] = NULL;
180    
181     // check to make sure the component isn't already in the list
182    
183     comp_stamps[i] = headStamp->match( id );
184     if( comp_stamps[i] == NULL ){
185    
186     // extract the component from the list;
187    
188     currentStamp = the_stamps->extractMolStamp( id );
189     if( currentStamp == NULL ){
190     sprintf( painCave.errMsg,
191     "SimSetup error: Component \"%s\" was not found in the "
192     "list of declared molecules\n",
193     id );
194     painCave.isFatal = 1;
195     simError();
196     }
197    
198     headStamp->add( currentStamp );
199     comp_stamps[i] = headStamp->match( id );
200     }
201     }
202    
203     #ifdef IS_MPI
204     strcpy( checkPointMsg, "Component stamps successfully extracted\n" );
205     MPIcheckPoint();
206     #endif // is_mpi
207    
208    
209    
210    
211     // caclulate the number of atoms, bonds, bends and torsions
212    
213     tot_atoms = 0;
214     tot_bonds = 0;
215     tot_bends = 0;
216     tot_torsions = 0;
217     for( i=0; i<n_components; i++ ){
218    
219     tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms();
220     tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds();
221     tot_bends += components_nmol[i] * comp_stamps[i]->getNBends();
222     tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions();
223     }
224    
225     tot_SRI = tot_bonds + tot_bends + tot_torsions;
226    
227     simnfo->n_atoms = tot_atoms;
228     simnfo->n_bonds = tot_bonds;
229     simnfo->n_bends = tot_bends;
230     simnfo->n_torsions = tot_torsions;
231     simnfo->n_SRI = tot_SRI;
232     simnfo->n_mol = tot_nmol;
233    
234    
235     #ifdef IS_MPI
236    
237     // divide the molecules among processors here.
238    
239     mpiSim = new mpiSimulation( simnfo );
240    
241    
242    
243     globalIndex = mpiSim->divideLabor();
244    
245    
246    
247     // set up the local variables
248    
249     int localMol, allMol;
250     int local_atoms, local_bonds, local_bends, local_torsions, local_SRI;
251    
252     allMol = 0;
253     localMol = 0;
254     local_atoms = 0;
255     local_bonds = 0;
256     local_bends = 0;
257     local_torsions = 0;
258     for( i=0; i<n_components; i++ ){
259    
260     for( j=0; j<components_nmol[i]; j++ ){
261    
262     if( mpiSim->getMyMolStart() <= allMol &&
263     allMol <= mpiSim->getMyMolEnd() ){
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 note 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    
308    
309     if( simnfo->n_SRI ){
310 mmeineke 412 Exclude::createArray(simnfo->n_SRI);
311     the_excludes = new Exclude*[simnfo->n_SRI];
312 mmeineke 377 simnfo->globalExcludes = new int;
313     simnfo->n_exclude = tot_SRI;
314     }
315     else{
316    
317 mmeineke 412 Exclude::createArray( 1 );
318     the_excludes = new Exclude*;
319     the_excludes[0] = new Exclude(0);
320     the_excludes[0]->setPair( 0,0 );
321 mmeineke 377 simnfo->globalExcludes = new int;
322     simnfo->globalExcludes[0] = 0;
323 mmeineke 412 simnfo->n_exclude = 0;
324 mmeineke 377 }
325    
326     // set the arrays into the SimInfo object
327    
328     simnfo->atoms = the_atoms;
329     simnfo->sr_interactions = the_sris;
330     simnfo->nGlobalExcludes = 0;
331     simnfo->excludes = the_excludes;
332    
333    
334     // get some of the tricky things that may still be in the globals
335    
336    
337     if( the_globals->haveBox() ){
338     simnfo->box_x = the_globals->getBox();
339     simnfo->box_y = the_globals->getBox();
340     simnfo->box_z = the_globals->getBox();
341     }
342     else if( the_globals->haveDensity() ){
343    
344     double vol;
345     vol = (double)tot_nmol / the_globals->getDensity();
346     simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) );
347     simnfo->box_y = simnfo->box_x;
348     simnfo->box_z = simnfo->box_x;
349     }
350     else{
351     if( !the_globals->haveBoxX() ){
352     sprintf( painCave.errMsg,
353     "SimSetup error, no periodic BoxX size given.\n" );
354     painCave.isFatal = 1;
355     simError();
356     }
357     simnfo->box_x = the_globals->getBoxX();
358    
359     if( !the_globals->haveBoxY() ){
360     sprintf( painCave.errMsg,
361     "SimSetup error, no periodic BoxY size given.\n" );
362     painCave.isFatal = 1;
363     simError();
364     }
365     simnfo->box_y = the_globals->getBoxY();
366    
367     if( !the_globals->haveBoxZ() ){
368     sprintf( painCave.errMsg,
369     "SimSetup error, no periodic BoxZ size given.\n" );
370     painCave.isFatal = 1;
371     simError();
372     }
373     simnfo->box_z = the_globals->getBoxZ();
374     }
375    
376     #ifdef IS_MPI
377     strcpy( checkPointMsg, "Box size set up" );
378     MPIcheckPoint();
379     #endif // is_mpi
380    
381    
382     // initialize the arrays
383    
384     the_ff->setSimInfo( simnfo );
385    
386     makeAtoms();
387     simnfo->identArray = new int[simnfo->n_atoms];
388     for(i=0; i<simnfo->n_atoms; i++){
389     simnfo->identArray[i] = the_atoms[i]->getIdent();
390     }
391    
392     if( tot_bonds ){
393     makeBonds();
394     }
395    
396     if( tot_bends ){
397     makeBends();
398     }
399    
400     if( tot_torsions ){
401     makeTorsions();
402     }
403    
404    
405 gezelter 394 if (the_globals->getUseRF() ) {
406     simnfo->useReactionField = 1;
407    
408     if( !the_globals->haveECR() ){
409     sprintf( painCave.errMsg,
410     "SimSetup Warning: using default value of 1/2 the smallest "
411     "box length for the electrostaticCutoffRadius.\n"
412     "I hope you have a very fast processor!\n");
413     painCave.isFatal = 0;
414     simError();
415     double smallest;
416     smallest = simnfo->box_x;
417     if (simnfo->box_y <= smallest) smallest = simnfo->box_y;
418     if (simnfo->box_z <= smallest) smallest = simnfo->box_z;
419     simnfo->ecr = 0.5 * smallest;
420     } else {
421     simnfo->ecr = the_globals->getECR();
422     }
423 mmeineke 377
424 gezelter 394 if( !the_globals->haveEST() ){
425     sprintf( painCave.errMsg,
426     "SimSetup Warning: using default value of 0.05 * the "
427     "electrostaticCutoffRadius for the electrostaticSkinThickness\n"
428     );
429     painCave.isFatal = 0;
430     simError();
431     simnfo->est = 0.05 * simnfo->ecr;
432     } else {
433     simnfo->est = the_globals->getEST();
434     }
435    
436     if(!the_globals->haveDielectric() ){
437     sprintf( painCave.errMsg,
438     "SimSetup Error: You are trying to use Reaction Field without"
439     "setting a dielectric constant!\n"
440     );
441     painCave.isFatal = 1;
442     simError();
443     }
444     simnfo->dielectric = the_globals->getDielectric();
445     } else {
446     if (simnfo->n_dipoles) {
447    
448     if( !the_globals->haveECR() ){
449     sprintf( painCave.errMsg,
450     "SimSetup Warning: using default value of 1/2 the smallest"
451     "box length for the electrostaticCutoffRadius.\n"
452     "I hope you have a very fast processor!\n");
453     painCave.isFatal = 0;
454     simError();
455     double smallest;
456     smallest = simnfo->box_x;
457     if (simnfo->box_y <= smallest) smallest = simnfo->box_y;
458     if (simnfo->box_z <= smallest) smallest = simnfo->box_z;
459     simnfo->ecr = 0.5 * smallest;
460     } else {
461     simnfo->ecr = the_globals->getECR();
462     }
463    
464     if( !the_globals->haveEST() ){
465     sprintf( painCave.errMsg,
466     "SimSetup Warning: using default value of 5% of the"
467     "electrostaticCutoffRadius for the "
468     "electrostaticSkinThickness\n"
469     );
470     painCave.isFatal = 0;
471     simError();
472     simnfo->est = 0.05 * simnfo->ecr;
473     } else {
474     simnfo->est = the_globals->getEST();
475     }
476     }
477     }
478 mmeineke 377
479 gezelter 394 #ifdef IS_MPI
480     strcpy( checkPointMsg, "electrostatic parameters check out" );
481     MPIcheckPoint();
482     #endif // is_mpi
483 mmeineke 377
484     if( the_globals->haveInitialConfig() ){
485    
486     InitializeFromFile* fileInit;
487     #ifdef IS_MPI // is_mpi
488     if( worldRank == 0 ){
489     #endif //is_mpi
490     fileInit = new InitializeFromFile( the_globals->getInitialConfig() );
491     #ifdef IS_MPI
492     }else fileInit = new InitializeFromFile( NULL );
493     #endif
494     fileInit->read_xyz( simnfo ); // default velocities on
495    
496     delete fileInit;
497     }
498     else{
499    
500     #ifdef IS_MPI
501    
502     // no init from bass
503    
504     sprintf( painCave.errMsg,
505     "Cannot intialize a parallel simulation without an initial configuration file.\n" );
506     painCave.isFatal;
507     simError();
508    
509     #else
510    
511     initFromBass();
512    
513    
514     #endif
515     }
516    
517     #ifdef IS_MPI
518     strcpy( checkPointMsg, "Successfully read in the initial configuration" );
519     MPIcheckPoint();
520     #endif // is_mpi
521    
522    
523    
524    
525    
526    
527    
528     #ifdef IS_MPI
529     if( worldRank == 0 ){
530     #endif // is_mpi
531    
532     if( the_globals->haveFinalConfig() ){
533     strcpy( simnfo->finalName, the_globals->getFinalConfig() );
534     }
535     else{
536     strcpy( simnfo->finalName, inFileName );
537     char* endTest;
538     int nameLength = strlen( simnfo->finalName );
539     endTest = &(simnfo->finalName[nameLength - 5]);
540     if( !strcmp( endTest, ".bass" ) ){
541     strcpy( endTest, ".eor" );
542     }
543     else if( !strcmp( endTest, ".BASS" ) ){
544     strcpy( endTest, ".eor" );
545     }
546     else{
547     endTest = &(simnfo->finalName[nameLength - 4]);
548     if( !strcmp( endTest, ".bss" ) ){
549     strcpy( endTest, ".eor" );
550     }
551     else if( !strcmp( endTest, ".mdl" ) ){
552     strcpy( endTest, ".eor" );
553     }
554     else{
555     strcat( simnfo->finalName, ".eor" );
556     }
557     }
558     }
559    
560     // make the sample and status out names
561    
562     strcpy( simnfo->sampleName, inFileName );
563     char* endTest;
564     int nameLength = strlen( simnfo->sampleName );
565     endTest = &(simnfo->sampleName[nameLength - 5]);
566     if( !strcmp( endTest, ".bass" ) ){
567     strcpy( endTest, ".dump" );
568     }
569     else if( !strcmp( endTest, ".BASS" ) ){
570     strcpy( endTest, ".dump" );
571     }
572     else{
573     endTest = &(simnfo->sampleName[nameLength - 4]);
574     if( !strcmp( endTest, ".bss" ) ){
575     strcpy( endTest, ".dump" );
576     }
577     else if( !strcmp( endTest, ".mdl" ) ){
578     strcpy( endTest, ".dump" );
579     }
580     else{
581     strcat( simnfo->sampleName, ".dump" );
582     }
583     }
584    
585     strcpy( simnfo->statusName, inFileName );
586     nameLength = strlen( simnfo->statusName );
587     endTest = &(simnfo->statusName[nameLength - 5]);
588     if( !strcmp( endTest, ".bass" ) ){
589     strcpy( endTest, ".stat" );
590     }
591     else if( !strcmp( endTest, ".BASS" ) ){
592     strcpy( endTest, ".stat" );
593     }
594     else{
595     endTest = &(simnfo->statusName[nameLength - 4]);
596     if( !strcmp( endTest, ".bss" ) ){
597     strcpy( endTest, ".stat" );
598     }
599     else if( !strcmp( endTest, ".mdl" ) ){
600     strcpy( endTest, ".stat" );
601     }
602     else{
603     strcat( simnfo->statusName, ".stat" );
604     }
605     }
606    
607     #ifdef IS_MPI
608     }
609     #endif // is_mpi
610    
611     // set the status, sample, and themal kick times
612    
613     if( the_globals->haveSampleTime() ){
614     simnfo->sampleTime = the_globals->getSampleTime();
615     simnfo->statusTime = simnfo->sampleTime;
616     simnfo->thermalTime = simnfo->sampleTime;
617     }
618     else{
619     simnfo->sampleTime = the_globals->getRunTime();
620     simnfo->statusTime = simnfo->sampleTime;
621     simnfo->thermalTime = simnfo->sampleTime;
622     }
623    
624     if( the_globals->haveStatusTime() ){
625     simnfo->statusTime = the_globals->getStatusTime();
626     }
627    
628     if( the_globals->haveThermalTime() ){
629     simnfo->thermalTime = the_globals->getThermalTime();
630     }
631    
632     // check for the temperature set flag
633    
634     if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet();
635    
636    
637     // // make the longe range forces and the integrator
638    
639     // new AllLong( simnfo );
640    
641     if( !strcmp( force_field, "TraPPE" ) ) new Verlet( *simnfo, the_ff );
642     if( !strcmp( force_field, "DipoleTest" ) ) new Symplectic( simnfo, the_ff );
643     if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo, the_ff );
644     if( !strcmp( force_field, "LJ" ) ) new Verlet( *simnfo, the_ff );
645    
646    
647    
648     // initialize the Fortran
649    
650     simnfo->refreshSim();
651    
652     if( !strcmp( simnfo->mixingRule, "standard") ){
653     the_ff->initForceField( LB_MIXING_RULE );
654     }
655     else if( !strcmp( simnfo->mixingRule, "explicit") ){
656     the_ff->initForceField( EXPLICIT_MIXING_RULE );
657     }
658     else{
659     sprintf( painCave.errMsg,
660     "SimSetup Error: unknown mixing rule -> \"%s\"\n",
661     simnfo->mixingRule );
662     painCave.isFatal = 1;
663     simError();
664     }
665    
666    
667     #ifdef IS_MPI
668     strcpy( checkPointMsg,
669     "Successfully intialized the mixingRule for Fortran." );
670     MPIcheckPoint();
671     #endif // is_mpi
672     }
673    
674 mmeineke 407
675     void SimSetup::makeMolecules( void ){
676    
677 mmeineke 412 int i, j, exI, exJ, tempEx, stampID, atomOffset, excludeOffset;
678 mmeineke 407 molInit info;
679     DirectionalAtom* dAtom;
680 mmeineke 412 LinkedAssign* extras;
681     LinkedAssign* current_extra;
682 mmeineke 407 AtomStamp* currentAtom;
683     BondStamp* currentBond;
684     BendStamp* currentBend;
685     TorsionStamp* currentTorsion;
686    
687     //init the forceField paramters
688    
689     the_ff->readParams();
690    
691    
692     // init the molecules
693    
694     atomOffset = 0;
695 mmeineke 412 excludeOffset = 0;
696 mmeineke 407 for(i=0; i<simnfo->n_mol; i++){
697    
698     stampID = the_molecules[i].getStampID();
699    
700     info.nAtoms = comp_stamps[stampID]->getNAtoms();
701     info.nBonds = comp_stamps[stampID]->getNBonds();
702     info.nBends = comp_stamps[stampID]->getNBends();
703     info.nTorsions = comp_stamps[stampID]->getNTorsions();
704 mmeineke 412 info.nExcludes = info.nBonds + info.nBends + info.nTorsions;
705    
706 mmeineke 407 info.myAtoms = &the_atoms[atomOffset];
707 mmeineke 412 info.myExcludes = &the_excludes[excludeOffset];
708 mmeineke 407 info.myBonds = new Bond*[info.nBonds];
709     info.myBends = new Bend*[info.nBends];
710     info.myTorsions = new Torsions*[info.nTorsions];
711    
712     theBonds = new bond_pair[info.nBonds];
713     theBends = new bend_set[info.nBends];
714     theTorsions = new torsion_set[info.nTorsions];
715    
716     // make the Atoms
717    
718     for(j=0; j<info.nAtoms; j++){
719    
720     currentAtom = theComponents[stampID]->getAtom( j );
721     if( currentAtom->haveOrientation() ){
722    
723     dAtom = new DirectionalAtom(j + atomOffset);
724     simnfo->n_oriented++;
725     info.myAtoms[j] = dAtom;
726    
727     ux = currentAtom->getOrntX();
728     uy = currentAtom->getOrntY();
729     uz = currentAtom->getOrntZ();
730    
731     uSqr = (ux * ux) + (uy * uy) + (uz * uz);
732    
733     u = sqrt( uSqr );
734     ux = ux / u;
735     uy = uy / u;
736     uz = uz / u;
737    
738     dAtom->setSUx( ux );
739     dAtom->setSUy( uy );
740     dAtom->setSUz( uz );
741     }
742     else{
743     info.myAtoms[j] = new GeneralAtom(j + atomOffset);
744     }
745     info.myAtoms[j]->setType( currentAtom->getType() );
746    
747     #ifdef IS_MPI
748    
749     info.myAtoms[j]->setGlobalIndex( globalIndex[j+atomOffset] );
750    
751     #endif // is_mpi
752     }
753    
754     // make the bonds
755 mmeineke 412 for(j=0; j<info.nBonds; j++){
756 mmeineke 407
757     currentBond = comp_stamps[stampID]->getBond( j );
758     theBonds[j].a = currentBond->getA() + atomOffset;
759     theBonds[j].b = currentBond->getB() + atomOffset;
760    
761     exI = theBonds[i].a;
762     exJ = theBonds[i].b;
763    
764     // exclude_I must always be the smaller of the pair
765     if( exI > exJ ){
766     tempEx = exI;
767     exI = exJ;
768     exJ = tempEx;
769     }
770     #ifdef IS_MPI
771 mmeineke 412 tempEx = exI;
772     exI = the_atoms[tempEx]->getGlobalIndex() + 1;
773     tempEx = exJ;
774     exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
775 mmeineke 407
776 mmeineke 412 the_excludes[j+excludeOffset]->setPair( exI, exJ );
777     #else // isn't MPI
778     the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
779     #endif //is_mpi
780     }
781     excludeOffset += info.nBonds;
782    
783     //make the bends
784     for(j=0; j<info.nBends; j++){
785 mmeineke 407
786 mmeineke 412 currentBend = comp_stamps[stampID]->getBend( j );
787     theBends[j].a = currentBend->getA() + atomOffset;
788     theBends[j].b = currentBend->getB() + atomOffset;
789     theBends[j].c = currentBend->getC() + atomOffset;
790    
791     if( currentBend->haveExtras() ){
792    
793     extras = current_bend->getExtras();
794     current_extra = extras;
795    
796     while( current_extra != NULL ){
797     if( !strcmp( current_extra->getlhs(), "ghostVectorSource" )){
798    
799     switch( current_extra->getType() ){
800    
801     case 0:
802     theBends[j].ghost =
803     current_extra->getInt() + atomOffset;
804     theBends[j].isGhost = 1;
805     break;
806    
807     case 1:
808     theBends[j].ghost =
809     (int)current_extra->getDouble() + atomOffset;
810     theBends[j].isGhost = 1;
811     break;
812    
813     default:
814     sprintf( painCave.errMsg,
815     "SimSetup Error: ghostVectorSource was neiter a "
816     "double nor an int.\n"
817     "-->Bend[%d] in %s\n",
818     j, comp_stamps[stampID]->getID() );
819     painCave.isFatal = 1;
820     simError();
821     }
822     }
823    
824     else{
825    
826     sprintf( painCave.errMsg,
827     "SimSetup Error: unhandled bend assignment:\n"
828     " -->%s in Bend[%d] in %s\n",
829     current_extra->getlhs(),
830     j, comp_stamps[stampID]->getID() );
831     painCave.isFatal = 1;
832     simError();
833     }
834    
835     current_extra = current_extra->getNext();
836     }
837     }
838    
839     if( !theBends[j].isGhost ){
840    
841     exI = theBends[j].a;
842     exJ = theBends[j].c;
843     }
844     else{
845    
846     exI = theBends[j].a;
847     exJ = theBends[j].b;
848     }
849    
850     // exclude_I must always be the smaller of the pair
851     if( exI > exJ ){
852     tempEx = exI;
853     exI = exJ;
854     exJ = tempEx;
855     }
856     #ifdef IS_MPI
857     tempEx = exI;
858     exI = the_atoms[tempEx]->getGlobalIndex() + 1;
859     tempEx = exJ;
860     exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
861    
862     the_excludes[j+excludeOffset]->setPair( exI, exJ );
863 mmeineke 407 #else // isn't MPI
864 mmeineke 412 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
865     #endif //is_mpi
866     }
867     excludeOffset += info.nBends;
868    
869     for(j=0; j<info.nTorsions; j++){
870 mmeineke 407
871 mmeineke 412 currentTorsion = comp_stamps[stampID]->getTorsion( j );
872     theTorsions[j].a = currentTorsion->getA() + atomOffset;
873     theTorsions[j].b = currentTorsion->getB() + atomOffset;
874     theTorsions[j].c = currentTorsion->getC() + atomOffset;
875     theTorsions[j].d = currentTorsion->getD() + atomOffset;
876    
877     exI = theTorsions[j].a;
878     exJ = theTorsions[j].d;
879 mmeineke 407
880 mmeineke 412 // exclude_I must always be the smaller of the pair
881     if( exI > exJ ){
882     tempEx = exI;
883     exI = exJ;
884     exJ = tempEx;
885     }
886     #ifdef IS_MPI
887     tempEx = exI;
888     exI = the_atoms[tempEx]->getGlobalIndex() + 1;
889     tempEx = exJ;
890     exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
891    
892     the_excludes[j+excludeOffset]->setPair( exI, exJ );
893     #else // isn't MPI
894     the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
895 mmeineke 407 #endif //is_mpi
896 mmeineke 412 }
897     excludeOffset += info.nTorsions;
898    
899 mmeineke 407
900    
901    
902    
903    
904    
905    
906 mmeineke 377 void SimSetup::makeAtoms( void ){
907    
908     int i, j, k, index;
909     double ux, uy, uz, uSqr, u;
910     AtomStamp* current_atom;
911    
912     DirectionalAtom* dAtom;
913     int molIndex, molStart, molEnd, nMemb, lMolIndex;
914    
915     lMolIndex = 0;
916     molIndex = 0;
917     index = 0;
918     for( i=0; i<n_components; i++ ){
919    
920     for( j=0; j<components_nmol[i]; j++ ){
921    
922     #ifdef IS_MPI
923     if( mpiSim->getMyMolStart() <= molIndex &&
924     molIndex <= mpiSim->getMyMolEnd() ){
925     #endif // is_mpi
926    
927     molStart = index;
928     nMemb = comp_stamps[i]->getNAtoms();
929     for( k=0; k<comp_stamps[i]->getNAtoms(); k++ ){
930    
931     current_atom = comp_stamps[i]->getAtom( k );
932     if( current_atom->haveOrientation() ){
933    
934     dAtom = new DirectionalAtom(index);
935     simnfo->n_oriented++;
936     the_atoms[index] = dAtom;
937    
938     ux = current_atom->getOrntX();
939     uy = current_atom->getOrntY();
940     uz = current_atom->getOrntZ();
941    
942     uSqr = (ux * ux) + (uy * uy) + (uz * uz);
943    
944     u = sqrt( uSqr );
945     ux = ux / u;
946     uy = uy / u;
947     uz = uz / u;
948    
949     dAtom->setSUx( ux );
950     dAtom->setSUy( uy );
951     dAtom->setSUz( uz );
952     }
953     else{
954     the_atoms[index] = new GeneralAtom(index);
955     }
956     the_atoms[index]->setType( current_atom->getType() );
957     the_atoms[index]->setIndex( index );
958    
959     // increment the index and repeat;
960     index++;
961     }
962    
963     molEnd = index -1;
964     the_molecules[lMolIndex].setNMembers( nMemb );
965     the_molecules[lMolIndex].setStartAtom( molStart );
966     the_molecules[lMolIndex].setEndAtom( molEnd );
967     the_molecules[lMolIndex].setStampID( i );
968     lMolIndex++;
969    
970     #ifdef IS_MPI
971     }
972     #endif //is_mpi
973    
974     molIndex++;
975     }
976     }
977    
978     #ifdef IS_MPI
979     for( i=0; i<mpiSim->getMyNlocal(); i++ ) the_atoms[i]->setGlobalIndex( globalIndex[i] );
980    
981     delete[] globalIndex;
982    
983     mpiSim->mpiRefresh();
984     #endif //IS_MPI
985    
986     the_ff->initializeAtoms();
987     }
988    
989     void SimSetup::makeBonds( void ){
990    
991     int i, j, k, index, offset, molIndex, exI, exJ, tempEx;
992     bond_pair* the_bonds;
993     BondStamp* current_bond;
994    
995     the_bonds = new bond_pair[tot_bonds];
996     index = 0;
997     offset = 0;
998     molIndex = 0;
999    
1000     for( i=0; i<n_components; i++ ){
1001    
1002     for( j=0; j<components_nmol[i]; j++ ){
1003    
1004     #ifdef IS_MPI
1005     if( mpiSim->getMyMolStart() <= molIndex &&
1006     molIndex <= mpiSim->getMyMolEnd() ){
1007     #endif // is_mpi
1008    
1009     for( k=0; k<comp_stamps[i]->getNBonds(); k++ ){
1010    
1011     current_bond = comp_stamps[i]->getBond( k );
1012     the_bonds[index].a = current_bond->getA() + offset;
1013     the_bonds[index].b = current_bond->getB() + offset;
1014    
1015     exI = the_bonds[index].a;
1016     exJ = the_bonds[index].b;
1017    
1018     // exclude_I must always be the smaller of the pair
1019     if( exI > exJ ){
1020     tempEx = exI;
1021     exI = exJ;
1022     exJ = tempEx;
1023     }
1024    
1025    
1026     #ifdef IS_MPI
1027    
1028     the_excludes[index*2] =
1029     the_atoms[exI]->getGlobalIndex() + 1;
1030     the_excludes[index*2 + 1] =
1031     the_atoms[exJ]->getGlobalIndex() + 1;
1032    
1033     #else // isn't MPI
1034    
1035     the_excludes[index*2] = exI + 1;
1036     the_excludes[index*2 + 1] = exJ + 1;
1037     // fortran index from 1 (hence the +1 in the indexing)
1038     #endif //is_mpi
1039    
1040     // increment the index and repeat;
1041     index++;
1042     }
1043     offset += comp_stamps[i]->getNAtoms();
1044    
1045     #ifdef IS_MPI
1046     }
1047     #endif //is_mpi
1048    
1049     molIndex++;
1050     }
1051     }
1052    
1053     the_ff->initializeBonds( the_bonds );
1054     }
1055    
1056     void SimSetup::makeBends( void ){
1057    
1058     int i, j, k, index, offset, molIndex, exI, exJ, tempEx;
1059     bend_set* the_bends;
1060     BendStamp* current_bend;
1061     LinkedAssign* extras;
1062     LinkedAssign* current_extra;
1063    
1064    
1065     the_bends = new bend_set[tot_bends];
1066     index = 0;
1067     offset = 0;
1068     molIndex = 0;
1069     for( i=0; i<n_components; i++ ){
1070    
1071     for( j=0; j<components_nmol[i]; j++ ){
1072    
1073     #ifdef IS_MPI
1074     if( mpiSim->getMyMolStart() <= molIndex &&
1075     molIndex <= mpiSim->getMyMolEnd() ){
1076     #endif // is_mpi
1077    
1078     for( k=0; k<comp_stamps[i]->getNBends(); k++ ){
1079    
1080     current_bend = comp_stamps[i]->getBend( k );
1081     the_bends[index].a = current_bend->getA() + offset;
1082     the_bends[index].b = current_bend->getB() + offset;
1083     the_bends[index].c = current_bend->getC() + offset;
1084    
1085     if( current_bend->haveExtras() ){
1086    
1087     extras = current_bend->getExtras();
1088     current_extra = extras;
1089    
1090     while( current_extra != NULL ){
1091     if( !strcmp( current_extra->getlhs(), "ghostVectorSource" )){
1092    
1093     switch( current_extra->getType() ){
1094    
1095     case 0:
1096     the_bends[index].ghost =
1097     current_extra->getInt() + offset;
1098     the_bends[index].isGhost = 1;
1099     break;
1100    
1101     case 1:
1102     the_bends[index].ghost =
1103     (int)current_extra->getDouble() + offset;
1104     the_bends[index].isGhost = 1;
1105     break;
1106    
1107     default:
1108     sprintf( painCave.errMsg,
1109     "SimSetup Error: ghostVectorSource was neiter a "
1110     "double nor an int.\n"
1111     "-->Bend[%d] in %s\n",
1112     k, comp_stamps[i]->getID() );
1113     painCave.isFatal = 1;
1114     simError();
1115     }
1116     }
1117    
1118     else{
1119    
1120     sprintf( painCave.errMsg,
1121     "SimSetup Error: unhandled bend assignment:\n"
1122     " -->%s in Bend[%d] in %s\n",
1123     current_extra->getlhs(),
1124     k, comp_stamps[i]->getID() );
1125     painCave.isFatal = 1;
1126     simError();
1127     }
1128    
1129     current_extra = current_extra->getNext();
1130     }
1131     }
1132    
1133     if( !the_bends[index].isGhost ){
1134    
1135     exI = the_bends[index].a;
1136     exJ = the_bends[index].c;
1137     }
1138     else{
1139    
1140     exI = the_bends[index].a;
1141     exJ = the_bends[index].b;
1142     }
1143    
1144     // exclude_I must always be the smaller of the pair
1145     if( exI > exJ ){
1146     tempEx = exI;
1147     exI = exJ;
1148     exJ = tempEx;
1149     }
1150    
1151    
1152     #ifdef IS_MPI
1153    
1154     the_excludes[(index + tot_bonds)*2] =
1155     the_atoms[exI]->getGlobalIndex() + 1;
1156     the_excludes[(index + tot_bonds)*2 + 1] =
1157     the_atoms[exJ]->getGlobalIndex() + 1;
1158    
1159     #else // isn't MPI
1160    
1161     the_excludes[(index + tot_bonds)*2] = exI + 1;
1162     the_excludes[(index + tot_bonds)*2 + 1] = exJ + 1;
1163     // fortran index from 1 (hence the +1 in the indexing)
1164     #endif //is_mpi
1165    
1166    
1167     // increment the index and repeat;
1168     index++;
1169     }
1170     offset += comp_stamps[i]->getNAtoms();
1171    
1172     #ifdef IS_MPI
1173     }
1174     #endif //is_mpi
1175    
1176     molIndex++;
1177     }
1178     }
1179    
1180     #ifdef IS_MPI
1181     sprintf( checkPointMsg,
1182     "Successfully created the bends list.\n" );
1183     MPIcheckPoint();
1184     #endif // is_mpi
1185    
1186    
1187     the_ff->initializeBends( the_bends );
1188     }
1189    
1190     void SimSetup::makeTorsions( void ){
1191    
1192     int i, j, k, index, offset, molIndex, exI, exJ, tempEx;
1193     torsion_set* the_torsions;
1194     TorsionStamp* current_torsion;
1195    
1196     the_torsions = new torsion_set[tot_torsions];
1197     index = 0;
1198     offset = 0;
1199     molIndex = 0;
1200     for( i=0; i<n_components; i++ ){
1201    
1202     for( j=0; j<components_nmol[i]; j++ ){
1203    
1204     #ifdef IS_MPI
1205     if( mpiSim->getMyMolStart() <= molIndex &&
1206     molIndex <= mpiSim->getMyMolEnd() ){
1207     #endif // is_mpi
1208    
1209     for( k=0; k<comp_stamps[i]->getNTorsions(); k++ ){
1210    
1211     current_torsion = comp_stamps[i]->getTorsion( k );
1212     the_torsions[index].a = current_torsion->getA() + offset;
1213     the_torsions[index].b = current_torsion->getB() + offset;
1214     the_torsions[index].c = current_torsion->getC() + offset;
1215     the_torsions[index].d = current_torsion->getD() + offset;
1216    
1217     exI = the_torsions[index].a;
1218     exJ = the_torsions[index].d;
1219    
1220    
1221     // exclude_I must always be the smaller of the pair
1222     if( exI > exJ ){
1223     tempEx = exI;
1224     exI = exJ;
1225     exJ = tempEx;
1226     }
1227    
1228    
1229     #ifdef IS_MPI
1230    
1231     the_excludes[(index + tot_bonds + tot_bends)*2] =
1232     the_atoms[exI]->getGlobalIndex() + 1;
1233     the_excludes[(index + tot_bonds + tot_bends)*2 + 1] =
1234     the_atoms[exJ]->getGlobalIndex() + 1;
1235    
1236     #else // isn't MPI
1237    
1238     the_excludes[(index + tot_bonds + tot_bends)*2] = exI + 1;
1239     the_excludes[(index + tot_bonds + tot_bends)*2 + 1] = exJ + 1;
1240     // fortran indexes from 1 (hence the +1 in the indexing)
1241     #endif //is_mpi
1242    
1243    
1244     // increment the index and repeat;
1245     index++;
1246     }
1247     offset += comp_stamps[i]->getNAtoms();
1248    
1249     #ifdef IS_MPI
1250     }
1251     #endif //is_mpi
1252    
1253     molIndex++;
1254     }
1255     }
1256    
1257     the_ff->initializeTorsions( the_torsions );
1258     }
1259    
1260     void SimSetup::initFromBass( void ){
1261    
1262     int i, j, k;
1263     int n_cells;
1264     double cellx, celly, cellz;
1265     double temp1, temp2, temp3;
1266     int n_per_extra;
1267     int n_extra;
1268     int have_extra, done;
1269    
1270     temp1 = (double)tot_nmol / 4.0;
1271     temp2 = pow( temp1, ( 1.0 / 3.0 ) );
1272     temp3 = ceil( temp2 );
1273    
1274     have_extra =0;
1275     if( temp2 < temp3 ){ // we have a non-complete lattice
1276     have_extra =1;
1277    
1278     n_cells = (int)temp3 - 1;
1279     cellx = simnfo->box_x / temp3;
1280     celly = simnfo->box_y / temp3;
1281     cellz = simnfo->box_z / temp3;
1282     n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells );
1283     temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) );
1284     n_per_extra = (int)ceil( temp1 );
1285    
1286     if( n_per_extra > 4){
1287     sprintf( painCave.errMsg,
1288     "SimSetup error. There has been an error in constructing"
1289     " the non-complete lattice.\n" );
1290     painCave.isFatal = 1;
1291     simError();
1292     }
1293     }
1294     else{
1295     n_cells = (int)temp3;
1296     cellx = simnfo->box_x / temp3;
1297     celly = simnfo->box_y / temp3;
1298     cellz = simnfo->box_z / temp3;
1299     }
1300    
1301     current_mol = 0;
1302     current_comp_mol = 0;
1303     current_comp = 0;
1304     current_atom_ndx = 0;
1305    
1306     for( i=0; i < n_cells ; i++ ){
1307     for( j=0; j < n_cells; j++ ){
1308     for( k=0; k < n_cells; k++ ){
1309    
1310     makeElement( i * cellx,
1311     j * celly,
1312     k * cellz );
1313    
1314     makeElement( i * cellx + 0.5 * cellx,
1315     j * celly + 0.5 * celly,
1316     k * cellz );
1317    
1318     makeElement( i * cellx,
1319     j * celly + 0.5 * celly,
1320     k * cellz + 0.5 * cellz );
1321    
1322     makeElement( i * cellx + 0.5 * cellx,
1323     j * celly,
1324     k * cellz + 0.5 * cellz );
1325     }
1326     }
1327     }
1328    
1329     if( have_extra ){
1330     done = 0;
1331    
1332     int start_ndx;
1333     for( i=0; i < (n_cells+1) && !done; i++ ){
1334     for( j=0; j < (n_cells+1) && !done; j++ ){
1335    
1336     if( i < n_cells ){
1337    
1338     if( j < n_cells ){
1339     start_ndx = n_cells;
1340     }
1341     else start_ndx = 0;
1342     }
1343     else start_ndx = 0;
1344    
1345     for( k=start_ndx; k < (n_cells+1) && !done; k++ ){
1346    
1347     makeElement( i * cellx,
1348     j * celly,
1349     k * cellz );
1350     done = ( current_mol >= tot_nmol );
1351    
1352     if( !done && n_per_extra > 1 ){
1353     makeElement( i * cellx + 0.5 * cellx,
1354     j * celly + 0.5 * celly,
1355     k * cellz );
1356     done = ( current_mol >= tot_nmol );
1357     }
1358    
1359     if( !done && n_per_extra > 2){
1360     makeElement( i * cellx,
1361     j * celly + 0.5 * celly,
1362     k * cellz + 0.5 * cellz );
1363     done = ( current_mol >= tot_nmol );
1364     }
1365    
1366     if( !done && n_per_extra > 3){
1367     makeElement( i * cellx + 0.5 * cellx,
1368     j * celly,
1369     k * cellz + 0.5 * cellz );
1370     done = ( current_mol >= tot_nmol );
1371     }
1372     }
1373     }
1374     }
1375     }
1376    
1377    
1378     for( i=0; i<simnfo->n_atoms; i++ ){
1379     simnfo->atoms[i]->set_vx( 0.0 );
1380     simnfo->atoms[i]->set_vy( 0.0 );
1381     simnfo->atoms[i]->set_vz( 0.0 );
1382     }
1383     }
1384    
1385     void SimSetup::makeElement( double x, double y, double z ){
1386    
1387     int k;
1388     AtomStamp* current_atom;
1389     DirectionalAtom* dAtom;
1390     double rotMat[3][3];
1391    
1392     for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){
1393    
1394     current_atom = comp_stamps[current_comp]->getAtom( k );
1395     if( !current_atom->havePosition() ){
1396     sprintf( painCave.errMsg,
1397     "SimSetup:initFromBass error.\n"
1398     "\tComponent %s, atom %s does not have a position specified.\n"
1399     "\tThe initialization routine is unable to give a start"
1400     " position.\n",
1401     comp_stamps[current_comp]->getID(),
1402     current_atom->getType() );
1403     painCave.isFatal = 1;
1404     simError();
1405     }
1406    
1407     the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() );
1408     the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() );
1409     the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() );
1410    
1411     if( the_atoms[current_atom_ndx]->isDirectional() ){
1412    
1413     dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx];
1414    
1415     rotMat[0][0] = 1.0;
1416     rotMat[0][1] = 0.0;
1417     rotMat[0][2] = 0.0;
1418    
1419     rotMat[1][0] = 0.0;
1420     rotMat[1][1] = 1.0;
1421     rotMat[1][2] = 0.0;
1422    
1423     rotMat[2][0] = 0.0;
1424     rotMat[2][1] = 0.0;
1425     rotMat[2][2] = 1.0;
1426    
1427     dAtom->setA( rotMat );
1428     }
1429    
1430     current_atom_ndx++;
1431     }
1432    
1433     current_mol++;
1434     current_comp_mol++;
1435    
1436     if( current_comp_mol >= components_nmol[current_comp] ){
1437    
1438     current_comp_mol = 0;
1439     current_comp++;
1440     }
1441     }