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;
32 import jalview.datamodel.*;
35 import jalview.schemes.*;
36 import jalview.ws.ebi.EBIFetchClient;
38 import java.awt.BorderLayout;
40 public class PDBViewer extends JInternalFrame implements Runnable
44 * The associated sequence in an alignment
60 public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
61 AlignmentPanel ap, String protocol) throws ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException
64 this.pdbentry = pdbentry;
68 this.protocol = protocol;
73 } catch (Exception ex)
78 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
79 + pdbentry.getFile());
81 pdbcanvas = new PDBCanvas();
83 setContentPane(pdbcanvas);
85 if (pdbentry.getFile() != null)
89 tmpPDBFile = pdbentry.getFile();
90 PDBfile pdbfile = new PDBfile(tmpPDBFile,
91 jalview.io.AppletFormatAdapter.FILE);
93 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
95 } catch (java.io.IOException ex)
102 Thread worker = new Thread(this);
106 if (pdbentry.getProperty() != null)
108 if (pdbentry.getProperty().get("method") != null)
110 title.append(" Method: ");
111 title.append(pdbentry.getProperty().get("method"));
113 if (pdbentry.getProperty().get("chains") != null)
115 title.append(" Chain:");
116 title.append(pdbentry.getProperty().get("chains"));
119 Desktop.addInternalFrame(this, title.toString(), 400, 400);
126 EBIFetchClient ebi = new EBIFetchClient();
127 String query = "pdb:" + pdbentry.getId();
128 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
131 if (pdbentry.getFile() != null)
132 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
133 } catch (Exception ex)
135 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
136 ex.printStackTrace();
140 private void jbInit() throws Exception
142 this.addKeyListener(new KeyAdapter()
144 public void keyPressed(KeyEvent evt)
146 pdbcanvas.keyPressed(evt);
150 this.setJMenuBar(jMenuBar1);
151 fileMenu.setText("File");
152 coloursMenu.setText("Colours");
153 saveMenu.setActionCommand("Save Image");
154 saveMenu.setText("Save As");
156 png.addActionListener(new ActionListener()
158 public void actionPerformed(ActionEvent e)
160 png_actionPerformed(e);
164 eps.addActionListener(new ActionListener()
166 public void actionPerformed(ActionEvent e)
168 eps_actionPerformed(e);
171 mapping.setText("View Mapping");
172 mapping.addActionListener(new ActionListener()
174 public void actionPerformed(ActionEvent e)
176 mapping_actionPerformed(e);
179 wire.setText("Wireframe");
180 wire.addActionListener(new ActionListener()
182 public void actionPerformed(ActionEvent e)
184 wire_actionPerformed(e);
187 depth.setSelected(true);
188 depth.setText("Depthcue");
189 depth.addActionListener(new ActionListener()
191 public void actionPerformed(ActionEvent e)
193 depth_actionPerformed(e);
196 zbuffer.setSelected(true);
197 zbuffer.setText("Z Buffering");
198 zbuffer.addActionListener(new ActionListener()
200 public void actionPerformed(ActionEvent e)
202 zbuffer_actionPerformed(e);
205 charge.setText("Charge & Cysteine");
206 charge.addActionListener(new ActionListener()
208 public void actionPerformed(ActionEvent e)
210 charge_actionPerformed(e);
213 chain.setText("By Chain");
214 chain.addActionListener(new ActionListener()
216 public void actionPerformed(ActionEvent e)
218 chain_actionPerformed(e);
221 seqButton.setSelected(true);
222 seqButton.setText("By Sequence");
223 seqButton.addActionListener(new ActionListener()
225 public void actionPerformed(ActionEvent e)
227 seqButton_actionPerformed(e);
230 allchains.setSelected(true);
231 allchains.setText("Show All Chains");
232 allchains.addItemListener(new ItemListener()
234 public void itemStateChanged(ItemEvent e)
236 allchains_itemStateChanged(e);
239 zappo.setText("Zappo");
240 zappo.addActionListener(new ActionListener()
242 public void actionPerformed(ActionEvent e)
244 zappo_actionPerformed(e);
247 taylor.setText("Taylor");
248 taylor.addActionListener(new ActionListener()
250 public void actionPerformed(ActionEvent e)
252 taylor_actionPerformed(e);
255 hydro.setText("Hydro");
256 hydro.addActionListener(new ActionListener()
258 public void actionPerformed(ActionEvent e)
260 hydro_actionPerformed(e);
263 helix.setText("Helix");
264 helix.addActionListener(new ActionListener()
266 public void actionPerformed(ActionEvent e)
268 helix_actionPerformed(e);
271 strand.setText("Strand");
272 strand.addActionListener(new ActionListener()
274 public void actionPerformed(ActionEvent e)
276 strand_actionPerformed(e);
279 turn.setText("Turn");
280 turn.addActionListener(new ActionListener()
282 public void actionPerformed(ActionEvent e)
284 turn_actionPerformed(e);
287 buried.setText("Buried");
288 buried.addActionListener(new ActionListener()
290 public void actionPerformed(ActionEvent e)
292 buried_actionPerformed(e);
295 user.setText("User Defined...");
296 user.addActionListener(new ActionListener()
298 public void actionPerformed(ActionEvent e)
300 user_actionPerformed(e);
303 viewMenu.setText("View");
304 background.setText("Background Colour...");
305 background.addActionListener(new ActionListener()
307 public void actionPerformed(ActionEvent e)
309 background_actionPerformed(e);
312 savePDB.setText("PDB File");
313 savePDB.addActionListener(new ActionListener()
315 public void actionPerformed(ActionEvent e)
317 savePDB_actionPerformed(e);
320 jMenuBar1.add(fileMenu);
321 jMenuBar1.add(coloursMenu);
322 jMenuBar1.add(viewMenu);
323 fileMenu.add(saveMenu);
324 fileMenu.add(mapping);
325 saveMenu.add(savePDB);
328 coloursMenu.add(seqButton);
329 coloursMenu.add(chain);
330 coloursMenu.add(charge);
331 coloursMenu.add(zappo);
332 coloursMenu.add(taylor);
333 coloursMenu.add(hydro);
334 coloursMenu.add(helix);
335 coloursMenu.add(strand);
336 coloursMenu.add(turn);
337 coloursMenu.add(buried);
338 coloursMenu.add(user);
339 coloursMenu.add(background);
340 ButtonGroup bg = new ButtonGroup();
353 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
355 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
356 .getUserColourSchemes().keys();
358 while (userColours.hasMoreElements())
360 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
361 userColours.nextElement().toString());
362 radioItem.setName("USER_DEFINED");
363 radioItem.addMouseListener(new MouseAdapter()
365 public void mousePressed(MouseEvent evt)
367 if (evt.isControlDown()
368 || SwingUtilities.isRightMouseButton(evt))
370 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
372 int option = JOptionPane.showInternalConfirmDialog(
373 jalview.gui.Desktop.desktop,
374 "Remove from default list?",
375 "Remove user defined colour",
376 JOptionPane.YES_NO_OPTION);
377 if (option == JOptionPane.YES_OPTION)
379 jalview.gui.UserDefinedColours
380 .removeColourFromDefaults(radioItem.getText());
381 coloursMenu.remove(radioItem);
385 radioItem.addActionListener(new ActionListener()
387 public void actionPerformed(ActionEvent evt)
389 user_actionPerformed(evt);
396 radioItem.addActionListener(new ActionListener()
398 public void actionPerformed(ActionEvent evt)
400 user_actionPerformed(evt);
403 coloursMenu.add(radioItem);
410 viewMenu.add(zbuffer);
411 viewMenu.add(allchains);
414 JMenuBar jMenuBar1 = new JMenuBar();
416 JMenu fileMenu = new JMenu();
418 JMenu coloursMenu = new JMenu();
420 JMenu saveMenu = new JMenu();
422 JMenuItem png = new JMenuItem();
424 JMenuItem eps = new JMenuItem();
426 JMenuItem mapping = new JMenuItem();
428 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
430 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
432 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
434 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
436 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
438 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
440 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
442 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
444 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
446 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
448 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
450 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
452 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
454 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
456 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
458 JMenu viewMenu = new JMenu();
460 JMenuItem background = new JMenuItem();
462 JMenuItem savePDB = new JMenuItem();
470 public void eps_actionPerformed(ActionEvent e)
472 makePDBImage(jalview.util.ImageMaker.EPS);
481 public void png_actionPerformed(ActionEvent e)
483 makePDBImage(jalview.util.ImageMaker.PNG);
486 void makePDBImage(int type)
488 int width = pdbcanvas.getWidth();
489 int height = pdbcanvas.getHeight();
491 jalview.util.ImageMaker im;
493 if (type == jalview.util.ImageMaker.PNG)
495 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
496 "Make PNG image from view", width, height, null, null);
500 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
501 "Make EPS file from view", width, height, null,
505 if (im.getGraphics() != null)
507 pdbcanvas.drawAll(im.getGraphics(), width, height);
512 public void charge_actionPerformed(ActionEvent e)
514 pdbcanvas.bysequence = false;
515 pdbcanvas.pdb.setChargeColours();
516 pdbcanvas.redrawneeded = true;
520 public void hydro_actionPerformed(ActionEvent e)
522 pdbcanvas.bysequence = false;
523 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
524 pdbcanvas.redrawneeded = true;
528 public void chain_actionPerformed(ActionEvent e)
530 pdbcanvas.bysequence = false;
531 pdbcanvas.pdb.setChainColours();
532 pdbcanvas.redrawneeded = true;
536 public void zbuffer_actionPerformed(ActionEvent e)
538 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
539 pdbcanvas.redrawneeded = true;
543 public void molecule_actionPerformed(ActionEvent e)
545 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
546 pdbcanvas.redrawneeded = true;
550 public void depth_actionPerformed(ActionEvent e)
552 pdbcanvas.depthcue = !pdbcanvas.depthcue;
553 pdbcanvas.redrawneeded = true;
557 public void wire_actionPerformed(ActionEvent e)
559 pdbcanvas.wire = !pdbcanvas.wire;
560 pdbcanvas.redrawneeded = true;
564 public void seqButton_actionPerformed(ActionEvent e)
566 pdbcanvas.bysequence = true;
567 pdbcanvas.updateSeqColours();
570 public void mapping_actionPerformed(ActionEvent e)
572 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
575 cap.setText(pdbcanvas.mappingDetails.toString());
576 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
577 } catch (OutOfMemoryError oom)
579 new OOMWarning("Opening sequence to structure mapping report", oom);
584 public void allchains_itemStateChanged(ItemEvent e)
586 pdbcanvas.setAllchainsVisible(allchains.getState());
589 public void zappo_actionPerformed(ActionEvent e)
591 pdbcanvas.bysequence = false;
592 pdbcanvas.pdb.setColours(new ZappoColourScheme());
593 pdbcanvas.redrawneeded = true;
597 public void taylor_actionPerformed(ActionEvent e)
599 pdbcanvas.bysequence = false;
600 pdbcanvas.pdb.setColours(new TaylorColourScheme());
601 pdbcanvas.redrawneeded = true;
605 public void helix_actionPerformed(ActionEvent e)
607 pdbcanvas.bysequence = false;
608 pdbcanvas.pdb.setColours(new HelixColourScheme());
609 pdbcanvas.redrawneeded = true;
613 public void strand_actionPerformed(ActionEvent e)
615 pdbcanvas.bysequence = false;
616 pdbcanvas.pdb.setColours(new StrandColourScheme());
617 pdbcanvas.redrawneeded = true;
621 public void turn_actionPerformed(ActionEvent e)
623 pdbcanvas.bysequence = false;
624 pdbcanvas.pdb.setColours(new TurnColourScheme());
625 pdbcanvas.redrawneeded = true;
629 public void buried_actionPerformed(ActionEvent e)
631 pdbcanvas.bysequence = false;
632 pdbcanvas.pdb.setColours(new BuriedColourScheme());
633 pdbcanvas.redrawneeded = true;
637 public void user_actionPerformed(ActionEvent e)
639 if (e.getActionCommand().equals("User Defined..."))
641 // new UserDefinedColours(pdbcanvas, null);
645 UserColourScheme udc = (UserColourScheme) UserDefinedColours
646 .getUserColourSchemes().get(e.getActionCommand());
648 pdbcanvas.pdb.setColours(udc);
649 pdbcanvas.redrawneeded = true;
654 public void background_actionPerformed(ActionEvent e)
656 java.awt.Color col = JColorChooser.showDialog(this,
657 "Select Background Colour", pdbcanvas.backgroundColour);
661 pdbcanvas.backgroundColour = col;
662 pdbcanvas.redrawneeded = true;
667 public void savePDB_actionPerformed(ActionEvent e)
669 JalviewFileChooser chooser = new JalviewFileChooser(
670 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
672 chooser.setFileView(new JalviewFileView());
673 chooser.setDialogTitle("Save PDB File");
674 chooser.setToolTipText("Save");
676 int value = chooser.showSaveDialog(this);
678 if (value == JalviewFileChooser.APPROVE_OPTION)
682 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
683 File outFile = chooser.getSelectedFile();
685 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
687 while ((data = in.readLine()) != null)
689 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
695 } catch (Exception ex)
697 ex.printStackTrace();