2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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;
65 import javax.swing.SwingUtilities;
67 public class PDBViewer extends JInternalFrame implements Runnable
71 * The associated sequence in an alignment
87 public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
88 AlignmentPanel ap, String protocol)
90 this.pdbentry = pdbentry;
94 this.protocol = protocol;
99 } catch (Exception ex)
101 ex.printStackTrace();
104 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
105 + pdbentry.getFile());
107 pdbcanvas = new PDBCanvas();
109 setContentPane(pdbcanvas);
111 if (pdbentry.getFile() != null)
115 tmpPDBFile = pdbentry.getFile();
116 PDBfile pdbfile = new PDBfile(false, false, false, tmpPDBFile,
117 jalview.io.AppletFormatAdapter.FILE);
119 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
121 } catch (java.io.IOException ex)
123 ex.printStackTrace();
128 Thread worker = new Thread(this);
132 if (pdbentry.getProperty() != null)
134 if (pdbentry.getProperty().get("method") != null)
136 title.append(" Method: ");
137 title.append(pdbentry.getProperty().get("method"));
139 if (pdbentry.getProperty().get("chains") != null)
141 title.append(" Chain:");
142 title.append(pdbentry.getProperty().get("chains"));
145 Desktop.addInternalFrame(this, title.toString(), 400, 400);
152 EBIFetchClient ebi = new EBIFetchClient();
153 String query = "pdb:" + pdbentry.getId();
154 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
157 if (pdbentry.getFile() != null)
159 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
161 } catch (Exception ex)
163 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
164 ex.printStackTrace();
168 private void jbInit() throws Exception
170 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()
186 public void actionPerformed(ActionEvent e)
188 png_actionPerformed(e);
192 eps.addActionListener(new ActionListener()
194 public void actionPerformed(ActionEvent e)
196 eps_actionPerformed(e);
199 mapping.setText(MessageManager.getString("label.view_mapping"));
200 mapping.addActionListener(new ActionListener()
202 public void actionPerformed(ActionEvent e)
204 mapping_actionPerformed(e);
207 wire.setText(MessageManager.getString("label.wireframe"));
208 wire.addActionListener(new ActionListener()
210 public void actionPerformed(ActionEvent e)
212 wire_actionPerformed(e);
215 depth.setSelected(true);
216 depth.setText(MessageManager.getString("label.depthcue"));
217 depth.addActionListener(new ActionListener()
219 public void actionPerformed(ActionEvent e)
221 depth_actionPerformed(e);
224 zbuffer.setSelected(true);
225 zbuffer.setText(MessageManager.getString("label.z_buffering"));
226 zbuffer.addActionListener(new ActionListener()
228 public void actionPerformed(ActionEvent e)
230 zbuffer_actionPerformed(e);
233 charge.setText(MessageManager.getString("label.charge_cysteine"));
234 charge.addActionListener(new ActionListener()
236 public void actionPerformed(ActionEvent e)
238 charge_actionPerformed(e);
241 chain.setText(MessageManager.getString("action.by_chain"));
242 chain.addActionListener(new ActionListener()
244 public void actionPerformed(ActionEvent e)
246 chain_actionPerformed(e);
249 seqButton.setSelected(true);
250 seqButton.setText(MessageManager.getString("action.by_sequence"));
251 seqButton.addActionListener(new ActionListener()
253 public void actionPerformed(ActionEvent e)
255 seqButton_actionPerformed(e);
258 allchains.setSelected(true);
259 allchains.setText(MessageManager.getString("label.show_all_chains"));
260 allchains.addItemListener(new ItemListener()
262 public void itemStateChanged(ItemEvent e)
264 allchains_itemStateChanged(e);
267 zappo.setText(MessageManager.getString("label.zappo"));
268 zappo.addActionListener(new ActionListener()
270 public void actionPerformed(ActionEvent e)
272 zappo_actionPerformed(e);
275 taylor.setText(MessageManager.getString("label.taylor"));
276 taylor.addActionListener(new ActionListener()
278 public void actionPerformed(ActionEvent e)
280 taylor_actionPerformed(e);
283 hydro.setText(MessageManager.getString("label.hydrophobicity"));
284 hydro.addActionListener(new ActionListener()
286 public void actionPerformed(ActionEvent e)
288 hydro_actionPerformed(e);
291 helix.setText(MessageManager.getString("label.helix_propensity"));
292 helix.addActionListener(new ActionListener()
294 public void actionPerformed(ActionEvent e)
296 helix_actionPerformed(e);
299 strand.setText(MessageManager.getString("label.strand_propensity"));
300 strand.addActionListener(new ActionListener()
302 public void actionPerformed(ActionEvent e)
304 strand_actionPerformed(e);
307 turn.setText(MessageManager.getString("label.turn_propensity"));
308 turn.addActionListener(new ActionListener()
310 public void actionPerformed(ActionEvent e)
312 turn_actionPerformed(e);
315 buried.setText(MessageManager.getString("label.buried_index"));
316 buried.addActionListener(new ActionListener()
318 public void actionPerformed(ActionEvent e)
320 buried_actionPerformed(e);
323 user.setText(MessageManager.getString("action.user_defined"));
324 user.addActionListener(new ActionListener()
326 public void actionPerformed(ActionEvent e)
328 user_actionPerformed(e);
331 viewMenu.setText(MessageManager.getString("action.view"));
332 background.setText(MessageManager.getString("label.background_colour")
334 background.addActionListener(new ActionListener()
336 public void actionPerformed(ActionEvent e)
338 background_actionPerformed(e);
341 savePDB.setText(MessageManager.getString("label.pdb_file"));
342 savePDB.addActionListener(new ActionListener()
344 public void actionPerformed(ActionEvent e)
346 savePDB_actionPerformed(e);
349 jMenuBar1.add(fileMenu);
350 jMenuBar1.add(coloursMenu);
351 jMenuBar1.add(viewMenu);
352 fileMenu.add(saveMenu);
353 fileMenu.add(mapping);
354 saveMenu.add(savePDB);
357 coloursMenu.add(seqButton);
358 coloursMenu.add(chain);
359 coloursMenu.add(charge);
360 coloursMenu.add(zappo);
361 coloursMenu.add(taylor);
362 coloursMenu.add(hydro);
363 coloursMenu.add(helix);
364 coloursMenu.add(strand);
365 coloursMenu.add(turn);
366 coloursMenu.add(buried);
367 coloursMenu.add(user);
368 coloursMenu.add(background);
369 ButtonGroup bg = new ButtonGroup();
382 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
384 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
385 .getUserColourSchemes().keys();
387 while (userColours.hasMoreElements())
389 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
390 userColours.nextElement().toString());
391 radioItem.setName("USER_DEFINED");
392 radioItem.addMouseListener(new MouseAdapter()
394 public void mousePressed(MouseEvent evt)
396 if (evt.isControlDown()
397 || SwingUtilities.isRightMouseButton(evt))
399 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
401 int option = JOptionPane.showInternalConfirmDialog(
402 jalview.gui.Desktop.desktop,
404 .getString("label.remove_from_default_list"),
406 .getString("label.remove_user_defined_colour"),
407 JOptionPane.YES_NO_OPTION);
408 if (option == JOptionPane.YES_OPTION)
410 jalview.gui.UserDefinedColours
411 .removeColourFromDefaults(radioItem.getText());
412 coloursMenu.remove(radioItem);
416 radioItem.addActionListener(new ActionListener()
418 public void actionPerformed(ActionEvent evt)
420 user_actionPerformed(evt);
427 radioItem.addActionListener(new ActionListener()
429 public void actionPerformed(ActionEvent evt)
431 user_actionPerformed(evt);
434 coloursMenu.add(radioItem);
441 viewMenu.add(zbuffer);
442 viewMenu.add(allchains);
445 JMenuBar jMenuBar1 = new JMenuBar();
447 JMenu fileMenu = new JMenu();
449 JMenu coloursMenu = new JMenu();
451 JMenu saveMenu = new JMenu();
453 JMenuItem png = new JMenuItem();
455 JMenuItem eps = new JMenuItem();
457 JMenuItem mapping = new JMenuItem();
459 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
461 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
463 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
465 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
467 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
469 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
471 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
473 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
475 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
477 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
479 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
481 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
483 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
485 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
487 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
489 JMenu viewMenu = new JMenu();
491 JMenuItem background = new JMenuItem();
493 JMenuItem savePDB = new JMenuItem();
501 public void eps_actionPerformed(ActionEvent e)
503 makePDBImage(jalview.util.ImageMaker.TYPE.EPS);
512 public void png_actionPerformed(ActionEvent e)
514 makePDBImage(jalview.util.ImageMaker.TYPE.PNG);
517 void makePDBImage(jalview.util.ImageMaker.TYPE type)
519 int width = pdbcanvas.getWidth();
520 int height = pdbcanvas.getHeight();
522 jalview.util.ImageMaker im;
524 if (type == jalview.util.ImageMaker.TYPE.PNG)
526 im = new jalview.util.ImageMaker(this,
527 jalview.util.ImageMaker.TYPE.PNG,
528 "Make PNG image from view", width, height, null, null);
530 else if (type == jalview.util.ImageMaker.TYPE.EPS)
532 im = new jalview.util.ImageMaker(this,
533 jalview.util.ImageMaker.TYPE.EPS,
534 "Make EPS file from view", width, height, null,
540 im = new jalview.util.ImageMaker(this,
541 jalview.util.ImageMaker.TYPE.SVG, "Make SVG file from PCA",
542 width, height, null, this.getTitle());
545 if (im.getGraphics() != null)
547 pdbcanvas.drawAll(im.getGraphics(), width, height);
552 public void charge_actionPerformed(ActionEvent e)
554 pdbcanvas.bysequence = false;
555 pdbcanvas.pdb.setChargeColours();
556 pdbcanvas.redrawneeded = true;
560 public void hydro_actionPerformed(ActionEvent e)
562 pdbcanvas.bysequence = false;
563 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
564 pdbcanvas.redrawneeded = true;
568 public void chain_actionPerformed(ActionEvent e)
570 pdbcanvas.bysequence = false;
571 pdbcanvas.pdb.setChainColours();
572 pdbcanvas.redrawneeded = true;
576 public void zbuffer_actionPerformed(ActionEvent e)
578 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
579 pdbcanvas.redrawneeded = true;
583 public void molecule_actionPerformed(ActionEvent e)
585 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
586 pdbcanvas.redrawneeded = true;
590 public void depth_actionPerformed(ActionEvent e)
592 pdbcanvas.depthcue = !pdbcanvas.depthcue;
593 pdbcanvas.redrawneeded = true;
597 public void wire_actionPerformed(ActionEvent e)
599 pdbcanvas.wire = !pdbcanvas.wire;
600 pdbcanvas.redrawneeded = true;
604 public void seqButton_actionPerformed(ActionEvent e)
606 pdbcanvas.bysequence = true;
607 pdbcanvas.updateSeqColours();
610 public void mapping_actionPerformed(ActionEvent e)
612 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
615 cap.setText(pdbcanvas.mappingDetails.toString());
616 Desktop.addInternalFrame(cap,
617 MessageManager.getString("label.pdb_sequence_mapping"), 550,
619 } catch (OutOfMemoryError oom)
621 new OOMWarning("Opening sequence to structure mapping report", oom);
626 public void allchains_itemStateChanged(ItemEvent e)
628 pdbcanvas.setAllchainsVisible(allchains.getState());
631 public void zappo_actionPerformed(ActionEvent e)
633 pdbcanvas.bysequence = false;
634 pdbcanvas.pdb.setColours(new ZappoColourScheme());
635 pdbcanvas.redrawneeded = true;
639 public void taylor_actionPerformed(ActionEvent e)
641 pdbcanvas.bysequence = false;
642 pdbcanvas.pdb.setColours(new TaylorColourScheme());
643 pdbcanvas.redrawneeded = true;
647 public void helix_actionPerformed(ActionEvent e)
649 pdbcanvas.bysequence = false;
650 pdbcanvas.pdb.setColours(new HelixColourScheme());
651 pdbcanvas.redrawneeded = true;
655 public void strand_actionPerformed(ActionEvent e)
657 pdbcanvas.bysequence = false;
658 pdbcanvas.pdb.setColours(new StrandColourScheme());
659 pdbcanvas.redrawneeded = true;
663 public void turn_actionPerformed(ActionEvent e)
665 pdbcanvas.bysequence = false;
666 pdbcanvas.pdb.setColours(new TurnColourScheme());
667 pdbcanvas.redrawneeded = true;
671 public void buried_actionPerformed(ActionEvent e)
673 pdbcanvas.bysequence = false;
674 pdbcanvas.pdb.setColours(new BuriedColourScheme());
675 pdbcanvas.redrawneeded = true;
679 public void user_actionPerformed(ActionEvent e)
681 if (e.getActionCommand().equals(
682 MessageManager.getString("action.user_defined")))
684 // new UserDefinedColours(pdbcanvas, null);
688 UserColourScheme udc = (UserColourScheme) UserDefinedColours
689 .getUserColourSchemes().get(e.getActionCommand());
691 pdbcanvas.pdb.setColours(udc);
692 pdbcanvas.redrawneeded = true;
697 public void background_actionPerformed(ActionEvent e)
699 java.awt.Color col = JColorChooser.showDialog(this,
700 MessageManager.getString("label.select_backgroud_colour"),
701 pdbcanvas.backgroundColour);
705 pdbcanvas.backgroundColour = col;
706 pdbcanvas.redrawneeded = true;
711 public void savePDB_actionPerformed(ActionEvent e)
713 JalviewFileChooser chooser = new JalviewFileChooser(
714 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
716 chooser.setFileView(new JalviewFileView());
717 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
718 chooser.setToolTipText(MessageManager.getString("action.save"));
720 int value = chooser.showSaveDialog(this);
722 if (value == JalviewFileChooser.APPROVE_OPTION)
726 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
727 File outFile = chooser.getSelectedFile();
729 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
731 while ((data = in.readLine()) != null)
733 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
740 } catch (Exception ex)
742 ex.printStackTrace();