1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package ffx.potential.parameters;
39
40 import ffx.utilities.FFXKeyword;
41
42 import java.util.Comparator;
43 import java.util.Objects;
44 import java.util.logging.Level;
45 import java.util.logging.Logger;
46
47 import static ffx.potential.parameters.ForceField.ForceFieldType.VDW;
48 import static ffx.potential.parameters.ForceField.ForceFieldType.VDW14;
49 import static ffx.utilities.KeywordGroup.PotentialFunctionParameter;
50 import static java.lang.Double.parseDouble;
51 import static java.lang.Integer.parseInt;
52 import static java.lang.StrictMath.abs;
53 import static java.lang.String.format;
54
55
56
57
58
59
60
61
62 @FFXKeyword(name = "vdw", clazz = String.class, keywordGroup = PotentialFunctionParameter,
63 description = """
64 [1 integer and 3 reals]
65 Provides values for a single van der Waals parameter. The integer modifier, if positive,
66 gives the atom class number for which vdw parameters are to be defined. Note that vdw parameters are given for atom classes, not atom types.
67 The three real number modifiers give the values of the atom size in Angstroms, homoatomic well depth in kcal/mole,
68 and an optional reduction factor for univalent atoms.
69 """)
70 @FFXKeyword(name = "vdw14", clazz = String.class, keywordGroup = PotentialFunctionParameter,
71 description = """
72 [1 integer and 2 reals]
73 Provides values for a single van der Waals parameter for use in 1-4 nonbonded interactions.
74 The integer modifier, if positive, gives the atom class number for which vdw parameters are to be defined.
75 Note that vdw parameters are given for atom classes, not atom types.
76 The two real number modifiers give the values of the atom size in Angstroms and the homoatomic well depth in kcal/mole.
77 Reduction factors, if used, are carried over from the vdw keyword for the same atom class.
78 """)
79 public final class VDWType extends BaseType implements Comparator<String> {
80
81 private static final Logger logger = Logger.getLogger(VDWType.class.getName());
82
83
84
85 public final double radius;
86
87
88
89 public final double wellDepth;
90
91
92
93
94
95 public final double reductionFactor;
96
97
98
99 public int atomClass;
100
101
102
103 private final VDWMode vdwMode;
104
105
106
107
108
109
110
111
112
113
114 public VDWType(int atomClass, double radius, double wellDepth, double reductionFactor) {
115 this(atomClass, radius, wellDepth, reductionFactor, VDWMode.NORMAL);
116 }
117
118
119
120
121
122
123
124
125
126
127
128 public VDWType(int atomClass, double radius, double wellDepth, double reductionFactor,
129 VDWMode vdwMode) {
130 super(VDW, Integer.toString(atomClass));
131 this.atomClass = atomClass;
132 this.radius = radius;
133 this.wellDepth = abs(wellDepth);
134 this.reductionFactor = reductionFactor;
135 this.vdwMode = vdwMode;
136 if (vdwMode == VDWMode.VDW14) {
137 forceFieldType = VDW14;
138 }
139 }
140
141
142
143
144
145
146
147
148
149 public static VDWType average(VDWType vdwType1, VDWType vdwType2, int atomClass) {
150 if (vdwType1 == null || vdwType2 == null) {
151 return null;
152 }
153 double radius = (vdwType1.radius + vdwType2.radius) / 2.0;
154 double wellDepth = (vdwType1.wellDepth + vdwType2.wellDepth) / 2.0;
155 double reductionFactor = (vdwType1.reductionFactor + vdwType2.reductionFactor) / 2.0;
156 return new VDWType(atomClass, radius, wellDepth, reductionFactor);
157 }
158
159
160
161
162
163
164
165
166 public static VDWType parse(String input, String[] tokens) {
167 if (tokens.length < 4) {
168 logger.log(Level.WARNING, "Invalid VDW type:\n{0}", input);
169 } else {
170 try {
171 int atomType = parseInt(tokens[1]);
172 double radius = parseDouble(tokens[2]);
173 double wellDepth = parseDouble(tokens[3]);
174 double reductionFactor = -1.0;
175 if (tokens.length == 5) {
176 reductionFactor = parseDouble(tokens[4]);
177 }
178 return new VDWType(atomType, radius, wellDepth, reductionFactor);
179 } catch (NumberFormatException e) {
180 String message = "Exception parsing VDW type:\n" + input + "\n";
181 logger.log(Level.SEVERE, message, e);
182 }
183 }
184 return null;
185 }
186
187
188
189
190
191
192
193
194 public static VDWType parseVDW14(String input, String[] tokens) {
195 if (tokens.length < 4) {
196 logger.log(Level.WARNING, "Invalid VDW type:\n{0}", input);
197 } else {
198 try {
199 int atomType = parseInt(tokens[1]);
200 double radius = parseDouble(tokens[2]);
201 double wellDepth = parseDouble(tokens[3]);
202 double reductionFactor = -1.0;
203 if (tokens.length == 5) {
204 reductionFactor = parseDouble(tokens[4]);
205 }
206 return new VDWType(atomType, radius, wellDepth, reductionFactor, VDWMode.VDW14);
207 } catch (NumberFormatException e) {
208 String message = "Exception parsing VDW14 type:\n" + input + "\n";
209 logger.log(Level.SEVERE, message, e);
210 }
211 }
212 return null;
213 }
214
215
216
217
218 @Override
219 public int compare(String s1, String s2) {
220 int t1 = parseInt(s1);
221 int t2 = parseInt(s2);
222 return Integer.compare(t1, t2);
223 }
224
225
226
227
228 @Override
229 public boolean equals(Object o) {
230 if (this == o) {
231 return true;
232 }
233 if (o == null || getClass() != o.getClass()) {
234 return false;
235 }
236 VDWType vdwType = (VDWType) o;
237 return (vdwType.atomClass == this.atomClass);
238 }
239
240
241
242
243 @Override
244 public int hashCode() {
245 return Objects.hash(atomClass);
246 }
247
248
249
250
251
252
253 @Override
254 public String toString() {
255 StringBuilder vdwString = new StringBuilder("vdw");
256 if (vdwMode == VDWMode.VDW14) {
257 vdwString.append("14");
258 }
259
260
261 if (reductionFactor <= 0e0) {
262 vdwString.append(format(" %5d %11.9f %11.9f", atomClass, radius, wellDepth));
263 } else {
264 vdwString.append(
265 format(" %5d %11.9f %11.9f %5.3f", atomClass, radius, wellDepth, reductionFactor));
266 }
267
268 return vdwString.toString();
269 }
270
271
272
273
274
275
276 void incrementClass(int increment) {
277 atomClass += increment;
278 setKey(Integer.toString(atomClass));
279 }
280
281
282
283
284 public enum VDWMode {
285 NORMAL, VDW14
286 }
287 }