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.bin.Cache;
24 import jalview.datamodel.PDBEntry;
25 import jalview.datamodel.SequenceI;
26 import jalview.gui.AlignmentPanel;
27 import jalview.gui.CutAndPasteTransfer;
28 import jalview.gui.Desktop;
29 import jalview.gui.OOMWarning;
30 import jalview.gui.UserDefinedColours;
31 import jalview.io.AppletFormatAdapter;
32 import jalview.io.JalviewFileChooser;
33 import jalview.io.JalviewFileView;
34 import jalview.schemes.BuriedColourScheme;
35 import jalview.schemes.HelixColourScheme;
36 import jalview.schemes.HydrophobicColourScheme;
37 import jalview.schemes.StrandColourScheme;
38 import jalview.schemes.TaylorColourScheme;
39 import jalview.schemes.TurnColourScheme;
40 import jalview.schemes.UserColourScheme;
41 import jalview.schemes.ZappoColourScheme;
42 import jalview.util.ImageMaker;
43 import jalview.util.MessageManager;
44 import jalview.ws.ebi.EBIFetchClient;
46 import java.awt.event.ActionEvent;
47 import java.awt.event.ActionListener;
48 import java.awt.event.ItemEvent;
49 import java.awt.event.ItemListener;
50 import java.awt.event.KeyAdapter;
51 import java.awt.event.KeyEvent;
52 import java.awt.event.MouseAdapter;
53 import java.awt.event.MouseEvent;
54 import java.io.BufferedReader;
56 import java.io.FileOutputStream;
57 import java.io.FileReader;
58 import java.io.PrintWriter;
59 import java.util.Enumeration;
61 import javax.swing.ButtonGroup;
62 import javax.swing.JCheckBoxMenuItem;
63 import javax.swing.JColorChooser;
64 import javax.swing.JInternalFrame;
65 import javax.swing.JMenu;
66 import javax.swing.JMenuBar;
67 import javax.swing.JMenuItem;
68 import javax.swing.JOptionPane;
69 import javax.swing.JRadioButtonMenuItem;
70 import javax.swing.SwingUtilities;
72 public class PDBViewer extends JInternalFrame implements Runnable
76 * The associated sequence in an alignment
92 public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
93 AlignmentPanel ap, String protocol)
95 this.pdbentry = pdbentry;
99 this.protocol = protocol;
104 } catch (Exception ex)
106 ex.printStackTrace();
109 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
110 + pdbentry.getFile());
112 pdbcanvas = new PDBCanvas();
114 setContentPane(pdbcanvas);
116 if (pdbentry.getFile() != null)
120 tmpPDBFile = pdbentry.getFile();
121 PDBfile pdbfile = new PDBfile(false, false, false, tmpPDBFile,
122 AppletFormatAdapter.FILE);
124 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
126 } catch (java.io.IOException ex)
128 ex.printStackTrace();
133 Thread worker = new Thread(this);
137 if (pdbentry.getProperty() != null)
139 if (pdbentry.getProperty().get("method") != null)
141 title.append(" Method: ");
142 title.append(pdbentry.getProperty().get("method"));
144 if (pdbentry.getProperty().get("chains") != null)
146 title.append(" Chain:");
147 title.append(pdbentry.getProperty().get("chains"));
150 Desktop.addInternalFrame(this, title.toString(), 400, 400);
157 EBIFetchClient ebi = new EBIFetchClient();
158 String query = "pdb:" + pdbentry.getId();
159 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
162 if (pdbentry.getFile() != null)
164 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
166 } catch (Exception ex)
168 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
169 ex.printStackTrace();
173 private void jbInit() throws Exception
175 this.addKeyListener(new KeyAdapter()
177 public void keyPressed(KeyEvent evt)
179 pdbcanvas.keyPressed(evt);
183 this.setJMenuBar(jMenuBar1);
184 fileMenu.setText(MessageManager.getString("action.file"));
185 coloursMenu.setText(MessageManager.getString("label.colours"));
186 saveMenu.setActionCommand(MessageManager.getString("action.save_image"));
187 saveMenu.setText(MessageManager.getString("action.save_as"));
189 png.addActionListener(new ActionListener()
191 public void actionPerformed(ActionEvent e)
193 png_actionPerformed(e);
197 eps.addActionListener(new ActionListener()
199 public void actionPerformed(ActionEvent e)
201 eps_actionPerformed(e);
204 mapping.setText(MessageManager.getString("label.view_mapping"));
205 mapping.addActionListener(new ActionListener()
207 public void actionPerformed(ActionEvent e)
209 mapping_actionPerformed(e);
212 wire.setText(MessageManager.getString("label.wireframe"));
213 wire.addActionListener(new ActionListener()
215 public void actionPerformed(ActionEvent e)
217 wire_actionPerformed(e);
220 depth.setSelected(true);
221 depth.setText(MessageManager.getString("label.depthcue"));
222 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()
233 public void actionPerformed(ActionEvent e)
235 zbuffer_actionPerformed(e);
238 charge.setText(MessageManager.getString("label.charge_cysteine"));
239 charge.addActionListener(new ActionListener()
241 public void actionPerformed(ActionEvent e)
243 charge_actionPerformed(e);
246 chain.setText(MessageManager.getString("action.by_chain"));
247 chain.addActionListener(new ActionListener()
249 public void actionPerformed(ActionEvent e)
251 chain_actionPerformed(e);
254 seqButton.setSelected(true);
255 seqButton.setText(MessageManager.getString("action.by_sequence"));
256 seqButton.addActionListener(new ActionListener()
258 public void actionPerformed(ActionEvent e)
260 seqButton_actionPerformed(e);
263 allchains.setSelected(true);
264 allchains.setText(MessageManager.getString("label.show_all_chains"));
265 allchains.addItemListener(new ItemListener()
267 public void itemStateChanged(ItemEvent e)
269 allchains_itemStateChanged(e);
272 zappo.setText(MessageManager.getString("label.zappo"));
273 zappo.addActionListener(new ActionListener()
275 public void actionPerformed(ActionEvent e)
277 zappo_actionPerformed(e);
280 taylor.setText(MessageManager.getString("label.taylor"));
281 taylor.addActionListener(new ActionListener()
283 public void actionPerformed(ActionEvent e)
285 taylor_actionPerformed(e);
288 hydro.setText(MessageManager.getString("label.hydrophobicity"));
289 hydro.addActionListener(new ActionListener()
291 public void actionPerformed(ActionEvent e)
293 hydro_actionPerformed(e);
296 helix.setText(MessageManager.getString("label.helix_propensity"));
297 helix.addActionListener(new ActionListener()
299 public void actionPerformed(ActionEvent e)
301 helix_actionPerformed(e);
304 strand.setText(MessageManager.getString("label.strand_propensity"));
305 strand.addActionListener(new ActionListener()
307 public void actionPerformed(ActionEvent e)
309 strand_actionPerformed(e);
312 turn.setText(MessageManager.getString("label.turn_propensity"));
313 turn.addActionListener(new ActionListener()
315 public void actionPerformed(ActionEvent e)
317 turn_actionPerformed(e);
320 buried.setText(MessageManager.getString("label.buried_index"));
321 buried.addActionListener(new ActionListener()
323 public void actionPerformed(ActionEvent e)
325 buried_actionPerformed(e);
328 user.setText(MessageManager.getString("action.user_defined"));
329 user.addActionListener(new ActionListener()
331 public void actionPerformed(ActionEvent e)
333 user_actionPerformed(e);
336 viewMenu.setText(MessageManager.getString("action.view"));
337 background.setText(MessageManager.getString("label.background_colour")
339 background.addActionListener(new ActionListener()
341 public void actionPerformed(ActionEvent e)
343 background_actionPerformed(e);
346 savePDB.setText(MessageManager.getString("label.pdb_file"));
347 savePDB.addActionListener(new ActionListener()
349 public void actionPerformed(ActionEvent e)
351 savePDB_actionPerformed(e);
354 jMenuBar1.add(fileMenu);
355 jMenuBar1.add(coloursMenu);
356 jMenuBar1.add(viewMenu);
357 fileMenu.add(saveMenu);
358 fileMenu.add(mapping);
359 saveMenu.add(savePDB);
362 coloursMenu.add(seqButton);
363 coloursMenu.add(chain);
364 coloursMenu.add(charge);
365 coloursMenu.add(zappo);
366 coloursMenu.add(taylor);
367 coloursMenu.add(hydro);
368 coloursMenu.add(helix);
369 coloursMenu.add(strand);
370 coloursMenu.add(turn);
371 coloursMenu.add(buried);
372 coloursMenu.add(user);
373 coloursMenu.add(background);
374 ButtonGroup bg = new ButtonGroup();
387 if (UserDefinedColours.getUserColourSchemes() != null)
389 Enumeration userColours = UserDefinedColours
390 .getUserColourSchemes().keys();
392 while (userColours.hasMoreElements())
394 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
395 userColours.nextElement().toString());
396 radioItem.setName("USER_DEFINED");
397 radioItem.addMouseListener(new MouseAdapter()
399 public void mousePressed(MouseEvent evt)
401 if (evt.isControlDown()
402 || SwingUtilities.isRightMouseButton(evt))
404 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
406 int option = JOptionPane.showInternalConfirmDialog(
409 .getString("label.remove_from_default_list"),
411 .getString("label.remove_user_defined_colour"),
412 JOptionPane.YES_NO_OPTION);
413 if (option == JOptionPane.YES_OPTION)
416 .removeColourFromDefaults(radioItem.getText());
417 coloursMenu.remove(radioItem);
421 radioItem.addActionListener(new ActionListener()
423 public void actionPerformed(ActionEvent evt)
425 user_actionPerformed(evt);
432 radioItem.addActionListener(new ActionListener()
434 public void actionPerformed(ActionEvent evt)
436 user_actionPerformed(evt);
439 coloursMenu.add(radioItem);
446 viewMenu.add(zbuffer);
447 viewMenu.add(allchains);
450 JMenuBar jMenuBar1 = new JMenuBar();
452 JMenu fileMenu = new JMenu();
454 JMenu coloursMenu = new JMenu();
456 JMenu saveMenu = new JMenu();
458 JMenuItem png = new JMenuItem();
460 JMenuItem eps = new JMenuItem();
462 JMenuItem mapping = new JMenuItem();
464 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
466 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
468 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
470 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
472 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
474 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
476 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
478 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
480 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
482 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
484 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
486 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
488 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
490 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
492 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
494 JMenu viewMenu = new JMenu();
496 JMenuItem background = new JMenuItem();
498 JMenuItem savePDB = new JMenuItem();
506 public void eps_actionPerformed(ActionEvent e)
508 makePDBImage(ImageMaker.TYPE.EPS);
517 public void png_actionPerformed(ActionEvent e)
519 makePDBImage(ImageMaker.TYPE.PNG);
522 void makePDBImage(ImageMaker.TYPE type)
524 int width = pdbcanvas.getWidth();
525 int height = pdbcanvas.getHeight();
529 if (type == ImageMaker.TYPE.PNG)
531 im = new ImageMaker(this, ImageMaker.TYPE.PNG,
532 "Make PNG image from view", width, height, null, null);
534 else if (type == ImageMaker.TYPE.EPS)
536 im = new ImageMaker(this, ImageMaker.TYPE.EPS,
537 "Make EPS file from view", width, height, null,
543 im = new ImageMaker(this, ImageMaker.TYPE.SVG,
544 "Make SVG file from PCA",
545 width, height, null, this.getTitle());
548 if (im.getGraphics() != null)
550 pdbcanvas.drawAll(im.getGraphics(), width, height);
555 public void charge_actionPerformed(ActionEvent e)
557 pdbcanvas.bysequence = false;
558 pdbcanvas.pdb.setChargeColours();
559 pdbcanvas.redrawneeded = true;
563 public void hydro_actionPerformed(ActionEvent e)
565 pdbcanvas.bysequence = false;
566 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
567 pdbcanvas.redrawneeded = true;
571 public void chain_actionPerformed(ActionEvent e)
573 pdbcanvas.bysequence = false;
574 pdbcanvas.pdb.setChainColours();
575 pdbcanvas.redrawneeded = true;
579 public void zbuffer_actionPerformed(ActionEvent e)
581 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
582 pdbcanvas.redrawneeded = true;
586 public void molecule_actionPerformed(ActionEvent e)
588 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
589 pdbcanvas.redrawneeded = true;
593 public void depth_actionPerformed(ActionEvent e)
595 pdbcanvas.depthcue = !pdbcanvas.depthcue;
596 pdbcanvas.redrawneeded = true;
600 public void wire_actionPerformed(ActionEvent e)
602 pdbcanvas.wire = !pdbcanvas.wire;
603 pdbcanvas.redrawneeded = true;
607 public void seqButton_actionPerformed(ActionEvent e)
609 pdbcanvas.bysequence = true;
610 pdbcanvas.updateSeqColours();
613 public void mapping_actionPerformed(ActionEvent e)
615 CutAndPasteTransfer cap = new CutAndPasteTransfer();
618 cap.setText(pdbcanvas.mappingDetails.toString());
619 Desktop.addInternalFrame(cap,
620 MessageManager.getString("label.pdb_sequence_mapping"), 550,
622 } catch (OutOfMemoryError oom)
624 new OOMWarning("Opening sequence to structure mapping report", oom);
629 public void allchains_itemStateChanged(ItemEvent e)
631 pdbcanvas.setAllchainsVisible(allchains.getState());
634 public void zappo_actionPerformed(ActionEvent e)
636 pdbcanvas.bysequence = false;
637 pdbcanvas.pdb.setColours(new ZappoColourScheme());
638 pdbcanvas.redrawneeded = true;
642 public void taylor_actionPerformed(ActionEvent e)
644 pdbcanvas.bysequence = false;
645 pdbcanvas.pdb.setColours(new TaylorColourScheme());
646 pdbcanvas.redrawneeded = true;
650 public void helix_actionPerformed(ActionEvent e)
652 pdbcanvas.bysequence = false;
653 pdbcanvas.pdb.setColours(new HelixColourScheme());
654 pdbcanvas.redrawneeded = true;
658 public void strand_actionPerformed(ActionEvent e)
660 pdbcanvas.bysequence = false;
661 pdbcanvas.pdb.setColours(new StrandColourScheme());
662 pdbcanvas.redrawneeded = true;
666 public void turn_actionPerformed(ActionEvent e)
668 pdbcanvas.bysequence = false;
669 pdbcanvas.pdb.setColours(new TurnColourScheme());
670 pdbcanvas.redrawneeded = true;
674 public void buried_actionPerformed(ActionEvent e)
676 pdbcanvas.bysequence = false;
677 pdbcanvas.pdb.setColours(new BuriedColourScheme());
678 pdbcanvas.redrawneeded = true;
682 public void user_actionPerformed(ActionEvent e)
684 if (e.getActionCommand().equals(
685 MessageManager.getString("action.user_defined")))
687 // new UserDefinedColours(pdbcanvas, null);
691 UserColourScheme udc = (UserColourScheme) UserDefinedColours
692 .getUserColourSchemes().get(e.getActionCommand());
694 pdbcanvas.pdb.setColours(udc);
695 pdbcanvas.redrawneeded = true;
700 public void background_actionPerformed(ActionEvent e)
702 java.awt.Color col = JColorChooser.showDialog(this,
703 MessageManager.getString("label.select_backgroud_colour"),
704 pdbcanvas.backgroundColour);
708 pdbcanvas.backgroundColour = col;
709 pdbcanvas.redrawneeded = true;
714 public void savePDB_actionPerformed(ActionEvent e)
716 JalviewFileChooser chooser = new JalviewFileChooser(
717 Cache.getProperty("LAST_DIRECTORY"));
719 chooser.setFileView(new JalviewFileView());
720 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
721 chooser.setToolTipText(MessageManager.getString("action.save"));
723 int value = chooser.showSaveDialog(this);
725 if (value == JalviewFileChooser.APPROVE_OPTION)
729 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
730 File outFile = chooser.getSelectedFile();
732 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
734 while ((data = in.readLine()) != null)
736 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
743 } catch (Exception ex)
745 ex.printStackTrace();