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 |
|
11 |
|
12 |
#ifdef IS_MPI |
13 |
|
14 |
int myNode; |
15 |
|
16 |
// Declare the structures that will be passed by MPI |
17 |
|
18 |
typedef struct{ |
19 |
char name[15]; |
20 |
double mass; |
21 |
double epslon; |
22 |
double sigma; |
23 |
double dipole; |
24 |
int isDipole; |
25 |
int last; // 0 -> default |
26 |
// 1 -> tells nodes to stop listening |
27 |
// -1 -> an error has occured. (handled in mpiForceField) |
28 |
} atomStruct; |
29 |
MPI_Datatype mpiAtomStructType; |
30 |
|
31 |
typedef struct{ |
32 |
char nameA[15]; |
33 |
char nameB[15]; |
34 |
char type[30]; |
35 |
double d0; |
36 |
int last; // 0 -> default |
37 |
// 1 -> tells nodes to stop listening |
38 |
// -1 -> an error has occured. (handled in mpiForceField) |
39 |
} bondStruct; |
40 |
MPI_Datatype mpiBondStructType; |
41 |
|
42 |
typedef struct{ |
43 |
char nameA[15]; |
44 |
char nameB[15]; |
45 |
char nameC[15]; |
46 |
char type[30]; |
47 |
double k1, k2, k3, t0; |
48 |
int last; // 0 -> default |
49 |
// 1 -> tells nodes to stop listening |
50 |
// -1 -> an error has occured. (handled in mpiForceField) |
51 |
} bendStruct; |
52 |
MPI_Datatype mpiBendStructType; |
53 |
|
54 |
typedef struct{ |
55 |
char nameA[15]; |
56 |
char nameB[15]; |
57 |
char nameC[15]; |
58 |
char nameD[15]; |
59 |
char type[30]; |
60 |
double k1, k2, k3, k4; |
61 |
int last; // 0 -> default |
62 |
// 1 -> tells nodes to stop listening |
63 |
// -1 -> an error has occured. (handled in mpiForceField) |
64 |
} TorsionStruct; |
65 |
MPI_Datatype mpiTorsionStructType; |
66 |
|
67 |
#endif |
68 |
|
69 |
|
70 |
|
71 |
TraPPE_ExFF::TraPPE_ExFF(){ |
72 |
|
73 |
char fileName[200]; |
74 |
char* ffPath_env = "FORCE_PARAM_PATH"; |
75 |
char* ffPath; |
76 |
char temp[200]; |
77 |
|
78 |
#ifdef IS_MPI |
79 |
int i; |
80 |
int mpiError; |
81 |
|
82 |
mpiError = MPI_Comm_rank(MPI_COMM_WORLD,&myNode); |
83 |
|
84 |
atomStruct atomProto; // mpiPrototype |
85 |
int atomBC[3] = {15,4,2}; // block counts |
86 |
MPI_Aint atomDspls[3]; // displacements |
87 |
MPI_Datatype atomMbrTypes[3]; // member mpi types |
88 |
|
89 |
|
90 |
|
91 |
MPI_Address(&atomProto.name, &atomDspls[0]); |
92 |
MPI_Address(&atomProto.mass, &atomDspls[1]); |
93 |
MPI_Address(&atomProto.isDipole, &atomDspls[2]); |
94 |
|
95 |
atomMbrTypes[0] = MPI_CHAR; |
96 |
atomMbrTypes[1] = MPI_DOUBLE; |
97 |
atomMbrTypes[2] = MPI_INT; |
98 |
|
99 |
for (i=2; i >= 0; i--) atomDspls[i] -= atomDspls[0]; |
100 |
|
101 |
MPI_Type_struct(3, atomBC, atomDspls, atomMbrTypes, &mpiAtomStructType); |
102 |
MPI_Type_commit(&mpiAtomStructType); |
103 |
|
104 |
|
105 |
|
106 |
|
107 |
if( myNode == 0 ){ |
108 |
#endif |
109 |
|
110 |
// generate the force file name |
111 |
|
112 |
strcpy( fileName, "TraPPE_Ex.frc" ); |
113 |
fprintf( stderr,"Trying to open %s\n", fileName ); |
114 |
|
115 |
// attempt to open the file in the current directory first. |
116 |
|
117 |
frcFile = fopen( fileName, "r" ); |
118 |
|
119 |
if( frcFile == NULL ){ |
120 |
|
121 |
// next see if the force path enviorment variable is set |
122 |
|
123 |
ffPath = getenv( ffPath_env ); |
124 |
if( ffPath == NULL ) { |
125 |
fprintf( stderr, |
126 |
"Error opening the force field parameter file: %s\n" |
127 |
"Have you tried setting the FORCE_PARAM_PATH environment " |
128 |
"vairable?\n", |
129 |
fileName ); |
130 |
exit( 8 ); |
131 |
} |
132 |
|
133 |
|
134 |
strcpy( temp, ffPath ); |
135 |
strcat( temp, "/" ); |
136 |
strcat( temp, fileName ); |
137 |
strcpy( fileName, temp ); |
138 |
|
139 |
frcFile = fopen( fileName, "r" ); |
140 |
|
141 |
if( frcFile == NULL ){ |
142 |
|
143 |
fprintf( stderr, |
144 |
"Error opening the force field parameter file: %s\n" |
145 |
"Have you tried setting the FORCE_PARAM_PATH environment " |
146 |
"vairable?\n", |
147 |
fileName ); |
148 |
exit( 8 ); |
149 |
} |
150 |
} |
151 |
#ifdef IS_MPI |
152 |
} |
153 |
#endif |
154 |
} |
155 |
|
156 |
|
157 |
TraPPE_ExFF::~TraPPE_ExFF(){ |
158 |
|
159 |
fclose( frcFile ); |
160 |
} |
161 |
|
162 |
void TraPPE_ExFF::initializeAtoms( void ){ |
163 |
|
164 |
class LinkedType { |
165 |
public: |
166 |
LinkedType(){ |
167 |
next = NULL; |
168 |
name[0] = '\0'; |
169 |
} |
170 |
~LinkedType(){ if( next != NULL ) delete next; } |
171 |
|
172 |
LinkedType* find(char* key){ |
173 |
if( !strcmp(name, key) ) return this; |
174 |
if( next != NULL ) return next->find(key); |
175 |
return NULL; |
176 |
} |
177 |
|
178 |
#ifdef IS_MPI |
179 |
void add( atomStruct &info ){ |
180 |
if( next != NULL ) next->add(info); |
181 |
else{ |
182 |
next = new LinkedType(); |
183 |
strcpy(next->name, info.name); |
184 |
next->isDipole = info.dipole; |
185 |
next->mass = info.mass; |
186 |
next->epslon = info.epslon; |
187 |
next->sigma = info.sigma; |
188 |
next->dipole = info.dipole; |
189 |
} |
190 |
} |
191 |
|
192 |
void duplicate( atomStruct &info ){ |
193 |
strcpy(info.name, name); |
194 |
info.isDipole = dipole; |
195 |
info.mass = mass; |
196 |
info.epslon = epslon; |
197 |
info.sigma = sigma; |
198 |
info.dipole = dipole; |
199 |
info.last = 0; |
200 |
} |
201 |
|
202 |
|
203 |
#endif |
204 |
|
205 |
char name[15]; |
206 |
int isDipole; |
207 |
double mass; |
208 |
double epslon; |
209 |
double sigma; |
210 |
double dipole; |
211 |
LinkedType* next; |
212 |
}; |
213 |
|
214 |
LinkedType* headAtomType; |
215 |
LinkedType* currentAtomType; |
216 |
LinkedType* tempAtomType; |
217 |
|
218 |
char readLine[500]; |
219 |
char* the_token; |
220 |
char* eof_test; |
221 |
int foundAtom = 0; |
222 |
int lineNum = 0; |
223 |
int i; |
224 |
|
225 |
////////////////////////////////////////////////// |
226 |
// a quick water fix |
227 |
|
228 |
double waterI[3][3]; |
229 |
waterI[0][0] = 1.76958347772500; |
230 |
waterI[0][1] = 0.0; |
231 |
waterI[0][2] = 0.0; |
232 |
|
233 |
waterI[1][0] = 0.0; |
234 |
waterI[1][1] = 0.614537057924513; |
235 |
waterI[1][2] = 0.0; |
236 |
|
237 |
waterI[2][0] = 0.0; |
238 |
waterI[2][1] = 0.0; |
239 |
waterI[2][2] = 1.15504641980049; |
240 |
|
241 |
|
242 |
double headI[3][3]; |
243 |
headI[0][0] = 1125; |
244 |
headI[0][1] = 0.0; |
245 |
headI[0][2] = 0.0; |
246 |
|
247 |
headI[1][0] = 0.0; |
248 |
headI[1][1] = 1125; |
249 |
headI[1][2] = 0.0; |
250 |
|
251 |
headI[2][0] = 0.0; |
252 |
headI[2][1] = 0.0; |
253 |
headI[2][2] = 250; |
254 |
|
255 |
|
256 |
|
257 |
////////////////////////////////////////////////// |
258 |
|
259 |
Atom** the_atoms; |
260 |
int nAtoms; |
261 |
the_atoms = entry_plug->atoms; |
262 |
nAtoms = entry_plug->n_atoms; |
263 |
|
264 |
// read in the atom types. |
265 |
|
266 |
rewind( frcFile ); |
267 |
headAtomType = new LinkedType; |
268 |
currentAtomType = headAtomType; |
269 |
|
270 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
271 |
lineNum++; |
272 |
if( eof_test == NULL ){ |
273 |
fprintf( stderr, "Error in reading Atoms from force file.\n" ); |
274 |
exit(8); |
275 |
} |
276 |
|
277 |
|
278 |
while( !foundAtom ){ |
279 |
while( eof_test != NULL && readLine[0] != '#' ){ |
280 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
281 |
lineNum++; |
282 |
} |
283 |
if( eof_test == NULL ){ |
284 |
fprintf( stderr, |
285 |
"Error in reading Atoms from force file at line %d.\n", |
286 |
lineNum ); |
287 |
exit(8); |
288 |
} |
289 |
|
290 |
the_token = strtok( readLine, " ,;\t#\n" ); |
291 |
foundAtom = !strcmp( "AtomTypes", the_token ); |
292 |
|
293 |
if( !foundAtom ){ |
294 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
295 |
lineNum++; |
296 |
|
297 |
if( eof_test == NULL ){ |
298 |
fprintf( stderr, |
299 |
"Error in reading Atoms from force file at line %d.\n", |
300 |
lineNum ); |
301 |
exit(8); |
302 |
} |
303 |
} |
304 |
} |
305 |
|
306 |
// we are now at the AtomTypes section. |
307 |
|
308 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
309 |
lineNum++; |
310 |
|
311 |
if( eof_test == NULL ){ |
312 |
fprintf( stderr, |
313 |
"Error in reading Atoms from force file at line %d.\n", |
314 |
lineNum ); |
315 |
exit(8); |
316 |
} |
317 |
|
318 |
while( readLine[0] != '#' && eof_test != NULL ){ |
319 |
|
320 |
if( readLine[0] != '!' ){ |
321 |
|
322 |
the_token = strtok( readLine, " \n\t,;" ); |
323 |
if( the_token != NULL ){ |
324 |
|
325 |
strcpy( currentAtomType->name, the_token ); |
326 |
|
327 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
328 |
fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); |
329 |
exit(8); |
330 |
} |
331 |
|
332 |
sscanf( the_token, "%d", ¤tAtomType->isDipole ); |
333 |
|
334 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
335 |
fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); |
336 |
exit(8); |
337 |
} |
338 |
|
339 |
sscanf( the_token, "%lf", ¤tAtomType->mass ); |
340 |
|
341 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
342 |
fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); |
343 |
exit(8); |
344 |
} |
345 |
|
346 |
sscanf( the_token, "%lf", ¤tAtomType->epslon ); |
347 |
|
348 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
349 |
fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); |
350 |
exit(8); |
351 |
} |
352 |
|
353 |
sscanf( the_token, "%lf", ¤tAtomType->sigma ); |
354 |
|
355 |
if( currentAtomType->isDipole ){ |
356 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
357 |
fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum ); |
358 |
exit(8); |
359 |
} |
360 |
|
361 |
sscanf( the_token, "%lf", ¤tAtomType->dipole ); |
362 |
} |
363 |
} |
364 |
} |
365 |
|
366 |
tempAtomType = new LinkedType; |
367 |
currentAtomType->next = tempAtomType; |
368 |
currentAtomType = tempAtomType; |
369 |
|
370 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
371 |
lineNum++; |
372 |
} |
373 |
|
374 |
|
375 |
// initialize the atoms |
376 |
|
377 |
DirectionalAtom* dAtom; |
378 |
|
379 |
for( i=0; i<nAtoms; i++ ){ |
380 |
|
381 |
currentAtomType = headAtomType->find( the_atoms[i]->getType() ); |
382 |
if( currentAtomType == NULL ){ |
383 |
fprintf( stderr, "AtomType error, %s not found in force file.\n", |
384 |
the_atoms[i]->getType() ); |
385 |
exit(8); |
386 |
} |
387 |
|
388 |
the_atoms[i]->setMass( currentAtomType->mass ); |
389 |
the_atoms[i]->setEpslon( currentAtomType->epslon ); |
390 |
the_atoms[i]->setSigma( currentAtomType->sigma ); |
391 |
the_atoms[i]->setLJ(); |
392 |
|
393 |
if( currentAtomType->isDipole ){ |
394 |
if( the_atoms[i]->isDirectional() ){ |
395 |
|
396 |
dAtom = (DirectionalAtom *) the_atoms[i]; |
397 |
dAtom->setMu( currentAtomType->dipole ); |
398 |
dAtom->setHasDipole( 1 ); |
399 |
dAtom->setJx( 0.0 ); |
400 |
dAtom->setJy( 0.0 ); |
401 |
dAtom->setJz( 0.0 ); |
402 |
|
403 |
if(!strcmp("SSD",the_atoms[i]->getType())){ |
404 |
dAtom->setI( waterI ); |
405 |
dAtom->setSSD( 1 ); |
406 |
} |
407 |
else if(!strcmp("HEAD",the_atoms[i]->getType())){ |
408 |
dAtom->setI( headI ); |
409 |
dAtom->setSSD( 0 ); |
410 |
} |
411 |
else{ |
412 |
fprintf(stderr, |
413 |
"AtmType error, %s does not have a moment of inertia set.\n", |
414 |
the_atoms[i]->getType() ); |
415 |
exit(8); |
416 |
} |
417 |
entry_plug->n_dipoles++; |
418 |
} |
419 |
else{ |
420 |
std::cerr |
421 |
<< "TraPPE_ExFF error: Atom \"" |
422 |
<< currentAtomType->name << "\" is a dipole, yet no standard" |
423 |
<< " orientation was specifed in the BASS file.\n"; |
424 |
exit(8); |
425 |
} |
426 |
} |
427 |
else{ |
428 |
if( the_atoms[i]->isDirectional() ){ |
429 |
std::cerr |
430 |
<< "TraPPE_ExFF error: Atom \"" |
431 |
<< currentAtomType->name << "\" was given a standard orientation" |
432 |
<< " in the BASS file, yet it is not a dipole.\n"; |
433 |
exit(8); |
434 |
} |
435 |
} |
436 |
} |
437 |
|
438 |
|
439 |
// clean up the memory |
440 |
|
441 |
delete headAtomType; |
442 |
} |
443 |
|
444 |
void TraPPE_ExFF::initializeBonds( bond_pair* the_bonds ){ |
445 |
|
446 |
class LinkedType { |
447 |
public: |
448 |
LinkedType(){ |
449 |
next = NULL; |
450 |
nameA[0] = '\0'; |
451 |
nameB[0] = '\0'; |
452 |
type[0] = '\0'; |
453 |
} |
454 |
~LinkedType(){ if( next != NULL ) delete next; } |
455 |
|
456 |
LinkedType* find(char* key1, char* key2){ |
457 |
if( !strcmp(nameA, key1 ) && !strcmp( nameB, key2 ) ) return this; |
458 |
if( !strcmp(nameA, key2 ) && !strcmp( nameB, key1 ) ) return this; |
459 |
if( next != NULL ) return next->find(key1, key2); |
460 |
return NULL; |
461 |
} |
462 |
|
463 |
#ifdef IS_MPI |
464 |
void add( bondStruct &info ){ |
465 |
if( next != NULL ) next->add(info); |
466 |
else{ |
467 |
next = new LinkedType(); |
468 |
strcpy(next->nameA, info.nameA); |
469 |
strcpy(next->nameB, info.nameB); |
470 |
strcpy(next->type, info.type); |
471 |
next->d0 = info.d0; |
472 |
} |
473 |
} |
474 |
|
475 |
void duplicate( bondStruct &info ){ |
476 |
strcpy(info.nameA, nameA); |
477 |
strcpy(info.nameB, nameB); |
478 |
strcpy(info.type, type); |
479 |
info.d0 = d0; |
480 |
info.last = 0; |
481 |
} |
482 |
|
483 |
|
484 |
#endif |
485 |
|
486 |
char nameA[15]; |
487 |
char nameB[15]; |
488 |
char type[30]; |
489 |
double d0; |
490 |
|
491 |
LinkedType* next; |
492 |
}; |
493 |
|
494 |
|
495 |
|
496 |
LinkedType* headBondType; |
497 |
LinkedType* currentBondType; |
498 |
LinkedType* tempBondType; |
499 |
|
500 |
char readLine[500]; |
501 |
char* the_token; |
502 |
char* eof_test; |
503 |
int foundBond = 0; |
504 |
int lineNum = 0; |
505 |
int i, a, b; |
506 |
char* atomA; |
507 |
char* atomB; |
508 |
|
509 |
SRI **the_sris; |
510 |
Atom** the_atoms; |
511 |
int nBonds; |
512 |
the_sris = entry_plug->sr_interactions; |
513 |
the_atoms = entry_plug->atoms; |
514 |
nBonds = entry_plug->n_bonds; |
515 |
|
516 |
// read in the bond types. |
517 |
|
518 |
rewind( frcFile ); |
519 |
headBondType = new LinkedType; |
520 |
currentBondType = headBondType; |
521 |
|
522 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
523 |
lineNum++; |
524 |
if( eof_test == NULL ){ |
525 |
fprintf( stderr, "Error in reading Bonds from force file.\n" ); |
526 |
exit(8); |
527 |
} |
528 |
|
529 |
|
530 |
while( !foundBond ){ |
531 |
while( eof_test != NULL && readLine[0] != '#' ){ |
532 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
533 |
lineNum++; |
534 |
} |
535 |
if( eof_test == NULL ){ |
536 |
fprintf( stderr, |
537 |
"Error in reading Bonds from force file at line %d.\n", |
538 |
lineNum ); |
539 |
exit(8); |
540 |
} |
541 |
|
542 |
the_token = strtok( readLine, " ,;\t#\n" ); |
543 |
foundBond = !strcmp( "BondTypes", the_token ); |
544 |
|
545 |
if( !foundBond ){ |
546 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
547 |
lineNum++; |
548 |
|
549 |
if( eof_test == NULL ){ |
550 |
fprintf( stderr, |
551 |
"Error in reading Bonds from force file at line %d.\n", |
552 |
lineNum ); |
553 |
exit(8); |
554 |
} |
555 |
} |
556 |
} |
557 |
|
558 |
// we are now at the BondTypes section. |
559 |
|
560 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
561 |
lineNum++; |
562 |
|
563 |
if( eof_test == NULL ){ |
564 |
fprintf( stderr, |
565 |
"Error in reading Bonds from force file at line %d.\n", |
566 |
lineNum ); |
567 |
exit(8); |
568 |
} |
569 |
|
570 |
while( readLine[0] != '#' && eof_test != NULL ){ |
571 |
|
572 |
if( readLine[0] != '!' ){ |
573 |
|
574 |
the_token = strtok( readLine, " \n\t,;" ); |
575 |
if( the_token != NULL ){ |
576 |
|
577 |
strcpy( currentBondType->nameA, the_token ); |
578 |
|
579 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
580 |
fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum ); |
581 |
exit(8); |
582 |
} |
583 |
|
584 |
strcpy( currentBondType->nameB, the_token ); |
585 |
|
586 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
587 |
fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum ); |
588 |
exit(8); |
589 |
} |
590 |
|
591 |
strcpy( currentBondType->type, the_token ); |
592 |
|
593 |
if( !strcmp( currentBondType->type, "fixed" ) ){ |
594 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
595 |
fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum ); |
596 |
exit(8); |
597 |
} |
598 |
|
599 |
sscanf( the_token, "%lf", ¤tBondType->d0 ); |
600 |
} |
601 |
|
602 |
else{ |
603 |
fprintf(stderr, |
604 |
"Unknown TraPPE_Ex bond type \"%s\" at line %d\n", |
605 |
currentBondType->type, |
606 |
lineNum ); |
607 |
exit(8); |
608 |
} |
609 |
} |
610 |
} |
611 |
|
612 |
tempBondType = new LinkedType; |
613 |
currentBondType->next = tempBondType; |
614 |
currentBondType = tempBondType; |
615 |
|
616 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
617 |
lineNum++; |
618 |
} |
619 |
|
620 |
|
621 |
// initialize the Bonds |
622 |
|
623 |
|
624 |
for( i=0; i<nBonds; i++ ){ |
625 |
|
626 |
a = the_bonds[i].a; |
627 |
b = the_bonds[i].b; |
628 |
|
629 |
atomA = the_atoms[a]->getType(); |
630 |
atomB = the_atoms[b]->getType(); |
631 |
currentBondType = headBondType->find( atomA, atomB ); |
632 |
if( currentBondType == NULL ){ |
633 |
fprintf( stderr, "BondType error, %s - %s not found in force file.\n", |
634 |
atomA, atomB ); |
635 |
exit(8); |
636 |
} |
637 |
|
638 |
if( !strcmp( currentBondType->type, "fixed" ) ){ |
639 |
|
640 |
the_sris[i] = new ConstrainedBond( *the_atoms[a], |
641 |
*the_atoms[b], |
642 |
currentBondType->d0 ); |
643 |
entry_plug->n_constraints++; |
644 |
} |
645 |
} |
646 |
|
647 |
|
648 |
// clean up the memory |
649 |
|
650 |
delete headBondType; |
651 |
|
652 |
} |
653 |
|
654 |
void TraPPE_ExFF::initializeBends( bend_set* the_bends ){ |
655 |
|
656 |
class LinkedType { |
657 |
public: |
658 |
LinkedType(){ |
659 |
next = NULL; |
660 |
nameA[0] = '\0'; |
661 |
nameB[0] = '\0'; |
662 |
nameC[0] = '\0'; |
663 |
type[0] = '\0'; |
664 |
} |
665 |
~LinkedType(){ if( next != NULL ) delete next; } |
666 |
|
667 |
LinkedType* find( char* key1, char* key2, char* key3 ){ |
668 |
if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) |
669 |
&& !strcmp( nameC, key3 ) ) return this; |
670 |
if( !strcmp( nameA, key3 ) && !strcmp( nameB, key2 ) |
671 |
&& !strcmp( nameC, key1 ) ) return this; |
672 |
if( next != NULL ) return next->find(key1, key2, key3); |
673 |
return NULL; |
674 |
} |
675 |
|
676 |
#ifdef IS_MPI |
677 |
|
678 |
void add( bendStruct &info ){ |
679 |
if( next != NULL ) next->add(info); |
680 |
else{ |
681 |
next = new LinkedType(); |
682 |
strcpy(next->nameA, info.nameA); |
683 |
strcpy(next->nameB, info.nameB); |
684 |
strcpy(next->nameC, info.nameC); |
685 |
strcpy(next->type, info.type); |
686 |
next->k1 = info.k1; |
687 |
next->k2 = info.k2; |
688 |
next->k3 = info.k3; |
689 |
next->t0 = info.t0; |
690 |
} |
691 |
} |
692 |
|
693 |
void duplicate( bendStruct &info ){ |
694 |
strcpy(info.nameA, nameA); |
695 |
strcpy(info.nameB, nameB); |
696 |
strcpy(info.nameC, nameC); |
697 |
strcpy(info.type, type); |
698 |
info.k1 = k1; |
699 |
info.k2 = k2; |
700 |
info.k3 = k3; |
701 |
info.t0 = t0; |
702 |
info.last = 0; |
703 |
} |
704 |
|
705 |
#endif |
706 |
|
707 |
char nameA[15]; |
708 |
char nameB[15]; |
709 |
char nameC[15]; |
710 |
char type[30]; |
711 |
double k1, k2, k3, t0; |
712 |
|
713 |
LinkedType* next; |
714 |
}; |
715 |
|
716 |
LinkedType* headBendType; |
717 |
LinkedType* currentBendType; |
718 |
LinkedType* tempBendType; |
719 |
|
720 |
char readLine[500]; |
721 |
char* the_token; |
722 |
char* eof_test; |
723 |
int foundBend = 0; |
724 |
int lineNum = 0; |
725 |
int i, a, b, c, index; |
726 |
char* atomA; |
727 |
char* atomB; |
728 |
char* atomC; |
729 |
QuadraticBend* qBend; |
730 |
|
731 |
SRI **the_sris; |
732 |
Atom** the_atoms; |
733 |
int nBends; |
734 |
the_sris = entry_plug->sr_interactions; |
735 |
the_atoms = entry_plug->atoms; |
736 |
nBends = entry_plug->n_bends; |
737 |
|
738 |
// read in the bend types. |
739 |
|
740 |
rewind( frcFile ); |
741 |
headBendType = new LinkedType; |
742 |
currentBendType = headBendType; |
743 |
|
744 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
745 |
lineNum++; |
746 |
if( eof_test == NULL ){ |
747 |
fprintf( stderr, "Error in reading Bends from force file.\n" ); |
748 |
exit(8); |
749 |
} |
750 |
|
751 |
|
752 |
while( !foundBend ){ |
753 |
while( eof_test != NULL && readLine[0] != '#' ){ |
754 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
755 |
lineNum++; |
756 |
} |
757 |
if( eof_test == NULL ){ |
758 |
fprintf( stderr, |
759 |
"Error in reading Bends from force file at line %d.\n", |
760 |
lineNum ); |
761 |
exit(8); |
762 |
} |
763 |
|
764 |
the_token = strtok( readLine, " ,;\t#\n" ); |
765 |
foundBend = !strcmp( "BendTypes", the_token ); |
766 |
|
767 |
if( !foundBend ){ |
768 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
769 |
lineNum++; |
770 |
|
771 |
if( eof_test == NULL ){ |
772 |
fprintf( stderr, |
773 |
"Error in reading Bends from force file at line %d.\n", |
774 |
lineNum ); |
775 |
exit(8); |
776 |
} |
777 |
} |
778 |
} |
779 |
|
780 |
// we are now at the BendTypes section. |
781 |
|
782 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
783 |
lineNum++; |
784 |
|
785 |
if( eof_test == NULL ){ |
786 |
fprintf( stderr, |
787 |
"Error in reading Bends from force file at line %d.\n", |
788 |
lineNum ); |
789 |
exit(8); |
790 |
} |
791 |
|
792 |
while( readLine[0] != '#' && eof_test != NULL ){ |
793 |
|
794 |
if( readLine[0] != '!' ){ |
795 |
|
796 |
the_token = strtok( readLine, " \n\t,;" ); |
797 |
if( the_token != NULL ){ |
798 |
|
799 |
strcpy( currentBendType->nameA, the_token ); |
800 |
|
801 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
802 |
fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); |
803 |
exit(8); |
804 |
} |
805 |
|
806 |
strcpy( currentBendType->nameB, the_token ); |
807 |
|
808 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
809 |
fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); |
810 |
exit(8); |
811 |
} |
812 |
|
813 |
strcpy( currentBendType->nameC, the_token ); |
814 |
|
815 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
816 |
fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); |
817 |
exit(8); |
818 |
} |
819 |
|
820 |
strcpy( currentBendType->type, the_token ); |
821 |
|
822 |
if( !strcmp( currentBendType->type, "quadratic" ) ){ |
823 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
824 |
fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); |
825 |
exit(8); |
826 |
} |
827 |
|
828 |
sscanf( the_token, "%lf", ¤tBendType->k1 ); |
829 |
|
830 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
831 |
fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); |
832 |
exit(8); |
833 |
} |
834 |
|
835 |
sscanf( the_token, "%lf", ¤tBendType->k2 ); |
836 |
|
837 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
838 |
fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); |
839 |
exit(8); |
840 |
} |
841 |
|
842 |
sscanf( the_token, "%lf", ¤tBendType->k3 ); |
843 |
|
844 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
845 |
fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum ); |
846 |
exit(8); |
847 |
} |
848 |
|
849 |
sscanf( the_token, "%lf", ¤tBendType->t0 ); |
850 |
} |
851 |
|
852 |
else{ |
853 |
fprintf(stderr, |
854 |
"Unknown TraPPE_Ex bend type \"%s\" at line %d\n", |
855 |
currentBendType->type, |
856 |
lineNum ); |
857 |
exit(8); |
858 |
} |
859 |
} |
860 |
} |
861 |
|
862 |
tempBendType = new LinkedType; |
863 |
currentBendType->next = tempBendType; |
864 |
currentBendType = tempBendType; |
865 |
|
866 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
867 |
lineNum++; |
868 |
} |
869 |
|
870 |
|
871 |
// initialize the Bends |
872 |
|
873 |
for( i=0; i<nBends; i++ ){ |
874 |
|
875 |
a = the_bends[i].a; |
876 |
b = the_bends[i].b; |
877 |
c = the_bends[i].c; |
878 |
|
879 |
atomA = the_atoms[a]->getType(); |
880 |
atomB = the_atoms[b]->getType(); |
881 |
atomC = the_atoms[c]->getType(); |
882 |
currentBendType = headBendType->find( atomA, atomB, atomC ); |
883 |
if( currentBendType == NULL ){ |
884 |
fprintf( stderr, "BendType error, %s - %s - %s not found" |
885 |
" in force file.\n", |
886 |
atomA, atomB, atomC ); |
887 |
exit(8); |
888 |
} |
889 |
|
890 |
if( !strcmp( currentBendType->type, "quadratic" ) ){ |
891 |
|
892 |
index = i + entry_plug->n_bonds; |
893 |
qBend = new QuadraticBend( *the_atoms[a], |
894 |
*the_atoms[b], |
895 |
*the_atoms[c] ); |
896 |
qBend->setConstants( currentBendType->k1, |
897 |
currentBendType->k2, |
898 |
currentBendType->k3, |
899 |
currentBendType->t0 ); |
900 |
the_sris[index] = qBend; |
901 |
} |
902 |
} |
903 |
|
904 |
|
905 |
// clean up the memory |
906 |
|
907 |
delete headBendType; |
908 |
|
909 |
} |
910 |
|
911 |
void TraPPE_ExFF::initializeTorsions( torsion_set* the_torsions ){ |
912 |
|
913 |
class LinkedType { |
914 |
public: |
915 |
LinkedType(){ |
916 |
next = NULL; |
917 |
nameA[0] = '\0'; |
918 |
nameB[0] = '\0'; |
919 |
nameC[0] = '\0'; |
920 |
type[0] = '\0'; |
921 |
} |
922 |
~LinkedType(){ if( next != NULL ) delete next; } |
923 |
|
924 |
LinkedType* find( char* key1, char* key2, char* key3, char* key4 ){ |
925 |
if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) && |
926 |
!strcmp( nameC, key3 ) && !strcmp( nameD, key4 ) ) return this; |
927 |
|
928 |
if( !strcmp( nameA, key4 ) && !strcmp( nameB, key3 ) && |
929 |
!strcmp( nameC, key2 ) && !strcmp( nameD, key4 ) ) return this; |
930 |
|
931 |
if( next != NULL ) return next->find(key1, key2, key3, key4); |
932 |
return NULL; |
933 |
} |
934 |
|
935 |
#ifdef IS_MPI |
936 |
|
937 |
void add( torsionStruct &info ){ |
938 |
if( next != NULL ) next->add(info); |
939 |
else{ |
940 |
next = new LinkedType(); |
941 |
strcpy(next->nameA, info.nameA); |
942 |
strcpy(next->nameB, info.nameB); |
943 |
strcpy(next->nameC, info.nameC); |
944 |
strcpy(next->type, info.type); |
945 |
next->k1 = info.k1; |
946 |
next->k2 = info.k2; |
947 |
next->k3 = info.k3; |
948 |
next->k4 = info.k4; |
949 |
} |
950 |
} |
951 |
|
952 |
void duplicate( torsionStruct &info ){ |
953 |
strcpy(info.nameA, nameA); |
954 |
strcpy(info.nameB, nameB); |
955 |
strcpy(info.nameC, nameC); |
956 |
strcpy(info.nameD, nameD); |
957 |
strcpy(info.type, type); |
958 |
info.k1 = k1; |
959 |
info.k2 = k2; |
960 |
info.k3 = k3; |
961 |
info.k4 = k4; |
962 |
info.last = 0; |
963 |
} |
964 |
|
965 |
#endif |
966 |
|
967 |
char nameA[15]; |
968 |
char nameB[15]; |
969 |
char nameC[15]; |
970 |
char nameD[15]; |
971 |
char type[30]; |
972 |
double k1, k2, k3, k4; |
973 |
|
974 |
LinkedType* next; |
975 |
}; |
976 |
|
977 |
LinkedType* headTorsionType; |
978 |
LinkedType* currentTorsionType; |
979 |
LinkedType* tempTorsionType; |
980 |
|
981 |
char readLine[500]; |
982 |
char* the_token; |
983 |
char* eof_test; |
984 |
int foundTorsion = 0; |
985 |
int lineNum = 0; |
986 |
int i, a, b, c, d, index; |
987 |
char* atomA; |
988 |
char* atomB; |
989 |
char* atomC; |
990 |
char* atomD; |
991 |
CubicTorsion* cTors; |
992 |
|
993 |
SRI **the_sris; |
994 |
Atom** the_atoms; |
995 |
int nTorsions; |
996 |
the_sris = entry_plug->sr_interactions; |
997 |
the_atoms = entry_plug->atoms; |
998 |
nTorsions = entry_plug->n_torsions; |
999 |
|
1000 |
// read in the torsion types. |
1001 |
|
1002 |
rewind( frcFile ); |
1003 |
headTorsionType = new LinkedType; |
1004 |
currentTorsionType = headTorsionType; |
1005 |
|
1006 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
1007 |
lineNum++; |
1008 |
if( eof_test == NULL ){ |
1009 |
fprintf( stderr, "Error in reading Torsions from force file.\n" ); |
1010 |
exit(8); |
1011 |
} |
1012 |
|
1013 |
|
1014 |
while( !foundTorsion ){ |
1015 |
while( eof_test != NULL && readLine[0] != '#' ){ |
1016 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
1017 |
lineNum++; |
1018 |
} |
1019 |
if( eof_test == NULL ){ |
1020 |
fprintf( stderr, |
1021 |
"Error in reading Torsions from force file at line %d.\n", |
1022 |
lineNum ); |
1023 |
exit(8); |
1024 |
} |
1025 |
|
1026 |
the_token = strtok( readLine, " ,;\t#\n" ); |
1027 |
foundTorsion = !strcmp( "TorsionTypes", the_token ); |
1028 |
|
1029 |
if( !foundTorsion ){ |
1030 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
1031 |
lineNum++; |
1032 |
|
1033 |
if( eof_test == NULL ){ |
1034 |
fprintf( stderr, |
1035 |
"Error in reading Torsions from force file at line %d.\n", |
1036 |
lineNum ); |
1037 |
exit(8); |
1038 |
} |
1039 |
} |
1040 |
} |
1041 |
|
1042 |
// we are now at the TorsionTypes section. |
1043 |
|
1044 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
1045 |
lineNum++; |
1046 |
|
1047 |
if( eof_test == NULL ){ |
1048 |
fprintf( stderr, |
1049 |
"Error in reading Torsions from force file at line %d.\n", |
1050 |
lineNum ); |
1051 |
exit(8); |
1052 |
} |
1053 |
|
1054 |
while( readLine[0] != '#' && eof_test != NULL ){ |
1055 |
|
1056 |
if( readLine[0] != '!' ){ |
1057 |
|
1058 |
the_token = strtok( readLine, " \n\t,;" ); |
1059 |
if( the_token != NULL ){ |
1060 |
|
1061 |
strcpy( currentTorsionType->nameA, the_token ); |
1062 |
|
1063 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1064 |
fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum ); |
1065 |
exit(8); |
1066 |
} |
1067 |
|
1068 |
strcpy( currentTorsionType->nameB, the_token ); |
1069 |
|
1070 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1071 |
fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum ); |
1072 |
exit(8); |
1073 |
} |
1074 |
|
1075 |
strcpy( currentTorsionType->nameC, the_token ); |
1076 |
|
1077 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1078 |
fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum ); |
1079 |
exit(8); |
1080 |
} |
1081 |
|
1082 |
strcpy( currentTorsionType->nameD, the_token ); |
1083 |
|
1084 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1085 |
fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum ); |
1086 |
exit(8); |
1087 |
} |
1088 |
|
1089 |
strcpy( currentTorsionType->type, the_token ); |
1090 |
|
1091 |
if( !strcmp( currentTorsionType->type, "cubic" ) ){ |
1092 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1093 |
fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum ); |
1094 |
exit(8); |
1095 |
} |
1096 |
|
1097 |
sscanf( the_token, "%lf", ¤tTorsionType->k1 ); |
1098 |
|
1099 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1100 |
fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum ); |
1101 |
exit(8); |
1102 |
} |
1103 |
|
1104 |
sscanf( the_token, "%lf", ¤tTorsionType->k2 ); |
1105 |
|
1106 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1107 |
fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum ); |
1108 |
exit(8); |
1109 |
} |
1110 |
|
1111 |
sscanf( the_token, "%lf", ¤tTorsionType->k3 ); |
1112 |
|
1113 |
if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){ |
1114 |
fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum ); |
1115 |
exit(8); |
1116 |
} |
1117 |
|
1118 |
sscanf( the_token, "%lf", ¤tTorsionType->k4 ); |
1119 |
} |
1120 |
|
1121 |
else{ |
1122 |
fprintf(stderr, |
1123 |
"Unknown TraPPE_Ex torsion type \"%s\" at line %d\n", |
1124 |
currentTorsionType->type, |
1125 |
lineNum ); |
1126 |
exit(8); |
1127 |
} |
1128 |
} |
1129 |
} |
1130 |
|
1131 |
tempTorsionType = new LinkedType; |
1132 |
currentTorsionType->next = tempTorsionType; |
1133 |
currentTorsionType = tempTorsionType; |
1134 |
|
1135 |
eof_test = fgets( readLine, sizeof(readLine), frcFile ); |
1136 |
lineNum++; |
1137 |
} |
1138 |
|
1139 |
|
1140 |
// initialize the Torsions |
1141 |
|
1142 |
for( i=0; i<nTorsions; i++ ){ |
1143 |
|
1144 |
a = the_torsions[i].a; |
1145 |
b = the_torsions[i].b; |
1146 |
c = the_torsions[i].c; |
1147 |
d = the_torsions[i].d; |
1148 |
|
1149 |
atomA = the_atoms[a]->getType(); |
1150 |
atomB = the_atoms[b]->getType(); |
1151 |
atomC = the_atoms[c]->getType(); |
1152 |
atomD = the_atoms[d]->getType(); |
1153 |
currentTorsionType = headTorsionType->find( atomA, atomB, atomC, atomD ); |
1154 |
if( currentTorsionType == NULL ){ |
1155 |
fprintf( stderr, "TorsionType error, %s - %s - %s - %s not found" |
1156 |
" in force file.\n", |
1157 |
atomA, atomB, atomC, atomD ); |
1158 |
exit(8); |
1159 |
} |
1160 |
|
1161 |
if( !strcmp( currentTorsionType->type, "cubic" ) ){ |
1162 |
index = i + entry_plug->n_bonds + entry_plug->n_bends; |
1163 |
|
1164 |
cTors = new CubicTorsion( *the_atoms[a], *the_atoms[b], |
1165 |
*the_atoms[c], *the_atoms[d] ); |
1166 |
cTors->setConstants( currentTorsionType->k1, currentTorsionType->k2, |
1167 |
currentTorsionType->k3, currentTorsionType->k4 ); |
1168 |
the_sris[index] = cTors; |
1169 |
} |
1170 |
} |
1171 |
|
1172 |
|
1173 |
// clean up the memory |
1174 |
|
1175 |
delete headTorsionType; |
1176 |
|
1177 |
} |