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