ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp
Revision: 11
Committed: Tue Jul 9 18:40:59 2002 UTC (22 years ago) by mmeineke
File size: 22515 byte(s)
Log Message:
This commit was generated by cvs2svn to compensate for changes in r10, which
included commits to RCS files with non-trunk default branches.

File Contents

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