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