X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FChimeraViewFrame.java;h=a92fe77758ae3c42c7b8d7c6c5f72aeb02ddc495;hb=2ab7b9b152018bb808693218ad88dc3778166492;hp=9b0d85be02c6756f1b53888aa04531b4b6cb17c0;hpb=4762b29420ed4df01b55a8afe5ab05467aaf41a9;p=jalview.git diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index 9b0d85b..a92fe77 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -20,11 +20,12 @@ */ package jalview.gui; +import jalview.api.AlignmentViewPanel; +import jalview.api.FeatureRenderer; import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; -import jalview.ext.rbvi.chimera.ChimeraCommands; import jalview.ext.rbvi.chimera.JalviewChimeraBinding; import jalview.gui.StructureViewer.ViewerType; import jalview.io.DataSourceType; @@ -46,9 +47,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Random; -import javax.swing.JCheckBoxMenuItem; import javax.swing.JInternalFrame; import javax.swing.JMenu; import javax.swing.JMenuItem; @@ -65,8 +64,6 @@ public class ChimeraViewFrame extends StructureViewerBase { private JalviewChimeraBinding jmb; - private IProgressIndicator progressBar = null; - /* * Path to Chimera session file. This is set when an open Jalview/Chimera * session is saved, or on restore from a Jalview project (if it holds the @@ -74,7 +71,9 @@ public class ChimeraViewFrame extends StructureViewerBase */ private String chimeraSessionFile = null; - private Random random = new Random(); + private int myWidth = 500; + + private int myHeight = 150; /** * Initialise menu options. @@ -86,8 +85,8 @@ public class ChimeraViewFrame extends StructureViewerBase viewerActionMenu.setText(MessageManager.getString("label.chimera")); - viewerColour.setText(MessageManager - .getString("label.colour_with_chimera")); + viewerColour + .setText(MessageManager.getString("label.colour_with_chimera")); viewerColour.setToolTipText(MessageManager .getString("label.let_chimera_manage_structure_colours")); @@ -111,8 +110,8 @@ public class ChimeraViewFrame extends StructureViewerBase final JMenu fetchAttributes = new JMenu( MessageManager.getString("label.fetch_chimera_attributes")); - fetchAttributes.setToolTipText(MessageManager - .getString("label.fetch_chimera_attributes_tip")); + fetchAttributes.setToolTipText( + MessageManager.getString("label.fetch_chimera_attributes_tip")); fetchAttributes.addMouseListener(new MouseAdapter() { @@ -123,7 +122,6 @@ public class ChimeraViewFrame extends StructureViewerBase } }); viewerActionMenu.add(fetchAttributes); - } /** @@ -134,34 +132,21 @@ public class ChimeraViewFrame extends StructureViewerBase */ protected void buildAttributesMenu(JMenu attributesMenu) { - List atts = jmb.sendChimeraCommand("list resattr", true); - if (atts == null) - { - return; - } + List atts = jmb.getChimeraAttributes(); attributesMenu.removeAll(); Collections.sort(atts); - for (String att : atts) + for (String attName : atts) { - final String attName = att.split(" ")[1]; - - /* - * ignore 'jv_*' attributes, as these are Jalview features that have - * been transferred to residue attributes in Chimera! - */ - if (!attName.startsWith(ChimeraCommands.NAMESPACE_PREFIX)) + JMenuItem menuItem = new JMenuItem(attName); + menuItem.addActionListener(new ActionListener() { - JMenuItem menuItem = new JMenuItem(attName); - menuItem.addActionListener(new ActionListener() + @Override + public void actionPerformed(ActionEvent e) { - @Override - public void actionPerformed(ActionEvent e) - { - getChimeraAttributes(attName); - } - }); - attributesMenu.add(menuItem); - } + getChimeraAttributes(attName); + } + }); + attributesMenu.add(menuItem); } } @@ -185,11 +170,13 @@ public class ChimeraViewFrame extends StructureViewerBase */ protected void sendFeaturesToChimera() { - jmb.sendFeaturesToViewer(getAlignmentPanel()); + int count = jmb.sendFeaturesToViewer(getAlignmentPanel()); + statusBar.setText( + MessageManager.formatMessage("label.attributes_set", count)); } /** - * add a single PDB structure to a new or existing Chimera view + * open a single PDB structure in a new Chimera view * * @param pdbentry * @param seq @@ -200,32 +187,10 @@ public class ChimeraViewFrame extends StructureViewerBase String[] chains, final AlignmentPanel ap) { this(); - String pdbId = pdbentry.getId(); - - /* - * If the PDB file is already loaded, the user may just choose to add to an - * existing viewer (or cancel) - */ - if (addAlreadyLoadedFile(seq, chains, ap, pdbId)) - { - return; - } - - /* - * Check if there are other Chimera views involving this alignment and give - * user the option to add and align this molecule to one of them (or cancel) - */ - if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId)) - { - return; - } - /* - * If the options above are declined or do not apply, show the structure in - * a new viewer - */ openNewChimera(ap, new PDBEntry[] { pdbentry }, - new SequenceI[][] { seq }); + new SequenceI[][] + { seq }); } /** @@ -233,9 +198,9 @@ public class ChimeraViewFrame extends StructureViewerBase */ protected void createProgressBar() { - if (progressBar == null) + if (getProgressIndicator() == null) { - progressBar = new ProgressBar(statusPanel, statusBar); + setProgressIndicator(new ProgressBar(statusPanel, statusBar)); } } @@ -250,11 +215,10 @@ public class ChimeraViewFrame extends StructureViewerBase if (pdbentrys.length > 1) { - alignAddedStructures = true; useAlignmentPanelForSuperposition(ap); } jmb.setColourBySequence(true); - setSize(400, 400); // probably should be a configurable/dynamic default here + setSize(myWidth, myHeight); initMenus(); addingStructures = false; @@ -264,7 +228,8 @@ public class ChimeraViewFrame extends StructureViewerBase this.addInternalFrameListener(new InternalFrameAdapter() { @Override - public void internalFrameClosing(InternalFrameEvent internalFrameEvent) + public void internalFrameClosing( + InternalFrameEvent internalFrameEvent) { closeViewer(false); } @@ -308,17 +273,19 @@ public class ChimeraViewFrame extends StructureViewerBase } /** - * create a new viewer containing several structures superimposed using the - * given alignPanel. + * create a new viewer containing several structures, optionally superimposed + * using the given alignPanel. * * @param pe * @param seqs * @param ap */ - public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs, + public ChimeraViewFrame(PDBEntry[] pe, boolean alignAdded, + SequenceI[][] seqs, AlignmentPanel ap) { this(); + setAlignAddedStructures(alignAdded); openNewChimera(ap, pe, seqs); } @@ -337,29 +304,6 @@ public class ChimeraViewFrame extends StructureViewerBase } /** - * Returns a list of any Chimera viewers in the desktop. The list is - * restricted to those linked to the given alignment panel if it is not null. - */ - @Override - protected List getViewersFor(AlignmentPanel ap) - { - List result = new ArrayList(); - JInternalFrame[] frames = Desktop.instance.getAllFrames(); - - for (JInternalFrame frame : frames) - { - if (frame instanceof ChimeraViewFrame) - { - if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap)) - { - result.add((StructureViewerBase) frame); - } - } - } - return result; - } - - /** * Launch Chimera. If we have a chimera session file name, send Chimera the * command to open its saved session file. */ @@ -385,9 +329,8 @@ public class ChimeraViewFrame extends StructureViewerBase boolean opened = jmb.openSession(chimeraSessionFile); if (!opened) { - System.err - .println("An error occurred opening Chimera session file " - + chimeraSessionFile); + System.err.println("An error occurred opening Chimera session file " + + chimeraSessionFile); } } @@ -395,27 +338,6 @@ public class ChimeraViewFrame extends StructureViewerBase } /** - * Show only the selected chain(s) in the viewer - */ - @Override - void showSelectedChains() - { - List toshow = new ArrayList(); - for (int i = 0; i < chainMenu.getItemCount(); i++) - { - if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem) - { - JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i); - if (item.isSelected()) - { - toshow.add(item.getText()); - } - } - } - jmb.showChains(toshow); - } - - /** * Close down this instance of Jalview's Chimera viewer, giving the user the * option to close the associated Chimera window (process). They may wish to * keep it open until they have had an opportunity to save any work. @@ -430,10 +352,9 @@ public class ChimeraViewFrame extends StructureViewerBase { if (!closeChimera) { - String prompt = MessageManager.formatMessage( - "label.confirm_close_chimera", - new Object[] { jmb.getViewerTitle(getViewerName(), - false) }); + String prompt = MessageManager + .formatMessage("label.confirm_close_chimera", new Object[] + { jmb.getViewerTitle(getViewerName(), false) }); prompt = JvSwingUtils.wrapTooltip(true, prompt); int confirm = JvOptionPane.showConfirmDialog(this, prompt, MessageManager.getString("label.close_viewer"), @@ -471,13 +392,13 @@ public class ChimeraViewFrame extends StructureViewerBase // todo - record which pdbids were successfully imported. StringBuilder errormsgs = new StringBuilder(128); StringBuilder files = new StringBuilder(128); - List filePDB = new ArrayList(); - List filePDBpos = new ArrayList(); + List filePDB = new ArrayList<>(); + List filePDBpos = new ArrayList<>(); PDBEntry thePdbEntry = null; StructureFile pdb = null; try { - String[] curfiles = jmb.getPdbFile(); // files currently in viewer + String[] curfiles = jmb.getStructureFiles(); // files currently in viewer // TODO: replace with reference fetching/transfer code (validate PDBentry // as a DBRef?) for (int pi = 0; pi < jmb.getPdbCount(); pi++) @@ -519,7 +440,7 @@ public class ChimeraViewFrame extends StructureViewerBase { filePDB.add(thePdbEntry); filePDBpos.add(Integer.valueOf(pi)); - files.append(" \"" + Platform.escapeString(file) + "\""); + files.append(" \"" + Platform.escapeBackslashes(file) + "\""); } } } catch (OutOfMemoryError oomerror) @@ -529,15 +450,16 @@ public class ChimeraViewFrame extends StructureViewerBase } catch (Exception ex) { ex.printStackTrace(); - errormsgs.append("When retrieving pdbfiles for '" - + thePdbEntry.getId() + "'"); + errormsgs.append( + "When retrieving pdbfiles for '" + thePdbEntry.getId() + "'"); } if (errormsgs.length() > 0) { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager - .formatMessage("label.pdb_entries_couldnt_be_retrieved", - new Object[] { errormsgs.toString() }), + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.formatMessage( + "label.pdb_entries_couldnt_be_retrieved", new Object[] + { errormsgs.toString() }), MessageManager.getString("label.couldnt_load_file"), JvOptionPane.ERROR_MESSAGE); } @@ -584,9 +506,12 @@ public class ChimeraViewFrame extends StructureViewerBase stopProgressBar("", startTime); } // Explicitly map to the filename used by Chimera ; + pdb = jmb.getSsm().setMapping(jmb.getSequence()[pos], - jmb.getChains()[pos], pe.getFile(), protocol); + jmb.getChains()[pos], pe.getFile(), protocol, + getProgressIndicator()); stashFoundChains(pdb, pe.getFile()); + } catch (OutOfMemoryError oomerror) { new OOMWarning( @@ -594,8 +519,9 @@ public class ChimeraViewFrame extends StructureViewerBase oomerror); } catch (Exception ex) { - Cache.log.error("Couldn't open " + pe.getFile() - + " in Chimera viewer!", ex); + Cache.log.error( + "Couldn't open " + pe.getFile() + " in Chimera viewer!", + ex); } finally { Cache.log.debug("File locations are " + files); @@ -607,13 +533,23 @@ public class ChimeraViewFrame extends StructureViewerBase jmb.setFinishedInit(true); jmb.setLoadingFromArchive(false); + /* + * ensure that any newly discovered features (e.g. RESNUM) + * are added to any open feature settings dialog + */ + FeatureRenderer fr = getBinding().getFeatureRenderer(null); + if (fr != null) + { + fr.featuresAdded(); + } + // refresh the sequence colours for the new structure(s) - for (AlignmentPanel ap : _colourwith) + for (AlignmentViewPanel ap : _colourwith) { jmb.updateColours(ap); } // do superposition if asked to - if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures) + if (alignAddedStructures) { new Thread(new Runnable() { @@ -623,7 +559,6 @@ public class ChimeraViewFrame extends StructureViewerBase alignStructs_withAllAlignPanels(); } }).start(); - alignAddedStructures = false; } addingStructures = false; } @@ -633,7 +568,7 @@ public class ChimeraViewFrame extends StructureViewerBase /** * Fetch PDB data and save to a local file. Returns the full path to the file, - * or null if fetch fails. + * or null if fetch fails. TODO: refactor to common with Jmol ? duplication * * @param processingEntry * @return @@ -644,15 +579,15 @@ public class ChimeraViewFrame extends StructureViewerBase { for (int i = 0; i < pdb.getChains().size(); i++) { - String chid = new String(pdb.getId() + ":" - + pdb.getChains().elementAt(i).id); + String chid = new String( + pdb.getId() + ":" + pdb.getChains().elementAt(i).id); jmb.getChainNames().add(chid); - jmb.getChainFile().put(chid, file); + jmb.addChainFile(chid, file); } } + private String fetchPdbFile(PDBEntry processingEntry) throws Exception { - // FIXME: this is duplicated code with Jmol frame ? String filePath = null; Pdb pdbclient = new Pdb(); AlignmentI pdbseq = null; @@ -664,7 +599,8 @@ public class ChimeraViewFrame extends StructureViewerBase * Write 'fetching PDB' progress on AlignFrame as we are not yet visible */ String msg = MessageManager.formatMessage("status.fetching_pdb", - new Object[] { pdbid }); + new Object[] + { pdbid }); getAlignmentPanel().alignFrame.setProgressBar(msg, handle); // long hdl = startProgressBar(MessageManager.formatMessage( // "status.fetching_pdb", new Object[] @@ -695,54 +631,18 @@ public class ChimeraViewFrame extends StructureViewerBase return filePath; } - /** - * Convenience method to update the progress bar if there is one. Be sure to - * call stopProgressBar with the returned handle to remove the message. - * - * @param msg - * @param handle - */ - public long startProgressBar(String msg) - { - // TODO would rather have startProgress/stopProgress as the - // IProgressIndicator interface - long tm = random.nextLong(); - if (progressBar != null) - { - progressBar.setProgressBar(msg, tm); - } - return tm; - } - - /** - * End the progress bar with the specified handle, leaving a message (if not - * null) on the status bar - * - * @param msg - * @param handle - */ - public void stopProgressBar(String msg, long handle) - { - if (progressBar != null) - { - progressBar.setProgressBar(msg, handle); - } - } - @Override public void eps_actionPerformed(ActionEvent e) { - throw new Error( - MessageManager - .getString("error.eps_generation_not_implemented")); + throw new Error(MessageManager + .getString("error.eps_generation_not_implemented")); } @Override public void png_actionPerformed(ActionEvent e) { - throw new Error( - MessageManager - .getString("error.png_generation_not_implemented")); + throw new Error(MessageManager + .getString("error.png_generation_not_implemented")); } @Override @@ -750,10 +650,14 @@ public class ChimeraViewFrame extends StructureViewerBase { try { - BrowserLauncher - .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide"); + String url = jmb.isChimeraX() + ? "http://www.rbvi.ucsf.edu/chimerax/docs/user/index.html" + : "https://www.cgl.ucsf.edu/chimera/docs/UsersGuide"; + BrowserLauncher.openURL(url); } catch (IOException ex) { + System.err + .println("Show Chimera help failed with: " + ex.getMessage()); } } @@ -778,7 +682,8 @@ public class ChimeraViewFrame extends StructureViewerBase { if (pathUsed == null) { - File tempFile = File.createTempFile("chimera", ".py"); + String suffix = jmb.isChimeraX() ? ".cxs" : ".py"; + File tempFile = File.createTempFile("chimera", suffix); tempFile.deleteOnExit(); pathUsed = tempFile.getPath(); } @@ -851,10 +756,19 @@ public class ChimeraViewFrame extends StructureViewerBase return "Chimera"; } + /** + * Sends commands to align structures according to associated alignment(s). + * + * @return + */ @Override - public void updateTitleAndMenus() + protected String alignStructs_withAllAlignPanels() { - super.updateTitleAndMenus(); - viewerActionMenu.setVisible(true); + String reply = super.alignStructs_withAllAlignPanels(); + if (reply != null) + { + statusBar.setText("Superposition failed: " + reply); + } + return reply; } }