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.*;
25 import jalview.datamodel.*;
28 import jalview.schemes.*;
29 import jalview.util.MessageManager;
30 import jalview.ws.ebi.EBIFetchClient;
32 public class PDBViewer extends JInternalFrame implements Runnable
36 * The associated sequence in an alignment
52 public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
53 AlignmentPanel ap, String protocol)
55 this.pdbentry = pdbentry;
59 this.protocol = protocol;
64 } catch (Exception ex)
69 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
70 + pdbentry.getFile());
72 pdbcanvas = new PDBCanvas();
74 setContentPane(pdbcanvas);
76 if (pdbentry.getFile() != null)
80 tmpPDBFile = pdbentry.getFile();
81 PDBfile pdbfile = new PDBfile(tmpPDBFile,
82 jalview.io.AppletFormatAdapter.FILE);
84 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
86 } catch (java.io.IOException ex)
93 Thread worker = new Thread(this);
97 if (pdbentry.getProperty() != null)
99 if (pdbentry.getProperty().get("method") != null)
101 title.append(" Method: ");
102 title.append(pdbentry.getProperty().get("method"));
104 if (pdbentry.getProperty().get("chains") != null)
106 title.append(" Chain:");
107 title.append(pdbentry.getProperty().get("chains"));
110 Desktop.addInternalFrame(this, title.toString(), 400, 400);
117 EBIFetchClient ebi = new EBIFetchClient();
118 String query = "pdb:" + pdbentry.getId();
119 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
122 if (pdbentry.getFile() != null)
123 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
124 } catch (Exception ex)
126 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
127 ex.printStackTrace();
131 private void jbInit() throws Exception
133 this.addKeyListener(new KeyAdapter()
135 public void keyPressed(KeyEvent evt)
137 pdbcanvas.keyPressed(evt);
141 this.setJMenuBar(jMenuBar1);
142 fileMenu.setText("File");
143 coloursMenu.setText("Colours");
144 saveMenu.setActionCommand("Save Image");
145 saveMenu.setText("Save As");
147 png.addActionListener(new ActionListener()
149 public void actionPerformed(ActionEvent e)
151 png_actionPerformed(e);
155 eps.addActionListener(new ActionListener()
157 public void actionPerformed(ActionEvent e)
159 eps_actionPerformed(e);
162 mapping.setText("View Mapping");
163 mapping.addActionListener(new ActionListener()
165 public void actionPerformed(ActionEvent e)
167 mapping_actionPerformed(e);
170 wire.setText("Wireframe");
171 wire.addActionListener(new ActionListener()
173 public void actionPerformed(ActionEvent e)
175 wire_actionPerformed(e);
178 depth.setSelected(true);
179 depth.setText("Depthcue");
180 depth.addActionListener(new ActionListener()
182 public void actionPerformed(ActionEvent e)
184 depth_actionPerformed(e);
187 zbuffer.setSelected(true);
188 zbuffer.setText("Z Buffering");
189 zbuffer.addActionListener(new ActionListener()
191 public void actionPerformed(ActionEvent e)
193 zbuffer_actionPerformed(e);
196 charge.setText("Charge & Cysteine");
197 charge.addActionListener(new ActionListener()
199 public void actionPerformed(ActionEvent e)
201 charge_actionPerformed(e);
204 chain.setText("By Chain");
205 chain.addActionListener(new ActionListener()
207 public void actionPerformed(ActionEvent e)
209 chain_actionPerformed(e);
212 seqButton.setSelected(true);
213 seqButton.setText("By Sequence");
214 seqButton.addActionListener(new ActionListener()
216 public void actionPerformed(ActionEvent e)
218 seqButton_actionPerformed(e);
221 allchains.setSelected(true);
222 allchains.setText("Show All Chains");
223 allchains.addItemListener(new ItemListener()
225 public void itemStateChanged(ItemEvent e)
227 allchains_itemStateChanged(e);
230 zappo.setText("Zappo");
231 zappo.addActionListener(new ActionListener()
233 public void actionPerformed(ActionEvent e)
235 zappo_actionPerformed(e);
238 taylor.setText("Taylor");
239 taylor.addActionListener(new ActionListener()
241 public void actionPerformed(ActionEvent e)
243 taylor_actionPerformed(e);
246 hydro.setText("Hydro");
247 hydro.addActionListener(new ActionListener()
249 public void actionPerformed(ActionEvent e)
251 hydro_actionPerformed(e);
254 helix.setText("Helix");
255 helix.addActionListener(new ActionListener()
257 public void actionPerformed(ActionEvent e)
259 helix_actionPerformed(e);
262 strand.setText("Strand");
263 strand.addActionListener(new ActionListener()
265 public void actionPerformed(ActionEvent e)
267 strand_actionPerformed(e);
270 turn.setText("Turn");
271 turn.addActionListener(new ActionListener()
273 public void actionPerformed(ActionEvent e)
275 turn_actionPerformed(e);
278 buried.setText("Buried");
279 buried.addActionListener(new ActionListener()
281 public void actionPerformed(ActionEvent e)
283 buried_actionPerformed(e);
286 user.setText("User Defined...");
287 user.addActionListener(new ActionListener()
289 public void actionPerformed(ActionEvent e)
291 user_actionPerformed(e);
294 viewMenu.setText("View");
295 background.setText("Background Colour...");
296 background.addActionListener(new ActionListener()
298 public void actionPerformed(ActionEvent e)
300 background_actionPerformed(e);
303 savePDB.setText("PDB File");
304 savePDB.addActionListener(new ActionListener()
306 public void actionPerformed(ActionEvent e)
308 savePDB_actionPerformed(e);
311 jMenuBar1.add(fileMenu);
312 jMenuBar1.add(coloursMenu);
313 jMenuBar1.add(viewMenu);
314 fileMenu.add(saveMenu);
315 fileMenu.add(mapping);
316 saveMenu.add(savePDB);
319 coloursMenu.add(seqButton);
320 coloursMenu.add(chain);
321 coloursMenu.add(charge);
322 coloursMenu.add(zappo);
323 coloursMenu.add(taylor);
324 coloursMenu.add(hydro);
325 coloursMenu.add(helix);
326 coloursMenu.add(strand);
327 coloursMenu.add(turn);
328 coloursMenu.add(buried);
329 coloursMenu.add(user);
330 coloursMenu.add(background);
331 ButtonGroup bg = new ButtonGroup();
344 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
346 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
347 .getUserColourSchemes().keys();
349 while (userColours.hasMoreElements())
351 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
352 userColours.nextElement().toString());
353 radioItem.setName("USER_DEFINED");
354 radioItem.addMouseListener(new MouseAdapter()
356 public void mousePressed(MouseEvent evt)
358 if (evt.isControlDown()
359 || SwingUtilities.isRightMouseButton(evt))
361 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
363 int option = JOptionPane.showInternalConfirmDialog(
364 jalview.gui.Desktop.desktop,
365 MessageManager.getString("label.remove_from_default_list"),
366 MessageManager.getString("label.remove_user_defined_colour"),
367 JOptionPane.YES_NO_OPTION);
368 if (option == JOptionPane.YES_OPTION)
370 jalview.gui.UserDefinedColours
371 .removeColourFromDefaults(radioItem.getText());
372 coloursMenu.remove(radioItem);
376 radioItem.addActionListener(new ActionListener()
378 public void actionPerformed(ActionEvent evt)
380 user_actionPerformed(evt);
387 radioItem.addActionListener(new ActionListener()
389 public void actionPerformed(ActionEvent evt)
391 user_actionPerformed(evt);
394 coloursMenu.add(radioItem);
401 viewMenu.add(zbuffer);
402 viewMenu.add(allchains);
405 JMenuBar jMenuBar1 = new JMenuBar();
407 JMenu fileMenu = new JMenu();
409 JMenu coloursMenu = new JMenu();
411 JMenu saveMenu = new JMenu();
413 JMenuItem png = new JMenuItem();
415 JMenuItem eps = new JMenuItem();
417 JMenuItem mapping = new JMenuItem();
419 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
421 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
423 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
425 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
427 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
429 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
431 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
433 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
435 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
437 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
439 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
441 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
443 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
445 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
447 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
449 JMenu viewMenu = new JMenu();
451 JMenuItem background = new JMenuItem();
453 JMenuItem savePDB = new JMenuItem();
461 public void eps_actionPerformed(ActionEvent e)
463 makePDBImage(jalview.util.ImageMaker.EPS);
472 public void png_actionPerformed(ActionEvent e)
474 makePDBImage(jalview.util.ImageMaker.PNG);
477 void makePDBImage(int type)
479 int width = pdbcanvas.getWidth();
480 int height = pdbcanvas.getHeight();
482 jalview.util.ImageMaker im;
484 if (type == jalview.util.ImageMaker.PNG)
486 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
487 "Make PNG image from view", width, height, null, null);
491 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
492 "Make EPS file from view", width, height, null,
496 if (im.getGraphics() != null)
498 pdbcanvas.drawAll(im.getGraphics(), width, height);
503 public void charge_actionPerformed(ActionEvent e)
505 pdbcanvas.bysequence = false;
506 pdbcanvas.pdb.setChargeColours();
507 pdbcanvas.redrawneeded = true;
511 public void hydro_actionPerformed(ActionEvent e)
513 pdbcanvas.bysequence = false;
514 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
515 pdbcanvas.redrawneeded = true;
519 public void chain_actionPerformed(ActionEvent e)
521 pdbcanvas.bysequence = false;
522 pdbcanvas.pdb.setChainColours();
523 pdbcanvas.redrawneeded = true;
527 public void zbuffer_actionPerformed(ActionEvent e)
529 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
530 pdbcanvas.redrawneeded = true;
534 public void molecule_actionPerformed(ActionEvent e)
536 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
537 pdbcanvas.redrawneeded = true;
541 public void depth_actionPerformed(ActionEvent e)
543 pdbcanvas.depthcue = !pdbcanvas.depthcue;
544 pdbcanvas.redrawneeded = true;
548 public void wire_actionPerformed(ActionEvent e)
550 pdbcanvas.wire = !pdbcanvas.wire;
551 pdbcanvas.redrawneeded = true;
555 public void seqButton_actionPerformed(ActionEvent e)
557 pdbcanvas.bysequence = true;
558 pdbcanvas.updateSeqColours();
561 public void mapping_actionPerformed(ActionEvent e)
563 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
566 cap.setText(pdbcanvas.mappingDetails.toString());
567 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
568 } catch (OutOfMemoryError oom)
570 new OOMWarning("Opening sequence to structure mapping report", oom);
575 public void allchains_itemStateChanged(ItemEvent e)
577 pdbcanvas.setAllchainsVisible(allchains.getState());
580 public void zappo_actionPerformed(ActionEvent e)
582 pdbcanvas.bysequence = false;
583 pdbcanvas.pdb.setColours(new ZappoColourScheme());
584 pdbcanvas.redrawneeded = true;
588 public void taylor_actionPerformed(ActionEvent e)
590 pdbcanvas.bysequence = false;
591 pdbcanvas.pdb.setColours(new TaylorColourScheme());
592 pdbcanvas.redrawneeded = true;
596 public void helix_actionPerformed(ActionEvent e)
598 pdbcanvas.bysequence = false;
599 pdbcanvas.pdb.setColours(new HelixColourScheme());
600 pdbcanvas.redrawneeded = true;
604 public void strand_actionPerformed(ActionEvent e)
606 pdbcanvas.bysequence = false;
607 pdbcanvas.pdb.setColours(new StrandColourScheme());
608 pdbcanvas.redrawneeded = true;
612 public void turn_actionPerformed(ActionEvent e)
614 pdbcanvas.bysequence = false;
615 pdbcanvas.pdb.setColours(new TurnColourScheme());
616 pdbcanvas.redrawneeded = true;
620 public void buried_actionPerformed(ActionEvent e)
622 pdbcanvas.bysequence = false;
623 pdbcanvas.pdb.setColours(new BuriedColourScheme());
624 pdbcanvas.redrawneeded = true;
628 public void user_actionPerformed(ActionEvent e)
630 if (e.getActionCommand().equals("User Defined..."))
632 // new UserDefinedColours(pdbcanvas, null);
636 UserColourScheme udc = (UserColourScheme) UserDefinedColours
637 .getUserColourSchemes().get(e.getActionCommand());
639 pdbcanvas.pdb.setColours(udc);
640 pdbcanvas.redrawneeded = true;
645 public void background_actionPerformed(ActionEvent e)
647 java.awt.Color col = JColorChooser.showDialog(this,
648 "Select Background Colour", pdbcanvas.backgroundColour);
652 pdbcanvas.backgroundColour = col;
653 pdbcanvas.redrawneeded = true;
658 public void savePDB_actionPerformed(ActionEvent e)
660 JalviewFileChooser chooser = new JalviewFileChooser(
661 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
663 chooser.setFileView(new JalviewFileView());
664 chooser.setDialogTitle("Save PDB File");
665 chooser.setToolTipText("Save");
667 int value = chooser.showSaveDialog(this);
669 if (value == JalviewFileChooser.APPROVE_OPTION)
673 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
674 File outFile = chooser.getSelectedFile();
676 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
678 while ((data = in.readLine()) != null)
680 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
687 } catch (Exception ex)
689 ex.printStackTrace();