1 |
#include <cstdlib> |
2 |
#include <cstdio> |
3 |
#include <cstring> |
4 |
|
5 |
#include <iostream> |
6 |
using namespace std; |
7 |
|
8 |
#include "ForceFields.hpp" |
9 |
#include "SRI.hpp" |
10 |
#include "simError.h" |
11 |
|
12 |
#include <fortranWrappers.hpp> |
13 |
|
14 |
#ifdef IS_MPI |
15 |
#include "mpiForceField.h" |
16 |
#endif // is_mpi |
17 |
|
18 |
namespace TPE { // restrict the access of the folowing to this file only. |
19 |
|
20 |
|
21 |
// Declare the structures that will be passed by MPI |
22 |
|
23 |
typedef struct{ |
24 |
char name[15]; |
25 |
double mass; |
26 |
double epslon; |
27 |
double sigma; |
28 |
double dipole; |
29 |
double w0; |
30 |
double v0; |
31 |
int isSSD; |
32 |
int isDipole; |
33 |
int ident; |
34 |
int last; // 0 -> default |
35 |
// 1 -> tells nodes to stop listening |
36 |
} atomStruct; |
37 |
|
38 |
|
39 |
typedef struct{ |
40 |
char nameA[15]; |
41 |
char nameB[15]; |
42 |
char type[30]; |
43 |
double d0; |
44 |
int last; // 0 -> default |
45 |
// 1 -> tells nodes to stop listening |
46 |
} bondStruct; |
47 |
|
48 |
|
49 |
typedef struct{ |
50 |
char nameA[15]; |
51 |
char nameB[15]; |
52 |
char nameC[15]; |
53 |
char type[30]; |
54 |
double k1, k2, k3, t0; |
55 |
int last; // 0 -> default |
56 |
// 1 -> tells nodes to stop listening |
57 |
} bendStruct; |
58 |
|
59 |
|
60 |
typedef struct{ |
61 |
char nameA[15]; |
62 |
char nameB[15]; |
63 |
char nameC[15]; |
64 |
char nameD[15]; |
65 |
char type[30]; |
66 |
double k1, k2, k3, k4; |
67 |
int last; // 0 -> default |
68 |
// 1 -> tells nodes to stop listening |
69 |
} torsionStruct; |
70 |
|
71 |
|
72 |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ); |
73 |
int parseBond( char *lineBuffer, int lineNum, bondStruct &info ); |
74 |
int parseBend( char *lineBuffer, int lineNum, bendStruct &info ); |
75 |
int parseTorsion( char *lineBuffer, int lineNum, torsionStruct &info ); |
76 |
|
77 |
|
78 |
#ifdef IS_MPI |
79 |
|
80 |
MPI_Datatype mpiAtomStructType; |
81 |
MPI_Datatype mpiBondStructType; |
82 |
MPI_Datatype mpiBendStructType; |
83 |
MPI_Datatype mpiTorsionStructType; |
84 |
|
85 |
#endif |
86 |
|
87 |
} // namespace |
88 |
|
89 |
using namespace TPE; |
90 |
|
91 |
|
92 |
//**************************************************************** |
93 |
// begins the actual forcefield stuff. |
94 |
//**************************************************************** |
95 |
|
96 |
|
97 |
TraPPE_ExFF::TraPPE_ExFF(){ |
98 |
|
99 |
char fileName[200]; |
100 |
char* ffPath_env = "FORCE_PARAM_PATH"; |
101 |
char* ffPath; |
102 |
char temp[200]; |
103 |
char errMsg[1000]; |
104 |
|
105 |
// do the funtion wrapping |
106 |
wrapMeFF( this ); |
107 |
|
108 |
|
109 |
#ifdef IS_MPI |
110 |
int i; |
111 |
|
112 |
// ********************************************************************** |
113 |
// Init the atomStruct mpi type |
114 |
|
115 |
atomStruct atomProto; // mpiPrototype |
116 |
int atomBC[3] = {15,6,4}; // block counts |
117 |
MPI_Aint atomDspls[3]; // displacements |
118 |
MPI_Datatype atomMbrTypes[3]; // member mpi types |
119 |
|
120 |
MPI_Address(&atomProto.name, &atomDspls[0]); |
121 |
MPI_Address(&atomProto.mass, &atomDspls[1]); |
122 |
MPI_Address(&atomProto.isSSD, &atomDspls[2]); |
123 |
|
124 |
atomMbrTypes[0] = MPI_CHAR; |
125 |
atomMbrTypes[1] = MPI_DOUBLE; |
126 |
atomMbrTypes[2] = MPI_INT; |
127 |
|
128 |
for (i=2; i >= 0; i--) atomDspls[i] -= atomDspls[0]; |
129 |
|
130 |
MPI_Type_struct(3, atomBC, atomDspls, atomMbrTypes, &mpiAtomStructType); |
131 |
MPI_Type_commit(&mpiAtomStructType); |
132 |
|
133 |
|
134 |
// ********************************************************************** |
135 |
// Init the bondStruct mpi type |
136 |
|
137 |
bondStruct bondProto; // mpiPrototype |
138 |
int bondBC[3] = {60,1,1}; // block counts |
139 |
MPI_Aint bondDspls[3]; // displacements |
140 |
MPI_Datatype bondMbrTypes[3]; // member mpi types |
141 |
|
142 |
MPI_Address(&bondProto.nameA, &bondDspls[0]); |
143 |
MPI_Address(&bondProto.d0, &bondDspls[1]); |
144 |
MPI_Address(&bondProto.last, &bondDspls[2]); |
145 |
|
146 |
bondMbrTypes[0] = MPI_CHAR; |
147 |
bondMbrTypes[1] = MPI_DOUBLE; |
148 |
bondMbrTypes[2] = MPI_INT; |
149 |
|
150 |
for (i=2; i >= 0; i--) bondDspls[i] -= bondDspls[0]; |
151 |
|
152 |
MPI_Type_struct(3, bondBC, bondDspls, bondMbrTypes, &mpiBondStructType); |
153 |
MPI_Type_commit(&mpiBondStructType); |
154 |
|
155 |
|
156 |
// ********************************************************************** |
157 |
// Init the bendStruct mpi type |
158 |
|
159 |
bendStruct bendProto; // mpiPrototype |
160 |
int bendBC[3] = {75,4,1}; // block counts |
161 |
MPI_Aint bendDspls[3]; // displacements |
162 |
MPI_Datatype bendMbrTypes[3]; // member mpi types |
163 |
|
164 |
MPI_Address(&bendProto.nameA, &bendDspls[0]); |
165 |
MPI_Address(&bendProto.k1, &bendDspls[1]); |
166 |
MPI_Address(&bendProto.last, &bendDspls[2]); |
167 |
|
168 |
bendMbrTypes[0] = MPI_CHAR; |
169 |
bendMbrTypes[1] = MPI_DOUBLE; |
170 |
bendMbrTypes[2] = MPI_INT; |
171 |
|
172 |
for (i=2; i >= 0; i--) bendDspls[i] -= bendDspls[0]; |
173 |
|
174 |
MPI_Type_struct(3, bendBC, bendDspls, bendMbrTypes, &mpiBendStructType); |
175 |
MPI_Type_commit(&mpiBendStructType); |
176 |
|
177 |
|
178 |
// ********************************************************************** |
179 |
// Init the torsionStruct mpi type |
180 |
|
181 |
torsionStruct torsionProto; // mpiPrototype |
182 |
int torsionBC[3] = {90,4,1}; // block counts |
183 |
MPI_Aint torsionDspls[3]; // displacements |
184 |
MPI_Datatype torsionMbrTypes[3]; // member mpi types |
185 |
|
186 |
MPI_Address(&torsionProto.nameA, &torsionDspls[0]); |
187 |
MPI_Address(&torsionProto.k1, &torsionDspls[1]); |
188 |
MPI_Address(&torsionProto.last, &torsionDspls[2]); |
189 |
|
190 |
torsionMbrTypes[0] = MPI_CHAR; |
191 |
torsionMbrTypes[1] = MPI_DOUBLE; |
192 |
torsionMbrTypes[2] = MPI_INT; |
193 |
|
194 |
for (i=2; i >= 0; i--) torsionDspls[i] -= torsionDspls[0]; |
195 |
|
196 |
MPI_Type_struct(3, torsionBC, torsionDspls, torsionMbrTypes, |
197 |
&mpiTorsionStructType); |
198 |
MPI_Type_commit(&mpiTorsionStructType); |
199 |
|
200 |
// *********************************************************************** |
201 |
|
202 |
if( worldRank == 0 ){ |
203 |
#endif |
204 |
|
205 |
// generate the force file name |
206 |
|
207 |
strcpy( fileName, "TraPPE_Ex.frc" ); |
208 |
// fprintf( stderr,"Trying to open %s\n", fileName ); |
209 |
|
210 |
// attempt to open the file in the current directory first. |
211 |
|
212 |
frcFile = fopen( fileName, "r" ); |
213 |
|
214 |
if( frcFile == NULL ){ |
215 |
|
216 |
// next see if the force path enviorment variable is set |
217 |
|
218 |
ffPath = getenv( ffPath_env ); |
219 |
if( ffPath == NULL ) { |
220 |
sprintf( painCave.errMsg, |
221 |
"Error opening the force field parameter file: %s\n" |
222 |
"Have you tried setting the FORCE_PARAM_PATH environment " |
223 |
"vairable?\n", |
224 |
fileName ); |
225 |
painCave.isFatal = 1; |
226 |
simError(); |
227 |
} |
228 |
|
229 |
|
230 |
strcpy( temp, ffPath ); |
231 |
strcat( temp, "/" ); |
232 |
strcat( temp, fileName ); |
233 |
strcpy( fileName, temp ); |
234 |
|
235 |
frcFile = fopen( fileName, "r" ); |
236 |
|
237 |
if( frcFile == NULL ){ |
238 |
|
239 |
sprintf( painCave.errMsg, |
240 |
"Error opening the force field parameter file: %s\n" |
241 |
"Have you tried setting the FORCE_PARAM_PATH environment " |
242 |
"vairable?\n", |
243 |
fileName ); |
244 |
painCave.isFatal = 1; |
245 |
simError(); |
246 |
} |
247 |
} |
248 |
|
249 |
#ifdef IS_MPI |
250 |
} |
251 |
|
252 |
sprintf( checkPointMsg, "TraPPE_ExFF file opened sucessfully." ); |
253 |
MPIcheckPoint(); |
254 |
|
255 |
#endif // is_mpi |
256 |
} |
257 |
|
258 |
|
259 |
TraPPE_ExFF::~TraPPE_ExFF(){ |
260 |
|
261 |
#ifdef IS_MPI |
262 |
if( worldRank == 0 ){ |
263 |
#endif // is_mpi |
264 |
|
265 |
fclose( frcFile ); |
266 |
|
267 |
#ifdef IS_MPI |
268 |
} |
269 |
#endif // is_mpi |
270 |
} |
271 |
|
272 |
|
273 |
void TraPPE_ExFF::initializeAtoms( void ){ |
274 |
|
275 |
class LinkedType { |
276 |
public: |
277 |
LinkedType(){ |
278 |
next = NULL; |
279 |
name[0] = '\0'; |
280 |
} |
281 |
~LinkedType(){ if( next != NULL ) delete next; } |
282 |
|
283 |
LinkedType* find(char* key){ |
284 |
if( !strcmp(name, key) ) return this; |
285 |
if( next != NULL ) return next->find(key); |
286 |
return NULL; |
287 |
} |
288 |
|
289 |
void add( atomStruct &info ){ |
290 |
|
291 |
// check for duplicates |
292 |
|
293 |
if( !strcmp( info.name, name ) ){ |
294 |
sprintf( painCave.errMsg, |
295 |
"Duplicate TraPPE_Ex atom type \"%s\" found in " |
296 |
"the TraPPE_ExFF param file./n", |
297 |
name ); |
298 |
painCave.isFatal = 1; |
299 |
simError(); |
300 |
} |
301 |
|
302 |
if( next != NULL ) next->add(info); |
303 |
else{ |
304 |
next = new LinkedType(); |
305 |
strcpy(next->name, info.name); |
306 |
next->isDipole = info.isDipole; |
307 |
next->isSSD = info.isSSD; |
308 |
next->mass = info.mass; |
309 |
next->epslon = info.epslon; |
310 |
next->sigma = info.sigma; |
311 |
next->dipole = info.dipole; |
312 |
next->w0 = info.w0; |
313 |
next->v0 = info.v0; |
314 |
next->ident = info.ident; |
315 |
} |
316 |
} |
317 |
|
318 |
#ifdef IS_MPI |
319 |
|
320 |
void duplicate( atomStruct &info ){ |
321 |
strcpy(info.name, name); |
322 |
info.isDipole = isDipole; |
323 |
info.isSSD = isSSD; |
324 |
info.mass = mass; |
325 |
info.epslon = epslon; |
326 |
info.sigma = sigma; |
327 |
info.dipole = dipole; |
328 |
info.w0 = w0; |
329 |
info.v0 = v0; |
330 |
info.last = 0; |
331 |
} |
332 |
|
333 |
|
334 |
#endif |
335 |
|
336 |
char name[15]; |
337 |
int isDipole; |
338 |
int isSSD; |
339 |
double mass; |
340 |
double epslon; |
341 |
double sigma; |
342 |
double dipole; |
343 |
double w0; |
344 |
double v0; |
345 |
int ident; |
346 |
LinkedType* next; |
347 |
}; |
348 |
|
349 |
LinkedType* headAtomType; |
350 |
LinkedType* currentAtomType; |
351 |
atomStruct info; |
352 |
info.last = 1; // initialize last to have the last set. |
353 |
// if things go well, last will be set to 0 |
354 |
|
355 |
|
356 |
|
357 |
int i; |
358 |
int identNum; |
359 |
|
360 |
Atom** the_atoms; |
361 |
int nAtoms; |
362 |
the_atoms = entry_plug->atoms; |
363 |
nAtoms = entry_plug->n_atoms; |
364 |
|
365 |
|
366 |
////////////////////////////////////////////////// |
367 |
// a quick water fix |
368 |
|
369 |
double waterI[3][3]; |
370 |
waterI[0][0] = 1.76958347772500; |
371 |
waterI[0][1] = 0.0; |
372 |
waterI[0][2] = 0.0; |
373 |
|
374 |
waterI[1][0] = 0.0; |
375 |
waterI[1][1] = 0.614537057924513; |
376 |
waterI[1][2] = 0.0; |
377 |
|
378 |
waterI[2][0] = 0.0; |
379 |
waterI[2][1] = 0.0; |
380 |
waterI[2][2] = 1.15504641980049; |
381 |
|
382 |
|
383 |
double headI[3][3]; |
384 |
headI[0][0] = 1125; |
385 |
headI[0][1] = 0.0; |
386 |
headI[0][2] = 0.0; |
387 |
|
388 |
headI[1][0] = 0.0; |
389 |
headI[1][1] = 1125; |
390 |
headI[1][2] = 0.0; |
391 |
|
392 |
headI[2][0] = 0.0; |
393 |
headI[2][1] = 0.0; |
394 |
headI[2][2] = 250; |
395 |
|
396 |
|
397 |
|
398 |
////////////////////////////////////////////////// |
399 |
|
400 |
|
401 |
#ifdef IS_MPI |
402 |
if( worldRank == 0 ){ |
403 |
#endif |
404 |
|
405 |
// read in the atom types. |
406 |
|
407 |
headAtomType = new LinkedType; |
408 |
|
409 |
fastForward( "AtomTypes", "initializeAtoms" ); |
410 |
|
411 |
// we are now at the AtomTypes section. |
412 |
|
413 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
414 |
lineNum++; |
415 |
|
416 |
|
417 |
// read a line, and start parseing out the atom types |
418 |
|
419 |
if( eof_test == NULL ){ |
420 |
sprintf( painCave.errMsg, |
421 |
"Error in reading Atoms from force file at line %d.\n", |
422 |
lineNum ); |
423 |
painCave.isFatal = 1; |
424 |
simError(); |
425 |
} |
426 |
|
427 |
identNum = 1; |
428 |
// stop reading at end of file, or at next section |
429 |
while( readLine[0] != '#' && eof_test != NULL ){ |
430 |
|
431 |
// toss comment lines |
432 |
if( readLine[0] != '!' ){ |
433 |
|
434 |
// the parser returns 0 if the line was blank |
435 |
if( parseAtom( readLine, lineNum, info ) ){ |
436 |
info.ident = identNum; |
437 |
headAtomType->add( info );; |
438 |
identNum++; |
439 |
} |
440 |
} |
441 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
442 |
lineNum++; |
443 |
} |
444 |
|
445 |
#ifdef IS_MPI |
446 |
|
447 |
// send out the linked list to all the other processes |
448 |
|
449 |
sprintf( checkPointMsg, |
450 |
"TraPPE_ExFF atom structures read successfully." ); |
451 |
MPIcheckPoint(); |
452 |
|
453 |
currentAtomType = headAtomType->next; //skip the first element who is a place holder. |
454 |
while( currentAtomType != NULL ){ |
455 |
currentAtomType->duplicate( info ); |
456 |
|
457 |
|
458 |
|
459 |
sendFrcStruct( &info, mpiAtomStructType ); |
460 |
|
461 |
sprintf( checkPointMsg, |
462 |
"successfully sent TraPPE_Ex force type: \"%s\"\n", |
463 |
info.name ); |
464 |
MPIcheckPoint(); |
465 |
|
466 |
currentAtomType = currentAtomType->next; |
467 |
} |
468 |
info.last = 1; |
469 |
sendFrcStruct( &info, mpiAtomStructType ); |
470 |
|
471 |
} |
472 |
|
473 |
else{ |
474 |
|
475 |
// listen for node 0 to send out the force params |
476 |
|
477 |
MPIcheckPoint(); |
478 |
|
479 |
headAtomType = new LinkedType; |
480 |
recieveFrcStruct( &info, mpiAtomStructType ); |
481 |
|
482 |
while( !info.last ){ |
483 |
|
484 |
|
485 |
|
486 |
headAtomType->add( info ); |
487 |
|
488 |
MPIcheckPoint(); |
489 |
|
490 |
recieveFrcStruct( &info, mpiAtomStructType ); |
491 |
} |
492 |
} |
493 |
#endif // is_mpi |
494 |
|
495 |
// call new A_types in fortran |
496 |
|
497 |
int isError; |
498 |
currentAtomType = headAtomType; |
499 |
while( currentAtomType != NULL ){ |
500 |
|
501 |
if( currentAtomType->name[0] != '\0' ){ |
502 |
isError = 0; |
503 |
newTPEtype( &(currentAtomType->ident), |
504 |
&(currentAtomType->mass), |
505 |
&(currentAtomType->epslon), |
506 |
&(currentAtomType->sigma), |
507 |
&(currentAtomType->isDipole), |
508 |
&(currentAtomType->isSSD), |
509 |
&(currentAtomType->dipole), |
510 |
&(currentAtomType->w0), |
511 |
&(currentAtomType->v0), |
512 |
&isError ); |
513 |
if( isError ){ |
514 |
sprintf( painCave.errMsg, |
515 |
"Error initializing the \"%s\" atom type in fortran\n", |
516 |
currentAtomType->name ); |
517 |
painCave.isFatal = 1; |
518 |
simError(); |
519 |
} |
520 |
} |
521 |
currentAtomType = currentAtomType->next; |
522 |
} |
523 |
|
524 |
#ifdef IS_MPI |
525 |
sprintf( checkPointMsg, |
526 |
"TraPPE_ExFF atom structures successfully sent to fortran\n" ); |
527 |
MPIcheckPoint(); |
528 |
#endif // is_mpi |
529 |
|
530 |
|
531 |
// initialize the atoms |
532 |
|
533 |
double bigSigma = 0.0; |
534 |
DirectionalAtom* dAtom; |
535 |
|
536 |
for( i=0; i<nAtoms; i++ ){ |
537 |
|
538 |
currentAtomType = headAtomType->find( the_atoms[i]->getType() ); |
539 |
if( currentAtomType == NULL ){ |
540 |
sprintf( painCave.errMsg, |
541 |
"AtomType error, %s not found in force file.\n", |
542 |
the_atoms[i]->getType() ); |
543 |
painCave.isFatal = 1; |
544 |
simError(); |
545 |
} |
546 |
|
547 |
the_atoms[i]->setMass( currentAtomType->mass ); |
548 |
the_atoms[i]->setEpslon( currentAtomType->epslon ); |
549 |
the_atoms[i]->setSigma( currentAtomType->sigma ); |
550 |
the_atoms[i]->setLJ(); |
551 |
|
552 |
if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma; |
553 |
|
554 |
if( currentAtomType->isDipole ){ |
555 |
if( the_atoms[i]->isDirectional() ){ |
556 |
|
557 |
dAtom = (DirectionalAtom *) the_atoms[i]; |
558 |
dAtom->setMu( currentAtomType->dipole ); |
559 |
dAtom->setHasDipole( 1 ); |
560 |
dAtom->setJx( 0.0 ); |
561 |
dAtom->setJy( 0.0 ); |
562 |
dAtom->setJz( 0.0 ); |
563 |
|
564 |
if(!strcmp("SSD",the_atoms[i]->getType())){ |
565 |
dAtom->setI( waterI ); |
566 |
dAtom->setSSD( 1 ); |
567 |
} |
568 |
else if(!strcmp("HEAD",the_atoms[i]->getType())){ |
569 |
dAtom->setI( headI ); |
570 |
dAtom->setSSD( 0 ); |
571 |
} |
572 |
else{ |
573 |
sprintf(painCave.errMsg, |
574 |
"AtmType error, %s does not have a moment of inertia set.\n", |
575 |
the_atoms[i]->getType() ); |
576 |
painCave.isFatal = 1; |
577 |
simError(); |
578 |
} |
579 |
entry_plug->n_dipoles++; |
580 |
} |
581 |
else{ |
582 |
|
583 |
sprintf( painCave.errMsg, |
584 |
"TraPPE_ExFF error: Atom \"%s\" is a dipole, yet no standard" |
585 |
" orientation was specifed in the BASS file.\n", |
586 |
currentAtomType->name ); |
587 |
painCave.isFatal = 1; |
588 |
simError(); |
589 |
} |
590 |
} |
591 |
else{ |
592 |
if( the_atoms[i]->isDirectional() ){ |
593 |
sprintf( painCave.errMsg, |
594 |
"TraPPE_ExFF error: Atom \"%s\" was given a standard" |
595 |
"orientation in the BASS file, yet it is not a dipole.\n", |
596 |
currentAtomType->name); |
597 |
painCave.isFatal = 1; |
598 |
simError(); |
599 |
} |
600 |
} |
601 |
} |
602 |
|
603 |
#ifdef IS_MPI |
604 |
double tempBig = bigSigma; |
605 |
MPI::COMM_WORLD.Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX ); |
606 |
#endif //is_mpi |
607 |
|
608 |
//calc rCut and rList |
609 |
|
610 |
entry_plug->rCut = 2.5 * bigSigma; |
611 |
|
612 |
if(entry_plug->rCut > (entry_plug->box_x / 2.0)) |
613 |
entry_plug->rCut = entry_plug->box_x / 2.0; |
614 |
|
615 |
if(entry_plug->rCut > (entry_plug->box_y / 2.0)) |
616 |
entry_plug->rCut = entry_plug->box_y / 2.0; |
617 |
|
618 |
if(entry_plug->rCut > (entry_plug->box_z / 2.0)) |
619 |
entry_plug->rCut = entry_plug->box_z / 2.0; |
620 |
|
621 |
entry_plug->rList = entry_plug->rCut + 1.0; |
622 |
|
623 |
|
624 |
// clean up the memory |
625 |
|
626 |
delete headAtomType; |
627 |
|
628 |
#ifdef IS_MPI |
629 |
sprintf( checkPointMsg, "TraPPE_Ex atoms initialized succesfully" ); |
630 |
MPIcheckPoint(); |
631 |
#endif // is_mpi |
632 |
|
633 |
} |
634 |
|
635 |
void TraPPE_ExFF::initializeBonds( bond_pair* the_bonds ){ |
636 |
|
637 |
class LinkedType { |
638 |
public: |
639 |
LinkedType(){ |
640 |
next = NULL; |
641 |
nameA[0] = '\0'; |
642 |
nameB[0] = '\0'; |
643 |
type[0] = '\0'; |
644 |
} |
645 |
~LinkedType(){ if( next != NULL ) delete next; } |
646 |
|
647 |
LinkedType* find(char* key1, char* key2){ |
648 |
if( !strcmp(nameA, key1 ) && !strcmp( nameB, key2 ) ) return this; |
649 |
if( !strcmp(nameA, key2 ) && !strcmp( nameB, key1 ) ) return this; |
650 |
if( next != NULL ) return next->find(key1, key2); |
651 |
return NULL; |
652 |
} |
653 |
|
654 |
|
655 |
void add( bondStruct &info ){ |
656 |
|
657 |
// check for duplicates |
658 |
int dup = 0; |
659 |
|
660 |
if( !strcmp(nameA, info.nameA ) && !strcmp( nameB, info.nameB ) ) dup = 1; |
661 |
if( !strcmp(nameA, info.nameB ) && !strcmp( nameB, info.nameA ) ) dup = 1; |
662 |
|
663 |
if(dup){ |
664 |
sprintf( painCave.errMsg, |
665 |
"Duplicate TraPPE_Ex bond type \"%s - %s\" found in " |
666 |
"the TraPPE_ExFF param file./n", |
667 |
nameA, nameB ); |
668 |
painCave.isFatal = 1; |
669 |
simError(); |
670 |
} |
671 |
|
672 |
|
673 |
if( next != NULL ) next->add(info); |
674 |
else{ |
675 |
next = new LinkedType(); |
676 |
strcpy(next->nameA, info.nameA); |
677 |
strcpy(next->nameB, info.nameB); |
678 |
strcpy(next->type, info.type); |
679 |
next->d0 = info.d0; |
680 |
} |
681 |
} |
682 |
|
683 |
#ifdef IS_MPI |
684 |
void duplicate( bondStruct &info ){ |
685 |
strcpy(info.nameA, nameA); |
686 |
strcpy(info.nameB, nameB); |
687 |
strcpy(info.type, type); |
688 |
info.d0 = d0; |
689 |
info.last = 0; |
690 |
} |
691 |
|
692 |
|
693 |
#endif |
694 |
|
695 |
char nameA[15]; |
696 |
char nameB[15]; |
697 |
char type[30]; |
698 |
double d0; |
699 |
|
700 |
LinkedType* next; |
701 |
}; |
702 |
|
703 |
|
704 |
|
705 |
LinkedType* headBondType; |
706 |
LinkedType* currentBondType; |
707 |
bondStruct info; |
708 |
info.last = 1; // initialize last to have the last set. |
709 |
// if things go well, last will be set to 0 |
710 |
|
711 |
SRI **the_sris; |
712 |
Atom** the_atoms; |
713 |
int nBonds; |
714 |
the_sris = entry_plug->sr_interactions; |
715 |
the_atoms = entry_plug->atoms; |
716 |
nBonds = entry_plug->n_bonds; |
717 |
|
718 |
int i, a, b; |
719 |
char* atomA; |
720 |
char* atomB; |
721 |
|
722 |
#ifdef IS_MPI |
723 |
if( worldRank == 0 ){ |
724 |
#endif |
725 |
|
726 |
// read in the bond types. |
727 |
|
728 |
headBondType = new LinkedType; |
729 |
|
730 |
fastForward( "BondTypes", "initializeBonds" ); |
731 |
|
732 |
// we are now at the bondTypes section |
733 |
|
734 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
735 |
lineNum++; |
736 |
|
737 |
|
738 |
// read a line, and start parseing out the atom types |
739 |
|
740 |
if( eof_test == NULL ){ |
741 |
sprintf( painCave.errMsg, |
742 |
"Error in reading bonds from force file at line %d.\n", |
743 |
lineNum ); |
744 |
painCave.isFatal = 1; |
745 |
simError(); |
746 |
} |
747 |
|
748 |
// stop reading at end of file, or at next section |
749 |
while( readLine[0] != '#' && eof_test != NULL ){ |
750 |
|
751 |
// toss comment lines |
752 |
if( readLine[0] != '!' ){ |
753 |
|
754 |
// the parser returns 0 if the line was blank |
755 |
if( parseBond( readLine, lineNum, info ) ){ |
756 |
headBondType->add( info ); |
757 |
} |
758 |
} |
759 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
760 |
lineNum++; |
761 |
} |
762 |
|
763 |
#ifdef IS_MPI |
764 |
|
765 |
// send out the linked list to all the other processes |
766 |
|
767 |
sprintf( checkPointMsg, |
768 |
"TraPPE_Ex bond structures read successfully." ); |
769 |
MPIcheckPoint(); |
770 |
|
771 |
currentBondType = headBondType; |
772 |
while( currentBondType != NULL ){ |
773 |
currentBondType->duplicate( info ); |
774 |
sendFrcStruct( &info, mpiBondStructType ); |
775 |
currentBondType = currentBondType->next; |
776 |
} |
777 |
info.last = 1; |
778 |
sendFrcStruct( &info, mpiBondStructType ); |
779 |
|
780 |
} |
781 |
|
782 |
else{ |
783 |
|
784 |
// listen for node 0 to send out the force params |
785 |
|
786 |
MPIcheckPoint(); |
787 |
|
788 |
headBondType = new LinkedType; |
789 |
recieveFrcStruct( &info, mpiBondStructType ); |
790 |
while( !info.last ){ |
791 |
|
792 |
headBondType->add( info ); |
793 |
recieveFrcStruct( &info, mpiBondStructType ); |
794 |
} |
795 |
} |
796 |
#endif // is_mpi |
797 |
|
798 |
|
799 |
// initialize the Bonds |
800 |
|
801 |
|
802 |
for( i=0; i<nBonds; i++ ){ |
803 |
|
804 |
a = the_bonds[i].a; |
805 |
b = the_bonds[i].b; |
806 |
|
807 |
atomA = the_atoms[a]->getType(); |
808 |
atomB = the_atoms[b]->getType(); |
809 |
currentBondType = headBondType->find( atomA, atomB ); |
810 |
if( currentBondType == NULL ){ |
811 |
sprintf( painCave.errMsg, |
812 |
"BondType error, %s - %s not found in force file.\n", |
813 |
atomA, atomB ); |
814 |
painCave.isFatal = 1; |
815 |
simError(); |
816 |
} |
817 |
|
818 |
if( !strcmp( currentBondType->type, "fixed" ) ){ |
819 |
|
820 |
the_sris[i] = new ConstrainedBond( *the_atoms[a], |
821 |
*the_atoms[b], |
822 |
currentBondType->d0 ); |
823 |
entry_plug->n_constraints++; |
824 |
} |
825 |
} |
826 |
|
827 |
|
828 |
// clean up the memory |
829 |
|
830 |
delete headBondType; |
831 |
|
832 |
#ifdef IS_MPI |
833 |
sprintf( checkPointMsg, "TraPPE_Ex bonds initialized succesfully" ); |
834 |
MPIcheckPoint(); |
835 |
#endif // is_mpi |
836 |
|
837 |
} |
838 |
|
839 |
void TraPPE_ExFF::initializeBends( bend_set* the_bends ){ |
840 |
|
841 |
class LinkedType { |
842 |
public: |
843 |
LinkedType(){ |
844 |
next = NULL; |
845 |
nameA[0] = '\0'; |
846 |
nameB[0] = '\0'; |
847 |
nameC[0] = '\0'; |
848 |
type[0] = '\0'; |
849 |
} |
850 |
~LinkedType(){ if( next != NULL ) delete next; } |
851 |
|
852 |
LinkedType* find( char* key1, char* key2, char* key3 ){ |
853 |
if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) |
854 |
&& !strcmp( nameC, key3 ) ) return this; |
855 |
if( !strcmp( nameA, key3 ) && !strcmp( nameB, key2 ) |
856 |
&& !strcmp( nameC, key1 ) ) return this; |
857 |
if( next != NULL ) return next->find(key1, key2, key3); |
858 |
return NULL; |
859 |
} |
860 |
|
861 |
void add( bendStruct &info ){ |
862 |
|
863 |
// check for duplicates |
864 |
int dup = 0; |
865 |
|
866 |
if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) |
867 |
&& !strcmp( nameC, info.nameC ) ) dup = 1; |
868 |
if( !strcmp( nameA, info.nameC ) && !strcmp( nameB, info.nameB ) |
869 |
&& !strcmp( nameC, info.nameA ) ) dup = 1; |
870 |
|
871 |
if(dup){ |
872 |
sprintf( painCave.errMsg, |
873 |
"Duplicate TraPPE_Ex bend type \"%s - %s - %s\" found in " |
874 |
"the TraPPE_ExFF param file./n", |
875 |
nameA, nameB, nameC ); |
876 |
painCave.isFatal = 1; |
877 |
simError(); |
878 |
} |
879 |
|
880 |
if( next != NULL ) next->add(info); |
881 |
else{ |
882 |
next = new LinkedType(); |
883 |
strcpy(next->nameA, info.nameA); |
884 |
strcpy(next->nameB, info.nameB); |
885 |
strcpy(next->nameC, info.nameC); |
886 |
strcpy(next->type, info.type); |
887 |
next->k1 = info.k1; |
888 |
next->k2 = info.k2; |
889 |
next->k3 = info.k3; |
890 |
next->t0 = info.t0; |
891 |
} |
892 |
} |
893 |
|
894 |
#ifdef IS_MPI |
895 |
|
896 |
void duplicate( bendStruct &info ){ |
897 |
strcpy(info.nameA, nameA); |
898 |
strcpy(info.nameB, nameB); |
899 |
strcpy(info.nameC, nameC); |
900 |
strcpy(info.type, type); |
901 |
info.k1 = k1; |
902 |
info.k2 = k2; |
903 |
info.k3 = k3; |
904 |
info.t0 = t0; |
905 |
info.last = 0; |
906 |
} |
907 |
|
908 |
#endif // is_mpi |
909 |
|
910 |
char nameA[15]; |
911 |
char nameB[15]; |
912 |
char nameC[15]; |
913 |
char type[30]; |
914 |
double k1, k2, k3, t0; |
915 |
|
916 |
LinkedType* next; |
917 |
}; |
918 |
|
919 |
LinkedType* headBendType; |
920 |
LinkedType* currentBendType; |
921 |
bendStruct info; |
922 |
info.last = 1; // initialize last to have the last set. |
923 |
// if things go well, last will be set to 0 |
924 |
|
925 |
QuadraticBend* qBend; |
926 |
SRI **the_sris; |
927 |
Atom** the_atoms; |
928 |
int nBends; |
929 |
the_sris = entry_plug->sr_interactions; |
930 |
the_atoms = entry_plug->atoms; |
931 |
nBends = entry_plug->n_bends; |
932 |
|
933 |
int i, a, b, c; |
934 |
char* atomA; |
935 |
char* atomB; |
936 |
char* atomC; |
937 |
|
938 |
|
939 |
#ifdef IS_MPI |
940 |
if( worldRank == 0 ){ |
941 |
#endif |
942 |
|
943 |
// read in the bend types. |
944 |
|
945 |
headBendType = new LinkedType; |
946 |
|
947 |
fastForward( "BendTypes", "initializeBends" ); |
948 |
|
949 |
// we are now at the bendTypes section |
950 |
|
951 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
952 |
lineNum++; |
953 |
|
954 |
// read a line, and start parseing out the bend types |
955 |
|
956 |
if( eof_test == NULL ){ |
957 |
sprintf( painCave.errMsg, |
958 |
"Error in reading bends from force file at line %d.\n", |
959 |
lineNum ); |
960 |
painCave.isFatal = 1; |
961 |
simError(); |
962 |
} |
963 |
|
964 |
// stop reading at end of file, or at next section |
965 |
while( readLine[0] != '#' && eof_test != NULL ){ |
966 |
|
967 |
// toss comment lines |
968 |
if( readLine[0] != '!' ){ |
969 |
|
970 |
// the parser returns 0 if the line was blank |
971 |
if( parseBend( readLine, lineNum, info ) ){ |
972 |
headBendType->add( info ); |
973 |
} |
974 |
} |
975 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
976 |
lineNum++; |
977 |
} |
978 |
|
979 |
#ifdef IS_MPI |
980 |
|
981 |
// send out the linked list to all the other processes |
982 |
|
983 |
sprintf( checkPointMsg, |
984 |
"TraPPE_Ex bend structures read successfully." ); |
985 |
MPIcheckPoint(); |
986 |
|
987 |
currentBendType = headBendType; |
988 |
while( currentBendType != NULL ){ |
989 |
currentBendType->duplicate( info ); |
990 |
sendFrcStruct( &info, mpiBendStructType ); |
991 |
currentBendType = currentBendType->next; |
992 |
} |
993 |
info.last = 1; |
994 |
sendFrcStruct( &info, mpiBendStructType ); |
995 |
|
996 |
} |
997 |
|
998 |
else{ |
999 |
|
1000 |
// listen for node 0 to send out the force params |
1001 |
|
1002 |
MPIcheckPoint(); |
1003 |
|
1004 |
headBendType = new LinkedType; |
1005 |
recieveFrcStruct( &info, mpiBendStructType ); |
1006 |
while( !info.last ){ |
1007 |
|
1008 |
headBendType->add( info ); |
1009 |
recieveFrcStruct( &info, mpiBendStructType ); |
1010 |
} |
1011 |
} |
1012 |
#endif // is_mpi |
1013 |
|
1014 |
// initialize the Bends |
1015 |
|
1016 |
int index; |
1017 |
|
1018 |
for( i=0; i<nBends; i++ ){ |
1019 |
|
1020 |
a = the_bends[i].a; |
1021 |
b = the_bends[i].b; |
1022 |
c = the_bends[i].c; |
1023 |
|
1024 |
atomA = the_atoms[a]->getType(); |
1025 |
atomB = the_atoms[b]->getType(); |
1026 |
atomC = the_atoms[c]->getType(); |
1027 |
currentBendType = headBendType->find( atomA, atomB, atomC ); |
1028 |
if( currentBendType == NULL ){ |
1029 |
sprintf( painCave.errMsg, "BendType error, %s - %s - %s not found" |
1030 |
" in force file.\n", |
1031 |
atomA, atomB, atomC ); |
1032 |
painCave.isFatal = 1; |
1033 |
simError(); |
1034 |
} |
1035 |
|
1036 |
if( !strcmp( currentBendType->type, "quadratic" ) ){ |
1037 |
|
1038 |
index = i + entry_plug->n_bonds; |
1039 |
qBend = new QuadraticBend( *the_atoms[a], |
1040 |
*the_atoms[b], |
1041 |
*the_atoms[c] ); |
1042 |
qBend->setConstants( currentBendType->k1, |
1043 |
currentBendType->k2, |
1044 |
currentBendType->k3, |
1045 |
currentBendType->t0 ); |
1046 |
the_sris[index] = qBend; |
1047 |
} |
1048 |
} |
1049 |
|
1050 |
|
1051 |
// clean up the memory |
1052 |
|
1053 |
delete headBendType; |
1054 |
|
1055 |
#ifdef IS_MPI |
1056 |
sprintf( checkPointMsg, "TraPPE_Ex bends initialized succesfully" ); |
1057 |
MPIcheckPoint(); |
1058 |
#endif // is_mpi |
1059 |
|
1060 |
} |
1061 |
|
1062 |
void TraPPE_ExFF::initializeTorsions( torsion_set* the_torsions ){ |
1063 |
|
1064 |
class LinkedType { |
1065 |
public: |
1066 |
LinkedType(){ |
1067 |
next = NULL; |
1068 |
nameA[0] = '\0'; |
1069 |
nameB[0] = '\0'; |
1070 |
nameC[0] = '\0'; |
1071 |
type[0] = '\0'; |
1072 |
} |
1073 |
~LinkedType(){ if( next != NULL ) delete next; } |
1074 |
|
1075 |
LinkedType* find( char* key1, char* key2, char* key3, char* key4 ){ |
1076 |
if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) && |
1077 |
!strcmp( nameC, key3 ) && !strcmp( nameD, key4 ) ) return this; |
1078 |
|
1079 |
if( !strcmp( nameA, key4 ) && !strcmp( nameB, key3 ) && |
1080 |
!strcmp( nameC, key2 ) && !strcmp( nameD, key1 ) ) return this; |
1081 |
|
1082 |
if( next != NULL ) return next->find(key1, key2, key3, key4); |
1083 |
return NULL; |
1084 |
} |
1085 |
|
1086 |
void add( torsionStruct &info ){ |
1087 |
|
1088 |
// check for duplicates |
1089 |
int dup = 0; |
1090 |
|
1091 |
if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) && |
1092 |
!strcmp( nameC, info.nameC ) && !strcmp( nameD, info.nameD ) ) dup = 1; |
1093 |
|
1094 |
if( !strcmp( nameA, info.nameD ) && !strcmp( nameB, info.nameC ) && |
1095 |
!strcmp( nameC, info.nameB ) && !strcmp( nameD, info.nameA ) ) dup = 1; |
1096 |
|
1097 |
if(dup){ |
1098 |
sprintf( painCave.errMsg, |
1099 |
"Duplicate TraPPE_Ex torsion type \"%s - %s - %s - %s\" found in " |
1100 |
"the TraPPE_ExFF param file./n", nameA, nameB, nameC, nameD ); |
1101 |
painCave.isFatal = 1; |
1102 |
simError(); |
1103 |
} |
1104 |
|
1105 |
if( next != NULL ) next->add(info); |
1106 |
else{ |
1107 |
next = new LinkedType(); |
1108 |
strcpy(next->nameA, info.nameA); |
1109 |
strcpy(next->nameB, info.nameB); |
1110 |
strcpy(next->nameC, info.nameC); |
1111 |
strcpy(next->type, info.type); |
1112 |
next->k1 = info.k1; |
1113 |
next->k2 = info.k2; |
1114 |
next->k3 = info.k3; |
1115 |
next->k4 = info.k4; |
1116 |
} |
1117 |
} |
1118 |
|
1119 |
#ifdef IS_MPI |
1120 |
|
1121 |
void duplicate( torsionStruct &info ){ |
1122 |
strcpy(info.nameA, nameA); |
1123 |
strcpy(info.nameB, nameB); |
1124 |
strcpy(info.nameC, nameC); |
1125 |
strcpy(info.nameD, nameD); |
1126 |
strcpy(info.type, type); |
1127 |
info.k1 = k1; |
1128 |
info.k2 = k2; |
1129 |
info.k3 = k3; |
1130 |
info.k4 = k4; |
1131 |
info.last = 0; |
1132 |
} |
1133 |
|
1134 |
#endif |
1135 |
|
1136 |
char nameA[15]; |
1137 |
char nameB[15]; |
1138 |
char nameC[15]; |
1139 |
char nameD[15]; |
1140 |
char type[30]; |
1141 |
double k1, k2, k3, k4; |
1142 |
|
1143 |
LinkedType* next; |
1144 |
}; |
1145 |
|
1146 |
LinkedType* headTorsionType; |
1147 |
LinkedType* currentTorsionType; |
1148 |
torsionStruct info; |
1149 |
info.last = 1; // initialize last to have the last set. |
1150 |
// if things go well, last will be set to 0 |
1151 |
|
1152 |
int i, a, b, c, d, index; |
1153 |
char* atomA; |
1154 |
char* atomB; |
1155 |
char* atomC; |
1156 |
char* atomD; |
1157 |
CubicTorsion* cTors; |
1158 |
|
1159 |
SRI **the_sris; |
1160 |
Atom** the_atoms; |
1161 |
int nTorsions; |
1162 |
the_sris = entry_plug->sr_interactions; |
1163 |
the_atoms = entry_plug->atoms; |
1164 |
nTorsions = entry_plug->n_torsions; |
1165 |
|
1166 |
#ifdef IS_MPI |
1167 |
if( worldRank == 0 ){ |
1168 |
#endif |
1169 |
|
1170 |
// read in the torsion types. |
1171 |
|
1172 |
headTorsionType = new LinkedType; |
1173 |
|
1174 |
fastForward( "TorsionTypes", "initializeTorsions" ); |
1175 |
|
1176 |
// we are now at the torsionTypes section |
1177 |
|
1178 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
1179 |
lineNum++; |
1180 |
|
1181 |
|
1182 |
// read a line, and start parseing out the atom types |
1183 |
|
1184 |
if( eof_test == NULL ){ |
1185 |
sprintf( painCave.errMsg, |
1186 |
"Error in reading torsions from force file at line %d.\n", |
1187 |
lineNum ); |
1188 |
painCave.isFatal = 1; |
1189 |
simError(); |
1190 |
} |
1191 |
|
1192 |
// stop reading at end of file, or at next section |
1193 |
while( readLine[0] != '#' && eof_test != NULL ){ |
1194 |
|
1195 |
// toss comment lines |
1196 |
if( readLine[0] != '!' ){ |
1197 |
|
1198 |
// the parser returns 0 if the line was blank |
1199 |
if( parseTorsion( readLine, lineNum, info ) ){ |
1200 |
headTorsionType->add( info ); |
1201 |
} |
1202 |
} |
1203 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
1204 |
lineNum++; |
1205 |
} |
1206 |
|
1207 |
#ifdef IS_MPI |
1208 |
|
1209 |
// send out the linked list to all the other processes |
1210 |
|
1211 |
sprintf( checkPointMsg, |
1212 |
"TraPPE_Ex torsion structures read successfully." ); |
1213 |
MPIcheckPoint(); |
1214 |
|
1215 |
currentTorsionType = headTorsionType; |
1216 |
while( currentTorsionType != NULL ){ |
1217 |
currentTorsionType->duplicate( info ); |
1218 |
sendFrcStruct( &info, mpiTorsionStructType ); |
1219 |
currentTorsionType = currentTorsionType->next; |
1220 |
} |
1221 |
info.last = 1; |
1222 |
sendFrcStruct( &info, mpiTorsionStructType ); |
1223 |
|
1224 |
} |
1225 |
|
1226 |
else{ |
1227 |
|
1228 |
// listen for node 0 to send out the force params |
1229 |
|
1230 |
MPIcheckPoint(); |
1231 |
|
1232 |
headTorsionType = new LinkedType; |
1233 |
recieveFrcStruct( &info, mpiTorsionStructType ); |
1234 |
while( !info.last ){ |
1235 |
|
1236 |
headTorsionType->add( info ); |
1237 |
recieveFrcStruct( &info, mpiTorsionStructType ); |
1238 |
} |
1239 |
} |
1240 |
#endif // is_mpi |
1241 |
|
1242 |
// initialize the Torsions |
1243 |
|
1244 |
for( i=0; i<nTorsions; i++ ){ |
1245 |
|
1246 |
a = the_torsions[i].a; |
1247 |
b = the_torsions[i].b; |
1248 |
c = the_torsions[i].c; |
1249 |
d = the_torsions[i].d; |
1250 |
|
1251 |
atomA = the_atoms[a]->getType(); |
1252 |
atomB = the_atoms[b]->getType(); |
1253 |
atomC = the_atoms[c]->getType(); |
1254 |
atomD = the_atoms[d]->getType(); |
1255 |
currentTorsionType = headTorsionType->find( atomA, atomB, atomC, atomD ); |
1256 |
if( currentTorsionType == NULL ){ |
1257 |
sprintf( painCave.errMsg, |
1258 |
"TorsionType error, %s - %s - %s - %s not found" |
1259 |
" in force file.\n", |
1260 |
atomA, atomB, atomC, atomD ); |
1261 |
painCave.isFatal = 1; |
1262 |
simError(); |
1263 |
} |
1264 |
|
1265 |
if( !strcmp( currentTorsionType->type, "cubic" ) ){ |
1266 |
index = i + entry_plug->n_bonds + entry_plug->n_bends; |
1267 |
|
1268 |
cTors = new CubicTorsion( *the_atoms[a], *the_atoms[b], |
1269 |
*the_atoms[c], *the_atoms[d] ); |
1270 |
cTors->setConstants( currentTorsionType->k1, currentTorsionType->k2, |
1271 |
currentTorsionType->k3, currentTorsionType->k4 ); |
1272 |
the_sris[index] = cTors; |
1273 |
} |
1274 |
} |
1275 |
|
1276 |
|
1277 |
// clean up the memory |
1278 |
|
1279 |
delete headTorsionType; |
1280 |
|
1281 |
#ifdef IS_MPI |
1282 |
sprintf( checkPointMsg, "TraPPE_Ex torsions initialized succesfully" ); |
1283 |
MPIcheckPoint(); |
1284 |
#endif // is_mpi |
1285 |
|
1286 |
} |
1287 |
|
1288 |
void TraPPE_ExFF::fastForward( char* stopText, char* searchOwner ){ |
1289 |
|
1290 |
int foundText = 0; |
1291 |
char* the_token; |
1292 |
|
1293 |
rewind( frcFile ); |
1294 |
lineNum = 0; |
1295 |
|
1296 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
1297 |
lineNum++; |
1298 |
if( eof_test == NULL ){ |
1299 |
sprintf( painCave.errMsg, "Error fast forwarding force file for %s: " |
1300 |
" file is empty.\n", |
1301 |
searchOwner ); |
1302 |
painCave.isFatal = 1; |
1303 |
simError(); |
1304 |
} |
1305 |
|
1306 |
|
1307 |
while( !foundText ){ |
1308 |
while( eof_test != NULL && readLine[0] != '#' ){ |
1309 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
1310 |
lineNum++; |
1311 |
} |
1312 |
if( eof_test == NULL ){ |
1313 |
sprintf( painCave.errMsg, |
1314 |
"Error fast forwarding force file for %s at " |
1315 |
"line %d: file ended unexpectedly.\n", |
1316 |
searchOwner, |
1317 |
lineNum ); |
1318 |
painCave.isFatal = 1; |
1319 |
simError(); |
1320 |
} |
1321 |
|
1322 |
the_token = strtok( readLine, " ,;\t#\n" ); |
1323 |
foundText = !strcmp( stopText, the_token ); |
1324 |
|
1325 |
if( !foundText ){ |
1326 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
1327 |
lineNum++; |
1328 |
|
1329 |
if( eof_test == NULL ){ |
1330 |
sprintf( painCave.errMsg, |
1331 |
"Error fast forwarding force file for %s at " |
1332 |
"line %d: file ended unexpectedly.\n", |
1333 |
searchOwner, |
1334 |
lineNum ); |
1335 |
painCave.isFatal = 1; |
1336 |
simError(); |
1337 |
} |
1338 |
} |
1339 |
} |
1340 |
} |
1341 |
|
1342 |
|
1343 |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){ |
1344 |
|
1345 |
char* the_token; |
1346 |
|
1347 |
the_token = strtok( lineBuffer, " \n\t,;" ); |
1348 |
if( the_token != NULL ){ |
1349 |
|
1350 |
strcpy( info.name, the_token ); |
1351 |
|
1352 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1353 |
sprintf( painCave.errMsg, |
1354 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
1355 |
painCave.isFatal = 1; |
1356 |
simError(); |
1357 |
} |
1358 |
|
1359 |
info.isDipole = atoi( the_token ); |
1360 |
|
1361 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1362 |
sprintf( painCave.errMsg, |
1363 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
1364 |
painCave.isFatal = 1; |
1365 |
simError(); |
1366 |
} |
1367 |
|
1368 |
info.isSSD = atoi( the_token ); |
1369 |
|
1370 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1371 |
sprintf( painCave.errMsg, |
1372 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
1373 |
painCave.isFatal = 1; |
1374 |
simError(); |
1375 |
} |
1376 |
|
1377 |
info.mass = atof( the_token ); |
1378 |
|
1379 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1380 |
sprintf( painCave.errMsg, |
1381 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
1382 |
painCave.isFatal = 1; |
1383 |
simError(); |
1384 |
} |
1385 |
|
1386 |
info.epslon = atof( the_token ); |
1387 |
|
1388 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1389 |
sprintf( painCave.errMsg, |
1390 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
1391 |
painCave.isFatal = 1; |
1392 |
simError(); |
1393 |
} |
1394 |
|
1395 |
info.sigma = atof( the_token ); |
1396 |
|
1397 |
if( info.isDipole ){ |
1398 |
|
1399 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1400 |
sprintf( painCave.errMsg, |
1401 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
1402 |
painCave.isFatal = 1; |
1403 |
simError(); |
1404 |
} |
1405 |
|
1406 |
info.dipole = atof( the_token ); |
1407 |
} |
1408 |
else info.dipole = 0.0; |
1409 |
|
1410 |
if( info.isSSD ){ |
1411 |
|
1412 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1413 |
sprintf( painCave.errMsg, |
1414 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
1415 |
painCave.isFatal = 1; |
1416 |
simError(); |
1417 |
} |
1418 |
|
1419 |
info.w0 = atof( the_token ); |
1420 |
|
1421 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1422 |
sprintf( painCave.errMsg, |
1423 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
1424 |
painCave.isFatal = 1; |
1425 |
simError(); |
1426 |
} |
1427 |
|
1428 |
info.v0 = atof( the_token ); |
1429 |
} |
1430 |
else info.v0 = info.w0 = 0.0; |
1431 |
|
1432 |
return 1; |
1433 |
} |
1434 |
else return 0; |
1435 |
} |
1436 |
|
1437 |
int parseBond( char *lineBuffer, int lineNum, bondStruct &info ){ |
1438 |
|
1439 |
char* the_token; |
1440 |
|
1441 |
the_token = strtok( lineBuffer, " \n\t,;" ); |
1442 |
if( the_token != NULL ){ |
1443 |
|
1444 |
strcpy( info.nameA, the_token ); |
1445 |
|
1446 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1447 |
sprintf( painCave.errMsg, |
1448 |
"Error parseing BondTypes: line %d\n", lineNum ); |
1449 |
painCave.isFatal = 1; |
1450 |
simError(); |
1451 |
} |
1452 |
|
1453 |
strcpy( info.nameB, the_token ); |
1454 |
|
1455 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1456 |
sprintf( painCave.errMsg, |
1457 |
"Error parseing BondTypes: line %d\n", lineNum ); |
1458 |
painCave.isFatal = 1; |
1459 |
simError(); |
1460 |
} |
1461 |
|
1462 |
strcpy( info.type, the_token ); |
1463 |
|
1464 |
if( !strcmp( info.type, "fixed" ) ){ |
1465 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1466 |
sprintf( painCave.errMsg, |
1467 |
"Error parseing BondTypes: line %d\n", lineNum ); |
1468 |
painCave.isFatal = 1; |
1469 |
simError(); |
1470 |
} |
1471 |
|
1472 |
info.d0 = atof( the_token ); |
1473 |
} |
1474 |
else{ |
1475 |
sprintf( painCave.errMsg, |
1476 |
"Unknown TraPPE_Ex bond type \"%s\" at line %d\n", |
1477 |
info.type, |
1478 |
lineNum ); |
1479 |
painCave.isFatal = 1; |
1480 |
simError(); |
1481 |
} |
1482 |
|
1483 |
return 1; |
1484 |
} |
1485 |
else return 0; |
1486 |
} |
1487 |
|
1488 |
|
1489 |
int parseBend( char *lineBuffer, int lineNum, bendStruct &info ){ |
1490 |
|
1491 |
char* the_token; |
1492 |
|
1493 |
the_token = strtok( lineBuffer, " \n\t,;" ); |
1494 |
if( the_token != NULL ){ |
1495 |
|
1496 |
strcpy( info.nameA, the_token ); |
1497 |
|
1498 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1499 |
sprintf( painCave.errMsg, |
1500 |
"Error parseing BondTypes: line %d\n", lineNum ); |
1501 |
painCave.isFatal = 1; |
1502 |
simError(); |
1503 |
} |
1504 |
|
1505 |
strcpy( info.nameB, the_token ); |
1506 |
|
1507 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1508 |
sprintf( painCave.errMsg, |
1509 |
"Error parseing BondTypes: line %d\n", lineNum ); |
1510 |
painCave.isFatal = 1; |
1511 |
simError(); |
1512 |
} |
1513 |
|
1514 |
strcpy( info.nameC, the_token ); |
1515 |
|
1516 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1517 |
sprintf( painCave.errMsg, |
1518 |
"Error parseing BondTypes: line %d\n", lineNum ); |
1519 |
painCave.isFatal = 1; |
1520 |
simError(); |
1521 |
} |
1522 |
|
1523 |
strcpy( info.type, the_token ); |
1524 |
|
1525 |
if( !strcmp( info.type, "quadratic" ) ){ |
1526 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1527 |
sprintf( painCave.errMsg, |
1528 |
"Error parseing BendTypes: line %d\n", lineNum ); |
1529 |
painCave.isFatal = 1; |
1530 |
simError(); |
1531 |
} |
1532 |
|
1533 |
info.k1 = atof( the_token ); |
1534 |
|
1535 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1536 |
sprintf( painCave.errMsg, |
1537 |
"Error parseing BendTypes: line %d\n", lineNum ); |
1538 |
painCave.isFatal = 1; |
1539 |
simError(); |
1540 |
} |
1541 |
|
1542 |
info.k2 = atof( the_token ); |
1543 |
|
1544 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1545 |
sprintf( painCave.errMsg, |
1546 |
"Error parseing BendTypes: line %d\n", lineNum ); |
1547 |
painCave.isFatal = 1; |
1548 |
simError(); |
1549 |
} |
1550 |
|
1551 |
info.k3 = atof( the_token ); |
1552 |
|
1553 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1554 |
sprintf( painCave.errMsg, |
1555 |
"Error parseing BendTypes: line %d\n", lineNum ); |
1556 |
painCave.isFatal = 1; |
1557 |
simError(); |
1558 |
} |
1559 |
|
1560 |
info.t0 = atof( the_token ); |
1561 |
} |
1562 |
|
1563 |
else{ |
1564 |
sprintf( painCave.errMsg, |
1565 |
"Unknown TraPPE_Ex bend type \"%s\" at line %d\n", |
1566 |
info.type, |
1567 |
lineNum ); |
1568 |
painCave.isFatal = 1; |
1569 |
simError(); |
1570 |
} |
1571 |
|
1572 |
return 1; |
1573 |
} |
1574 |
else return 0; |
1575 |
} |
1576 |
|
1577 |
int parseTorsion( char *lineBuffer, int lineNum, torsionStruct &info ){ |
1578 |
|
1579 |
char* the_token; |
1580 |
|
1581 |
the_token = strtok( lineBuffer, " \n\t,;" ); |
1582 |
if( the_token != NULL ){ |
1583 |
|
1584 |
strcpy( info.nameA, the_token ); |
1585 |
|
1586 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1587 |
sprintf( painCave.errMsg, |
1588 |
"Error parseing TorsionTypes: line %d\n", lineNum ); |
1589 |
painCave.isFatal = 1; |
1590 |
simError(); |
1591 |
} |
1592 |
|
1593 |
strcpy( info.nameB, the_token ); |
1594 |
|
1595 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1596 |
sprintf( painCave.errMsg, |
1597 |
"Error parseing TorsionTypes: line %d\n", lineNum ); |
1598 |
painCave.isFatal = 1; |
1599 |
simError(); |
1600 |
} |
1601 |
|
1602 |
strcpy( info.nameC, the_token ); |
1603 |
|
1604 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1605 |
sprintf( painCave.errMsg, |
1606 |
"Error parseing TorsionTypes: line %d\n", lineNum ); |
1607 |
painCave.isFatal = 1; |
1608 |
simError(); |
1609 |
} |
1610 |
|
1611 |
strcpy( info.nameD, the_token ); |
1612 |
|
1613 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1614 |
sprintf( painCave.errMsg, |
1615 |
"Error parseing TorsionTypes: line %d\n", lineNum ); |
1616 |
painCave.isFatal = 1; |
1617 |
simError(); |
1618 |
} |
1619 |
|
1620 |
strcpy( info.type, the_token ); |
1621 |
|
1622 |
if( !strcmp( info.type, "cubic" ) ){ |
1623 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1624 |
sprintf( painCave.errMsg, |
1625 |
"Error parseing TorsionTypes: line %d\n", lineNum ); |
1626 |
painCave.isFatal = 1; |
1627 |
simError(); |
1628 |
} |
1629 |
|
1630 |
info.k1 = atof( the_token ); |
1631 |
|
1632 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1633 |
sprintf( painCave.errMsg, |
1634 |
"Error parseing TorsionTypes: line %d\n", lineNum ); |
1635 |
painCave.isFatal = 1; |
1636 |
simError(); |
1637 |
} |
1638 |
|
1639 |
info.k2 = atof( the_token ); |
1640 |
|
1641 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1642 |
sprintf( painCave.errMsg, |
1643 |
"Error parseing TorsionTypes: line %d\n", lineNum ); |
1644 |
painCave.isFatal = 1; |
1645 |
simError(); |
1646 |
} |
1647 |
|
1648 |
info.k3 = atof( the_token ); |
1649 |
|
1650 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1651 |
sprintf( painCave.errMsg, |
1652 |
"Error parseing TorsionTypes: line %d\n", lineNum ); |
1653 |
painCave.isFatal = 1; |
1654 |
simError(); |
1655 |
} |
1656 |
|
1657 |
info.k4 = atof( the_token ); |
1658 |
|
1659 |
} |
1660 |
|
1661 |
else{ |
1662 |
sprintf( painCave.errMsg, |
1663 |
"Unknown TraPPE_Ex torsion type \"%s\" at line %d\n", |
1664 |
info.type, |
1665 |
lineNum ); |
1666 |
painCave.isFatal = 1; |
1667 |
simError(); |
1668 |
} |
1669 |
|
1670 |
return 1; |
1671 |
} |
1672 |
|
1673 |
else return 0; |
1674 |
} |