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