Merge branch 'develop' into trialMerge
[jalview.git] / src / MCview / AppletPDBCanvas.java
old mode 100755 (executable)
new mode 100644 (file)
index 222672b..bc36d9e
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 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 java.io.*;\r
-import java.util.*;\r
-\r
-// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-\r
-import jalview.analysis.*;\r
-import jalview.datamodel.*;\r
-\r
-import jalview.appletgui.*;\r
-import jalview.structure.*;\r
-\r
-public class AppletPDBCanvas\r
-    extends Panel implements MouseListener, MouseMotionListener, StructureListener\r
-{\r
-\r
-  MCMatrix idmat = new MCMatrix(3, 3);\r
-  MCMatrix objmat = new MCMatrix(3, 3);\r
-  boolean redrawneeded = true;\r
-  int omx = 0;\r
-  int mx = 0;\r
-  int omy = 0;\r
-  int my = 0;\r
-  public PDBfile pdb;\r
-  PDBEntry pdbentry;\r
-  int bsize;\r
-  Image img;\r
-  Graphics ig;\r
-  Dimension prefsize;\r
-  float[] centre = new float[3];\r
-  float[] width = new float[3];\r
-  float maxwidth;\r
-  float scale;\r
-  String inStr;\r
-  String inType;\r
-  boolean bysequence = true;\r
-  boolean depthcue = true;\r
-  boolean wire = false;\r
-  boolean bymolecule = false;\r
-  boolean zbuffer = true;\r
-  boolean dragging;\r
-  int xstart;\r
-  int xend;\r
-  int ystart;\r
-  int yend;\r
-  int xmid;\r
-  int ymid;\r
-  Font font = new Font("Helvetica", Font.PLAIN, 10);\r
-  public SequenceI [] sequence;\r
-  final StringBuffer mappingDetails = new StringBuffer();\r
-  String appletToolTip = null;\r
-  int toolx, tooly;\r
-  PDBChain mainchain;\r
-  Vector highlightRes;\r
-  boolean pdbAction = false;\r
-  Bond highlightBond1, highlightBond2;\r
-  boolean errorLoading = false;\r
-  boolean seqColoursReady = false;\r
-  FeatureRenderer fr;\r
-  AlignmentPanel ap;\r
-  StructureSelectionManager ssm;\r
-\r
-  public AppletPDBCanvas(PDBEntry pdbentry,\r
-                         SequenceI[] seq,\r
-                         AlignmentPanel ap,\r
-                         String protocol)\r
-\r
-  {\r
-    this.ap = ap;\r
-    this.pdbentry = pdbentry;\r
-    this.sequence = seq;\r
-\r
-    ssm = StructureSelectionManager.getStructureSelectionManager();\r
-\r
-    try{\r
-      pdb = ssm.setMapping(seq, pdbentry.getFile(), protocol);\r
-    }catch(Exception ex)\r
-    {\r
-      ex.printStackTrace();\r
-      return;\r
-    }\r
-\r
-    pdbentry.setId(pdb.id);\r
-\r
-    ssm.addStructureViewerListener(this);\r
-\r
-    colourBySequence(ap.getSequenceRenderer(),\r
-                     ap.av.getShowSequenceFeatures() ?\r
-                     ap.getFeatureRenderer() : null);\r
-\r
-    int max = -10;\r
-    int maxchain = -1;\r
-    int pdbstart = 0;\r
-    int pdbend = 0;\r
-    int seqstart = 0;\r
-    int seqend = 0;\r
-    AlignSeq maxAlignseq = null;\r
-\r
-    //JUST DEAL WITH ONE SEQUENCE FOR NOW\r
-    SequenceI sequence = seq[0];\r
-\r
-    for (int i = 0; i < pdb.chains.size(); i++)\r
-    {\r
-\r
-      mappingDetails.append("\n\nPDB Sequence is :\nSequence = " +\r
-                            ( (PDBChain) pdb.chains.elementAt(i)).sequence.\r
-                            getSequenceAsString());\r
-      mappingDetails.append("\nNo of residues = " +\r
-                            ( (PDBChain) pdb.chains.elementAt(i)).residues.size() +\r
-                            "\n\n");\r
-\r
-      // Now lets compare the sequences to get\r
-      // the start and end points.\r
-      // Align the sequence to the pdb\r
-      AlignSeq as = new AlignSeq(sequence,\r
-                                 ( (PDBChain) pdb.chains.elementAt(i)).sequence,\r
-                                 "pep");\r
-      as.calcScoreMatrix();\r
-      as.traceAlignment();\r
-      PrintStream ps = new PrintStream(System.out)\r
-      {\r
-        public void print(String x)\r
-        {\r
-          mappingDetails.append(x);\r
-        }\r
-\r
-        public void println()\r
-        {\r
-          mappingDetails.append("\n");\r
-        }\r
-      };\r
-\r
-      as.printAlignment(ps);\r
-\r
-      if (as.maxscore > max)\r
-      {\r
-        max = as.maxscore;\r
-        maxchain = i;\r
-\r
-        pdbstart = as.seq2start;\r
-        pdbend = as.seq2end;\r
-        seqstart = as.seq1start + sequence.getStart() - 1;\r
-        seqend = as.seq1end + sequence.getEnd() - 1;\r
-        maxAlignseq = as;\r
-      }\r
-\r
-      mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);\r
-      mappingDetails.append("\nSEQ start/end " + seqstart + " " + seqend);\r
-    }\r
-\r
-    mainchain = (PDBChain) pdb.chains.elementAt(maxchain);\r
-\r
-    mainchain.pdbstart = pdbstart;\r
-    mainchain.pdbend = pdbend;\r
-    mainchain.seqstart = seqstart;\r
-    mainchain.seqend = seqend;\r
-    mainchain.isVisible = true;\r
-  //  mainchain.makeExactMapping(maxAlignseq, sequence);\r
-  //  mainchain.transferRESNUMFeatures(sequence, null);\r
-    this.pdb = pdb;\r
-    this.prefsize = new Dimension(getSize().width, getSize().height);\r
-\r
-    //Initialize the matrices to identity\r
-    for (int i = 0; i < 3; i++)\r
-    {\r
-      for (int j = 0; j < 3; j++)\r
-      {\r
-        if (i != j)\r
-        {\r
-          idmat.addElement(i, j, 0);\r
-          objmat.addElement(i, j, 0);\r
-        }\r
-        else\r
-        {\r
-          idmat.addElement(i, j, 1);\r
-          objmat.addElement(i, j, 1);\r
-        }\r
-      }\r
-    }\r
-\r
-    addMouseMotionListener(this);\r
-    addMouseListener(this);\r
-\r
-    addKeyListener(new KeyAdapter()\r
-    {\r
-      public void keyPressed(KeyEvent evt)\r
-      {\r
-        doKeyPressed(evt);\r
-      }\r
-    });\r
-\r
-    findCentre();\r
-    findWidth();\r
-\r
-    setupBonds();\r
-\r
-    scale = findScale();\r
-  }\r
-\r
-  Vector visiblebonds;\r
-  void setupBonds()\r
-  {\r
-    seqColoursReady = false;\r
-    // Sort the bonds by z coord\r
-    visiblebonds = new Vector();\r
-\r
-    for (int ii = 0; ii < pdb.chains.size(); ii++)\r
-    {\r
-      if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)\r
-      {\r
-        Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
-        for (int i = 0; i < tmp.size(); i++)\r
-        {\r
-          visiblebonds.addElement(tmp.elementAt(i));\r
-        }\r
-      }\r
-    }\r
-    seqColoursReady = true;\r
-    colourBySequence(ap.getSequenceRenderer(),\r
-                               ap.av.getShowSequenceFeatures() ?\r
-                               ap.getFeatureRenderer() : null);\r
-    redrawneeded = true;\r
-    repaint();\r
-  }\r
-\r
-  public void findWidth()\r
-  {\r
-    float[] max = new float[3];\r
-    float[] min = new float[3];\r
-\r
-    max[0] = (float) - 1e30;\r
-    max[1] = (float) - 1e30;\r
-    max[2] = (float) - 1e30;\r
-\r
-    min[0] = (float) 1e30;\r
-    min[1] = (float) 1e30;\r
-    min[2] = (float) 1e30;\r
-\r
-    for (int ii = 0; ii < pdb.chains.size(); ii++)\r
-    {\r
-      if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)\r
-      {\r
-        Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
-        for (int i = 0; i < bonds.size(); i++)\r
-        {\r
-          Bond tmp = (Bond) bonds.elementAt(i);\r
-\r
-          if (tmp.start[0] >= max[0])\r
-          {\r
-            max[0] = tmp.start[0];\r
-          }\r
-\r
-          if (tmp.start[1] >= max[1])\r
-          {\r
-            max[1] = tmp.start[1];\r
-          }\r
-\r
-          if (tmp.start[2] >= max[2])\r
-          {\r
-            max[2] = tmp.start[2];\r
-          }\r
-\r
-          if (tmp.start[0] <= min[0])\r
-          {\r
-            min[0] = tmp.start[0];\r
-          }\r
-\r
-          if (tmp.start[1] <= min[1])\r
-          {\r
-            min[1] = tmp.start[1];\r
-          }\r
-\r
-          if (tmp.start[2] <= min[2])\r
-          {\r
-            min[2] = tmp.start[2];\r
-          }\r
-\r
-          if (tmp.end[0] >= max[0])\r
-          {\r
-            max[0] = tmp.end[0];\r
-          }\r
-\r
-          if (tmp.end[1] >= max[1])\r
-          {\r
-            max[1] = tmp.end[1];\r
-          }\r
-\r
-          if (tmp.end[2] >= max[2])\r
-          {\r
-            max[2] = tmp.end[2];\r
-          }\r
-\r
-          if (tmp.end[0] <= min[0])\r
-          {\r
-            min[0] = tmp.end[0];\r
-          }\r
-\r
-          if (tmp.end[1] <= min[1])\r
-          {\r
-            min[1] = tmp.end[1];\r
-          }\r
-\r
-          if (tmp.end[2] <= min[2])\r
-          {\r
-            min[2] = tmp.end[2];\r
-          }\r
-        }\r
-      }\r
-    }\r
-\r
-    width[0] = (float) Math.abs(max[0] - min[0]);\r
-    width[1] = (float) Math.abs(max[1] - min[1]);\r
-    width[2] = (float) Math.abs(max[2] - min[2]);\r
-\r
-    maxwidth = width[0];\r
-\r
-    if (width[1] > width[0])\r
-    {\r
-      maxwidth = width[1];\r
-    }\r
-\r
-    if (width[2] > width[1])\r
-    {\r
-      maxwidth = width[2];\r
-    }\r
-\r
-    // System.out.println("Maxwidth = " + maxwidth);\r
-  }\r
-\r
-  public float findScale()\r
-  {\r
-    int dim;\r
-    int width;\r
-    int height;\r
-\r
-    if (getSize().width != 0)\r
-    {\r
-      width = getSize().width;\r
-      height = getSize().height;\r
-    }\r
-    else\r
-    {\r
-      width = prefsize.width;\r
-      height = prefsize.height;\r
-    }\r
-\r
-    if (width < height)\r
-    {\r
-      dim = width;\r
-    }\r
-    else\r
-    {\r
-      dim = height;\r
-    }\r
-\r
-    return (float) (dim / (1.5d * maxwidth));\r
-  }\r
-\r
-  public void findCentre()\r
-  {\r
-    float xtot = 0;\r
-    float ytot = 0;\r
-    float ztot = 0;\r
-\r
-    int bsize = 0;\r
-\r
-    //Find centre coordinate\r
-    for (int ii = 0; ii < pdb.chains.size(); ii++)\r
-    {\r
-      if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)\r
-      {\r
-        Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
-        bsize += bonds.size();\r
-\r
-        for (int i = 0; i < bonds.size(); i++)\r
-        {\r
-          xtot = xtot + ( (Bond) bonds.elementAt(i)).start[0] +\r
-              ( (Bond) bonds.elementAt(i)).end[0];\r
-\r
-          ytot = ytot + ( (Bond) bonds.elementAt(i)).start[1] +\r
-              ( (Bond) bonds.elementAt(i)).end[1];\r
-\r
-          ztot = ztot + ( (Bond) bonds.elementAt(i)).start[2] +\r
-              ( (Bond) bonds.elementAt(i)).end[2];\r
-        }\r
-      }\r
-    }\r
-\r
-    centre[0] = xtot / (2 * (float) bsize);\r
-    centre[1] = ytot / (2 * (float) bsize);\r
-    centre[2] = ztot / (2 * (float) bsize);\r
-  }\r
-\r
-  public void paint(Graphics g)\r
-  {\r
-\r
-    if (errorLoading)\r
-    {\r
-      g.setColor(Color.white);\r
-      g.fillRect(0, 0, getSize().width, getSize().height);\r
-      g.setColor(Color.black);\r
-      g.setFont(new Font("Verdana", Font.BOLD, 14));\r
-      g.drawString("Error loading PDB data!!", 50, getSize().height / 2);\r
-      return;\r
-    }\r
-\r
-    if (!seqColoursReady)\r
-    {\r
-      g.setColor(Color.black);\r
-      g.setFont(new Font("Verdana", Font.BOLD, 14));\r
-      g.drawString("Fetching PDB data...", 50, getSize().height / 2);\r
-      return;\r
-    }\r
-\r
-    //Only create the image at the beginning -\r
-    //this saves much memory usage\r
-    if ( (img == null) || (prefsize.width != getSize().width) ||\r
-        (prefsize.height != getSize().height))\r
-    {\r
-\r
-      try\r
-      {\r
-        prefsize.width = getSize().width;\r
-        prefsize.height = getSize().height;\r
-\r
-        scale = findScale();\r
-        img = createImage(prefsize.width, prefsize.height);\r
-        ig = img.getGraphics();\r
-\r
-        redrawneeded = true;\r
-      }\r
-      catch (Exception ex)\r
-      {\r
-        ex.printStackTrace();\r
-      }\r
-    }\r
-\r
-    if (redrawneeded)\r
-    {\r
-      drawAll(ig, prefsize.width, prefsize.height);\r
-      redrawneeded = false;\r
-    }\r
-    if (appletToolTip != null)\r
-    {\r
-      ig.setColor(Color.red);\r
-      ig.drawString(appletToolTip, toolx, tooly);\r
-    }\r
-\r
-    g.drawImage(img, 0, 0, this);\r
-\r
-    pdbAction = false;\r
-  }\r
-\r
-  public void drawAll(Graphics g, int width, int height)\r
-  {\r
-    ig.setColor(Color.black);\r
-    ig.fillRect(0, 0, width, height);\r
-    drawScene(ig);\r
-    drawLabels(ig);\r
-  }\r
-\r
-  public void setColours(jalview.schemes.ColourSchemeI cs)\r
-  {\r
-    bysequence = false;\r
-    pdb.setColours(cs);\r
-    redrawneeded = true;\r
-    repaint();\r
-  }\r
-\r
-\r
-\r
-  // This method has been taken out of PDBChain to allow\r
-  // Applet and Application specific sequence renderers to be used\r
-  void colourBySequence(SequenceRenderer sr, FeatureRenderer fr)\r
-  {\r
-    StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());\r
-\r
-    boolean showFeatures = false;\r
-    if (fr!=null)\r
-    {\r
-      if (fr == null)\r
-      {\r
-        fr = new jalview.appletgui.FeatureRenderer(ap.av);\r
-      }\r
-      fr.transferSettings(fr);\r
-      showFeatures = true;\r
-    }\r
-\r
-    PDBChain chain;\r
-    if (bysequence && pdb != null)\r
-    {\r
-      for (int ii = 0; ii < pdb.chains.size(); ii++)\r
-      {\r
-        chain = (PDBChain) pdb.chains.elementAt(ii);\r
-\r
-        for (int i = 0; i < chain.bonds.size(); i++)\r
-        {\r
-          Bond tmp = (Bond) chain.bonds.elementAt(i);\r
-          tmp.startCol = Color.lightGray;\r
-          tmp.endCol = Color.lightGray;\r
-          if (chain != mainchain)\r
-          {\r
-            continue;\r
-          }\r
-\r
-          for (int s = 0; s < sequence.length; s++)\r
-          {\r
-            for (int m = 0; m < mapping.length; m++)\r
-            {\r
-              if (mapping[m].getSequence() == sequence[s])\r
-              {\r
-                int pos = mapping[m].getSeqPos(tmp.at1.resNumber)-1;\r
-                if (pos > 0)\r
-                {\r
-                  pos = sequence[s].findIndex(pos);\r
-                  tmp.startCol = sr.getResidueBoxColour(sequence[s], pos);\r
-                  if (showFeatures)\r
-                  {\r
-                    tmp.startCol = fr.findFeatureColour(tmp.startCol,\r
-                                                        sequence[s],\r
-                                                        pos);\r
-                  }\r
-                }\r
-                pos = mapping[m].getSeqPos(tmp.at2.resNumber)-1;\r
-                if (pos > 0)\r
-                {\r
-                  pos = sequence[s].findIndex(pos);\r
-                  tmp.endCol = sr.getResidueBoxColour(sequence[s], pos);\r
-                  if (showFeatures)\r
-                  {\r
-                    tmp.endCol = fr.findFeatureColour(tmp.endCol,\r
-                                                        sequence[s],\r
-                                                        pos);\r
-                  }\r
-                }\r
-\r
-              }\r
-            }\r
-          }\r
-        }\r
-      }\r
-    }\r
-  }\r
-\r
-  Zsort zsort;\r
-  public void drawScene(Graphics g)\r
-  {\r
-    if (zbuffer)\r
-    {\r
-      if (zsort == null)\r
-      {\r
-        zsort = new Zsort();\r
-      }\r
-\r
-      zsort.Zsort(visiblebonds);\r
-    }\r
-\r
-    Bond tmpBond = null;\r
-    for (int i = 0; i < visiblebonds.size(); i++)\r
-    {\r
-      tmpBond = (Bond) visiblebonds.elementAt(i);\r
-\r
-      xstart = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) +\r
-                      (getSize().width / 2));\r
-      ystart = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) +\r
-                      (getSize().height / 2));\r
-\r
-      xend = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +\r
-                    (getSize().width / 2));\r
-      yend = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +\r
-                    (getSize().height / 2));\r
-\r
-      xmid = (xend + xstart) / 2;\r
-      ymid = (yend + ystart) / 2;\r
-\r
-      if (depthcue && !bymolecule)\r
-      {\r
-        if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))\r
-        {\r
-          g.setColor(tmpBond.startCol.darker().darker());\r
-          drawLine(g, xstart, ystart, xmid, ymid);\r
-\r
-          g.setColor(tmpBond.endCol.darker().darker());\r
-          drawLine(g, xmid, ymid, xend, yend);\r
-        }\r
-        else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))\r
-        {\r
-          g.setColor(tmpBond.startCol.darker());\r
-          drawLine(g, xstart, ystart, xmid, ymid);\r
-\r
-          g.setColor(tmpBond.endCol.darker());\r
-          drawLine(g, xmid, ymid, xend, yend);\r
-        }\r
-        else\r
-        {\r
-          g.setColor(tmpBond.startCol);\r
-          drawLine(g, xstart, ystart, xmid, ymid);\r
-\r
-          g.setColor(tmpBond.endCol);\r
-          drawLine(g, xmid, ymid, xend, yend);\r
-        }\r
-\r
-      }\r
-      else if (depthcue && bymolecule)\r
-      {\r
-        if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))\r
-        {\r
-          g.setColor(Color.green.darker().darker());\r
-          drawLine(g, xstart, ystart, xend, yend);\r
-        }\r
-        else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))\r
-        {\r
-          g.setColor(Color.green.darker());\r
-          drawLine(g, xstart, ystart, xend, yend);\r
-        }\r
-        else\r
-        {\r
-          g.setColor(Color.green);\r
-          drawLine(g, xstart, ystart, xend, yend);\r
-        }\r
-      }\r
-      else if (!depthcue && !bymolecule)\r
-      {\r
-        g.setColor(tmpBond.startCol);\r
-        drawLine(g, xstart, ystart, xmid, ymid);\r
-        g.setColor(tmpBond.endCol);\r
-        drawLine(g, xmid, ymid, xend, yend);\r
-      }\r
-      else\r
-      {\r
-        drawLine(g, xstart, ystart, xend, yend);\r
-      }\r
-\r
-      if (highlightBond1 != null && highlightBond1 == tmpBond)\r
-      {\r
-        g.setColor(Color.white);\r
-        drawLine(g, xmid, ymid, xend, yend);\r
-      }\r
-\r
-      if (highlightBond2 != null && highlightBond2 == tmpBond)\r
-      {\r
-        g.setColor(Color.white);\r
-        drawLine(g, xstart, ystart, xmid, ymid);\r
-      }\r
-\r
-    }\r
-  }\r
-\r
-  public void drawLine(Graphics g, int x1, int y1, int x2, int y2)\r
-  {\r
-    if (!wire)\r
-    {\r
-      if ( ( (float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5)\r
-      {\r
-        g.drawLine(x1, y1, x2, y2);\r
-        g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1);\r
-        g.drawLine(x1, y1 - 1, x2, y2 - 1);\r
-      }\r
-      else\r
-      {\r
-        g.setColor(g.getColor().brighter());\r
-        g.drawLine(x1, y1, x2, y2);\r
-        g.drawLine(x1 + 1, y1, x2 + 1, y2);\r
-        g.drawLine(x1 - 1, y1, x2 - 1, y2);\r
-      }\r
-    }\r
-    else\r
-    {\r
-      g.drawLine(x1, y1, x2, y2);\r
-    }\r
-  }\r
-\r
-  public Dimension minimumsize()\r
-  {\r
-    return prefsize;\r
-  }\r
-\r
-  public Dimension preferredsize()\r
-  {\r
-    return prefsize;\r
-  }\r
-\r
-  public void doKeyPressed(KeyEvent evt)\r
-  {\r
-    if (evt.getKeyCode() == KeyEvent.VK_UP)\r
-    {\r
-      scale = (float) (scale * 1.1);\r
-      redrawneeded = true;\r
-      repaint();\r
-    }\r
-    else if (evt.getKeyCode() == KeyEvent.VK_DOWN)\r
-    {\r
-      scale = (float) (scale * 0.9);\r
-      redrawneeded = true;\r
-      repaint();\r
-    }\r
-  }\r
-\r
-  public void mousePressed(MouseEvent e)\r
-  {\r
-    pdbAction = true;\r
-    Atom fatom = findAtom(e.getX(), e.getY());\r
-    if (fatom != null)\r
-    {\r
-      fatom.isSelected = !fatom.isSelected;\r
-\r
-      redrawneeded = true;\r
-      repaint();\r
-      if (foundchain != -1)\r
-      {\r
-        PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
-        if (chain == mainchain)\r
-        {\r
-          if (fatom.alignmentMapping != -1)\r
-          {\r
-            if (highlightRes == null)\r
-            {\r
-              highlightRes = new Vector();\r
-            }\r
-\r
-            if (highlightRes.contains(fatom.alignmentMapping + "" + ""))\r
-            {\r
-              highlightRes.removeElement(fatom.alignmentMapping + "");\r
-            }\r
-            else\r
-            {\r
-              highlightRes.addElement(fatom.alignmentMapping + "");\r
-            }\r
-          }\r
-        }\r
-      }\r
-\r
-    }\r
-    mx = e.getX();\r
-    my = e.getY();\r
-    omx = mx;\r
-    omy = my;\r
-    dragging = false;\r
-  }\r
-\r
-  public void mouseMoved(MouseEvent e)\r
-  {\r
-    pdbAction = true;\r
-    if (highlightBond1 != null)\r
-    {\r
-      highlightBond1.at2.isSelected = false;\r
-      highlightBond2.at1.isSelected = false;\r
-      highlightBond1 = null;\r
-      highlightBond2 = null;\r
-    }\r
-\r
-    Atom fatom = findAtom(e.getX(), e.getY());\r
-\r
-    PDBChain chain = null;\r
-    if (foundchain != -1)\r
-    {\r
-      chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
-      if (chain == mainchain)\r
-      {\r
-        mouseOverStructure(fatom.resNumber, chain.id);\r
-      }\r
-    }\r
-\r
-    if (fatom != null)\r
-    {\r
-      toolx = e.getX();\r
-      tooly = e.getY();\r
-\r
-      appletToolTip = chain.id + ":" + fatom.resNumber + " " + fatom.resName;\r
-      redrawneeded = true;\r
-      repaint();\r
-    }\r
-    else\r
-    {\r
-      mouseOverStructure(-1, chain!=null?chain.id:null);\r
-      appletToolTip = null;\r
-      redrawneeded = true;\r
-      repaint();\r
-    }\r
-  }\r
-\r
-  public void mouseClicked(MouseEvent e)\r
-  {\r
-  }\r
-\r
-  public void mouseEntered(MouseEvent e)\r
-  {\r
-  }\r
-\r
-  public void mouseExited(MouseEvent e)\r
-  {\r
-  }\r
-\r
-  public void mouseDragged(MouseEvent evt)\r
-  {\r
-    int x = evt.getX();\r
-    int y = evt.getY();\r
-    mx = x;\r
-    my = y;\r
-\r
-    MCMatrix objmat = new MCMatrix(3, 3);\r
-    objmat.setIdentity();\r
-\r
-    if ( (evt.getModifiers() & Event.META_MASK) != 0)\r
-    {\r
-      objmat.rotatez( (float) ( (mx - omx)));\r
-    }\r
-    else\r
-    {\r
-      objmat.rotatex( (float) ( (my - omy)));\r
-      objmat.rotatey( (float) ( (omx - mx)));\r
-    }\r
-\r
-    //Alter the bonds\r
-    for (int ii = 0; ii < pdb.chains.size(); ii++)\r
-    {\r
-      Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
-      for (int i = 0; i < bonds.size(); i++)\r
-      {\r
-        Bond tmpBond = (Bond) bonds.elementAt(i);\r
-\r
-        //Translate the bond so the centre is 0,0,0\r
-        tmpBond.translate( -centre[0], -centre[1], -centre[2]);\r
-\r
-        //Now apply the rotation matrix\r
-        tmpBond.start = objmat.vectorMultiply(tmpBond.start);\r
-        tmpBond.end = objmat.vectorMultiply(tmpBond.end);\r
-\r
-        //Now translate back again\r
-        tmpBond.translate(centre[0], centre[1], centre[2]);\r
-      }\r
-    }\r
-\r
-    objmat = null;\r
-\r
-    omx = mx;\r
-    omy = my;\r
-\r
-    dragging = true;\r
-\r
-    redrawneeded = true;\r
-\r
-    repaint();\r
-  }\r
-\r
-  public void mouseReleased(MouseEvent evt)\r
-  {\r
-    dragging = false;\r
-    return;\r
-  }\r
-\r
-  void drawLabels(Graphics g)\r
-  {\r
-\r
-    for (int ii = 0; ii < pdb.chains.size(); ii++)\r
-    {\r
-      PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
-\r
-      if (chain.isVisible)\r
-      {\r
-        Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
-        for (int i = 0; i < bonds.size(); i++)\r
-        {\r
-          Bond tmpBond = (Bond) bonds.elementAt(i);\r
-\r
-          if (tmpBond.at1.isSelected)\r
-          {\r
-            labelAtom(g, tmpBond, 1);\r
-          }\r
-\r
-          if (tmpBond.at2.isSelected)\r
-          {\r
-\r
-            labelAtom(g, tmpBond, 2);\r
-          }\r
-        }\r
-      }\r
-    }\r
-  }\r
-\r
-  public void labelAtom(Graphics g, Bond b, int n)\r
-  {\r
-    g.setFont(font);\r
-\r
-    if (n == 1)\r
-    {\r
-      int xstart = (int) ( ( (b.start[0] - centre[0]) * scale) +\r
-                          (getSize().width / 2));\r
-      int ystart = (int) ( ( (b.start[1] - centre[1]) * scale) +\r
-                          (getSize().height / 2));\r
-\r
-      g.setColor(Color.red);\r
-      g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);\r
-    }\r
-\r
-    if (n == 2)\r
-    {\r
-      int xstart = (int) ( ( (b.end[0] - centre[0]) * scale) +\r
-                          (getSize().width / 2));\r
-      int ystart = (int) ( ( (b.end[1] - centre[1]) * scale) +\r
-                          (getSize().height / 2));\r
-\r
-      g.setColor(Color.red);\r
-      g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);\r
-    }\r
-  }\r
-\r
-  int foundchain = -1;\r
-  public Atom findAtom(int x, int y)\r
-  {\r
-    Atom fatom = null;\r
-\r
-    foundchain = -1;\r
-\r
-    for (int ii = 0; ii < pdb.chains.size(); ii++)\r
-    {\r
-      PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
-      int truex;\r
-      Bond tmpBond = null;\r
-\r
-      if (chain.isVisible)\r
-      {\r
-        Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
-        for (int i = 0; i < bonds.size(); i++)\r
-        {\r
-          tmpBond = (Bond) bonds.elementAt(i);\r
-\r
-          truex = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) +\r
-                         (getSize().width / 2));\r
-\r
-          if (Math.abs(truex - x) <= 2)\r
-          {\r
-            int truey = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) +\r
-                               (getSize().height / 2));\r
-\r
-            if (Math.abs(truey - y) <= 2)\r
-            {\r
-              fatom = tmpBond.at1;\r
-              foundchain = ii;\r
-              break;\r
-            }\r
-          }\r
-        }\r
-\r
-        // Still here? Maybe its the last bond\r
-\r
-        truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +\r
-                       (getSize().width / 2));\r
-\r
-        if (Math.abs(truex - x) <= 2)\r
-        {\r
-          int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +\r
-                             (getSize().height / 2));\r
-\r
-          if (Math.abs(truey - y) <= 2)\r
-          {\r
-            fatom = tmpBond.at2;\r
-            foundchain = ii;\r
-            break;\r
-          }\r
-        }\r
-\r
-      }\r
-\r
-      if (fatom != null) //)&& chain.ds != null)\r
-      {\r
-        chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
-      }\r
-    }\r
-\r
-    return fatom;\r
-  }\r
-\r
-  public void update(Graphics g)\r
-  {\r
-    paint(g);\r
-  }\r
-\r
-  public void highlightRes(int ii)\r
-  {\r
-    if (!seqColoursReady)\r
-    {\r
-      return;\r
-    }\r
-\r
-    if (highlightRes != null\r
-        && highlightRes.contains( (ii - 1) + ""))\r
-    {\r
-      return;\r
-    }\r
-\r
-    int index = -1;\r
-    Bond tmpBond;\r
-    for (index = 0; index < mainchain.bonds.size(); index++)\r
-    {\r
-      tmpBond = (Bond) mainchain.bonds.elementAt(index);\r
-      if (tmpBond.at1.alignmentMapping == ii - 1)\r
-      {\r
-        if (highlightBond1 != null)\r
-        {\r
-          highlightBond1.at2.isSelected = false;\r
-        }\r
-\r
-        if (highlightBond2 != null)\r
-        {\r
-          highlightBond2.at1.isSelected = false;\r
-        }\r
-\r
-        highlightBond1 = null;\r
-        highlightBond2 = null;\r
-\r
-        if (index > 0)\r
-        {\r
-          highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);\r
-          highlightBond1.at2.isSelected = true;\r
-        }\r
-\r
-        if (index != mainchain.bonds.size())\r
-        {\r
-          highlightBond2 = (Bond) mainchain.bonds.elementAt(index);\r
-          highlightBond2.at1.isSelected = true;\r
-        }\r
-\r
-        break;\r
-      }\r
-    }\r
-\r
-    redrawneeded = true;\r
-    repaint();\r
-  }\r
-\r
-  public void setAllchainsVisible(boolean b)\r
-  {\r
-    for (int ii = 0; ii < pdb.chains.size(); ii++)\r
-    {\r
-      PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
-      chain.isVisible = b;\r
-    }\r
-    mainchain.isVisible = true;\r
-    findCentre();\r
-    setupBonds();\r
-  }\r
-\r
-\r
-  //////////////////////////////////\r
-  ///StructureListener\r
-  public String getPdbFile()\r
-  {\r
-    return "???";\r
-  }\r
-\r
-\r
-  String lastMessage;\r
-  public void mouseOverStructure(int pdbResNum, String chain)\r
-  {\r
-      if (lastMessage == null || !lastMessage.equals(pdbResNum+chain))\r
-        ssm.mouseOverStructure(pdbResNum, chain, pdbentry.getFile());\r
-\r
-      lastMessage = pdbResNum+chain;\r
-  }\r
-\r
-  StringBuffer resetLastRes = new StringBuffer();\r
-  StringBuffer eval = new StringBuffer();\r
-\r
-  public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile)\r
-  {\r
-    if (!seqColoursReady)\r
-    {\r
-      return;\r
-    }\r
-\r
-    if (highlightRes != null\r
-        && highlightRes.contains( (atomIndex - 1) + ""))\r
-    {\r
-      return;\r
-    }\r
-\r
-    int index = -1;\r
-    Bond tmpBond;\r
-    for (index = 0; index < mainchain.bonds.size(); index++)\r
-    {\r
-      tmpBond = (Bond) mainchain.bonds.elementAt(index);\r
-      if (tmpBond.at1.atomIndex == atomIndex)\r
-      {\r
-        if (highlightBond1 != null)\r
-        {\r
-          highlightBond1.at2.isSelected = false;\r
-        }\r
-\r
-        if (highlightBond2 != null)\r
-        {\r
-          highlightBond2.at1.isSelected = false;\r
-        }\r
-\r
-        highlightBond1 = null;\r
-        highlightBond2 = null;\r
-\r
-        if (index > 0)\r
-        {\r
-          highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);\r
-          highlightBond1.at2.isSelected = true;\r
-        }\r
-\r
-        if (index != mainchain.bonds.size())\r
-        {\r
-          highlightBond2 = (Bond) mainchain.bonds.elementAt(index);\r
-          highlightBond2.at1.isSelected = true;\r
-        }\r
-\r
-        break;\r
-      }\r
-    }\r
-\r
-    redrawneeded = true;\r
-    repaint();\r
-  }\r
-\r
-  public void updateColours(Object source)\r
-  {\r
-    AlignmentPanel ap = (AlignmentPanel) source;\r
-    colourBySequence(ap.getSequenceRenderer(),\r
-                     ap.av.getShowSequenceFeatures() ?\r
-                     ap.getFeatureRenderer() : null);\r
-    redrawneeded = true;\r
-    repaint();\r
-  }\r
-\r
-\r
-}\r
+package MCview;
+
+public class AppletPDBCanvas
+{
+
+}