2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.event.*;
26 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import jalview.util.MessageManager;
31 import jalview.ws.ebi.EBIFetchClient;
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)
56 this.pdbentry = pdbentry;
60 this.protocol = protocol;
65 } catch (Exception ex)
70 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
71 + pdbentry.getFile());
73 pdbcanvas = new PDBCanvas();
75 setContentPane(pdbcanvas);
77 if (pdbentry.getFile() != null)
81 tmpPDBFile = pdbentry.getFile();
82 PDBfile pdbfile = new PDBfile(tmpPDBFile,
83 jalview.io.AppletFormatAdapter.FILE);
85 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
87 } catch (java.io.IOException ex)
94 Thread worker = new Thread(this);
98 if (pdbentry.getProperty() != null)
100 if (pdbentry.getProperty().get("method") != null)
102 title.append(" Method: ");
103 title.append(pdbentry.getProperty().get("method"));
105 if (pdbentry.getProperty().get("chains") != null)
107 title.append(" Chain:");
108 title.append(pdbentry.getProperty().get("chains"));
111 Desktop.addInternalFrame(this, title.toString(), 400, 400);
118 EBIFetchClient ebi = new EBIFetchClient();
119 String query = "pdb:" + pdbentry.getId();
120 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
123 if (pdbentry.getFile() != null)
124 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
125 } catch (Exception ex)
127 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
128 ex.printStackTrace();
132 private void jbInit() throws Exception
134 this.addKeyListener(new KeyAdapter()
136 public void keyPressed(KeyEvent evt)
138 pdbcanvas.keyPressed(evt);
142 this.setJMenuBar(jMenuBar1);
143 fileMenu.setText(MessageManager.getString("action.file"));
144 coloursMenu.setText(MessageManager.getString("label.colours"));
145 saveMenu.setActionCommand(MessageManager.getString("action.save_image"));
146 saveMenu.setText(MessageManager.getString("action.save_as"));
148 png.addActionListener(new ActionListener()
150 public void actionPerformed(ActionEvent e)
152 png_actionPerformed(e);
156 eps.addActionListener(new ActionListener()
158 public void actionPerformed(ActionEvent e)
160 eps_actionPerformed(e);
163 mapping.setText(MessageManager.getString("label.view_mapping"));
164 mapping.addActionListener(new ActionListener()
166 public void actionPerformed(ActionEvent e)
168 mapping_actionPerformed(e);
171 wire.setText(MessageManager.getString("label.wireframe"));
172 wire.addActionListener(new ActionListener()
174 public void actionPerformed(ActionEvent e)
176 wire_actionPerformed(e);
179 depth.setSelected(true);
180 depth.setText(MessageManager.getString("label.depthcue"));
181 depth.addActionListener(new ActionListener()
183 public void actionPerformed(ActionEvent e)
185 depth_actionPerformed(e);
188 zbuffer.setSelected(true);
189 zbuffer.setText(MessageManager.getString("label.z_buffering"));
190 zbuffer.addActionListener(new ActionListener()
192 public void actionPerformed(ActionEvent e)
194 zbuffer_actionPerformed(e);
197 charge.setText(MessageManager.getString("label.charge_cysteine"));
198 charge.addActionListener(new ActionListener()
200 public void actionPerformed(ActionEvent e)
202 charge_actionPerformed(e);
205 chain.setText(MessageManager.getString("action.by_chain"));
206 chain.addActionListener(new ActionListener()
208 public void actionPerformed(ActionEvent e)
210 chain_actionPerformed(e);
213 seqButton.setSelected(true);
214 seqButton.setText(MessageManager.getString("action.by_sequence"));
215 seqButton.addActionListener(new ActionListener()
217 public void actionPerformed(ActionEvent e)
219 seqButton_actionPerformed(e);
222 allchains.setSelected(true);
223 allchains.setText(MessageManager.getString("label.show_all_chains"));
224 allchains.addItemListener(new ItemListener()
226 public void itemStateChanged(ItemEvent e)
228 allchains_itemStateChanged(e);
231 zappo.setText(MessageManager.getString("label.zappo"));
232 zappo.addActionListener(new ActionListener()
234 public void actionPerformed(ActionEvent e)
236 zappo_actionPerformed(e);
239 taylor.setText(MessageManager.getString("label.taylor"));
240 taylor.addActionListener(new ActionListener()
242 public void actionPerformed(ActionEvent e)
244 taylor_actionPerformed(e);
247 hydro.setText(MessageManager.getString("label.hydrophobicity"));
248 hydro.addActionListener(new ActionListener()
250 public void actionPerformed(ActionEvent e)
252 hydro_actionPerformed(e);
255 helix.setText(MessageManager.getString("label.helix_propensity"));
256 helix.addActionListener(new ActionListener()
258 public void actionPerformed(ActionEvent e)
260 helix_actionPerformed(e);
263 strand.setText(MessageManager.getString("label.strand_propensity"));
264 strand.addActionListener(new ActionListener()
266 public void actionPerformed(ActionEvent e)
268 strand_actionPerformed(e);
271 turn.setText(MessageManager.getString("label.turn_propensity"));
272 turn.addActionListener(new ActionListener()
274 public void actionPerformed(ActionEvent e)
276 turn_actionPerformed(e);
279 buried.setText(MessageManager.getString("label.buried_index"));
280 buried.addActionListener(new ActionListener()
282 public void actionPerformed(ActionEvent e)
284 buried_actionPerformed(e);
287 user.setText(MessageManager.getString("action.user_defined"));
288 user.addActionListener(new ActionListener()
290 public void actionPerformed(ActionEvent e)
292 user_actionPerformed(e);
295 viewMenu.setText(MessageManager.getString("action.view"));
296 background.setText(MessageManager.getString("label.background_colour") + "...");
297 background.addActionListener(new ActionListener()
299 public void actionPerformed(ActionEvent e)
301 background_actionPerformed(e);
304 savePDB.setText(MessageManager.getString("label.pdb_file"));
305 savePDB.addActionListener(new ActionListener()
307 public void actionPerformed(ActionEvent e)
309 savePDB_actionPerformed(e);
312 jMenuBar1.add(fileMenu);
313 jMenuBar1.add(coloursMenu);
314 jMenuBar1.add(viewMenu);
315 fileMenu.add(saveMenu);
316 fileMenu.add(mapping);
317 saveMenu.add(savePDB);
320 coloursMenu.add(seqButton);
321 coloursMenu.add(chain);
322 coloursMenu.add(charge);
323 coloursMenu.add(zappo);
324 coloursMenu.add(taylor);
325 coloursMenu.add(hydro);
326 coloursMenu.add(helix);
327 coloursMenu.add(strand);
328 coloursMenu.add(turn);
329 coloursMenu.add(buried);
330 coloursMenu.add(user);
331 coloursMenu.add(background);
332 ButtonGroup bg = new ButtonGroup();
345 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
347 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
348 .getUserColourSchemes().keys();
350 while (userColours.hasMoreElements())
352 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
353 userColours.nextElement().toString());
354 radioItem.setName("USER_DEFINED");
355 radioItem.addMouseListener(new MouseAdapter()
357 public void mousePressed(MouseEvent evt)
359 if (evt.isControlDown()
360 || SwingUtilities.isRightMouseButton(evt))
362 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
364 int option = JOptionPane.showInternalConfirmDialog(
365 jalview.gui.Desktop.desktop,
366 MessageManager.getString("label.remove_from_default_list"),
367 MessageManager.getString("label.remove_user_defined_colour"),
368 JOptionPane.YES_NO_OPTION);
369 if (option == JOptionPane.YES_OPTION)
371 jalview.gui.UserDefinedColours
372 .removeColourFromDefaults(radioItem.getText());
373 coloursMenu.remove(radioItem);
377 radioItem.addActionListener(new ActionListener()
379 public void actionPerformed(ActionEvent evt)
381 user_actionPerformed(evt);
388 radioItem.addActionListener(new ActionListener()
390 public void actionPerformed(ActionEvent evt)
392 user_actionPerformed(evt);
395 coloursMenu.add(radioItem);
402 viewMenu.add(zbuffer);
403 viewMenu.add(allchains);
406 JMenuBar jMenuBar1 = new JMenuBar();
408 JMenu fileMenu = new JMenu();
410 JMenu coloursMenu = new JMenu();
412 JMenu saveMenu = new JMenu();
414 JMenuItem png = new JMenuItem();
416 JMenuItem eps = new JMenuItem();
418 JMenuItem mapping = new JMenuItem();
420 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
422 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
424 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
426 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
428 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
430 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
432 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
434 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
436 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
438 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
440 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
442 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
444 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
446 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
448 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
450 JMenu viewMenu = new JMenu();
452 JMenuItem background = new JMenuItem();
454 JMenuItem savePDB = new JMenuItem();
462 public void eps_actionPerformed(ActionEvent e)
464 makePDBImage(jalview.util.ImageMaker.EPS);
473 public void png_actionPerformed(ActionEvent e)
475 makePDBImage(jalview.util.ImageMaker.PNG);
478 void makePDBImage(int type)
480 int width = pdbcanvas.getWidth();
481 int height = pdbcanvas.getHeight();
483 jalview.util.ImageMaker im;
485 if (type == jalview.util.ImageMaker.PNG)
487 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
488 "Make PNG image from view", width, height, null, null);
492 im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
493 "Make EPS file from view", width, height, null,
497 if (im.getGraphics() != null)
499 pdbcanvas.drawAll(im.getGraphics(), width, height);
504 public void charge_actionPerformed(ActionEvent e)
506 pdbcanvas.bysequence = false;
507 pdbcanvas.pdb.setChargeColours();
508 pdbcanvas.redrawneeded = true;
512 public void hydro_actionPerformed(ActionEvent e)
514 pdbcanvas.bysequence = false;
515 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
516 pdbcanvas.redrawneeded = true;
520 public void chain_actionPerformed(ActionEvent e)
522 pdbcanvas.bysequence = false;
523 pdbcanvas.pdb.setChainColours();
524 pdbcanvas.redrawneeded = true;
528 public void zbuffer_actionPerformed(ActionEvent e)
530 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
531 pdbcanvas.redrawneeded = true;
535 public void molecule_actionPerformed(ActionEvent e)
537 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
538 pdbcanvas.redrawneeded = true;
542 public void depth_actionPerformed(ActionEvent e)
544 pdbcanvas.depthcue = !pdbcanvas.depthcue;
545 pdbcanvas.redrawneeded = true;
549 public void wire_actionPerformed(ActionEvent e)
551 pdbcanvas.wire = !pdbcanvas.wire;
552 pdbcanvas.redrawneeded = true;
556 public void seqButton_actionPerformed(ActionEvent e)
558 pdbcanvas.bysequence = true;
559 pdbcanvas.updateSeqColours();
562 public void mapping_actionPerformed(ActionEvent e)
564 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
567 cap.setText(pdbcanvas.mappingDetails.toString());
568 Desktop.addInternalFrame(cap, MessageManager.getString("label.pdb_sequence_mapping"), 550, 600);
569 } catch (OutOfMemoryError oom)
571 new OOMWarning("Opening sequence to structure mapping report", oom);
576 public void allchains_itemStateChanged(ItemEvent e)
578 pdbcanvas.setAllchainsVisible(allchains.getState());
581 public void zappo_actionPerformed(ActionEvent e)
583 pdbcanvas.bysequence = false;
584 pdbcanvas.pdb.setColours(new ZappoColourScheme());
585 pdbcanvas.redrawneeded = true;
589 public void taylor_actionPerformed(ActionEvent e)
591 pdbcanvas.bysequence = false;
592 pdbcanvas.pdb.setColours(new TaylorColourScheme());
593 pdbcanvas.redrawneeded = true;
597 public void helix_actionPerformed(ActionEvent e)
599 pdbcanvas.bysequence = false;
600 pdbcanvas.pdb.setColours(new HelixColourScheme());
601 pdbcanvas.redrawneeded = true;
605 public void strand_actionPerformed(ActionEvent e)
607 pdbcanvas.bysequence = false;
608 pdbcanvas.pdb.setColours(new StrandColourScheme());
609 pdbcanvas.redrawneeded = true;
613 public void turn_actionPerformed(ActionEvent e)
615 pdbcanvas.bysequence = false;
616 pdbcanvas.pdb.setColours(new TurnColourScheme());
617 pdbcanvas.redrawneeded = true;
621 public void buried_actionPerformed(ActionEvent e)
623 pdbcanvas.bysequence = false;
624 pdbcanvas.pdb.setColours(new BuriedColourScheme());
625 pdbcanvas.redrawneeded = true;
629 public void user_actionPerformed(ActionEvent e)
631 if (e.getActionCommand().equals(MessageManager.getString("action.user_defined")))
633 // new UserDefinedColours(pdbcanvas, null);
637 UserColourScheme udc = (UserColourScheme) UserDefinedColours
638 .getUserColourSchemes().get(e.getActionCommand());
640 pdbcanvas.pdb.setColours(udc);
641 pdbcanvas.redrawneeded = true;
646 public void background_actionPerformed(ActionEvent e)
648 java.awt.Color col = JColorChooser.showDialog(this,
649 MessageManager.getString("label.select_backgroud_colour"), pdbcanvas.backgroundColour);
653 pdbcanvas.backgroundColour = col;
654 pdbcanvas.redrawneeded = true;
659 public void savePDB_actionPerformed(ActionEvent e)
661 JalviewFileChooser chooser = new JalviewFileChooser(
662 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
664 chooser.setFileView(new JalviewFileView());
665 chooser.setDialogTitle("Save PDB File");
666 chooser.setToolTipText(MessageManager.getString("action.save"));
668 int value = chooser.showSaveDialog(this);
670 if (value == JalviewFileChooser.APPROVE_OPTION)
674 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
675 File outFile = chooser.getSelectedFile();
677 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
679 while ((data = in.readLine()) != null)
681 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
688 } catch (Exception ex)
690 ex.printStackTrace();