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 static ffx.utilities.KeywordGroup.PotentialFunctionParameter;
41 import static java.lang.Double.parseDouble;
42 import static java.lang.Integer.parseInt;
43 import static java.lang.String.format;
44
45 import ffx.potential.parameters.ForceField.ForceFieldType;
46 import ffx.utilities.FFXKeyword;
47 import java.util.Arrays;
48 import java.util.Comparator;
49 import java.util.logging.Level;
50 import java.util.logging.Logger;
51
52
53
54
55
56
57
58 @FFXKeyword(name = "vdwpr", clazz = String.class, keywordGroup = PotentialFunctionParameter, description =
59 "[2 integers and 2 reals] "
60 + "Provides the values for the vdw parameters for a single special heteroatomic pair of atoms. "
61 + "The integer modifiers give the pair of atom class numbers for which special vdw parameters are to be defined. "
62 + "The two real number modifiers give the values of the minimum energy contact distance in Angstroms and the well depth at the minimum distance in kcal/mole.")
63 public final class VDWPairType extends BaseType implements Comparator<String> {
64
65 private static final Logger logger = Logger.getLogger(VDWPairType.class.getName());
66
67 public final double radius;
68
69 public final double wellDepth;
70
71 public final int[] atomClasses;
72
73
74
75
76
77
78
79
80
81 public VDWPairType(int[] atomClasses, double radius, double wellDepth) {
82 super(ForceFieldType.VDWPR, sortKey(atomClasses));
83 this.atomClasses = atomClasses;
84 this.radius = radius;
85 this.wellDepth = wellDepth;
86 }
87
88
89
90
91
92
93
94
95
96 public static VDWPairType average(VDWPairType vdwType1, VDWPairType vdwType2, int[] atomClasses) {
97 if (vdwType1 == null || vdwType2 == null) {
98 return null;
99 }
100
101 double radius = (vdwType1.radius + vdwType2.radius) / 2.0;
102 double wellDepth = (vdwType1.wellDepth + vdwType2.wellDepth) / 2.0;
103
104 return new VDWPairType(atomClasses, radius, wellDepth);
105 }
106
107
108
109
110
111
112
113
114 public static VDWPairType parse(String input, String[] tokens) {
115 if (tokens.length < 5) {
116 logger.log(Level.WARNING, "Invalid VDWPR type:\n{0}", input);
117 } else {
118 try {
119 int atomClass1 = parseInt(tokens[1]);
120 int atomClass2 = parseInt(tokens[2]);
121 double radius = parseDouble(tokens[3]);
122 double wellDepth = parseDouble(tokens[4]);
123 return new VDWPairType(new int[] {atomClass1, atomClass2}, radius, wellDepth);
124 } catch (NumberFormatException e) {
125 String message = "Exception parsing VDWPR type:\n" + input + "\n";
126 logger.log(Level.SEVERE, message, e);
127 }
128 }
129 return null;
130 }
131
132
133 @Override
134 public int compare(String key1, String key2) {
135 String[] keys1 = key1.split(" ");
136 String[] keys2 = key2.split(" ");
137 int[] c1 = new int[2];
138 int[] c2 = new int[2];
139 for (int i = 0; i < 2; i++) {
140 c1[i] = Integer.parseInt(keys1[i]);
141 c2[i] = Integer.parseInt(keys2[i]);
142 }
143
144 if (c1[0] < c2[0]) {
145 return -1;
146 } else if (c1[0] > c2[0]) {
147 return 1;
148 } else if (c1[1] < c2[1]) {
149 return -1;
150 } else if (c1[1] > c2[1]) {
151 return 1;
152 }
153
154 return 0;
155 }
156
157
158 @Override
159 public boolean equals(Object o) {
160 if (this == o) {
161 return true;
162 }
163 if (o == null || getClass() != o.getClass()) {
164 return false;
165 }
166 VDWPairType vdwPairType = (VDWPairType) o;
167 return Arrays.equals(atomClasses, vdwPairType.atomClasses);
168 }
169
170
171 @Override
172 public int hashCode() {
173 return Arrays.hashCode(atomClasses);
174 }
175
176
177
178
179
180
181 @Override
182 public String toString() {
183 return format("vdwpr %5d %5d %11.9f %11.9f", atomClasses[0], atomClasses[1], radius,
184 wellDepth);
185 }
186
187
188
189
190
191
192
193 public static String sortKey(int[] c) {
194 if (c == null || c.length != 2) {
195 return null;
196 }
197
198 int temp;
199 if (c[1] <= c[0]) {
200 temp = c[1];
201 c[1] = c[0];
202 c[0] = temp;
203 }
204
205 return c[0] + " " + c[1];
206 }
207
208
209
210
211
212
213 public void incrementClasses(int increment) {
214 for (int i = 0; i < atomClasses.length; i++) {
215 atomClasses[i] += increment;
216 }
217 setKey(sortKey(atomClasses));
218 }
219
220 }