1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import java.awt.event.ActionEvent; |
24 |
|
import java.awt.event.ActionListener; |
25 |
|
import java.io.File; |
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.List; |
28 |
|
import java.util.Map; |
29 |
|
|
30 |
|
import javax.swing.JInternalFrame; |
31 |
|
import javax.swing.JMenuItem; |
32 |
|
import javax.swing.event.InternalFrameAdapter; |
33 |
|
import javax.swing.event.InternalFrameEvent; |
34 |
|
|
35 |
|
import jalview.api.AlignmentViewPanel; |
36 |
|
import jalview.api.FeatureRenderer; |
37 |
|
import jalview.bin.Console; |
38 |
|
import jalview.datamodel.PDBEntry; |
39 |
|
import jalview.datamodel.SequenceI; |
40 |
|
import jalview.datamodel.StructureViewerModel; |
41 |
|
import jalview.datamodel.StructureViewerModel.StructureData; |
42 |
|
import jalview.gui.StructureViewer.ViewerType; |
43 |
|
import jalview.io.DataSourceType; |
44 |
|
import jalview.io.StructureFile; |
45 |
|
import jalview.structures.models.AAStructureBindingModel; |
46 |
|
import jalview.util.MessageManager; |
47 |
|
|
|
|
| 0% |
Uncovered Elements: 187 (187) |
Complexity: 39 |
Complexity Density: 0.3 |
|
48 |
|
public class PymolViewer extends StructureViewerBase |
49 |
|
{ |
50 |
|
private static final int myWidth = 500; |
51 |
|
|
52 |
|
private static final int myHeight = 150; |
53 |
|
|
54 |
|
private PymolBindingModel binding; |
55 |
|
|
56 |
|
private String pymolSessionFile; |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
58 |
0 |
public PymolViewer()... |
59 |
|
{ |
60 |
0 |
super(); |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
0 |
setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); |
67 |
|
} |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
69 |
0 |
public PymolViewer(PDBEntry pdb, SequenceI[] seqs, Object object,... |
70 |
|
AlignmentPanel ap) |
71 |
|
{ |
72 |
0 |
this(); |
73 |
0 |
openNewPymol(ap, new PDBEntry[] { pdb }, new SequenceI[][] { seqs }); |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
76 |
0 |
public PymolViewer(PDBEntry[] pe, boolean alignAdded, SequenceI[][] seqs,... |
77 |
|
AlignmentPanel ap) |
78 |
|
{ |
79 |
0 |
this(); |
80 |
0 |
setAlignAddedStructures(alignAdded); |
81 |
0 |
openNewPymol(ap, pe, seqs); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
@param |
88 |
|
@param |
89 |
|
@param |
90 |
|
@param |
91 |
|
@param |
92 |
|
@param |
93 |
|
@param |
94 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 3 |
Complexity Density: 0.14 |
|
95 |
0 |
public PymolViewer(StructureViewerModel viewerModel,... |
96 |
|
AlignmentPanel alignPanel, String sessionFile, String vid) |
97 |
|
{ |
98 |
|
|
99 |
0 |
this(); |
100 |
0 |
setViewId(vid); |
101 |
0 |
this.pymolSessionFile = sessionFile; |
102 |
0 |
Map<File, StructureData> pdbData = viewerModel.getFileData(); |
103 |
0 |
PDBEntry[] pdbArray = new PDBEntry[pdbData.size()]; |
104 |
0 |
SequenceI[][] seqsArray = new SequenceI[pdbData.size()][]; |
105 |
0 |
int i = 0; |
106 |
0 |
for (StructureData data : pdbData.values()) |
107 |
|
{ |
108 |
0 |
PDBEntry pdbentry = new PDBEntry(data.getPdbId(), null, |
109 |
|
PDBEntry.Type.PDB, data.getFilePath()); |
110 |
0 |
pdbArray[i] = pdbentry; |
111 |
0 |
List<SequenceI> sequencesForPdb = data.getSeqList(); |
112 |
0 |
seqsArray[i] = sequencesForPdb |
113 |
|
.toArray(new SequenceI[sequencesForPdb.size()]); |
114 |
0 |
i++; |
115 |
|
} |
116 |
|
|
117 |
0 |
openNewPymol(alignPanel, pdbArray, seqsArray); |
118 |
0 |
if (viewerModel.isColourByViewer()) |
119 |
|
{ |
120 |
0 |
binding.setColourBySequence(false); |
121 |
0 |
seqColour.setSelected(false); |
122 |
0 |
viewerColour.setSelected(true); |
123 |
|
} |
124 |
0 |
else if (viewerModel.isColourWithAlignPanel()) |
125 |
|
{ |
126 |
0 |
binding.setColourBySequence(true); |
127 |
0 |
seqColour.setSelected(true); |
128 |
0 |
viewerColour.setSelected(false); |
129 |
|
} |
130 |
|
} |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 2 |
Complexity Density: 0.13 |
|
132 |
0 |
private void openNewPymol(AlignmentPanel ap, PDBEntry[] pe,... |
133 |
|
SequenceI[][] seqs) |
134 |
|
{ |
135 |
0 |
createProgressBar(); |
136 |
0 |
binding = new PymolBindingModel(this, ap.getStructureSelectionManager(), |
137 |
|
pe, seqs); |
138 |
0 |
addAlignmentPanel(ap); |
139 |
0 |
useAlignmentPanelForColourbyseq(ap); |
140 |
|
|
141 |
0 |
if (pe.length > 1) |
142 |
|
{ |
143 |
0 |
useAlignmentPanelForSuperposition(ap); |
144 |
|
} |
145 |
0 |
binding.setColourBySequence(true); |
146 |
0 |
setSize(myWidth, myHeight); |
147 |
0 |
initMenus(); |
148 |
0 |
viewerActionMenu.setText("PyMOL"); |
149 |
0 |
updateTitleAndMenus(); |
150 |
|
|
151 |
0 |
addingStructures = false; |
152 |
0 |
worker = new Thread(this); |
153 |
0 |
worker.start(); |
154 |
|
|
155 |
0 |
this.addInternalFrameListener(new InternalFrameAdapter() |
156 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
0 |
@Override... |
158 |
|
public void internalFrameClosing( |
159 |
|
InternalFrameEvent internalFrameEvent) |
160 |
|
{ |
161 |
0 |
closeViewer(false); |
162 |
|
} |
163 |
|
}); |
164 |
|
|
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
170 |
0 |
protected void createProgressBar()... |
171 |
|
{ |
172 |
0 |
if (getProgressIndicator() == null) |
173 |
|
{ |
174 |
0 |
setProgressIndicator(new ProgressBar(statusPanel, statusBar)); |
175 |
|
} |
176 |
|
} |
177 |
|
|
|
|
| 0% |
Uncovered Elements: 83 (83) |
Complexity: 16 |
Complexity Density: 0.27 |
|
178 |
0 |
@Override... |
179 |
|
public void run() |
180 |
|
{ |
181 |
|
|
182 |
|
|
183 |
0 |
StringBuilder errormsgs = new StringBuilder(128); |
184 |
0 |
List<PDBEntry> filePDB = new ArrayList<>(); |
185 |
0 |
List<Integer> filePDBpos = new ArrayList<>(); |
186 |
0 |
String[] curfiles = binding.getStructureFiles(); |
187 |
|
|
188 |
0 |
for (int pi = 0; pi < binding.getPdbCount(); pi++) |
189 |
|
{ |
190 |
0 |
String file = null; |
191 |
0 |
PDBEntry thePdbEntry = binding.getPdbEntry(pi); |
192 |
0 |
if (thePdbEntry.getFile() == null) |
193 |
|
{ |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
0 |
file = fetchPdbFile(thePdbEntry); |
198 |
0 |
if (file == null) |
199 |
|
{ |
200 |
0 |
errormsgs.append("'" + thePdbEntry.getId() + "' "); |
201 |
|
} |
202 |
|
} |
203 |
|
else |
204 |
|
{ |
205 |
|
|
206 |
|
|
207 |
|
|
208 |
0 |
file = new File(thePdbEntry.getFile()).getAbsoluteFile().getPath(); |
209 |
|
|
210 |
|
} |
211 |
0 |
if (file != null) |
212 |
|
{ |
213 |
0 |
filePDB.add(thePdbEntry); |
214 |
0 |
filePDBpos.add(Integer.valueOf(pi)); |
215 |
|
} |
216 |
|
} |
217 |
|
|
218 |
0 |
if (!filePDB.isEmpty()) |
219 |
|
{ |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
0 |
binding.setFinishedInit(false); |
224 |
0 |
if (!addingStructures) |
225 |
|
{ |
226 |
0 |
try |
227 |
|
{ |
228 |
0 |
initPymol(); |
229 |
|
} catch (Exception ex) |
230 |
|
{ |
231 |
0 |
Console.error("Couldn't open PyMOL viewer!", ex); |
232 |
|
|
233 |
0 |
return; |
234 |
|
} |
235 |
|
} |
236 |
0 |
if (!binding.isViewerRunning()) |
237 |
|
{ |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
0 |
return; |
242 |
|
} |
243 |
|
|
244 |
0 |
int num = -1; |
245 |
0 |
for (PDBEntry pe : filePDB) |
246 |
|
{ |
247 |
0 |
num++; |
248 |
0 |
if (pe.getFile() != null) |
249 |
|
{ |
250 |
0 |
try |
251 |
|
{ |
252 |
0 |
int pos = filePDBpos.get(num).intValue(); |
253 |
0 |
long startTime = startProgressBar(getViewerName() + " " |
254 |
|
+ MessageManager.getString("status.opening_file_for") |
255 |
|
+ " " + pe.getId()); |
256 |
0 |
binding.openFile(pe); |
257 |
0 |
binding.addSequence(pos, binding.getSequence()[pos]); |
258 |
0 |
File fl = new File(pe.getFile()); |
259 |
0 |
DataSourceType protocol = DataSourceType.URL; |
260 |
0 |
try |
261 |
|
{ |
262 |
0 |
if (fl.exists()) |
263 |
|
{ |
264 |
0 |
protocol = DataSourceType.FILE; |
265 |
|
} |
266 |
|
} catch (Throwable e) |
267 |
|
{ |
268 |
|
} finally |
269 |
|
{ |
270 |
0 |
stopProgressBar("", startTime); |
271 |
|
} |
272 |
|
|
273 |
0 |
StructureFile pdb = null; |
274 |
0 |
if (pe.hasStructureFile()) |
275 |
|
{ |
276 |
0 |
pdb = pe.getStructureFile(); |
277 |
0 |
Console.debug("(Re)Using StructureFile " + pdb.getId()); |
278 |
|
} |
279 |
|
else |
280 |
|
{ |
281 |
0 |
pdb = binding.getSsm().setMapping(binding.getSequence()[pos], |
282 |
|
binding.getChains()[pos], pe.getFile(), protocol, |
283 |
|
getProgressIndicator()); |
284 |
|
} |
285 |
0 |
binding.stashFoundChains(pdb, pe.getFile()); |
286 |
|
} catch (Exception ex) |
287 |
|
{ |
288 |
0 |
Console.error("Couldn't open " + pe.getFile() + " in " |
289 |
|
+ getViewerName() + "!", ex); |
290 |
|
} finally |
291 |
|
{ |
292 |
|
|
293 |
|
} |
294 |
|
} |
295 |
|
} |
296 |
|
|
297 |
0 |
binding.refreshGUI(); |
298 |
0 |
binding.setFinishedInit(true); |
299 |
0 |
binding.setLoadingFromArchive(false); |
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
0 |
FeatureRenderer fr = getBinding().getFeatureRenderer(null); |
306 |
0 |
if (fr != null) |
307 |
|
{ |
308 |
0 |
fr.featuresAdded(); |
309 |
|
} |
310 |
|
|
311 |
|
|
312 |
0 |
for (AlignmentViewPanel ap : _colourwith) |
313 |
|
{ |
314 |
0 |
binding.updateColours(ap); |
315 |
|
} |
316 |
|
|
317 |
0 |
if (alignAddedStructures) |
318 |
|
{ |
319 |
0 |
new Thread(new Runnable() |
320 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
321 |
0 |
@Override... |
322 |
|
public void run() |
323 |
|
{ |
324 |
0 |
alignStructsWithAllAlignPanels(); |
325 |
|
} |
326 |
|
}).start(); |
327 |
|
} |
328 |
0 |
addingStructures = false; |
329 |
|
} |
330 |
0 |
_started = false; |
331 |
0 |
worker = null; |
332 |
|
|
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
339 |
0 |
void initPymol()... |
340 |
|
{ |
341 |
0 |
Desktop.addInternalFrame(this, |
342 |
|
binding.getViewerTitle(getViewerName(), true), |
343 |
|
getBounds().width, getBounds().height); |
344 |
|
|
345 |
0 |
if (!binding.launchPymol()) |
346 |
|
{ |
347 |
0 |
JvOptionPane.showMessageDialog(Desktop.desktop, |
348 |
|
MessageManager.formatMessage("label.open_viewer_failed", |
349 |
|
getViewerName()), |
350 |
|
MessageManager.getString("label.error_loading_file"), |
351 |
|
JvOptionPane.ERROR_MESSAGE); |
352 |
0 |
binding.closeViewer(true); |
353 |
0 |
this.dispose(); |
354 |
0 |
return; |
355 |
|
} |
356 |
|
|
357 |
0 |
if (this.pymolSessionFile != null) |
358 |
|
{ |
359 |
0 |
boolean opened = binding.openSession(pymolSessionFile); |
360 |
0 |
if (!opened) |
361 |
|
{ |
362 |
0 |
Console.error("An error occurred opening PyMOL session file " |
363 |
|
+ pymolSessionFile); |
364 |
|
} |
365 |
|
} |
366 |
|
|
367 |
|
} |
368 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
369 |
0 |
@Override... |
370 |
|
public AAStructureBindingModel getBinding() |
371 |
|
{ |
372 |
0 |
return binding; |
373 |
|
} |
374 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
375 |
0 |
@Override... |
376 |
|
public ViewerType getViewerType() |
377 |
|
{ |
378 |
0 |
return ViewerType.PYMOL; |
379 |
|
} |
380 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
381 |
0 |
@Override... |
382 |
|
protected String getViewerName() |
383 |
|
{ |
384 |
0 |
return "PyMOL"; |
385 |
|
} |
386 |
|
|
387 |
|
JMenuItem writeFeatures = null; |
388 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
389 |
0 |
@Override... |
390 |
|
protected void initMenus() |
391 |
|
{ |
392 |
0 |
super.initMenus(); |
393 |
|
|
394 |
0 |
savemenu.setVisible(false); |
395 |
0 |
viewMenu.add(fitToWindow); |
396 |
|
|
397 |
0 |
writeFeatures = new JMenuItem( |
398 |
|
MessageManager.getString("label.create_viewer_attributes")); |
399 |
0 |
writeFeatures.setToolTipText( |
400 |
|
MessageManager.getString("label.create_viewer_attributes_tip")); |
401 |
0 |
writeFeatures.addActionListener(new ActionListener() |
402 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
403 |
0 |
@Override... |
404 |
|
public void actionPerformed(ActionEvent e) |
405 |
|
{ |
406 |
0 |
sendFeaturesToPymol(); |
407 |
|
} |
408 |
|
}); |
409 |
0 |
viewerActionMenu.add(writeFeatures); |
410 |
|
} |
411 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
412 |
0 |
@Override... |
413 |
|
protected void buildActionMenu() |
414 |
|
{ |
415 |
0 |
super.buildActionMenu(); |
416 |
0 |
viewerActionMenu.add(writeFeatures); |
417 |
|
} |
418 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
419 |
0 |
protected void sendFeaturesToPymol()... |
420 |
|
{ |
421 |
0 |
int count = binding.sendFeaturesToViewer(getAlignmentPanel()); |
422 |
0 |
statusBar.setText(MessageManager.formatMessage("label.attributes_set", |
423 |
|
count, getViewerName())); |
424 |
|
} |
425 |
|
|
426 |
|
} |