2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 import java.awt.event.*;
26 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import jalview.ws.ebi.EBIFetchClient;
32 import java.awt.BorderLayout;
34 public class PDBViewer extends JInternalFrame implements Runnable
38 * The associated sequence in an alignment
54 public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
55 AlignmentPanel ap, String protocol)
58 this.pdbentry = pdbentry;
62 this.protocol = protocol;
67 } catch (Exception ex)
72 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
73 + pdbentry.getFile());
75 pdbcanvas = new PDBCanvas();
77 setContentPane(pdbcanvas);
79 if (pdbentry.getFile() != null)
83 tmpPDBFile = pdbentry.getFile();
84 PDBfile pdbfile = new PDBfile(tmpPDBFile,
85 jalview.io.AppletFormatAdapter.FILE);
87 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
89 } catch (java.io.IOException ex)
96 Thread worker = new Thread(this);
100 if (pdbentry.getProperty() != null)
102 if (pdbentry.getProperty().get("method") != null)
104 title.append(" Method: ");
105 title.append(pdbentry.getProperty().get("method"));
107 if (pdbentry.getProperty().get("chains") != null)
109 title.append(" Chain:");
110 title.append(pdbentry.getProperty().get("chains"));
113 Desktop.addInternalFrame(this, title.toString(), 400, 400);
120 EBIFetchClient ebi = new EBIFetchClient();
121 String query = "pdb:" + pdbentry.getId();
122 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
125 if (pdbentry.getFile() != null)
126 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
127 } catch (Exception ex)
129 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
130 ex.printStackTrace();
134 private void jbInit() throws Exception
136 this.addKeyListener(new KeyAdapter()
138 public void keyPressed(KeyEvent evt)
140 pdbcanvas.keyPressed(evt);
144 this.setJMenuBar(jMenuBar1);
145 fileMenu.setText("File");
146 coloursMenu.setText("Colours");
147 saveMenu.setActionCommand("Save Image");
148 saveMenu.setText("Save As");
150 png.addActionListener(new ActionListener()
152 public void actionPerformed(ActionEvent e)
154 png_actionPerformed(e);
158 eps.addActionListener(new ActionListener()
160 public void actionPerformed(ActionEvent e)
162 eps_actionPerformed(e);
165 mapping.setText("View Mapping");
166 mapping.addActionListener(new ActionListener()
168 public void actionPerformed(ActionEvent e)
170 mapping_actionPerformed(e);
173 wire.setText("Wireframe");
174 wire.addActionListener(new ActionListener()
176 public void actionPerformed(ActionEvent e)
178 wire_actionPerformed(e);
181 depth.setSelected(true);
182 depth.setText("Depthcue");
183 depth.addActionListener(new ActionListener()
185 public void actionPerformed(ActionEvent e)
187 depth_actionPerformed(e);
190 zbuffer.setSelected(true);
191 zbuffer.setText("Z Buffering");
192 zbuffer.addActionListener(new ActionListener()
194 public void actionPerformed(ActionEvent e)
196 zbuffer_actionPerformed(e);
199 charge.setText("Charge & Cysteine");
200 charge.addActionListener(new ActionListener()
202 public void actionPerformed(ActionEvent e)
204 charge_actionPerformed(e);
207 chain.setText("By Chain");
208 chain.addActionListener(new ActionListener()
210 public void actionPerformed(ActionEvent e)
212 chain_actionPerformed(e);
215 seqButton.setSelected(true);
216 seqButton.setText("By Sequence");
217 seqButton.addActionListener(new ActionListener()
219 public void actionPerformed(ActionEvent e)
221 seqButton_actionPerformed(e);
224 allchains.setSelected(true);
225 allchains.setText("Show All Chains");
226 allchains.addItemListener(new ItemListener()
228 public void itemStateChanged(ItemEvent e)
230 allchains_itemStateChanged(e);
233 zappo.setText("Zappo");
234 zappo.addActionListener(new ActionListener()
236 public void actionPerformed(ActionEvent e)
238 zappo_actionPerformed(e);
241 taylor.setText("Taylor");
242 taylor.addActionListener(new ActionListener()
244 public void actionPerformed(ActionEvent e)
246 taylor_actionPerformed(e);
249 hydro.setText("Hydro");
250 hydro.addActionListener(new ActionListener()
252 public void actionPerformed(ActionEvent e)
254 hydro_actionPerformed(e);
257 helix.setText("Helix");
258 helix.addActionListener(new ActionListener()
260 public void actionPerformed(ActionEvent e)
262 helix_actionPerformed(e);
265 strand.setText("Strand");
266 strand.addActionListener(new ActionListener()
268 public void actionPerformed(ActionEvent e)
270 strand_actionPerformed(e);
273 turn.setText("Turn");
274 turn.addActionListener(new ActionListener()
276 public void actionPerformed(ActionEvent e)
278 turn_actionPerformed(e);
281 buried.setText("Buried");
282 buried.addActionListener(new ActionListener()
284 public void actionPerformed(ActionEvent e)
286 buried_actionPerformed(e);
289 user.setText("User Defined...");
290 user.addActionListener(new ActionListener()
292 public void actionPerformed(ActionEvent e)
294 user_actionPerformed(e);
297 viewMenu.setText("View");
298 background.setText("Background Colour...");
299 background.addActionListener(new ActionListener()
301 public void actionPerformed(ActionEvent e)
303 background_actionPerformed(e);
306 savePDB.setText("PDB File");
307 savePDB.addActionListener(new ActionListener()
309 public void actionPerformed(ActionEvent e)
311 savePDB_actionPerformed(e);
314 jMenuBar1.add(fileMenu);
315 jMenuBar1.add(coloursMenu);
316 jMenuBar1.add(viewMenu);
317 fileMenu.add(saveMenu);
318 fileMenu.add(mapping);
319 saveMenu.add(savePDB);
322 coloursMenu.add(seqButton);
323 coloursMenu.add(chain);
324 coloursMenu.add(charge);
325 coloursMenu.add(zappo);
326 coloursMenu.add(taylor);
327 coloursMenu.add(hydro);
328 coloursMenu.add(helix);
329 coloursMenu.add(strand);
330 coloursMenu.add(turn);
331 coloursMenu.add(buried);
332 coloursMenu.add(user);
333 coloursMenu.add(background);
334 ButtonGroup bg = new ButtonGroup();
347 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
349 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
350 .getUserColourSchemes().keys();
352 while (userColours.hasMoreElements())
354 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
355 userColours.nextElement().toString());
356 radioItem.setName("USER_DEFINED");
357 radioItem.addMouseListener(new MouseAdapter()
359 public void mousePressed(MouseEvent evt)
361 if (evt.isControlDown()
362 || SwingUtilities.isRightMouseButton(evt))
365 .removeActionListener(radioItem.getActionListeners()[0]);
367 int option = JOptionPane.showInternalConfirmDialog(
368 jalview.gui.Desktop.desktop,
369 "Remove from default list?",
370 "Remove user defined colour",
371 JOptionPane.YES_NO_OPTION);
372 if (option == JOptionPane.YES_OPTION)
374 jalview.gui.UserDefinedColours
375 .removeColourFromDefaults(radioItem.getText());
376 coloursMenu.remove(radioItem);
380 radioItem.addActionListener(new ActionListener()
382 public void actionPerformed(ActionEvent evt)
384 user_actionPerformed(evt);
391 radioItem.addActionListener(new ActionListener()
393 public void actionPerformed(ActionEvent evt)
395 user_actionPerformed(evt);
398 coloursMenu.add(radioItem);
405 viewMenu.add(zbuffer);
406 viewMenu.add(allchains);
409 JMenuBar jMenuBar1 = new JMenuBar();
411 JMenu fileMenu = new JMenu();
413 JMenu coloursMenu = new JMenu();
415 JMenu saveMenu = new JMenu();
417 JMenuItem png = new JMenuItem();
419 JMenuItem eps = new JMenuItem();
421 JMenuItem mapping = new JMenuItem();
423 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
425 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
427 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
429 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
431 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
433 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
435 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
437 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
439 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
441 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
443 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
445 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
447 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
449 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
451 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
453 JMenu viewMenu = new JMenu();
455 JMenuItem background = new JMenuItem();
457 JMenuItem savePDB = new JMenuItem();
465 public void eps_actionPerformed(ActionEvent e)
467 makePDBImage(jalview.util.ImageMaker.EPS);
476 public void png_actionPerformed(ActionEvent e)
478 makePDBImage(jalview.util.ImageMaker.PNG);
481 void makePDBImage(int type)
483 int width = pdbcanvas.getWidth();
484 int height = pdbcanvas.getHeight();
486 jalview.util.ImageMaker im;
488 if (type == jalview.util.ImageMaker.PNG)
490 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
491 "Make PNG image from view", width, height, null, null);
495 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
496 "Make EPS file from view", width, height, null, this
500 if (im.getGraphics() != null)
502 pdbcanvas.drawAll(im.getGraphics(), width, height);
507 public void charge_actionPerformed(ActionEvent e)
509 pdbcanvas.bysequence = false;
510 pdbcanvas.pdb.setChargeColours();
511 pdbcanvas.redrawneeded = true;
515 public void hydro_actionPerformed(ActionEvent e)
517 pdbcanvas.bysequence = false;
518 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
519 pdbcanvas.redrawneeded = true;
523 public void chain_actionPerformed(ActionEvent e)
525 pdbcanvas.bysequence = false;
526 pdbcanvas.pdb.setChainColours();
527 pdbcanvas.redrawneeded = true;
531 public void zbuffer_actionPerformed(ActionEvent e)
533 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
534 pdbcanvas.redrawneeded = true;
538 public void molecule_actionPerformed(ActionEvent e)
540 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
541 pdbcanvas.redrawneeded = true;
545 public void depth_actionPerformed(ActionEvent e)
547 pdbcanvas.depthcue = !pdbcanvas.depthcue;
548 pdbcanvas.redrawneeded = true;
552 public void wire_actionPerformed(ActionEvent e)
554 pdbcanvas.wire = !pdbcanvas.wire;
555 pdbcanvas.redrawneeded = true;
559 public void seqButton_actionPerformed(ActionEvent e)
561 pdbcanvas.bysequence = true;
562 pdbcanvas.updateSeqColours();
565 public void mapping_actionPerformed(ActionEvent e)
567 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
568 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
569 cap.setText(pdbcanvas.mappingDetails.toString());
572 public void allchains_itemStateChanged(ItemEvent e)
574 pdbcanvas.setAllchainsVisible(allchains.getState());
577 public void zappo_actionPerformed(ActionEvent e)
579 pdbcanvas.bysequence = false;
580 pdbcanvas.pdb.setColours(new ZappoColourScheme());
581 pdbcanvas.redrawneeded = true;
585 public void taylor_actionPerformed(ActionEvent e)
587 pdbcanvas.bysequence = false;
588 pdbcanvas.pdb.setColours(new TaylorColourScheme());
589 pdbcanvas.redrawneeded = true;
593 public void helix_actionPerformed(ActionEvent e)
595 pdbcanvas.bysequence = false;
596 pdbcanvas.pdb.setColours(new HelixColourScheme());
597 pdbcanvas.redrawneeded = true;
601 public void strand_actionPerformed(ActionEvent e)
603 pdbcanvas.bysequence = false;
604 pdbcanvas.pdb.setColours(new StrandColourScheme());
605 pdbcanvas.redrawneeded = true;
609 public void turn_actionPerformed(ActionEvent e)
611 pdbcanvas.bysequence = false;
612 pdbcanvas.pdb.setColours(new TurnColourScheme());
613 pdbcanvas.redrawneeded = true;
617 public void buried_actionPerformed(ActionEvent e)
619 pdbcanvas.bysequence = false;
620 pdbcanvas.pdb.setColours(new BuriedColourScheme());
621 pdbcanvas.redrawneeded = true;
625 public void user_actionPerformed(ActionEvent e)
627 if (e.getActionCommand().equals("User Defined..."))
629 // new UserDefinedColours(pdbcanvas, null);
633 UserColourScheme udc = (UserColourScheme) UserDefinedColours
634 .getUserColourSchemes().get(e.getActionCommand());
636 pdbcanvas.pdb.setColours(udc);
637 pdbcanvas.redrawneeded = true;
642 public void background_actionPerformed(ActionEvent e)
644 java.awt.Color col = JColorChooser.showDialog(this,
645 "Select Background Colour", pdbcanvas.backgroundColour);
649 pdbcanvas.backgroundColour = col;
650 pdbcanvas.redrawneeded = true;
655 public void savePDB_actionPerformed(ActionEvent e)
657 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
658 .getProperty("LAST_DIRECTORY"));
660 chooser.setFileView(new JalviewFileView());
661 chooser.setDialogTitle("Save PDB File");
662 chooser.setToolTipText("Save");
664 int value = chooser.showSaveDialog(this);
666 if (value == JalviewFileChooser.APPROVE_OPTION)
670 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
671 File outFile = chooser.getSelectedFile();
673 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
675 while ((data = in.readLine()) != null)
677 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
683 } catch (Exception ex)
685 ex.printStackTrace();