+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * 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;
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,
* @param colourBySequence
* @param newViewId
*/
- public PymolViewer(String sessionFile, AlignmentPanel alignPanel,
- PDBEntry[] pdbArray, SequenceI[][] seqsArray,
- boolean colourByPymol, boolean colourBySequence, String newViewId)
+ public PymolViewer(StructureViewerModel viewerModel,
+ AlignmentPanel alignPanel, String sessionFile, String vid)
{
// TODO convert to base/factory class method
this();
- setViewId(newViewId);
+ setViewId(vid);
this.pymolSessionFile = sessionFile;
+ Map<File, StructureData> 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<SequenceI> sequencesForPdb = data.getSeqList();
+ seqsArray[i] = sequencesForPdb
+ .toArray(new SequenceI[sequencesForPdb.size()]);
+ i++;
+ }
+
openNewPymol(alignPanel, pdbArray, seqsArray);
- if (colourByPymol)
+ if (viewerModel.isColourByViewer())
{
binding.setColourBySequence(false);
seqColour.setSelected(false);
viewerColour.setSelected(true);
}
- else if (colourBySequence)
+ else if (viewerModel.isColourWithAlignPanel())
{
binding.setColourBySequence(true);
seqColour.setSelected(true);
public void run()
{
// todo pull up much of this
-
+
StringBuilder errormsgs = new StringBuilder(128);
List<PDBEntry> filePDB = new ArrayList<>();
List<Integer> 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;
/*
* 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)
filePDBpos.add(Integer.valueOf(pi));
}
}
-
+
if (!filePDB.isEmpty())
{
/*
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)
{
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);
}
}
}
getViewerName()),
MessageManager.getString("label.error_loading_file"),
JvOptionPane.ERROR_MESSAGE);
+ binding.closeViewer(true);
this.dispose();
return;
}
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);
}
}
return "PyMOL";
}
+ JMenuItem writeFeatures = null;
+
+ @Override
+ protected void initMenus()
+ {
+ 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 void buildActionMenu()
+ {
+ super.buildActionMenu();
+ viewerActionMenu.add(writeFeatures);
+ }
+
+ protected void sendFeaturesToPymol()
+ {
+ int count = binding.sendFeaturesToViewer(getAlignmentPanel());
+ statusBar.setText(MessageManager.formatMessage("label.attributes_set",
+ count, getViewerName()));
+ }
+
}