*/
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;
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;
{
private JalviewChimeraBinding jmb;
- private boolean allChainsSelected = false;
-
private IProgressIndicator progressBar = null;
/*
private Random random = new Random();
+ private int myWidth = 500;
+
+ private int myHeight = 150;
+
/**
* Initialise menu options.
*/
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"));
helpItem.setText(MessageManager.getString("label.chimera_help"));
savemenu.setVisible(false); // not yet implemented
viewMenu.add(fitToWindow);
+
+ /*
+ * exchange of Jalview features and Chimera attributes is for now
+ * an optionally enabled experimental feature
+ */
+ if (Desktop.instance.showExperimental())
+ {
+ 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<String> 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
+ * <p>
+ * The syntax is: setattr r <attName> <attValue> <atomSpec>
+ * <p>
+ * 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));
}
/**
* a new viewer
*/
openNewChimera(ap, new PDBEntry[] { pdbentry },
- new SequenceI[][] { seq });
+ new SequenceI[][]
+ { seq });
}
/**
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);
useAlignmentPanelForSuperposition(ap);
}
jmb.setColourBySequence(true);
- setSize(400, 400); // probably should be a configurable/dynamic default here
+ setSize(myWidth, myHeight);
initMenus();
addingStructures = false;
this.addInternalFrameListener(new InternalFrameAdapter()
{
@Override
- public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
+ public void internalFrameClosing(
+ InternalFrameEvent internalFrameEvent)
{
closeViewer(false);
}
@Override
protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
{
- List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
+ List<StructureViewerBase> result = new ArrayList<>();
JInternalFrame[] frames = Desktop.instance.getAllFrames();
for (JInternalFrame frame : frames)
void initChimera()
{
jmb.setFinishedInit(false);
- jalview.gui.Desktop.addInternalFrame(this,
+ Desktop.addInternalFrame(this,
jmb.getViewerTitle(getViewerName(), true), getBounds().width,
getBounds().height);
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);
}
}
- jmb.setFinishedInit(true);
jmb.startChimeraListener();
}
-
/**
* Show only the selected chain(s) in the viewer
*/
@Override
void showSelectedChains()
{
- List<String> toshow = new ArrayList<String>();
+ List<String> toshow = new ArrayList<>();
for (int i = 0; i < chainMenu.getItemCount(); i++)
{
if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
{
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"),
// todo - record which pdbids were successfully imported.
StringBuilder errormsgs = new StringBuilder(128);
StringBuilder files = new StringBuilder(128);
- List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
- List<Integer> filePDBpos = new ArrayList<Integer>();
+ List<PDBEntry> filePDB = new ArrayList<>();
+ List<Integer> 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++)
} 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);
}
if (files.length() > 0)
{
+ jmb.setFinishedInit(false);
if (!addingStructures)
{
try
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,
+ progressBar);
stashFoundChains(pdb, pe.getFile());
+
} catch (OutOfMemoryError oomerror)
{
new OOMWarning(
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);
}
}
}
+
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)
{
/**
* 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
{
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);
}
}
+
private String fetchPdbFile(PDBEntry processingEntry) throws Exception
{
// FIXME: this is duplicated code with Jmol frame ?
* 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[]
@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
{
BrowserLauncher
.openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
- } catch (Exception ex)
+ } catch (IOException ex)
{
}
}
{
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;
+ }
+
+ @Override
+ protected IProgressIndicator getIProgressIndicator()
+ {
+ return progressBar;
+ }
}