1 /*
2 *   This routine reads the data from a .frc forcefield file and stores it in
3 *   dynamically allocated memory. This allows for fast searches of the
4 *   file.
5 *
6 */
7 
8 #include "msi2lmp.h"
9 #include "Forcefield.h"
10 
11 #include <stdlib.h>
12 #include <string.h>
13 
14 struct FrcFieldItem ff_atomtypes, equivalence, ff_vdw, ff_bond, ff_morse, ff_ang, ff_tor, ff_oop,
15   ff_bonbon, ff_bonang, ff_angtor, ff_angangtor, ff_endbontor, ff_midbontor, ff_angang, ff_bonbon13;
16 
17 
ClearFrcData(void)18 void ClearFrcData(void)
19 {
20   ClearFrcItem(&ff_atomtypes);
21   ClearFrcItem(&equivalence);
22   ClearFrcItem(&ff_vdw);
23   ClearFrcItem(&ff_bond);
24   if (forcefield & FF_TYPE_CLASS1) {  /* Morse bond terms for class I */
25       ClearFrcItem(&ff_morse);
26   }
27   ClearFrcItem(&ff_ang);
28   ClearFrcItem(&ff_tor);
29   ClearFrcItem(&ff_oop);
30 
31   if (forcefield & FF_TYPE_CLASS2) {  /* Cross terms for class II */
32     ClearFrcItem(&ff_bonbon);
33     ClearFrcItem(&ff_bonang);
34     ClearFrcItem(&ff_angtor);
35     ClearFrcItem(&ff_angangtor);
36     ClearFrcItem(&ff_endbontor);
37     ClearFrcItem(&ff_midbontor);
38     ClearFrcItem(&ff_bonbon13);
39     ClearFrcItem(&ff_angang);
40   }
41 }
42 
ReadFrcFile(void)43 void ReadFrcFile(void)
44 {
45   const char *val;
46 
47   /* Open Forcefield File */
48   if ( (FrcF = fopen(FrcFileName,"r")) == NULL ) {
49     fprintf(stderr,"Cannot open %s\n", FrcFileName);
50     exit(72);
51   }
52   InitializeItems(); /* sets keywords, number of members and number of
53                         parameters for each structure */
54   /* allocate memory to and search and fill each structure */
55 
56   val = SearchAndCheck("type");
57 
58   if (forcefield & (FF_TYPE_CLASS1|FF_TYPE_OPLSAA)) {
59     if (strcmp(val,"A-B") == 0) {
60       ljtypeflag = 0;
61     } else {
62       fprintf(stderr," Inconsistent data in force field file.\n"
63               " Expected: 'A-B' type non-bonded data, found: %s\n",val);
64       exit(73);
65     }
66   } else if (forcefield & FF_TYPE_CLASS2) {
67     if (strcmp(val,"r-eps") == 0) {
68       ljtypeflag = 1;
69     } else {
70       fprintf(stderr,"Inconsistent parameter file.\n"
71               " Expected: 'r-eps' type non-bonded data, found: %s\n",val);
72       exit(74);
73     }
74   }
75   free((void *)val);
76 
77   SearchAndFill(&ff_atomtypes);
78   SearchAndFill(&equivalence);
79   SearchAndFill(&ff_vdw);
80   SearchAndFill(&ff_bond);
81   if (forcefield & FF_TYPE_CLASS1) {  /* Morse bond terms for class I */
82     SearchAndFill(&ff_morse);
83   }
84   SearchAndFill(&ff_ang);
85   SearchAndFill(&ff_tor);
86   SearchAndFill(&ff_oop);
87 
88   if (forcefield & FF_TYPE_CLASS2) {  /* Cross terms for class II */
89     SearchAndFill(&ff_bonbon);
90     SearchAndFill(&ff_bonang);
91     SearchAndFill(&ff_angtor);
92     SearchAndFill(&ff_angangtor);
93     SearchAndFill(&ff_endbontor);
94     SearchAndFill(&ff_midbontor);
95     SearchAndFill(&ff_bonbon13);
96     SearchAndFill(&ff_angang);
97   }
98   if (pflag > 1) {
99 
100     fprintf(stderr,"\n Item %s has %d entries\n",
101             ff_atomtypes.keyword,ff_atomtypes.entries);
102     fprintf(stderr," Item %s has %d entries\n",
103             equivalence.keyword,equivalence.entries);
104     fprintf(stderr," Item %s has %d entries\n",
105             ff_vdw.keyword,ff_vdw.entries);
106     fprintf(stderr," Item %s has %d entries\n",
107             ff_bond.keyword,ff_bond.entries);
108     if (forcefield & FF_TYPE_CLASS1)
109       fprintf(stderr," Item %s has %d entries\n",
110               ff_morse.keyword,ff_morse.entries);
111     fprintf(stderr," Item %s has %d entries\n",
112             ff_ang.keyword,ff_ang.entries);
113     if (forcefield & FF_TYPE_CLASS2) {
114       fprintf(stderr," Item %s has %d entries\n",
115               ff_bonbon.keyword,ff_bonbon.entries);
116       fprintf(stderr," Item %s has %d entries\n",
117               ff_bonang.keyword,ff_bonang.entries);
118     }
119     fprintf(stderr," Item %s has %d entries\n",
120             ff_tor.keyword,ff_tor.entries);
121     if (forcefield & FF_TYPE_CLASS2) {
122       fprintf(stderr," Item %s has %d entries\n",
123               ff_angtor.keyword,ff_angtor.entries);
124       fprintf(stderr," Item %s has %d entries\n",
125               ff_angangtor.keyword,ff_angangtor.entries);
126       fprintf(stderr," Item %s has %d entries\n",
127               ff_endbontor.keyword,ff_endbontor.entries);
128       fprintf(stderr," Item %s has %d entries\n",
129               ff_midbontor.keyword,ff_midbontor.entries);
130       fprintf(stderr," Item %s has %d entries\n",
131               ff_bonbon13.keyword,ff_bonbon13.entries);
132     }
133     fprintf(stderr," Item %s has %d entries\n",
134             ff_oop.keyword,ff_oop.entries);
135     if (forcefield & FF_TYPE_CLASS2) {
136       fprintf(stderr," Item %s has %d entries\n",
137               ff_angang.keyword,ff_angang.entries);
138     }
139     fprintf(stderr,"\n");
140   }
141   fclose(FrcF);
142 }
143 
144