fixed pdbentry creation and multiple uniprot or pdb entry retrieval.
authorjprocter <Jim Procter>
Fri, 9 Dec 2005 16:02:40 +0000 (16:02 +0000)
committerjprocter <Jim Procter>
Fri, 9 Dec 2005 16:02:40 +0000 (16:02 +0000)
src/MCview/PDBViewer.java
src/jalview/gui/SequenceFetcher.java

index 50a4a36..f0b37df 100755 (executable)
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
- */\r
-package MCview;\r
-\r
-import javax.swing.*;\r
-import java.awt.event.*;\r
-import jalview.datamodel.*;\r
-import jalview.schemes.*;\r
-import jalview.gui.*;\r
-import jalview.io.EBIFetchClient;\r
-import java.awt.event.ActionListener;\r
-import java.awt.event.ActionEvent;\r
-\r
-public class PDBViewer extends JInternalFrame implements Runnable\r
-{\r
-  PDBEntry pdb;\r
-  Sequence sequence;\r
-  PDBCanvas pdbcanvas;\r
-\r
-\r
-  public PDBViewer(PDBEntry entry,\r
-                   Sequence seq,\r
-                   SeqCanvas seqcanvas)\r
-  {\r
-    /*Uncomment this to modify in Jbuilder\r
-    try\r
-    {\r
-      jbInit();\r
-    }\r
-    catch (Exception ex)\r
-    {\r
-      ex.printStackTrace();\r
-    }*/\r
-\r
-\r
-    pdb = entry;\r
-    sequence = seq;\r
-\r
-    Thread worker = new Thread(this);\r
-    worker.start();\r
-\r
-    pdbcanvas = new PDBCanvas(seqcanvas, seq);\r
-\r
-    setContentPane(pdbcanvas);\r
-    StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId());\r
-    if(pdb.getProperty()!=null)\r
-    {\r
-      title.append( " Method: " );\r
-      title.append(pdb.getProperty().get("method"));\r
-      title.append( " Chain:" );\r
-      title.append( pdb.getProperty().get("chains"));\r
-    }\r
-\r
-     Desktop.addInternalFrame(this,title.toString(),400, 400);\r
-  }\r
-\r
-  public void run()\r
-  {\r
-    try\r
-    {\r
-      EBIFetchClient ebi = new EBIFetchClient();\r
-      String[] result = ebi.fetchData("pdb:" + pdb.getId(), "default","raw");\r
-\r
-      PDBfile pdbfile = new PDBfile(result);\r
-\r
-      pdbcanvas.setPDBFile(pdbfile);\r
-\r
-      try\r
-      {\r
-        jbInit();\r
-      }\r
-      catch (Exception ex)\r
-      {\r
-        ex.printStackTrace();\r
-      }\r
-    }\r
-    catch (Exception ex)\r
-    {\r
-      ex.printStackTrace();\r
-    }\r
-  }\r
-\r
-  private void jbInit()\r
-      throws Exception\r
-  {\r
-    this.addKeyListener(new KeyAdapter()\r
-        {\r
-            public void keyPressed(KeyEvent evt)\r
-            {\r
-              pdbcanvas.keyPressed(evt);\r
-            }\r
-        });\r
-\r
-    this.setJMenuBar(jMenuBar1);\r
-    fileMenu.setText("File");\r
-    coloursMenu.setText("Colours");\r
-    saveMenu.setActionCommand("Save Image");\r
-    saveMenu.setText("Save As");\r
-    png.setText("PNG");\r
-    png.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        png_actionPerformed(e);\r
-      }\r
-    });\r
-    eps.setText("EPS");\r
-    eps.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        eps_actionPerformed(e);\r
-      }\r
-    });\r
-    mapping.setText("View Mapping");\r
-    mapping.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        mapping_actionPerformed(e);\r
-      }\r
-    });\r
-    wire.setText("Wireframe");\r
-    wire.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        wire_actionPerformed(e);\r
-      }\r
-    });\r
-    depth.setSelected(true);\r
-    depth.setText("Depthcue");\r
-    depth.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        depth_actionPerformed(e);\r
-      }\r
-    });\r
-    zbuffer.setSelected(true);\r
-    zbuffer.setText("Z Buffering");\r
-    zbuffer.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        zbuffer_actionPerformed(e);\r
-      }\r
-    });\r
-    charge.setText("Charge & Cysteine");\r
-    charge.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        charge_actionPerformed(e);\r
-      }\r
-    });\r
-    chain.setText("By Chain");\r
-    chain.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        chain_actionPerformed(e);\r
-      }\r
-    });\r
-    seqButton.setSelected(true);\r
-    seqButton.setText("By Sequence");\r
-    seqButton.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        seqButton_actionPerformed(e);\r
-      }\r
-    });\r
-    allchains.setSelected(true);\r
-    allchains.setText("Show All Chains");\r
-    allchains.addItemListener(new ItemListener()\r
-    {\r
-      public void itemStateChanged(ItemEvent e)\r
-      {\r
-        allchains_itemStateChanged(e);\r
-      }\r
-    });\r
-    zappo.setText("Zappo");\r
-    zappo.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        zappo_actionPerformed(e);\r
-      }\r
-    });\r
-    taylor.setText("Taylor");\r
-    taylor.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        taylor_actionPerformed(e);\r
-      }\r
-    });\r
-    hydro.setText("Hydro");\r
-    hydro.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        hydro_actionPerformed(e);\r
-      }\r
-    });\r
-    helix.setText("Helix");\r
-    helix.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        helix_actionPerformed(e);\r
-      }\r
-    });\r
-    strand.setText("Strand");\r
-    strand.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        strand_actionPerformed(e);\r
-      }\r
-    });\r
-    turn.setText("Turn");\r
-    turn.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        turn_actionPerformed(e);\r
-      }\r
-    });\r
-    buried.setText("Buried");\r
-    buried.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        buried_actionPerformed(e);\r
-      }\r
-    });\r
-    user.setText("User Defined...");\r
-    user.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        user_actionPerformed(e);\r
-      }\r
-    });\r
-    viewMenu.setText("View");\r
-    jMenuBar1.add(fileMenu);\r
-    jMenuBar1.add(coloursMenu);\r
-    jMenuBar1.add(viewMenu);\r
-    fileMenu.add(saveMenu);\r
-    fileMenu.add(mapping);\r
-    saveMenu.add(png);\r
-    saveMenu.add(eps);\r
-    coloursMenu.add(seqButton);\r
-    coloursMenu.add(chain);\r
-    coloursMenu.add(charge);\r
-    coloursMenu.add(zappo);\r
-    coloursMenu.add(taylor);\r
-    coloursMenu.add(hydro);\r
-    coloursMenu.add(helix);\r
-    coloursMenu.add(strand);\r
-    coloursMenu.add(turn);\r
-    coloursMenu.add(buried);\r
-    coloursMenu.add(user);\r
-    ButtonGroup bg = new ButtonGroup();\r
-    bg.add(seqButton);\r
-    bg.add(chain);\r
-    bg.add(charge);\r
-    bg.add(zappo);\r
-    bg.add(taylor);\r
-    bg.add(hydro);\r
-    bg.add(helix);\r
-    bg.add(strand);\r
-    bg.add(turn);\r
-    bg.add(buried);\r
-    bg.add(user);\r
-\r
-\r
-    if(jalview.gui.UserDefinedColours.getUserColourSchemes()!=null)\r
-    {\r
-      java.util.Enumeration userColours = jalview.gui.UserDefinedColours.\r
-          getUserColourSchemes().keys();\r
-\r
-      while (userColours.hasMoreElements())\r
-      {\r
-        final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.\r
-            nextElement().toString());\r
-        radioItem.setName("USER_DEFINED");\r
-        radioItem.addMouseListener(new MouseAdapter()\r
-            {\r
-              public void mousePressed(MouseEvent evt)\r
-              {\r
-                if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))\r
-                {\r
-                  radioItem.removeActionListener(radioItem.getActionListeners()[0]);\r
-\r
-                  int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,\r
-                      "Remove from default list?",\r
-                      "Remove user defined colour",\r
-                      JOptionPane.YES_NO_OPTION);\r
-                  if(option == JOptionPane.YES_OPTION)\r
-                  {\r
-                    jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());\r
-                    coloursMenu.remove(radioItem);\r
-                  }\r
-                  else\r
-                    radioItem.addActionListener(new ActionListener()\r
-                    {\r
-                      public void actionPerformed(ActionEvent evt)\r
-                      {\r
-                        user_actionPerformed(evt);\r
-                      }\r
-                    });\r
-                }\r
-              }\r
-            });\r
-        radioItem.addActionListener(new ActionListener()\r
-        {\r
-          public void actionPerformed(ActionEvent evt)\r
-          {\r
-            user_actionPerformed(evt);\r
-          }\r
-        });\r
-        coloursMenu.add(radioItem);\r
-        bg.add(radioItem);\r
-      }\r
-    }\r
-\r
-    viewMenu.add(wire);\r
-    viewMenu.add(depth);\r
-    viewMenu.add(zbuffer);\r
-    viewMenu.add(allchains);\r
-  }\r
-\r
-  JMenuBar jMenuBar1 = new JMenuBar();\r
-  JMenu fileMenu = new JMenu();\r
-  JMenu coloursMenu = new JMenu();\r
-  JMenu saveMenu = new JMenu();\r
-  JMenuItem png = new JMenuItem();\r
-  JMenuItem eps = new JMenuItem();\r
-  JMenuItem mapping = new JMenuItem();\r
-  JCheckBoxMenuItem wire = new JCheckBoxMenuItem();\r
-  JCheckBoxMenuItem depth = new JCheckBoxMenuItem();\r
-  JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();\r
-  JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();\r
-\r
-  JRadioButtonMenuItem charge = new JRadioButtonMenuItem();\r
-  JRadioButtonMenuItem chain = new JRadioButtonMenuItem();\r
-  JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();\r
-  JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();\r
-  JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();\r
-  JRadioButtonMenuItem zappo = new  JRadioButtonMenuItem();\r
-  JRadioButtonMenuItem user = new JRadioButtonMenuItem();\r
-  JRadioButtonMenuItem buried = new JRadioButtonMenuItem();\r
-  JRadioButtonMenuItem turn = new JRadioButtonMenuItem();\r
-  JRadioButtonMenuItem strand = new JRadioButtonMenuItem();\r
-  JRadioButtonMenuItem helix = new JRadioButtonMenuItem();\r
-  JMenu viewMenu = new JMenu();\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param e DOCUMENT ME!\r
-   */\r
-  public void eps_actionPerformed(ActionEvent e)\r
-  {\r
-    makePDBImage(jalview.util.ImageMaker.EPS);\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param e DOCUMENT ME!\r
-   */\r
-  public void png_actionPerformed(ActionEvent e)\r
-  {\r
-     makePDBImage(jalview.util.ImageMaker.PNG);\r
-  }\r
-\r
-  void makePDBImage(int type)\r
-  {\r
-    int width = pdbcanvas.getWidth();\r
-    int height = pdbcanvas.getHeight();\r
-\r
-    jalview.util.ImageMaker im;\r
-\r
-    if (type == jalview.util.ImageMaker.PNG)\r
-      im = new jalview.util.ImageMaker(this,\r
-                                       jalview.util.ImageMaker.PNG,\r
-                                       "Make PNG image from view",\r
-                                       width, height,\r
-                                       null, null);\r
-    else\r
-      im = new jalview.util.ImageMaker(this,\r
-                                       jalview.util.ImageMaker.EPS,\r
-                                       "Make EPS file from view",\r
-                                       width, height,\r
-                                       null, this.getTitle());\r
-\r
-    if (im.getGraphics() != null)\r
-    {\r
-      pdbcanvas.drawAll(im.getGraphics(), width, height);\r
-      im.writeImage();\r
-    }\r
-  }\r
-  public void charge_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.bysequence = false;\r
-    pdbcanvas.pdb.setChargeColours();\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void hydro_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.bysequence = false;\r
-    pdbcanvas.pdb.setColours(new HydrophobicColourScheme());\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void chain_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.bysequence = false;\r
-    pdbcanvas.pdb.setChainColours();\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void zbuffer_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.zbuffer = ! pdbcanvas.zbuffer;\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void molecule_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.bymolecule = ! pdbcanvas.bymolecule;\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void depth_actionPerformed(ActionEvent e)\r
-  {\r
-  pdbcanvas.depthcue = ! pdbcanvas.depthcue;\r
-  pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void wire_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.wire = ! pdbcanvas.wire;\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void seqButton_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.bysequence = true;\r
-    pdbcanvas.updateSeqColours();\r
-  }\r
-\r
-\r
-  public void mapping_actionPerformed(ActionEvent e)\r
-  {\r
-    jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();\r
-    Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);\r
-    cap.setText(pdbcanvas.mappingDetails.toString());\r
-  }\r
-\r
-  public void allchains_itemStateChanged(ItemEvent e)\r
-  {\r
-    pdbcanvas.setAllchainsVisible(allchains.getState());\r
-  }\r
-\r
-  public void zappo_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.bysequence = false;\r
-    pdbcanvas.pdb.setColours(new ZappoColourScheme());\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void taylor_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.bysequence = false;\r
-    pdbcanvas.pdb.setColours(new TaylorColourScheme());\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void helix_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.bysequence = false;\r
-    pdbcanvas.pdb.setColours(new HelixColourScheme());\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void strand_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.bysequence = false;\r
-    pdbcanvas.pdb.setColours(new StrandColourScheme());\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void turn_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.bysequence = false;\r
-    pdbcanvas.pdb.setColours(new TurnColourScheme());\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void buried_actionPerformed(ActionEvent e)\r
-  {\r
-    pdbcanvas.bysequence = false;\r
-    pdbcanvas.pdb.setColours(new BuriedColourScheme());\r
-    pdbcanvas.redrawneeded=true;\r
-    pdbcanvas.repaint();\r
-  }\r
-\r
-  public void user_actionPerformed(ActionEvent e)\r
-  {\r
-    if (e.getActionCommand().equals("User Defined..."))\r
-    {\r
-      new UserDefinedColours(pdbcanvas, null);\r
-    }\r
-    else\r
-    {\r
-      UserColourScheme udc = (UserColourScheme) UserDefinedColours.\r
-          getUserColourSchemes().get(e.getActionCommand());\r
-\r
-      pdbcanvas.pdb.setColours(udc);\r
-      pdbcanvas.redrawneeded=true;\r
-      pdbcanvas.repaint();\r
-    }\r
-  }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+package MCview;
+
+import javax.swing.*;
+import java.awt.event.*;
+import jalview.datamodel.*;
+import jalview.schemes.*;
+import jalview.gui.*;
+import jalview.io.EBIFetchClient;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+public class PDBViewer extends JInternalFrame implements Runnable
+{
+  PDBEntry pdb;
+  Sequence sequence;
+  PDBCanvas pdbcanvas;
+
+
+  public PDBViewer(PDBEntry entry,
+                   Sequence seq,
+                   SeqCanvas seqcanvas)
+  {
+    /*Uncomment this to modify in Jbuilder
+    try
+    {
+      jbInit();
+    }
+    catch (Exception ex)
+    {
+      ex.printStackTrace();
+    }*/
+
+    if (entry==null)
+      return;
+    pdb = entry;
+    sequence = seq;
+
+    Thread worker = new Thread(this);
+    worker.start();
+
+    pdbcanvas = new PDBCanvas(seqcanvas, seq);
+
+    setContentPane(pdbcanvas);
+    StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId());
+    if(pdb.getProperty()!=null)
+    {
+      if (pdb.getProperty().get("method")!=null)
+      {
+        title.append(" Method: ");
+        title.append(pdb.getProperty().get("method"));
+      }
+      if (pdb.getProperty().get("chains") != null)
+      {
+        title.append(" Chain:");
+        title.append(pdb.getProperty().get("chains"));
+      }
+    }
+     Desktop.addInternalFrame(this,title.toString(),400, 400);
+  }
+
+  public void run()
+  {
+    try
+    {
+      EBIFetchClient ebi = new EBIFetchClient();
+      String query = "pdb:" + pdb.getId();
+      String[] result = ebi.fetchData(query, "default","raw");
+      if (result!=null) {
+        PDBfile pdbfile = new PDBfile(result);
+        pdbcanvas.setPDBFile(pdbfile);
+      } else {
+        throw new Exception("Empty result for WSDbFetch Query: "+query);
+      }
+
+      try
+      {
+        jbInit();
+      }
+      catch (Exception ex)
+      {
+        ex.printStackTrace();
+      }
+    }
+    catch (Exception ex)
+    {
+      ex.printStackTrace();
+      showErrorMessage("Failed to retrieve PDB structure.");
+//      this.dispose();
+    }
+  }
+
+  private void jbInit()
+      throws Exception
+  {
+    this.addKeyListener(new KeyAdapter()
+        {
+            public void keyPressed(KeyEvent evt)
+            {
+              pdbcanvas.keyPressed(evt);
+            }
+        });
+
+    this.setJMenuBar(jMenuBar1);
+    fileMenu.setText("File");
+    coloursMenu.setText("Colours");
+    saveMenu.setActionCommand("Save Image");
+    saveMenu.setText("Save As");
+    png.setText("PNG");
+    png.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        png_actionPerformed(e);
+      }
+    });
+    eps.setText("EPS");
+    eps.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        eps_actionPerformed(e);
+      }
+    });
+    mapping.setText("View Mapping");
+    mapping.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        mapping_actionPerformed(e);
+      }
+    });
+    wire.setText("Wireframe");
+    wire.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        wire_actionPerformed(e);
+      }
+    });
+    depth.setSelected(true);
+    depth.setText("Depthcue");
+    depth.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        depth_actionPerformed(e);
+      }
+    });
+    zbuffer.setSelected(true);
+    zbuffer.setText("Z Buffering");
+    zbuffer.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        zbuffer_actionPerformed(e);
+      }
+    });
+    charge.setText("Charge & Cysteine");
+    charge.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        charge_actionPerformed(e);
+      }
+    });
+    chain.setText("By Chain");
+    chain.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        chain_actionPerformed(e);
+      }
+    });
+    seqButton.setSelected(true);
+    seqButton.setText("By Sequence");
+    seqButton.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        seqButton_actionPerformed(e);
+      }
+    });
+    allchains.setSelected(true);
+    allchains.setText("Show All Chains");
+    allchains.addItemListener(new ItemListener()
+    {
+      public void itemStateChanged(ItemEvent e)
+      {
+        allchains_itemStateChanged(e);
+      }
+    });
+    zappo.setText("Zappo");
+    zappo.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        zappo_actionPerformed(e);
+      }
+    });
+    taylor.setText("Taylor");
+    taylor.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        taylor_actionPerformed(e);
+      }
+    });
+    hydro.setText("Hydro");
+    hydro.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        hydro_actionPerformed(e);
+      }
+    });
+    helix.setText("Helix");
+    helix.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        helix_actionPerformed(e);
+      }
+    });
+    strand.setText("Strand");
+    strand.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        strand_actionPerformed(e);
+      }
+    });
+    turn.setText("Turn");
+    turn.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        turn_actionPerformed(e);
+      }
+    });
+    buried.setText("Buried");
+    buried.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        buried_actionPerformed(e);
+      }
+    });
+    user.setText("User Defined...");
+    user.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        user_actionPerformed(e);
+      }
+    });
+    viewMenu.setText("View");
+    jMenuBar1.add(fileMenu);
+    jMenuBar1.add(coloursMenu);
+    jMenuBar1.add(viewMenu);
+    fileMenu.add(saveMenu);
+    fileMenu.add(mapping);
+    saveMenu.add(png);
+    saveMenu.add(eps);
+    coloursMenu.add(seqButton);
+    coloursMenu.add(chain);
+    coloursMenu.add(charge);
+    coloursMenu.add(zappo);
+    coloursMenu.add(taylor);
+    coloursMenu.add(hydro);
+    coloursMenu.add(helix);
+    coloursMenu.add(strand);
+    coloursMenu.add(turn);
+    coloursMenu.add(buried);
+    coloursMenu.add(user);
+    ButtonGroup bg = new ButtonGroup();
+    bg.add(seqButton);
+    bg.add(chain);
+    bg.add(charge);
+    bg.add(zappo);
+    bg.add(taylor);
+    bg.add(hydro);
+    bg.add(helix);
+    bg.add(strand);
+    bg.add(turn);
+    bg.add(buried);
+    bg.add(user);
+
+
+    if(jalview.gui.UserDefinedColours.getUserColourSchemes()!=null)
+    {
+      java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
+          getUserColourSchemes().keys();
+
+      while (userColours.hasMoreElements())
+      {
+        final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
+            nextElement().toString());
+        radioItem.setName("USER_DEFINED");
+        radioItem.addMouseListener(new MouseAdapter()
+            {
+              public void mousePressed(MouseEvent evt)
+              {
+                if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
+                {
+                  radioItem.removeActionListener(radioItem.getActionListeners()[0]);
+
+                  int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
+                      "Remove from default list?",
+                      "Remove user defined colour",
+                      JOptionPane.YES_NO_OPTION);
+                  if(option == JOptionPane.YES_OPTION)
+                  {
+                    jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
+                    coloursMenu.remove(radioItem);
+                  }
+                  else
+                    radioItem.addActionListener(new ActionListener()
+                    {
+                      public void actionPerformed(ActionEvent evt)
+                      {
+                        user_actionPerformed(evt);
+                      }
+                    });
+                }
+              }
+            });
+        radioItem.addActionListener(new ActionListener()
+        {
+          public void actionPerformed(ActionEvent evt)
+          {
+            user_actionPerformed(evt);
+          }
+        });
+        coloursMenu.add(radioItem);
+        bg.add(radioItem);
+      }
+    }
+
+    viewMenu.add(wire);
+    viewMenu.add(depth);
+    viewMenu.add(zbuffer);
+    viewMenu.add(allchains);
+  }
+
+  JMenuBar jMenuBar1 = new JMenuBar();
+  JMenu fileMenu = new JMenu();
+  JMenu coloursMenu = new JMenu();
+  JMenu saveMenu = new JMenu();
+  JMenuItem png = new JMenuItem();
+  JMenuItem eps = new JMenuItem();
+  JMenuItem mapping = new JMenuItem();
+  JCheckBoxMenuItem wire = new JCheckBoxMenuItem();
+  JCheckBoxMenuItem depth = new JCheckBoxMenuItem();
+  JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem();
+  JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();
+
+  JRadioButtonMenuItem charge = new JRadioButtonMenuItem();
+  JRadioButtonMenuItem chain = new JRadioButtonMenuItem();
+  JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();
+  JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();
+  JRadioButtonMenuItem taylor = new JRadioButtonMenuItem();
+  JRadioButtonMenuItem zappo = new  JRadioButtonMenuItem();
+  JRadioButtonMenuItem user = new JRadioButtonMenuItem();
+  JRadioButtonMenuItem buried = new JRadioButtonMenuItem();
+  JRadioButtonMenuItem turn = new JRadioButtonMenuItem();
+  JRadioButtonMenuItem strand = new JRadioButtonMenuItem();
+  JRadioButtonMenuItem helix = new JRadioButtonMenuItem();
+  JMenu viewMenu = new JMenu();
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param e DOCUMENT ME!
+   */
+  public void eps_actionPerformed(ActionEvent e)
+  {
+    makePDBImage(jalview.util.ImageMaker.EPS);
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param e DOCUMENT ME!
+   */
+  public void png_actionPerformed(ActionEvent e)
+  {
+     makePDBImage(jalview.util.ImageMaker.PNG);
+  }
+
+  void makePDBImage(int type)
+  {
+    int width = pdbcanvas.getWidth();
+    int height = pdbcanvas.getHeight();
+
+    jalview.util.ImageMaker im;
+
+    if (type == jalview.util.ImageMaker.PNG)
+      im = new jalview.util.ImageMaker(this,
+                                       jalview.util.ImageMaker.PNG,
+                                       "Make PNG image from view",
+                                       width, height,
+                                       null, null);
+    else
+      im = new jalview.util.ImageMaker(this,
+                                       jalview.util.ImageMaker.EPS,
+                                       "Make EPS file from view",
+                                       width, height,
+                                       null, this.getTitle());
+
+    if (im.getGraphics() != null)
+    {
+      pdbcanvas.drawAll(im.getGraphics(), width, height);
+      im.writeImage();
+    }
+  }
+  public void charge_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.bysequence = false;
+    pdbcanvas.pdb.setChargeColours();
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void hydro_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.bysequence = false;
+    pdbcanvas.pdb.setColours(new HydrophobicColourScheme());
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void chain_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.bysequence = false;
+    pdbcanvas.pdb.setChainColours();
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void zbuffer_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.zbuffer = ! pdbcanvas.zbuffer;
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void molecule_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.bymolecule = ! pdbcanvas.bymolecule;
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void depth_actionPerformed(ActionEvent e)
+  {
+  pdbcanvas.depthcue = ! pdbcanvas.depthcue;
+  pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void wire_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.wire = ! pdbcanvas.wire;
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void seqButton_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.bysequence = true;
+    pdbcanvas.updateSeqColours();
+  }
+
+
+  public void mapping_actionPerformed(ActionEvent e)
+  {
+    jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
+    Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
+    cap.setText(pdbcanvas.mappingDetails.toString());
+  }
+
+  public void allchains_itemStateChanged(ItemEvent e)
+  {
+    pdbcanvas.setAllchainsVisible(allchains.getState());
+  }
+  void showErrorMessage(String error)
+  {
+    JOptionPane.showInternalMessageDialog(Desktop.desktop,
+         error, "PDB Viewer Error", JOptionPane.WARNING_MESSAGE);
+  }
+
+
+  public void zappo_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.bysequence = false;
+    pdbcanvas.pdb.setColours(new ZappoColourScheme());
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void taylor_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.bysequence = false;
+    pdbcanvas.pdb.setColours(new TaylorColourScheme());
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void helix_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.bysequence = false;
+    pdbcanvas.pdb.setColours(new HelixColourScheme());
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void strand_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.bysequence = false;
+    pdbcanvas.pdb.setColours(new StrandColourScheme());
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void turn_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.bysequence = false;
+    pdbcanvas.pdb.setColours(new TurnColourScheme());
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void buried_actionPerformed(ActionEvent e)
+  {
+    pdbcanvas.bysequence = false;
+    pdbcanvas.pdb.setColours(new BuriedColourScheme());
+    pdbcanvas.redrawneeded=true;
+    pdbcanvas.repaint();
+  }
+
+  public void user_actionPerformed(ActionEvent e)
+  {
+    if (e.getActionCommand().equals("User Defined..."))
+    {
+      new UserDefinedColours(pdbcanvas, null);
+    }
+    else
+    {
+      UserColourScheme udc = (UserColourScheme) UserDefinedColours.
+          getUserColourSchemes().get(e.getActionCommand());
+
+      pdbcanvas.pdb.setColours(udc);
+      pdbcanvas.redrawneeded=true;
+      pdbcanvas.repaint();
+    }
+  }
+}
index aa494f5..b3ccf5e 100755 (executable)
@@ -29,7 +29,6 @@ import java.io.File;
 import jalview.io.*;\r
 import java.util.*;\r
 \r
