-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProtoAminoAcid.java
224 lines (168 loc) · 5.99 KB
/
ProtoAminoAcid.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
import java.util.*;
import java.io.*;
import org.apache.commons.math3.geometry.euclidean.threed.*;
import org.jgrapht.graph.*;
/**
A class used that lets us build larger peptides. It contains information about geometry, force field parameters, and connections for the 20 standard amino acids. Each amino acid has been processed in Macromodel with a version corresponding to the N terminal, the C terminal, and a version corresponding to being part of a polypeptide chain.
*/
public class ProtoAminoAcid {
/** A nested enum describing a ProtoAminoAcid as either a C-terminal, N-terminal, or central amino acid */
private enum Position {
/** Represents N-terminal postion */
N_TERMINAL,
/** Represents C-terminal position */
C_TERMINAL,
/** Represents chain Amino Acid (not on terminal ends) */
CHAIN;
public String toString() {
switch(this)
{
case N_TERMINAL : return "nterm";
case C_TERMINAL : return "cterm";
default : return "center";
}
}
}
/** A simple weighted graph which represents bonds between atoms */
SimpleWeightedGraph<Atom, DefaultWeightedEdge> bonds;
/**
A list of the atoms that are not sticky in the prototypical amino acid
*/
List<Atom> nonStickyAtoms;
/**
An atom used to indicate which atom is the C alpha atom
*/
Atom cAlpha;
public ProtoAminoAcid(AminoAcid aminoAcid, Position position) {
Scanner thisFile = null;
List<Atom> allAtoms = new ArrayList<>();
bonds = new SimpleWeightedGraph<Atom, DefaultWeightedEdge>(DefaultWeightedEdge.class);
try
{
thisFile = new Scanner(new FileReader("aa_library/" + aminoAcid.toString().toLowerCase()+"_"+position.toString()+"-out"));
int delimeterCount = 0;
int totalAtoms = 0;
int totalBondsDoubled = 0;
int atomsEnteredCount = 0;
int bondsEnteredCount = 0;
//booleans to indicate if it is time to read atoms or bonds
boolean enter_atoms = false;
boolean enter_bonds = false;
while (thisFile.hasNextLine())
{
//ignore lines before the data we are interested in
String currentLine = thisFile.nextLine();
if (currentLine.indexOf("m_atom[") >= 0)
{
String[] parts = currentLine.split("\\s+");
totalAtoms = Integer.parseInt(parts[1].substring(7,parts[1].length()-1));
enter_atoms = true;
}
if (currentLine.indexOf("m_bond[") >= 0)
{
String[] parts = currentLine.split("\\s+");
totalBondsDoubled = Integer.parseInt(parts[1].substring(7,parts[1].length()-1));
enter_bonds = true;
}
if (currentLine.indexOf(":::") < 0 && delimeterCount < 5)
{
continue;
}
else if (currentLine.indexOf(":::") >= 0)
{
delimeterCount++;
continue;
}
//skips lines after "m_bond[]" and before ::: which specifies data entry
else if (delimeterCount < 7 && enter_bonds)
{
continue;
}
if (enter_atoms) {
// parse currentLine to access data fields
String processedLine = currentLine.replaceAll("\"","");
String[] parts = processedLine.split("\\s+");
String atomName = parts[14].substring(0,1);
Atom atom = new Atom(atomName, new Vector3D(Double.parseDouble(parts[3]),Double.parseDouble(parts[4]),Double.parseDouble(parts[5])));
allAtoms.add(atom);
bonds.addVertex(atom);
atomsEnteredCount++;
if (atomsEnteredCount == totalAtoms)
enter_atoms = false;
}
if (enter_bonds) {
DefaultWeightedEdge thisEdge = null;
// parse currentLine to access data fields
String processedLine = currentLine.replaceAll("\"","");
String[] parts = processedLine.split("\\s+");
int atomIndex1 = Integer.parseInt(parts[2]) - 1;
int atomIndex2 = Integer.parseInt(parts[3]) - 1;
if (bonds.getEdge(allAtoms.get(atomIndex1),allAtoms.get(atomIndex2))== null)
{
thisEdge = bonds.addEdge(allAtoms.get(atomIndex1), allAtoms.get(atomIndex2));
Double bondOrder = Double.parseDouble(parts[4]);
bonds.setEdgeWeight(thisEdge, bondOrder);
}
bondsEnteredCount++;
if (bondsEnteredCount == totalBondsDoubled)
enter_bonds = false;
}
}
thisFile = new Scanner(new FileReader("aa_library/" + aminoAcid.toString().toLowerCase()+"_"+position.toString()+"_opls.txt"));
boolean atData = false;
boolean getAtomData = false;
int linesPastForceFieldHeader = 0;
final int LINESTOIGNOREAFTERHEADER = 4;
boolean ignoreFourLines = true;
int atomIndex = 0;
atomsEnteredCount = 0;
while(thisFile.hasNextLine())
{
String currentLine = thisFile.nextLine();
if (!atData && currentLine.indexOf("OPLSAA FORCE FIELD TYPE ASSIGNED") < 0)
continue;
else
{
atData = true;
if (ignoreFourLines) {
for( int lines = 0; lines < LINESTOIGNOREAFTERHEADER; lines++)
{
currentLine = thisFile.nextLine();
}
ignoreFourLines = false;
getAtomData = true;
}
}
if (getAtomData)
{
System.out.println(currentLine);
String[] parts = currentLine.split("\\s+");
System.out.println(parts[5]);
System.out.println(parts[7]);
Atom currentAtom = allAtoms.get(atomIndex);
currentAtom.setPartialCharge(Double.parseDouble(parts[5]));
currentAtom.setSigma(Double.parseDouble(parts[6]));
currentAtom.setEpsilon(Double.parseDouble(parts[7]));
atomsEnteredCount++;
if (atomsEnteredCount == totalAtoms)
getAtomData = false;
}
}
}
catch (IOException e)
{
e.printStackTrace();
System.exit(1);
}
finally
{
if (thisFile != null)
thisFile.close();
}
System.out.println(bonds.toString());
System.out.println(allAtoms.toString());
}
public static void main(String[] args) {
ProtoAminoAcid test = new ProtoAminoAcid(AminoAcid.ASP, Position.CHAIN);
}
}