X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FChimeraViewFrame.java;h=bc247cad7c77ad662110e7b258e2ba75ae0d6f4c;hb=fd9e6f7e0424bb69e46443d7d96237d99e792c03;hp=ce719d0d0fceba41cd7e4bb69f58eccff84015b1;hpb=89da71c0b164a26d5613167ec467db95701b4638;p=jalview.git diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index ce719d0..bc247ca 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -26,11 +26,13 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; 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.AppletFormatAdapter; +import jalview.io.DataSourceType; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; +import jalview.io.StructureFile; import jalview.schemes.BuriedColourScheme; import jalview.schemes.ColourSchemeI; import jalview.schemes.HelixColourScheme; @@ -49,6 +51,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -58,6 +62,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Random; import java.util.Vector; @@ -67,7 +72,6 @@ import javax.swing.JColorChooser; import javax.swing.JInternalFrame; import javax.swing.JMenu; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; import javax.swing.event.MenuEvent; @@ -181,6 +185,97 @@ public class ChimeraViewFrame extends StructureViewerBase // TODO Auto-generated method stub } }); + + JMenuItem writeFeatures = new JMenuItem( + MessageManager.getString("label.create_chimera_attributes")); + writeFeatures.setToolTipText(MessageManager + .getString("label.create_chimera_attributes_tip")); + writeFeatures.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + sendFeaturesToChimera(); + } + }); + viewerActionMenu.add(writeFeatures); + + final JMenu fetchAttributes = new JMenu("Fetch Chimera attributes"); + fetchAttributes + .setToolTipText("Copy Chimera attribute to Jalview feature"); + fetchAttributes.addMouseListener(new MouseAdapter() + { + + @Override + public void mouseEntered(MouseEvent e) + { + buildAttributesMenu(fetchAttributes); + } + }); + viewerActionMenu.add(fetchAttributes); + + } + + /** + * Query Chimera for its residue attribute names and add them as items off the + * attributes menu + * + * @param attributesMenu + */ + protected void buildAttributesMenu(JMenu attributesMenu) + { + List atts = jmb.sendChimeraCommand("list resattr", true); + if (atts == null) + { + return; + } + attributesMenu.removeAll(); + Collections.sort(atts); + for (String att : 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() + { + @Override + public void actionPerformed(ActionEvent e) + { + getChimeraAttributes(attName); + } + }); + attributesMenu.add(menuItem); + } + } + } + + /** + * Read residues in Chimera with the given attribute name, and set as features + * on the corresponding sequence positions (if any) + * + * @param attName + */ + protected void getChimeraAttributes(String attName) + { + jmb.copyStructureAttributesToFeatures(attName, getAlignmentPanel()); + } + + /** + * Send a command to Chimera to create residue attributes for Jalview features + *

+ * The syntax is: setattr r + *