-\r
 public class SequenceFetcher\r
     extends JPanel implements Runnable\r
 {\r
@@ -57,12 +56,16 @@ public class SequenceFetcher
 \r
     frame = new JInternalFrame();\r
     frame.setContentPane(this);\r
-    if(System.getProperty("os.name").startsWith("Mac"))\r
-      Desktop.addInternalFrame(frame, ((af==null) ?\r
-                                       "New " : "Additional ")+"Sequence Fetcher (WSDBfetch@EBI)", 400, 140);\r
+    if (System.getProperty("os.name").startsWith("Mac"))\r
+      Desktop.addInternalFrame(frame, getFrameTitle(), 400, 140);\r
     else\r
-      Desktop.addInternalFrame(frame, ((af==null) ?\r
-                                       "New " : "Additional ")+"Sequence Fetcher (WSDBfetch@EBI)", 400, 125);\r
+      Desktop.addInternalFrame(frame, getFrameTitle(), 400, 125);\r
+  }\r
+\r
+  private String getFrameTitle()\r
+  {\r
+    return ( (alignFrame == null) ? "New " : "Additional ") +\r
+        "Sequence Fetcher (WSDBfetch@EBI)";\r
   }\r
 \r
   private void jbInit()\r
@@ -149,12 +152,13 @@ public class SequenceFetcher
     worker.start();\r
   }\r
 \r
