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)
62 this.pdbentry = pdbentry;
66 this.protocol = protocol;
71 } catch (Exception ex)
76 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
77 + pdbentry.getFile());
79 pdbcanvas = new PDBCanvas();
81 setContentPane(pdbcanvas);
83 if (pdbentry.getFile() != null)
87 tmpPDBFile = pdbentry.getFile();
88 PDBfile pdbfile = new PDBfile(tmpPDBFile,
89 jalview.io.AppletFormatAdapter.FILE);
91 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
93 } catch (java.io.IOException ex)
100 Thread worker = new Thread(this);
104 if (pdbentry.getProperty() != null)
106 if (pdbentry.getProperty().get("method") != null)
108 title.append(" Method: ");
109 title.append(pdbentry.getProperty().get("method"));
111 if (pdbentry.getProperty().get("chains") != null)
113 title.append(" Chain:");
114 title.append(pdbentry.getProperty().get("chains"));
117 Desktop.addInternalFrame(this, title.toString(), 400, 400);
124 EBIFetchClient ebi = new EBIFetchClient();
125 String query = "pdb:" + pdbentry.getId();
126 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
129 if (pdbentry.getFile() != null)
130 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
131 } catch (Exception ex)
133 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
134 ex.printStackTrace();
138 private void jbInit() throws Exception
140 this.addKeyListener(new KeyAdapter()
142 public void keyPressed(KeyEvent evt)
144 pdbcanvas.keyPressed(evt);
148 this.setJMenuBar(jMenuBar1);
149 fileMenu.setText("File");
150 coloursMenu.setText("Colours");
151 saveMenu.setActionCommand("Save Image");
152 saveMenu.setText("Save As");
154 png.addActionListener(new ActionListener()
156 public void actionPerformed(ActionEvent e)
158 png_actionPerformed(e);
162 eps.addActionListener(new ActionListener()
164 public void actionPerformed(ActionEvent e)
166 eps_actionPerformed(e);
169 mapping.setText("View Mapping");
170 mapping.addActionListener(new ActionListener()
172 public void actionPerformed(ActionEvent e)
174 mapping_actionPerformed(e);
177 wire.setText("Wireframe");
178 wire.addActionListener(new ActionListener()
180 public void actionPerformed(ActionEvent e)
182 wire_actionPerformed(e);
185 depth.setSelected(true);
186 depth.setText("Depthcue");
187 depth.addActionListener(new ActionListener()
189 public void actionPerformed(ActionEvent e)
191 depth_actionPerformed(e);
194 zbuffer.setSelected(true);
195 zbuffer.setText("Z Buffering");
196 zbuffer.addActionListener(new ActionListener()
198 public void actionPerformed(ActionEvent e)
200 zbuffer_actionPerformed(e);
203 charge.setText("Charge & Cysteine");
204 charge.addActionListener(new ActionListener()
206 public void actionPerformed(ActionEvent e)
208 charge_actionPerformed(e);
211 chain.setText("By Chain");
212 chain.addActionListener(new ActionListener()
214 public void actionPerformed(ActionEvent e)
216 chain_actionPerformed(e);
219 seqButton.setSelected(true);
220 seqButton.setText("By Sequence");
221 seqButton.addActionListener(new ActionListener()
223 public void actionPerformed(ActionEvent e)
225 seqButton_actionPerformed(e);
228 allchains.setSelected(true);
229 allchains.setText("Show All Chains");
230 allchains.addItemListener(new ItemListener()
232 public void itemStateChanged(ItemEvent e)
234 allchains_itemStateChanged(e);
237 zappo.setText("Zappo");
238 zappo.addActionListener(new ActionListener()
240 public void actionPerformed(ActionEvent e)
242 zappo_actionPerformed(e);
245 taylor.setText("Taylor");
246 taylor.addActionListener(new ActionListener()
248 public void actionPerformed(ActionEvent e)
250 taylor_actionPerformed(e);
253 hydro.setText("Hydro");
254 hydro.addActionListener(new ActionListener()
256 public void actionPerformed(ActionEvent e)
258 hydro_actionPerformed(e);
261 helix.setText("Helix");
262 helix.addActionListener(new ActionListener()
264 public void actionPerformed(ActionEvent e)
266 helix_actionPerformed(e);
269 strand.setText("Strand");
270 strand.addActionListener(new ActionListener()
272 public void actionPerformed(ActionEvent e)
274 strand_actionPerformed(e);
277 turn.setText("Turn");
278 turn.addActionListener(new ActionListener()
280 public void actionPerformed(ActionEvent e)
282 turn_actionPerformed(e);
285 buried.setText("Buried");
286 buried.addActionListener(new ActionListener()
288 public void actionPerformed(ActionEvent e)
290 buried_actionPerformed(e);
293 user.setText("User Defined...");
294 user.addActionListener(new ActionListener()
296 public void actionPerformed(ActionEvent e)
298 user_actionPerformed(e);
301 viewMenu.setText("View");
302 background.setText("Background Colour...");
303 background.addActionListener(new ActionListener()
305 public void actionPerformed(ActionEvent e)
307 background_actionPerformed(e);
310 savePDB.setText("PDB File");
311 savePDB.addActionListener(new ActionListener()
313 public void actionPerformed(ActionEvent e)
315 savePDB_actionPerformed(e);
318 jMenuBar1.add(fileMenu);
319 jMenuBar1.add(coloursMenu);
320 jMenuBar1.add(viewMenu);
321 fileMenu.add(saveMenu);
322 fileMenu.add(mapping);
323 saveMenu.add(savePDB);
326 coloursMenu.add(seqButton);
327 coloursMenu.add(chain);
328 coloursMenu.add(charge);
329 coloursMenu.add(zappo);
330 coloursMenu.add(taylor);
331 coloursMenu.add(hydro);
332 coloursMenu.add(helix);
333 coloursMenu.add(strand);
334 coloursMenu.add(turn);
335 coloursMenu.add(buried);
336 coloursMenu.add(user);
337 coloursMenu.add(background);
338 ButtonGroup bg = new ButtonGroup();
351 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
353 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
354 .getUserColourSchemes().keys();
356 while (userColours.hasMoreElements())
358 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
359 userColours.nextElement().toString());
360 radioItem.setName("USER_DEFINED");
361 radioItem.addMouseListener(new MouseAdapter()
363 public void mousePressed(MouseEvent evt)
365 if (evt.isControlDown()
366 || SwingUtilities.isRightMouseButton(evt))
368 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
370 int option = JOptionPane.showInternalConfirmDialog(
371 jalview.gui.Desktop.desktop,
372 "Remove from default list?",
373 "Remove user defined colour",
374 JOptionPane.YES_NO_OPTION);
375 if (option == JOptionPane.YES_OPTION)
377 jalview.gui.UserDefinedColours
378 .removeColourFromDefaults(radioItem.getText());
379 coloursMenu.remove(radioItem);
383 radioItem.addActionListener(new ActionListener()
385 public void actionPerformed(ActionEvent evt)
387 user_actionPerformed(evt);
394 radioItem.addActionListener(new ActionListener()
396 public void actionPerformed(ActionEvent evt)
398 user_actionPerformed(evt);
401 coloursMenu.add(radioItem);
408 viewMenu.add(zbuffer);
409 viewMenu.add(allchains);
412 JMenuBar jMenuBar1 = new JMenuBar();
414 JMenu fileMenu = new JMenu();
416 JMenu coloursMenu = new JMenu();
418 JMenu saveMenu = new JMenu();
420 JMenuItem png = new JMenuItem();
422 JMenuItem eps = new JMenuItem();
424 JMenuItem mapping = new JMenuItem();
426 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
428 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
430 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
432 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
434 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
436 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
438 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
440 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
442 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
444 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
446 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
448 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
450 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
452 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
454 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
456 JMenu viewMenu = new JMenu();
458 JMenuItem background = new JMenuItem();
460 JMenuItem savePDB = new JMenuItem();
468 public void eps_actionPerformed(ActionEvent e)
470 makePDBImage(jalview.util.ImageMaker.EPS);
479 public void png_actionPerformed(ActionEvent e)
481 makePDBImage(jalview.util.ImageMaker.PNG);
484 void makePDBImage(int type)
486 int width = pdbcanvas.getWidth();
487 int height = pdbcanvas.getHeight();
489 jalview.util.ImageMaker im;
491 if (type == jalview.util.ImageMaker.PNG)
493 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
494 "Make PNG image from view", width, height, null, null);
498 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
499 "Make EPS file from view", width, height, null,
503 if (im.getGraphics() != null)
505 pdbcanvas.drawAll(im.getGraphics(), width, height);
510 public void charge_actionPerformed(ActionEvent e)
512 pdbcanvas.bysequence = false;
513 pdbcanvas.pdb.setChargeColours();
514 pdbcanvas.redrawneeded = true;
518 public void hydro_actionPerformed(ActionEvent e)
520 pdbcanvas.bysequence = false;
521 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
522 pdbcanvas.redrawneeded = true;
526 public void chain_actionPerformed(ActionEvent e)
528 pdbcanvas.bysequence = false;
529 pdbcanvas.pdb.setChainColours();
530 pdbcanvas.redrawneeded = true;
534 public void zbuffer_actionPerformed(ActionEvent e)
536 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
537 pdbcanvas.redrawneeded = true;
541 public void molecule_actionPerformed(ActionEvent e)
543 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
544 pdbcanvas.redrawneeded = true;
548 public void depth_actionPerformed(ActionEvent e)
550 pdbcanvas.depthcue = !pdbcanvas.depthcue;
551 pdbcanvas.redrawneeded = true;
555 public void wire_actionPerformed(ActionEvent e)
557 pdbcanvas.wire = !pdbcanvas.wire;
558 pdbcanvas.redrawneeded = true;
562 public void seqButton_actionPerformed(ActionEvent e)
564 pdbcanvas.bysequence = true;
565 pdbcanvas.updateSeqColours();
568 public void mapping_actionPerformed(ActionEvent e)
570 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
573 cap.setText(pdbcanvas.mappingDetails.toString());
574 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
575 } catch (OutOfMemoryError oom)
577 new OOMWarning("Opening sequence to structure mapping report", oom);
582 public void allchains_itemStateChanged(ItemEvent e)
584 pdbcanvas.setAllchainsVisible(allchains.getState());
587 public void zappo_actionPerformed(ActionEvent e)
589 pdbcanvas.bysequence = false;
590 pdbcanvas.pdb.setColours(new ZappoColourScheme());
591 pdbcanvas.redrawneeded = true;
595 public void taylor_actionPerformed(ActionEvent e)
597 pdbcanvas.bysequence = false;
598 pdbcanvas.pdb.setColours(new TaylorColourScheme());
599 pdbcanvas.redrawneeded = true;
603 public void helix_actionPerformed(ActionEvent e)
605 pdbcanvas.bysequence = false;
606 pdbcanvas.pdb.setColours(new HelixColourScheme());
607 pdbcanvas.redrawneeded = true;
611 public void strand_actionPerformed(ActionEvent e)
613 pdbcanvas.bysequence = false;
614 pdbcanvas.pdb.setColours(new StrandColourScheme());
615 pdbcanvas.redrawneeded = true;
619 public void turn_actionPerformed(ActionEvent e)
621 pdbcanvas.bysequence = false;
622 pdbcanvas.pdb.setColours(new TurnColourScheme());
623 pdbcanvas.redrawneeded = true;
627 public void buried_actionPerformed(ActionEvent e)
629 pdbcanvas.bysequence = false;
630 pdbcanvas.pdb.setColours(new BuriedColourScheme());
631 pdbcanvas.redrawneeded = true;
635 public void user_actionPerformed(ActionEvent e)
637 if (e.getActionCommand().equals("User Defined..."))
639 // new UserDefinedColours(pdbcanvas, null);
643 UserColourScheme udc = (UserColourScheme) UserDefinedColours
644 .getUserColourSchemes().get(e.getActionCommand());
646 pdbcanvas.pdb.setColours(udc);
647 pdbcanvas.redrawneeded = true;
652 public void background_actionPerformed(ActionEvent e)
654 java.awt.Color col = JColorChooser.showDialog(this,
655 "Select Background Colour", pdbcanvas.backgroundColour);
659 pdbcanvas.backgroundColour = col;
660 pdbcanvas.redrawneeded = true;
665 public void savePDB_actionPerformed(ActionEvent e)
667 JalviewFileChooser chooser = new JalviewFileChooser(
668 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
670 chooser.setFileView(new JalviewFileView());
671 chooser.setDialogTitle("Save PDB File");
672 chooser.setToolTipText("Save");
674 int value = chooser.showSaveDialog(this);
676 if (value == JalviewFileChooser.APPROVE_OPTION)
680 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
681 File outFile = chooser.getSelectedFile();
683 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
685 while ((data = in.readLine()) != null)
687 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
694 } catch (Exception ex)
696 ex.printStackTrace();