2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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.*;
24 import javax.xml.parsers.ParserConfigurationException;
26 import org.xml.sax.SAXException;
28 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
29 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
30 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
31 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
33 import jalview.datamodel.*;
36 import jalview.schemes.*;
37 import jalview.ws.ebi.EBIFetchClient;
39 import java.awt.BorderLayout;
41 public class PDBViewer extends JInternalFrame implements Runnable
45 * The associated sequence in an alignment
61 public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
62 AlignmentPanel ap, String protocol) throws ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
65 this.pdbentry = pdbentry;
69 this.protocol = protocol;
74 } catch (Exception ex)
79 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
80 + pdbentry.getFile());
82 pdbcanvas = new PDBCanvas();
84 setContentPane(pdbcanvas);
86 if (pdbentry.getFile() != null)
90 tmpPDBFile = pdbentry.getFile();
91 PDBfile pdbfile = new PDBfile(tmpPDBFile,
92 jalview.io.AppletFormatAdapter.FILE);
94 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
96 } catch (java.io.IOException ex)
103 Thread worker = new Thread(this);
107 if (pdbentry.getProperty() != null)
109 if (pdbentry.getProperty().get("method") != null)
111 title.append(" Method: ");
112 title.append(pdbentry.getProperty().get("method"));
114 if (pdbentry.getProperty().get("chains") != null)
116 title.append(" Chain:");
117 title.append(pdbentry.getProperty().get("chains"));
120 Desktop.addInternalFrame(this, title.toString(), 400, 400);
127 EBIFetchClient ebi = new EBIFetchClient();
128 String query = "pdb:" + pdbentry.getId();
129 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
132 if (pdbentry.getFile() != null)
133 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
134 } catch (Exception ex)
136 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
137 ex.printStackTrace();
141 private void jbInit() throws Exception
143 this.addKeyListener(new KeyAdapter()
145 public void keyPressed(KeyEvent evt)
147 pdbcanvas.keyPressed(evt);
151 this.setJMenuBar(jMenuBar1);
152 fileMenu.setText("File");
153 coloursMenu.setText("Colours");
154 saveMenu.setActionCommand("Save Image");
155 saveMenu.setText("Save As");
157 png.addActionListener(new ActionListener()
159 public void actionPerformed(ActionEvent e)
161 png_actionPerformed(e);
165 eps.addActionListener(new ActionListener()
167 public void actionPerformed(ActionEvent e)
169 eps_actionPerformed(e);
172 mapping.setText("View Mapping");
173 mapping.addActionListener(new ActionListener()
175 public void actionPerformed(ActionEvent e)
177 mapping_actionPerformed(e);
180 wire.setText("Wireframe");
181 wire.addActionListener(new ActionListener()
183 public void actionPerformed(ActionEvent e)
185 wire_actionPerformed(e);
188 depth.setSelected(true);
189 depth.setText("Depthcue");
190 depth.addActionListener(new ActionListener()
192 public void actionPerformed(ActionEvent e)
194 depth_actionPerformed(e);
197 zbuffer.setSelected(true);
198 zbuffer.setText("Z Buffering");
199 zbuffer.addActionListener(new ActionListener()
201 public void actionPerformed(ActionEvent e)
203 zbuffer_actionPerformed(e);
206 charge.setText("Charge & Cysteine");
207 charge.addActionListener(new ActionListener()
209 public void actionPerformed(ActionEvent e)
211 charge_actionPerformed(e);
214 chain.setText("By Chain");
215 chain.addActionListener(new ActionListener()
217 public void actionPerformed(ActionEvent e)
219 chain_actionPerformed(e);
222 seqButton.setSelected(true);
223 seqButton.setText("By Sequence");
224 seqButton.addActionListener(new ActionListener()
226 public void actionPerformed(ActionEvent e)
228 seqButton_actionPerformed(e);
231 allchains.setSelected(true);
232 allchains.setText("Show All Chains");
233 allchains.addItemListener(new ItemListener()
235 public void itemStateChanged(ItemEvent e)
237 allchains_itemStateChanged(e);
240 zappo.setText("Zappo");
241 zappo.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
245 zappo_actionPerformed(e);
248 taylor.setText("Taylor");
249 taylor.addActionListener(new ActionListener()
251 public void actionPerformed(ActionEvent e)
253 taylor_actionPerformed(e);
256 hydro.setText("Hydro");
257 hydro.addActionListener(new ActionListener()
259 public void actionPerformed(ActionEvent e)
261 hydro_actionPerformed(e);
264 helix.setText("Helix");
265 helix.addActionListener(new ActionListener()
267 public void actionPerformed(ActionEvent e)
269 helix_actionPerformed(e);
272 strand.setText("Strand");
273 strand.addActionListener(new ActionListener()
275 public void actionPerformed(ActionEvent e)
277 strand_actionPerformed(e);
280 turn.setText("Turn");
281 turn.addActionListener(new ActionListener()
283 public void actionPerformed(ActionEvent e)
285 turn_actionPerformed(e);
288 buried.setText("Buried");
289 buried.addActionListener(new ActionListener()
291 public void actionPerformed(ActionEvent e)
293 buried_actionPerformed(e);
296 user.setText("User Defined...");
297 user.addActionListener(new ActionListener()
299 public void actionPerformed(ActionEvent e)
301 user_actionPerformed(e);
304 viewMenu.setText("View");
305 background.setText("Background Colour...");
306 background.addActionListener(new ActionListener()
308 public void actionPerformed(ActionEvent e)
310 background_actionPerformed(e);
313 savePDB.setText("PDB File");
314 savePDB.addActionListener(new ActionListener()
316 public void actionPerformed(ActionEvent e)
318 savePDB_actionPerformed(e);
321 jMenuBar1.add(fileMenu);
322 jMenuBar1.add(coloursMenu);
323 jMenuBar1.add(viewMenu);
324 fileMenu.add(saveMenu);
325 fileMenu.add(mapping);
326 saveMenu.add(savePDB);
329 coloursMenu.add(seqButton);
330 coloursMenu.add(chain);
331 coloursMenu.add(charge);
332 coloursMenu.add(zappo);
333 coloursMenu.add(taylor);
334 coloursMenu.add(hydro);
335 coloursMenu.add(helix);
336 coloursMenu.add(strand);
337 coloursMenu.add(turn);
338 coloursMenu.add(buried);
339 coloursMenu.add(user);
340 coloursMenu.add(background);
341 ButtonGroup bg = new ButtonGroup();
354 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
356 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
357 .getUserColourSchemes().keys();
359 while (userColours.hasMoreElements())
361 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
362 userColours.nextElement().toString());
363 radioItem.setName("USER_DEFINED");
364 radioItem.addMouseListener(new MouseAdapter()
366 public void mousePressed(MouseEvent evt)
368 if (evt.isControlDown()
369 || SwingUtilities.isRightMouseButton(evt))
371 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
373 int option = JOptionPane.showInternalConfirmDialog(
374 jalview.gui.Desktop.desktop,
375 "Remove from default list?",
376 "Remove user defined colour",
377 JOptionPane.YES_NO_OPTION);
378 if (option == JOptionPane.YES_OPTION)
380 jalview.gui.UserDefinedColours
381 .removeColourFromDefaults(radioItem.getText());
382 coloursMenu.remove(radioItem);
386 radioItem.addActionListener(new ActionListener()
388 public void actionPerformed(ActionEvent evt)
390 user_actionPerformed(evt);
397 radioItem.addActionListener(new ActionListener()
399 public void actionPerformed(ActionEvent evt)
401 user_actionPerformed(evt);
404 coloursMenu.add(radioItem);
411 viewMenu.add(zbuffer);
412 viewMenu.add(allchains);
415 JMenuBar jMenuBar1 = new JMenuBar();
417 JMenu fileMenu = new JMenu();
419 JMenu coloursMenu = new JMenu();
421 JMenu saveMenu = new JMenu();
423 JMenuItem png = new JMenuItem();
425 JMenuItem eps = new JMenuItem();
427 JMenuItem mapping = new JMenuItem();
429 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
431 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
433 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
435 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
437 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
439 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
441 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
443 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
445 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
447 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
449 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
451 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
453 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
455 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
457 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
459 JMenu viewMenu = new JMenu();
461 JMenuItem background = new JMenuItem();
463 JMenuItem savePDB = new JMenuItem();
471 public void eps_actionPerformed(ActionEvent e)
473 makePDBImage(jalview.util.ImageMaker.EPS);
482 public void png_actionPerformed(ActionEvent e)
484 makePDBImage(jalview.util.ImageMaker.PNG);
487 void makePDBImage(int type)
489 int width = pdbcanvas.getWidth();
490 int height = pdbcanvas.getHeight();
492 jalview.util.ImageMaker im;
494 if (type == jalview.util.ImageMaker.PNG)
496 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
497 "Make PNG image from view", width, height, null, null);
501 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
502 "Make EPS file from view", width, height, null,
506 if (im.getGraphics() != null)
508 pdbcanvas.drawAll(im.getGraphics(), width, height);
513 public void charge_actionPerformed(ActionEvent e)
515 pdbcanvas.bysequence = false;
516 pdbcanvas.pdb.setChargeColours();
517 pdbcanvas.redrawneeded = true;
521 public void hydro_actionPerformed(ActionEvent e)
523 pdbcanvas.bysequence = false;
524 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
525 pdbcanvas.redrawneeded = true;
529 public void chain_actionPerformed(ActionEvent e)
531 pdbcanvas.bysequence = false;
532 pdbcanvas.pdb.setChainColours();
533 pdbcanvas.redrawneeded = true;
537 public void zbuffer_actionPerformed(ActionEvent e)
539 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
540 pdbcanvas.redrawneeded = true;
544 public void molecule_actionPerformed(ActionEvent e)
546 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
547 pdbcanvas.redrawneeded = true;
551 public void depth_actionPerformed(ActionEvent e)
553 pdbcanvas.depthcue = !pdbcanvas.depthcue;
554 pdbcanvas.redrawneeded = true;
558 public void wire_actionPerformed(ActionEvent e)
560 pdbcanvas.wire = !pdbcanvas.wire;
561 pdbcanvas.redrawneeded = true;
565 public void seqButton_actionPerformed(ActionEvent e)
567 pdbcanvas.bysequence = true;
568 pdbcanvas.updateSeqColours();
571 public void mapping_actionPerformed(ActionEvent e)
573 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
576 cap.setText(pdbcanvas.mappingDetails.toString());
577 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
578 } catch (OutOfMemoryError oom)
580 new OOMWarning("Opening sequence to structure mapping report", oom);
585 public void allchains_itemStateChanged(ItemEvent e)
587 pdbcanvas.setAllchainsVisible(allchains.getState());
590 public void zappo_actionPerformed(ActionEvent e)
592 pdbcanvas.bysequence = false;
593 pdbcanvas.pdb.setColours(new ZappoColourScheme());
594 pdbcanvas.redrawneeded = true;
598 public void taylor_actionPerformed(ActionEvent e)
600 pdbcanvas.bysequence = false;
601 pdbcanvas.pdb.setColours(new TaylorColourScheme());
602 pdbcanvas.redrawneeded = true;
606 public void helix_actionPerformed(ActionEvent e)
608 pdbcanvas.bysequence = false;
609 pdbcanvas.pdb.setColours(new HelixColourScheme());
610 pdbcanvas.redrawneeded = true;
614 public void strand_actionPerformed(ActionEvent e)
616 pdbcanvas.bysequence = false;
617 pdbcanvas.pdb.setColours(new StrandColourScheme());
618 pdbcanvas.redrawneeded = true;
622 public void turn_actionPerformed(ActionEvent e)
624 pdbcanvas.bysequence = false;
625 pdbcanvas.pdb.setColours(new TurnColourScheme());
626 pdbcanvas.redrawneeded = true;
630 public void buried_actionPerformed(ActionEvent e)
632 pdbcanvas.bysequence = false;
633 pdbcanvas.pdb.setColours(new BuriedColourScheme());
634 pdbcanvas.redrawneeded = true;
638 public void user_actionPerformed(ActionEvent e)
640 if (e.getActionCommand().equals("User Defined..."))
642 // new UserDefinedColours(pdbcanvas, null);
646 UserColourScheme udc = (UserColourScheme) UserDefinedColours
647 .getUserColourSchemes().get(e.getActionCommand());
649 pdbcanvas.pdb.setColours(udc);
650 pdbcanvas.redrawneeded = true;
655 public void background_actionPerformed(ActionEvent e)
657 java.awt.Color col = JColorChooser.showDialog(this,
658 "Select Background Colour", pdbcanvas.backgroundColour);
662 pdbcanvas.backgroundColour = col;
663 pdbcanvas.redrawneeded = true;
668 public void savePDB_actionPerformed(ActionEvent e)
670 JalviewFileChooser chooser = new JalviewFileChooser(
671 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
673 chooser.setFileView(new JalviewFileView());
674 chooser.setDialogTitle("Save PDB File");
675 chooser.setToolTipText("Save");
677 int value = chooser.showSaveDialog(this);
679 if (value == JalviewFileChooser.APPROVE_OPTION)
683 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
684 File outFile = chooser.getSelectedFile();
686 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
688 while ((data = in.readLine()) != null)
690 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
696 } catch (Exception ex)
698 ex.printStackTrace();