1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ext.pymol; |
22 |
|
|
23 |
|
import java.awt.Color; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Arrays; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Map; |
28 |
|
|
29 |
|
import jalview.structure.AtomSpecModel; |
30 |
|
import jalview.structure.StructureCommand; |
31 |
|
import jalview.structure.StructureCommandI; |
32 |
|
import jalview.structure.StructureCommandsBase; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@see |
42 |
|
@see |
43 |
|
|
|
|
| 86% |
Uncovered Elements: 15 (107) |
Complexity: 25 |
Complexity Density: 0.32 |
|
44 |
|
public class PymolCommands extends StructureCommandsBase |
45 |
|
{ |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
private static final StructureCommand FOCUS_VIEW = new StructureCommand( |
50 |
|
"zoom"); |
51 |
|
|
52 |
|
|
53 |
|
private static final StructureCommand CLOSE_PYMOL = new StructureCommand( |
54 |
|
"quit"); |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
private static final StructureCommand COLOUR_BY_CHAIN = new StructureCommand( |
59 |
|
"spectrum", "chain"); |
60 |
|
|
61 |
|
private static final List<StructureCommandI> COLOR_BY_CHARGE = Arrays |
62 |
|
.asList(new StructureCommand("color", "white", "*"), |
63 |
|
new StructureCommand("color", "red", "resn ASP resn GLU"), |
64 |
|
new StructureCommand("color", "blue", |
65 |
|
"resn LYS resn ARG"), |
66 |
|
new StructureCommand("color", "yellow", "resn CYS")); |
67 |
|
|
68 |
|
private static final List<StructureCommandI> SHOW_BACKBONE = Arrays |
69 |
|
.asList(new StructureCommand("hide", "everything"), |
70 |
|
new StructureCommand("show", "ribbon")); |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
1 |
@Override... |
73 |
|
public StructureCommandI colourByChain() |
74 |
|
{ |
75 |
1 |
return COLOUR_BY_CHAIN; |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
1 |
@Override... |
79 |
|
public List<StructureCommandI> colourByCharge() |
80 |
|
{ |
81 |
1 |
return COLOR_BY_CHARGE; |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
1 |
@Override... |
85 |
|
public StructureCommandI setBackgroundColour(Color col) |
86 |
|
{ |
87 |
|
|
88 |
1 |
return new StructureCommand("bg_color", getColourString(col)); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
@param |
96 |
|
@return |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
5 |
protected String getColourString(Color c)... |
99 |
|
{ |
100 |
5 |
return String.format("0x%02x%02x%02x", c.getRed(), c.getGreen(), |
101 |
|
c.getBlue()); |
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
0 |
@Override... |
105 |
|
public StructureCommandI focusView() |
106 |
|
{ |
107 |
0 |
return FOCUS_VIEW; |
108 |
|
} |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
110 |
0 |
@Override... |
111 |
|
public List<StructureCommandI> showChains(List<String> toShow) |
112 |
|
{ |
113 |
|
|
114 |
0 |
List<StructureCommandI> commands = new ArrayList<>(); |
115 |
0 |
commands.add(new StructureCommand("hide", "everything")); |
116 |
0 |
commands.add(new StructureCommand("show", "lines")); |
117 |
0 |
StringBuilder chains = new StringBuilder(); |
118 |
0 |
for (String chain : toShow) |
119 |
|
{ |
120 |
0 |
chains.append(" chain ").append(chain); |
121 |
|
} |
122 |
0 |
commands.add( |
123 |
|
new StructureCommand("show", "cartoon", chains.toString())); |
124 |
0 |
return commands; |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
127 |
1 |
@Override... |
128 |
|
public List<StructureCommandI> superposeStructures(AtomSpecModel refAtoms, |
129 |
|
AtomSpecModel atomSpec, AtomSpecType specType) |
130 |
|
{ |
131 |
|
|
132 |
|
|
133 |
1 |
List<StructureCommandI> commands = new ArrayList<>(); |
134 |
1 |
String refAtomsAlphaOnly = "(" + getAtomSpec(refAtoms, specType) |
135 |
|
+ " and (altloc '' or altloc 'a'))"; |
136 |
1 |
String atomSpec2AlphaOnly = "(" + getAtomSpec(atomSpec, specType) |
137 |
|
+ " and (altloc '' or altloc 'a'))"; |
138 |
|
|
139 |
|
|
140 |
1 |
commands.add(new StructureCommand("undo_disable")); |
141 |
1 |
commands.add(new StructureCommand("pair_fit", atomSpec2AlphaOnly, |
142 |
|
refAtomsAlphaOnly)); |
143 |
1 |
commands.add(new StructureCommand("undo_enable")); |
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
1 |
String refAtomsAll = getAtomSpec(refAtoms, AtomSpecType.RESIDUE_ONLY); |
149 |
1 |
String atomSpec2All = getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY); |
150 |
1 |
commands.add(new StructureCommand("show", "cartoon", |
151 |
|
refAtomsAll + " " + atomSpec2All)); |
152 |
|
|
153 |
1 |
return commands; |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
1 |
@Override... |
157 |
|
public StructureCommandI openCommandFile(String path) |
158 |
|
{ |
159 |
|
|
160 |
1 |
return new StructureCommand("run", path); |
161 |
|
} |
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
163 |
1 |
@Override... |
164 |
|
public StructureCommandI saveSession(String filepath) |
165 |
|
{ |
166 |
|
|
167 |
1 |
return new StructureCommand("save", filepath); |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
@see |
181 |
|
|
|
|
| 94.1% |
Uncovered Elements: 2 (34) |
Complexity: 6 |
Complexity Density: 0.25 |
|
182 |
36 |
@Override... |
183 |
|
public String getAtomSpec(AtomSpecModel model, AtomSpecType specType) |
184 |
|
{ |
185 |
36 |
StringBuilder sb = new StringBuilder(64); |
186 |
36 |
boolean first = true; |
187 |
36 |
for (String modelId : model.getModels()) |
188 |
|
{ |
189 |
52 |
for (String chain : model.getChains(modelId)) |
190 |
|
{ |
191 |
86 |
if (!first) |
192 |
|
{ |
193 |
52 |
sb.append(" "); |
194 |
|
} |
195 |
86 |
first = false; |
196 |
86 |
List<int[]> rangeList = model.getRanges(modelId, chain); |
197 |
86 |
chain = chain.trim(); |
198 |
86 |
sb.append(modelId).append("//").append(chain).append("/"); |
199 |
86 |
boolean firstRange = true; |
200 |
86 |
for (int[] range : rangeList) |
201 |
|
{ |
202 |
111 |
if (!firstRange) |
203 |
|
{ |
204 |
25 |
sb.append("+"); |
205 |
|
} |
206 |
111 |
firstRange = false; |
207 |
111 |
sb.append(String.valueOf(range[0])); |
208 |
111 |
if (range[0] != range[1]) |
209 |
|
{ |
210 |
86 |
sb.append("-").append(String.valueOf(range[1])); |
211 |
|
} |
212 |
|
} |
213 |
86 |
sb.append("/"); |
214 |
86 |
if (specType == AtomSpecType.ALPHA) |
215 |
|
{ |
216 |
34 |
sb.append("CA"); |
217 |
|
} |
218 |
86 |
if (specType == AtomSpecType.PHOSPHATE) |
219 |
|
{ |
220 |
0 |
sb.append("P"); |
221 |
|
} |
222 |
|
} |
223 |
|
} |
224 |
36 |
return sb.toString(); |
225 |
|
} |
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
1 |
@Override... |
228 |
|
public List<StructureCommandI> showBackbone() |
229 |
|
{ |
230 |
1 |
return SHOW_BACKBONE; |
231 |
|
} |
232 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
233 |
4 |
@Override... |
234 |
|
protected StructureCommandI colourResidues(String atomSpec, Color colour) |
235 |
|
{ |
236 |
|
|
237 |
4 |
return new StructureCommand("color", getColourString(colour), atomSpec); |
238 |
|
} |
239 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
240 |
1 |
@Override... |
241 |
|
protected String getResidueSpec(String residue) |
242 |
|
{ |
243 |
|
|
244 |
1 |
return "resn " + residue; |
245 |
|
} |
246 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
247 |
1 |
@Override... |
248 |
|
public StructureCommandI loadFile(String file) |
249 |
|
{ |
250 |
1 |
return new StructureCommand("load", file); |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
@param |
259 |
|
@return |
260 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
261 |
1 |
@Override... |
262 |
|
public List<StructureCommandI> colourBySequence( |
263 |
|
Map<Object, AtomSpecModel> colourMap) |
264 |
|
{ |
265 |
1 |
List<StructureCommandI> commands = new ArrayList<>(); |
266 |
1 |
for (Object key : colourMap.keySet()) |
267 |
|
{ |
268 |
3 |
Color colour = (Color) key; |
269 |
3 |
final AtomSpecModel colourData = colourMap.get(colour); |
270 |
3 |
commands.add(getColourCommand(colourData, colour)); |
271 |
|
} |
272 |
|
|
273 |
1 |
return commands; |
274 |
|
} |
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
@param |
285 |
|
@param |
286 |
|
@param |
287 |
|
@return |
288 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
289 |
7 |
protected StructureCommandI setAttribute(String attributeName,... |
290 |
|
String attributeValue, AtomSpecModel atomSpecModel) |
291 |
|
{ |
292 |
7 |
StringBuilder sb = new StringBuilder(128); |
293 |
7 |
sb.append("p.").append(attributeName).append("='") |
294 |
|
.append(attributeValue).append("'"); |
295 |
7 |
String atomSpec = getAtomSpec(atomSpecModel, AtomSpecType.RESIDUE_ONLY); |
296 |
7 |
return new StructureCommand("iterate", atomSpec, sb.toString()); |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
@param |
314 |
|
@return |
315 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
316 |
5 |
@Override... |
317 |
|
public List<StructureCommandI> setAttributes( |
318 |
|
Map<String, Map<Object, AtomSpecModel>> featureMap) |
319 |
|
{ |
320 |
5 |
List<StructureCommandI> commands = new ArrayList<>(); |
321 |
5 |
for (String featureType : featureMap.keySet()) |
322 |
|
{ |
323 |
5 |
String attributeName = makeAttributeName(featureType); |
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
5 |
Map<Object, AtomSpecModel> values = featureMap.get(featureType); |
332 |
5 |
for (Object value : values.keySet()) |
333 |
|
{ |
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
6 |
AtomSpecModel atomSpecModel = values.get(value); |
340 |
6 |
String featureValue = value.toString(); |
341 |
6 |
featureValue = featureValue.replaceAll("\\'", "'"); |
342 |
6 |
StructureCommandI cmd = setAttribute(attributeName, featureValue, |
343 |
|
atomSpecModel); |
344 |
6 |
commands.add(cmd); |
345 |
|
} |
346 |
|
} |
347 |
|
|
348 |
5 |
return commands; |
349 |
|
} |
350 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
351 |
1 |
@Override... |
352 |
|
public StructureCommandI openSession(String filepath) |
353 |
|
{ |
354 |
|
|
355 |
|
|
356 |
1 |
return new StructureCommand("load", filepath, "", "0", "pse"); |
357 |
|
} |
358 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
359 |
1 |
@Override... |
360 |
|
public StructureCommandI closeViewer() |
361 |
|
{ |
362 |
|
|
363 |
1 |
return CLOSE_PYMOL; |
364 |
|
} |
365 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
366 |
0 |
@Override... |
367 |
|
public List<StructureCommandI> centerViewOn(List<AtomSpecModel> residues) |
368 |
|
{ |
369 |
|
|
370 |
0 |
return null; |
371 |
|
} |
372 |
|
|
373 |
|
} |