X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FChimeraViewFrame.java;fp=src%2Fjalview%2Fgui%2FChimeraViewFrame.java;h=ec9feb7786407694f87b0fc2384f0088767f0e3c;hb=d5bcc3830eab04e6db816e1c2ad8fce1dc189612;hp=530f4fe5342f250f963236bde3c07804a0ba5359;hpb=3ebdd4e28382e38a181aae1eed71549f603f9025;p=jalview.git diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index 530f4fe..ec9feb7 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -20,10 +20,12 @@ */ package jalview.gui; +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; @@ -35,16 +37,22 @@ import jalview.util.Platform; import jalview.ws.dbsources.Pdb; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.io.File; import java.io.FileInputStream; import java.io.IOException; 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; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; @@ -58,8 +66,6 @@ public class ChimeraViewFrame extends StructureViewerBase { private JalviewChimeraBinding jmb; - private boolean allChainsSelected = false; - private IProgressIndicator progressBar = null; /* @@ -71,6 +77,10 @@ public class ChimeraViewFrame extends StructureViewerBase private Random random = new Random(); + private int myWidth = 500; + + private int myHeight = 150; + /** * Initialise menu options. */ @@ -89,6 +99,100 @@ public class ChimeraViewFrame extends StructureViewerBase helpItem.setText(MessageManager.getString("label.chimera_help")); savemenu.setVisible(false); // not yet implemented viewMenu.add(fitToWindow); + + 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( + MessageManager.getString("label.fetch_chimera_attributes")); + fetchAttributes.setToolTipText(MessageManager + .getString("label.fetch_chimera_attributes_tip")); + 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() + { + int count = jmb.sendFeaturesToViewer(getAlignmentPanel()); + statusBar.setText(MessageManager.formatMessage("label.attributes_set", + count)); } /** @@ -146,7 +250,6 @@ public class ChimeraViewFrame extends StructureViewerBase SequenceI[][] seqs) { createProgressBar(); - // FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs jmb = new JalviewChimeraBindingModel(this, ap.getStructureSelectionManager(), pdbentrys, seqs, null); addAlignmentPanel(ap); @@ -158,7 +261,7 @@ public class ChimeraViewFrame extends StructureViewerBase useAlignmentPanelForSuperposition(ap); } jmb.setColourBySequence(true); - setSize(400, 400); // probably should be a configurable/dynamic default here + setSize(myWidth, myHeight); initMenus(); addingStructures = false; @@ -270,7 +373,7 @@ public class ChimeraViewFrame extends StructureViewerBase void initChimera() { jmb.setFinishedInit(false); - jalview.gui.Desktop.addInternalFrame(this, + Desktop.addInternalFrame(this, jmb.getViewerTitle(getViewerName(), true), getBounds().width, getBounds().height); @@ -294,12 +397,10 @@ public class ChimeraViewFrame extends StructureViewerBase + chimeraSessionFile); } } - jmb.setFinishedInit(true); jmb.startChimeraListener(); } - /** * Show only the selected chain(s) in the viewer */ @@ -450,6 +551,7 @@ public class ChimeraViewFrame extends StructureViewerBase if (files.length() > 0) { + jmb.setFinishedInit(false); if (!addingStructures) { try @@ -507,10 +609,21 @@ public class ChimeraViewFrame extends StructureViewerBase } } } + jmb.refreshGUI(); 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) { @@ -656,7 +769,7 @@ public class ChimeraViewFrame extends StructureViewerBase { BrowserLauncher .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide"); - } catch (Exception ex) + } catch (IOException ex) { } } @@ -754,4 +867,20 @@ public class ChimeraViewFrame extends StructureViewerBase { return "Chimera"; } + + /** + * Sends commands to align structures according to associated alignment(s). + * + * @return + */ + @Override + protected String alignStructs_withAllAlignPanels() + { + String reply = super.alignStructs_withAllAlignPanels(); + if (reply != null) + { + statusBar.setText("Superposition failed: " + reply); + } + return reply; + } }