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") + "...");
299 background.addActionListener(new ActionListener()
301 public void actionPerformed(ActionEvent e)
303 background_actionPerformed(e);
306 savePDB.setText(MessageManager.getString("label.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))
364 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
366 int option = JOptionPane.showInternalConfirmDialog(
367 jalview.gui.Desktop.desktop,
368 MessageManager.getString("label.remove_from_default_list"),
369 MessageManager.getString("label.remove_user_defined_colour"),
370 JOptionPane.YES_NO_OPTION);
371 if (option == JOptionPane.YES_OPTION)
373 jalview.gui.UserDefinedColours
374 .removeColourFromDefaults(radioItem.getText());
375 coloursMenu.remove(radioItem);
379 radioItem.addActionListener(new ActionListener()
381 public void actionPerformed(ActionEvent evt)
383 user_actionPerformed(evt);
390 radioItem.addActionListener(new ActionListener()
392 public void actionPerformed(ActionEvent evt)
394 user_actionPerformed(evt);
397 coloursMenu.add(radioItem);
404 viewMenu.add(zbuffer);
405 viewMenu.add(allchains);
408 JMenuBar jMenuBar1 = new JMenuBar();
410 JMenu fileMenu = new JMenu();
412 JMenu coloursMenu = new JMenu();
414 JMenu saveMenu = new JMenu();
416 JMenuItem png = new JMenuItem();
418 JMenuItem eps = new JMenuItem();
420 JMenuItem mapping = new JMenuItem();
422 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
424 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
426 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
428 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
430 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
432 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
434 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
436 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
438 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
440 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
442 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
444 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
446 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
448 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
450 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
452 JMenu viewMenu = new JMenu();
454 JMenuItem background = new JMenuItem();
456 JMenuItem savePDB = new JMenuItem();
464 public void eps_actionPerformed(ActionEvent e)
466 makePDBImage(jalview.util.ImageMaker.EPS);
475 public void png_actionPerformed(ActionEvent e)
477 makePDBImage(jalview.util.ImageMaker.PNG);
480 void makePDBImage(int type)
482 int width = pdbcanvas.getWidth();
483 int height = pdbcanvas.getHeight();
485 jalview.util.ImageMaker im;
487 if (type == jalview.util.ImageMaker.PNG)
489 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
490 "Make PNG image from view", width, height, null, null);
494 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
495 "Make EPS file from view", width, height, null,
499 if (im.getGraphics() != null)
501 pdbcanvas.drawAll(im.getGraphics(), width, height);
506 public void charge_actionPerformed(ActionEvent e)
508 pdbcanvas.bysequence = false;
509 pdbcanvas.pdb.setChargeColours();
510 pdbcanvas.redrawneeded = true;
514 public void hydro_actionPerformed(ActionEvent e)
516 pdbcanvas.bysequence = false;
517 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
518 pdbcanvas.redrawneeded = true;
522 public void chain_actionPerformed(ActionEvent e)
524 pdbcanvas.bysequence = false;
525 pdbcanvas.pdb.setChainColours();
526 pdbcanvas.redrawneeded = true;
530 public void zbuffer_actionPerformed(ActionEvent e)
532 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
533 pdbcanvas.redrawneeded = true;
537 public void molecule_actionPerformed(ActionEvent e)
539 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
540 pdbcanvas.redrawneeded = true;
544 public void depth_actionPerformed(ActionEvent e)
546 pdbcanvas.depthcue = !pdbcanvas.depthcue;
547 pdbcanvas.redrawneeded = true;
551 public void wire_actionPerformed(ActionEvent e)
553 pdbcanvas.wire = !pdbcanvas.wire;
554 pdbcanvas.redrawneeded = true;
558 public void seqButton_actionPerformed(ActionEvent e)
560 pdbcanvas.bysequence = true;
561 pdbcanvas.updateSeqColours();
564 public void mapping_actionPerformed(ActionEvent e)
566 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
569 cap.setText(pdbcanvas.mappingDetails.toString());
570 Desktop.addInternalFrame(cap, MessageManager.getString("label.pdb_sequence_mapping"), 550, 600);
571 } catch (OutOfMemoryError oom)
573 new OOMWarning("Opening sequence to structure mapping report", oom);
578 public void allchains_itemStateChanged(ItemEvent e)
580 pdbcanvas.setAllchainsVisible(allchains.getState());
583 public void zappo_actionPerformed(ActionEvent e)
585 pdbcanvas.bysequence = false;
586 pdbcanvas.pdb.setColours(new ZappoColourScheme());
587 pdbcanvas.redrawneeded = true;
591 public void taylor_actionPerformed(ActionEvent e)
593 pdbcanvas.bysequence = false;
594 pdbcanvas.pdb.setColours(new TaylorColourScheme());
595 pdbcanvas.redrawneeded = true;
599 public void helix_actionPerformed(ActionEvent e)
601 pdbcanvas.bysequence = false;
602 pdbcanvas.pdb.setColours(new HelixColourScheme());
603 pdbcanvas.redrawneeded = true;
607 public void strand_actionPerformed(ActionEvent e)
609 pdbcanvas.bysequence = false;
610 pdbcanvas.pdb.setColours(new StrandColourScheme());
611 pdbcanvas.redrawneeded = true;
615 public void turn_actionPerformed(ActionEvent e)
617 pdbcanvas.bysequence = false;
618 pdbcanvas.pdb.setColours(new TurnColourScheme());
619 pdbcanvas.redrawneeded = true;
623 public void buried_actionPerformed(ActionEvent e)
625 pdbcanvas.bysequence = false;
626 pdbcanvas.pdb.setColours(new BuriedColourScheme());
627 pdbcanvas.redrawneeded = true;
631 public void user_actionPerformed(ActionEvent e)
633 if (e.getActionCommand().equals(MessageManager.getString("action.user_defined")))
635 // new UserDefinedColours(pdbcanvas, null);
639 UserColourScheme udc = (UserColourScheme) UserDefinedColours
640 .getUserColourSchemes().get(e.getActionCommand());
642 pdbcanvas.pdb.setColours(udc);
643 pdbcanvas.redrawneeded = true;
648 public void background_actionPerformed(ActionEvent e)
650 java.awt.Color col = JColorChooser.showDialog(this,
651 MessageManager.getString("label.select_backgroud_colour"), pdbcanvas.backgroundColour);
655 pdbcanvas.backgroundColour = col;
656 pdbcanvas.redrawneeded = true;
661 public void savePDB_actionPerformed(ActionEvent e)
663 JalviewFileChooser chooser = new JalviewFileChooser(
664 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
666 chooser.setFileView(new JalviewFileView());
667 chooser.setDialogTitle("Save PDB File");
668 chooser.setToolTipText(MessageManager.getString("action.save"));
670 int value = chooser.showSaveDialog(this);
672 if (value == JalviewFileChooser.APPROVE_OPTION)
676 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
677 File outFile = chooser.getSelectedFile();
679 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
681 while ((data = in.readLine()) != null)
683 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
690 } catch (Exception ex)
692 ex.printStackTrace();