-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackboneMutator.java
297 lines (263 loc) · 13.3 KB
/
BackboneMutator.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
import org.apache.commons.math3.geometry.euclidean.threed.*;
import java.io.*;
import java.util.*;
import org.apache.commons.math3.distribution.NormalDistribution;
import java.util.concurrent.*;
import org.jgrapht.*;
import org.jgrapht.graph.*;
import org.jgrapht.alg.*;
import com.google.common.collect.*;
/**
* This collects together methods for taking a peptide and changing its
* omega, phi, and psi angles to appropriate randomly-selected values.
*/
public class BackboneMutator implements Mutator
{
/** This is the probability for giving a cis omega dihedral angle for a proline. */
public static final double CIS_PROLINE_PROBABILITY = 0.08;
/** This is the width of the normal distribution in degrees to draw omega angles for if no database data are available. */
public static final double DEFAULT_OMEGA_WIDTH = 5.0;
/** should not be invoked */
private BackboneMutator()
{
throw new IllegalArgumentException("not instantiable");
}
/**
* Takes a peptide and sets the omega angle. We don't check that residue belongs to peptide.
* @param peptide the peptide to set the omega of
* @param residue the residue to set the omega of
* @param omegaAngle the angle to set the omega to in degrees
* @return the rotated peptide
*/
public static Peptide setOmega(Peptide peptide, Residue residue, double omegaAngle)
{
ProtoTorsion omega = residue.omega;
return peptide.setMolecule( peptide.setDihedral(omega, omegaAngle) );
}
/**
* Takes a peptide and sets the omega angle. We don't check that residue belongs to peptide.
* @param peptide the peptide to set the omega of
* @param i the index of the residue to adjust
* @param omegaAngle the angle to set the omega to in degrees
* @return the rotated peptide
*/
public static Peptide setOmega(Peptide peptide, int i, double omegaAngle)
{
ProtoTorsion omega = peptide.sequence.get(i).omega;
return peptide.setMolecule( peptide.setDihedral(omega, omegaAngle) );
}
/**
* Convenience method that mutates the omega torsion angle of the i-th
* residue (i=0,1,...,n-1). The omega angle is randomly selected.
* @param peptide the peptide to mutate
* @param i the index of the residue to mutate
* @return the mutated peptide
*/
public static Peptide mutateOmega(Peptide peptide, int i)
{
if ( i < 0 || i > peptide.sequence.size() - 1 )
throw new IllegalArgumentException("residue index out of range");
AminoAcid aa2 = peptide.sequence.get(i).aminoAcid;
// get the residue to the left
Double omegaValue = null;
if ( i > 0 )
{
if ( aa2.isProline() )
{
// give this some chance of becoming cis-proline
double draw = ThreadLocalRandom.current().nextDouble();
if ( draw < CIS_PROLINE_PROBABILITY )
omegaValue = new NormalDistribution(0.0, DEFAULT_OMEGA_WIDTH).sample();
}
if ( omegaValue == null )
{
// this is a normal amino acid, so use information from OmegaDatabase
AminoAcid aa1 = peptide.sequence.get(i-1).aminoAcid;
double psi0 = peptide.sequence.get(i-1).psi.getDihedralAngle();
double phi1 = peptide.sequence.get(i).phi.getDihedralAngle();
omegaValue = OmegaDatabase.getOmega(aa1, psi0, aa2, phi1);
}
}
else
{
// there is no residue to the left, so just return a normally distributed value with a small width
omegaValue = new NormalDistribution(180.0, DEFAULT_OMEGA_WIDTH).sample();
}
// make the change
return setOmega(peptide, peptide.sequence.get(i), omegaValue);
}
/**
* Takes a peptide and sets the (phi,psi) value to a likely value using Dunbrack Ramachandran data.
* @param peptide the starting structure
* @param i the index of the residue to be mutated
* @return the result of the mutation
*/
public static Peptide mutatePhiPsi(Peptide peptide, int i)
{
return mutatePhiPsi(peptide, peptide.sequence.get(i));
}
/**
* Takes a peptide and sets the (phi,psi) value to a likely value using Dunbrack Ramachandran data.
* @param peptide the starting structure
* @param residue the residue whose (phi,psi) angles are to be mutated
* @return the result of the mutation
*/
public static Peptide mutatePhiPsi(Peptide peptide, Residue residue)
{
// get residue index
List<Residue> sequence = peptide.sequence;
int residueIndex = sequence.indexOf(residue);
// get adjacent amino acids
AminoAcid centralAminoAcid = residue.aminoAcid;
if ( centralAminoAcid == AminoAcid.DPRO )
centralAminoAcid = AminoAcid.LPRO;
double centralOmega = residue.omega.getDihedralAngle();
Double newPhiValue = null;
Double newPsiValue = null;
AminoAcid leftAminoAcid = null;
Double leftOmega = null;
if ( residueIndex > 0 )
{
Residue leftResidue = sequence.get(residueIndex-1);
leftAminoAcid = leftResidue.aminoAcid;
leftOmega = leftResidue.omega.getDihedralAngle();
}
AminoAcid rightAminoAcid = null;
Double rightOmega = null;
if ( residueIndex < sequence.size() - 1 )
{
Residue rightResidue = sequence.get(residueIndex+1);
rightAminoAcid = rightResidue.aminoAcid;
rightOmega = rightResidue.omega.getDihedralAngle();
}
// if D-proline is adjacent, set to null because we don't have data for that
if ( leftAminoAcid == AminoAcid.DPRO )
leftAminoAcid = null;
if ( rightAminoAcid == AminoAcid.DPRO )
rightAminoAcid = null;
// use serine data for adjacent transition states
if ( leftAminoAcid == AminoAcid.TS )
leftAminoAcid = AminoAcid.SER;
if ( rightAminoAcid == AminoAcid.TS )
rightAminoAcid = AminoAcid.SER;
// obtain appropriate probability distribution of phi,psi
DiscreteProbabilityDistribution<RotamerLibrary.Angles> DPD = null;
if ( leftAminoAcid != null && rightAminoAcid != null )
DPD = RamachandranDatabase.getTripletDistribution(leftAminoAcid, leftOmega, centralAminoAcid, centralOmega, rightAminoAcid, rightOmega);
else if ( leftAminoAcid == null && rightAminoAcid != null )
DPD = RamachandranDatabase.getRightDistribution(centralAminoAcid, centralOmega, rightAminoAcid, rightOmega);
else if ( leftAminoAcid != null && rightAminoAcid == null )
DPD = RamachandranDatabase.getLeftDistribution(leftAminoAcid, leftOmega, centralAminoAcid, centralOmega);
else
throw new IllegalArgumentException("should not be possible");
// draw random phi,psi from the distribution
RotamerLibrary.Angles draw = DPD.getRandom();
newPhiValue = draw.phi;
newPsiValue = draw.psi;
if ( residue.aminoAcid == AminoAcid.DPRO )
{
// no rotamer data for non-hairpin D-proline so get data for L-proline in this position and invert numbers
newPhiValue = newPhiValue * -1.0;
newPsiValue = newPsiValue * -1.0;
//System.out.println(String.format("phi,psi for dpro: %6.1f, %6.1f", newPhiValue, newPsiValue));
}
// make the mutation
return setPhiPsi(peptide, residue, newPhiValue, newPsiValue);
}
/**
* Sets the backbone (phi,psi) angles of a residue to specific values.
* @param peptide the starting structure
* @param residue the residue whose (phi,psi) angles are to be mutated
* @param newPhiValue the phi value we will be setting residue's phi to in degrees
* @param newPsiValue the psi value we will be setting residue's psi to in degeres
* @return the result of the mutation
*/
public static Peptide setPhiPsi(Peptide peptide, Residue residue, double newPhiValue, double newPsiValue)
{
int residueIndex = peptide.sequence.indexOf(residue);
if ( residueIndex == -1 )
throw new IllegalArgumentException("this residue does not belong to the specified peptide");
return setPhiPsi(peptide, residueIndex, newPhiValue, newPsiValue);
}
/**
* Sets the backbone (phi,psi) angles of a residue to specific values.
* @param peptide the starting structure
* @param residueIndex the index of the residue whose (phi,psi) angles are to be mutated
* @param newPhiValue the phi value we will be setting residue's phi to in degrees
* @param newPsiValue the psi value we will be setting residue's psi to in degeres
* @return the result of the mutation
*/
public static Peptide setPhiPsi(Peptide peptide, int residueIndex, double newPhiValue, double newPsiValue)
{
if ( newPhiValue < -180.0 || newPhiValue > 180.0 || newPsiValue < -180.0 || newPsiValue > 180.0 )
throw new IllegalArgumentException("angle out of range");
Residue residue = peptide.sequence.get(residueIndex);
ProtoTorsion phi = residue.phi;
ProtoTorsion psi = residue.psi;
double omegaValue = residue.omega.getDihedralAngle();
Peptide newPeptide = null;
if ( residue.aminoAcid.isProline() )
{
// special procedure for proline
//System.out.println("old chi1: " + residue.chis.get(0).getDihedralAngle());
//System.out.println("old chi2: " + residue.chis.get(1).getDihedralAngle());
//System.out.println("old chi3: " + residue.chis.get(2).getDihedralAngle());
// disconnect bond in temporary molecule
Molecule tempMolecule = peptide.moveAtoms(new HashMap<Atom,Atom>());
ProtoTorsion chi3 = residue.chis.get(2);
Atom atom3 = chi3.atom3;
Atom atom4 = chi3.atom4;
DefaultWeightedEdge e = tempMolecule.connectivity.removeEdge(atom3,atom4);
if ( e == null )
throw new NullPointerException("unexpected null for proline connection");
// keep psi for later
IndexTorsion psiIndexTorsion = IndexTorsion.createIndexTorsion(psi, tempMolecule);
// save information for chi mutations
LinkedList<ProtoTorsion> oldProtoTorsions = new LinkedList<>(residue.chis);
oldProtoTorsions.removeLast();
List<IndexTorsion> indexTorsions = new LinkedList<>();
for (ProtoTorsion p : oldProtoTorsions)
indexTorsions.add(IndexTorsion.createIndexTorsion(p, tempMolecule));
// make phi mutation
tempMolecule = tempMolecule.setDihedral(phi, newPhiValue);
// make psi mutation
tempMolecule = tempMolecule.setDihedral(psiIndexTorsion, newPsiValue);
// choose new proline chis
// there's no easy way to adjust the third chi value, so we don't set it
List<Double> newChis = null;
if ( residue.aminoAcid == AminoAcid.LPRO )
{
newChis = RotamerDatabase.getRandomRotamer(AminoAcid.LPRO, omegaValue, newPhiValue, newPsiValue);;
newChis = ImmutableList.of(newChis.get(0), newChis.get(1));
}
else if ( residue.aminoAcid == AminoAcid.DPRO )
{
// these numbers have already been inverted so un-invert them
newChis = RotamerDatabase.getRandomRotamer(AminoAcid.LPRO, omegaValue, -1.0*newPhiValue, -1.0*newPsiValue);;
// invert the answer we get
newChis = ImmutableList.of(newChis.get(0)*-1.0, newChis.get(1)*-1.0);
}
else
throw new IllegalArgumentException("I don't know how to deal with this kind of proline");
// adjust the chis
for (int j=0; j < oldProtoTorsions.size(); j++)
{
IndexTorsion i = indexTorsions.get(j);
double newChiValue = newChis.get(j);
tempMolecule = tempMolecule.setDihedral(i, newChiValue);
}
// move the atoms
// note that this way of doing things preserves the previous connectivity
newPeptide = peptide.setMolecule(tempMolecule);
}
else
{
// make mutation directly
IndexTorsion psiIndexTorsion = IndexTorsion.createIndexTorsion(psi, peptide);
newPeptide = peptide.setMolecule( peptide.setDihedral(phi, newPhiValue) );
Residue newResidue = newPeptide.sequence.get(residueIndex);
newPeptide = newPeptide.setMolecule( newPeptide.setDihedral(psiIndexTorsion, newPsiValue) );
}
return newPeptide;
}
}