1 |
#include <stdlib.h> |
2 |
#include <stdio.h> |
3 |
#include <string.h> |
4 |
|
5 |
#include <iostream> |
6 |
using namespace std; |
7 |
|
8 |
#ifdef IS_MPI |
9 |
#include <mpi.h> |
10 |
#endif //is_mpi |
11 |
|
12 |
#include "UseTheForce/ForceFields.hpp" |
13 |
#include "primitives/SRI.hpp" |
14 |
#include "utils/simError.h" |
15 |
#include "types/AtomType.hpp" |
16 |
#include "types/DirectionalAtomType.hpp" |
17 |
#include "UseTheForce/DarkSide/lj_interface.h" |
18 |
#include "UseTheForce/DarkSide/charge_interface.h" |
19 |
#include "UseTheForce/DarkSide/dipole_interface.h" |
20 |
#include "UseTheForce/DarkSide/sticky_interface.h" |
21 |
|
22 |
#ifdef IS_MPI |
23 |
#include "UseTheForce/mpiForceField.h" |
24 |
#endif // is_mpi |
25 |
|
26 |
|
27 |
|
28 |
namespace WATER_NS{ |
29 |
|
30 |
// Declare the structures that will be passed by the parser and MPI |
31 |
|
32 |
typedef struct{ |
33 |
char name[15]; |
34 |
double mass; |
35 |
double epslon; |
36 |
double sigma; |
37 |
double charge; |
38 |
int isDirectional; |
39 |
int isLJ; |
40 |
int isCharge; |
41 |
int ident; |
42 |
int last; // 0 -> default |
43 |
// 1 -> in MPI: tells nodes to stop listening |
44 |
} atomStruct; |
45 |
|
46 |
typedef struct{ |
47 |
char name[15]; |
48 |
double Ixx; |
49 |
double Iyy; |
50 |
double Izz; |
51 |
double dipole; |
52 |
double w0; |
53 |
double v0; |
54 |
double v0p; |
55 |
double rl; |
56 |
double ru; |
57 |
double rlp; |
58 |
double rup; |
59 |
int isDipole; |
60 |
int isSticky; |
61 |
int last; // 0 -> default |
62 |
// 1 -> in MPI: tells nodes to stop listening |
63 |
} directionalStruct; |
64 |
|
65 |
int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ); |
66 |
int parseDirectional( char *lineBuffer, int lineNum, directionalStruct &info ); |
67 |
|
68 |
|
69 |
#ifdef IS_MPI |
70 |
|
71 |
MPI_Datatype mpiAtomStructType; |
72 |
MPI_Datatype mpiDirectionalStructType; |
73 |
|
74 |
#endif |
75 |
|
76 |
class LinkedAtomType { |
77 |
public: |
78 |
LinkedAtomType(){ |
79 |
next = NULL; |
80 |
name[0] = '\0'; |
81 |
} |
82 |
~LinkedAtomType(){ if( next != NULL ) delete next; } |
83 |
|
84 |
LinkedAtomType* find(char* key){ |
85 |
if( !strcmp(name, key) ) return this; |
86 |
if( next != NULL ) return next->find(key); |
87 |
return NULL; |
88 |
} |
89 |
|
90 |
|
91 |
void add( atomStruct &info ){ |
92 |
|
93 |
// check for duplicates |
94 |
|
95 |
if( !strcmp( info.name, name ) ){ |
96 |
sprintf( painCave.errMsg, |
97 |
"Duplicate WATER atom type \"%s\" found in " |
98 |
"the WATER param file./n", |
99 |
name ); |
100 |
painCave.isFatal = 1; |
101 |
simError(); |
102 |
} |
103 |
|
104 |
if( next != NULL ) next->add(info); |
105 |
else{ |
106 |
next = new LinkedAtomType(); |
107 |
strcpy(next->name, info.name); |
108 |
next->isDirectional = info.isDirectional; |
109 |
next->isLJ = info.isLJ; |
110 |
next->isCharge = info.isCharge; |
111 |
next->mass = info.mass; |
112 |
next->epslon = info.epslon; |
113 |
next->sigma = info.sigma; |
114 |
next->charge = info.charge; |
115 |
next->ident = info.ident; |
116 |
} |
117 |
} |
118 |
|
119 |
#ifdef IS_MPI |
120 |
|
121 |
void duplicate( atomStruct &info ){ |
122 |
strcpy(info.name, name); |
123 |
info.isDirectional = isDirectional; |
124 |
info.isLJ = isLJ; |
125 |
info.isCharge = isCharge; |
126 |
info.mass = mass; |
127 |
info.epslon = epslon; |
128 |
info.sigma = sigma; |
129 |
info.charge = charge; |
130 |
info.ident = ident; |
131 |
info.last = 0; |
132 |
} |
133 |
|
134 |
#endif |
135 |
|
136 |
char name[15]; |
137 |
int isDirectional; |
138 |
int isLJ; |
139 |
int isCharge; |
140 |
double mass; |
141 |
double epslon; |
142 |
double sigma; |
143 |
double charge; |
144 |
int ident; |
145 |
LinkedAtomType* next; |
146 |
}; |
147 |
|
148 |
class LinkedDirectionalType { |
149 |
public: |
150 |
LinkedDirectionalType(){ |
151 |
next = NULL; |
152 |
name[0] = '\0'; |
153 |
} |
154 |
~LinkedDirectionalType(){ if( next != NULL ) delete next; } |
155 |
|
156 |
LinkedDirectionalType* find(char* key){ |
157 |
if( !strcmp(name, key) ) return this; |
158 |
if( next != NULL ) return next->find(key); |
159 |
return NULL; |
160 |
} |
161 |
|
162 |
|
163 |
void add( directionalStruct &info ){ |
164 |
|
165 |
// check for duplicates |
166 |
|
167 |
if( !strcmp( info.name, name ) ){ |
168 |
sprintf( painCave.errMsg, |
169 |
"Duplicate WATER directional type \"%s\" found in " |
170 |
"the WATER param file./n", |
171 |
name ); |
172 |
painCave.isFatal = 1; |
173 |
simError(); |
174 |
} |
175 |
|
176 |
if( next != NULL ) next->add(info); |
177 |
else{ |
178 |
next = new LinkedDirectionalType(); |
179 |
strcpy(next->name, info.name); |
180 |
next->isDipole = info.isDipole; |
181 |
next->isSticky = info.isSticky; |
182 |
next->Ixx = info.Ixx; |
183 |
next->Iyy = info.Iyy; |
184 |
next->Izz = info.Izz; |
185 |
next->dipole = info.dipole; |
186 |
next->w0 = info.w0; |
187 |
next->v0 = info.v0; |
188 |
next->v0p = info.v0p; |
189 |
next->rl = info.rl; |
190 |
next->ru = info.ru; |
191 |
next->rlp = info.rlp; |
192 |
next->rup = info.rup; |
193 |
} |
194 |
} |
195 |
|
196 |
#ifdef IS_MPI |
197 |
|
198 |
void duplicate( directionalStruct &info ){ |
199 |
strcpy(info.name, name); |
200 |
info.isDipole = isDipole; |
201 |
info.isSticky = isSticky; |
202 |
info.Ixx = Ixx; |
203 |
info.Iyy = Iyy; |
204 |
info.Izz = Izz; |
205 |
info.dipole = dipole; |
206 |
info.w0 = w0; |
207 |
info.v0 = v0; |
208 |
info.v0p = v0p; |
209 |
info.rl = rl; |
210 |
info.ru = ru; |
211 |
info.rlp = rlp; |
212 |
info.rup = rup; |
213 |
info.last = 0; |
214 |
} |
215 |
|
216 |
#endif |
217 |
|
218 |
char name[15]; |
219 |
int isDipole; |
220 |
int isSticky; |
221 |
double Ixx; |
222 |
double Iyy; |
223 |
double Izz; |
224 |
double dipole; |
225 |
double w0; |
226 |
double v0; |
227 |
double v0p; |
228 |
double rl; |
229 |
double ru; |
230 |
double rlp; |
231 |
double rup; |
232 |
LinkedDirectionalType* next; |
233 |
}; |
234 |
|
235 |
LinkedAtomType* headAtomType; |
236 |
LinkedAtomType* currentAtomType; |
237 |
LinkedDirectionalType* headDirectionalType; |
238 |
LinkedDirectionalType* currentDirectionalType; |
239 |
} // namespace |
240 |
|
241 |
using namespace WATER_NS; |
242 |
|
243 |
//**************************************************************** |
244 |
// begins the actual forcefield stuff. |
245 |
//**************************************************************** |
246 |
|
247 |
|
248 |
WATER::WATER(){ |
249 |
|
250 |
string fileName; |
251 |
string tempString; |
252 |
|
253 |
headAtomType = NULL; |
254 |
currentAtomType = NULL; |
255 |
headDirectionalType = NULL; |
256 |
currentDirectionalType = NULL; |
257 |
|
258 |
#ifdef IS_MPI |
259 |
int i; |
260 |
|
261 |
// ********************************************************************** |
262 |
// Init the atomStruct mpi type |
263 |
|
264 |
atomStruct atomProto; // mpiPrototype |
265 |
int atomBC[3] = {15,4,5}; // block counts |
266 |
MPI_Aint atomDspls[3]; // displacements |
267 |
MPI_Datatype atomMbrTypes[3]; // member mpi types |
268 |
|
269 |
MPI_Address(&atomProto.name, &atomDspls[0]); |
270 |
MPI_Address(&atomProto.mass, &atomDspls[1]); |
271 |
MPI_Address(&atomProto.isDirectional, &atomDspls[2]); |
272 |
|
273 |
atomMbrTypes[0] = MPI_CHAR; |
274 |
atomMbrTypes[1] = MPI_DOUBLE; |
275 |
atomMbrTypes[2] = MPI_INT; |
276 |
|
277 |
for (i=2; i >= 0; i--) atomDspls[i] -= atomDspls[0]; |
278 |
|
279 |
MPI_Type_struct(3, atomBC, atomDspls, atomMbrTypes, &mpiAtomStructType); |
280 |
MPI_Type_commit(&mpiAtomStructType); |
281 |
|
282 |
// *********************************************************************** |
283 |
|
284 |
// ********************************************************************** |
285 |
// Init the directionalStruct mpi type |
286 |
|
287 |
directionalStruct directionalProto; // mpiPrototype |
288 |
int directionalBC[3] = {15,11,3}; // block counts |
289 |
MPI_Aint directionalDspls[3]; // displacements |
290 |
MPI_Datatype directionalMbrTypes[3]; // member mpi types |
291 |
|
292 |
MPI_Address(&directionalProto.name, &directionalDspls[0]); |
293 |
MPI_Address(&directionalProto.Ixx, &directionalDspls[1]); |
294 |
MPI_Address(&directionalProto.isDipole, &directionalDspls[2]); |
295 |
|
296 |
directionalMbrTypes[0] = MPI_CHAR; |
297 |
directionalMbrTypes[1] = MPI_DOUBLE; |
298 |
directionalMbrTypes[2] = MPI_INT; |
299 |
|
300 |
for (i=2; i >= 0; i--) directionalDspls[i] -= directionalDspls[0]; |
301 |
|
302 |
MPI_Type_struct(3, directionalBC, directionalDspls, directionalMbrTypes, |
303 |
&mpiDirectionalStructType); |
304 |
MPI_Type_commit(&mpiDirectionalStructType); |
305 |
|
306 |
// *********************************************************************** |
307 |
|
308 |
if( worldRank == 0 ){ |
309 |
#endif |
310 |
|
311 |
// generate the force file name |
312 |
|
313 |
fileName = "WATER.frc"; |
314 |
|
315 |
// fprintf( stderr,"Trying to open %s\n", fileName ); |
316 |
|
317 |
// attempt to open the file in the current directory first. |
318 |
|
319 |
frcFile = fopen( fileName.c_str(), "r" ); |
320 |
|
321 |
if( frcFile == NULL ){ |
322 |
|
323 |
tempString = ffPath + "/" + fileName; |
324 |
fileName = tempString; |
325 |
|
326 |
frcFile = fopen( fileName.c_str(), "r" ); |
327 |
|
328 |
if( frcFile == NULL ){ |
329 |
|
330 |
sprintf( painCave.errMsg, |
331 |
"Error opening the force field parameter file:\n" |
332 |
"\t%s\n" |
333 |
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
334 |
"variable?\n", |
335 |
fileName.c_str() ); |
336 |
painCave.severity = OOPSE_ERROR; |
337 |
painCave.isFatal = 1; |
338 |
simError(); |
339 |
} |
340 |
} |
341 |
|
342 |
#ifdef IS_MPI |
343 |
} |
344 |
|
345 |
sprintf( checkPointMsg, "WATER file opened sucessfully." ); |
346 |
MPIcheckPoint(); |
347 |
|
348 |
#endif // is_mpi |
349 |
} |
350 |
|
351 |
|
352 |
WATER::~WATER(){ |
353 |
|
354 |
if( headAtomType != NULL ) delete headAtomType; |
355 |
if( headDirectionalType != NULL ) delete headDirectionalType; |
356 |
|
357 |
#ifdef IS_MPI |
358 |
if( worldRank == 0 ){ |
359 |
#endif // is_mpi |
360 |
|
361 |
fclose( frcFile ); |
362 |
|
363 |
#ifdef IS_MPI |
364 |
} |
365 |
#endif // is_mpi |
366 |
} |
367 |
|
368 |
void WATER::cleanMe( void ){ |
369 |
|
370 |
#ifdef IS_MPI |
371 |
|
372 |
// keep the linked list in the mpi version |
373 |
|
374 |
#else // is_mpi |
375 |
|
376 |
// delete the linked list in the single processor version |
377 |
|
378 |
if( headAtomType != NULL ) delete headAtomType; |
379 |
if( headDirectionalType != NULL ) delete headDirectionalType; |
380 |
|
381 |
#endif // is_mpi |
382 |
} |
383 |
|
384 |
|
385 |
void WATER::initForceField(){ |
386 |
|
387 |
initFortran(entry_plug->useReactionField ); |
388 |
} |
389 |
|
390 |
|
391 |
void WATER::readParams( void ){ |
392 |
|
393 |
int identNum, isError; |
394 |
int tempDirect0, tempDirect1; |
395 |
|
396 |
atomStruct atomInfo; |
397 |
directionalStruct directionalInfo; |
398 |
fpos_t *atomPos; |
399 |
AtomType* at; |
400 |
|
401 |
atomInfo.last = 1; // initialize last to have the last set. |
402 |
directionalInfo.last = 1; // if things go well, last will be set to 0 |
403 |
|
404 |
atomPos = new fpos_t; |
405 |
bigSigma = 0.0; |
406 |
|
407 |
#ifdef IS_MPI |
408 |
if( worldRank == 0 ){ |
409 |
#endif |
410 |
|
411 |
// read in the atom types. |
412 |
|
413 |
headAtomType = new LinkedAtomType; |
414 |
headDirectionalType = new LinkedDirectionalType; |
415 |
|
416 |
fastForward( "AtomTypes", "initializeAtoms" ); |
417 |
|
418 |
// we are now at the AtomTypes section. |
419 |
|
420 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
421 |
lineNum++; |
422 |
|
423 |
|
424 |
// read a line, and start parsing out the atom types |
425 |
|
426 |
if( eof_test == NULL ){ |
427 |
sprintf( painCave.errMsg, |
428 |
"Error in reading Atoms from force file at line %d.\n", |
429 |
lineNum ); |
430 |
painCave.isFatal = 1; |
431 |
simError(); |
432 |
} |
433 |
|
434 |
identNum = 1; |
435 |
// stop reading at end of file, or at next section |
436 |
while( readLine[0] != '#' && eof_test != NULL ){ |
437 |
|
438 |
// toss comment lines |
439 |
if( readLine[0] != '!' ){ |
440 |
|
441 |
// the parser returns 0 if the line was blank |
442 |
if( parseAtom( readLine, lineNum, atomInfo ) ){ |
443 |
atomInfo.ident = identNum; |
444 |
headAtomType->add( atomInfo ); |
445 |
if ( atomInfo.isDirectional ) { |
446 |
|
447 |
// if the atom is directional, skip to the directional section |
448 |
// and parse directional info. |
449 |
fgetpos( frcFile, atomPos ); |
450 |
sectionSearch( "DirectionalTypes", atomInfo.name, |
451 |
"initializeDirectional" ); |
452 |
parseDirectional( readLine, lineNum, directionalInfo ); |
453 |
headDirectionalType->add( directionalInfo ); |
454 |
|
455 |
// return to the AtomTypes section |
456 |
fsetpos( frcFile, atomPos ); |
457 |
} |
458 |
identNum++; |
459 |
} |
460 |
} |
461 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
462 |
lineNum++; |
463 |
} |
464 |
|
465 |
#ifdef IS_MPI |
466 |
|
467 |
// send out the linked list to all the other processes |
468 |
|
469 |
sprintf( checkPointMsg, |
470 |
"WATER atom and directional structures read successfully." ); |
471 |
MPIcheckPoint(); |
472 |
currentAtomType = headAtomType->next; //skip the first element place holder |
473 |
currentDirectionalType = headDirectionalType->next; // same w/ directional |
474 |
|
475 |
while( currentAtomType != NULL ){ |
476 |
currentAtomType->duplicate( atomInfo ); |
477 |
|
478 |
sendFrcStruct( &atomInfo, mpiAtomStructType ); |
479 |
|
480 |
sprintf( checkPointMsg, |
481 |
"successfully sent WATER force type: \"%s\"\n", |
482 |
atomInfo.name ); |
483 |
|
484 |
if ( atomInfo.isDirectional ){ |
485 |
// send out the directional linked list to all the other processes |
486 |
|
487 |
currentDirectionalType->duplicate( directionalInfo ); |
488 |
sendFrcStruct( &directionalInfo, mpiDirectionalStructType ); |
489 |
|
490 |
sprintf( checkPointMsg, |
491 |
"successfully sent WATER directional type: \"%s\"\n", |
492 |
directionalInfo.name ); |
493 |
} |
494 |
|
495 |
MPIcheckPoint(); |
496 |
tempDirect0 = atomInfo.isDirectional; |
497 |
currentAtomType = currentAtomType->next; |
498 |
if( tempDirect0 ) |
499 |
currentDirectionalType = currentDirectionalType->next; |
500 |
} |
501 |
|
502 |
atomInfo.last = 1; |
503 |
sendFrcStruct( &atomInfo, mpiAtomStructType ); |
504 |
directionalInfo.last = 1; |
505 |
if ( atomInfo.isDirectional ) |
506 |
sendFrcStruct( &directionalInfo, mpiDirectionalStructType ); |
507 |
} |
508 |
|
509 |
else{ |
510 |
// listen for node 0 to send out the force params |
511 |
|
512 |
MPIcheckPoint(); |
513 |
|
514 |
headAtomType = new LinkedAtomType; |
515 |
headDirectionalType = new LinkedDirectionalType; |
516 |
receiveFrcStruct( &atomInfo, mpiAtomStructType ); |
517 |
|
518 |
if ( atomInfo.isDirectional ) |
519 |
receiveFrcStruct( &directionalInfo, mpiDirectionalStructType ); |
520 |
|
521 |
while( !atomInfo.last ){ |
522 |
|
523 |
headAtomType->add( atomInfo ); |
524 |
|
525 |
MPIcheckPoint(); |
526 |
|
527 |
receiveFrcStruct( &atomInfo, mpiAtomStructType ); |
528 |
|
529 |
if( atomInfo.isDirectional ){ |
530 |
headDirectionalType->add( directionalInfo ); |
531 |
|
532 |
receiveFrcStruct( &directionalInfo, mpiDirectionalStructType ); |
533 |
} |
534 |
} |
535 |
} |
536 |
|
537 |
#endif // is_mpi |
538 |
|
539 |
// dummy variables |
540 |
|
541 |
currentAtomType = headAtomType->next; |
542 |
currentDirectionalType = headDirectionalType->next; |
543 |
|
544 |
while( currentAtomType != NULL ){ |
545 |
if( currentAtomType->name[0] != '\0' ){ |
546 |
if (currentAtomType->isDirectional) |
547 |
at = new DirectionalAtomType(); |
548 |
else |
549 |
at = new AtomType(); |
550 |
|
551 |
if (currentAtomType->isLJ) { |
552 |
at->setLennardJones(); |
553 |
} |
554 |
|
555 |
if (currentAtomType->isCharge) { |
556 |
at->setCharge(); |
557 |
} |
558 |
|
559 |
if (currentAtomType->isDirectional) { |
560 |
if (currentDirectionalType->isDipole) { |
561 |
((DirectionalAtomType*)at)->setDipole(); |
562 |
} |
563 |
|
564 |
if (currentDirectionalType->isSticky) { |
565 |
((DirectionalAtomType*)at)->setSticky(); |
566 |
} |
567 |
} |
568 |
|
569 |
at->setIdent(currentAtomType->ident); |
570 |
at->setName(currentAtomType->name); |
571 |
at->complete(); |
572 |
} |
573 |
currentAtomType = currentAtomType->next; |
574 |
} |
575 |
|
576 |
currentAtomType = headAtomType->next; |
577 |
currentDirectionalType = headDirectionalType->next; |
578 |
|
579 |
while( currentAtomType != NULL ){ |
580 |
|
581 |
if( currentAtomType->isLJ ){ |
582 |
isError = 0; |
583 |
newLJtype( &(currentAtomType->ident), &(currentAtomType->sigma), |
584 |
&(currentAtomType->epslon), &isError); |
585 |
if( isError ){ |
586 |
sprintf( painCave.errMsg, |
587 |
"Error initializing the \"%s\" LJ type in fortran\n", |
588 |
currentAtomType->name ); |
589 |
painCave.isFatal = 1; |
590 |
simError(); |
591 |
} |
592 |
} |
593 |
|
594 |
if (currentAtomType->isCharge) { |
595 |
newChargeType(&(currentAtomType->ident), &(currentAtomType->charge), |
596 |
&isError); |
597 |
if( isError ){ |
598 |
sprintf( painCave.errMsg, |
599 |
"Error initializing the \"%s\" charge type in fortran\n", |
600 |
currentAtomType->name ); |
601 |
painCave.isFatal = 1; |
602 |
simError(); |
603 |
} |
604 |
} |
605 |
|
606 |
if (currentAtomType->isDirectional){ |
607 |
if (currentDirectionalType->isDipole) { |
608 |
newDipoleType(&(currentAtomType->ident), |
609 |
&(currentDirectionalType->dipole), |
610 |
&isError); |
611 |
if( isError ){ |
612 |
sprintf( painCave.errMsg, |
613 |
"Error initializing the \"%s\" dipole type in fortran\n", |
614 |
currentDirectionalType->name ); |
615 |
painCave.isFatal = 1; |
616 |
simError(); |
617 |
} |
618 |
} |
619 |
|
620 |
if(currentDirectionalType->isSticky) { |
621 |
makeStickyType( &(currentDirectionalType->w0), |
622 |
&(currentDirectionalType->v0), |
623 |
&(currentDirectionalType->v0p), |
624 |
&(currentDirectionalType->rl), |
625 |
&(currentDirectionalType->ru), |
626 |
&(currentDirectionalType->rlp), |
627 |
&(currentDirectionalType->rup)); |
628 |
} |
629 |
} |
630 |
currentAtomType = currentAtomType->next; |
631 |
} |
632 |
|
633 |
#ifdef IS_MPI |
634 |
sprintf( checkPointMsg, |
635 |
"WATER atom and directional structures successfully" |
636 |
"sent to fortran\n" ); |
637 |
MPIcheckPoint(); |
638 |
#endif // is_mpi |
639 |
|
640 |
} |
641 |
|
642 |
|
643 |
void WATER::initializeAtoms( int nAtoms, Atom** the_atoms ){ |
644 |
|
645 |
int i,j,k; |
646 |
|
647 |
// initialize the atoms |
648 |
DirectionalAtom* dAtom; |
649 |
double ji[3]; |
650 |
double inertialMat[3][3]; |
651 |
|
652 |
for( i=0; i<nAtoms; i++ ){ |
653 |
currentAtomType = headAtomType->find( the_atoms[i]->getType() ); |
654 |
if( currentAtomType == NULL ){ |
655 |
sprintf( painCave.errMsg, |
656 |
"AtomType error, %s not found in force file.\n", |
657 |
the_atoms[i]->getType() ); |
658 |
painCave.isFatal = 1; |
659 |
simError(); |
660 |
} |
661 |
the_atoms[i]->setMass( currentAtomType->mass ); |
662 |
the_atoms[i]->setIdent( currentAtomType->ident ); |
663 |
|
664 |
if (currentAtomType->isLJ) entry_plug->useLennardJones = 1; |
665 |
if (currentAtomType->isCharge) entry_plug->useCharges = 1; |
666 |
if (currentAtomType->isDirectional) { |
667 |
if (currentDirectionalType->isDipole) entry_plug->useDipoles = 1; |
668 |
if (currentDirectionalType->isSticky) entry_plug->useSticky = 1; |
669 |
} |
670 |
|
671 |
if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma; |
672 |
|
673 |
the_atoms[i]->setHasCharge(currentAtomType->isCharge); |
674 |
|
675 |
if( currentAtomType->isDirectional ){ |
676 |
currentDirectionalType = |
677 |
headDirectionalType->find( the_atoms[i]->getType() ); |
678 |
if( currentDirectionalType == NULL ){ |
679 |
sprintf( painCave.errMsg, |
680 |
"DirectionalType error, %s not found in force file.\n", |
681 |
the_atoms[i]->getType() ); |
682 |
painCave.isFatal = 1; |
683 |
simError(); |
684 |
} |
685 |
|
686 |
// zero out the moments of inertia matrix |
687 |
for( j=0; j<3; j++ ) |
688 |
for( k=0; k<3; k++ ) |
689 |
inertialMat[j][k] = 0.0; |
690 |
|
691 |
// load the force file moments of inertia |
692 |
inertialMat[0][0] = currentDirectionalType->Ixx; |
693 |
inertialMat[1][1] = currentDirectionalType->Iyy; |
694 |
inertialMat[2][2] = currentDirectionalType->Izz; |
695 |
|
696 |
dAtom = (DirectionalAtom *) the_atoms[i]; |
697 |
dAtom->setHasDipole( currentDirectionalType->isDipole ); |
698 |
|
699 |
ji[0] = 0.0; |
700 |
ji[1] = 0.0; |
701 |
ji[2] = 0.0; |
702 |
dAtom->setJ( ji ); |
703 |
dAtom->setI( inertialMat ); |
704 |
|
705 |
entry_plug->n_dipoles++; |
706 |
} |
707 |
} |
708 |
} |
709 |
|
710 |
void WATER::initializeBonds( int nBonds, Bond** BondArray, |
711 |
bond_pair* the_bonds ){ |
712 |
|
713 |
if( nBonds ){ |
714 |
sprintf( painCave.errMsg, |
715 |
"WATER does not support bonds.\n" ); |
716 |
painCave.isFatal = 1; |
717 |
simError(); |
718 |
} |
719 |
} |
720 |
|
721 |
void WATER::initializeBends( int nBends, Bend** bendArray, |
722 |
bend_set* the_bends ){ |
723 |
|
724 |
if( nBends ){ |
725 |
sprintf( painCave.errMsg, |
726 |
"WATER does not support bends.\n" ); |
727 |
painCave.isFatal = 1; |
728 |
simError(); |
729 |
} |
730 |
} |
731 |
|
732 |
void WATER::initializeTorsions( int nTorsions, Torsion** torsionArray, |
733 |
torsion_set* the_torsions ){ |
734 |
|
735 |
if( nTorsions ){ |
736 |
sprintf( painCave.errMsg, |
737 |
"WATER does not support torsions.\n" ); |
738 |
painCave.isFatal = 1; |
739 |
simError(); |
740 |
} |
741 |
} |
742 |
|
743 |
void WATER::fastForward( char* stopText, char* searchOwner ){ |
744 |
|
745 |
int foundText = 0; |
746 |
char* the_token; |
747 |
|
748 |
rewind( frcFile ); |
749 |
lineNum = 0; |
750 |
|
751 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
752 |
lineNum++; |
753 |
if( eof_test == NULL ){ |
754 |
sprintf( painCave.errMsg, "Error fast forwarding force file for %s: " |
755 |
" file is empty.\n", |
756 |
searchOwner ); |
757 |
painCave.isFatal = 1; |
758 |
simError(); |
759 |
} |
760 |
|
761 |
|
762 |
while( !foundText ){ |
763 |
while( eof_test != NULL && readLine[0] != '#' ){ |
764 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
765 |
lineNum++; |
766 |
} |
767 |
if( eof_test == NULL ){ |
768 |
sprintf( painCave.errMsg, |
769 |
"Error fast forwarding force file for %s at " |
770 |
"line %d: file ended unexpectedly.\n", |
771 |
searchOwner, |
772 |
lineNum ); |
773 |
painCave.isFatal = 1; |
774 |
simError(); |
775 |
} |
776 |
|
777 |
the_token = strtok( readLine, " ,;\t#\n" ); |
778 |
foundText = !strcmp( stopText, the_token ); |
779 |
|
780 |
if( !foundText ){ |
781 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
782 |
lineNum++; |
783 |
|
784 |
if( eof_test == NULL ){ |
785 |
sprintf( painCave.errMsg, |
786 |
"Error fast forwarding force file for %s at " |
787 |
"line %d: file ended unexpectedly.\n", |
788 |
searchOwner, |
789 |
lineNum ); |
790 |
painCave.isFatal = 1; |
791 |
simError(); |
792 |
} |
793 |
} |
794 |
} |
795 |
} |
796 |
|
797 |
void WATER::sectionSearch( char* secHead, char* stopText, char* searchOwner ){ |
798 |
|
799 |
int foundSection = 0; |
800 |
int foundText = 0; |
801 |
char* the_token; |
802 |
fpos_t *tempPos; |
803 |
|
804 |
rewind( frcFile ); |
805 |
lineNum = 0; |
806 |
tempPos = new fpos_t; |
807 |
|
808 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
809 |
lineNum++; |
810 |
if( eof_test == NULL ){ |
811 |
sprintf( painCave.errMsg, "Error fast forwarding force file for %s: " |
812 |
" file is empty.\n", |
813 |
searchOwner ); |
814 |
painCave.isFatal = 1; |
815 |
simError(); |
816 |
} |
817 |
|
818 |
while( !foundSection ){ |
819 |
while( eof_test != NULL && readLine[0] != '#' ){ |
820 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
821 |
lineNum++; |
822 |
} |
823 |
if( eof_test == NULL ){ |
824 |
sprintf( painCave.errMsg, |
825 |
"Error fast forwarding force file for %s at " |
826 |
"line %d: file ended unexpectedly.\n", |
827 |
searchOwner, |
828 |
lineNum ); |
829 |
painCave.isFatal = 1; |
830 |
simError(); |
831 |
} |
832 |
the_token = strtok( readLine, " ,;\t#\n" ); |
833 |
foundSection = !strcmp( secHead, the_token ); |
834 |
|
835 |
if( !foundSection ){ |
836 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
837 |
lineNum++; |
838 |
|
839 |
if( eof_test == NULL ){ |
840 |
sprintf( painCave.errMsg, |
841 |
"Error section searching force file for %s at " |
842 |
"line %d: file ended unexpectedly.\n", |
843 |
searchOwner, |
844 |
lineNum ); |
845 |
painCave.isFatal = 1; |
846 |
simError(); |
847 |
} |
848 |
} |
849 |
} |
850 |
|
851 |
while( !foundText ){ |
852 |
|
853 |
fgetpos( frcFile, tempPos ); |
854 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
855 |
lineNum++; |
856 |
|
857 |
if( eof_test == NULL ){ |
858 |
sprintf( painCave.errMsg, |
859 |
"Error fast forwarding force file for %s at " |
860 |
"line %d: file ended unexpectedly.\n", |
861 |
searchOwner, |
862 |
lineNum ); |
863 |
painCave.isFatal = 1; |
864 |
simError(); |
865 |
} |
866 |
|
867 |
the_token = strtok( readLine, " ,;\t#\n" ); |
868 |
if( the_token != NULL ){ |
869 |
foundText = !strcmp( stopText, the_token ); |
870 |
} |
871 |
} |
872 |
fsetpos( frcFile, tempPos ); |
873 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
874 |
lineNum++; |
875 |
} |
876 |
|
877 |
|
878 |
int WATER_NS::parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){ |
879 |
|
880 |
char* the_token; |
881 |
|
882 |
the_token = strtok( lineBuffer, " \n\t,;" ); |
883 |
if( the_token != NULL ){ |
884 |
|
885 |
strcpy( info.name, the_token ); |
886 |
|
887 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
888 |
sprintf( painCave.errMsg, |
889 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
890 |
painCave.isFatal = 1; |
891 |
simError(); |
892 |
} |
893 |
|
894 |
info.isDirectional = atoi( the_token ); |
895 |
|
896 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
897 |
sprintf( painCave.errMsg, |
898 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
899 |
painCave.isFatal = 1; |
900 |
simError(); |
901 |
} |
902 |
|
903 |
info.isLJ = atoi( the_token ); |
904 |
|
905 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
906 |
sprintf( painCave.errMsg, |
907 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
908 |
painCave.isFatal = 1; |
909 |
simError(); |
910 |
} |
911 |
|
912 |
info.isCharge = atoi( the_token ); |
913 |
|
914 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
915 |
sprintf( painCave.errMsg, |
916 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
917 |
painCave.isFatal = 1; |
918 |
simError(); |
919 |
} |
920 |
|
921 |
info.mass = atof( the_token ); |
922 |
|
923 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
924 |
sprintf( painCave.errMsg, |
925 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
926 |
painCave.isFatal = 1; |
927 |
simError(); |
928 |
} |
929 |
|
930 |
info.epslon = atof( the_token ); |
931 |
|
932 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
933 |
sprintf( painCave.errMsg, |
934 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
935 |
painCave.isFatal = 1; |
936 |
simError(); |
937 |
} |
938 |
|
939 |
info.sigma = atof( the_token ); |
940 |
|
941 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
942 |
sprintf( painCave.errMsg, |
943 |
"Error parseing AtomTypes: line %d\n", lineNum ); |
944 |
painCave.isFatal = 1; |
945 |
simError(); |
946 |
} |
947 |
|
948 |
info.charge = atof( the_token ); |
949 |
|
950 |
return 1; |
951 |
} |
952 |
else return 0; |
953 |
} |
954 |
|
955 |
int WATER_NS::parseDirectional( char *lineBuffer, int lineNum, directionalStruct &info ){ |
956 |
|
957 |
char* the_token; |
958 |
|
959 |
the_token = strtok( lineBuffer, " \n\t,;" ); |
960 |
if( the_token != NULL ){ |
961 |
|
962 |
strcpy( info.name, the_token ); |
963 |
|
964 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
965 |
sprintf( painCave.errMsg, |
966 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
967 |
painCave.isFatal = 1; |
968 |
simError(); |
969 |
} |
970 |
|
971 |
info.isDipole = atoi( the_token ); |
972 |
|
973 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
974 |
sprintf( painCave.errMsg, |
975 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
976 |
painCave.isFatal = 1; |
977 |
simError(); |
978 |
} |
979 |
|
980 |
info.isSticky = atoi( the_token ); |
981 |
|
982 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
983 |
sprintf( painCave.errMsg, |
984 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
985 |
painCave.isFatal = 1; |
986 |
simError(); |
987 |
} |
988 |
|
989 |
info.Ixx = atof( the_token ); |
990 |
|
991 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
992 |
sprintf( painCave.errMsg, |
993 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
994 |
painCave.isFatal = 1; |
995 |
simError(); |
996 |
} |
997 |
|
998 |
info.Iyy = atof( the_token ); |
999 |
|
1000 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1001 |
sprintf( painCave.errMsg, |
1002 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
1003 |
painCave.isFatal = 1; |
1004 |
simError(); |
1005 |
} |
1006 |
|
1007 |
info.Izz = atof( the_token ); |
1008 |
|
1009 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1010 |
sprintf( painCave.errMsg, |
1011 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
1012 |
painCave.isFatal = 1; |
1013 |
simError(); |
1014 |
} |
1015 |
|
1016 |
|
1017 |
info.dipole = atof( the_token ); |
1018 |
|
1019 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1020 |
sprintf( painCave.errMsg, |
1021 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
1022 |
painCave.isFatal = 1; |
1023 |
simError(); |
1024 |
} |
1025 |
|
1026 |
info.w0 = atof( the_token ); |
1027 |
|
1028 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1029 |
sprintf( painCave.errMsg, |
1030 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
1031 |
painCave.isFatal = 1; |
1032 |
simError(); |
1033 |
} |
1034 |
|
1035 |
info.v0 = atof( the_token ); |
1036 |
|
1037 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1038 |
sprintf( painCave.errMsg, |
1039 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
1040 |
painCave.isFatal = 1; |
1041 |
simError(); |
1042 |
} |
1043 |
|
1044 |
info.v0p = atof( the_token ); |
1045 |
|
1046 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1047 |
sprintf( painCave.errMsg, |
1048 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
1049 |
painCave.isFatal = 1; |
1050 |
simError(); |
1051 |
} |
1052 |
|
1053 |
info.rl = atof( the_token ); |
1054 |
|
1055 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1056 |
sprintf( painCave.errMsg, |
1057 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
1058 |
painCave.isFatal = 1; |
1059 |
simError(); |
1060 |
} |
1061 |
|
1062 |
info.ru = atof( the_token ); |
1063 |
|
1064 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1065 |
sprintf( painCave.errMsg, |
1066 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
1067 |
painCave.isFatal = 1; |
1068 |
simError(); |
1069 |
} |
1070 |
|
1071 |
info.rlp = atof( the_token ); |
1072 |
|
1073 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1074 |
sprintf( painCave.errMsg, |
1075 |
"Error parseing DirectionalTypes: line %d\n", lineNum ); |
1076 |
painCave.isFatal = 1; |
1077 |
simError(); |
1078 |
} |
1079 |
|
1080 |
info.rup = atof( the_token ); |
1081 |
|
1082 |
return 1; |
1083 |
} |
1084 |
else return 0; |
1085 |
} |