-  private void resetDialog() {\r
+  private void resetDialog()\r
+  {\r
     database.setEnabled(true);\r
     textfield.setEnabled(true);\r
     ok.setEnabled(true);\r
     cancel.setEnabled(true);\r
-    frame.setTitle("Sequence Fetcher (WSDBfetch@EBI)");\r
+    frame.setTitle(getFrameTitle());\r
   }\r
 \r
   public void run()\r
@@ -162,23 +166,24 @@ public class SequenceFetcher
     String error = "";\r
     if (database.getSelectedItem().equals(noDbSelected))\r
       error += "Please select the source database\n";\r
-    com.stevesoft.pat.Regex empty=new com.stevesoft.pat.Regex("\\s+","");\r
+    com.stevesoft.pat.Regex empty = new com.stevesoft.pat.Regex("\\s+", "");\r
     textfield.setText(empty.replaceAll(textfield.getText()));\r
-    if (textfield.getText().length()==0)\r
-      error+="Please enter a (semi-colon separated list of) database id(s)";\r
-    if (error.length()>0) {\r
+    if (textfield.getText().length() == 0)\r
+      error += "Please enter a (semi-colon separated list of) database id(s)";\r
+    if (error.length() > 0)\r
+    {\r
       showErrorMessage(error);\r
       resetDialog();\r
       return;\r
     }\r
 \r
-   result = new StringBuffer();\r
+    result = new StringBuffer();\r
     if (database.getSelectedItem().equals("Uniprot"))\r
     {\r
       getUniprotFile(textfield.getText());\r
     }\r
     else if (database.getSelectedItem().equals("EMBL")\r
-        || database.getSelectedItem().equals("EMBLCDS"))\r
+             || database.getSelectedItem().equals("EMBLCDS"))\r
     {\r
       EBIFetchClient dbFetch = new EBIFetchClient();\r
       String[] reply = dbFetch.fetchData(\r
@@ -193,12 +198,19 @@ public class SequenceFetcher
     }\r
     else if (database.getSelectedItem().equals("PDB"))\r
     {\r
-      result = getPDBFile(textfield.getText().toUpperCase());\r
-      if (result!=null)\r
+      StringTokenizer qset = new StringTokenizer(textfield.getText(), ";");\r
+      String query;\r
+      while (qset.hasMoreTokens() && ((query = qset.nextToken())!=null))\r
+      {\r
+        StringBuffer respart = getPDBFile(query.toUpperCase());\r
+        result.append(respart);\r
+\r
+      }\r
+\r
+      if (result != null)\r
         parseResult(result.toString());\r
     }\r
 \r
-\r
     if (result == null || result.length() == 0)\r
       showErrorMessage("Error retrieving " + textfield.getText()\r
                        + " from " + database.getSelectedItem());\r
@@ -210,41 +222,42 @@ public class SequenceFetcher
   void getUniprotFile(String id)\r
   {\r
     EBIFetchClient ebi = new EBIFetchClient();\r
-    File file = ebi.fetchDataAsFile("uniprot:"+id,"xml", null);\r
+    File file = ebi.fetchDataAsFile("uniprot:" + id, "xml", null);\r
     SequenceFeatureFetcher sff = new SequenceFeatureFetcher();\r
     Vector entries = sff.getUniprotEntries(file);\r
 \r
-    if(entries!=null)\r
+    if (entries != null)\r
     {\r
       //First, make the new sequences\r
       Enumeration en = entries.elements();\r
       while (en.hasMoreElements())\r
       {\r
         UniprotEntry entry = (UniprotEntry) en.nextElement();\r
-        StringBuffer name = new StringBuffer( ">Uniprot/Swiss-Prot" );\r
+        StringBuffer name = new StringBuffer(">Uniprot/Swiss-Prot");\r
         Enumeration en2 = entry.getAccession().elements();\r
-        while(en2.hasMoreElements())\r
+        while (en2.hasMoreElements())\r
         {\r
           name.append("|");\r
           name.append(en2.nextElement());\r
         }\r
         en2 = entry.getName().elements();\r
-        while(en2.hasMoreElements())\r
+        while (en2.hasMoreElements())\r
         {\r
           name.append("|");\r
           name.append(en2.nextElement());\r
         }\r
 \r
-        if(entry.getProteinName()!=null)\r
-          name.append(" "+entry.getProteinName().elementAt(0));\r
+        if (entry.getProteinName() != null)\r
+          name.append(" " + entry.getProteinName().elementAt(0));\r
 \r
-        result.append(name +"\n"+entry.getUniprotSequence().getContent());\r
+        result.append(name + "\n" + entry.getUniprotSequence().getContent() +\r
+                      "\n");\r
 \r
       }\r
 \r
       //Then read in the features and apply them to the dataset\r
-      SequenceI [] sequence = parseResult(result.toString());\r
-      for(int i=0; i<entries.size(); i++)\r
+      SequenceI[] sequence = parseResult(result.toString());\r
+      for (int i = 0; i < entries.size(); i++)\r
       {\r
         UniprotEntry entry = (UniprotEntry) entries.elementAt(i);\r
         Enumeration e = entry.getDbReference().elements();\r
@@ -265,124 +278,155 @@ public class SequenceFetcher
     }\r
   }\r
 \r
-    StringBuffer getPDBFile(String id)\r
+  StringBuffer getPDBFile(String id)\r
+  {\r
+    StringBuffer result = new StringBuffer();\r
+    String chain = null;\r
+    if (id.indexOf(":") > -1)\r
     {\r
-      StringBuffer result = new StringBuffer();\r
-      String chain = null;\r
-      if (id.indexOf(":") > -1)\r
-      {\r
-        chain = id.substring(id.indexOf(":") + 1);\r
-        id = id.substring(0, id.indexOf(":"));\r
-      }\r
+      chain = id.substring(id.indexOf(":") + 1);\r
+      id = id.substring(0, id.indexOf(":"));\r
+    }\r
 \r
-      EBIFetchClient ebi = new EBIFetchClient();\r
-      String[] reply = ebi.fetchData("pdb:" + id, "pdb", "raw");\r
-      if (reply==null)\r
-        return null;\r
-      try\r
-      {\r
-        PDBfile pdbfile = new PDBfile(reply);\r
-        for (int i = 0; i < pdbfile.chains.size(); i++)\r
-        {\r
-          if (chain == null ||\r
-              ( (PDBChain) pdbfile.chains.elementAt(i)).id.\r
-              toUpperCase().equals(chain))\r
-            result.append("\n>PDB|" + id + "|" +\r
-                          ( (PDBChain) pdbfile.chains.elementAt(i)).sequence.\r
-                          getName() +\r
-                          "\n"\r
-                          +\r
-                          ( (PDBChain) pdbfile.chains.elementAt(i)).sequence.\r
-                          getSequence());\r
-        }\r
-      }\r
-      catch (Exception ex) // Problem parsing PDB file\r
+    EBIFetchClient ebi = new EBIFetchClient();\r
+    String[] reply = ebi.fetchData("pdb:" + id, "pdb", "raw");\r
+    if (reply == null)\r
+      return null;\r
+    try\r
+    {\r
+      PDBfile pdbfile = new PDBfile(reply);\r
+      for (int i = 0; i < pdbfile.chains.size(); i++)\r
       {\r
-        jalview.bin.Cache.log.warn("Exception when retrieving " + textfield.getText() + " from " +\r
-            database.getSelectedItem(), ex);\r
-        return null;\r
+        if (chain == null ||\r
+            ( (PDBChain) pdbfile.chains.elementAt(i)).id.\r
+            toUpperCase().equals(chain))\r
+          result.append("\n>PDB|" + id + "|" +\r
+                        ( (PDBChain) pdbfile.chains.elementAt(i)).sequence.\r
+                        getName() +\r
+                        "\n"\r
+                        +\r
+                        ( (PDBChain) pdbfile.chains.elementAt(i)).sequence.\r
+                        getSequence());\r
       }\r
-\r
-      return result;\r
     }\r
-\r
-    SequenceI[] parseResult(String result)\r
+    catch (Exception ex) // Problem parsing PDB file\r
     {\r
-      String format = IdentifyFile.Identify(result, "Paste");\r
-      SequenceI[] sequences = null;\r
+      jalview.bin.Cache.log.warn("Exception when retrieving " +\r
+                                 textfield.getText() + " from " +\r
+                                 database.getSelectedItem(), ex);\r
+      return null;\r
+    }\r
 \r
-      if (FormatAdapter.formats.contains(format))\r
+    return result;\r
+  }\r
+\r
+  SequenceI[] parseResult(String result)\r
+  {\r
+    String format = IdentifyFile.Identify(result, "Paste");\r
+    SequenceI[] sequences = null;\r
+\r
+    if (FormatAdapter.formats.contains(format))\r
+    {\r
+      sequences = new FormatAdapter().readFile(result.toString(), "Paste",\r
+                                               format);\r
+      if (sequences != null && sequences.length > 0)\r
       {\r
-        sequences = new FormatAdapter().readFile(result.toString(), "Paste", format);\r
-        if (sequences != null && sequences.length>0)\r
+        if (alignFrame == null)\r
         {\r
-          if(alignFrame==null)\r
+          AlignFrame af = new AlignFrame(new Alignment(sequences));\r
+          af.currentFileFormat = format;\r
+          Desktop.addInternalFrame(af,\r
+                                   "Retrieved from " + database.getSelectedItem(),\r
+                                   AlignFrame.NEW_WINDOW_WIDTH,\r
+                                   AlignFrame.NEW_WINDOW_HEIGHT);\r
+          af.statusBar.setText("Successfully pasted alignment file");\r
+          try\r
           {\r
-            AlignFrame af = new AlignFrame(new Alignment(sequences));\r
-            af.currentFileFormat = format;\r
-            Desktop.addInternalFrame(af, "Retrieved from "+database.getSelectedItem(),\r
-                                     AlignFrame.NEW_WINDOW_WIDTH,\r
-                                     AlignFrame.NEW_WINDOW_HEIGHT);\r
-            af.statusBar.setText("Successfully pasted alignment file");\r
-            try\r
-            {\r
-              af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));\r
-            }\r
-            catch (Exception ex)\r
-            {}\r
+            af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));\r
           }\r
-          else\r
+          catch (Exception ex)\r
+          {}\r
+        }\r
+        else\r
+        {\r
+          for (int i = 0; i < sequences.length; i++)\r
           {\r
-            for (int i = 0; i < sequences.length; i++)\r
-            {\r
-              alignFrame.viewport.alignment.addSequence(sequences[i]);\r
-\r
-              ////////////////////////////\r
-              //Datset needs extension;\r
-              /////////////////////////////\r
-              Sequence ds = new Sequence(sequences[i].getName(),\r
-                                         AlignSeq.extractGaps("-. ",\r
-                  sequences[i].getSequence()),\r
-                                         sequences[i].getStart(),\r
-                                         sequences[i].getEnd());\r
-              sequences[i].setDatasetSequence(ds);\r
-              alignFrame.viewport.alignment.getDataset().addSequence(ds);\r
-            }\r
-            alignFrame.viewport.setEndSeq(alignFrame.viewport.alignment.\r
-                                          getHeight());\r
-            alignFrame.viewport.alignment.getWidth();\r
-            alignFrame.viewport.firePropertyChange("alignment", null,\r
-            alignFrame.viewport.getAlignment().getSequences());\r
-\r
+            alignFrame.viewport.alignment.addSequence(sequences[i]);\r
+\r
+            ////////////////////////////\r
+            //Datset needs extension;\r
+            /////////////////////////////\r
+            Sequence ds = new Sequence(sequences[i].getName(),\r
+                                       AlignSeq.extractGaps("-. ",\r
+                sequences[i].getSequence()),\r
+                                       sequences[i].getStart(),\r
+                                       sequences[i].getEnd());\r
+            sequences[i].setDatasetSequence(ds);\r
+            alignFrame.viewport.alignment.getDataset().addSequence(ds);\r
           }\r
+          alignFrame.viewport.setEndSeq(alignFrame.viewport.alignment.\r
+                                        getHeight());\r
+          alignFrame.viewport.alignment.getWidth();\r
+          alignFrame.viewport.firePropertyChange("alignment", null,\r
+                                                 alignFrame.viewport.\r
+                                                 getAlignment().getSequences());\r
 \r
-          if (database.getSelectedItem().equals("PDB"))\r
+        }\r
+\r
+        if (database.getSelectedItem().equals("PDB"))\r
+        {\r
+          // Parse out the ids from the structured names\r
+          boolean errors = false;\r
+          for (int i = 0; i < sequences.length; i++)\r
           {\r
-            for (int i = 0; i < sequences.length; i++)\r
+            PDBEntry entry = new PDBEntry();\r
+            com.stevesoft.pat.Regex idbits = new com.stevesoft.pat.Regex(\r
+                "PDB\\|([0-9A-z]{4})\\|(.)");\r
+            if (idbits.search(sequences[i].getName()))\r
             {\r
-              PDBEntry entry = new PDBEntry();\r
-              entry.setId(textfield.getText());\r
+              String pdbid = idbits.substring(1);\r
+              String pdbccode = idbits.substring(2);\r
+              // Construct the PDBEntry\r
+              entry.setId(pdbid);\r
+              if (entry.getProperty() == null)\r
+                entry.setProperty(new Hashtable());\r
+              entry.getProperty().put("chains",\r
+                                      pdbccode\r
+                                      + "=" + sequences[i].getStart()\r
+                                      + "-" + sequences[i].getEnd());\r
               sequences[i].getDatasetSequence().addPDBId(entry);\r
             }\r
+            else\r
+            {\r
+              // don't add an entry for this chain, but this is probably a bug\r
+              // that the user should know about.\r
+              jalview.bin.Cache.log.warn(\r
+                  "No PDBEntry constructed for sequence " + i + " : " +\r
+                  sequences[i].getName());\r
+              errors = true;\r
+            }\r
           }\r
-\r
+          if (errors)\r
+            jalview.bin.Cache.log.warn(\r
+                "Query string that resulted in PDBEntry construction failure was :\n" +\r
+                textfield.getText());\r
         }\r
-        else\r
-          showErrorMessage( "Error retrieving "+textfield.getText()\r
-                            +" from "+database.getSelectedItem());\r
+\r
       }\r
+      else\r
+        showErrorMessage("Error retrieving " + textfield.getText()\r
+                         + " from " + database.getSelectedItem());\r
+    }\r
 \r
-      return sequences;\r
+    return sequences;\r
 \r
   }\r
 \r
   void showErrorMessage(String error)\r
   {\r
     JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-         error, "Error Retrieving Data", JOptionPane.WARNING_MESSAGE);\r
+                                          error, "Error Retrieving Data",\r
+                                          JOptionPane.WARNING_MESSAGE);\r
   }\r
 }\r
 \r
-\r
-\r
-\r