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 |
chuckv |
124 |
#include "mpiInterface.h" |
10 |
mmeineke |
10 |
|
11 |
|
|
SimSetup::SimSetup(){ |
12 |
|
|
stamps = new MakeStamps(); |
13 |
|
|
globals = new Globals(); |
14 |
|
|
} |
15 |
|
|
|
16 |
|
|
SimSetup::~SimSetup(){ |
17 |
|
|
delete stamps; |
18 |
|
|
delete globals; |
19 |
|
|
} |
20 |
|
|
|
21 |
|
|
void SimSetup::parseFile( char* fileName ){ |
22 |
|
|
|
23 |
|
|
inFileName = fileName; |
24 |
|
|
set_interface_stamps( stamps, globals ); |
25 |
chuckv |
124 |
#ifdef MPI |
26 |
|
|
mpiEventInit(); |
27 |
|
|
#endif |
28 |
mmeineke |
10 |
yacc_BASS( fileName ); |
29 |
chuckv |
124 |
#ifdef MPI |
30 |
|
|
throwMPIEvent(NULL); |
31 |
|
|
#endif |
32 |
|
|
|
33 |
mmeineke |
10 |
} |
34 |
|
|
|
35 |
chuckv |
124 |
#ifdef MPI |
36 |
|
|
void SimSetup::receiveParse(void){ |
37 |
|
|
|
38 |
|
|
set_interface_stamps( stamps, globals ); |
39 |
|
|
mpiEventInit(); |
40 |
|
|
mpiEventLoop(); |
41 |
|
|
|
42 |
|
|
} |
43 |
|
|
#endif |
44 |
|
|
|
45 |
mmeineke |
10 |
void SimSetup::createSim( void ){ |
46 |
|
|
|
47 |
|
|
MakeStamps *the_stamps; |
48 |
|
|
Globals* the_globals; |
49 |
|
|
int i; |
50 |
|
|
|
51 |
|
|
// get the stamps and globals; |
52 |
|
|
the_stamps = stamps; |
53 |
|
|
the_globals = globals; |
54 |
|
|
|
55 |
|
|
// set the easy ones first |
56 |
|
|
simnfo->target_temp = the_globals->getTargetTemp(); |
57 |
|
|
simnfo->dt = the_globals->getDt(); |
58 |
|
|
simnfo->run_time = the_globals->getRunTime(); |
59 |
|
|
|
60 |
|
|
// get the ones we know are there, yet still may need some work. |
61 |
|
|
n_components = the_globals->getNComponents(); |
62 |
|
|
strcpy( force_field, the_globals->getForceField() ); |
63 |
|
|
strcpy( ensemble, the_globals->getEnsemble() ); |
64 |
chuckv |
124 |
|
65 |
mmeineke |
10 |
if( !strcmp( force_field, "TraPPE" ) ) the_ff = new TraPPEFF(); |
66 |
|
|
else if( !strcmp( force_field, "DipoleTest" ) ) the_ff = new DipoleTestFF(); |
67 |
|
|
else if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF(); |
68 |
|
|
else{ |
69 |
chuckv |
124 |
std::cerr<< "SimSetup Error. Unrecognized force field -> " |
70 |
mmeineke |
10 |
<< force_field << "\n"; |
71 |
|
|
exit(8); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
// get the components and calculate the tot_nMol and indvidual n_mol |
75 |
|
|
the_components = the_globals->getComponents(); |
76 |
|
|
components_nmol = new int[n_components]; |
77 |
|
|
comp_stamps = new MoleculeStamp*[n_components]; |
78 |
chuckv |
124 |
|
79 |
mmeineke |
10 |
if( !the_globals->haveNMol() ){ |
80 |
chuckv |
124 |
// we don't have the total number of molecules, so we assume it is |
81 |
mmeineke |
10 |
// given in each component |
82 |
|
|
|
83 |
|
|
tot_nmol = 0; |
84 |
|
|
for( i=0; i<n_components; i++ ){ |
85 |
chuckv |
124 |
|
86 |
mmeineke |
10 |
if( !the_components[i]->haveNMol() ){ |
87 |
|
|
// we have a problem |
88 |
|
|
std::cerr << "SimSetup Error. No global NMol or component NMol" |
89 |
|
|
<< " given. Cannot calculate the number of atoms.\n"; |
90 |
|
|
exit( 8 ); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
tot_nmol += the_components[i]->getNMol(); |
94 |
|
|
components_nmol[i] = the_components[i]->getNMol(); |
95 |
|
|
} |
96 |
|
|
} |
97 |
|
|
else{ |
98 |
|
|
std::cerr << "NOT A SUPPORTED FEATURE\n"; |
99 |
chuckv |
124 |
|
100 |
mmeineke |
10 |
// tot_nmol = the_globals->getNMol(); |
101 |
chuckv |
124 |
|
102 |
mmeineke |
10 |
// //we have the total number of molecules, now we check for molfractions |
103 |
|
|
// for( i=0; i<n_components; i++ ){ |
104 |
chuckv |
124 |
|
105 |
mmeineke |
10 |
// if( !the_components[i]->haveMolFraction() ){ |
106 |
chuckv |
124 |
|
107 |
mmeineke |
10 |
// if( !the_components[i]->haveNMol() ){ |
108 |
|
|
// //we have a problem |
109 |
|
|
// std::cerr << "SimSetup error. Neither molFraction nor " |
110 |
|
|
// << " nMol was given in component |
111 |
|
|
|
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
// make an array of molecule stamps that match the components used. |
115 |
|
|
|
116 |
|
|
for( i=0; i<n_components; i++ ){ |
117 |
|
|
|
118 |
chuckv |
124 |
comp_stamps[i] = |
119 |
mmeineke |
10 |
the_stamps->getMolecule( the_components[i]->getType() ); |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
|
123 |
chuckv |
124 |
|
124 |
mmeineke |
10 |
// caclulate the number of atoms, bonds, bends and torsions |
125 |
|
|
|
126 |
|
|
tot_atoms = 0; |
127 |
|
|
tot_bonds = 0; |
128 |
|
|
tot_bends = 0; |
129 |
|
|
tot_torsions = 0; |
130 |
|
|
for( i=0; i<n_components; i++ ){ |
131 |
chuckv |
124 |
|
132 |
mmeineke |
10 |
tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms(); |
133 |
|
|
tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds(); |
134 |
|
|
tot_bends += components_nmol[i] * comp_stamps[i]->getNBends(); |
135 |
|
|
tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions(); |
136 |
|
|
} |
137 |
chuckv |
124 |
|
138 |
mmeineke |
10 |
tot_SRI = tot_bonds + tot_bends + tot_torsions; |
139 |
chuckv |
124 |
|
140 |
mmeineke |
10 |
simnfo->n_atoms = tot_atoms; |
141 |
|
|
simnfo->n_bonds = tot_bonds; |
142 |
|
|
simnfo->n_bends = tot_bends; |
143 |
|
|
simnfo->n_torsions = tot_torsions; |
144 |
|
|
simnfo->n_SRI = tot_SRI; |
145 |
|
|
|
146 |
|
|
// create the atom and short range interaction arrays |
147 |
chuckv |
124 |
|
148 |
mmeineke |
10 |
the_atoms = new Atom*[tot_atoms]; |
149 |
mmeineke |
113 |
the_molecules = new Molecule[tot_nmol]; |
150 |
chuckv |
124 |
|
151 |
|
|
|
152 |
mmeineke |
10 |
if( tot_SRI ){ |
153 |
|
|
the_sris = new SRI*[tot_SRI]; |
154 |
|
|
the_excludes = new ex_pair[tot_SRI]; |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
// set the arrays into the SimInfo object |
158 |
|
|
|
159 |
|
|
simnfo->atoms = the_atoms; |
160 |
|
|
simnfo->sr_interactions = the_sris; |
161 |
|
|
simnfo->n_exclude = tot_SRI; |
162 |
|
|
simnfo->excludes = the_excludes; |
163 |
|
|
|
164 |
chuckv |
124 |
|
165 |
mmeineke |
10 |
// initialize the arrays |
166 |
chuckv |
124 |
|
167 |
mmeineke |
10 |
the_ff->setSimInfo( simnfo ); |
168 |
chuckv |
124 |
|
169 |
mmeineke |
10 |
makeAtoms(); |
170 |
|
|
|
171 |
|
|
if( tot_bonds ){ |
172 |
|
|
makeBonds(); |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
if( tot_bends ){ |
176 |
|
|
makeBends(); |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
if( tot_torsions ){ |
180 |
|
|
makeTorsions(); |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
// makeMolecules(); |
184 |
|
|
|
185 |
|
|
// get some of the tricky things that may still be in the globals |
186 |
|
|
|
187 |
|
|
if( simnfo->n_dipoles ){ |
188 |
|
|
|
189 |
|
|
if( !the_globals->haveRRF() ){ |
190 |
|
|
std::cerr << "SimSetup Error, system has dipoles, but no rRF was set.\n"; |
191 |
|
|
exit(8); |
192 |
|
|
} |
193 |
|
|
if( !the_globals->haveDielectric() ){ |
194 |
|
|
std::cerr << "SimSetup Error, system has dipoles, but no" |
195 |
|
|
<< " dielectric was set.\n"; |
196 |
|
|
exit(8); |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
simnfo->rRF = the_globals->getRRF(); |
200 |
|
|
simnfo->dielectric = the_globals->getDielectric(); |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
if( the_globals->haveBox() ){ |
204 |
|
|
simnfo->box_x = the_globals->getBox(); |
205 |
|
|
simnfo->box_y = the_globals->getBox(); |
206 |
|
|
simnfo->box_z = the_globals->getBox(); |
207 |
|
|
} |
208 |
|
|
else if( the_globals->haveDensity() ){ |
209 |
chuckv |
124 |
|
210 |
mmeineke |
10 |
double vol; |
211 |
|
|
vol = (double)tot_nmol / the_globals->getDensity(); |
212 |
|
|
simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) ); |
213 |
|
|
simnfo->box_y = simnfo->box_x; |
214 |
|
|
simnfo->box_z = simnfo->box_x; |
215 |
|
|
} |
216 |
|
|
else{ |
217 |
|
|
if( !the_globals->haveBoxX() ){ |
218 |
|
|
std::cerr << "SimSetup error, no periodic BoxX size given.\n"; |
219 |
|
|
exit(8); |
220 |
|
|
} |
221 |
|
|
simnfo->box_x = the_globals->getBoxX(); |
222 |
|
|
|
223 |
|
|
if( !the_globals->haveBoxY() ){ |
224 |
|
|
std::cerr << "SimSetup error, no periodic BoxY size given.\n"; |
225 |
|
|
exit(8); |
226 |
|
|
} |
227 |
|
|
simnfo->box_y = the_globals->getBoxY(); |
228 |
|
|
|
229 |
|
|
if( !the_globals->haveBoxZ() ){ |
230 |
|
|
std::cerr << "SimSetup error, no periodic BoxZ size given.\n"; |
231 |
|
|
exit(8); |
232 |
|
|
} |
233 |
|
|
simnfo->box_z = the_globals->getBoxZ(); |
234 |
|
|
} |
235 |
|
|
|
236 |
chuckv |
124 |
|
237 |
|
|
// if( the_globals->haveInitialConfig() ){ |
238 |
|
|
// InitializeFromFile* fileInit; |
239 |
|
|
// fileInit = new InitializeFromFile( the_globals->getInitialConfig() ); |
240 |
|
|
|
241 |
|
|
// fileInit->read_xyz( simnfo ); // default velocities on |
242 |
|
|
|
243 |
|
|
// delete fileInit; |
244 |
|
|
// } |
245 |
|
|
// else{ |
246 |
|
|
|
247 |
mmeineke |
10 |
initFromBass(); |
248 |
|
|
|
249 |
|
|
|
250 |
chuckv |
124 |
// } |
251 |
|
|
|
252 |
|
|
// if( the_globals->haveFinalConfig() ){ |
253 |
|
|
// strcpy( simnfo->finalName, the_globals->getFinalConfig() ); |
254 |
|
|
// } |
255 |
|
|
// else{ |
256 |
|
|
// strcpy( simnfo->finalName, inFileName ); |
257 |
|
|
// char* endTest; |
258 |
|
|
// int nameLength = strlen( simnfo->finalName ); |
259 |
|
|
// endTest = &(simnfo->finalName[nameLength - 5]); |
260 |
|
|
// if( !strcmp( endTest, ".bass" ) ){ |
261 |
|
|
// strcpy( endTest, ".eor" ); |
262 |
|
|
// } |
263 |
|
|
// else if( !strcmp( endTest, ".BASS" ) ){ |
264 |
|
|
// strcpy( endTest, ".eor" ); |
265 |
|
|
// } |
266 |
|
|
// else{ |
267 |
|
|
// endTest = &(simnfo->finalName[nameLength - 4]); |
268 |
|
|
// if( !strcmp( endTest, ".bss" ) ){ |
269 |
|
|
// strcpy( endTest, ".eor" ); |
270 |
|
|
// } |
271 |
|
|
// else if( !strcmp( endTest, ".mdl" ) ){ |
272 |
|
|
// strcpy( endTest, ".eor" ); |
273 |
|
|
// } |
274 |
|
|
// else{ |
275 |
|
|
// strcat( simnfo->finalName, ".eor" ); |
276 |
|
|
// } |
277 |
|
|
// } |
278 |
|
|
// } |
279 |
|
|
|
280 |
|
|
// // make the sample and status out names |
281 |
|
|
|
282 |
|
|
// strcpy( simnfo->sampleName, inFileName ); |
283 |
|
|
// char* endTest; |
284 |
|
|
// int nameLength = strlen( simnfo->sampleName ); |
285 |
|
|
// endTest = &(simnfo->sampleName[nameLength - 5]); |
286 |
|
|
// if( !strcmp( endTest, ".bass" ) ){ |
287 |
|
|
// strcpy( endTest, ".dump" ); |
288 |
|
|
// } |
289 |
|
|
// else if( !strcmp( endTest, ".BASS" ) ){ |
290 |
|
|
// strcpy( endTest, ".dump" ); |
291 |
|
|
// } |
292 |
|
|
// else{ |
293 |
|
|
// endTest = &(simnfo->sampleName[nameLength - 4]); |
294 |
|
|
// if( !strcmp( endTest, ".bss" ) ){ |
295 |
|
|
// strcpy( endTest, ".dump" ); |
296 |
|
|
// } |
297 |
|
|
// else if( !strcmp( endTest, ".mdl" ) ){ |
298 |
|
|
// strcpy( endTest, ".dump" ); |
299 |
|
|
// } |
300 |
|
|
// else{ |
301 |
|
|
// strcat( simnfo->sampleName, ".dump" ); |
302 |
|
|
// } |
303 |
|
|
// } |
304 |
|
|
|
305 |
|
|
// strcpy( simnfo->statusName, inFileName ); |
306 |
|
|
// nameLength = strlen( simnfo->statusName ); |
307 |
|
|
// endTest = &(simnfo->statusName[nameLength - 5]); |
308 |
|
|
// if( !strcmp( endTest, ".bass" ) ){ |
309 |
|
|
// strcpy( endTest, ".stat" ); |
310 |
|
|
// } |
311 |
|
|
// else if( !strcmp( endTest, ".BASS" ) ){ |
312 |
|
|
// strcpy( endTest, ".stat" ); |
313 |
|
|
// } |
314 |
|
|
// else{ |
315 |
|
|
// endTest = &(simnfo->statusName[nameLength - 4]); |
316 |
|
|
// if( !strcmp( endTest, ".bss" ) ){ |
317 |
|
|
// strcpy( endTest, ".stat" ); |
318 |
|
|
// } |
319 |
|
|
// else if( !strcmp( endTest, ".mdl" ) ){ |
320 |
|
|
// strcpy( endTest, ".stat" ); |
321 |
|
|
// } |
322 |
|
|
// else{ |
323 |
|
|
// strcat( simnfo->statusName, ".stat" ); |
324 |
|
|
// } |
325 |
|
|
// } |
326 |
|
|
|
327 |
|
|
|
328 |
mmeineke |
10 |
// set the status, sample, and themal kick times |
329 |
|
|
|
330 |
|
|
if( the_globals->haveSampleTime() ){ |
331 |
chuckv |
124 |
simnfo->sampleTime = the_globals->getSampleTime(); |
332 |
mmeineke |
10 |
simnfo->statusTime = simnfo->sampleTime; |
333 |
|
|
simnfo->thermalTime = simnfo->sampleTime; |
334 |
|
|
} |
335 |
|
|
else{ |
336 |
chuckv |
124 |
simnfo->sampleTime = the_globals->getRunTime(); |
337 |
mmeineke |
10 |
simnfo->statusTime = simnfo->sampleTime; |
338 |
|
|
simnfo->thermalTime = simnfo->sampleTime; |
339 |
|
|
} |
340 |
|
|
|
341 |
|
|
if( the_globals->haveStatusTime() ){ |
342 |
|
|
simnfo->statusTime = the_globals->getStatusTime(); |
343 |
|
|
} |
344 |
|
|
|
345 |
|
|
if( the_globals->haveThermalTime() ){ |
346 |
|
|
simnfo->thermalTime = the_globals->getThermalTime(); |
347 |
|
|
} |
348 |
|
|
|
349 |
|
|
// check for the temperature set flag |
350 |
|
|
|
351 |
|
|
if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet(); |
352 |
chuckv |
124 |
|
353 |
|
|
|
354 |
mmeineke |
10 |
// make the longe range forces and the integrator |
355 |
chuckv |
124 |
|
356 |
mmeineke |
10 |
new AllLong( simnfo ); |
357 |
chuckv |
124 |
|
358 |
mmeineke |
10 |
if( !strcmp( force_field, "TraPPE" ) ) new Verlet( *simnfo ); |
359 |
|
|
if( !strcmp( force_field, "DipoleTest" ) ) new Symplectic( simnfo ); |
360 |
|
|
if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo ); |
361 |
|
|
} |
362 |
|
|
|
363 |
|
|
void SimSetup::makeAtoms( void ){ |
364 |
chuckv |
124 |
|
365 |
mmeineke |
10 |
int i, j, k, index; |
366 |
|
|
double ux, uy, uz, uSqr, u; |
367 |
|
|
AtomStamp* current_atom; |
368 |
|
|
DirectionalAtom* dAtom; |
369 |
mmeineke |
117 |
int molIndex, molStart, molEnd, nMemb; |
370 |
mmeineke |
10 |
|
371 |
chuckv |
124 |
|
372 |
mmeineke |
117 |
molIndex = 0; |
373 |
mmeineke |
10 |
index = 0; |
374 |
|
|
for( i=0; i<n_components; i++ ){ |
375 |
chuckv |
124 |
|
376 |
mmeineke |
10 |
for( j=0; j<components_nmol[i]; j++ ){ |
377 |
chuckv |
124 |
|
378 |
mmeineke |
117 |
molStart = index; |
379 |
|
|
nMemb = comp_stamps[i]->getNAtoms(); |
380 |
mmeineke |
10 |
for( k=0; k<comp_stamps[i]->getNAtoms(); k++ ){ |
381 |
chuckv |
124 |
|
382 |
mmeineke |
10 |
current_atom = comp_stamps[i]->getAtom( k ); |
383 |
chuckv |
124 |
if( current_atom->haveOrientation() ){ |
384 |
mmeineke |
10 |
|
385 |
|
|
dAtom = new DirectionalAtom; |
386 |
|
|
simnfo->n_oriented++; |
387 |
|
|
the_atoms[index] = dAtom; |
388 |
chuckv |
124 |
|
389 |
mmeineke |
10 |
ux = current_atom->getOrntX(); |
390 |
|
|
uy = current_atom->getOrntY(); |
391 |
|
|
uz = current_atom->getOrntZ(); |
392 |
chuckv |
124 |
|
393 |
mmeineke |
10 |
uSqr = (ux * ux) + (uy * uy) + (uz * uz); |
394 |
chuckv |
124 |
|
395 |
mmeineke |
10 |
u = sqrt( uSqr ); |
396 |
|
|
ux = ux / u; |
397 |
|
|
uy = uy / u; |
398 |
|
|
uz = uz / u; |
399 |
chuckv |
124 |
|
400 |
mmeineke |
10 |
dAtom->setSUx( ux ); |
401 |
|
|
dAtom->setSUy( uy ); |
402 |
|
|
dAtom->setSUz( uz ); |
403 |
|
|
} |
404 |
|
|
else{ |
405 |
|
|
the_atoms[index] = new GeneralAtom; |
406 |
|
|
} |
407 |
|
|
the_atoms[index]->setType( current_atom->getType() ); |
408 |
|
|
the_atoms[index]->setIndex( index ); |
409 |
chuckv |
124 |
|
410 |
mmeineke |
10 |
// increment the index and repeat; |
411 |
|
|
index++; |
412 |
|
|
} |
413 |
chuckv |
124 |
|
414 |
mmeineke |
117 |
molEnd = index -1; |
415 |
|
|
the_molecules[molIndex].setNMembers( nMemb ); |
416 |
|
|
the_molecules[molIndex].setStartAtom( molStart ); |
417 |
|
|
the_molecules[molIndex].setEndAtom( molEnd ); |
418 |
|
|
molIndex++; |
419 |
|
|
|
420 |
mmeineke |
10 |
} |
421 |
|
|
} |
422 |
chuckv |
124 |
|
423 |
mmeineke |
10 |
the_ff->initializeAtoms(); |
424 |
|
|
} |
425 |
|
|
|
426 |
|
|
void SimSetup::makeBonds( void ){ |
427 |
|
|
|
428 |
|
|
int i, j, k, index, offset; |
429 |
|
|
bond_pair* the_bonds; |
430 |
|
|
BondStamp* current_bond; |
431 |
|
|
|
432 |
|
|
the_bonds = new bond_pair[tot_bonds]; |
433 |
|
|
index = 0; |
434 |
|
|
offset = 0; |
435 |
|
|
for( i=0; i<n_components; i++ ){ |
436 |
chuckv |
124 |
|
437 |
mmeineke |
10 |
for( j=0; j<components_nmol[i]; j++ ){ |
438 |
chuckv |
124 |
|
439 |
mmeineke |
10 |
for( k=0; k<comp_stamps[i]->getNBonds(); k++ ){ |
440 |
chuckv |
124 |
|
441 |
mmeineke |
10 |
current_bond = comp_stamps[i]->getBond( k ); |
442 |
|
|
the_bonds[index].a = current_bond->getA() + offset; |
443 |
|
|
the_bonds[index].b = current_bond->getB() + offset; |
444 |
|
|
|
445 |
|
|
the_excludes[index].i = the_bonds[index].a; |
446 |
|
|
the_excludes[index].j = the_bonds[index].b; |
447 |
|
|
|
448 |
|
|
// increment the index and repeat; |
449 |
|
|
index++; |
450 |
|
|
} |
451 |
|
|
offset += comp_stamps[i]->getNAtoms(); |
452 |
|
|
} |
453 |
|
|
} |
454 |
chuckv |
124 |
|
455 |
mmeineke |
10 |
the_ff->initializeBonds( the_bonds ); |
456 |
|
|
} |
457 |
|
|
|
458 |
|
|
void SimSetup::makeBends( void ){ |
459 |
|
|
|
460 |
|
|
int i, j, k, index, offset; |
461 |
|
|
bend_set* the_bends; |
462 |
|
|
BendStamp* current_bend; |
463 |
|
|
|
464 |
|
|
the_bends = new bend_set[tot_bends]; |
465 |
|
|
index = 0; |
466 |
|
|
offset = 0; |
467 |
|
|
for( i=0; i<n_components; i++ ){ |
468 |
chuckv |
124 |
|
469 |
mmeineke |
10 |
for( j=0; j<components_nmol[i]; j++ ){ |
470 |
chuckv |
124 |
|
471 |
mmeineke |
10 |
for( k=0; k<comp_stamps[i]->getNBends(); k++ ){ |
472 |
chuckv |
124 |
|
473 |
mmeineke |
10 |
current_bend = comp_stamps[i]->getBend( k ); |
474 |
|
|
the_bends[index].a = current_bend->getA() + offset; |
475 |
|
|
the_bends[index].b = current_bend->getB() + offset; |
476 |
|
|
the_bends[index].c = current_bend->getC() + offset; |
477 |
|
|
|
478 |
|
|
the_excludes[index + tot_bonds].i = the_bends[index].a; |
479 |
|
|
the_excludes[index + tot_bonds].j = the_bends[index].c; |
480 |
|
|
|
481 |
|
|
// increment the index and repeat; |
482 |
|
|
index++; |
483 |
|
|
} |
484 |
|
|
offset += comp_stamps[i]->getNAtoms(); |
485 |
|
|
} |
486 |
|
|
} |
487 |
chuckv |
124 |
|
488 |
mmeineke |
10 |
the_ff->initializeBends( the_bends ); |
489 |
|
|
} |
490 |
|
|
|
491 |
|
|
void SimSetup::makeTorsions( void ){ |
492 |
|
|
|
493 |
|
|
int i, j, k, index, offset; |
494 |
|
|
torsion_set* the_torsions; |
495 |
|
|
TorsionStamp* current_torsion; |
496 |
|
|
|
497 |
|
|
the_torsions = new torsion_set[tot_torsions]; |
498 |
|
|
index = 0; |
499 |
|
|
offset = 0; |
500 |
|
|
for( i=0; i<n_components; i++ ){ |
501 |
chuckv |
124 |
|
502 |
mmeineke |
10 |
for( j=0; j<components_nmol[i]; j++ ){ |
503 |
chuckv |
124 |
|
504 |
mmeineke |
10 |
for( k=0; k<comp_stamps[i]->getNTorsions(); k++ ){ |
505 |
chuckv |
124 |
|
506 |
mmeineke |
10 |
current_torsion = comp_stamps[i]->getTorsion( k ); |
507 |
|
|
the_torsions[index].a = current_torsion->getA() + offset; |
508 |
|
|
the_torsions[index].b = current_torsion->getB() + offset; |
509 |
|
|
the_torsions[index].c = current_torsion->getC() + offset; |
510 |
|
|
the_torsions[index].d = current_torsion->getD() + offset; |
511 |
|
|
|
512 |
|
|
the_excludes[index + tot_bonds + tot_bends].i = the_torsions[index].a; |
513 |
|
|
the_excludes[index + tot_bonds + tot_bends].j = the_torsions[index].d; |
514 |
|
|
|
515 |
|
|
// increment the index and repeat; |
516 |
|
|
index++; |
517 |
|
|
} |
518 |
|
|
offset += comp_stamps[i]->getNAtoms(); |
519 |
|
|
} |
520 |
|
|
} |
521 |
chuckv |
124 |
|
522 |
mmeineke |
10 |
the_ff->initializeTorsions( the_torsions ); |
523 |
|
|
} |
524 |
|
|
|
525 |
|
|
void SimSetup::initFromBass( void ){ |
526 |
|
|
|
527 |
|
|
int i, j, k; |
528 |
|
|
int n_cells; |
529 |
|
|
double cellx, celly, cellz; |
530 |
|
|
double temp1, temp2, temp3; |
531 |
|
|
int n_per_extra; |
532 |
|
|
int n_extra; |
533 |
|
|
int have_extra, done; |
534 |
|
|
|
535 |
|
|
temp1 = (double)tot_nmol / 4.0; |
536 |
|
|
temp2 = pow( temp1, ( 1.0 / 3.0 ) ); |
537 |
|
|
temp3 = ceil( temp2 ); |
538 |
|
|
|
539 |
|
|
have_extra =0; |
540 |
|
|
if( temp2 < temp3 ){ // we have a non-complete lattice |
541 |
|
|
have_extra =1; |
542 |
|
|
|
543 |
|
|
n_cells = (int)temp3 - 1; |
544 |
|
|
cellx = simnfo->box_x / temp3; |
545 |
|
|
celly = simnfo->box_y / temp3; |
546 |
|
|
cellz = simnfo->box_z / temp3; |
547 |
|
|
n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells ); |
548 |
|
|
temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) ); |
549 |
|
|
n_per_extra = (int)ceil( temp1 ); |
550 |
|
|
|
551 |
|
|
if( n_per_extra > 4){ |
552 |
|
|
std::cerr << "THere has been an error in constructing the non-complete lattice.\n"; |
553 |
|
|
exit(8); |
554 |
|
|
} |
555 |
|
|
} |
556 |
|
|
else{ |
557 |
|
|
n_cells = (int)temp3; |
558 |
|
|
cellx = simnfo->box_x / temp3; |
559 |
|
|
celly = simnfo->box_y / temp3; |
560 |
|
|
cellz = simnfo->box_z / temp3; |
561 |
|
|
} |
562 |
chuckv |
124 |
|
563 |
mmeineke |
10 |
current_mol = 0; |
564 |
|
|
current_comp_mol = 0; |
565 |
|
|
current_comp = 0; |
566 |
|
|
current_atom_ndx = 0; |
567 |
chuckv |
124 |
|
568 |
mmeineke |
10 |
for( i=0; i < n_cells ; i++ ){ |
569 |
|
|
for( j=0; j < n_cells; j++ ){ |
570 |
|
|
for( k=0; k < n_cells; k++ ){ |
571 |
chuckv |
124 |
|
572 |
mmeineke |
10 |
makeElement( i * cellx, |
573 |
|
|
j * celly, |
574 |
|
|
k * cellz ); |
575 |
chuckv |
124 |
|
576 |
mmeineke |
10 |
makeElement( i * cellx + 0.5 * cellx, |
577 |
|
|
j * celly + 0.5 * celly, |
578 |
|
|
k * cellz ); |
579 |
chuckv |
124 |
|
580 |
mmeineke |
10 |
makeElement( i * cellx, |
581 |
|
|
j * celly + 0.5 * celly, |
582 |
|
|
k * cellz + 0.5 * cellz ); |
583 |
chuckv |
124 |
|
584 |
mmeineke |
10 |
makeElement( i * cellx + 0.5 * cellx, |
585 |
|
|
j * celly, |
586 |
|
|
k * cellz + 0.5 * cellz ); |
587 |
|
|
} |
588 |
|
|
} |
589 |
|
|
} |
590 |
|
|
|
591 |
|
|
if( have_extra ){ |
592 |
|
|
done = 0; |
593 |
chuckv |
124 |
|
594 |
mmeineke |
10 |
int start_ndx; |
595 |
|
|
for( i=0; i < (n_cells+1) && !done; i++ ){ |
596 |
|
|
for( j=0; j < (n_cells+1) && !done; j++ ){ |
597 |
chuckv |
124 |
|
598 |
mmeineke |
10 |
if( i < n_cells ){ |
599 |
chuckv |
124 |
|
600 |
mmeineke |
10 |
if( j < n_cells ){ |
601 |
|
|
start_ndx = n_cells; |
602 |
|
|
} |
603 |
|
|
else start_ndx = 0; |
604 |
|
|
} |
605 |
|
|
else start_ndx = 0; |
606 |
chuckv |
124 |
|
607 |
mmeineke |
10 |
for( k=start_ndx; k < (n_cells+1) && !done; k++ ){ |
608 |
chuckv |
124 |
|
609 |
mmeineke |
10 |
makeElement( i * cellx, |
610 |
|
|
j * celly, |
611 |
|
|
k * cellz ); |
612 |
|
|
done = ( current_mol >= tot_nmol ); |
613 |
chuckv |
124 |
|
614 |
mmeineke |
10 |
if( !done && n_per_extra > 1 ){ |
615 |
|
|
makeElement( i * cellx + 0.5 * cellx, |
616 |
|
|
j * celly + 0.5 * celly, |
617 |
|
|
k * cellz ); |
618 |
|
|
done = ( current_mol >= tot_nmol ); |
619 |
|
|
} |
620 |
chuckv |
124 |
|
621 |
mmeineke |
10 |
if( !done && n_per_extra > 2){ |
622 |
|
|
makeElement( i * cellx, |
623 |
|
|
j * celly + 0.5 * celly, |
624 |
|
|
k * cellz + 0.5 * cellz ); |
625 |
|
|
done = ( current_mol >= tot_nmol ); |
626 |
|
|
} |
627 |
chuckv |
124 |
|
628 |
mmeineke |
10 |
if( !done && n_per_extra > 3){ |
629 |
|
|
makeElement( i * cellx + 0.5 * cellx, |
630 |
|
|
j * celly, |
631 |
|
|
k * cellz + 0.5 * cellz ); |
632 |
|
|
done = ( current_mol >= tot_nmol ); |
633 |
|
|
} |
634 |
|
|
} |
635 |
|
|
} |
636 |
|
|
} |
637 |
|
|
} |
638 |
chuckv |
124 |
|
639 |
|
|
|
640 |
mmeineke |
10 |
for( i=0; i<simnfo->n_atoms; i++ ){ |
641 |
|
|
simnfo->atoms[i]->set_vx( 0.0 ); |
642 |
|
|
simnfo->atoms[i]->set_vy( 0.0 ); |
643 |
|
|
simnfo->atoms[i]->set_vz( 0.0 ); |
644 |
|
|
} |
645 |
|
|
} |
646 |
|
|
|
647 |
|
|
void SimSetup::makeElement( double x, double y, double z ){ |
648 |
|
|
|
649 |
|
|
int k; |
650 |
|
|
AtomStamp* current_atom; |
651 |
|
|
DirectionalAtom* dAtom; |
652 |
|
|
double rotMat[3][3]; |
653 |
|
|
|
654 |
|
|
for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){ |
655 |
chuckv |
124 |
|
656 |
mmeineke |
10 |
current_atom = comp_stamps[current_comp]->getAtom( k ); |
657 |
|
|
if( !current_atom->havePosition() ){ |
658 |
|
|
std::cerr << "Component " << comp_stamps[current_comp]->getID() |
659 |
|
|
<< ", atom " << current_atom->getType() |
660 |
|
|
<< " does not have a position specified.\n" |
661 |
|
|
<< "The initialization routine is unable to give a start" |
662 |
|
|
<< " position.\n"; |
663 |
|
|
exit(8); |
664 |
|
|
} |
665 |
chuckv |
124 |
|
666 |
mmeineke |
10 |
the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() ); |
667 |
|
|
the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() ); |
668 |
|
|
the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() ); |
669 |
chuckv |
124 |
|
670 |
mmeineke |
10 |
if( the_atoms[current_atom_ndx]->isDirectional() ){ |
671 |
chuckv |
124 |
|
672 |
mmeineke |
10 |
dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx]; |
673 |
chuckv |
124 |
|
674 |
mmeineke |
10 |
rotMat[0][0] = 1.0; |
675 |
|
|
rotMat[0][1] = 0.0; |
676 |
|
|
rotMat[0][2] = 0.0; |
677 |
|
|
|
678 |
|
|
rotMat[1][0] = 0.0; |
679 |
|
|
rotMat[1][1] = 1.0; |
680 |
|
|
rotMat[1][2] = 0.0; |
681 |
|
|
|
682 |
|
|
rotMat[2][0] = 0.0; |
683 |
|
|
rotMat[2][1] = 0.0; |
684 |
|
|
rotMat[2][2] = 1.0; |
685 |
|
|
|
686 |
|
|
dAtom->setA( rotMat ); |
687 |
|
|
} |
688 |
|
|
|
689 |
|
|
current_atom_ndx++; |
690 |
|
|
} |
691 |
chuckv |
124 |
|
692 |
mmeineke |
10 |
current_mol++; |
693 |
|
|
current_comp_mol++; |
694 |
|
|
|
695 |
|
|
if( current_comp_mol >= components_nmol[current_comp] ){ |
696 |
chuckv |
124 |
|
697 |
mmeineke |
10 |
current_comp_mol = 0; |
698 |
|
|
current_comp++; |
699 |
|
|
} |
700 |
|
|
} |