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