2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 import java.awt.event.*;
26 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import jalview.ws.ebi.EBIFetchClient;
32 import java.awt.BorderLayout;
34 public class PDBViewer
35 extends JInternalFrame implements Runnable
39 * The associated sequence in an alignment
50 public PDBViewer(PDBEntry pdbentry,
57 this.pdbentry = pdbentry;
61 this.protocol = protocol;
73 StringBuffer title = new StringBuffer(seq[0].getName()
75 + pdbentry.getFile());
77 pdbcanvas = new PDBCanvas();
79 setContentPane(pdbcanvas);
81 if (pdbentry.getFile() != null)
85 tmpPDBFile = pdbentry.getFile();
86 PDBfile pdbfile = new PDBfile(tmpPDBFile,
87 jalview.io.AppletFormatAdapter.FILE);
89 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
92 catch (java.io.IOException ex)
99 Thread worker = new Thread(this);
105 if (pdbentry.getProperty() != null)
107 if (pdbentry.getProperty().get("method") != null)
109 title.append(" Method: ");
110 title.append(pdbentry.getProperty().get("method"));
112 if (pdbentry.getProperty().get("chains") != null)
114 title.append(" Chain:");
115 title.append(pdbentry.getProperty().get("chains"));
118 Desktop.addInternalFrame(this, title.toString(), 400, 400);
125 EBIFetchClient ebi = new EBIFetchClient();
126 String query = "pdb:" + pdbentry.getId();
127 pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
130 if(pdbentry.getFile()!=null)
131 pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
135 pdbcanvas.errorMessage = "Error retrieving file: "+pdbentry.getId();
136 ex.printStackTrace();
140 private void jbInit()
143 this.addKeyListener(new KeyAdapter()
145 public void keyPressed(KeyEvent evt)
147 pdbcanvas.keyPressed(evt);
151 this.setJMenuBar(jMenuBar1);
152 fileMenu.setText("File");
153 coloursMenu.setText("Colours");
154 saveMenu.setActionCommand("Save Image");
155 saveMenu.setText("Save As");
157 png.addActionListener(new ActionListener()
159 public void actionPerformed(ActionEvent e)
161 png_actionPerformed(e);
165 eps.addActionListener(new ActionListener()
167 public void actionPerformed(ActionEvent e)
169 eps_actionPerformed(e);
172 mapping.setText("View Mapping");
173 mapping.addActionListener(new ActionListener()
175 public void actionPerformed(ActionEvent e)
177 mapping_actionPerformed(e);
180 wire.setText("Wireframe");
181 wire.addActionListener(new ActionListener()
183 public void actionPerformed(ActionEvent e)
185 wire_actionPerformed(e);
188 depth.setSelected(true);
189 depth.setText("Depthcue");
190 depth.addActionListener(new ActionListener()
192 public void actionPerformed(ActionEvent e)
194 depth_actionPerformed(e);
197 zbuffer.setSelected(true);
198 zbuffer.setText("Z Buffering");
199 zbuffer.addActionListener(new ActionListener()
201 public void actionPerformed(ActionEvent e)
203 zbuffer_actionPerformed(e);
206 charge.setText("Charge & Cysteine");
207 charge.addActionListener(new ActionListener()
209 public void actionPerformed(ActionEvent e)
211 charge_actionPerformed(e);
214 chain.setText("By Chain");
215 chain.addActionListener(new ActionListener()
217 public void actionPerformed(ActionEvent e)
219 chain_actionPerformed(e);
222 seqButton.setSelected(true);
223 seqButton.setText("By Sequence");
224 seqButton.addActionListener(new ActionListener()
226 public void actionPerformed(ActionEvent e)
228 seqButton_actionPerformed(e);
231 allchains.setSelected(true);
232 allchains.setText("Show All Chains");
233 allchains.addItemListener(new ItemListener()
235 public void itemStateChanged(ItemEvent e)
237 allchains_itemStateChanged(e);
240 zappo.setText("Zappo");
241 zappo.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
245 zappo_actionPerformed(e);
248 taylor.setText("Taylor");
249 taylor.addActionListener(new ActionListener()
251 public void actionPerformed(ActionEvent e)
253 taylor_actionPerformed(e);
256 hydro.setText("Hydro");
257 hydro.addActionListener(new ActionListener()
259 public void actionPerformed(ActionEvent e)
261 hydro_actionPerformed(e);
264 helix.setText("Helix");
265 helix.addActionListener(new ActionListener()
267 public void actionPerformed(ActionEvent e)
269 helix_actionPerformed(e);
272 strand.setText("Strand");
273 strand.addActionListener(new ActionListener()
275 public void actionPerformed(ActionEvent e)
277 strand_actionPerformed(e);
280 turn.setText("Turn");
281 turn.addActionListener(new ActionListener()
283 public void actionPerformed(ActionEvent e)
285 turn_actionPerformed(e);
288 buried.setText("Buried");
289 buried.addActionListener(new ActionListener()
291 public void actionPerformed(ActionEvent e)
293 buried_actionPerformed(e);
296 user.setText("User Defined...");
297 user.addActionListener(new ActionListener()
299 public void actionPerformed(ActionEvent e)
301 user_actionPerformed(e);
304 viewMenu.setText("View");
305 background.setText("Background Colour...");
306 background.addActionListener(new ActionListener()
308 public void actionPerformed(ActionEvent e)
310 background_actionPerformed(e);
313 savePDB.setText("PDB File");
314 savePDB.addActionListener(new ActionListener()
316 public void actionPerformed(ActionEvent e)
318 savePDB_actionPerformed(e);
321 jMenuBar1.add(fileMenu);
322 jMenuBar1.add(coloursMenu);
323 jMenuBar1.add(viewMenu);
324 fileMenu.add(saveMenu);
325 fileMenu.add(mapping);
326 saveMenu.add(savePDB);
329 coloursMenu.add(seqButton);
330 coloursMenu.add(chain);
331 coloursMenu.add(charge);
332 coloursMenu.add(zappo);
333 coloursMenu.add(taylor);
334 coloursMenu.add(hydro);
335 coloursMenu.add(helix);
336 coloursMenu.add(strand);
337 coloursMenu.add(turn);
338 coloursMenu.add(buried);
339 coloursMenu.add(user);
340 coloursMenu.add(background);
341 ButtonGroup bg = new ButtonGroup();
354 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
356 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
357 getUserColourSchemes().keys();
359 while (userColours.hasMoreElements())
361 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
363 nextElement().toString());
364 radioItem.setName("USER_DEFINED");
365 radioItem.addMouseListener(new MouseAdapter()
367 public void mousePressed(MouseEvent evt)
369 if (evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
371 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
373 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.
375 "Remove from default list?",
376 "Remove user defined colour",
377 JOptionPane.YES_NO_OPTION);
378 if (option == JOptionPane.YES_OPTION)
380 jalview.gui.UserDefinedColours.removeColourFromDefaults(
381 radioItem.getText());
382 coloursMenu.remove(radioItem);
386 radioItem.addActionListener(new ActionListener()
388 public void actionPerformed(ActionEvent evt)
390 user_actionPerformed(evt);
397 radioItem.addActionListener(new ActionListener()
399 public void actionPerformed(ActionEvent evt)
401 user_actionPerformed(evt);
404 coloursMenu.add(radioItem);
411 viewMenu.add(zbuffer);
412 viewMenu.add(allchains);
415 JMenuBar jMenuBar1 = new JMenuBar();
416 JMenu fileMenu = new JMenu();
417 JMenu coloursMenu = new JMenu();
418 JMenu saveMenu = new JMenu();
419 JMenuItem png = new JMenuItem();
420 JMenuItem eps = new JMenuItem();
421 JMenuItem mapping = new JMenuItem();
422 JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
423 JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
424 JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
425 JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
427 JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
428 JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
429 JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
430 JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
431 JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
432 JRadioButtonMenuItem zappo = new JRadioButtonMenuItem();
433 JRadioButtonMenuItem user = new JRadioButtonMenuItem();
434 JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
435 JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
436 JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
437 JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
438 JMenu viewMenu = new JMenu();
439 JMenuItem background = new JMenuItem();
440 JMenuItem savePDB = new JMenuItem();
445 * @param e DOCUMENT ME!
447 public void eps_actionPerformed(ActionEvent e)
449 makePDBImage(jalview.util.ImageMaker.EPS);
455 * @param e DOCUMENT ME!
457 public void png_actionPerformed(ActionEvent e)
459 makePDBImage(jalview.util.ImageMaker.PNG);
462 void makePDBImage(int type)
464 int width = pdbcanvas.getWidth();
465 int height = pdbcanvas.getHeight();
467 jalview.util.ImageMaker im;
469 if (type == jalview.util.ImageMaker.PNG)
471 im = new jalview.util.ImageMaker(this,
472 jalview.util.ImageMaker.PNG,
473 "Make PNG image from view",
479 im = new jalview.util.ImageMaker(this,
480 jalview.util.ImageMaker.EPS,
481 "Make EPS file from view",
483 null, this.getTitle());
486 if (im.getGraphics() != null)
488 pdbcanvas.drawAll(im.getGraphics(), width, height);
493 public void charge_actionPerformed(ActionEvent e)
495 pdbcanvas.bysequence = false;
496 pdbcanvas.pdb.setChargeColours();
497 pdbcanvas.redrawneeded = true;
501 public void hydro_actionPerformed(ActionEvent e)
503 pdbcanvas.bysequence = false;
504 pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
505 pdbcanvas.redrawneeded = true;
509 public void chain_actionPerformed(ActionEvent e)
511 pdbcanvas.bysequence = false;
512 pdbcanvas.pdb.setChainColours();
513 pdbcanvas.redrawneeded = true;
517 public void zbuffer_actionPerformed(ActionEvent e)
519 pdbcanvas.zbuffer = !pdbcanvas.zbuffer;
520 pdbcanvas.redrawneeded = true;
524 public void molecule_actionPerformed(ActionEvent e)
526 pdbcanvas.bymolecule = !pdbcanvas.bymolecule;
527 pdbcanvas.redrawneeded = true;
531 public void depth_actionPerformed(ActionEvent e)
533 pdbcanvas.depthcue = !pdbcanvas.depthcue;
534 pdbcanvas.redrawneeded = true;
538 public void wire_actionPerformed(ActionEvent e)
540 pdbcanvas.wire = !pdbcanvas.wire;
541 pdbcanvas.redrawneeded = true;
545 public void seqButton_actionPerformed(ActionEvent e)
547 pdbcanvas.bysequence = true;
548 pdbcanvas.updateSeqColours();
551 public void mapping_actionPerformed(ActionEvent e)
553 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
554 Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
555 cap.setText(pdbcanvas.mappingDetails.toString());
558 public void allchains_itemStateChanged(ItemEvent e)
560 pdbcanvas.setAllchainsVisible(allchains.getState());
564 public void zappo_actionPerformed(ActionEvent e)
566 pdbcanvas.bysequence = false;
567 pdbcanvas.pdb.setColours(new ZappoColourScheme());
568 pdbcanvas.redrawneeded = true;
572 public void taylor_actionPerformed(ActionEvent e)
574 pdbcanvas.bysequence = false;
575 pdbcanvas.pdb.setColours(new TaylorColourScheme());
576 pdbcanvas.redrawneeded = true;
580 public void helix_actionPerformed(ActionEvent e)
582 pdbcanvas.bysequence = false;
583 pdbcanvas.pdb.setColours(new HelixColourScheme());
584 pdbcanvas.redrawneeded = true;
588 public void strand_actionPerformed(ActionEvent e)
590 pdbcanvas.bysequence = false;
591 pdbcanvas.pdb.setColours(new StrandColourScheme());
592 pdbcanvas.redrawneeded = true;
596 public void turn_actionPerformed(ActionEvent e)
598 pdbcanvas.bysequence = false;
599 pdbcanvas.pdb.setColours(new TurnColourScheme());
600 pdbcanvas.redrawneeded = true;
604 public void buried_actionPerformed(ActionEvent e)
606 pdbcanvas.bysequence = false;
607 pdbcanvas.pdb.setColours(new BuriedColourScheme());
608 pdbcanvas.redrawneeded = true;
612 public void user_actionPerformed(ActionEvent e)
614 if (e.getActionCommand().equals("User Defined..."))
616 // new UserDefinedColours(pdbcanvas, null);
620 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
621 getUserColourSchemes().get(e.getActionCommand());
623 pdbcanvas.pdb.setColours(udc);
624 pdbcanvas.redrawneeded = true;
629 public void background_actionPerformed(ActionEvent e)
631 java.awt.Color col = JColorChooser.showDialog(this,
632 "Select Background Colour",
633 pdbcanvas.backgroundColour);
637 pdbcanvas.backgroundColour = col;
638 pdbcanvas.redrawneeded = true;
643 public void savePDB_actionPerformed(ActionEvent e)
645 JalviewFileChooser chooser = new JalviewFileChooser(
646 jalview.bin.Cache.getProperty(
649 chooser.setFileView(new JalviewFileView());
650 chooser.setDialogTitle("Save PDB File");
651 chooser.setToolTipText("Save");
653 int value = chooser.showSaveDialog(this);
655 if (value == JalviewFileChooser.APPROVE_OPTION)
659 BufferedReader in = new BufferedReader(new FileReader(tmpPDBFile));
660 File outFile = chooser.getSelectedFile();
662 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
664 while ( (data = in.readLine()) != null)
667 ! (data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1)
677 ex.printStackTrace();