ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimSetup.cpp
Revision: 438
Committed: Mon Mar 31 21:50:59 2003 UTC (21 years, 3 months ago) by chuckv
File size: 28076 byte(s)
Log Message:
Fixes in MPI force calc and in Trappe_Ex parsing.

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     // set up the local variables
244    
245     int localMol, allMol;
246     int local_atoms, local_bonds, local_bends, local_torsions, local_SRI;
247 mmeineke 422
248     int* mol2proc = mpiSim->getMolToProcMap();
249     int* molCompType = mpiSim->getMolComponentType();
250 mmeineke 377
251     allMol = 0;
252     localMol = 0;
253     local_atoms = 0;
254     local_bonds = 0;
255     local_bends = 0;
256     local_torsions = 0;
257     for( i=0; i<n_components; i++ ){
258    
259     for( j=0; j<components_nmol[i]; j++ ){
260    
261 mmeineke 422 if( mol2proc[j] == worldRank ){
262 mmeineke 377
263     local_atoms += comp_stamps[i]->getNAtoms();
264     local_bonds += comp_stamps[i]->getNBonds();
265     local_bends += comp_stamps[i]->getNBends();
266     local_torsions += comp_stamps[i]->getNTorsions();
267     localMol++;
268     }
269     allMol++;
270     }
271     }
272     local_SRI = local_bonds + local_bends + local_torsions;
273    
274    
275     simnfo->n_atoms = mpiSim->getMyNlocal();
276    
277     if( local_atoms != simnfo->n_atoms ){
278     sprintf( painCave.errMsg,
279     "SimSetup error: mpiSim's localAtom (%d) and SimSetup's"
280 mmeineke 422 " localAtom (%d) are not equal.\n",
281 mmeineke 377 simnfo->n_atoms,
282     local_atoms );
283     painCave.isFatal = 1;
284     simError();
285     }
286    
287     simnfo->n_bonds = local_bonds;
288     simnfo->n_bends = local_bends;
289     simnfo->n_torsions = local_torsions;
290     simnfo->n_SRI = local_SRI;
291     simnfo->n_mol = localMol;
292    
293     strcpy( checkPointMsg, "Passed nlocal consistency check." );
294     MPIcheckPoint();
295    
296    
297     #endif // is_mpi
298    
299    
300     // create the atom and short range interaction arrays
301    
302     Atom::createArrays(simnfo->n_atoms);
303     the_atoms = new Atom*[simnfo->n_atoms];
304     the_molecules = new Molecule[simnfo->n_mol];
305 mmeineke 422 int molIndex;
306 mmeineke 377
307 mmeineke 422 // initialize the molecule's stampID's
308 mmeineke 377
309 mmeineke 422 #ifdef IS_MPI
310    
311    
312     molIndex = 0;
313     for(i=0; i<mpiSim->getTotNmol(); i++){
314    
315     if(mol2proc[i] == worldRank ){
316     the_molecules[molIndex].setStampID( molCompType[i] );
317 chuckv 438 the_molecules[molIndex].setMyIndex( molIndex );
318 mmeineke 422 molIndex++;
319     }
320     }
321    
322     #else // is_mpi
323    
324     molIndex = 0;
325     for(i=0; i<n_components; i++){
326     for(j=0; j<components_nmol[i]; j++ ){
327     the_molecules[molIndex].setStampID( i );
328 chuckv 438 the_molecules[molIndex].setMyIndex( molIndex );
329 mmeineke 422 molIndex++;
330     }
331     }
332    
333    
334     #endif // is_mpi
335    
336    
337 mmeineke 377 if( simnfo->n_SRI ){
338 mmeineke 431
339     std::cerr << "n_SRI = " << simnfo->n_SRI << "\n";
340    
341 mmeineke 412 Exclude::createArray(simnfo->n_SRI);
342     the_excludes = new Exclude*[simnfo->n_SRI];
343 mmeineke 431 for( int ex=0; ex<simnfo->n_SRI; ex++) the_excludes[ex] = new Exclude(ex);
344 mmeineke 377 simnfo->globalExcludes = new int;
345 chuckv 438 simnfo->n_exclude = simnfo->n_SRI;
346 mmeineke 377 }
347     else{
348    
349 mmeineke 412 Exclude::createArray( 1 );
350     the_excludes = new Exclude*;
351     the_excludes[0] = new Exclude(0);
352     the_excludes[0]->setPair( 0,0 );
353 mmeineke 377 simnfo->globalExcludes = new int;
354     simnfo->globalExcludes[0] = 0;
355 mmeineke 412 simnfo->n_exclude = 0;
356 mmeineke 377 }
357    
358     // set the arrays into the SimInfo object
359    
360     simnfo->atoms = the_atoms;
361 mmeineke 429 simnfo->molecules = the_molecules;
362 mmeineke 377 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 mmeineke 422 makeMolecules();
419 mmeineke 377 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 gezelter 394 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 mmeineke 377
443 gezelter 394 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 mmeineke 377
498 gezelter 394 #ifdef IS_MPI
499     strcpy( checkPointMsg, "electrostatic parameters check out" );
500     MPIcheckPoint();
501     #endif // is_mpi
502 mmeineke 377
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 chuckv 432 #ifdef IS_MPI
664     mpiSim->mpiRefresh();
665     #endif
666 mmeineke 377
667 chuckv 432 // initialize the Fortran
668 mmeineke 377
669 chuckv 432
670 mmeineke 377 simnfo->refreshSim();
671    
672     if( !strcmp( simnfo->mixingRule, "standard") ){
673     the_ff->initForceField( LB_MIXING_RULE );
674     }
675     else if( !strcmp( simnfo->mixingRule, "explicit") ){
676     the_ff->initForceField( EXPLICIT_MIXING_RULE );
677     }
678     else{
679     sprintf( painCave.errMsg,
680     "SimSetup Error: unknown mixing rule -> \"%s\"\n",
681     simnfo->mixingRule );
682     painCave.isFatal = 1;
683     simError();
684     }
685    
686    
687     #ifdef IS_MPI
688     strcpy( checkPointMsg,
689     "Successfully intialized the mixingRule for Fortran." );
690     MPIcheckPoint();
691     #endif // is_mpi
692     }
693    
694 mmeineke 407
695     void SimSetup::makeMolecules( void ){
696    
697 mmeineke 412 int i, j, exI, exJ, tempEx, stampID, atomOffset, excludeOffset;
698 mmeineke 407 molInit info;
699     DirectionalAtom* dAtom;
700 mmeineke 412 LinkedAssign* extras;
701     LinkedAssign* current_extra;
702 mmeineke 407 AtomStamp* currentAtom;
703     BondStamp* currentBond;
704     BendStamp* currentBend;
705     TorsionStamp* currentTorsion;
706 mmeineke 427
707     bond_pair* theBonds;
708     bend_set* theBends;
709     torsion_set* theTorsions;
710    
711 mmeineke 407
712     //init the forceField paramters
713    
714     the_ff->readParams();
715    
716    
717 mmeineke 427 // init the atoms
718 mmeineke 407
719 mmeineke 427 double ux, uy, uz, u, uSqr;
720    
721 mmeineke 407 atomOffset = 0;
722 mmeineke 412 excludeOffset = 0;
723 mmeineke 407 for(i=0; i<simnfo->n_mol; i++){
724    
725     stampID = the_molecules[i].getStampID();
726    
727     info.nAtoms = comp_stamps[stampID]->getNAtoms();
728     info.nBonds = comp_stamps[stampID]->getNBonds();
729     info.nBends = comp_stamps[stampID]->getNBends();
730     info.nTorsions = comp_stamps[stampID]->getNTorsions();
731 mmeineke 412 info.nExcludes = info.nBonds + info.nBends + info.nTorsions;
732    
733 mmeineke 407 info.myAtoms = &the_atoms[atomOffset];
734 mmeineke 412 info.myExcludes = &the_excludes[excludeOffset];
735 mmeineke 407 info.myBonds = new Bond*[info.nBonds];
736     info.myBends = new Bend*[info.nBends];
737 mmeineke 427 info.myTorsions = new Torsion*[info.nTorsions];
738 mmeineke 407
739     theBonds = new bond_pair[info.nBonds];
740     theBends = new bend_set[info.nBends];
741     theTorsions = new torsion_set[info.nTorsions];
742    
743     // make the Atoms
744    
745     for(j=0; j<info.nAtoms; j++){
746    
747 mmeineke 427 currentAtom = comp_stamps[stampID]->getAtom( j );
748 mmeineke 407 if( currentAtom->haveOrientation() ){
749    
750     dAtom = new DirectionalAtom(j + atomOffset);
751     simnfo->n_oriented++;
752     info.myAtoms[j] = dAtom;
753    
754     ux = currentAtom->getOrntX();
755     uy = currentAtom->getOrntY();
756     uz = currentAtom->getOrntZ();
757    
758     uSqr = (ux * ux) + (uy * uy) + (uz * uz);
759    
760     u = sqrt( uSqr );
761     ux = ux / u;
762     uy = uy / u;
763     uz = uz / u;
764    
765     dAtom->setSUx( ux );
766     dAtom->setSUy( uy );
767     dAtom->setSUz( uz );
768     }
769     else{
770     info.myAtoms[j] = new GeneralAtom(j + atomOffset);
771     }
772     info.myAtoms[j]->setType( currentAtom->getType() );
773    
774     #ifdef IS_MPI
775    
776     info.myAtoms[j]->setGlobalIndex( globalIndex[j+atomOffset] );
777    
778     #endif // is_mpi
779     }
780    
781     // make the bonds
782 mmeineke 412 for(j=0; j<info.nBonds; j++){
783 mmeineke 407
784     currentBond = comp_stamps[stampID]->getBond( j );
785     theBonds[j].a = currentBond->getA() + atomOffset;
786     theBonds[j].b = currentBond->getB() + atomOffset;
787    
788 mmeineke 435 exI = theBonds[j].a;
789     exJ = theBonds[j].b;
790 mmeineke 407
791     // exclude_I must always be the smaller of the pair
792     if( exI > exJ ){
793     tempEx = exI;
794     exI = exJ;
795     exJ = tempEx;
796     }
797     #ifdef IS_MPI
798 mmeineke 412 tempEx = exI;
799     exI = the_atoms[tempEx]->getGlobalIndex() + 1;
800     tempEx = exJ;
801     exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
802 mmeineke 407
803 mmeineke 412 the_excludes[j+excludeOffset]->setPair( exI, exJ );
804     #else // isn't MPI
805 mmeineke 435
806 mmeineke 412 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
807     #endif //is_mpi
808     }
809     excludeOffset += info.nBonds;
810    
811     //make the bends
812     for(j=0; j<info.nBends; j++){
813 mmeineke 407
814 mmeineke 412 currentBend = comp_stamps[stampID]->getBend( j );
815     theBends[j].a = currentBend->getA() + atomOffset;
816     theBends[j].b = currentBend->getB() + atomOffset;
817     theBends[j].c = currentBend->getC() + atomOffset;
818    
819     if( currentBend->haveExtras() ){
820    
821 mmeineke 427 extras = currentBend->getExtras();
822 mmeineke 412 current_extra = extras;
823    
824     while( current_extra != NULL ){
825     if( !strcmp( current_extra->getlhs(), "ghostVectorSource" )){
826    
827     switch( current_extra->getType() ){
828    
829     case 0:
830     theBends[j].ghost =
831     current_extra->getInt() + atomOffset;
832     theBends[j].isGhost = 1;
833     break;
834    
835     case 1:
836     theBends[j].ghost =
837     (int)current_extra->getDouble() + atomOffset;
838     theBends[j].isGhost = 1;
839     break;
840    
841     default:
842     sprintf( painCave.errMsg,
843 chuckv 434 "SimSetup Error: ghostVectorSource was neither a "
844 mmeineke 412 "double nor an int.\n"
845     "-->Bend[%d] in %s\n",
846     j, comp_stamps[stampID]->getID() );
847     painCave.isFatal = 1;
848     simError();
849     }
850     }
851    
852     else{
853    
854     sprintf( painCave.errMsg,
855     "SimSetup Error: unhandled bend assignment:\n"
856     " -->%s in Bend[%d] in %s\n",
857     current_extra->getlhs(),
858     j, comp_stamps[stampID]->getID() );
859     painCave.isFatal = 1;
860     simError();
861     }
862    
863     current_extra = current_extra->getNext();
864     }
865     }
866    
867     if( !theBends[j].isGhost ){
868    
869     exI = theBends[j].a;
870     exJ = theBends[j].c;
871     }
872     else{
873    
874     exI = theBends[j].a;
875     exJ = theBends[j].b;
876     }
877    
878     // exclude_I must always be the smaller of the pair
879     if( exI > exJ ){
880     tempEx = exI;
881     exI = exJ;
882     exJ = tempEx;
883     }
884     #ifdef IS_MPI
885     tempEx = exI;
886     exI = the_atoms[tempEx]->getGlobalIndex() + 1;
887     tempEx = exJ;
888     exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
889    
890     the_excludes[j+excludeOffset]->setPair( exI, exJ );
891 mmeineke 407 #else // isn't MPI
892 mmeineke 412 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
893     #endif //is_mpi
894     }
895     excludeOffset += info.nBends;
896    
897     for(j=0; j<info.nTorsions; j++){
898 mmeineke 407
899 mmeineke 412 currentTorsion = comp_stamps[stampID]->getTorsion( j );
900     theTorsions[j].a = currentTorsion->getA() + atomOffset;
901     theTorsions[j].b = currentTorsion->getB() + atomOffset;
902     theTorsions[j].c = currentTorsion->getC() + atomOffset;
903     theTorsions[j].d = currentTorsion->getD() + atomOffset;
904    
905     exI = theTorsions[j].a;
906     exJ = theTorsions[j].d;
907 mmeineke 407
908 mmeineke 412 // exclude_I must always be the smaller of the pair
909     if( exI > exJ ){
910     tempEx = exI;
911     exI = exJ;
912     exJ = tempEx;
913     }
914     #ifdef IS_MPI
915     tempEx = exI;
916     exI = the_atoms[tempEx]->getGlobalIndex() + 1;
917     tempEx = exJ;
918     exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
919    
920     the_excludes[j+excludeOffset]->setPair( exI, exJ );
921     #else // isn't MPI
922     the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
923 mmeineke 407 #endif //is_mpi
924 mmeineke 412 }
925     excludeOffset += info.nTorsions;
926    
927 mmeineke 407
928 mmeineke 414 // send the arrays off to the forceField for init.
929 mmeineke 407
930 mmeineke 414 the_ff->initializeAtoms( info.nAtoms, info.myAtoms );
931     the_ff->initializeBonds( info.nBonds, info.myBonds, theBonds );
932     the_ff->initializeBends( info.nBends, info.myBends, theBends );
933     the_ff->initializeTorsions( info.nTorsions, info.myTorsions, theTorsions );
934 mmeineke 407
935    
936 mmeineke 414 the_molecules[i].initialize( info );
937 chuckv 438
938    
939 mmeineke 414 atomOffset += info.nAtoms;
940 mmeineke 427 delete[] theBonds;
941     delete[] theBends;
942     delete[] theTorsions;
943 mmeineke 414 }
944 mmeineke 407
945 chuckv 434 #ifdef IS_MPI
946     sprintf( checkPointMsg, "all molecules initialized succesfully" );
947     MPIcheckPoint();
948     #endif // is_mpi
949    
950 mmeineke 414 // clean up the forcefield
951 mmeineke 420 the_ff->calcRcut();
952 mmeineke 414 the_ff->cleanMe();
953 chuckv 434
954 mmeineke 414 }
955 mmeineke 407
956 mmeineke 377 void SimSetup::initFromBass( void ){
957    
958     int i, j, k;
959     int n_cells;
960     double cellx, celly, cellz;
961     double temp1, temp2, temp3;
962     int n_per_extra;
963     int n_extra;
964     int have_extra, done;
965    
966     temp1 = (double)tot_nmol / 4.0;
967     temp2 = pow( temp1, ( 1.0 / 3.0 ) );
968     temp3 = ceil( temp2 );
969    
970     have_extra =0;
971     if( temp2 < temp3 ){ // we have a non-complete lattice
972     have_extra =1;
973    
974     n_cells = (int)temp3 - 1;
975     cellx = simnfo->box_x / temp3;
976     celly = simnfo->box_y / temp3;
977     cellz = simnfo->box_z / temp3;
978     n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells );
979     temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) );
980     n_per_extra = (int)ceil( temp1 );
981    
982     if( n_per_extra > 4){
983     sprintf( painCave.errMsg,
984     "SimSetup error. There has been an error in constructing"
985     " the non-complete lattice.\n" );
986     painCave.isFatal = 1;
987     simError();
988     }
989     }
990     else{
991     n_cells = (int)temp3;
992     cellx = simnfo->box_x / temp3;
993     celly = simnfo->box_y / temp3;
994     cellz = simnfo->box_z / temp3;
995     }
996    
997     current_mol = 0;
998     current_comp_mol = 0;
999     current_comp = 0;
1000     current_atom_ndx = 0;
1001    
1002     for( i=0; i < n_cells ; i++ ){
1003     for( j=0; j < n_cells; j++ ){
1004     for( k=0; k < n_cells; k++ ){
1005    
1006     makeElement( i * cellx,
1007     j * celly,
1008     k * cellz );
1009    
1010     makeElement( i * cellx + 0.5 * cellx,
1011     j * celly + 0.5 * celly,
1012     k * cellz );
1013    
1014     makeElement( i * cellx,
1015     j * celly + 0.5 * celly,
1016     k * cellz + 0.5 * cellz );
1017    
1018     makeElement( i * cellx + 0.5 * cellx,
1019     j * celly,
1020     k * cellz + 0.5 * cellz );
1021     }
1022     }
1023     }
1024    
1025     if( have_extra ){
1026     done = 0;
1027    
1028     int start_ndx;
1029     for( i=0; i < (n_cells+1) && !done; i++ ){
1030     for( j=0; j < (n_cells+1) && !done; j++ ){
1031    
1032     if( i < n_cells ){
1033    
1034     if( j < n_cells ){
1035     start_ndx = n_cells;
1036     }
1037     else start_ndx = 0;
1038     }
1039     else start_ndx = 0;
1040    
1041     for( k=start_ndx; k < (n_cells+1) && !done; k++ ){
1042    
1043     makeElement( i * cellx,
1044     j * celly,
1045     k * cellz );
1046     done = ( current_mol >= tot_nmol );
1047    
1048     if( !done && n_per_extra > 1 ){
1049     makeElement( i * cellx + 0.5 * cellx,
1050     j * celly + 0.5 * celly,
1051     k * cellz );
1052     done = ( current_mol >= tot_nmol );
1053     }
1054    
1055     if( !done && n_per_extra > 2){
1056     makeElement( i * cellx,
1057     j * celly + 0.5 * celly,
1058     k * cellz + 0.5 * cellz );
1059     done = ( current_mol >= tot_nmol );
1060     }
1061    
1062     if( !done && n_per_extra > 3){
1063     makeElement( i * cellx + 0.5 * cellx,
1064     j * celly,
1065     k * cellz + 0.5 * cellz );
1066     done = ( current_mol >= tot_nmol );
1067     }
1068     }
1069     }
1070     }
1071     }
1072    
1073    
1074     for( i=0; i<simnfo->n_atoms; i++ ){
1075     simnfo->atoms[i]->set_vx( 0.0 );
1076     simnfo->atoms[i]->set_vy( 0.0 );
1077     simnfo->atoms[i]->set_vz( 0.0 );
1078     }
1079     }
1080    
1081     void SimSetup::makeElement( double x, double y, double z ){
1082    
1083     int k;
1084     AtomStamp* current_atom;
1085     DirectionalAtom* dAtom;
1086     double rotMat[3][3];
1087    
1088     for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){
1089    
1090     current_atom = comp_stamps[current_comp]->getAtom( k );
1091     if( !current_atom->havePosition() ){
1092     sprintf( painCave.errMsg,
1093     "SimSetup:initFromBass error.\n"
1094     "\tComponent %s, atom %s does not have a position specified.\n"
1095     "\tThe initialization routine is unable to give a start"
1096     " position.\n",
1097     comp_stamps[current_comp]->getID(),
1098     current_atom->getType() );
1099     painCave.isFatal = 1;
1100     simError();
1101     }
1102    
1103     the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() );
1104     the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() );
1105     the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() );
1106    
1107     if( the_atoms[current_atom_ndx]->isDirectional() ){
1108    
1109     dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx];
1110    
1111     rotMat[0][0] = 1.0;
1112     rotMat[0][1] = 0.0;
1113     rotMat[0][2] = 0.0;
1114    
1115     rotMat[1][0] = 0.0;
1116     rotMat[1][1] = 1.0;
1117     rotMat[1][2] = 0.0;
1118    
1119     rotMat[2][0] = 0.0;
1120     rotMat[2][1] = 0.0;
1121     rotMat[2][2] = 1.0;
1122    
1123     dAtom->setA( rotMat );
1124     }
1125    
1126     current_atom_ndx++;
1127     }
1128    
1129     current_mol++;
1130     current_comp_mol++;
1131    
1132     if( current_comp_mol >= components_nmol[current_comp] ){
1133    
1134     current_comp_mol = 0;
1135     current_comp++;
1136     }
1137     }