2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
22 import java.awt.event.*;
24 import javax.xml.parsers.ParserConfigurationException;
26 import org.xml.sax.SAXException;
28 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
29 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
30 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
31 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
33 import jalview.datamodel.*;
36 import jalview.schemes.*;
37 import jalview.ws.ebi.EBIFetchClient;
39 public class PDBViewer extends JInternalFrame implements Runnable
43 * The associated sequence in an alignment
59 public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
60 AlignmentPanel ap, String protocol) throws ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
63 this.pdbentry = pdbentry;
67 this.protocol = protocol;
72 } catch (Exception ex)
77 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
78 + pdbentry.getFile());
80 pdbcanvas = new PDBCanvas();
82 setContentPane(pdbcanvas);
84 if (pdbentry.getFile() != null)
88 tmpPDBFile = pdbentry.getFile();
89 PDBfile pdbfile = new PDBfile(tmpPDBFile,
90 jalview.io.AppletFormatAdapter.FILE);
92 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
94 } catch (java.io.IOException ex)
101 Thread worker = new Thread(this);
105 if (pdbentry.getProperty() != null)
107 if (pdbentry.getProperty().get("method") != null)
109 title.append(" Method: ");
110 title.append(pdbentry.getProperty().get("method"));
112 if (pdbentry.getProperty().get("chains") != null)
114 title.append(" Chain:");
115 title.append(pdbentry.getProperty().get("chains"));
118 Desktop.addInternalFrame(this, title.toString(), 400, 400);
125 EBIFetchClient ebi = new EBIFetchClient();
126 String query = "pdb:" + pdbentry.getId();
127 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
130 if (pdbentry.getFile() != null)
131 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
132 } catch (Exception ex)
134 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
135 ex.printStackTrace();
139 private void jbInit() throws Exception
141 this.addKeyListener(new KeyAdapter()
143 public void keyPressed(KeyEvent evt)
145 pdbcanvas.keyPressed(evt);
149 this.setJMenuBar(jMenuBar1);
150 fileMenu.setText("File");
151 coloursMenu.setText("Colours");
152 saveMenu.setActionCommand("Save Image");
153 saveMenu.setText("Save As");
155 png.addActionListener(new ActionListener()
157 public void actionPerformed(ActionEvent e)
159 png_actionPerformed(e);
163 eps.addActionListener(new ActionListener()
165 public void actionPerformed(ActionEvent e)
167 eps_actionPerformed(e);
170 mapping.setText("View Mapping");
171 mapping.addActionListener(new ActionListener()
173 public void actionPerformed(ActionEvent e)
175 mapping_actionPerformed(e);
178 wire.setText("Wireframe");
179 wire.addActionListener(new ActionListener()
181 public void actionPerformed(ActionEvent e)
183 wire_actionPerformed(e);
186 depth.setSelected(true);
187 depth.setText("Depthcue");
188 depth.addActionListener(new ActionListener()
190 public void actionPerformed(ActionEvent e)
192 depth_actionPerformed(e);
195 zbuffer.setSelected(true);
196 zbuffer.setText("Z Buffering");
197 zbuffer.addActionListener(new ActionListener()
199 public void actionPerformed(ActionEvent e)
201 zbuffer_actionPerformed(e);
204 charge.setText("Charge & Cysteine");
205 charge.addActionListener(new ActionListener()
207 public void actionPerformed(ActionEvent e)
209 charge_actionPerformed(e);
212 chain.setText("By Chain");
213 chain.addActionListener(new ActionListener()
215 public void actionPerformed(ActionEvent e)
217 chain_actionPerformed(e);
220 seqButton.setSelected(true);
221 seqButton.setText("By Sequence");
222 seqButton.addActionListener(new ActionListener()
224 public void actionPerformed(ActionEvent e)
226 seqButton_actionPerformed(e);
229 allchains.setSelected(true);
230 allchains.setText("Show All Chains");
231 allchains.addItemListener(new ItemListener()
233 public void itemStateChanged(ItemEvent e)
235 allchains_itemStateChanged(e);
238 zappo.setText("Zappo");
239 zappo.addActionListener(new ActionListener()
241 public void actionPerformed(ActionEvent e)
243 zappo_actionPerformed(e);
246 taylor.setText("Taylor");
247 taylor.addActionListener(new ActionListener()
249 public void actionPerformed(ActionEvent e)
251 taylor_actionPerformed(e);
254 hydro.setText("Hydro");
255 hydro.addActionListener(new ActionListener()
257 public void actionPerformed(ActionEvent e)
259 hydro_actionPerformed(e);
262 helix.setText("Helix");
263 helix.addActionListener(new ActionListener()
265 public void actionPerformed(ActionEvent e)
267 helix_actionPerformed(e);
270 strand.setText("Strand");
271 strand.addActionListener(new ActionListener()
273 public void actionPerformed(ActionEvent e)
275 strand_actionPerformed(e);
278 turn.setText("Turn");
279 turn.addActionListener(new ActionListener()
281 public void actionPerformed(ActionEvent e)
283 turn_actionPerformed(e);
286 buried.setText("Buried");
287 buried.addActionListener(new ActionListener()
289 public void actionPerformed(ActionEvent e)
291 buried_actionPerformed(e);
294 user.setText("User Defined...");
295 user.addActionListener(new ActionListener()
297 public void actionPerformed(ActionEvent e)
299 user_actionPerformed(e);
302 viewMenu.setText("View");
303 background.setText("Background Colour...");
304 background.addActionListener(new ActionListener()
306 public void actionPerformed(ActionEvent e)
308 background_actionPerformed(e);
311 savePDB.setText("PDB File");
312 savePDB.addActionListener(new ActionListener()
314 public void actionPerformed(ActionEvent e)
316 savePDB_actionPerformed(e);
319 jMenuBar1.add(fileMenu);
320 jMenuBar1.add(coloursMenu);
321 jMenuBar1.add(viewMenu);
322 fileMenu.add(saveMenu);
323 fileMenu.add(mapping);
324 saveMenu.add(savePDB);
327 coloursMenu.add(seqButton);
328 coloursMenu.add(chain);
329 coloursMenu.add(charge);
330 coloursMenu.add(zappo);
331 coloursMenu.add(taylor);
332 coloursMenu.add(hydro);
333 coloursMenu.add(helix);
334 coloursMenu.add(strand);
335 coloursMenu.add(turn);
336 coloursMenu.add(buried);
337 coloursMenu.add(user);
338 coloursMenu.add(background);
339 ButtonGroup bg = new ButtonGroup();
352 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
354 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
355 .getUserColourSchemes().keys();
357 while (userColours.hasMoreElements())
359 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
360 userColours.nextElement().toString());
361 radioItem.setName("USER_DEFINED");
362 radioItem.addMouseListener(new MouseAdapter()
364 public void mousePressed(MouseEvent evt)
366 if (evt.isControlDown()
367 || SwingUtilities.isRightMouseButton(evt))
369 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
371 int option = JOptionPane.showInternalConfirmDialog(
372 jalview.gui.Desktop.desktop,
373 "Remove from default list?",
374 "Remove user defined colour",
375 JOptionPane.YES_NO_OPTION);
376 if (option == JOptionPane.YES_OPTION)
378 jalview.gui.UserDefinedColours
379 .removeColourFromDefaults(radioItem.getText());
380 coloursMenu.remove(radioItem);
384 radioItem.addActionListener(new ActionListener()
386 public void actionPerformed(ActionEvent evt)
388 user_actionPerformed(evt);
395 radioItem.addActionListener(new ActionListener()
397 public void actionPerformed(ActionEvent evt)
399 user_actionPerformed(evt);
402 coloursMenu.add(radioItem);
409 viewMenu.add(zbuffer);
410 viewMenu.add(allchains);
413 JMenuBar jMenuBar1 = new JMenuBar();
415 JMenu fileMenu = new JMenu();
417 JMenu coloursMenu = new JMenu();
419 JMenu saveMenu = new JMenu();
421 JMenuItem png = new JMenuItem();
423 JMenuItem eps = new JMenuItem();
425 JMenuItem mapping = new JMenuItem();
427 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
429 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
431 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
433 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
435 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
437 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
439 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
441 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
443 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
445 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
447 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
449 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
451 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
453 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
455 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
457 JMenu viewMenu = new JMenu();
459 JMenuItem background = new JMenuItem();
461 JMenuItem savePDB = new JMenuItem();
469 public void eps_actionPerformed(ActionEvent e)
471 makePDBImage(jalview.util.ImageMaker.EPS);
480 public void png_actionPerformed(ActionEvent e)
482 makePDBImage(jalview.util.ImageMaker.PNG);
485 void makePDBImage(int type)
487 int width = pdbcanvas.getWidth();
488 int height = pdbcanvas.getHeight();
490 jalview.util.ImageMaker im;
492 if (type == jalview.util.ImageMaker.PNG)
494 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
495 "Make PNG image from view", width, height, null, null);
499 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
500 "Make EPS file from view", width, height, null,
504 if (im.getGraphics() != null)
506 pdbcanvas.drawAll(im.getGraphics(), width, height);
511 public void charge_actionPerformed(ActionEvent e)
513 pdbcanvas.bysequence = false;
514 pdbcanvas.pdb.setChargeColours();
515 pdbcanvas.redrawneeded = true;
519 public void hydro_actionPerformed(ActionEvent e)
521 pdbcanvas.bysequence = false;
522 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
523 pdbcanvas.redrawneeded = true;
527 public void chain_actionPerformed(ActionEvent e)
529 pdbcanvas.bysequence = false;
530 pdbcanvas.pdb.setChainColours();
531 pdbcanvas.redrawneeded = true;
535 public void zbuffer_actionPerformed(ActionEvent e)
537 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
538 pdbcanvas.redrawneeded = true;
542 public void molecule_actionPerformed(ActionEvent e)
544 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
545 pdbcanvas.redrawneeded = true;
549 public void depth_actionPerformed(ActionEvent e)
551 pdbcanvas.depthcue = !pdbcanvas.depthcue;
552 pdbcanvas.redrawneeded = true;
556 public void wire_actionPerformed(ActionEvent e)
558 pdbcanvas.wire = !pdbcanvas.wire;
559 pdbcanvas.redrawneeded = true;
563 public void seqButton_actionPerformed(ActionEvent e)
565 pdbcanvas.bysequence = true;
566 pdbcanvas.updateSeqColours();
569 public void mapping_actionPerformed(ActionEvent e)
571 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
574 cap.setText(pdbcanvas.mappingDetails.toString());
575 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
576 } catch (OutOfMemoryError oom)
578 new OOMWarning("Opening sequence to structure mapping report", oom);
583 public void allchains_itemStateChanged(ItemEvent e)
585 pdbcanvas.setAllchainsVisible(allchains.getState());
588 public void zappo_actionPerformed(ActionEvent e)
590 pdbcanvas.bysequence = false;
591 pdbcanvas.pdb.setColours(new ZappoColourScheme());
592 pdbcanvas.redrawneeded = true;
596 public void taylor_actionPerformed(ActionEvent e)
598 pdbcanvas.bysequence = false;
599 pdbcanvas.pdb.setColours(new TaylorColourScheme());
600 pdbcanvas.redrawneeded = true;
604 public void helix_actionPerformed(ActionEvent e)
606 pdbcanvas.bysequence = false;
607 pdbcanvas.pdb.setColours(new HelixColourScheme());
608 pdbcanvas.redrawneeded = true;
612 public void strand_actionPerformed(ActionEvent e)
614 pdbcanvas.bysequence = false;
615 pdbcanvas.pdb.setColours(new StrandColourScheme());
616 pdbcanvas.redrawneeded = true;
620 public void turn_actionPerformed(ActionEvent e)
622 pdbcanvas.bysequence = false;
623 pdbcanvas.pdb.setColours(new TurnColourScheme());
624 pdbcanvas.redrawneeded = true;
628 public void buried_actionPerformed(ActionEvent e)
630 pdbcanvas.bysequence = false;
631 pdbcanvas.pdb.setColours(new BuriedColourScheme());
632 pdbcanvas.redrawneeded = true;
636 public void user_actionPerformed(ActionEvent e)
638 if (e.getActionCommand().equals("User Defined..."))
640 // new UserDefinedColours(pdbcanvas, null);
644 UserColourScheme udc = (UserColourScheme) UserDefinedColours
645 .getUserColourSchemes().get(e.getActionCommand());
647 pdbcanvas.pdb.setColours(udc);
648 pdbcanvas.redrawneeded = true;
653 public void background_actionPerformed(ActionEvent e)
655 java.awt.Color col = JColorChooser.showDialog(this,
656 "Select Background Colour", pdbcanvas.backgroundColour);
660 pdbcanvas.backgroundColour = col;
661 pdbcanvas.redrawneeded = true;
666 public void savePDB_actionPerformed(ActionEvent e)
668 JalviewFileChooser chooser = new JalviewFileChooser(
669 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
671 chooser.setFileView(new JalviewFileView());
672 chooser.setDialogTitle("Save PDB File");
673 chooser.setToolTipText("Save");
675 int value = chooser.showSaveDialog(this);
677 if (value == JalviewFileChooser.APPROVE_OPTION)
681 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
682 File outFile = chooser.getSelectedFile();
684 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
686 while ((data = in.readLine()) != null)
688 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
695 } catch (Exception ex)
697 ex.printStackTrace();