2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
25 import java.awt.event.*;
28 import jalview.datamodel.*;
31 import jalview.schemes.*;
32 import jalview.util.MessageManager;
33 import jalview.ws.ebi.EBIFetchClient;
35 public class PDBViewer extends JInternalFrame implements Runnable
39 * The associated sequence in an alignment
55 public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
56 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(MessageManager.getString("action.file"));
146 coloursMenu.setText(MessageManager.getString("label.colours"));
147 saveMenu.setActionCommand(MessageManager.getString("action.save_image"));
148 saveMenu.setText(MessageManager.getString("action.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(MessageManager.getString("label.view_mapping"));
166 mapping.addActionListener(new ActionListener()
168 public void actionPerformed(ActionEvent e)
170 mapping_actionPerformed(e);
173 wire.setText(MessageManager.getString("label.wireframe"));
174 wire.addActionListener(new ActionListener()
176 public void actionPerformed(ActionEvent e)
178 wire_actionPerformed(e);
181 depth.setSelected(true);
182 depth.setText(MessageManager.getString("label.depthcue"));
183 depth.addActionListener(new ActionListener()
185 public void actionPerformed(ActionEvent e)
187 depth_actionPerformed(e);
190 zbuffer.setSelected(true);
191 zbuffer.setText(MessageManager.getString("label.z_buffering"));
192 zbuffer.addActionListener(new ActionListener()
194 public void actionPerformed(ActionEvent e)
196 zbuffer_actionPerformed(e);
199 charge.setText(MessageManager.getString("label.charge_cysteine"));
200 charge.addActionListener(new ActionListener()
202 public void actionPerformed(ActionEvent e)
204 charge_actionPerformed(e);
207 chain.setText(MessageManager.getString("action.by_chain"));
208 chain.addActionListener(new ActionListener()
210 public void actionPerformed(ActionEvent e)
212 chain_actionPerformed(e);
215 seqButton.setSelected(true);
216 seqButton.setText(MessageManager.getString("action.by_sequence"));
217 seqButton.addActionListener(new ActionListener()
219 public void actionPerformed(ActionEvent e)
221 seqButton_actionPerformed(e);
224 allchains.setSelected(true);
225 allchains.setText(MessageManager.getString("label.show_all_chains"));
226 allchains.addItemListener(new ItemListener()
228 public void itemStateChanged(ItemEvent e)
230 allchains_itemStateChanged(e);
233 zappo.setText(MessageManager.getString("label.zappo"));
234 zappo.addActionListener(new ActionListener()
236 public void actionPerformed(ActionEvent e)
238 zappo_actionPerformed(e);
241 taylor.setText(MessageManager.getString("label.taylor"));
242 taylor.addActionListener(new ActionListener()
244 public void actionPerformed(ActionEvent e)
246 taylor_actionPerformed(e);
249 hydro.setText(MessageManager.getString("label.hydrophobicity"));
250 hydro.addActionListener(new ActionListener()
252 public void actionPerformed(ActionEvent e)
254 hydro_actionPerformed(e);
257 helix.setText(MessageManager.getString("label.helix_propensity"));
258 helix.addActionListener(new ActionListener()
260 public void actionPerformed(ActionEvent e)
262 helix_actionPerformed(e);
265 strand.setText(MessageManager.getString("label.strand_propensity"));
266 strand.addActionListener(new ActionListener()
268 public void actionPerformed(ActionEvent e)
270 strand_actionPerformed(e);
273 turn.setText(MessageManager.getString("label.turn_propensity"));
274 turn.addActionListener(new ActionListener()
276 public void actionPerformed(ActionEvent e)
278 turn_actionPerformed(e);
281 buried.setText(MessageManager.getString("label.buried_index"));
282 buried.addActionListener(new ActionListener()
284 public void actionPerformed(ActionEvent e)
286 buried_actionPerformed(e);
289 user.setText(MessageManager.getString("action.user_defined"));
290 user.addActionListener(new ActionListener()
292 public void actionPerformed(ActionEvent e)
294 user_actionPerformed(e);
297 viewMenu.setText(MessageManager.getString("action.view"));
298 background.setText(MessageManager.getString("label.background_colour")
300 background.addActionListener(new ActionListener()
302 public void actionPerformed(ActionEvent e)
304 background_actionPerformed(e);
307 savePDB.setText(MessageManager.getString("label.pdb_file"));
308 savePDB.addActionListener(new ActionListener()
310 public void actionPerformed(ActionEvent e)
312 savePDB_actionPerformed(e);
315 jMenuBar1.add(fileMenu);
316 jMenuBar1.add(coloursMenu);
317 jMenuBar1.add(viewMenu);
318 fileMenu.add(saveMenu);
319 fileMenu.add(mapping);
320 saveMenu.add(savePDB);
323 coloursMenu.add(seqButton);
324 coloursMenu.add(chain);
325 coloursMenu.add(charge);
326 coloursMenu.add(zappo);
327 coloursMenu.add(taylor);
328 coloursMenu.add(hydro);
329 coloursMenu.add(helix);
330 coloursMenu.add(strand);
331 coloursMenu.add(turn);
332 coloursMenu.add(buried);
333 coloursMenu.add(user);
334 coloursMenu.add(background);
335 ButtonGroup bg = new ButtonGroup();
348 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
350 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
351 .getUserColourSchemes().keys();
353 while (userColours.hasMoreElements())
355 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
356 userColours.nextElement().toString());
357 radioItem.setName("USER_DEFINED");
358 radioItem.addMouseListener(new MouseAdapter()
360 public void mousePressed(MouseEvent evt)
362 if (evt.isControlDown()
363 || SwingUtilities.isRightMouseButton(evt))
365 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
367 int option = JOptionPane.showInternalConfirmDialog(
368 jalview.gui.Desktop.desktop,
370 .getString("label.remove_from_default_list"),
372 .getString("label.remove_user_defined_colour"),
373 JOptionPane.YES_NO_OPTION);
374 if (option == JOptionPane.YES_OPTION)
376 jalview.gui.UserDefinedColours
377 .removeColourFromDefaults(radioItem.getText());
378 coloursMenu.remove(radioItem);
382 radioItem.addActionListener(new ActionListener()
384 public void actionPerformed(ActionEvent evt)
386 user_actionPerformed(evt);
393 radioItem.addActionListener(new ActionListener()
395 public void actionPerformed(ActionEvent evt)
397 user_actionPerformed(evt);
400 coloursMenu.add(radioItem);
407 viewMenu.add(zbuffer);
408 viewMenu.add(allchains);
411 JMenuBar jMenuBar1 = new JMenuBar();
413 JMenu fileMenu = new JMenu();
415 JMenu coloursMenu = new JMenu();
417 JMenu saveMenu = new JMenu();
419 JMenuItem png = new JMenuItem();
421 JMenuItem eps = new JMenuItem();
423 JMenuItem mapping = new JMenuItem();
425 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
427 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
429 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
431 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
433 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
435 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
437 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
439 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
441 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
443 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
445 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
447 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
449 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
451 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
453 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
455 JMenu viewMenu = new JMenu();
457 JMenuItem background = new JMenuItem();
459 JMenuItem savePDB = new JMenuItem();
467 public void eps_actionPerformed(ActionEvent e)
469 makePDBImage(jalview.util.ImageMaker.EPS);
478 public void png_actionPerformed(ActionEvent e)
480 makePDBImage(jalview.util.ImageMaker.PNG);
483 void makePDBImage(int type)
485 int width = pdbcanvas.getWidth();
486 int height = pdbcanvas.getHeight();
488 jalview.util.ImageMaker im;
490 if (type == jalview.util.ImageMaker.PNG)
492 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
493 "Make PNG image from view", width, height, null, null);
497 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
498 "Make EPS file from view", width, height, null,
502 if (im.getGraphics() != null)
504 pdbcanvas.drawAll(im.getGraphics(), width, height);
509 public void charge_actionPerformed(ActionEvent e)
511 pdbcanvas.bysequence = false;
512 pdbcanvas.pdb.setChargeColours();
513 pdbcanvas.redrawneeded = true;
517 public void hydro_actionPerformed(ActionEvent e)
519 pdbcanvas.bysequence = false;
520 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
521 pdbcanvas.redrawneeded = true;
525 public void chain_actionPerformed(ActionEvent e)
527 pdbcanvas.bysequence = false;
528 pdbcanvas.pdb.setChainColours();
529 pdbcanvas.redrawneeded = true;
533 public void zbuffer_actionPerformed(ActionEvent e)
535 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
536 pdbcanvas.redrawneeded = true;
540 public void molecule_actionPerformed(ActionEvent e)
542 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
543 pdbcanvas.redrawneeded = true;
547 public void depth_actionPerformed(ActionEvent e)
549 pdbcanvas.depthcue = !pdbcanvas.depthcue;
550 pdbcanvas.redrawneeded = true;
554 public void wire_actionPerformed(ActionEvent e)
556 pdbcanvas.wire = !pdbcanvas.wire;
557 pdbcanvas.redrawneeded = true;
561 public void seqButton_actionPerformed(ActionEvent e)
563 pdbcanvas.bysequence = true;
564 pdbcanvas.updateSeqColours();
567 public void mapping_actionPerformed(ActionEvent e)
569 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
572 cap.setText(pdbcanvas.mappingDetails.toString());
573 Desktop.addInternalFrame(cap,
574 MessageManager.getString("label.pdb_sequence_mapping"), 550,
576 } catch (OutOfMemoryError oom)
578 new OOMWarning("Opening sequence to structure mapping report", oom);
583 public void allchains_itemStateChanged(ItemEvent e)
585 pdbcanvas.setAllchainsVisible(allchains.getState());
588 public void zappo_actionPerformed(ActionEvent e)
590 pdbcanvas.bysequence = false;
591 pdbcanvas.pdb.setColours(new ZappoColourScheme());
592 pdbcanvas.redrawneeded = true;
596 public void taylor_actionPerformed(ActionEvent e)
598 pdbcanvas.bysequence = false;
599 pdbcanvas.pdb.setColours(new TaylorColourScheme());
600 pdbcanvas.redrawneeded = true;
604 public void helix_actionPerformed(ActionEvent e)
606 pdbcanvas.bysequence = false;
607 pdbcanvas.pdb.setColours(new HelixColourScheme());
608 pdbcanvas.redrawneeded = true;
612 public void strand_actionPerformed(ActionEvent e)
614 pdbcanvas.bysequence = false;
615 pdbcanvas.pdb.setColours(new StrandColourScheme());
616 pdbcanvas.redrawneeded = true;
620 public void turn_actionPerformed(ActionEvent e)
622 pdbcanvas.bysequence = false;
623 pdbcanvas.pdb.setColours(new TurnColourScheme());
624 pdbcanvas.redrawneeded = true;
628 public void buried_actionPerformed(ActionEvent e)
630 pdbcanvas.bysequence = false;
631 pdbcanvas.pdb.setColours(new BuriedColourScheme());
632 pdbcanvas.redrawneeded = true;
636 public void user_actionPerformed(ActionEvent e)
638 if (e.getActionCommand().equals(
639 MessageManager.getString("action.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 MessageManager.getString("label.select_backgroud_colour"),
658 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(MessageManager.getString("action.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))
697 } catch (Exception ex)
699 ex.printStackTrace();