2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5.1)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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.*;
25 import jalview.datamodel.*;
28 import jalview.schemes.*;
29 import jalview.ws.ebi.EBIFetchClient;
31 import java.awt.BorderLayout;
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)
57 this.pdbentry = pdbentry;
61 this.protocol = protocol;
66 } catch (Exception ex)
71 StringBuffer title = new StringBuffer(seq[0].getName() + ":"
72 + pdbentry.getFile());
74 pdbcanvas = new PDBCanvas();
76 setContentPane(pdbcanvas);
78 if (pdbentry.getFile() != null)
82 tmpPDBFile = pdbentry.getFile();
83 PDBfile pdbfile = new PDBfile(tmpPDBFile,
84 jalview.io.AppletFormatAdapter.FILE);
86 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
88 } catch (java.io.IOException ex)
95 Thread worker = new Thread(this);
99 if (pdbentry.getProperty() != null)
101 if (pdbentry.getProperty().get("method") != null)
103 title.append(" Method: ");
104 title.append(pdbentry.getProperty().get("method"));
106 if (pdbentry.getProperty().get("chains") != null)
108 title.append(" Chain:");
109 title.append(pdbentry.getProperty().get("chains"));
112 Desktop.addInternalFrame(this, title.toString(), 400, 400);
119 EBIFetchClient ebi = new EBIFetchClient();
120 String query = "pdb:" + pdbentry.getId();
121 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
124 if (pdbentry.getFile() != null)
125 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
126 } catch (Exception ex)
128 pdbcanvas.errorMessage = "Error retrieving file: " + pdbentry.getId();
129 ex.printStackTrace();
133 private void jbInit() throws Exception
135 this.addKeyListener(new KeyAdapter()
137 public void keyPressed(KeyEvent evt)
139 pdbcanvas.keyPressed(evt);
143 this.setJMenuBar(jMenuBar1);
144 fileMenu.setText("File");
145 coloursMenu.setText("Colours");
146 saveMenu.setActionCommand("Save Image");
147 saveMenu.setText("Save As");
149 png.addActionListener(new ActionListener()
151 public void actionPerformed(ActionEvent e)
153 png_actionPerformed(e);
157 eps.addActionListener(new ActionListener()
159 public void actionPerformed(ActionEvent e)
161 eps_actionPerformed(e);
164 mapping.setText("View Mapping");
165 mapping.addActionListener(new ActionListener()
167 public void actionPerformed(ActionEvent e)
169 mapping_actionPerformed(e);
172 wire.setText("Wireframe");
173 wire.addActionListener(new ActionListener()
175 public void actionPerformed(ActionEvent e)
177 wire_actionPerformed(e);
180 depth.setSelected(true);
181 depth.setText("Depthcue");
182 depth.addActionListener(new ActionListener()
184 public void actionPerformed(ActionEvent e)
186 depth_actionPerformed(e);
189 zbuffer.setSelected(true);
190 zbuffer.setText("Z Buffering");
191 zbuffer.addActionListener(new ActionListener()
193 public void actionPerformed(ActionEvent e)
195 zbuffer_actionPerformed(e);
198 charge.setText("Charge & Cysteine");
199 charge.addActionListener(new ActionListener()
201 public void actionPerformed(ActionEvent e)
203 charge_actionPerformed(e);
206 chain.setText("By Chain");
207 chain.addActionListener(new ActionListener()
209 public void actionPerformed(ActionEvent e)
211 chain_actionPerformed(e);
214 seqButton.setSelected(true);
215 seqButton.setText("By Sequence");
216 seqButton.addActionListener(new ActionListener()
218 public void actionPerformed(ActionEvent e)
220 seqButton_actionPerformed(e);
223 allchains.setSelected(true);
224 allchains.setText("Show All Chains");
225 allchains.addItemListener(new ItemListener()
227 public void itemStateChanged(ItemEvent e)
229 allchains_itemStateChanged(e);
232 zappo.setText("Zappo");
233 zappo.addActionListener(new ActionListener()
235 public void actionPerformed(ActionEvent e)
237 zappo_actionPerformed(e);
240 taylor.setText("Taylor");
241 taylor.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
245 taylor_actionPerformed(e);
248 hydro.setText("Hydro");
249 hydro.addActionListener(new ActionListener()
251 public void actionPerformed(ActionEvent e)
253 hydro_actionPerformed(e);
256 helix.setText("Helix");
257 helix.addActionListener(new ActionListener()
259 public void actionPerformed(ActionEvent e)
261 helix_actionPerformed(e);
264 strand.setText("Strand");
265 strand.addActionListener(new ActionListener()
267 public void actionPerformed(ActionEvent e)
269 strand_actionPerformed(e);
272 turn.setText("Turn");
273 turn.addActionListener(new ActionListener()
275 public void actionPerformed(ActionEvent e)
277 turn_actionPerformed(e);
280 buried.setText("Buried");
281 buried.addActionListener(new ActionListener()
283 public void actionPerformed(ActionEvent e)
285 buried_actionPerformed(e);
288 user.setText("User Defined...");
289 user.addActionListener(new ActionListener()
291 public void actionPerformed(ActionEvent e)
293 user_actionPerformed(e);
296 viewMenu.setText("View");
297 background.setText("Background Colour...");
298 background.addActionListener(new ActionListener()
300 public void actionPerformed(ActionEvent e)
302 background_actionPerformed(e);
305 savePDB.setText("PDB File");
306 savePDB.addActionListener(new ActionListener()
308 public void actionPerformed(ActionEvent e)
310 savePDB_actionPerformed(e);
313 jMenuBar1.add(fileMenu);
314 jMenuBar1.add(coloursMenu);
315 jMenuBar1.add(viewMenu);
316 fileMenu.add(saveMenu);
317 fileMenu.add(mapping);
318 saveMenu.add(savePDB);
321 coloursMenu.add(seqButton);
322 coloursMenu.add(chain);
323 coloursMenu.add(charge);
324 coloursMenu.add(zappo);
325 coloursMenu.add(taylor);
326 coloursMenu.add(hydro);
327 coloursMenu.add(helix);
328 coloursMenu.add(strand);
329 coloursMenu.add(turn);
330 coloursMenu.add(buried);
331 coloursMenu.add(user);
332 coloursMenu.add(background);
333 ButtonGroup bg = new ButtonGroup();
346 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
348 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
349 .getUserColourSchemes().keys();
351 while (userColours.hasMoreElements())
353 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
354 userColours.nextElement().toString());
355 radioItem.setName("USER_DEFINED");
356 radioItem.addMouseListener(new MouseAdapter()
358 public void mousePressed(MouseEvent evt)
360 if (evt.isControlDown()
361 || SwingUtilities.isRightMouseButton(evt))
364 .removeActionListener(radioItem.getActionListeners()[0]);
366 int option = JOptionPane.showInternalConfirmDialog(
367 jalview.gui.Desktop.desktop,
368 "Remove from default list?",
369 "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, this
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();
567 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
568 cap.setText(pdbcanvas.mappingDetails.toString());
571 public void allchains_itemStateChanged(ItemEvent e)
573 pdbcanvas.setAllchainsVisible(allchains.getState());
576 public void zappo_actionPerformed(ActionEvent e)
578 pdbcanvas.bysequence = false;
579 pdbcanvas.pdb.setColours(new ZappoColourScheme());
580 pdbcanvas.redrawneeded = true;
584 public void taylor_actionPerformed(ActionEvent e)
586 pdbcanvas.bysequence = false;
587 pdbcanvas.pdb.setColours(new TaylorColourScheme());
588 pdbcanvas.redrawneeded = true;
592 public void helix_actionPerformed(ActionEvent e)
594 pdbcanvas.bysequence = false;
595 pdbcanvas.pdb.setColours(new HelixColourScheme());
596 pdbcanvas.redrawneeded = true;
600 public void strand_actionPerformed(ActionEvent e)
602 pdbcanvas.bysequence = false;
603 pdbcanvas.pdb.setColours(new StrandColourScheme());
604 pdbcanvas.redrawneeded = true;
608 public void turn_actionPerformed(ActionEvent e)
610 pdbcanvas.bysequence = false;
611 pdbcanvas.pdb.setColours(new TurnColourScheme());
612 pdbcanvas.redrawneeded = true;
616 public void buried_actionPerformed(ActionEvent e)
618 pdbcanvas.bysequence = false;
619 pdbcanvas.pdb.setColours(new BuriedColourScheme());
620 pdbcanvas.redrawneeded = true;
624 public void user_actionPerformed(ActionEvent e)
626 if (e.getActionCommand().equals("User Defined..."))
628 // new UserDefinedColours(pdbcanvas, null);
632 UserColourScheme udc = (UserColourScheme) UserDefinedColours
633 .getUserColourSchemes().get(e.getActionCommand());
635 pdbcanvas.pdb.setColours(udc);
636 pdbcanvas.redrawneeded = true;
641 public void background_actionPerformed(ActionEvent e)
643 java.awt.Color col = JColorChooser.showDialog(this,
644 "Select Background Colour", pdbcanvas.backgroundColour);
648 pdbcanvas.backgroundColour = col;
649 pdbcanvas.redrawneeded = true;
654 public void savePDB_actionPerformed(ActionEvent e)
656 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
657 .getProperty("LAST_DIRECTORY"));
659 chooser.setFileView(new JalviewFileView());
660 chooser.setDialogTitle("Save PDB File");
661 chooser.setToolTipText("Save");
663 int value = chooser.showSaveDialog(this);
665 if (value == JalviewFileChooser.APPROVE_OPTION)
669 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
670 File outFile = chooser.getSelectedFile();
672 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
674 while ((data = in.readLine()) != null)
676 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
682 } catch (Exception ex)
684 ex.printStackTrace();