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 |
|
|
int i; |
77 |
|
|
|
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 |
|
|
|
165 |
|
|
for( i=0; i<n_components; i++ ){ |
166 |
|
|
|
167 |
chuckv |
124 |
comp_stamps[i] = |
168 |
mmeineke |
10 |
the_stamps->getMolecule( the_components[i]->getType() ); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
|
172 |
chuckv |
124 |
|
173 |
mmeineke |
10 |
// caclulate the number of atoms, bonds, bends and torsions |
174 |
|
|
|
175 |
|
|
tot_atoms = 0; |
176 |
|
|
tot_bonds = 0; |
177 |
|
|
tot_bends = 0; |
178 |
|
|
tot_torsions = 0; |
179 |
|
|
for( i=0; i<n_components; i++ ){ |
180 |
chuckv |
124 |
|
181 |
mmeineke |
10 |
tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms(); |
182 |
|
|
tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds(); |
183 |
|
|
tot_bends += components_nmol[i] * comp_stamps[i]->getNBends(); |
184 |
|
|
tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions(); |
185 |
|
|
} |
186 |
chuckv |
124 |
|
187 |
mmeineke |
10 |
tot_SRI = tot_bonds + tot_bends + tot_torsions; |
188 |
chuckv |
124 |
|
189 |
mmeineke |
10 |
simnfo->n_atoms = tot_atoms; |
190 |
|
|
simnfo->n_bonds = tot_bonds; |
191 |
|
|
simnfo->n_bends = tot_bends; |
192 |
|
|
simnfo->n_torsions = tot_torsions; |
193 |
|
|
simnfo->n_SRI = tot_SRI; |
194 |
|
|
|
195 |
|
|
// create the atom and short range interaction arrays |
196 |
chuckv |
124 |
|
197 |
mmeineke |
184 |
Atom::createArrays(tot_atoms); |
198 |
mmeineke |
10 |
the_atoms = new Atom*[tot_atoms]; |
199 |
mmeineke |
113 |
the_molecules = new Molecule[tot_nmol]; |
200 |
chuckv |
124 |
|
201 |
|
|
|
202 |
mmeineke |
10 |
if( tot_SRI ){ |
203 |
|
|
the_sris = new SRI*[tot_SRI]; |
204 |
|
|
the_excludes = new ex_pair[tot_SRI]; |
205 |
|
|
} |
206 |
|
|
|
207 |
|
|
// set the arrays into the SimInfo object |
208 |
|
|
|
209 |
|
|
simnfo->atoms = the_atoms; |
210 |
|
|
simnfo->sr_interactions = the_sris; |
211 |
|
|
simnfo->n_exclude = tot_SRI; |
212 |
|
|
simnfo->excludes = the_excludes; |
213 |
|
|
|
214 |
chuckv |
124 |
|
215 |
mmeineke |
10 |
// initialize the arrays |
216 |
chuckv |
124 |
|
217 |
mmeineke |
10 |
the_ff->setSimInfo( simnfo ); |
218 |
chuckv |
124 |
|
219 |
mmeineke |
10 |
makeAtoms(); |
220 |
|
|
|
221 |
|
|
if( tot_bonds ){ |
222 |
|
|
makeBonds(); |
223 |
|
|
} |
224 |
|
|
|
225 |
|
|
if( tot_bends ){ |
226 |
|
|
makeBends(); |
227 |
|
|
} |
228 |
|
|
|
229 |
|
|
if( tot_torsions ){ |
230 |
|
|
makeTorsions(); |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
// makeMolecules(); |
234 |
|
|
|
235 |
|
|
// get some of the tricky things that may still be in the globals |
236 |
|
|
|
237 |
|
|
if( simnfo->n_dipoles ){ |
238 |
|
|
|
239 |
|
|
if( !the_globals->haveRRF() ){ |
240 |
mmeineke |
189 |
sprintf( painCave.errMsg, |
241 |
|
|
"SimSetup Error, system has dipoles, but no rRF was set.\n"); |
242 |
|
|
painCave.isFatal = 1; |
243 |
|
|
simError(); |
244 |
mmeineke |
10 |
} |
245 |
|
|
if( !the_globals->haveDielectric() ){ |
246 |
mmeineke |
189 |
sprintf( painCave.errMsg, |
247 |
|
|
"SimSetup Error, system has dipoles, but no" |
248 |
|
|
" dielectric was set.\n" ); |
249 |
|
|
painCave.isFatal = 1; |
250 |
|
|
simError(); |
251 |
mmeineke |
10 |
} |
252 |
|
|
|
253 |
|
|
simnfo->rRF = the_globals->getRRF(); |
254 |
|
|
simnfo->dielectric = the_globals->getDielectric(); |
255 |
|
|
} |
256 |
|
|
|
257 |
mmeineke |
189 |
#ifdef IS_MPI |
258 |
|
|
strcpy( checkPointMsg, "rRf and dielectric check out" ); |
259 |
|
|
MPIcheckPoint(); |
260 |
|
|
#endif // is_mpi |
261 |
|
|
|
262 |
mmeineke |
10 |
if( the_globals->haveBox() ){ |
263 |
|
|
simnfo->box_x = the_globals->getBox(); |
264 |
|
|
simnfo->box_y = the_globals->getBox(); |
265 |
|
|
simnfo->box_z = the_globals->getBox(); |
266 |
|
|
} |
267 |
|
|
else if( the_globals->haveDensity() ){ |
268 |
chuckv |
124 |
|
269 |
mmeineke |
10 |
double vol; |
270 |
|
|
vol = (double)tot_nmol / the_globals->getDensity(); |
271 |
|
|
simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) ); |
272 |
|
|
simnfo->box_y = simnfo->box_x; |
273 |
|
|
simnfo->box_z = simnfo->box_x; |
274 |
|
|
} |
275 |
|
|
else{ |
276 |
|
|
if( !the_globals->haveBoxX() ){ |
277 |
mmeineke |
189 |
sprintf( painCave.errMsg, |
278 |
|
|
"SimSetup error, no periodic BoxX size given.\n" ); |
279 |
|
|
painCave.isFatal = 1; |
280 |
|
|
simError(); |
281 |
mmeineke |
10 |
} |
282 |
|
|
simnfo->box_x = the_globals->getBoxX(); |
283 |
|
|
|
284 |
|
|
if( !the_globals->haveBoxY() ){ |
285 |
mmeineke |
189 |
sprintf( painCave.errMsg, |
286 |
|
|
"SimSetup error, no periodic BoxY size given.\n" ); |
287 |
|
|
painCave.isFatal = 1; |
288 |
|
|
simError(); |
289 |
mmeineke |
10 |
} |
290 |
|
|
simnfo->box_y = the_globals->getBoxY(); |
291 |
|
|
|
292 |
|
|
if( !the_globals->haveBoxZ() ){ |
293 |
mmeineke |
189 |
sprintf( painCave.errMsg, |
294 |
|
|
"SimSetup error, no periodic BoxZ size given.\n" ); |
295 |
|
|
painCave.isFatal = 1; |
296 |
|
|
simError(); |
297 |
mmeineke |
10 |
} |
298 |
|
|
simnfo->box_z = the_globals->getBoxZ(); |
299 |
|
|
} |
300 |
|
|
|
301 |
mmeineke |
189 |
#ifdef IS_MPI |
302 |
|
|
strcpy( checkPointMsg, "Box size set up" ); |
303 |
|
|
MPIcheckPoint(); |
304 |
|
|
#endif // is_mpi |
305 |
chuckv |
124 |
|
306 |
mmeineke |
189 |
|
307 |
|
|
|
308 |
chuckv |
124 |
// if( the_globals->haveInitialConfig() ){ |
309 |
|
|
// InitializeFromFile* fileInit; |
310 |
|
|
// fileInit = new InitializeFromFile( the_globals->getInitialConfig() ); |
311 |
|
|
|
312 |
|
|
// fileInit->read_xyz( simnfo ); // default velocities on |
313 |
|
|
|
314 |
|
|
// delete fileInit; |
315 |
|
|
// } |
316 |
|
|
// else{ |
317 |
|
|
|
318 |
mmeineke |
189 |
initFromBass(); |
319 |
|
|
|
320 |
|
|
#ifdef IS_MPI |
321 |
|
|
strcpy( checkPointMsg, "initFromBass successfully created the lattice" ); |
322 |
|
|
MPIcheckPoint(); |
323 |
|
|
#endif // is_mpi |
324 |
mmeineke |
10 |
|
325 |
|
|
|
326 |
mmeineke |
189 |
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
// } |
330 |
|
|
|
331 |
mmeineke |
184 |
#ifdef IS_MPI |
332 |
mmeineke |
189 |
if( worldRank == 0 ){ |
333 |
mmeineke |
184 |
#endif // is_mpi |
334 |
mmeineke |
189 |
|
335 |
|
|
if( the_globals->haveFinalConfig() ){ |
336 |
|
|
strcpy( simnfo->finalName, the_globals->getFinalConfig() ); |
337 |
|
|
} |
338 |
|
|
else{ |
339 |
|
|
strcpy( simnfo->finalName, inFileName ); |
340 |
|
|
char* endTest; |
341 |
|
|
int nameLength = strlen( simnfo->finalName ); |
342 |
|
|
endTest = &(simnfo->finalName[nameLength - 5]); |
343 |
|
|
if( !strcmp( endTest, ".bass" ) ){ |
344 |
|
|
strcpy( endTest, ".eor" ); |
345 |
mmeineke |
184 |
} |
346 |
mmeineke |
189 |
else if( !strcmp( endTest, ".BASS" ) ){ |
347 |
|
|
strcpy( endTest, ".eor" ); |
348 |
|
|
} |
349 |
mmeineke |
184 |
else{ |
350 |
mmeineke |
189 |
endTest = &(simnfo->finalName[nameLength - 4]); |
351 |
|
|
if( !strcmp( endTest, ".bss" ) ){ |
352 |
mmeineke |
184 |
strcpy( endTest, ".eor" ); |
353 |
|
|
} |
354 |
mmeineke |
189 |
else if( !strcmp( endTest, ".mdl" ) ){ |
355 |
mmeineke |
184 |
strcpy( endTest, ".eor" ); |
356 |
|
|
} |
357 |
|
|
else{ |
358 |
mmeineke |
189 |
strcat( simnfo->finalName, ".eor" ); |
359 |
mmeineke |
184 |
} |
360 |
|
|
} |
361 |
mmeineke |
189 |
} |
362 |
|
|
|
363 |
|
|
// make the sample and status out names |
364 |
|
|
|
365 |
|
|
strcpy( simnfo->sampleName, inFileName ); |
366 |
|
|
char* endTest; |
367 |
|
|
int nameLength = strlen( simnfo->sampleName ); |
368 |
|
|
endTest = &(simnfo->sampleName[nameLength - 5]); |
369 |
|
|
if( !strcmp( endTest, ".bass" ) ){ |
370 |
|
|
strcpy( endTest, ".dump" ); |
371 |
|
|
} |
372 |
|
|
else if( !strcmp( endTest, ".BASS" ) ){ |
373 |
|
|
strcpy( endTest, ".dump" ); |
374 |
|
|
} |
375 |
|
|
else{ |
376 |
|
|
endTest = &(simnfo->sampleName[nameLength - 4]); |
377 |
|
|
if( !strcmp( endTest, ".bss" ) ){ |
378 |
mmeineke |
184 |
strcpy( endTest, ".dump" ); |
379 |
|
|
} |
380 |
mmeineke |
189 |
else if( !strcmp( endTest, ".mdl" ) ){ |
381 |
mmeineke |
184 |
strcpy( endTest, ".dump" ); |
382 |
|
|
} |
383 |
|
|
else{ |
384 |
mmeineke |
189 |
strcat( simnfo->sampleName, ".dump" ); |
385 |
mmeineke |
184 |
} |
386 |
mmeineke |
189 |
} |
387 |
|
|
|
388 |
|
|
strcpy( simnfo->statusName, inFileName ); |
389 |
|
|
nameLength = strlen( simnfo->statusName ); |
390 |
|
|
endTest = &(simnfo->statusName[nameLength - 5]); |
391 |
|
|
if( !strcmp( endTest, ".bass" ) ){ |
392 |
|
|
strcpy( endTest, ".stat" ); |
393 |
|
|
} |
394 |
|
|
else if( !strcmp( endTest, ".BASS" ) ){ |
395 |
|
|
strcpy( endTest, ".stat" ); |
396 |
|
|
} |
397 |
|
|
else{ |
398 |
|
|
endTest = &(simnfo->statusName[nameLength - 4]); |
399 |
|
|
if( !strcmp( endTest, ".bss" ) ){ |
400 |
mmeineke |
184 |
strcpy( endTest, ".stat" ); |
401 |
|
|
} |
402 |
mmeineke |
189 |
else if( !strcmp( endTest, ".mdl" ) ){ |
403 |
mmeineke |
184 |
strcpy( endTest, ".stat" ); |
404 |
|
|
} |
405 |
|
|
else{ |
406 |
mmeineke |
189 |
strcat( simnfo->statusName, ".stat" ); |
407 |
mmeineke |
184 |
} |
408 |
mmeineke |
189 |
} |
409 |
|
|
|
410 |
mmeineke |
184 |
#ifdef IS_MPI |
411 |
mmeineke |
189 |
} |
412 |
mmeineke |
184 |
#endif // is_mpi |
413 |
mmeineke |
189 |
|
414 |
mmeineke |
10 |
// set the status, sample, and themal kick times |
415 |
mmeineke |
189 |
|
416 |
mmeineke |
10 |
if( the_globals->haveSampleTime() ){ |
417 |
chuckv |
124 |
simnfo->sampleTime = the_globals->getSampleTime(); |
418 |
mmeineke |
10 |
simnfo->statusTime = simnfo->sampleTime; |
419 |
|
|
simnfo->thermalTime = simnfo->sampleTime; |
420 |
|
|
} |
421 |
|
|
else{ |
422 |
chuckv |
124 |
simnfo->sampleTime = the_globals->getRunTime(); |
423 |
mmeineke |
10 |
simnfo->statusTime = simnfo->sampleTime; |
424 |
|
|
simnfo->thermalTime = simnfo->sampleTime; |
425 |
|
|
} |
426 |
|
|
|
427 |
|
|
if( the_globals->haveStatusTime() ){ |
428 |
|
|
simnfo->statusTime = the_globals->getStatusTime(); |
429 |
|
|
} |
430 |
|
|
|
431 |
|
|
if( the_globals->haveThermalTime() ){ |
432 |
|
|
simnfo->thermalTime = the_globals->getThermalTime(); |
433 |
|
|
} |
434 |
|
|
|
435 |
|
|
// check for the temperature set flag |
436 |
|
|
|
437 |
|
|
if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet(); |
438 |
chuckv |
124 |
|
439 |
|
|
|
440 |
mmeineke |
10 |
// make the longe range forces and the integrator |
441 |
chuckv |
124 |
|
442 |
mmeineke |
10 |
new AllLong( simnfo ); |
443 |
chuckv |
124 |
|
444 |
mmeineke |
10 |
if( !strcmp( force_field, "TraPPE" ) ) new Verlet( *simnfo ); |
445 |
|
|
if( !strcmp( force_field, "DipoleTest" ) ) new Symplectic( simnfo ); |
446 |
|
|
if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo ); |
447 |
|
|
} |
448 |
|
|
|
449 |
|
|
void SimSetup::makeAtoms( void ){ |
450 |
chuckv |
124 |
|
451 |
mmeineke |
10 |
int i, j, k, index; |
452 |
|
|
double ux, uy, uz, uSqr, u; |
453 |
|
|
AtomStamp* current_atom; |
454 |
|
|
DirectionalAtom* dAtom; |
455 |
mmeineke |
117 |
int molIndex, molStart, molEnd, nMemb; |
456 |
mmeineke |
10 |
|
457 |
chuckv |
124 |
|
458 |
mmeineke |
117 |
molIndex = 0; |
459 |
mmeineke |
10 |
index = 0; |
460 |
|
|
for( i=0; i<n_components; i++ ){ |
461 |
chuckv |
124 |
|
462 |
mmeineke |
10 |
for( j=0; j<components_nmol[i]; j++ ){ |
463 |
chuckv |
124 |
|
464 |
mmeineke |
117 |
molStart = index; |
465 |
|
|
nMemb = comp_stamps[i]->getNAtoms(); |
466 |
mmeineke |
10 |
for( k=0; k<comp_stamps[i]->getNAtoms(); k++ ){ |
467 |
chuckv |
124 |
|
468 |
mmeineke |
10 |
current_atom = comp_stamps[i]->getAtom( k ); |
469 |
chuckv |
124 |
if( current_atom->haveOrientation() ){ |
470 |
mmeineke |
10 |
|
471 |
mmeineke |
145 |
dAtom = new DirectionalAtom(index); |
472 |
mmeineke |
10 |
simnfo->n_oriented++; |
473 |
|
|
the_atoms[index] = dAtom; |
474 |
chuckv |
124 |
|
475 |
mmeineke |
10 |
ux = current_atom->getOrntX(); |
476 |
|
|
uy = current_atom->getOrntY(); |
477 |
|
|
uz = current_atom->getOrntZ(); |
478 |
chuckv |
124 |
|
479 |
mmeineke |
10 |
uSqr = (ux * ux) + (uy * uy) + (uz * uz); |
480 |
chuckv |
124 |
|
481 |
mmeineke |
10 |
u = sqrt( uSqr ); |
482 |
|
|
ux = ux / u; |
483 |
|
|
uy = uy / u; |
484 |
|
|
uz = uz / u; |
485 |
chuckv |
124 |
|
486 |
mmeineke |
10 |
dAtom->setSUx( ux ); |
487 |
|
|
dAtom->setSUy( uy ); |
488 |
|
|
dAtom->setSUz( uz ); |
489 |
|
|
} |
490 |
|
|
else{ |
491 |
mmeineke |
145 |
the_atoms[index] = new GeneralAtom(index); |
492 |
mmeineke |
10 |
} |
493 |
|
|
the_atoms[index]->setType( current_atom->getType() ); |
494 |
|
|
the_atoms[index]->setIndex( index ); |
495 |
chuckv |
124 |
|
496 |
mmeineke |
10 |
// increment the index and repeat; |
497 |
|
|
index++; |
498 |
|
|
} |
499 |
chuckv |
124 |
|
500 |
mmeineke |
117 |
molEnd = index -1; |
501 |
|
|
the_molecules[molIndex].setNMembers( nMemb ); |
502 |
|
|
the_molecules[molIndex].setStartAtom( molStart ); |
503 |
|
|
the_molecules[molIndex].setEndAtom( molEnd ); |
504 |
|
|
molIndex++; |
505 |
|
|
|
506 |
mmeineke |
10 |
} |
507 |
|
|
} |
508 |
chuckv |
124 |
|
509 |
mmeineke |
10 |
the_ff->initializeAtoms(); |
510 |
|
|
} |
511 |
|
|
|
512 |
|
|
void SimSetup::makeBonds( void ){ |
513 |
|
|
|
514 |
|
|
int i, j, k, index, offset; |
515 |
|
|
bond_pair* the_bonds; |
516 |
|
|
BondStamp* current_bond; |
517 |
|
|
|
518 |
|
|
the_bonds = new bond_pair[tot_bonds]; |
519 |
|
|
index = 0; |
520 |
|
|
offset = 0; |
521 |
|
|
for( i=0; i<n_components; i++ ){ |
522 |
chuckv |
124 |
|
523 |
mmeineke |
10 |
for( j=0; j<components_nmol[i]; j++ ){ |
524 |
chuckv |
124 |
|
525 |
mmeineke |
10 |
for( k=0; k<comp_stamps[i]->getNBonds(); k++ ){ |
526 |
chuckv |
124 |
|
527 |
mmeineke |
10 |
current_bond = comp_stamps[i]->getBond( k ); |
528 |
|
|
the_bonds[index].a = current_bond->getA() + offset; |
529 |
|
|
the_bonds[index].b = current_bond->getB() + offset; |
530 |
|
|
|
531 |
|
|
the_excludes[index].i = the_bonds[index].a; |
532 |
|
|
the_excludes[index].j = the_bonds[index].b; |
533 |
|
|
|
534 |
|
|
// increment the index and repeat; |
535 |
|
|
index++; |
536 |
|
|
} |
537 |
|
|
offset += comp_stamps[i]->getNAtoms(); |
538 |
|
|
} |
539 |
|
|
} |
540 |
chuckv |
124 |
|
541 |
mmeineke |
10 |
the_ff->initializeBonds( the_bonds ); |
542 |
|
|
} |
543 |
|
|
|
544 |
|
|
void SimSetup::makeBends( void ){ |
545 |
|
|
|
546 |
|
|
int i, j, k, index, offset; |
547 |
|
|
bend_set* the_bends; |
548 |
|
|
BendStamp* current_bend; |
549 |
|
|
|
550 |
|
|
the_bends = new bend_set[tot_bends]; |
551 |
|
|
index = 0; |
552 |
|
|
offset = 0; |
553 |
|
|
for( i=0; i<n_components; i++ ){ |
554 |
chuckv |
124 |
|
555 |
mmeineke |
10 |
for( j=0; j<components_nmol[i]; j++ ){ |
556 |
chuckv |
124 |
|
557 |
mmeineke |
10 |
for( k=0; k<comp_stamps[i]->getNBends(); k++ ){ |
558 |
chuckv |
124 |
|
559 |
mmeineke |
10 |
current_bend = comp_stamps[i]->getBend( k ); |
560 |
|
|
the_bends[index].a = current_bend->getA() + offset; |
561 |
|
|
the_bends[index].b = current_bend->getB() + offset; |
562 |
|
|
the_bends[index].c = current_bend->getC() + offset; |
563 |
|
|
|
564 |
|
|
the_excludes[index + tot_bonds].i = the_bends[index].a; |
565 |
|
|
the_excludes[index + tot_bonds].j = the_bends[index].c; |
566 |
|
|
|
567 |
|
|
// increment the index and repeat; |
568 |
|
|
index++; |
569 |
|
|
} |
570 |
|
|
offset += comp_stamps[i]->getNAtoms(); |
571 |
|
|
} |
572 |
|
|
} |
573 |
chuckv |
124 |
|
574 |
mmeineke |
10 |
the_ff->initializeBends( the_bends ); |
575 |
|
|
} |
576 |
|
|
|
577 |
|
|
void SimSetup::makeTorsions( void ){ |
578 |
|
|
|
579 |
|
|
int i, j, k, index, offset; |
580 |
|
|
torsion_set* the_torsions; |
581 |
|
|
TorsionStamp* current_torsion; |
582 |
|
|
|
583 |
|
|
the_torsions = new torsion_set[tot_torsions]; |
584 |
|
|
index = 0; |
585 |
|
|
offset = 0; |
586 |
|
|
for( i=0; i<n_components; i++ ){ |
587 |
chuckv |
124 |
|
588 |
mmeineke |
10 |
for( j=0; j<components_nmol[i]; j++ ){ |
589 |
chuckv |
124 |
|
590 |
mmeineke |
10 |
for( k=0; k<comp_stamps[i]->getNTorsions(); k++ ){ |
591 |
chuckv |
124 |
|
592 |
mmeineke |
10 |
current_torsion = comp_stamps[i]->getTorsion( k ); |
593 |
|
|
the_torsions[index].a = current_torsion->getA() + offset; |
594 |
|
|
the_torsions[index].b = current_torsion->getB() + offset; |
595 |
|
|
the_torsions[index].c = current_torsion->getC() + offset; |
596 |
|
|
the_torsions[index].d = current_torsion->getD() + offset; |
597 |
|
|
|
598 |
|
|
the_excludes[index + tot_bonds + tot_bends].i = the_torsions[index].a; |
599 |
|
|
the_excludes[index + tot_bonds + tot_bends].j = the_torsions[index].d; |
600 |
|
|
|
601 |
|
|
// increment the index and repeat; |
602 |
|
|
index++; |
603 |
|
|
} |
604 |
|
|
offset += comp_stamps[i]->getNAtoms(); |
605 |
|
|
} |
606 |
|
|
} |
607 |
chuckv |
124 |
|
608 |
mmeineke |
10 |
the_ff->initializeTorsions( the_torsions ); |
609 |
|
|
} |
610 |
|
|
|
611 |
|
|
void SimSetup::initFromBass( void ){ |
612 |
|
|
|
613 |
|
|
int i, j, k; |
614 |
|
|
int n_cells; |
615 |
|
|
double cellx, celly, cellz; |
616 |
|
|
double temp1, temp2, temp3; |
617 |
|
|
int n_per_extra; |
618 |
|
|
int n_extra; |
619 |
|
|
int have_extra, done; |
620 |
|
|
|
621 |
|
|
temp1 = (double)tot_nmol / 4.0; |
622 |
|
|
temp2 = pow( temp1, ( 1.0 / 3.0 ) ); |
623 |
|
|
temp3 = ceil( temp2 ); |
624 |
|
|
|
625 |
|
|
have_extra =0; |
626 |
|
|
if( temp2 < temp3 ){ // we have a non-complete lattice |
627 |
|
|
have_extra =1; |
628 |
|
|
|
629 |
|
|
n_cells = (int)temp3 - 1; |
630 |
|
|
cellx = simnfo->box_x / temp3; |
631 |
|
|
celly = simnfo->box_y / temp3; |
632 |
|
|
cellz = simnfo->box_z / temp3; |
633 |
|
|
n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells ); |
634 |
|
|
temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) ); |
635 |
|
|
n_per_extra = (int)ceil( temp1 ); |
636 |
|
|
|
637 |
|
|
if( n_per_extra > 4){ |
638 |
mmeineke |
189 |
sprintf( painCave.errMsg, |
639 |
|
|
"SimSetup error. There has been an error in constructing" |
640 |
|
|
" the non-complete lattice.\n" ); |
641 |
|
|
painCave.isFatal = 1; |
642 |
|
|
simError(); |
643 |
mmeineke |
10 |
} |
644 |
|
|
} |
645 |
|
|
else{ |
646 |
|
|
n_cells = (int)temp3; |
647 |
|
|
cellx = simnfo->box_x / temp3; |
648 |
|
|
celly = simnfo->box_y / temp3; |
649 |
|
|
cellz = simnfo->box_z / temp3; |
650 |
|
|
} |
651 |
chuckv |
124 |
|
652 |
mmeineke |
10 |
current_mol = 0; |
653 |
|
|
current_comp_mol = 0; |
654 |
|
|
current_comp = 0; |
655 |
|
|
current_atom_ndx = 0; |
656 |
chuckv |
124 |
|
657 |
mmeineke |
10 |
for( i=0; i < n_cells ; i++ ){ |
658 |
|
|
for( j=0; j < n_cells; j++ ){ |
659 |
|
|
for( k=0; k < n_cells; k++ ){ |
660 |
chuckv |
124 |
|
661 |
mmeineke |
10 |
makeElement( i * cellx, |
662 |
|
|
j * celly, |
663 |
|
|
k * cellz ); |
664 |
chuckv |
124 |
|
665 |
mmeineke |
10 |
makeElement( i * cellx + 0.5 * cellx, |
666 |
|
|
j * celly + 0.5 * celly, |
667 |
|
|
k * cellz ); |
668 |
chuckv |
124 |
|
669 |
mmeineke |
10 |
makeElement( i * cellx, |
670 |
|
|
j * celly + 0.5 * celly, |
671 |
|
|
k * cellz + 0.5 * cellz ); |
672 |
chuckv |
124 |
|
673 |
mmeineke |
10 |
makeElement( i * cellx + 0.5 * cellx, |
674 |
|
|
j * celly, |
675 |
|
|
k * cellz + 0.5 * cellz ); |
676 |
|
|
} |
677 |
|
|
} |
678 |
|
|
} |
679 |
|
|
|
680 |
|
|
if( have_extra ){ |
681 |
|
|
done = 0; |
682 |
chuckv |
124 |
|
683 |
mmeineke |
10 |
int start_ndx; |
684 |
|
|
for( i=0; i < (n_cells+1) && !done; i++ ){ |
685 |
|
|
for( j=0; j < (n_cells+1) && !done; j++ ){ |
686 |
chuckv |
124 |
|
687 |
mmeineke |
10 |
if( i < n_cells ){ |
688 |
chuckv |
124 |
|
689 |
mmeineke |
10 |
if( j < n_cells ){ |
690 |
|
|
start_ndx = n_cells; |
691 |
|
|
} |
692 |
|
|
else start_ndx = 0; |
693 |
|
|
} |
694 |
|
|
else start_ndx = 0; |
695 |
chuckv |
124 |
|
696 |
mmeineke |
10 |
for( k=start_ndx; k < (n_cells+1) && !done; k++ ){ |
697 |
chuckv |
124 |
|
698 |
mmeineke |
10 |
makeElement( i * cellx, |
699 |
|
|
j * celly, |
700 |
|
|
k * cellz ); |
701 |
|
|
done = ( current_mol >= tot_nmol ); |
702 |
chuckv |
124 |
|
703 |
mmeineke |
10 |
if( !done && n_per_extra > 1 ){ |
704 |
|
|
makeElement( i * cellx + 0.5 * cellx, |
705 |
|
|
j * celly + 0.5 * celly, |
706 |
|
|
k * cellz ); |
707 |
|
|
done = ( current_mol >= tot_nmol ); |
708 |
|
|
} |
709 |
chuckv |
124 |
|
710 |
mmeineke |
10 |
if( !done && n_per_extra > 2){ |
711 |
|
|
makeElement( i * cellx, |
712 |
|
|
j * celly + 0.5 * celly, |
713 |
|
|
k * cellz + 0.5 * cellz ); |
714 |
|
|
done = ( current_mol >= tot_nmol ); |
715 |
|
|
} |
716 |
chuckv |
124 |
|
717 |
mmeineke |
10 |
if( !done && n_per_extra > 3){ |
718 |
|
|
makeElement( i * cellx + 0.5 * cellx, |
719 |
|
|
j * celly, |
720 |
|
|
k * cellz + 0.5 * cellz ); |
721 |
|
|
done = ( current_mol >= tot_nmol ); |
722 |
|
|
} |
723 |
|
|
} |
724 |
|
|
} |
725 |
|
|
} |
726 |
|
|
} |
727 |
chuckv |
124 |
|
728 |
|
|
|
729 |
mmeineke |
10 |
for( i=0; i<simnfo->n_atoms; i++ ){ |
730 |
|
|
simnfo->atoms[i]->set_vx( 0.0 ); |
731 |
|
|
simnfo->atoms[i]->set_vy( 0.0 ); |
732 |
|
|
simnfo->atoms[i]->set_vz( 0.0 ); |
733 |
|
|
} |
734 |
|
|
} |
735 |
|
|
|
736 |
|
|
void SimSetup::makeElement( double x, double y, double z ){ |
737 |
|
|
|
738 |
|
|
int k; |
739 |
|
|
AtomStamp* current_atom; |
740 |
|
|
DirectionalAtom* dAtom; |
741 |
|
|
double rotMat[3][3]; |
742 |
|
|
|
743 |
|
|
for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){ |
744 |
chuckv |
124 |
|
745 |
mmeineke |
10 |
current_atom = comp_stamps[current_comp]->getAtom( k ); |
746 |
|
|
if( !current_atom->havePosition() ){ |
747 |
mmeineke |
189 |
sprintf( painCave.errMsg, |
748 |
|
|
"SimSetup:initFromBass error.\n" |
749 |
|
|
"\tComponent %s, atom %s does not have a position specified.\n" |
750 |
|
|
"\tThe initialization routine is unable to give a start" |
751 |
|
|
" position.\n", |
752 |
|
|
comp_stamps[current_comp]->getID(), |
753 |
|
|
current_atom->getType() ); |
754 |
|
|
painCave.isFatal = 1; |
755 |
|
|
simError(); |
756 |
mmeineke |
10 |
} |
757 |
chuckv |
124 |
|
758 |
mmeineke |
10 |
the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() ); |
759 |
|
|
the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() ); |
760 |
|
|
the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() ); |
761 |
chuckv |
124 |
|
762 |
mmeineke |
10 |
if( the_atoms[current_atom_ndx]->isDirectional() ){ |
763 |
chuckv |
124 |
|
764 |
mmeineke |
10 |
dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx]; |
765 |
chuckv |
124 |
|
766 |
mmeineke |
10 |
rotMat[0][0] = 1.0; |
767 |
|
|
rotMat[0][1] = 0.0; |
768 |
|
|
rotMat[0][2] = 0.0; |
769 |
|
|
|
770 |
|
|
rotMat[1][0] = 0.0; |
771 |
|
|
rotMat[1][1] = 1.0; |
772 |
|
|
rotMat[1][2] = 0.0; |
773 |
|
|
|
774 |
|
|
rotMat[2][0] = 0.0; |
775 |
|
|
rotMat[2][1] = 0.0; |
776 |
|
|
rotMat[2][2] = 1.0; |
777 |
|
|
|
778 |
|
|
dAtom->setA( rotMat ); |
779 |
|
|
} |
780 |
|
|
|
781 |
|
|
current_atom_ndx++; |
782 |
|
|
} |
783 |
chuckv |
124 |
|
784 |
mmeineke |
10 |
current_mol++; |
785 |
|
|
current_comp_mol++; |
786 |
|
|
|
787 |
|
|
if( current_comp_mol >= components_nmol[current_comp] ){ |
788 |
chuckv |
124 |
|
789 |
mmeineke |
10 |
current_comp_mol = 0; |
790 |
|
|
current_comp++; |
791 |
|
|
} |
792 |
|
|
} |