+ * For example: setattr r jv:chain "Ferredoxin-1, Chloroplastic" #0:94.A + */ + protected void sendFeaturesToChimera() + { + jmb.sendFeaturesToViewer(getAlignmentPanel()); } /** @@ -247,11 +342,8 @@ public class ChimeraViewFrame extends StructureViewerBase SequenceI[][] seqs) { createProgressBar(); - // FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs - String[][] chains = extractChains(seqs); jmb = new JalviewChimeraBindingModel(this, - ap.getStructureSelectionManager(), pdbentrys, seqs, chains, - null); + ap.getStructureSelectionManager(), pdbentrys, seqs, null); addAlignmentPanel(ap); useAlignmentPanelForColourbyseq(ap); if (pdbentrys.length > 1) @@ -279,42 +371,6 @@ public class ChimeraViewFrame extends StructureViewerBase } /** - * Retrieve chains for sequences by inspecting their PDB refs. The hope is - * that the first will be to the sequence's own chain. Really need a more - * managed way of doing this. - * - * @param seqs - * @return - */ - protected String[][] extractChains(SequenceI[][] seqs) - { - String[][] chains = new String[seqs.length][]; - for (int i = 0; i < seqs.length; i++) - { - chains[i] = new String[seqs[i].length]; - int seqno = 0; - for (SequenceI seq : seqs[i]) - { - String chain = null; - if (seq.getDatasetSequence() != null) - { - Vector pdbrefs = seq.getDatasetSequence() - .getAllPDBEntries(); - if (pdbrefs != null && pdbrefs.size() > 0) - { - // FIXME: SequenceI.PDBEntry[0] chain mapping used for - // ChimeraViewFrame. Is this even used ??? - - chain = pdbrefs.get(0).getChainCode(); - } - } - chains[i][seqno++] = chain; - } - } - return chains; - } - - /** * Create a new viewer from saved session state data including Chimera session * file * @@ -378,28 +434,6 @@ public class ChimeraViewFrame extends StructureViewerBase setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); } - /** - * 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 @@ -407,17 +441,15 @@ public class ChimeraViewFrame extends StructureViewerBase */ void initChimera() { - jmb.setFinishedInit(false); - jalview.gui.Desktop.addInternalFrame(this, - jmb.getViewerTitle("Chimera", true), getBounds().width, - getBounds().height); + Desktop.addInternalFrame(this, jmb.getViewerTitle("Chimera", true), + getBounds().width, getBounds().height); if (!jmb.launchChimera()) { - JOptionPane.showMessageDialog(Desktop.desktop, + JvOptionPane.showMessageDialog(Desktop.desktop, MessageManager.getString("label.chimera_failed"), MessageManager.getString("label.error_loading_file"), - JOptionPane.ERROR_MESSAGE); + JvOptionPane.ERROR_MESSAGE); this.dispose(); return; } @@ -432,7 +464,6 @@ public class ChimeraViewFrame extends StructureViewerBase + chimeraSessionFile); } } - jmb.setFinishedInit(true); jmb.startChimeraListener(); } @@ -443,6 +474,7 @@ public class ChimeraViewFrame extends StructureViewerBase * * @param chainNames */ + @Override void setChainMenuItems(List chainNames) { chainMenu.removeAll(); @@ -494,6 +526,7 @@ public class ChimeraViewFrame extends StructureViewerBase /** * Show only the selected chain(s) in the viewer */ + @Override void showSelectedChains() { List toshow = new ArrayList(); @@ -516,35 +549,47 @@ public class ChimeraViewFrame extends StructureViewerBase * 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. * - * @param closeChimera + * @param forceCloseChimera * if true, close any linked Chimera process; if false, prompt first */ @Override - public void closeViewer(boolean closeChimera) + public void closeViewer(boolean forceCloseChimera) { - if (jmb != null && jmb.isChimeraRunning()) + if (jmb != null) { - if (!closeChimera) + if (jmb.isChimeraRunning()) { - String prompt = MessageManager.formatMessage( - "label.confirm_close_chimera", - new Object[] { jmb.getViewerTitle("Chimera", false) }); - prompt = JvSwingUtils.wrapTooltip(true, prompt); - int confirm = JOptionPane.showConfirmDialog(this, prompt, - MessageManager.getString("label.close_viewer"), - JOptionPane.YES_NO_CANCEL_OPTION); /* - * abort closure if user hits escape or Cancel + * force close, or prompt to close, Chimera */ - if (confirm == JOptionPane.CANCEL_OPTION - || confirm == JOptionPane.CLOSED_OPTION) + if (!forceCloseChimera) { - return; + String prompt = MessageManager.formatMessage( + "label.confirm_close_chimera", + new Object[] { jmb.getViewerTitle("Chimera", false) }); + prompt = JvSwingUtils.wrapTooltip(true, prompt); + int confirm = JvOptionPane.showConfirmDialog(this, prompt, + MessageManager.getString("label.close_viewer"), + JvOptionPane.YES_NO_CANCEL_OPTION); + /* + * abort closure if user hits escape or Cancel + */ + if (confirm == JvOptionPane.CANCEL_OPTION + || confirm == JvOptionPane.CLOSED_OPTION) + { + return; + } + forceCloseChimera = confirm == JvOptionPane.YES_OPTION; } - closeChimera = confirm == JOptionPane.YES_OPTION; } - jmb.closeViewer(closeChimera); + + /* + * close the viewer plus any side-effects e.g. remove mappings + * note we do this also if closing Chimera triggered this method + */ + jmb.closeViewer(forceCloseChimera); } + setAlignmentPanel(null); _aps.clear(); _alignwith.clear(); @@ -569,6 +614,7 @@ public class ChimeraViewFrame extends StructureViewerBase List filePDB = new ArrayList(); List filePDBpos = new ArrayList(); PDBEntry thePdbEntry = null; + StructureFile pdb = null; try { String[] curfiles = jmb.getPdbFile(); // files currently in viewer @@ -629,15 +675,16 @@ public class ChimeraViewFrame extends StructureViewerBase if (errormsgs.length() > 0) { - JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager + JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager .formatMessage("label.pdb_entries_couldnt_be_retrieved", new Object[] { errormsgs.toString() }), MessageManager.getString("label.couldnt_load_file"), - JOptionPane.ERROR_MESSAGE); + JvOptionPane.ERROR_MESSAGE); } if (files.length() > 0) { + jmb.setFinishedInit(false); if (!addingStructures) { try @@ -663,12 +710,12 @@ public class ChimeraViewFrame extends StructureViewerBase jmb.openFile(pe); jmb.addSequence(pos, jmb.getSequence()[pos]); File fl = new File(pe.getFile()); - String protocol = AppletFormatAdapter.URL; + DataSourceType protocol = DataSourceType.URL; try { if (fl.exists()) { - protocol = AppletFormatAdapter.FILE; + protocol = DataSourceType.FILE; } } catch (Throwable e) { @@ -677,8 +724,9 @@ public class ChimeraViewFrame extends StructureViewerBase stopProgressBar("", startTime); } // Explicitly map to the filename used by Chimera ; - jmb.getSsm().setMapping(jmb.getSequence()[pos], + pdb = jmb.getSsm().setMapping(jmb.getSequence()[pos], jmb.getChains()[pos], pe.getFile(), protocol); + stashFoundChains(pdb, pe.getFile()); } catch (OutOfMemoryError oomerror) { new OOMWarning( @@ -694,6 +742,8 @@ public class ChimeraViewFrame extends StructureViewerBase } } } + + jmb.refreshGUI(); jmb.setFinishedInit(true); jmb.setLoadingFromArchive(false); @@ -729,6 +779,17 @@ public class ChimeraViewFrame extends StructureViewerBase * @return * @throws Exception */ + + private void stashFoundChains(StructureFile pdb, String file) + { + for (int i = 0; i < pdb.getChains().size(); i++) + { + String chid = new String(pdb.getId() + ":" + + pdb.getChains().elementAt(i).id); + jmb.getChainNames().add(chid); + jmb.getChainFile().put(chid, file); + } + } private String fetchPdbFile(PDBEntry processingEntry) throws Exception { // FIXME: this is duplicated code with Jmol frame ? @@ -1040,10 +1101,10 @@ public class ChimeraViewFrame extends StructureViewerBase setChainMenuItems(jmb.getChainNames()); this.setTitle(jmb.getViewerTitle("Chimera", true)); - if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1) - { + // if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1) + // { viewerActionMenu.setVisible(true); - } + // } if (!jmb.isLoadingFromArchive()) { seqColour_actionPerformed(null);