2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, 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.ws.ebi.EBIFetchClient;
31 import java.awt.BorderLayout;
33 public class PDBViewer extends JInternalFrame implements Runnable
37 * The associated sequence in an alignment
53 public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
54 AlignmentPanel ap, String protocol)
57 this.pdbentry = pdbentry;
61 this.protocol = protocol;
66 } catch (Exception ex)
71 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
72 + pdbentry.getFile());
74 pdbcanvas = new PDBCanvas();
76 setContentPane(pdbcanvas);
78 if (pdbentry.getFile() != null)
82 tmpPDBFile = pdbentry.getFile();
83 PDBfile pdbfile = new PDBfile(tmpPDBFile,
84 jalview.io.AppletFormatAdapter.FILE);
86 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
88 } catch (java.io.IOException ex)
95 Thread worker = new Thread(this);
99 if (pdbentry.getProperty() != null)
101 if (pdbentry.getProperty().get("method") != null)
103 title.append(" Method: ");
104 title.append(pdbentry.getProperty().get("method"));
106 if (pdbentry.getProperty().get("chains") != null)
108 title.append(" Chain:");
109 title.append(pdbentry.getProperty().get("chains"));
112 Desktop.addInternalFrame(this, title.toString(), 400, 400);
119 EBIFetchClient ebi = new EBIFetchClient();
120 String query = "pdb:" + pdbentry.getId();
121 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
124 if (pdbentry.getFile() != null)
125 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
126 } catch (Exception ex)
128 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
129 ex.printStackTrace();
133 private void jbInit() throws Exception
135 this.addKeyListener(new KeyAdapter()
137 public void keyPressed(KeyEvent evt)
139 pdbcanvas.keyPressed(evt);
143 this.setJMenuBar(jMenuBar1);
144 fileMenu.setText("File");
145 coloursMenu.setText("Colours");
146 saveMenu.setActionCommand("Save Image");
147 saveMenu.setText("Save As");
149 png.addActionListener(new ActionListener()
151 public void actionPerformed(ActionEvent e)
153 png_actionPerformed(e);
157 eps.addActionListener(new ActionListener()
159 public void actionPerformed(ActionEvent e)
161 eps_actionPerformed(e);
164 mapping.setText("View Mapping");
165 mapping.addActionListener(new ActionListener()
167 public void actionPerformed(ActionEvent e)
169 mapping_actionPerformed(e);
172 wire.setText("Wireframe");
173 wire.addActionListener(new ActionListener()
175 public void actionPerformed(ActionEvent e)
177 wire_actionPerformed(e);
180 depth.setSelected(true);
181 depth.setText("Depthcue");
182 depth.addActionListener(new ActionListener()
184 public void actionPerformed(ActionEvent e)
186 depth_actionPerformed(e);
189 zbuffer.setSelected(true);
190 zbuffer.setText("Z Buffering");
191 zbuffer.addActionListener(new ActionListener()
193 public void actionPerformed(ActionEvent e)
195 zbuffer_actionPerformed(e);
198 charge.setText("Charge & Cysteine");
199 charge.addActionListener(new ActionListener()
201 public void actionPerformed(ActionEvent e)
203 charge_actionPerformed(e);
206 chain.setText("By Chain");
207 chain.addActionListener(new ActionListener()
209 public void actionPerformed(ActionEvent e)
211 chain_actionPerformed(e);
214 seqButton.setSelected(true);
215 seqButton.setText("By Sequence");
216 seqButton.addActionListener(new ActionListener()
218 public void actionPerformed(ActionEvent e)
220 seqButton_actionPerformed(e);
223 allchains.setSelected(true);
224 allchains.setText("Show All Chains");
225 allchains.addItemListener(new ItemListener()
227 public void itemStateChanged(ItemEvent e)
229 allchains_itemStateChanged(e);
232 zappo.setText("Zappo");
233 zappo.addActionListener(new ActionListener()
235 public void actionPerformed(ActionEvent e)
237 zappo_actionPerformed(e);
240 taylor.setText("Taylor");
241 taylor.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
245 taylor_actionPerformed(e);
248 hydro.setText("Hydro");
249 hydro.addActionListener(new ActionListener()
251 public void actionPerformed(ActionEvent e)
253 hydro_actionPerformed(e);
256 helix.setText("Helix");
257 helix.addActionListener(new ActionListener()
259 public void actionPerformed(ActionEvent e)
261 helix_actionPerformed(e);
264 strand.setText("Strand");
265 strand.addActionListener(new ActionListener()
267 public void actionPerformed(ActionEvent e)
269 strand_actionPerformed(e);
272 turn.setText("Turn");
273 turn.addActionListener(new ActionListener()
275 public void actionPerformed(ActionEvent e)
277 turn_actionPerformed(e);
280 buried.setText("Buried");
281 buried.addActionListener(new ActionListener()
283 public void actionPerformed(ActionEvent e)
285 buried_actionPerformed(e);
288 user.setText("User Defined...");
289 user.addActionListener(new ActionListener()
291 public void actionPerformed(ActionEvent e)
293 user_actionPerformed(e);
296 viewMenu.setText("View");
297 background.setText("Background Colour...");
298 background.addActionListener(new ActionListener()
300 public void actionPerformed(ActionEvent e)
302 background_actionPerformed(e);
305 savePDB.setText("PDB File");
306 savePDB.addActionListener(new ActionListener()
308 public void actionPerformed(ActionEvent e)
310 savePDB_actionPerformed(e);
313 jMenuBar1.add(fileMenu);
314 jMenuBar1.add(coloursMenu);
315 jMenuBar1.add(viewMenu);
316 fileMenu.add(saveMenu);
317 fileMenu.add(mapping);
318 saveMenu.add(savePDB);
321 coloursMenu.add(seqButton);
322 coloursMenu.add(chain);
323 coloursMenu.add(charge);
324 coloursMenu.add(zappo);
325 coloursMenu.add(taylor);
326 coloursMenu.add(hydro);
327 coloursMenu.add(helix);
328 coloursMenu.add(strand);
329 coloursMenu.add(turn);
330 coloursMenu.add(buried);
331 coloursMenu.add(user);
332 coloursMenu.add(background);
333 ButtonGroup bg = new ButtonGroup();
346 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
348 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
349 .getUserColourSchemes().keys();
351 while (userColours.hasMoreElements())
353 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
354 userColours.nextElement().toString());
355 radioItem.setName("USER_DEFINED");
356 radioItem.addMouseListener(new MouseAdapter()
358 public void mousePressed(MouseEvent evt)
360 if (evt.isControlDown()
361 || SwingUtilities.isRightMouseButton(evt))
363 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
365 int option = JOptionPane.showInternalConfirmDialog(
366 jalview.gui.Desktop.desktop,
367 "Remove from default list?",
368 "Remove user defined colour",
369 JOptionPane.YES_NO_OPTION);
370 if (option == JOptionPane.YES_OPTION)
372 jalview.gui.UserDefinedColours
373 .removeColourFromDefaults(radioItem.getText());
374 coloursMenu.remove(radioItem);
378 radioItem.addActionListener(new ActionListener()
380 public void actionPerformed(ActionEvent evt)
382 user_actionPerformed(evt);
389 radioItem.addActionListener(new ActionListener()
391 public void actionPerformed(ActionEvent evt)
393 user_actionPerformed(evt);
396 coloursMenu.add(radioItem);
403 viewMenu.add(zbuffer);
404 viewMenu.add(allchains);
407 JMenuBar jMenuBar1 = new JMenuBar();
409 JMenu fileMenu = new JMenu();
411 JMenu coloursMenu = new JMenu();
413 JMenu saveMenu = new JMenu();
415 JMenuItem png = new JMenuItem();
417 JMenuItem eps = new JMenuItem();
419 JMenuItem mapping = new JMenuItem();
421 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
423 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
425 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
427 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
429 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
431 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
433 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
435 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
437 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
439 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
441 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
443 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
445 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
447 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
449 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
451 JMenu viewMenu = new JMenu();
453 JMenuItem background = new JMenuItem();
455 JMenuItem savePDB = new JMenuItem();
463 public void eps_actionPerformed(ActionEvent e)
465 makePDBImage(jalview.util.ImageMaker.EPS);
474 public void png_actionPerformed(ActionEvent e)
476 makePDBImage(jalview.util.ImageMaker.PNG);
479 void makePDBImage(int type)
481 int width = pdbcanvas.getWidth();
482 int height = pdbcanvas.getHeight();
484 jalview.util.ImageMaker im;
486 if (type == jalview.util.ImageMaker.PNG)
488 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
489 "Make PNG image from view", width, height, null, null);
493 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
494 "Make EPS file from view", width, height, null,
498 if (im.getGraphics() != null)
500 pdbcanvas.drawAll(im.getGraphics(), width, height);
505 public void charge_actionPerformed(ActionEvent e)
507 pdbcanvas.bysequence = false;
508 pdbcanvas.pdb.setChargeColours();
509 pdbcanvas.redrawneeded = true;
513 public void hydro_actionPerformed(ActionEvent e)
515 pdbcanvas.bysequence = false;
516 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
517 pdbcanvas.redrawneeded = true;
521 public void chain_actionPerformed(ActionEvent e)
523 pdbcanvas.bysequence = false;
524 pdbcanvas.pdb.setChainColours();
525 pdbcanvas.redrawneeded = true;
529 public void zbuffer_actionPerformed(ActionEvent e)
531 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
532 pdbcanvas.redrawneeded = true;
536 public void molecule_actionPerformed(ActionEvent e)
538 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
539 pdbcanvas.redrawneeded = true;
543 public void depth_actionPerformed(ActionEvent e)
545 pdbcanvas.depthcue = !pdbcanvas.depthcue;
546 pdbcanvas.redrawneeded = true;
550 public void wire_actionPerformed(ActionEvent e)
552 pdbcanvas.wire = !pdbcanvas.wire;
553 pdbcanvas.redrawneeded = true;
557 public void seqButton_actionPerformed(ActionEvent e)
559 pdbcanvas.bysequence = true;
560 pdbcanvas.updateSeqColours();
563 public void mapping_actionPerformed(ActionEvent e)
565 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
568 cap.setText(pdbcanvas.mappingDetails.toString());
569 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
570 } catch (OutOfMemoryError oom)
572 new OOMWarning("Opening sequence to structure mapping report", oom);
577 public void allchains_itemStateChanged(ItemEvent e)
579 pdbcanvas.setAllchainsVisible(allchains.getState());
582 public void zappo_actionPerformed(ActionEvent e)
584 pdbcanvas.bysequence = false;
585 pdbcanvas.pdb.setColours(new ZappoColourScheme());
586 pdbcanvas.redrawneeded = true;
590 public void taylor_actionPerformed(ActionEvent e)
592 pdbcanvas.bysequence = false;
593 pdbcanvas.pdb.setColours(new TaylorColourScheme());
594 pdbcanvas.redrawneeded = true;
598 public void helix_actionPerformed(ActionEvent e)
600 pdbcanvas.bysequence = false;
601 pdbcanvas.pdb.setColours(new HelixColourScheme());
602 pdbcanvas.redrawneeded = true;
606 public void strand_actionPerformed(ActionEvent e)
608 pdbcanvas.bysequence = false;
609 pdbcanvas.pdb.setColours(new StrandColourScheme());
610 pdbcanvas.redrawneeded = true;
614 public void turn_actionPerformed(ActionEvent e)
616 pdbcanvas.bysequence = false;
617 pdbcanvas.pdb.setColours(new TurnColourScheme());
618 pdbcanvas.redrawneeded = true;
622 public void buried_actionPerformed(ActionEvent e)
624 pdbcanvas.bysequence = false;
625 pdbcanvas.pdb.setColours(new BuriedColourScheme());
626 pdbcanvas.redrawneeded = true;
630 public void user_actionPerformed(ActionEvent e)
632 if (e.getActionCommand().equals("User Defined..."))
634 // new UserDefinedColours(pdbcanvas, null);
638 UserColourScheme udc = (UserColourScheme) UserDefinedColours
639 .getUserColourSchemes().get(e.getActionCommand());
641 pdbcanvas.pdb.setColours(udc);
642 pdbcanvas.redrawneeded = true;
647 public void background_actionPerformed(ActionEvent e)
649 java.awt.Color col = JColorChooser.showDialog(this,
650 "Select Background Colour", pdbcanvas.backgroundColour);
654 pdbcanvas.backgroundColour = col;
655 pdbcanvas.redrawneeded = true;
660 public void savePDB_actionPerformed(ActionEvent e)
662 JalviewFileChooser chooser = new JalviewFileChooser(
663 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
665 chooser.setFileView(new JalviewFileView());
666 chooser.setDialogTitle("Save PDB File");
667 chooser.setToolTipText("Save");
669 int value = chooser.showSaveDialog(this);
671 if (value == JalviewFileChooser.APPROVE_OPTION)
675 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
676 File outFile = chooser.getSelectedFile();
678 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
680 while ((data = in.readLine()) != null)
682 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
688 } catch (Exception ex)
690 ex.printStackTrace();