3 import jalview.api.AlignmentViewPanel;
4 import jalview.api.FeatureRenderer;
5 import jalview.bin.Cache;
6 import jalview.datamodel.PDBEntry;
7 import jalview.datamodel.SequenceI;
8 import jalview.gui.StructureViewer.ViewerType;
9 import jalview.io.DataSourceType;
10 import jalview.io.StructureFile;
11 import jalview.structures.models.AAStructureBindingModel;
12 import jalview.util.MessageManager;
15 import java.util.ArrayList;
16 import java.util.List;
18 import javax.swing.JInternalFrame;
19 import javax.swing.event.InternalFrameAdapter;
20 import javax.swing.event.InternalFrameEvent;
22 public class PymolViewer extends StructureViewerBase
24 private static final int myWidth = 500;
26 private static final int myHeight = 150;
28 private PymolBindingModel binding;
30 private String pymolSessionFile;
37 * closeViewer will decide whether or not to close this frame
38 * depending on whether user chooses to Cancel or not
40 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
43 public PymolViewer(PDBEntry pdb, SequenceI[] seqs, Object object,
47 openNewPymol(ap, new PDBEntry[] { pdb },
52 public PymolViewer(PDBEntry[] pe, boolean alignAdded, SequenceI[][] seqs,
56 setAlignAddedStructures(alignAdded);
57 openNewPymol(ap, pe, seqs);
60 private void openNewPymol(AlignmentPanel ap, PDBEntry[] pe,
64 binding = new PymolBindingModel(this, ap.getStructureSelectionManager(),
66 addAlignmentPanel(ap);
67 useAlignmentPanelForColourbyseq(ap);
71 useAlignmentPanelForSuperposition(ap);
73 binding.setColourBySequence(true);
74 setSize(myWidth, myHeight);
76 viewerActionMenu.setText("PyMOL");
77 updateTitleAndMenus();
79 addingStructures = false;
80 worker = new Thread(this);
83 this.addInternalFrameListener(new InternalFrameAdapter()
86 public void internalFrameClosing(
87 InternalFrameEvent internalFrameEvent)
96 * Create a helper to manage progress bar display
98 protected void createProgressBar()
100 if (getProgressIndicator() == null)
102 setProgressIndicator(new ProgressBar(statusPanel, statusBar));
109 // todo pull up much of this
111 StringBuilder errormsgs = new StringBuilder(128);
112 List<PDBEntry> filePDB = new ArrayList<>();
113 List<Integer> filePDBpos = new ArrayList<>();
114 String[] curfiles = binding.getStructureFiles(); // files currently in viewer
115 for (int pi = 0; pi < binding.getPdbCount(); pi++)
118 PDBEntry thePdbEntry = binding.getPdbEntry(pi);
119 if (thePdbEntry.getFile() == null)
122 * Retrieve PDB data, save to file, attach to PDBEntry
124 file = fetchPdbFile(thePdbEntry);
127 errormsgs.append("'" + thePdbEntry.getId() + "' ");
135 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
137 // todo - skip if already loaded in PyMOL
141 filePDB.add(thePdbEntry);
142 filePDBpos.add(Integer.valueOf(pi));
146 if (!filePDB.isEmpty())
149 * at least one structure to add to viewer
151 binding.setFinishedInit(false);
152 if (!addingStructures)
157 } catch (Exception ex)
159 Cache.log.error("Couldn't open PyMOL viewer!", ex);
163 for (PDBEntry pe : filePDB)
166 if (pe.getFile() != null)
170 int pos = filePDBpos.get(num).intValue();
171 long startTime = startProgressBar(getViewerName() + " "
172 + MessageManager.getString("status.opening_file_for")
174 binding.openFile(pe);
175 binding.addSequence(pos, binding.getSequence()[pos]);
176 File fl = new File(pe.getFile());
177 DataSourceType protocol = DataSourceType.URL;
182 protocol = DataSourceType.FILE;
184 } catch (Throwable e)
188 stopProgressBar("", startTime);
191 StructureFile pdb = binding.getSsm().setMapping(
192 binding.getSequence()[pos], binding.getChains()[pos],
193 pe.getFile(), protocol,
194 getProgressIndicator());
195 binding.stashFoundChains(pdb, pe.getFile());
196 } catch (Exception ex)
199 "Couldn't open " + pe.getFile() + " in Chimera viewer!",
203 // Cache.log.debug("File locations are " + files);
208 binding.refreshGUI();
209 binding.setFinishedInit(true);
210 binding.setLoadingFromArchive(false);
213 * ensure that any newly discovered features (e.g. RESNUM)
214 * are added to any open feature settings dialog
216 FeatureRenderer fr = getBinding().getFeatureRenderer(null);
222 // refresh the sequence colours for the new structure(s)
223 for (AlignmentViewPanel ap : _colourwith)
225 binding.updateColours(ap);
227 // do superposition if asked to
228 if (alignAddedStructures)
230 new Thread(new Runnable()
235 alignStructsWithAllAlignPanels();
239 addingStructures = false;
247 * Launch PyMOL. If we have a session file name, send PyMOL the command to
248 * open its saved session file.
252 Desktop.addInternalFrame(this,
253 binding.getViewerTitle(getViewerName(), true),
254 getBounds().width, getBounds().height);
256 if (!binding.launchPymol())
258 JvOptionPane.showMessageDialog(Desktop.desktop,
259 MessageManager.getString("label.pymol_failed"),
260 MessageManager.getString("label.error_loading_file"),
261 JvOptionPane.ERROR_MESSAGE);
266 if (this.pymolSessionFile != null)
268 boolean opened = binding.openSession(pymolSessionFile);
271 System.err.println("An error occurred opening PyMOL session file "
275 // binding.startPymolListener();
279 public AAStructureBindingModel getBinding()
285 public void closeViewer(boolean closePymol)
287 if (binding != null && binding.isPymolRunning())
291 // TODO i18n (and pull up)
292 String prompt = MessageManager
293 .formatMessage("label.confirm_close_pymol", new Object[]
294 { binding.getViewerTitle(getViewerName(), false) });
295 prompt = JvSwingUtils.wrapTooltip(true, prompt);
296 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
297 MessageManager.getString("label.close_viewer"),
298 JvOptionPane.YES_NO_CANCEL_OPTION);
300 * abort closure if user hits escape or Cancel
302 if (confirm == JvOptionPane.CANCEL_OPTION
303 || confirm == JvOptionPane.CLOSED_OPTION)
307 closePymol = confirm == JvOptionPane.YES_OPTION;
309 binding.closeViewer(closePymol);
311 setAlignmentPanel(null);
315 // TODO: check for memory leaks where instance isn't finalised because
317 // holds a reference to the window
323 public String getStateInfo()
329 public ViewerType getViewerType()
331 return ViewerType.PYMOL;
335 protected String getViewerName()