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 |
|
package ext.edu.ucsf.rbvi.strucviz2; |
34 |
|
|
35 |
|
import java.awt.Color; |
36 |
|
import java.io.BufferedReader; |
37 |
|
import java.io.File; |
38 |
|
import java.io.IOException; |
39 |
|
import java.io.InputStream; |
40 |
|
import java.io.InputStreamReader; |
41 |
|
import java.io.UnsupportedEncodingException; |
42 |
|
import java.net.URLEncoder; |
43 |
|
import java.nio.charset.StandardCharsets; |
44 |
|
import java.nio.file.Paths; |
45 |
|
import java.util.ArrayList; |
46 |
|
import java.util.Collection; |
47 |
|
import java.util.HashMap; |
48 |
|
import java.util.List; |
49 |
|
import java.util.Map; |
50 |
|
|
51 |
|
import org.apache.http.NameValuePair; |
52 |
|
import org.apache.http.message.BasicNameValuePair; |
53 |
|
import org.slf4j.Logger; |
54 |
|
import org.slf4j.LoggerFactory; |
55 |
|
|
56 |
|
import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType; |
57 |
|
import ext.edu.ucsf.rbvi.strucviz2.port.ListenerThreads; |
58 |
|
import jalview.ws.HttpClientUtils; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
|
|
| 0% |
Uncovered Elements: 449 (449) |
Complexity: 122 |
Complexity Density: 0.42 |
|
63 |
|
public class ChimeraManager |
64 |
|
{ |
65 |
|
private static final int REST_REPLY_TIMEOUT_MS = 15000; |
66 |
|
|
67 |
|
private static final int CONNECTION_TIMEOUT_MS = 100; |
68 |
|
|
69 |
|
private static final boolean debug = false; |
70 |
|
|
71 |
|
private int chimeraRestPort; |
72 |
|
|
73 |
|
private Process chimera; |
74 |
|
|
75 |
|
private ListenerThreads chimeraListenerThread; |
76 |
|
|
77 |
|
private Map<Integer, ChimeraModel> currentModelsMap; |
78 |
|
|
79 |
|
private Logger logger = LoggerFactory |
80 |
|
.getLogger(ext.edu.ucsf.rbvi.strucviz2.ChimeraManager.class); |
81 |
|
|
82 |
|
private StructureManager structureManager; |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
84 |
0 |
public ChimeraManager(StructureManager structureManager)... |
85 |
|
{ |
86 |
0 |
this.structureManager = structureManager; |
87 |
0 |
chimera = null; |
88 |
0 |
chimeraListenerThread = null; |
89 |
0 |
currentModelsMap = new HashMap<>(); |
90 |
|
|
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
93 |
0 |
public List<ChimeraModel> getChimeraModels(String modelName)... |
94 |
|
{ |
95 |
0 |
List<ChimeraModel> models = getChimeraModels(modelName, |
96 |
|
ModelType.PDB_MODEL); |
97 |
0 |
models.addAll(getChimeraModels(modelName, ModelType.SMILES)); |
98 |
0 |
return models; |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
101 |
0 |
public List<ChimeraModel> getChimeraModels(String modelName,... |
102 |
|
ModelType modelType) |
103 |
|
{ |
104 |
0 |
List<ChimeraModel> models = new ArrayList<>(); |
105 |
0 |
for (ChimeraModel model : currentModelsMap.values()) |
106 |
|
{ |
107 |
0 |
if (modelName.equals(model.getModelName()) |
108 |
|
&& modelType.equals(model.getModelType())) |
109 |
|
{ |
110 |
0 |
models.add(model); |
111 |
|
} |
112 |
|
} |
113 |
0 |
return models; |
114 |
|
} |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
116 |
0 |
public Map<String, List<ChimeraModel>> getChimeraModelsMap()... |
117 |
|
{ |
118 |
0 |
Map<String, List<ChimeraModel>> models = new HashMap<>(); |
119 |
0 |
for (ChimeraModel model : currentModelsMap.values()) |
120 |
|
{ |
121 |
0 |
String modelName = model.getModelName(); |
122 |
0 |
if (!models.containsKey(modelName)) |
123 |
|
{ |
124 |
0 |
models.put(modelName, new ArrayList<ChimeraModel>()); |
125 |
|
} |
126 |
0 |
if (!models.get(modelName).contains(model)) |
127 |
|
{ |
128 |
0 |
models.get(modelName).add(model); |
129 |
|
} |
130 |
|
} |
131 |
0 |
return models; |
132 |
|
} |
133 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
134 |
0 |
public ChimeraModel getChimeraModel(Integer modelNumber,... |
135 |
|
Integer subModelNumber) |
136 |
|
{ |
137 |
0 |
Integer key = ChimUtils.makeModelKey(modelNumber, subModelNumber); |
138 |
0 |
if (currentModelsMap.containsKey(key)) |
139 |
|
{ |
140 |
0 |
return currentModelsMap.get(key); |
141 |
|
} |
142 |
0 |
return null; |
143 |
|
} |
144 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
0 |
public ChimeraModel getChimeraModel()... |
146 |
|
{ |
147 |
0 |
return currentModelsMap.values().iterator().next(); |
148 |
|
} |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
0 |
public Collection<ChimeraModel> getChimeraModels()... |
151 |
|
{ |
152 |
|
|
153 |
0 |
return currentModelsMap.values(); |
154 |
|
} |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
156 |
0 |
public int getChimeraModelsCount(boolean smiles)... |
157 |
|
{ |
158 |
|
|
159 |
0 |
int counter = currentModelsMap.size(); |
160 |
0 |
if (smiles) |
161 |
|
{ |
162 |
0 |
return counter; |
163 |
|
} |
164 |
|
|
165 |
0 |
for (ChimeraModel model : currentModelsMap.values()) |
166 |
|
{ |
167 |
0 |
if (model.getModelType() == ModelType.SMILES) |
168 |
|
{ |
169 |
0 |
counter--; |
170 |
|
} |
171 |
|
} |
172 |
0 |
return counter; |
173 |
|
} |
174 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
175 |
0 |
public boolean hasChimeraModel(Integer modelNubmer)... |
176 |
|
{ |
177 |
0 |
return hasChimeraModel(modelNubmer, 0); |
178 |
|
} |
179 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
180 |
0 |
public boolean hasChimeraModel(Integer modelNubmer,... |
181 |
|
Integer subModelNumber) |
182 |
|
{ |
183 |
0 |
return currentModelsMap.containsKey( |
184 |
|
ChimUtils.makeModelKey(modelNubmer, subModelNumber)); |
185 |
|
} |
186 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
187 |
0 |
public void addChimeraModel(Integer modelNumber, Integer subModelNumber,... |
188 |
|
ChimeraModel model) |
189 |
|
{ |
190 |
0 |
currentModelsMap.put( |
191 |
|
ChimUtils.makeModelKey(modelNumber, subModelNumber), model); |
192 |
|
} |
193 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
194 |
0 |
public void removeChimeraModel(Integer modelNumber,... |
195 |
|
Integer subModelNumber) |
196 |
|
{ |
197 |
0 |
int modelKey = ChimUtils.makeModelKey(modelNumber, subModelNumber); |
198 |
0 |
if (currentModelsMap.containsKey(modelKey)) |
199 |
|
{ |
200 |
0 |
currentModelsMap.remove(modelKey); |
201 |
|
} |
202 |
|
} |
203 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
204 |
0 |
public List<ChimeraModel> openModel(String modelPath, ModelType type)... |
205 |
|
{ |
206 |
0 |
return openModel(modelPath, getFileNameFromPath(modelPath), type); |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
@param |
213 |
|
@param |
214 |
|
@param |
215 |
|
@return |
216 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 8 |
Complexity Density: 0.36 |
|
217 |
0 |
public List<ChimeraModel> openModel(String modelPath, String modelName,... |
218 |
|
ModelType type) |
219 |
|
{ |
220 |
0 |
logger.info("chimera open " + modelPath); |
221 |
|
|
222 |
0 |
List<ChimeraModel> modelList = getModelList(); |
223 |
0 |
List<String> response = null; |
224 |
|
|
225 |
0 |
if (type == ModelType.MODBASE_MODEL) |
226 |
|
{ |
227 |
0 |
response = sendChimeraCommand("open modbase:" + modelPath, true); |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
} |
232 |
|
else |
233 |
|
{ |
234 |
0 |
response = sendChimeraCommand("open " + modelPath, true); |
235 |
|
} |
236 |
0 |
if (response == null) |
237 |
|
{ |
238 |
|
|
239 |
0 |
logger.warn("Could not open " + modelPath); |
240 |
0 |
return null; |
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
|
|
245 |
0 |
for (ChimeraModel newModel : getModelList()) |
246 |
|
{ |
247 |
0 |
if (!modelList.contains(newModel)) |
248 |
|
{ |
249 |
0 |
newModel.setModelName(modelName); |
250 |
0 |
sendChimeraCommand("setattr M name " + modelName + " #" |
251 |
|
+ newModel.getModelNumber(), false); |
252 |
0 |
modelList.add(newModel); |
253 |
|
} |
254 |
|
} |
255 |
|
|
256 |
|
|
257 |
0 |
for (ChimeraModel chimeraModel : modelList) |
258 |
|
{ |
259 |
|
|
260 |
0 |
Color modelColor = isChimeraX() ? null : getModelColor(chimeraModel); |
261 |
0 |
if (modelColor != null) |
262 |
|
{ |
263 |
0 |
chimeraModel.setModelColor(modelColor); |
264 |
|
} |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
0 |
if (type != ModelType.SMILES && !isChimeraX()) |
272 |
|
{ |
273 |
0 |
addResidues(chimeraModel); |
274 |
|
} |
275 |
|
} |
276 |
|
|
277 |
0 |
sendChimeraCommand("focus", false); |
278 |
|
|
279 |
0 |
return modelList; |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
@param |
287 |
|
@return |
288 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
289 |
0 |
private String getFileNameFromPath(String modelPath)... |
290 |
|
{ |
291 |
0 |
String modelName = modelPath; |
292 |
0 |
if (modelPath == null) |
293 |
|
{ |
294 |
0 |
return null; |
295 |
|
} |
296 |
|
|
297 |
0 |
if (modelPath.lastIndexOf(File.separator) > 0) |
298 |
|
{ |
299 |
0 |
modelName = modelPath |
300 |
|
.substring(modelPath.lastIndexOf(File.separator) + 1); |
301 |
|
} |
302 |
0 |
else if (modelPath.lastIndexOf("/") > 0) |
303 |
|
{ |
304 |
0 |
modelName = modelPath.substring(modelPath.lastIndexOf("/") + 1); |
305 |
|
} |
306 |
0 |
return modelName; |
307 |
|
} |
308 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
309 |
0 |
public void closeModel(ChimeraModel model)... |
310 |
|
{ |
311 |
|
|
312 |
|
|
313 |
|
|
314 |
0 |
stopListening(); |
315 |
0 |
logger.info("chimera close model " + model.getModelName()); |
316 |
0 |
if (currentModelsMap.containsKey(ChimUtils.makeModelKey( |
317 |
|
model.getModelNumber(), model.getSubModelNumber()))) |
318 |
|
{ |
319 |
0 |
sendChimeraCommand("close " + model.toSpec(), false); |
320 |
|
|
321 |
0 |
currentModelsMap.remove(ChimUtils.makeModelKey(model.getModelNumber(), |
322 |
|
model.getSubModelNumber())); |
323 |
|
|
324 |
|
} |
325 |
|
else |
326 |
|
{ |
327 |
0 |
logger.warn("Could not find model " + model.getModelName() |
328 |
|
+ " to close."); |
329 |
|
} |
330 |
0 |
startListening(); |
331 |
|
} |
332 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
333 |
0 |
public void startListening()... |
334 |
|
{ |
335 |
0 |
sendChimeraCommand("listen start models; listen start selection", |
336 |
|
false); |
337 |
|
} |
338 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
339 |
0 |
public void stopListening()... |
340 |
|
{ |
341 |
0 |
String command = "listen stop models ; listen stop selection "; |
342 |
0 |
sendChimeraCommand(command, false); |
343 |
|
} |
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
@param |
349 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
350 |
0 |
public void startListening(String uri)... |
351 |
|
{ |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
0 |
String command = "listen start models url " + uri; |
356 |
0 |
sendChimeraCommand(command, false); |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
0 |
command = "listen start select prefix SelectionChanged url " + uri; |
362 |
0 |
sendChimeraCommand(command, false); |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
@param |
369 |
|
|
370 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
371 |
0 |
public void select(String command)... |
372 |
|
{ |
373 |
0 |
sendChimeraCommand("listen stop selection; " + command |
374 |
|
+ "; listen start selection", false); |
375 |
|
} |
376 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
377 |
0 |
public void focus()... |
378 |
|
{ |
379 |
0 |
sendChimeraCommand("focus", false); |
380 |
|
} |
381 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
382 |
0 |
public void clearOnChimeraExit()... |
383 |
|
{ |
384 |
0 |
chimera = null; |
385 |
0 |
currentModelsMap.clear(); |
386 |
0 |
this.chimeraRestPort = 0; |
387 |
0 |
structureManager.clearOnChimeraExit(); |
388 |
|
} |
389 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
390 |
0 |
public void exitChimera()... |
391 |
|
{ |
392 |
0 |
if (isChimeraLaunched() && chimera != null) |
393 |
|
{ |
394 |
0 |
sendChimeraCommand("stop really", false); |
395 |
0 |
try |
396 |
|
{ |
397 |
|
|
398 |
|
|
399 |
0 |
chimera.destroy(); |
400 |
|
} catch (Exception ex) |
401 |
|
{ |
402 |
|
|
403 |
|
} |
404 |
|
} |
405 |
0 |
clearOnChimeraExit(); |
406 |
|
} |
407 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
408 |
0 |
public Map<Integer, ChimeraModel> getSelectedModels()... |
409 |
|
{ |
410 |
0 |
Map<Integer, ChimeraModel> selectedModelsMap = new HashMap<>(); |
411 |
0 |
List<String> chimeraReply = sendChimeraCommand( |
412 |
|
"list selection level molecule", true); |
413 |
0 |
if (chimeraReply != null) |
414 |
|
{ |
415 |
0 |
for (String modelLine : chimeraReply) |
416 |
|
{ |
417 |
0 |
ChimeraModel chimeraModel = new ChimeraModel(modelLine); |
418 |
0 |
Integer modelKey = ChimUtils.makeModelKey( |
419 |
|
chimeraModel.getModelNumber(), |
420 |
|
chimeraModel.getSubModelNumber()); |
421 |
0 |
selectedModelsMap.put(modelKey, chimeraModel); |
422 |
|
} |
423 |
|
} |
424 |
0 |
return selectedModelsMap; |
425 |
|
} |
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
@return |
432 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
433 |
0 |
public List<String> getSelectedResidueSpecs()... |
434 |
|
{ |
435 |
0 |
List<String> selectedResidues = new ArrayList<>(); |
436 |
|
|
437 |
0 |
String command = "list selection level residue"; |
438 |
0 |
List<String> chimeraReply = sendChimeraCommand(command, true); |
439 |
0 |
if (chimeraReply != null) |
440 |
|
{ |
441 |
|
|
442 |
|
|
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
|
447 |
|
|
448 |
|
|
449 |
0 |
for (String inputLine : chimeraReply) |
450 |
|
{ |
451 |
0 |
String[] inputLineParts = inputLine.split("\\s+"); |
452 |
0 |
if (inputLineParts.length >= 5) |
453 |
|
{ |
454 |
0 |
selectedResidues.add(inputLineParts[2]); |
455 |
|
} |
456 |
|
} |
457 |
|
} |
458 |
0 |
return selectedResidues; |
459 |
|
} |
460 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
461 |
0 |
public void getSelectedResidues(... |
462 |
|
Map<Integer, ChimeraModel> selectedModelsMap) |
463 |
|
{ |
464 |
0 |
List<String> chimeraReply = sendChimeraCommand( |
465 |
|
"list selection level residue", true); |
466 |
0 |
if (chimeraReply != null) |
467 |
|
{ |
468 |
0 |
for (String inputLine : chimeraReply) |
469 |
|
{ |
470 |
0 |
ChimeraResidue r = new ChimeraResidue(inputLine); |
471 |
0 |
Integer modelKey = ChimUtils.makeModelKey(r.getModelNumber(), |
472 |
|
r.getSubModelNumber()); |
473 |
0 |
if (selectedModelsMap.containsKey(modelKey)) |
474 |
|
{ |
475 |
0 |
ChimeraModel model = selectedModelsMap.get(modelKey); |
476 |
0 |
model.addResidue(r); |
477 |
|
} |
478 |
|
} |
479 |
|
} |
480 |
|
} |
481 |
|
|
482 |
|
|
483 |
|
|
484 |
|
|
485 |
|
|
486 |
|
|
487 |
|
@return |
488 |
|
|
489 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
490 |
0 |
public List<ChimeraModel> getModelList()... |
491 |
|
{ |
492 |
0 |
List<ChimeraModel> modelList = new ArrayList<>(); |
493 |
0 |
String command = "list models type " |
494 |
0 |
+ (isChimeraX() ? "AtomicStructure" : "molecule"); |
495 |
0 |
List<String> list = sendChimeraCommand(command, true); |
496 |
0 |
if (list != null) |
497 |
|
{ |
498 |
0 |
for (String modelLine : list) |
499 |
|
{ |
500 |
0 |
try |
501 |
|
{ |
502 |
0 |
ChimeraModel chimeraModel = new ChimeraModel(modelLine); |
503 |
0 |
modelList.add(chimeraModel); |
504 |
|
} catch (NullPointerException e) |
505 |
|
{ |
506 |
|
|
507 |
|
} |
508 |
|
} |
509 |
|
} |
510 |
0 |
return modelList; |
511 |
|
} |
512 |
|
|
513 |
|
|
514 |
|
|
515 |
|
|
516 |
|
|
517 |
|
|
518 |
|
@return |
519 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
520 |
0 |
public List<String> getPresets()... |
521 |
|
{ |
522 |
0 |
ArrayList<String> presetList = new ArrayList<>(); |
523 |
0 |
List<String> output = sendChimeraCommand("preset list", true); |
524 |
0 |
if (output != null) |
525 |
|
{ |
526 |
0 |
for (String preset : output) |
527 |
|
{ |
528 |
0 |
preset = preset.substring(7); |
529 |
0 |
preset = preset.replaceFirst("\"", "("); |
530 |
0 |
preset = preset.replaceFirst("\"", ")"); |
531 |
|
|
532 |
0 |
presetList.add(preset); |
533 |
|
} |
534 |
|
} |
535 |
0 |
return presetList; |
536 |
|
} |
537 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
538 |
0 |
public boolean isChimeraLaunched()... |
539 |
|
{ |
540 |
0 |
boolean launched = false; |
541 |
0 |
if (chimera != null) |
542 |
|
{ |
543 |
0 |
try |
544 |
|
{ |
545 |
0 |
chimera.exitValue(); |
546 |
|
|
547 |
|
} catch (IllegalThreadStateException e) |
548 |
|
{ |
549 |
|
|
550 |
0 |
launched = true; |
551 |
|
} |
552 |
|
} |
553 |
0 |
return launched; |
554 |
|
} |
555 |
|
|
556 |
|
|
557 |
|
|
558 |
|
|
559 |
|
|
560 |
|
|
561 |
|
@param |
562 |
|
@return |
563 |
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 5 |
Complexity Density: 0.19 |
|
564 |
0 |
public boolean launchChimera(List<String> chimeraPaths)... |
565 |
|
{ |
566 |
|
|
567 |
0 |
if (isChimeraLaunched()) |
568 |
|
{ |
569 |
0 |
return true; |
570 |
|
} |
571 |
|
|
572 |
|
|
573 |
0 |
String error = "Error message: "; |
574 |
0 |
String workingPath = ""; |
575 |
|
|
576 |
0 |
for (String chimeraPath : chimeraPaths) |
577 |
|
{ |
578 |
0 |
try |
579 |
|
{ |
580 |
|
|
581 |
0 |
chimeraPath = Paths.get(chimeraPath).toRealPath().toString(); |
582 |
0 |
File path = new File(chimeraPath); |
583 |
|
|
584 |
|
|
585 |
0 |
if (!path.canExecute()) |
586 |
|
{ |
587 |
0 |
error += "File '" + path + "' does not exist.\n"; |
588 |
0 |
continue; |
589 |
|
} |
590 |
0 |
List<String> args = new ArrayList<>(); |
591 |
0 |
args.add(chimeraPath); |
592 |
|
|
593 |
|
|
594 |
0 |
addLaunchArguments(args); |
595 |
0 |
ProcessBuilder pb = new ProcessBuilder(args); |
596 |
0 |
chimera = pb.start(); |
597 |
0 |
error = ""; |
598 |
0 |
workingPath = chimeraPath; |
599 |
0 |
break; |
600 |
|
} catch (Exception e) |
601 |
|
{ |
602 |
|
|
603 |
0 |
error += e.getMessage(); |
604 |
|
} |
605 |
|
} |
606 |
|
|
607 |
0 |
if (error.length() == 0) |
608 |
|
{ |
609 |
0 |
this.chimeraRestPort = getPortNumber(); |
610 |
0 |
System.out.println( |
611 |
|
"Chimera REST API started on port " + chimeraRestPort); |
612 |
|
|
613 |
0 |
structureManager.setChimeraPathProperty(workingPath); |
614 |
|
|
615 |
|
|
616 |
|
|
617 |
0 |
return (chimeraRestPort > 0); |
618 |
|
} |
619 |
|
|
620 |
|
|
621 |
0 |
logger.warn(error); |
622 |
0 |
return false; |
623 |
|
} |
624 |
|
|
625 |
|
|
626 |
|
|
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
@param |
631 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
632 |
0 |
protected void addLaunchArguments(List<String> args)... |
633 |
|
{ |
634 |
0 |
args.add("--start"); |
635 |
0 |
args.add("RESTServer"); |
636 |
|
} |
637 |
|
|
638 |
|
|
639 |
|
|
640 |
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 9 |
Complexity Density: 0.38 |
|
641 |
0 |
private int getPortNumber()... |
642 |
|
{ |
643 |
0 |
int port = 0; |
644 |
0 |
InputStream readChan = chimera.getInputStream(); |
645 |
0 |
BufferedReader lineReader = new BufferedReader( |
646 |
|
new InputStreamReader(readChan)); |
647 |
0 |
StringBuilder responses = new StringBuilder(); |
648 |
0 |
try |
649 |
|
{ |
650 |
0 |
String response = lineReader.readLine(); |
651 |
0 |
while (response != null) |
652 |
|
{ |
653 |
0 |
responses.append("\n" + response); |
654 |
|
|
655 |
|
|
656 |
0 |
if (response.startsWith("REST server")) |
657 |
|
{ |
658 |
0 |
String[] tokens = response.split(" "); |
659 |
0 |
for (int i = 0; i < tokens.length - 1; i++) |
660 |
|
{ |
661 |
0 |
if ("port".equals(tokens[i])) |
662 |
|
{ |
663 |
0 |
port = Integer.parseInt(tokens[i + 1]); |
664 |
0 |
break; |
665 |
|
} |
666 |
|
} |
667 |
|
} |
668 |
0 |
if (port > 0) |
669 |
|
{ |
670 |
0 |
break; |
671 |
|
} |
672 |
0 |
response = lineReader.readLine(); |
673 |
|
} |
674 |
|
} catch (Exception e) |
675 |
|
{ |
676 |
0 |
logger.error("Failed to get REST port number from " + responses + ": " |
677 |
|
+ e.getMessage()); |
678 |
|
} finally |
679 |
|
{ |
680 |
0 |
try |
681 |
|
{ |
682 |
0 |
lineReader.close(); |
683 |
|
} catch (IOException e2) |
684 |
|
{ |
685 |
|
} |
686 |
|
} |
687 |
0 |
if (port == 0) |
688 |
|
{ |
689 |
0 |
System.err.println( |
690 |
|
"Failed to start Chimera with REST service, response was: " |
691 |
|
+ responses); |
692 |
|
} |
693 |
0 |
logger.info( |
694 |
|
"Chimera REST service listening on port " + chimeraRestPort); |
695 |
0 |
return port; |
696 |
|
} |
697 |
|
|
698 |
|
|
699 |
|
|
700 |
|
|
701 |
|
@param |
702 |
|
|
703 |
|
@return |
704 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
705 |
0 |
public Color getModelColor(ChimeraModel model)... |
706 |
|
{ |
707 |
0 |
List<String> colorLines = sendChimeraCommand( |
708 |
|
"list model spec " + model.toSpec() + " attribute color", true); |
709 |
0 |
if (colorLines == null || colorLines.size() == 0) |
710 |
|
{ |
711 |
0 |
return null; |
712 |
|
} |
713 |
0 |
return ChimUtils.parseModelColor(colorLines.get(0)); |
714 |
|
} |
715 |
|
|
716 |
|
|
717 |
|
|
718 |
|
|
719 |
|
|
720 |
|
|
721 |
|
|
722 |
|
@param |
723 |
|
|
724 |
|
|
725 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
726 |
0 |
public void addResidues(ChimeraModel model)... |
727 |
|
{ |
728 |
0 |
int modelNumber = model.getModelNumber(); |
729 |
0 |
int subModelNumber = model.getSubModelNumber(); |
730 |
|
|
731 |
0 |
List<String> reply = sendChimeraCommand( |
732 |
|
"list residues spec " + model.toSpec(), true); |
733 |
0 |
if (reply == null) |
734 |
|
{ |
735 |
0 |
return; |
736 |
|
} |
737 |
0 |
for (String inputLine : reply) |
738 |
|
{ |
739 |
0 |
ChimeraResidue r = new ChimeraResidue(inputLine); |
740 |
0 |
if (r.getModelNumber() == modelNumber |
741 |
|
|| r.getSubModelNumber() == subModelNumber) |
742 |
|
{ |
743 |
0 |
model.addResidue(r); |
744 |
|
} |
745 |
|
} |
746 |
|
} |
747 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
748 |
0 |
public List<String> getAttrList()... |
749 |
|
{ |
750 |
0 |
List<String> attributes = new ArrayList<>(); |
751 |
0 |
String command = (isChimeraX() ? "info " : "list ") + "resattr"; |
752 |
0 |
final List<String> reply = sendChimeraCommand(command, true); |
753 |
0 |
if (reply != null) |
754 |
|
{ |
755 |
0 |
for (String inputLine : reply) |
756 |
|
{ |
757 |
0 |
String[] lineParts = inputLine.split("\\s"); |
758 |
0 |
if (lineParts.length == 2 && lineParts[0].equals("resattr")) |
759 |
|
{ |
760 |
0 |
attributes.add(lineParts[1]); |
761 |
|
} |
762 |
|
} |
763 |
|
} |
764 |
0 |
return attributes; |
765 |
|
} |
766 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 8 |
Complexity Density: 0.42 |
|
767 |
0 |
public Map<ChimeraResidue, Object> getAttrValues(String aCommand,... |
768 |
|
ChimeraModel model) |
769 |
|
{ |
770 |
0 |
Map<ChimeraResidue, Object> values = new HashMap<>(); |
771 |
0 |
final List<String> reply = sendChimeraCommand("list residue spec " |
772 |
|
+ model.toSpec() + " attribute " + aCommand, true); |
773 |
0 |
if (reply != null) |
774 |
|
{ |
775 |
0 |
for (String inputLine : reply) |
776 |
|
{ |
777 |
0 |
String[] lineParts = inputLine.split("\\s"); |
778 |
0 |
if (lineParts.length == 5) |
779 |
|
{ |
780 |
0 |
ChimeraResidue residue = ChimUtils.getResidue(lineParts[2], |
781 |
|
model); |
782 |
0 |
String value = lineParts[4]; |
783 |
0 |
if (residue != null) |
784 |
|
{ |
785 |
0 |
if (value.equals("None")) |
786 |
|
{ |
787 |
0 |
continue; |
788 |
|
} |
789 |
0 |
if (value.equals("True") || value.equals("False")) |
790 |
|
{ |
791 |
0 |
values.put(residue, Boolean.valueOf(value)); |
792 |
0 |
continue; |
793 |
|
} |
794 |
0 |
try |
795 |
|
{ |
796 |
0 |
Double doubleValue = Double.valueOf(value); |
797 |
0 |
values.put(residue, doubleValue); |
798 |
|
} catch (NumberFormatException ex) |
799 |
|
{ |
800 |
0 |
values.put(residue, value); |
801 |
|
} |
802 |
|
} |
803 |
|
} |
804 |
|
} |
805 |
|
} |
806 |
0 |
return values; |
807 |
|
} |
808 |
|
|
809 |
|
private volatile boolean busy = false; |
810 |
|
|
811 |
|
|
812 |
|
|
813 |
|
|
814 |
|
@param |
815 |
|
|
816 |
|
@param |
817 |
|
|
818 |
|
|
819 |
|
@return |
820 |
|
|
821 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 9 |
Complexity Density: 0.53 |
|
822 |
0 |
public List<String> sendChimeraCommand(String command, boolean reply)... |
823 |
|
{ |
824 |
0 |
if (debug) |
825 |
|
{ |
826 |
0 |
System.out.println("chimeradebug>> " + command); |
827 |
|
} |
828 |
0 |
if (!isChimeraLaunched() || command == null |
829 |
|
|| "".equals(command.trim())) |
830 |
|
{ |
831 |
0 |
return null; |
832 |
|
} |
833 |
|
|
834 |
|
|
835 |
|
|
836 |
|
|
837 |
0 |
int waited = 0; |
838 |
0 |
int pause = 25; |
839 |
0 |
while (busy && waited < 1001) |
840 |
|
{ |
841 |
0 |
try |
842 |
|
{ |
843 |
0 |
Thread.sleep(pause); |
844 |
0 |
waited += pause; |
845 |
|
} catch (InterruptedException q) |
846 |
|
{ |
847 |
|
} |
848 |
|
} |
849 |
0 |
busy = true; |
850 |
0 |
long startTime = System.currentTimeMillis(); |
851 |
0 |
try |
852 |
|
{ |
853 |
0 |
return sendRestCommand(command); |
854 |
|
} finally |
855 |
|
{ |
856 |
|
|
857 |
|
|
858 |
|
|
859 |
0 |
busy = false; |
860 |
0 |
if (debug) |
861 |
|
{ |
862 |
0 |
System.out.println("Chimera command took " |
863 |
|
+ (System.currentTimeMillis() - startTime) + "ms: " |
864 |
|
+ command); |
865 |
|
} |
866 |
|
} |
867 |
|
} |
868 |
|
|
869 |
|
|
870 |
|
|
871 |
|
|
872 |
|
@param |
873 |
|
@return |
874 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 8 |
Complexity Density: 0.4 |
|
875 |
0 |
protected List<String> sendRestCommand(String command)... |
876 |
|
{ |
877 |
0 |
String restUrl = "http://127.0.0.1:" + this.chimeraRestPort + "/run"; |
878 |
0 |
List<NameValuePair> commands = new ArrayList<>(1); |
879 |
0 |
String method = getHttpRequestMethod(); |
880 |
0 |
if ("GET".equals(method)) |
881 |
|
{ |
882 |
0 |
try |
883 |
|
{ |
884 |
0 |
command = URLEncoder.encode(command, StandardCharsets.UTF_8.name()); |
885 |
|
} catch (UnsupportedEncodingException e) |
886 |
|
{ |
887 |
0 |
command = command.replace(" ", "+").replace("#", "%23") |
888 |
|
.replace("|", "%7C").replace(";", "%3B") |
889 |
|
.replace(":", "%3A"); |
890 |
|
} |
891 |
|
} |
892 |
0 |
commands.add(new BasicNameValuePair("command", command)); |
893 |
|
|
894 |
0 |
List<String> reply = new ArrayList<>(); |
895 |
0 |
BufferedReader response = null; |
896 |
0 |
try |
897 |
|
{ |
898 |
0 |
response = "GET".equals(method) |
899 |
|
? HttpClientUtils.doHttpGet(restUrl, commands, |
900 |
|
CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS) |
901 |
|
: HttpClientUtils.doHttpUrlPost(restUrl, commands, |
902 |
|
CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS); |
903 |
0 |
String line = ""; |
904 |
0 |
while ((line = response.readLine()) != null) |
905 |
|
{ |
906 |
0 |
reply.add(line); |
907 |
|
} |
908 |
|
} catch (Exception e) |
909 |
|
{ |
910 |
0 |
logger.error("REST call '" + command + "' failed: " + e.getMessage()); |
911 |
|
} finally |
912 |
|
{ |
913 |
0 |
if (response != null) |
914 |
|
{ |
915 |
0 |
try |
916 |
|
{ |
917 |
0 |
response.close(); |
918 |
|
} catch (IOException e) |
919 |
|
{ |
920 |
|
} |
921 |
|
} |
922 |
|
} |
923 |
0 |
return reply; |
924 |
|
} |
925 |
|
|
926 |
|
|
927 |
|
|
928 |
|
|
929 |
|
|
930 |
|
@return |
931 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
932 |
0 |
protected String getHttpRequestMethod()... |
933 |
|
{ |
934 |
0 |
return "POST"; |
935 |
|
} |
936 |
|
|
937 |
|
|
938 |
|
|
939 |
|
|
940 |
|
|
941 |
|
@param |
942 |
|
@param |
943 |
|
@return |
944 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.23 |
|
945 |
0 |
protected List<String> sendStdinCommand(String command, boolean readReply)... |
946 |
|
{ |
947 |
0 |
chimeraListenerThread.clearResponse(command); |
948 |
0 |
String text = command.concat("\n"); |
949 |
0 |
try |
950 |
|
{ |
951 |
|
|
952 |
0 |
chimera.getOutputStream().write(text.getBytes()); |
953 |
0 |
chimera.getOutputStream().flush(); |
954 |
|
} catch (IOException e) |
955 |
|
{ |
956 |
|
|
957 |
|
|
958 |
0 |
logger.warn("Unable to execute command: " + text); |
959 |
0 |
logger.warn("Exiting..."); |
960 |
0 |
clearOnChimeraExit(); |
961 |
0 |
return null; |
962 |
|
} |
963 |
0 |
if (!readReply) |
964 |
|
{ |
965 |
0 |
return null; |
966 |
|
} |
967 |
0 |
List<String> rsp = chimeraListenerThread.getResponse(command); |
968 |
0 |
return rsp; |
969 |
|
} |
970 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
971 |
0 |
public StructureManager getStructureManager()... |
972 |
|
{ |
973 |
0 |
return structureManager; |
974 |
|
} |
975 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
976 |
0 |
public boolean isBusy()... |
977 |
|
{ |
978 |
0 |
return busy; |
979 |
|
} |
980 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
981 |
0 |
public Process getChimeraProcess()... |
982 |
|
{ |
983 |
0 |
return chimera; |
984 |
|
} |
985 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
986 |
0 |
public boolean isChimeraX()... |
987 |
|
{ |
988 |
0 |
return false; |
989 |
|
} |
990 |
|
} |