2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.datamodel.PDBEntry;
24 import jalview.datamodel.SequenceI;
25 import jalview.gui.AlignmentPanel;
26 import jalview.gui.Desktop;
27 import jalview.gui.OOMWarning;
28 import jalview.gui.UserDefinedColours;
29 import jalview.io.JalviewFileChooser;
30 import jalview.io.JalviewFileView;
31 import jalview.schemes.BuriedColourScheme;
32 import jalview.schemes.HelixColourScheme;
33 import jalview.schemes.HydrophobicColourScheme;
34 import jalview.schemes.StrandColourScheme;
35 import jalview.schemes.TaylorColourScheme;
36 import jalview.schemes.TurnColourScheme;
37 import jalview.schemes.UserColourScheme;
38 import jalview.schemes.ZappoColourScheme;
39 import jalview.util.MessageManager;
40 import jalview.ws.ebi.EBIFetchClient;
42 import java.awt.event.ActionEvent;
43 import java.awt.event.ActionListener;
44 import java.awt.event.ItemEvent;
45 import java.awt.event.ItemListener;
46 import java.awt.event.KeyAdapter;
47 import java.awt.event.KeyEvent;
48 import java.awt.event.MouseAdapter;
49 import java.awt.event.MouseEvent;
50 import java.io.BufferedReader;
52 import java.io.FileOutputStream;
53 import java.io.FileReader;
54 import java.io.PrintWriter;
56 import javax.swing.ButtonGroup;
57 import javax.swing.JCheckBoxMenuItem;
58 import javax.swing.JColorChooser;
59 import javax.swing.JInternalFrame;
60 import javax.swing.JMenu;
61 import javax.swing.JMenuBar;
62 import javax.swing.JMenuItem;
63 import javax.swing.JOptionPane;
64 import javax.swing.JRadioButtonMenuItem;
66 public class PDBViewer extends JInternalFrame implements Runnable
70 * The associated sequence in an alignment
86 public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
87 AlignmentPanel ap, String protocol)
89 this.pdbentry = pdbentry;
93 this.protocol = protocol;
98 } catch (Exception ex)
100 ex.printStackTrace();
103 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
104 + pdbentry.getFile());
106 pdbcanvas = new PDBCanvas();
108 setContentPane(pdbcanvas);
110 if (pdbentry.getFile() != null)
114 tmpPDBFile = pdbentry.getFile();
115 PDBfile pdbfile = new PDBfile(false, false, false, tmpPDBFile,
116 jalview.io.AppletFormatAdapter.FILE);
118 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
120 } catch (java.io.IOException ex)
122 ex.printStackTrace();
127 Thread worker = new Thread(this);
131 String method = (String) pdbentry.getProperty("method");
134 title.append(" Method: ");
135 title.append(method);
137 String ch = (String) pdbentry.getProperty("chains");
140 title.append(" Chain:");
143 Desktop.addInternalFrame(this, title.toString(), 400, 400);
151 EBIFetchClient ebi = new EBIFetchClient();
152 String query = "pdb:" + pdbentry.getId();
153 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", ".xml")
156 if (pdbentry.getFile() != null)
158 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
160 } catch (Exception ex)
162 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
163 ex.printStackTrace();
167 private void jbInit() throws Exception
169 this.addKeyListener(new KeyAdapter()
172 public void keyPressed(KeyEvent evt)
174 pdbcanvas.keyPressed(evt);
178 this.setJMenuBar(jMenuBar1);
179 fileMenu.setText(MessageManager.getString("action.file"));
180 coloursMenu.setText(MessageManager.getString("label.colours"));
181 saveMenu.setActionCommand(MessageManager.getString("action.save_image"));
182 saveMenu.setText(MessageManager.getString("action.save_as"));
184 png.addActionListener(new ActionListener()
187 public void actionPerformed(ActionEvent e)
189 png_actionPerformed(e);
193 eps.addActionListener(new ActionListener()
196 public void actionPerformed(ActionEvent e)
198 eps_actionPerformed(e);
201 mapping.setText(MessageManager.getString("label.view_mapping"));
202 mapping.addActionListener(new ActionListener()
205 public void actionPerformed(ActionEvent e)
207 mapping_actionPerformed(e);
210 wire.setText(MessageManager.getString("label.wireframe"));
211 wire.addActionListener(new ActionListener()
214 public void actionPerformed(ActionEvent e)
216 wire_actionPerformed(e);
219 depth.setSelected(true);
220 depth.setText(MessageManager.getString("label.depthcue"));
221 depth.addActionListener(new ActionListener()
224 public void actionPerformed(ActionEvent e)
226 depth_actionPerformed(e);
229 zbuffer.setSelected(true);
230 zbuffer.setText(MessageManager.getString("label.z_buffering"));
231 zbuffer.addActionListener(new ActionListener()
234 public void actionPerformed(ActionEvent e)
236 zbuffer_actionPerformed(e);
239 charge.setText(MessageManager.getString("label.charge_cysteine"));
240 charge.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
245 charge_actionPerformed(e);
248 chain.setText(MessageManager.getString("action.by_chain"));
249 chain.addActionListener(new ActionListener()
252 public void actionPerformed(ActionEvent e)
254 chain_actionPerformed(e);
257 seqButton.setSelected(true);
258 seqButton.setText(MessageManager.getString("action.by_sequence"));
259 seqButton.addActionListener(new ActionListener()
262 public void actionPerformed(ActionEvent e)
264 seqButton_actionPerformed(e);
267 allchains.setSelected(true);
268 allchains.setText(MessageManager.getString("label.show_all_chains"));
269 allchains.addItemListener(new ItemListener()
272 public void itemStateChanged(ItemEvent e)
274 allchains_itemStateChanged(e);
277 zappo.setText(MessageManager.getString("label.zappo"));
278 zappo.addActionListener(new ActionListener()
281 public void actionPerformed(ActionEvent e)
283 zappo_actionPerformed(e);
286 taylor.setText(MessageManager.getString("label.taylor"));
287 taylor.addActionListener(new ActionListener()
290 public void actionPerformed(ActionEvent e)
292 taylor_actionPerformed(e);
295 hydro.setText(MessageManager.getString("label.hydrophobicity"));
296 hydro.addActionListener(new ActionListener()
299 public void actionPerformed(ActionEvent e)
301 hydro_actionPerformed(e);
304 helix.setText(MessageManager.getString("label.helix_propensity"));
305 helix.addActionListener(new ActionListener()
308 public void actionPerformed(ActionEvent e)
310 helix_actionPerformed(e);
313 strand.setText(MessageManager.getString("label.strand_propensity"));
314 strand.addActionListener(new ActionListener()
317 public void actionPerformed(ActionEvent e)
319 strand_actionPerformed(e);
322 turn.setText(MessageManager.getString("label.turn_propensity"));
323 turn.addActionListener(new ActionListener()
326 public void actionPerformed(ActionEvent e)
328 turn_actionPerformed(e);
331 buried.setText(MessageManager.getString("label.buried_index"));
332 buried.addActionListener(new ActionListener()
335 public void actionPerformed(ActionEvent e)
337 buried_actionPerformed(e);
340 user.setText(MessageManager.getString("action.user_defined"));
341 user.addActionListener(new ActionListener()
344 public void actionPerformed(ActionEvent e)
346 user_actionPerformed(e);
349 viewMenu.setText(MessageManager.getString("action.view"));
351 .setText(MessageManager.getString("action.background_colour"));
352 background.addActionListener(new ActionListener()
355 public void actionPerformed(ActionEvent e)
357 background_actionPerformed(e);
360 savePDB.setText(MessageManager.getString("label.pdb_file"));
361 savePDB.addActionListener(new ActionListener()
364 public void actionPerformed(ActionEvent e)
366 savePDB_actionPerformed(e);
369 jMenuBar1.add(fileMenu);
370 jMenuBar1.add(coloursMenu);
371 jMenuBar1.add(viewMenu);
372 fileMenu.add(saveMenu);
373 fileMenu.add(mapping);
374 saveMenu.add(savePDB);
377 coloursMenu.add(seqButton);
378 coloursMenu.add(chain);
379 coloursMenu.add(charge);
380 coloursMenu.add(zappo);
381 coloursMenu.add(taylor);
382 coloursMenu.add(hydro);
383 coloursMenu.add(helix);
384 coloursMenu.add(strand);
385 coloursMenu.add(turn);
386 coloursMenu.add(buried);
387 coloursMenu.add(user);
388 coloursMenu.add(background);
389 ButtonGroup bg = new ButtonGroup();
402 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
404 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
405 .getUserColourSchemes().keys();
407 while (userColours.hasMoreElements())
409 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
410 userColours.nextElement().toString());
411 radioItem.setName("USER_DEFINED");
412 radioItem.addMouseListener(new MouseAdapter()
415 public void mousePressed(MouseEvent evt)
417 if (evt.isPopupTrigger()) // Mac
419 offerRemoval(radioItem);
424 public void mouseReleased(MouseEvent evt)
426 if (evt.isPopupTrigger()) // Windows
428 offerRemoval(radioItem);
435 void offerRemoval(final JRadioButtonMenuItem radioItem)
437 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
439 int option = JOptionPane.showInternalConfirmDialog(
440 jalview.gui.Desktop.desktop, MessageManager
441 .getString("label.remove_from_default_list"),
443 .getString("label.remove_user_defined_colour"),
444 JOptionPane.YES_NO_OPTION);
445 if (option == JOptionPane.YES_OPTION)
447 jalview.gui.UserDefinedColours
448 .removeColourFromDefaults(radioItem.getText());
449 coloursMenu.remove(radioItem);
453 radioItem.addActionListener(new ActionListener()
456 public void actionPerformed(ActionEvent evt)
458 user_actionPerformed(evt);
464 radioItem.addActionListener(new ActionListener()
467 public void actionPerformed(ActionEvent evt)
469 user_actionPerformed(evt);
472 coloursMenu.add(radioItem);
479 viewMenu.add(zbuffer);
480 viewMenu.add(allchains);
483 JMenuBar jMenuBar1 = new JMenuBar();
485 JMenu fileMenu = new JMenu();
487 JMenu coloursMenu = new JMenu();
489 JMenu saveMenu = new JMenu();
491 JMenuItem png = new JMenuItem();
493 JMenuItem eps = new JMenuItem();
495 JMenuItem mapping = new JMenuItem();
497 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
499 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
501 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
503 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
505 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
507 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
509 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
511 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
513 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
515 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
517 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
519 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
521 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
523 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
525 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
527 JMenu viewMenu = new JMenu();
529 JMenuItem background = new JMenuItem();
531 JMenuItem savePDB = new JMenuItem();
539 public void eps_actionPerformed(ActionEvent e)
541 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
550 public void png_actionPerformed(ActionEvent e)
552 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
555 void makePDBImage(jalview.util.ImageMaker.TYPE type)
557 int width = pdbcanvas.getWidth();
558 int height = pdbcanvas.getHeight();
560 jalview.util.ImageMaker im;
562 if (type == jalview.util.ImageMaker.TYPE.PNG)
564 im = new jalview.util.ImageMaker(this,
565 jalview.util.ImageMaker.TYPE.PNG, "Make PNG image from view",
566 width, height, null, null, null, 0, false);
568 else if (type == jalview.util.ImageMaker.TYPE.EPS)
570 im = new jalview.util.ImageMaker(this,
571 jalview.util.ImageMaker.TYPE.EPS, "Make EPS file from view",
572 width, height, null, this.getTitle(), null, 0, false);
577 im = new jalview.util.ImageMaker(this,
578 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
579 width, height, null, this.getTitle(), null, 0, false);
582 if (im.getGraphics() != null)
584 pdbcanvas.drawAll(im.getGraphics(), width, height);
589 public void charge_actionPerformed(ActionEvent e)
591 pdbcanvas.bysequence = false;
592 pdbcanvas.pdb.setChargeColours();
593 pdbcanvas.redrawneeded = true;
597 public void hydro_actionPerformed(ActionEvent e)
599 pdbcanvas.bysequence = false;
600 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
601 pdbcanvas.redrawneeded = true;
605 public void chain_actionPerformed(ActionEvent e)
607 pdbcanvas.bysequence = false;
608 pdbcanvas.pdb.setChainColours();
609 pdbcanvas.redrawneeded = true;
613 public void zbuffer_actionPerformed(ActionEvent e)
615 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
616 pdbcanvas.redrawneeded = true;
620 public void molecule_actionPerformed(ActionEvent e)
622 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
623 pdbcanvas.redrawneeded = true;
627 public void depth_actionPerformed(ActionEvent e)
629 pdbcanvas.depthcue = !pdbcanvas.depthcue;
630 pdbcanvas.redrawneeded = true;
634 public void wire_actionPerformed(ActionEvent e)
636 pdbcanvas.wire = !pdbcanvas.wire;
637 pdbcanvas.redrawneeded = true;
641 public void seqButton_actionPerformed(ActionEvent e)
643 pdbcanvas.bysequence = true;
644 pdbcanvas.updateSeqColours();
647 public void mapping_actionPerformed(ActionEvent e)
649 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
652 cap.setText(pdbcanvas.mappingDetails.toString());
653 Desktop.addInternalFrame(cap,
654 MessageManager.getString("label.pdb_sequence_mapping"), 550,
656 } catch (OutOfMemoryError oom)
658 new OOMWarning("Opening sequence to structure mapping report", oom);
663 public void allchains_itemStateChanged(ItemEvent e)
665 pdbcanvas.setAllchainsVisible(allchains.getState());
668 public void zappo_actionPerformed(ActionEvent e)
670 pdbcanvas.bysequence = false;
671 pdbcanvas.pdb.setColours(new ZappoColourScheme());
672 pdbcanvas.redrawneeded = true;
676 public void taylor_actionPerformed(ActionEvent e)
678 pdbcanvas.bysequence = false;
679 pdbcanvas.pdb.setColours(new TaylorColourScheme());
680 pdbcanvas.redrawneeded = true;
684 public void helix_actionPerformed(ActionEvent e)
686 pdbcanvas.bysequence = false;
687 pdbcanvas.pdb.setColours(new HelixColourScheme());
688 pdbcanvas.redrawneeded = true;
692 public void strand_actionPerformed(ActionEvent e)
694 pdbcanvas.bysequence = false;
695 pdbcanvas.pdb.setColours(new StrandColourScheme());
696 pdbcanvas.redrawneeded = true;
700 public void turn_actionPerformed(ActionEvent e)
702 pdbcanvas.bysequence = false;
703 pdbcanvas.pdb.setColours(new TurnColourScheme());
704 pdbcanvas.redrawneeded = true;
708 public void buried_actionPerformed(ActionEvent e)
710 pdbcanvas.bysequence = false;
711 pdbcanvas.pdb.setColours(new BuriedColourScheme());
712 pdbcanvas.redrawneeded = true;
716 public void user_actionPerformed(ActionEvent e)
718 if (e.getActionCommand().equals(
719 MessageManager.getString("action.user_defined")))
721 // new UserDefinedColours(pdbcanvas, null);
725 UserColourScheme udc = (UserColourScheme) UserDefinedColours
726 .getUserColourSchemes().get(e.getActionCommand());
728 pdbcanvas.pdb.setColours(udc);
729 pdbcanvas.redrawneeded = true;
734 public void background_actionPerformed(ActionEvent e)
736 java.awt.Color col = JColorChooser.showDialog(this,
737 MessageManager.getString("label.select_backgroud_colour"),
738 pdbcanvas.backgroundColour);
742 pdbcanvas.backgroundColour = col;
743 pdbcanvas.redrawneeded = true;
748 public void savePDB_actionPerformed(ActionEvent e)
750 JalviewFileChooser chooser = new JalviewFileChooser(
751 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
753 chooser.setFileView(new JalviewFileView());
754 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
755 chooser.setToolTipText(MessageManager.getString("action.save"));
757 int value = chooser.showSaveDialog(this);
759 if (value == JalviewFileChooser.APPROVE_OPTION)
763 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
764 File outFile = chooser.getSelectedFile();
766 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
768 while ((data = in.readLine()) != null)
770 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
777 } catch (Exception ex)
779 ex.printStackTrace();