-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHydrogenBondMutator.java
311 lines (282 loc) · 16.1 KB
/
HydrogenBondMutator.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
import java.util.*;
import com.google.common.collect.*;
import org.jgrapht.*;
import org.jgrapht.graph.*;
/**
* This class converts the atom types in a Peptide from one that
* has the histidine and hydroxyl far apart to one that has them
* close together. This involves adding a bond to the connectivity table.
* We can also undo this change.
*/
public class HydrogenBondMutator implements Singleton, Mutator
{
public static final List<Pair<Integer,Integer>> HID_SEPARATED_ATOM_TYPES;
public static final List<Pair<Integer,Integer>> HID_CLOSE_ATOM_TYPES;
public static final List<Pair<Integer,Integer>> HIE_SEPARATED_ATOM_TYPES;
public static final List<Pair<Integer,Integer>> HIE_CLOSE_ATOM_TYPES;
/**
* the new hydrogen bond will be formed from this close contact atom type (AMOEBA)
*/
public static final int HBOND_FROM_ATOM_TYPE = 416;
/**
* the new hydrogen bond will be formed to this close contact atom type (AMOEBA)
*/
public static final int HBOND_TO_ATOM_TYPE = 421;
static
{
// check that the hydrogen bond is being formed between atoms of different types
if ( HBOND_FROM_ATOM_TYPE == HBOND_TO_ATOM_TYPE )
throw new IllegalArgumentException("must form hydrogen bond between atoms of different types");
// initialize parallel lists
List<Pair<Integer,Integer>> tempCommonSeparatedList = new LinkedList<>();
List<Pair<Integer,Integer>> tempCommonCloseList = new LinkedList<>();
List<Pair<Integer,Integer>> tempHIDSeparatedList = new LinkedList<>();
List<Pair<Integer,Integer>> tempHIDCloseList = new LinkedList<>();
List<Pair<Integer,Integer>> tempHIESeparatedList = new LinkedList<>();
List<Pair<Integer,Integer>> tempHIECloseList = new LinkedList<>();
// regular transition state atom type conversion
// these entries are common to both HID and HIE
// first entry in pair is the AMOEBA type, second is the OPLS type
tempCommonSeparatedList.add(new Pair<Integer,Integer>(401,401)); tempCommonCloseList.add(new Pair<Integer,Integer>(421,421));
tempCommonSeparatedList.add(new Pair<Integer,Integer>(402,402)); tempCommonCloseList.add(new Pair<Integer,Integer>(422,422));
tempCommonSeparatedList.add(new Pair<Integer,Integer>(403,403)); tempCommonCloseList.add(new Pair<Integer,Integer>(423,423));
tempCommonSeparatedList.add(new Pair<Integer,Integer>(404,404)); tempCommonCloseList.add(new Pair<Integer,Integer>(424,424));
tempCommonSeparatedList.add(new Pair<Integer,Integer>(405,405)); tempCommonCloseList.add(new Pair<Integer,Integer>(425,425));
tempCommonSeparatedList.add(new Pair<Integer,Integer>(406,406)); tempCommonCloseList.add(new Pair<Integer,Integer>(426,426));
tempCommonSeparatedList.add(new Pair<Integer,Integer>(407,407)); tempCommonCloseList.add(new Pair<Integer,Integer>(427,427));
tempCommonSeparatedList.add(new Pair<Integer,Integer>(408,408)); tempCommonCloseList.add(new Pair<Integer,Integer>(428,428));
tempCommonSeparatedList.add(new Pair<Integer,Integer>(409,409)); tempCommonCloseList.add(new Pair<Integer,Integer>(429,429));
tempCommonSeparatedList.add(new Pair<Integer,Integer>(410,410)); tempCommonCloseList.add(new Pair<Integer,Integer>(430,430));
tempCommonSeparatedList.add(new Pair<Integer,Integer>(411,411)); tempCommonCloseList.add(new Pair<Integer,Integer>(431,431));
tempHIDSeparatedList.addAll(tempCommonSeparatedList);
tempHIDCloseList.addAll(tempCommonCloseList);
tempHIESeparatedList.addAll(tempCommonSeparatedList);
tempHIECloseList.addAll(tempCommonCloseList);
// HID histidine to close contact atom types
tempHIDSeparatedList.add(new Pair<Integer,Integer>(119,153)); tempHIDCloseList.add(new Pair<Integer,Integer>(414,414));
tempHIDSeparatedList.add(new Pair<Integer,Integer>(122,152)); tempHIDCloseList.add(new Pair<Integer,Integer>(412,412));
tempHIDSeparatedList.add(new Pair<Integer,Integer>(123, 12)); tempHIDCloseList.add(new Pair<Integer,Integer>(413,413));
tempHIDSeparatedList.add(new Pair<Integer,Integer>(126,156)); tempHIDCloseList.add(new Pair<Integer,Integer>(416,416));
tempHIDSeparatedList.add(new Pair<Integer,Integer>(124,151)); tempHIDCloseList.add(new Pair<Integer,Integer>(419,419));
tempHIDSeparatedList.add(new Pair<Integer,Integer>(125, 12)); tempHIDCloseList.add(new Pair<Integer,Integer>(420,420));
tempHIDSeparatedList.add(new Pair<Integer,Integer>(120,148)); tempHIDCloseList.add(new Pair<Integer,Integer>(417,417));
tempHIDSeparatedList.add(new Pair<Integer,Integer>(121,149)); tempHIDCloseList.add(new Pair<Integer,Integer>(418,418));
// HIE histidine to close contact atom types
tempHIESeparatedList.add(new Pair<Integer,Integer>(129,152)); tempHIECloseList.add(new Pair<Integer,Integer>(412,412));
tempHIESeparatedList.add(new Pair<Integer,Integer>(131,153)); tempHIECloseList.add(new Pair<Integer,Integer>(414,414));
tempHIESeparatedList.add(new Pair<Integer,Integer>(132, 12)); tempHIECloseList.add(new Pair<Integer,Integer>(415,415));
tempHIESeparatedList.add(new Pair<Integer,Integer>(135,148)); tempHIECloseList.add(new Pair<Integer,Integer>(417,417));
tempHIESeparatedList.add(new Pair<Integer,Integer>(136,149)); tempHIECloseList.add(new Pair<Integer,Integer>(418,418));
tempHIESeparatedList.add(new Pair<Integer,Integer>(133,151)); tempHIECloseList.add(new Pair<Integer,Integer>(419,419));
tempHIESeparatedList.add(new Pair<Integer,Integer>(134, 12)); tempHIECloseList.add(new Pair<Integer,Integer>(420,420));
tempHIESeparatedList.add(new Pair<Integer,Integer>(130,156)); tempHIECloseList.add(new Pair<Integer,Integer>(416,416));
// make immutable copies
HID_SEPARATED_ATOM_TYPES = ImmutableList.copyOf(tempHIDSeparatedList);
HID_CLOSE_ATOM_TYPES = ImmutableList.copyOf(tempHIDCloseList);
HIE_SEPARATED_ATOM_TYPES = ImmutableList.copyOf(tempHIESeparatedList);
HIE_CLOSE_ATOM_TYPES = ImmutableList.copyOf(tempHIECloseList);
// check list sizes
if ( HID_SEPARATED_ATOM_TYPES.size() != HID_CLOSE_ATOM_TYPES.size() )
throw new IllegalArgumentException(String.format("HID list size mismatch %d %d", HID_SEPARATED_ATOM_TYPES.size(), HID_CLOSE_ATOM_TYPES.size()));
if ( HIE_SEPARATED_ATOM_TYPES.size() != HIE_CLOSE_ATOM_TYPES.size() )
throw new IllegalArgumentException(String.format("HID list size mismatch %d %d", HIE_SEPARATED_ATOM_TYPES.size(), HIE_CLOSE_ATOM_TYPES.size()));
// check every key has a value and there are no duplicate keys
// (duplicate values might occur)
for (int i=0; i < HID_SEPARATED_ATOM_TYPES.size(); i++)
{
Pair<Integer,Integer> from = HID_SEPARATED_ATOM_TYPES.get(i);
Pair<Integer,Integer> to = HID_CLOSE_ATOM_TYPES.get(i);
if ( from == null || to == null ||
from.getFirst() < 1 || from.getSecond() < 1 ||
to.getFirst() < 1 || to.getSecond() < 1 ||
from.equals(to) )
throw new IllegalArgumentException("invalid entry in HID table");
int occurrences = Collections.frequency(HID_SEPARATED_ATOM_TYPES, from);
if ( occurrences > 1 )
throw new IllegalArgumentException(String.format("duplicate HID key found (%d instances, from %s to %s", occurrences, from.toString(), to.toString()));
}
for (int i=0; i < HIE_SEPARATED_ATOM_TYPES.size(); i++)
{
Pair<Integer,Integer> from = HIE_SEPARATED_ATOM_TYPES.get(i);
Pair<Integer,Integer> to = HIE_CLOSE_ATOM_TYPES.get(i);
if ( from == null || to == null ||
from.getFirst() < 1 || from.getSecond() < 1 ||
to.getFirst() < 1 || to.getSecond() < 1 ||
from.equals(to) )
throw new IllegalArgumentException("invalid entry in HIE table");
int occurrences = Collections.frequency(HIE_SEPARATED_ATOM_TYPES, from);
if ( occurrences > 1 )
throw new IllegalArgumentException(String.format("duplicate HIE key found (%d instances, from %s to %s", occurrences, from.toString(), to.toString()));
}
}
/** class is not instantiable */
private HydrogenBondMutator()
{
throw new IllegalArgumentException("not instantiable");
}
/**
* Returns the separated and close atom types appropriate for this peptide.
* @param peptide the peptide
* @return first is separated second is close
*/
public static Pair< List<Pair<Integer,Integer>>, List<Pair<Integer,Integer>> > getAtomTypeLists(Peptide peptide)
{
// determine whether we are dealing with HID or HIE
String description = null;
for ( Residue r : peptide.sequence )
{
if ( r.description.indexOf("histidine") > -1 )
{
if ( description == null )
description = r.description;
else
throw new IllegalArgumentException("cannot handle two histidines");
}
}
if ( description == null )
throw new NullPointerException("must be exactly one histidine in the molecule to do a mutation");
if ( description.indexOf("histidine_hd") > -1 )
return new Pair<>(HID_SEPARATED_ATOM_TYPES, HID_CLOSE_ATOM_TYPES);
else if ( description.indexOf("histidine_he") > -1 )
return new Pair<>(HIE_SEPARATED_ATOM_TYPES, HIE_CLOSE_ATOM_TYPES);
else
throw new IllegalArgumentException("unknown histidine type");
}
/**
* Converts the atom types in a peptide from ones where the histidine and
* hydroxyl are far apart to ones where they are close together. Also
* adds the new hydrogen bond.
* @param peptide the original peptide
* @return the new peptide
*/
public static Peptide mutate(Peptide peptide)
{
// adjust atom types creating new atom map
Pair< List<Pair<Integer,Integer>>, List<Pair<Integer,Integer>> > listPair = getAtomTypeLists(peptide);
List<Pair<Integer,Integer>> separatedTypes = listPair.getFirst();
List<Pair<Integer,Integer>> closeTypes = listPair.getSecond();
HashMap<Atom,Atom> atomMap = new HashMap<>();
for (Atom a : peptide.contents)
{
Pair<Integer,Integer> currentType = new Pair<>(a.type1, a.type2);
if ( separatedTypes.contains(currentType) )
{
int index = separatedTypes.indexOf(currentType);
Pair<Integer,Integer> targetType = closeTypes.get(index);
Atom newAtom = a.setAtomType(targetType.getFirst(), targetType.getSecond());
atomMap.put(a, newAtom);
}
}
Peptide adjustedPeptide = peptide.moveAtoms2(atomMap);
// locate the atoms to form a hydrogen bond between
Atom fromAtom = null;
Atom toAtom = null;
for (Atom a : adjustedPeptide.contents)
{
if ( a.type1 == HBOND_FROM_ATOM_TYPE )
{
if ( fromAtom == null )
fromAtom = a;
else
throw new IllegalArgumentException("error, duplicate from atom type when forming hydrogen bond!");
}
if ( a.type1 == HBOND_TO_ATOM_TYPE )
{
if ( toAtom == null )
toAtom = a;
else
throw new IllegalArgumentException("error, duplicate to atom type when forming hydrogen bond!");
}
}
if ( fromAtom == null || toAtom == null )
throw new NullPointerException("couldn't find the atoms to make a hydrogen bond between");
// add the new bond
if ( adjustedPeptide.connectivity.containsEdge(fromAtom,toAtom) )
throw new IllegalArgumentException("target hydrogen bond already exists");
DefaultWeightedEdge newEdge = adjustedPeptide.connectivity.addEdge(fromAtom,toAtom);
adjustedPeptide.connectivity.setEdgeWeight(newEdge, 1.0);
return adjustedPeptide;
}
/**
* Converts the atom types in a peptide from the close contact types to the
* separated types. Also removes the new hydrogen bond.
* @param peptide the original peptide
* @return the new peptide
*/
public static Peptide unmutate(Peptide peptide)
{
// locate the atoms to remove a hydrogen bond between
Atom fromAtom = null;
Atom toAtom = null;
for (Atom a : peptide.contents)
{
if ( a.type1 == HBOND_FROM_ATOM_TYPE )
{
if ( fromAtom == null )
fromAtom = a;
else
throw new IllegalArgumentException("error, duplicate from atom type when deleting hydrogen bond!");
}
if ( a.type2 == HBOND_TO_ATOM_TYPE )
{
if ( toAtom == null )
toAtom = a;
else
throw new IllegalArgumentException("error, duplicate to atom type when deleting hydrogen bond!");
}
}
if ( fromAtom == null || toAtom == null )
throw new NullPointerException("couldn't find the atoms to delete a hydrogen bond with");
// delete the hydrogen bond
Peptide adjustedPeptide = peptide.moveAtoms2(new HashMap<Atom,Atom>());
DefaultWeightedEdge edge = adjustedPeptide.connectivity.getEdge(fromAtom,toAtom);
if ( edge == null )
throw new NullPointerException("found the hydrogen-bonded atoms, but they're not bonded");
adjustedPeptide.connectivity.removeEdge(edge);
// adjust atom types creating new atom map
Pair< List<Pair<Integer,Integer>>, List<Pair<Integer,Integer>> > listPair = getAtomTypeLists(peptide);
List<Pair<Integer,Integer>> separatedTypes = listPair.getFirst();
List<Pair<Integer,Integer>> closeTypes = listPair.getSecond();
HashMap<Atom,Atom> atomMap = new HashMap<>();
for (Atom a : adjustedPeptide.contents)
{
Pair<Integer,Integer> currentType = new Pair<>(a.type1, a.type2);
if ( closeTypes.contains(currentType) )
{
int index = closeTypes.indexOf(currentType);
Pair<Integer,Integer> targetType = separatedTypes.get(index);
Atom newAtom = a.setAtomType(targetType.getFirst(), targetType.getSecond());
atomMap.put(a, newAtom);
}
}
adjustedPeptide = adjustedPeptide.moveAtoms2(atomMap);
// transfer the EnergyBreakdown
//EnergyBreakdown energyBreakdown = peptide.energyBreakdown;
//adjustedPeptide = adjustedPeptide.setEnergyBreakdown(energyBreakdown);
return adjustedPeptide;
}
/**
* Mutate a whole bunch of peptides at once.
* @param peptides the peptides to mutate
* @param the mutated peptides
*/
public static List<Peptide> mutate(List<Peptide> peptides)
{
List<Peptide> returnList = new ArrayList<>(peptides.size());
for (Peptide p : peptides)
returnList.add(mutate(p));
return returnList;
}
/**
* Mutate a whole bunch of peptides at once.
* @param peptides the peptides to mutate
* @param the mutated peptides
*/
public static List<Peptide> unmutate(List<Peptide> peptides)
{
List<Peptide> returnList = new ArrayList<>(peptides.size());
for (Peptide p : peptides)
returnList.add(unmutate(p));
return returnList;
}
}