X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FPDBViewer.java;h=8bfd7b51eb3147c355d1fd42e5a5b0844eae9166;hb=0e533ac31cde9a3b168482d08961d619ce20528c;hp=3e4d21ceeebc5ae2422a8ef4eee1993ddc700529;hpb=dd74fc4938723fe5ec48d4e5fdcfbe58ac42a48d;p=jalview.git diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index 3e4d21c..8bfd7b5 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -1,20 +1,19 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle - * - * This program 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 2 - * of the License, or (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8) + * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle + * + * 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 . */ package MCview; @@ -27,50 +26,64 @@ import jalview.datamodel.*; import jalview.gui.*; import jalview.io.*; import jalview.schemes.*; +import jalview.ws.ebi.EBIFetchClient; -public class PDBViewer - extends JInternalFrame implements Runnable +public class PDBViewer extends JInternalFrame implements Runnable { - PDBEntry pdb; + /** * The associated sequence in an alignment */ - Sequence sequence; PDBCanvas pdbcanvas; + + PDBEntry pdbentry; + + SequenceI[] seq; + + String[] chains; + + AlignmentPanel ap; + + String protocol; + String tmpPDBFile; - public PDBViewer(PDBEntry entry, - Sequence seq, - SeqCanvas seqcanvas) + public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains, + AlignmentPanel ap, String protocol) + { + this.pdbentry = pdbentry; + this.seq = seq; + this.chains = chains; + this.ap = ap; + this.protocol = protocol; + try { jbInit(); - } - catch (Exception ex) + } catch (Exception ex) { ex.printStackTrace(); } - if (entry == null) - { - return; - } - pdb = entry; - sequence = seq; - pdbcanvas = new PDBCanvas(seqcanvas, sequence); + StringBuffer title = new StringBuffer(seq[0].getName() + ":" + + pdbentry.getFile()); + + pdbcanvas = new PDBCanvas(); + + setContentPane(pdbcanvas); - if (pdb.getFile() != null) + if (pdbentry.getFile() != null) { try { - tmpPDBFile = pdb.getFile(); + tmpPDBFile = pdbentry.getFile(); PDBfile pdbfile = new PDBfile(tmpPDBFile, - jalview.io.AppletFormatAdapter.FILE); - pdbcanvas.setPDBFile(pdbfile); + jalview.io.AppletFormatAdapter.FILE); - } - catch (java.io.IOException ex) + pdbcanvas.init(pdbentry, seq, chains, ap, protocol); + + } catch (java.io.IOException ex) { ex.printStackTrace(); } @@ -81,19 +94,17 @@ public class PDBViewer worker.start(); } - setContentPane(pdbcanvas); - StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId()); - if (pdb.getProperty() != null) + if (pdbentry.getProperty() != null) { - if (pdb.getProperty().get("method") != null) + if (pdbentry.getProperty().get("method") != null) { title.append(" Method: "); - title.append(pdb.getProperty().get("method")); + title.append(pdbentry.getProperty().get("method")); } - if (pdb.getProperty().get("chains") != null) + if (pdbentry.getProperty().get("chains") != null) { title.append(" Chain:"); - title.append(pdb.getProperty().get("chains")); + title.append(pdbentry.getProperty().get("chains")); } } Desktop.addInternalFrame(this, title.toString(), 400, 400); @@ -104,29 +115,20 @@ public class PDBViewer try { EBIFetchClient ebi = new EBIFetchClient(); - String query = "pdb:" + pdb.getId(); - tmpPDBFile = ebi.fetchDataAsFile(query, "default", "raw").getAbsolutePath(); - if (tmpPDBFile != null) - { - PDBfile pdbfile = new PDBfile(tmpPDBFile, - jalview.io.AppletFormatAdapter.FILE); - pdbcanvas.setPDBFile(pdbfile); - } - else - { - throw new Exception("Empty result for WSDbFetch Query: " + query); - } - } - catch (Exception ex) + String query = "pdb:" + pdbentry.getId(); + pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw") + .getAbsolutePath()); + + if (pdbentry.getFile() != null) + pdbcanvas.init(pdbentry, seq, chains, ap, protocol); + } catch (Exception ex) { + pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId(); ex.printStackTrace(); - showErrorMessage("Failed to retrieve PDB structure."); -// this.dispose(); } } - private void jbInit() - throws Exception + private void jbInit() throws Exception { this.addKeyListener(new KeyAdapter() { @@ -341,32 +343,32 @@ public class PDBViewer if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null) { - java.util.Enumeration userColours = jalview.gui.UserDefinedColours. - getUserColourSchemes().keys(); + java.util.Enumeration userColours = jalview.gui.UserDefinedColours + .getUserColourSchemes().keys(); while (userColours.hasMoreElements()) { final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem( - userColours. - nextElement().toString()); + userColours.nextElement().toString()); radioItem.setName("USER_DEFINED"); radioItem.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent evt) { - if (evt.isControlDown() || SwingUtilities.isRightMouseButton(evt)) + if (evt.isControlDown() + || SwingUtilities.isRightMouseButton(evt)) { radioItem.removeActionListener(radioItem.getActionListeners()[0]); - int option = JOptionPane.showInternalConfirmDialog(jalview.gui. - Desktop.desktop, - "Remove from default list?", - "Remove user defined colour", - JOptionPane.YES_NO_OPTION); + int option = JOptionPane.showInternalConfirmDialog( + jalview.gui.Desktop.desktop, + "Remove from default list?", + "Remove user defined colour", + JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { - jalview.gui.UserDefinedColours.removeColourFromDefaults( - radioItem.getText()); + jalview.gui.UserDefinedColours + .removeColourFromDefaults(radioItem.getText()); coloursMenu.remove(radioItem); } else @@ -401,36 +403,60 @@ public class PDBViewer } JMenuBar jMenuBar1 = new JMenuBar(); + JMenu fileMenu = new JMenu(); + JMenu coloursMenu = new JMenu(); + JMenu saveMenu = new JMenu(); + JMenuItem png = new JMenuItem(); + JMenuItem eps = new JMenuItem(); + JMenuItem mapping = new JMenuItem(); + JCheckBoxMenuItem wire = new JCheckBoxMenuItem(); + JCheckBoxMenuItem depth = new JCheckBoxMenuItem(); + JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem(); + JCheckBoxMenuItem allchains = new JCheckBoxMenuItem(); JRadioButtonMenuItem charge = new JRadioButtonMenuItem(); + JRadioButtonMenuItem chain = new JRadioButtonMenuItem(); + JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem(); + JRadioButtonMenuItem hydro = new JRadioButtonMenuItem(); + JRadioButtonMenuItem taylor = new JRadioButtonMenuItem(); + JRadioButtonMenuItem zappo = new JRadioButtonMenuItem(); + JRadioButtonMenuItem user = new JRadioButtonMenuItem(); + JRadioButtonMenuItem buried = new JRadioButtonMenuItem(); + JRadioButtonMenuItem turn = new JRadioButtonMenuItem(); + JRadioButtonMenuItem strand = new JRadioButtonMenuItem(); + JRadioButtonMenuItem helix = new JRadioButtonMenuItem(); + JMenu viewMenu = new JMenu(); + JMenuItem background = new JMenuItem(); + JMenuItem savePDB = new JMenuItem(); /** * DOCUMENT ME! - * - * @param e DOCUMENT ME! + * + * @param e + * DOCUMENT ME! */ public void eps_actionPerformed(ActionEvent e) { @@ -439,8 +465,9 @@ public class PDBViewer /** * DOCUMENT ME! - * - * @param e DOCUMENT ME! + * + * @param e + * DOCUMENT ME! */ public void png_actionPerformed(ActionEvent e) { @@ -456,19 +483,14 @@ public class PDBViewer if (type == jalview.util.ImageMaker.PNG) { - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.PNG, - "Make PNG image from view", - width, height, - null, null); + im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG, + "Make PNG image from view", width, height, null, null); } else { - im = new jalview.util.ImageMaker(this, - jalview.util.ImageMaker.EPS, - "Make EPS file from view", - width, height, - null, this.getTitle()); + im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS, + "Make EPS file from view", width, height, null, + this.getTitle()); } if (im.getGraphics() != null) @@ -539,8 +561,15 @@ public class PDBViewer public void mapping_actionPerformed(ActionEvent e) { jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer(); - Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600); - cap.setText(pdbcanvas.mappingDetails.toString()); + try + { + cap.setText(pdbcanvas.mappingDetails.toString()); + Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600); + } catch (OutOfMemoryError oom) + { + new OOMWarning("Opening sequence to structure mapping report", oom); + cap.dispose(); + } } public void allchains_itemStateChanged(ItemEvent e) @@ -548,13 +577,6 @@ public class PDBViewer pdbcanvas.setAllchainsVisible(allchains.getState()); } - void showErrorMessage(String error) - { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - error, "PDB Viewer Error", - JOptionPane.WARNING_MESSAGE); - } - public void zappo_actionPerformed(ActionEvent e) { pdbcanvas.bysequence = false; @@ -607,12 +629,12 @@ public class PDBViewer { if (e.getActionCommand().equals("User Defined...")) { - new UserDefinedColours(pdbcanvas, null); + // new UserDefinedColours(pdbcanvas, null); } else { - UserColourScheme udc = (UserColourScheme) UserDefinedColours. - getUserColourSchemes().get(e.getActionCommand()); + UserColourScheme udc = (UserColourScheme) UserDefinedColours + .getUserColourSchemes().get(e.getActionCommand()); pdbcanvas.pdb.setColours(udc); pdbcanvas.redrawneeded = true; @@ -623,8 +645,7 @@ public class PDBViewer public void background_actionPerformed(ActionEvent e) { java.awt.Color col = JColorChooser.showDialog(this, - "Select Background Colour", - pdbcanvas.backgroundColour); + "Select Background Colour", pdbcanvas.backgroundColour); if (col != null) { @@ -637,8 +658,7 @@ public class PDBViewer public void savePDB_actionPerformed(ActionEvent e) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty( - "LAST_DIRECTORY")); + jalview.bin.Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Save PDB File"); @@ -655,18 +675,16 @@ public class PDBViewer PrintWriter out = new PrintWriter(new FileOutputStream(outFile)); String data; - while ( (data = in.readLine()) != null) + while ((data = in.readLine()) != null) { - if ( - ! (data.indexOf("
") > -1 || data.indexOf("
") > -1) - ) + if (!(data.indexOf("
") > -1 || data.indexOf("
") > -1)) { out.println(data); } } out.close(); - } - catch (Exception ex) + in.close(); + } catch (Exception ex) { ex.printStackTrace(); }