ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimSetup.cpp
Revision: 427
Committed: Thu Mar 27 20:48:37 2003 UTC (21 years, 3 months ago) by mmeineke
File size: 27616 byte(s)
Log Message:
fixed a few more bugs.

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 mmeineke 424 if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF();
92 mmeineke 377 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 mmeineke 422
250     int* mol2proc = mpiSim->getMolToProcMap();
251     int* molCompType = mpiSim->getMolComponentType();
252 mmeineke 377
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 mmeineke 422 if( mol2proc[j] == worldRank ){
264 mmeineke 377
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 mmeineke 422 " localAtom (%d) are not equal.\n",
283 mmeineke 377 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 mmeineke 422 int molIndex;
308 mmeineke 377
309 mmeineke 422 // initialize the molecule's stampID's
310 mmeineke 377
311 mmeineke 422 #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 mmeineke 377 if( simnfo->n_SRI ){
338 mmeineke 412 Exclude::createArray(simnfo->n_SRI);
339     the_excludes = new Exclude*[simnfo->n_SRI];
340 mmeineke 377 simnfo->globalExcludes = new int;
341     simnfo->n_exclude = tot_SRI;
342     }
343     else{
344    
345 mmeineke 412 Exclude::createArray( 1 );
346     the_excludes = new Exclude*;
347     the_excludes[0] = new Exclude(0);
348     the_excludes[0]->setPair( 0,0 );
349 mmeineke 377 simnfo->globalExcludes = new int;
350     simnfo->globalExcludes[0] = 0;
351 mmeineke 412 simnfo->n_exclude = 0;
352 mmeineke 377 }
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 mmeineke 422 makeMolecules();
414 mmeineke 377 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 gezelter 394 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 mmeineke 377
438 gezelter 394 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 mmeineke 377
493 gezelter 394 #ifdef IS_MPI
494     strcpy( checkPointMsg, "electrostatic parameters check out" );
495     MPIcheckPoint();
496     #endif // is_mpi
497 mmeineke 377
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 mmeineke 407
687     void SimSetup::makeMolecules( void ){
688    
689 mmeineke 412 int i, j, exI, exJ, tempEx, stampID, atomOffset, excludeOffset;
690 mmeineke 407 molInit info;
691     DirectionalAtom* dAtom;
692 mmeineke 412 LinkedAssign* extras;
693     LinkedAssign* current_extra;
694 mmeineke 407 AtomStamp* currentAtom;
695     BondStamp* currentBond;
696     BendStamp* currentBend;
697     TorsionStamp* currentTorsion;
698 mmeineke 427
699     bond_pair* theBonds;
700     bend_set* theBends;
701     torsion_set* theTorsions;
702    
703 mmeineke 407
704     //init the forceField paramters
705    
706     the_ff->readParams();
707    
708    
709 mmeineke 427 // init the atoms
710 mmeineke 407
711 mmeineke 427 double ux, uy, uz, u, uSqr;
712    
713 mmeineke 407 atomOffset = 0;
714 mmeineke 412 excludeOffset = 0;
715 mmeineke 407 for(i=0; i<simnfo->n_mol; i++){
716    
717     stampID = the_molecules[i].getStampID();
718    
719     info.nAtoms = comp_stamps[stampID]->getNAtoms();
720     info.nBonds = comp_stamps[stampID]->getNBonds();
721     info.nBends = comp_stamps[stampID]->getNBends();
722     info.nTorsions = comp_stamps[stampID]->getNTorsions();
723 mmeineke 412 info.nExcludes = info.nBonds + info.nBends + info.nTorsions;
724    
725 mmeineke 407 info.myAtoms = &the_atoms[atomOffset];
726 mmeineke 412 info.myExcludes = &the_excludes[excludeOffset];
727 mmeineke 407 info.myBonds = new Bond*[info.nBonds];
728     info.myBends = new Bend*[info.nBends];
729 mmeineke 427 info.myTorsions = new Torsion*[info.nTorsions];
730 mmeineke 407
731     theBonds = new bond_pair[info.nBonds];
732     theBends = new bend_set[info.nBends];
733     theTorsions = new torsion_set[info.nTorsions];
734    
735     // make the Atoms
736    
737     for(j=0; j<info.nAtoms; j++){
738    
739 mmeineke 427 currentAtom = comp_stamps[stampID]->getAtom( j );
740 mmeineke 407 if( currentAtom->haveOrientation() ){
741    
742     dAtom = new DirectionalAtom(j + atomOffset);
743     simnfo->n_oriented++;
744     info.myAtoms[j] = dAtom;
745    
746     ux = currentAtom->getOrntX();
747     uy = currentAtom->getOrntY();
748     uz = currentAtom->getOrntZ();
749    
750     uSqr = (ux * ux) + (uy * uy) + (uz * uz);
751    
752     u = sqrt( uSqr );
753     ux = ux / u;
754     uy = uy / u;
755     uz = uz / u;
756    
757     dAtom->setSUx( ux );
758     dAtom->setSUy( uy );
759     dAtom->setSUz( uz );
760     }
761     else{
762     info.myAtoms[j] = new GeneralAtom(j + atomOffset);
763     }
764     info.myAtoms[j]->setType( currentAtom->getType() );
765    
766     #ifdef IS_MPI
767    
768     info.myAtoms[j]->setGlobalIndex( globalIndex[j+atomOffset] );
769    
770     #endif // is_mpi
771     }
772    
773     // make the bonds
774 mmeineke 412 for(j=0; j<info.nBonds; j++){
775 mmeineke 407
776     currentBond = comp_stamps[stampID]->getBond( j );
777     theBonds[j].a = currentBond->getA() + atomOffset;
778     theBonds[j].b = currentBond->getB() + atomOffset;
779    
780     exI = theBonds[i].a;
781     exJ = theBonds[i].b;
782    
783     // exclude_I must always be the smaller of the pair
784     if( exI > exJ ){
785     tempEx = exI;
786     exI = exJ;
787     exJ = tempEx;
788     }
789     #ifdef IS_MPI
790 mmeineke 412 tempEx = exI;
791     exI = the_atoms[tempEx]->getGlobalIndex() + 1;
792     tempEx = exJ;
793     exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
794 mmeineke 407
795 mmeineke 412 the_excludes[j+excludeOffset]->setPair( exI, exJ );
796     #else // isn't MPI
797     the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
798     #endif //is_mpi
799     }
800     excludeOffset += info.nBonds;
801    
802     //make the bends
803     for(j=0; j<info.nBends; j++){
804 mmeineke 407
805 mmeineke 412 currentBend = comp_stamps[stampID]->getBend( j );
806     theBends[j].a = currentBend->getA() + atomOffset;
807     theBends[j].b = currentBend->getB() + atomOffset;
808     theBends[j].c = currentBend->getC() + atomOffset;
809    
810     if( currentBend->haveExtras() ){
811    
812 mmeineke 427 extras = currentBend->getExtras();
813 mmeineke 412 current_extra = extras;
814    
815     while( current_extra != NULL ){
816     if( !strcmp( current_extra->getlhs(), "ghostVectorSource" )){
817    
818     switch( current_extra->getType() ){
819    
820     case 0:
821     theBends[j].ghost =
822     current_extra->getInt() + atomOffset;
823     theBends[j].isGhost = 1;
824     break;
825    
826     case 1:
827     theBends[j].ghost =
828     (int)current_extra->getDouble() + atomOffset;
829     theBends[j].isGhost = 1;
830     break;
831    
832     default:
833     sprintf( painCave.errMsg,
834     "SimSetup Error: ghostVectorSource was neiter a "
835     "double nor an int.\n"
836     "-->Bend[%d] in %s\n",
837     j, comp_stamps[stampID]->getID() );
838     painCave.isFatal = 1;
839     simError();
840     }
841     }
842    
843     else{
844    
845     sprintf( painCave.errMsg,
846     "SimSetup Error: unhandled bend assignment:\n"
847     " -->%s in Bend[%d] in %s\n",
848     current_extra->getlhs(),
849     j, comp_stamps[stampID]->getID() );
850     painCave.isFatal = 1;
851     simError();
852     }
853    
854     current_extra = current_extra->getNext();
855     }
856     }
857    
858     if( !theBends[j].isGhost ){
859    
860     exI = theBends[j].a;
861     exJ = theBends[j].c;
862     }
863     else{
864    
865     exI = theBends[j].a;
866     exJ = theBends[j].b;
867     }
868    
869     // exclude_I must always be the smaller of the pair
870     if( exI > exJ ){
871     tempEx = exI;
872     exI = exJ;
873     exJ = tempEx;
874     }
875     #ifdef IS_MPI
876     tempEx = exI;
877     exI = the_atoms[tempEx]->getGlobalIndex() + 1;
878     tempEx = exJ;
879     exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
880    
881     the_excludes[j+excludeOffset]->setPair( exI, exJ );
882 mmeineke 407 #else // isn't MPI
883 mmeineke 412 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
884     #endif //is_mpi
885     }
886     excludeOffset += info.nBends;
887    
888     for(j=0; j<info.nTorsions; j++){
889 mmeineke 407
890 mmeineke 412 currentTorsion = comp_stamps[stampID]->getTorsion( j );
891     theTorsions[j].a = currentTorsion->getA() + atomOffset;
892     theTorsions[j].b = currentTorsion->getB() + atomOffset;
893     theTorsions[j].c = currentTorsion->getC() + atomOffset;
894     theTorsions[j].d = currentTorsion->getD() + atomOffset;
895    
896     exI = theTorsions[j].a;
897     exJ = theTorsions[j].d;
898 mmeineke 407
899 mmeineke 412 // exclude_I must always be the smaller of the pair
900     if( exI > exJ ){
901     tempEx = exI;
902     exI = exJ;
903     exJ = tempEx;
904     }
905     #ifdef IS_MPI
906     tempEx = exI;
907     exI = the_atoms[tempEx]->getGlobalIndex() + 1;
908     tempEx = exJ;
909     exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
910    
911     the_excludes[j+excludeOffset]->setPair( exI, exJ );
912     #else // isn't MPI
913     the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
914 mmeineke 407 #endif //is_mpi
915 mmeineke 412 }
916     excludeOffset += info.nTorsions;
917    
918 mmeineke 407
919 mmeineke 414 // send the arrays off to the forceField for init.
920 mmeineke 407
921 mmeineke 414 the_ff->initializeAtoms( info.nAtoms, info.myAtoms );
922     the_ff->initializeBonds( info.nBonds, info.myBonds, theBonds );
923     the_ff->initializeBends( info.nBends, info.myBends, theBends );
924     the_ff->initializeTorsions( info.nTorsions, info.myTorsions, theTorsions );
925 mmeineke 407
926    
927 mmeineke 414 the_molecules[i].initialize( info );
928     atomOffset += info.nAtoms;
929 mmeineke 427 delete[] theBonds;
930     delete[] theBends;
931     delete[] theTorsions;
932 mmeineke 414 }
933 mmeineke 407
934 mmeineke 414 // clean up the forcefield
935 mmeineke 420 the_ff->calcRcut();
936 mmeineke 414 the_ff->cleanMe();
937     }
938 mmeineke 407
939 mmeineke 377 void SimSetup::initFromBass( void ){
940    
941     int i, j, k;
942     int n_cells;
943     double cellx, celly, cellz;
944     double temp1, temp2, temp3;
945     int n_per_extra;
946     int n_extra;
947     int have_extra, done;
948    
949     temp1 = (double)tot_nmol / 4.0;
950     temp2 = pow( temp1, ( 1.0 / 3.0 ) );
951     temp3 = ceil( temp2 );
952    
953     have_extra =0;
954     if( temp2 < temp3 ){ // we have a non-complete lattice
955     have_extra =1;
956    
957     n_cells = (int)temp3 - 1;
958     cellx = simnfo->box_x / temp3;
959     celly = simnfo->box_y / temp3;
960     cellz = simnfo->box_z / temp3;
961     n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells );
962     temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) );
963     n_per_extra = (int)ceil( temp1 );
964    
965     if( n_per_extra > 4){
966     sprintf( painCave.errMsg,
967     "SimSetup error. There has been an error in constructing"
968     " the non-complete lattice.\n" );
969     painCave.isFatal = 1;
970     simError();
971     }
972     }
973     else{
974     n_cells = (int)temp3;
975     cellx = simnfo->box_x / temp3;
976     celly = simnfo->box_y / temp3;
977     cellz = simnfo->box_z / temp3;
978     }
979    
980     current_mol = 0;
981     current_comp_mol = 0;
982     current_comp = 0;
983     current_atom_ndx = 0;
984    
985     for( i=0; i < n_cells ; i++ ){
986     for( j=0; j < n_cells; j++ ){
987     for( k=0; k < n_cells; k++ ){
988    
989     makeElement( i * cellx,
990     j * celly,
991     k * cellz );
992    
993     makeElement( i * cellx + 0.5 * cellx,
994     j * celly + 0.5 * celly,
995     k * cellz );
996    
997     makeElement( i * cellx,
998     j * celly + 0.5 * celly,
999     k * cellz + 0.5 * cellz );
1000    
1001     makeElement( i * cellx + 0.5 * cellx,
1002     j * celly,
1003     k * cellz + 0.5 * cellz );
1004     }
1005     }
1006     }
1007    
1008     if( have_extra ){
1009     done = 0;
1010    
1011     int start_ndx;
1012     for( i=0; i < (n_cells+1) && !done; i++ ){
1013     for( j=0; j < (n_cells+1) && !done; j++ ){
1014    
1015     if( i < n_cells ){
1016    
1017     if( j < n_cells ){
1018     start_ndx = n_cells;
1019     }
1020     else start_ndx = 0;
1021     }
1022     else start_ndx = 0;
1023    
1024     for( k=start_ndx; k < (n_cells+1) && !done; k++ ){
1025    
1026     makeElement( i * cellx,
1027     j * celly,
1028     k * cellz );
1029     done = ( current_mol >= tot_nmol );
1030    
1031     if( !done && n_per_extra > 1 ){
1032     makeElement( i * cellx + 0.5 * cellx,
1033     j * celly + 0.5 * celly,
1034     k * cellz );
1035     done = ( current_mol >= tot_nmol );
1036     }
1037    
1038     if( !done && n_per_extra > 2){
1039     makeElement( i * cellx,
1040     j * celly + 0.5 * celly,
1041     k * cellz + 0.5 * cellz );
1042     done = ( current_mol >= tot_nmol );
1043     }
1044    
1045     if( !done && n_per_extra > 3){
1046     makeElement( i * cellx + 0.5 * cellx,
1047     j * celly,
1048     k * cellz + 0.5 * cellz );
1049     done = ( current_mol >= tot_nmol );
1050     }
1051     }
1052     }
1053     }
1054     }
1055    
1056    
1057     for( i=0; i<simnfo->n_atoms; i++ ){
1058     simnfo->atoms[i]->set_vx( 0.0 );
1059     simnfo->atoms[i]->set_vy( 0.0 );
1060     simnfo->atoms[i]->set_vz( 0.0 );
1061     }
1062     }
1063    
1064     void SimSetup::makeElement( double x, double y, double z ){
1065    
1066     int k;
1067     AtomStamp* current_atom;
1068     DirectionalAtom* dAtom;
1069     double rotMat[3][3];
1070    
1071     for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){
1072    
1073     current_atom = comp_stamps[current_comp]->getAtom( k );
1074     if( !current_atom->havePosition() ){
1075     sprintf( painCave.errMsg,
1076     "SimSetup:initFromBass error.\n"
1077     "\tComponent %s, atom %s does not have a position specified.\n"
1078     "\tThe initialization routine is unable to give a start"
1079     " position.\n",
1080     comp_stamps[current_comp]->getID(),
1081     current_atom->getType() );
1082     painCave.isFatal = 1;
1083     simError();
1084     }
1085    
1086     the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() );
1087     the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() );
1088     the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() );
1089    
1090     if( the_atoms[current_atom_ndx]->isDirectional() ){
1091    
1092     dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx];
1093    
1094     rotMat[0][0] = 1.0;
1095     rotMat[0][1] = 0.0;
1096     rotMat[0][2] = 0.0;
1097    
1098     rotMat[1][0] = 0.0;
1099     rotMat[1][1] = 1.0;
1100     rotMat[1][2] = 0.0;
1101    
1102     rotMat[2][0] = 0.0;
1103     rotMat[2][1] = 0.0;
1104     rotMat[2][2] = 1.0;
1105    
1106     dAtom->setA( rotMat );
1107     }
1108    
1109     current_atom_ndx++;
1110     }
1111    
1112     current_mol++;
1113     current_comp_mol++;
1114    
1115     if( current_comp_mol >= components_nmol[current_comp] ){
1116    
1117     current_comp_mol = 0;
1118     current_comp++;
1119     }
1120     }