X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPymolViewer.java;h=9dc28c869f41e0006180418f0f677c8eecc926bb;hb=fa9da54fb97cb2eacb1af7859024d90166bddb8f;hp=09451be4ba6dc92fcfc5c0cda4f5e55bf9b1f7e1;hpb=42f4227ed213d422a87d3b22fc9e85d14ffaf53f;p=jalview.git
diff --git a/src/jalview/gui/PymolViewer.java b/src/jalview/gui/PymolViewer.java
index 09451be..9dc28c8 100644
--- a/src/jalview/gui/PymolViewer.java
+++ b/src/jalview/gui/PymolViewer.java
@@ -1,24 +1,50 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.gui;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.JInternalFrame;
+import javax.swing.JMenuItem;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
+
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureRenderer;
-import jalview.bin.Cache;
+import jalview.bin.Console;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.StructureViewerModel;
+import jalview.datamodel.StructureViewerModel.StructureData;
import jalview.gui.StructureViewer.ViewerType;
import jalview.io.DataSourceType;
import jalview.io.StructureFile;
import jalview.structures.models.AAStructureBindingModel;
import jalview.util.MessageManager;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.swing.JInternalFrame;
-import javax.swing.event.InternalFrameAdapter;
-import javax.swing.event.InternalFrameEvent;
-
public class PymolViewer extends StructureViewerBase
{
private static final int myWidth = 500;
@@ -44,9 +70,7 @@ public class PymolViewer extends StructureViewerBase
AlignmentPanel ap)
{
this();
- openNewPymol(ap, new PDBEntry[] { pdb },
- new SequenceI[][]
- { seqs });
+ openNewPymol(ap, new PDBEntry[] { pdb }, new SequenceI[][] { seqs });
}
public PymolViewer(PDBEntry[] pe, boolean alignAdded, SequenceI[][] seqs,
@@ -57,6 +81,54 @@ public class PymolViewer extends StructureViewerBase
openNewPymol(ap, pe, seqs);
}
+ /**
+ * Constructor given a session file to be restored
+ *
+ * @param sessionFile
+ * @param alignPanel
+ * @param pdbArray
+ * @param seqsArray
+ * @param colourByPymol
+ * @param colourBySequence
+ * @param newViewId
+ */
+ public PymolViewer(StructureViewerModel viewerModel,
+ AlignmentPanel alignPanel, String sessionFile, String vid)
+ {
+ // TODO convert to base/factory class method
+ this();
+ setViewId(vid);
+ this.pymolSessionFile = sessionFile;
+ Map pdbData = viewerModel.getFileData();
+ PDBEntry[] pdbArray = new PDBEntry[pdbData.size()];
+ SequenceI[][] seqsArray = new SequenceI[pdbData.size()][];
+ int i = 0;
+ for (StructureData data : pdbData.values())
+ {
+ PDBEntry pdbentry = new PDBEntry(data.getPdbId(), null,
+ PDBEntry.Type.PDB, data.getFilePath());
+ pdbArray[i] = pdbentry;
+ List sequencesForPdb = data.getSeqList();
+ seqsArray[i] = sequencesForPdb
+ .toArray(new SequenceI[sequencesForPdb.size()]);
+ i++;
+ }
+
+ openNewPymol(alignPanel, pdbArray, seqsArray);
+ if (viewerModel.isColourByViewer())
+ {
+ binding.setColourBySequence(false);
+ seqColour.setSelected(false);
+ viewerColour.setSelected(true);
+ }
+ else if (viewerModel.isColourWithAlignPanel())
+ {
+ binding.setColourBySequence(true);
+ seqColour.setSelected(true);
+ viewerColour.setSelected(false);
+ }
+ }
+
private void openNewPymol(AlignmentPanel ap, PDBEntry[] pe,
SequenceI[][] seqs)
{
@@ -73,6 +145,8 @@ public class PymolViewer extends StructureViewerBase
binding.setColourBySequence(true);
setSize(myWidth, myHeight);
initMenus();
+ viewerActionMenu.setText("PyMOL");
+ updateTitleAndMenus();
addingStructures = false;
worker = new Thread(this);
@@ -105,11 +179,12 @@ public class PymolViewer extends StructureViewerBase
public void run()
{
// todo pull up much of this
-
+
StringBuilder errormsgs = new StringBuilder(128);
List filePDB = new ArrayList<>();
List filePDBpos = new ArrayList<>();
- String[] curfiles = binding.getStructureFiles(); // files currently in viewer
+ String[] curfiles = binding.getStructureFiles(); // files currently in
+ // viewer
for (int pi = 0; pi < binding.getPdbCount(); pi++)
{
String file = null;
@@ -130,8 +205,7 @@ public class PymolViewer extends StructureViewerBase
/*
* got file already
*/
- file = new File(thePdbEntry.getFile()).getAbsoluteFile()
- .getPath();
+ file = new File(thePdbEntry.getFile()).getAbsoluteFile().getPath();
// todo - skip if already loaded in PyMOL
}
if (file != null)
@@ -140,7 +214,7 @@ public class PymolViewer extends StructureViewerBase
filePDBpos.add(Integer.valueOf(pi));
}
}
-
+
if (!filePDB.isEmpty())
{
/*
@@ -154,9 +228,19 @@ public class PymolViewer extends StructureViewerBase
initPymol();
} catch (Exception ex)
{
- Cache.log.error("Couldn't open PyMOL viewer!", ex);
+ Console.error("Couldn't open PyMOL viewer!", ex);
+ // if we couldn't open Pymol, no point continuing
+ return;
}
}
+ if (!binding.isViewerRunning())
+ {
+ // nothing to do
+ // TODO: ensure we tidy up JAL-3619
+
+ return;
+ }
+
int num = -1;
for (PDBEntry pe : filePDB)
{
@@ -188,17 +272,15 @@ public class PymolViewer extends StructureViewerBase
StructureFile pdb = binding.getSsm().setMapping(
binding.getSequence()[pos], binding.getChains()[pos],
- pe.getFile(), protocol,
- getProgressIndicator());
+ pe.getFile(), protocol, getProgressIndicator());
binding.stashFoundChains(pdb, pe.getFile());
} catch (Exception ex)
{
- Cache.log.error(
- "Couldn't open " + pe.getFile() + " in Chimera viewer!",
- ex);
+ Console.error("Couldn't open " + pe.getFile() + " in "
+ + getViewerName() + "!", ex);
} finally
{
- // Cache.log.debug("File locations are " + files);
+ // Cache.debug("File locations are " + files);
}
}
}
@@ -254,9 +336,11 @@ public class PymolViewer extends StructureViewerBase
if (!binding.launchPymol())
{
JvOptionPane.showMessageDialog(Desktop.desktop,
- MessageManager.getString("label.pymol_failed"),
+ MessageManager.formatMessage("label.open_viewer_failed",
+ getViewerName()),
MessageManager.getString("label.error_loading_file"),
JvOptionPane.ERROR_MESSAGE);
+ binding.closeViewer(true);
this.dispose();
return;
}
@@ -266,7 +350,7 @@ public class PymolViewer extends StructureViewerBase
boolean opened = binding.openSession(pymolSessionFile);
if (!opened)
{
- System.err.println("An error occurred opening PyMOL session file "
+ Console.error("An error occurred opening PyMOL session file "
+ pymolSessionFile);
}
}
@@ -280,59 +364,54 @@ public class PymolViewer extends StructureViewerBase
}
@Override
- public void closeViewer(boolean closePymol)
+ public ViewerType getViewerType()
{
- if (binding != null && binding.isPymolRunning())
- {
- if (!closePymol)
- {
- // TODO i18n (and pull up)
- String prompt = MessageManager
- .formatMessage("label.confirm_close_pymol", new Object[]
- { binding.getViewerTitle(getViewerName(), 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;
- }
- closePymol = confirm == JvOptionPane.YES_OPTION;
- }
- binding.closeViewer(closePymol);
- }
- setAlignmentPanel(null);
- _aps.clear();
- _alignwith.clear();
- _colourwith.clear();
- // TODO: check for memory leaks where instance isn't finalised because
- // binding
- // holds a reference to the window
- binding = null;
- dispose();
+ return ViewerType.PYMOL;
}
@Override
- public String getStateInfo()
+ protected String getViewerName()
{
- return null;
+ return "PyMOL";
}
+ JMenuItem writeFeatures = null;
+
@Override
- public ViewerType getViewerType()
+ protected void initMenus()
{
- return ViewerType.PYMOL;
+ super.initMenus();
+
+ savemenu.setVisible(false); // not yet implemented
+ viewMenu.add(fitToWindow);
+
+ writeFeatures = new JMenuItem(
+ MessageManager.getString("label.create_viewer_attributes"));
+ writeFeatures.setToolTipText(
+ MessageManager.getString("label.create_viewer_attributes_tip"));
+ writeFeatures.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ sendFeaturesToPymol();
+ }
+ });
+ viewerActionMenu.add(writeFeatures);
}
@Override
- protected String getViewerName()
+ protected void buildActionMenu()
{
- return "PyMOL";
+ super.buildActionMenu();
+ viewerActionMenu.add(writeFeatures);
+ }
+
+ protected void sendFeaturesToPymol()
+ {
+ int count = binding.sendFeaturesToViewer(getAlignmentPanel());
+ statusBar.setText(MessageManager.formatMessage("label.attributes_set",
+ count, getViewerName()));
}
}