New files
authoramwaterhouse <Andrew Waterhouse>
Thu, 18 Nov 2004 18:43:47 +0000 (18:43 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 18 Nov 2004 18:43:47 +0000 (18:43 +0000)
src/MCview/Atom.java [new file with mode: 0755]
src/MCview/Bond.java [new file with mode: 0755]
src/MCview/Bond.jn [new file with mode: 0755]
src/MCview/Bond.jsave [new file with mode: 0755]
src/MCview/MCMatrix.java [new file with mode: 0755]
src/MCview/PDBChain.java [new file with mode: 0755]
src/MCview/PDBfile.java [new file with mode: 0755]
src/MCview/Residue.java [new file with mode: 0755]
src/MCview/Zsort.java [new file with mode: 0755]
src/MCview/myAtom.java [new file with mode: 0755]
src/MCview/rotCanvas.java [new file with mode: 0755]

diff --git a/src/MCview/Atom.java b/src/MCview/Atom.java
new file mode 100755 (executable)
index 0000000..c89d489
--- /dev/null
@@ -0,0 +1,52 @@
+package MCview;\r
+import java.util.*;\r
+import java.awt.*;\r
+\r
+public class Atom {\r
+  double x;\r
+  double y;\r
+  double z;\r
+  int number;\r
+  String name;\r
+  String resName;\r
+  int resNumber;\r
+  int type;\r
+  Color color;\r
+  String chain;\r
+\r
+  public Atom(StringTokenizer str) {\r
+    this.number  = (new Integer(str.nextToken())).intValue();\r
+    this.name    = str.nextToken();\r
+    this.resName = str.nextToken();\r
+\r
+    String tmpstr = new String();\r
+\r
+    try {\r
+      tmpstr = str.nextToken();\r
+\r
+      this.resNumber = (new Integer(tmpstr).intValue());\r
+      this.chain     = "A";\r
+      this.color     = Color.green;\r
+\r
+    } catch(NumberFormatException e) {\r
+      this.chain = tmpstr;\r
+\r
+      if (tmpstr.equals("A")) {\r
+        this.color = new Color((float)Math.random(),(float)Math.random(),(float)Math.random());\r
+      } else {\r
+        this.color = Color.red;\r
+      }\r
+      this.resNumber = (new Integer(str.nextToken()).intValue());\r
+    }\r
+\r
+    this.x = (double)(new Double(str.nextToken()).floatValue());\r
+    this.y = (double)(new Double(str.nextToken()).floatValue());\r
+    this.z = (double)(new Double(str.nextToken()).floatValue());\r
+\r
+  }\r
+\r
+  public void setColor(Color col) {\r
+    this.color = col;\r
+  }\r
+\r
+}\r
diff --git a/src/MCview/Bond.java b/src/MCview/Bond.java
new file mode 100755 (executable)
index 0000000..60b2f21
--- /dev/null
@@ -0,0 +1,65 @@
+package MCview;\r
+\r
+import java.awt.*;\r
+\r
+public class Bond {\r
+\r
+  float start[];\r
+  float end[];\r
+\r
+  Color startCol;\r
+  Color endCol;\r
+\r
+  public myAtom at1;\r
+  public myAtom at2;\r
+\r
+  public Bond(float[] start, float[] end, myAtom at1, myAtom at2) {\r
+    this.start    = start;\r
+    this.end      = end;\r
+    this.startCol = at1.color;\r
+    this.endCol   = at2.color;\r
+    this.at1      = at1;\r
+    this.at2      = at2;\r
+  }\r
+  public Bond(Bond bond) {\r
+    this.start    = new float[3];\r
+\r
+    this.start[0] = bond.start[0];\r
+    this.start[1] = bond.start[1];\r
+    this.start[2] = bond.start[2];\r
+\r
+    this.end    = new float[3];\r
+\r
+    this.end[0] = bond.end[0];\r
+    this.end[1] = bond.end[1];\r
+    this.end[2] = bond.end[2];\r
+\r
+    this.startCol = bond.startCol;\r
+    this.endCol   = bond.endCol;\r
+  }\r
+\r
+  public void print() {\r
+    System.out.println("Start " + start[0] + " "+ start[1] + " " + start[2]);\r
+    System.out.println("End   " + end[0] + " "+ end[1] + " " + end[2]);\r
+  }\r
+\r
+  public float length() {\r
+    float len = (end[0] - start[0])*(end[0] - start[0]) +\r
+                (end[1] - start[1])*(end[1] - start[1]) +\r
+                (end[2] - start[2])*(end[2] - start[2]);\r
+\r
+    len = (float)(Math.sqrt(len));\r
+\r
+    return len;\r
+  }\r
+  public void translate(float x, float y, float z) {\r
+    start[0] = (start[0] + x);\r
+    end[0]   = (end[0] + x);\r
+\r
+    start[1] = (start[1] + y);\r
+    end[1]   = (end[1] + y);\r
+\r
+    start[2] = (start[2] + z);\r
+    end[2]   = (end[2] + z);\r
+  }\r
+}\r
diff --git a/src/MCview/Bond.jn b/src/MCview/Bond.jn
new file mode 100755 (executable)
index 0000000..b52e445
--- /dev/null
@@ -0,0 +1,57 @@
+package MCview;\r
+\r
+import java.awt.*;\r
+\r
+public class Bond {\r
+\r
+  float start[];\r
+  float end[];\r
+\r
+  Color startCol;\r
+  Color endCol;\r
+\r
+  public myAtom at1;\r
+  public myAtom at2;\r
+\r
+  public Bond(float[] start, float[] end, myAtom at1, myAtom at2) {\r
+     this.start = start;\r
+     this.end = end;\r
+     this.startCol = at1.color;\r
+     this.endCol = at2.color;\r
+     this.at1 = at1;\r
+     this.at2 = at2;\r
+  }\r
+  public Bond(Bond bond) {\r
+     this.start = new float[3];\r
+     this.start[0] = bond.start[0];\r
+     this.start[1] = bond.start[1];\r
+     this.start[2] = bond.start[2];\r
+     this.end = new float[3];\r
+     this.end[0] = bond.end[0];\r
+     this.end[1] = bond.end[1];\r
+     this.end[2] = bond.end[2];\r
+     this.startCol = bond.startCol;\r
+     this.endCol = bond.endCol;\r
+  }\r
+\r
+  public void print() {\r
+     System.out.println("Start " + start[0] + " "+ start[1] + " " + start[2]);\r
+     System.out.println("End   " + end[0] + " "+ end[1] + " " + end[2]);\r
+  }\r
+  \r
+  public float length() {\r
+     float len = (end[0] - start[0])*(end[0] - start[0]) +\r
+                  (end[1] - start[1])*(end[1] - start[1]) +\r
+                  (end[2] - start[2])*(end[2] - start[2]);\r
+     len = (float)(Math.sqrt(len));\r
+     return len;\r
+  }\r
+  public void translate(float x, float y, float z) {\r
+     start[0] = (start[0] + x);\r
+     end[0] = (end[0] + x);\r
+     start[1] =(start[1] + y);\r
+     end[1] = (end[1] + y);\r
+     start[2] = (start[2] + z);\r
+     end[2] = (end[2] + z);\r
+  }\r
+}\r
diff --git a/src/MCview/Bond.jsave b/src/MCview/Bond.jsave
new file mode 100755 (executable)
index 0000000..0d0e560
--- /dev/null
@@ -0,0 +1,57 @@
+package MCview;\r\r
+\r\r
+import java.awt.*;\r\r
+\r\r
+public class Bond {\r\r
+\r\r
+  float start[];\r\r
+  float end[];\r\r
+\r\r
+  Color startCol;\r\r
+  Color endCol;\r\r
+\r\r
+  public myAtom at1;\r\r
+  public myAtom at2;\r\r
+\r\r
+  public Bond(float[] start, float[] end, myAtom at1, myAtom at2) {\r\r
+     this.start = start;\r\r
+     this.end = end;\r\r
+     this.startCol = at1.color;\r\r
+     this.endCol = at2.color;\r\r
+     this.at1 = at1;\r\r
+     this.at2 = at2;\r\r
+  }\r\r
+  public Bond(Bond bond) {\r\r
+     this.start = new float[3];\r\r
+     this.start[0] = bond.start[0];\r\r
+     this.start[1] = bond.start[1];\r\r
+     this.start[2] = bond.start[2];\r\r
+     this.end = new float[3];\r\r
+     this.end[0] = bond.end[0];\r\r
+     this.end[1] = bond.end[1];\r\r
+     this.end[2] = bond.end[2];\r\r
+     this.startCol = bond.startCol;\r\r
+     this.endCol = bond.endCol;\r\r
+  }\r\r
+\r\r
+  public void print() {\r\r
+     System.out.println("Start " + start[0] + " "+ start[1] + " " + start[2]);\r\r
+     System.out.println("End   " + end[0] + " "+ end[1] + " " + end[2]);\r\r
+  }\r\r
+  \r\r
+  public float length() {\r\r
+     float len = (end[0] - start[0])*(end[0] - start[0]) +\r\r
+                  (end[1] - start[1])*(end[1] - start[1]) +\r\r
+                  (end[2] - start[2])*(end[2] - start[2]);\r\r
+     len = (float)(Math.sqrt(len));\r\r
+     return len;\r\r
+  }\r\r
+  public void translate(float x, float y, float z) {\r\r
+     start[0] = (start[0] + x);\r\r
+     end[0] = (end[0] + x);\r\r
+     start[1] =(start[1] + y);\r\r
+     end[1] = (end[1] + y);\r\r
+     start[2] = (start[2] + z);\r\r
+     end[2] = (end[2] + z);\r\r
+  }\r\r
+}\r\r
diff --git a/src/MCview/MCMatrix.java b/src/MCview/MCMatrix.java
new file mode 100755 (executable)
index 0000000..4994573
--- /dev/null
@@ -0,0 +1,143 @@
+package MCview;\r
+\r
+public class MCMatrix {\r
+  float matrix[][];\r
+  float tmp[][];\r
+\r
+  float mycos;\r
+  float mysin;\r
+  float myconst = (float)(Math.PI/180);\r
+\r
+  public MCMatrix(int rows, int cols) {\r
+    matrix = new float[rows][cols];\r
+    tmp    = new float[rows][cols];\r
+  }\r
+\r
+  public void addElement(int i, int j, float value) {\r
+    matrix[i][j] = value;\r
+  }\r
+\r
+  public void print() {\r
+    System.out.println(matrix[0][0] + " " + matrix[0][1] + " " + matrix[0][2]);\r
+    System.out.println(matrix[1][0] + " " + matrix[1][1] + " " + matrix[1][2]);\r
+    System.out.println(matrix[2][0] + " " + matrix[2][1] + " " + matrix[2][2]);\r
+  }\r
+\r
+  public void rotatex(float degrees) {\r
+    mycos = (float)(Math.cos(degrees*myconst));\r
+    mysin = (float)(Math.sin(degrees*myconst));\r
+\r
+    tmp[0][0] = 1;\r
+    tmp[0][1] = 0;\r
+    tmp[0][2] = 0;\r
+    tmp[1][0] = 0;\r
+    tmp[1][1] = mycos;\r
+    tmp[1][2] = mysin;\r
+    tmp[2][0] = 0;\r
+    tmp[2][1] = -mysin;\r
+    tmp[2][2] = mycos;\r
+    preMultiply(tmp);\r
+  }\r
+\r
+  public void rotatez(float degrees) {\r
+    mycos = (float)(Math.cos(degrees*myconst));\r
+    mysin = (float)(Math.sin(degrees*myconst));\r
+\r
+    tmp[0][0] = mycos;\r
+    tmp[0][1] = -mysin;\r
+    tmp[0][2] = 0;\r
+    tmp[1][0] = mysin;\r
+    tmp[1][1] = mycos;\r
+    tmp[1][2] = 0;\r
+    tmp[2][0] = 0;\r
+    tmp[2][1] = 0;\r
+    tmp[2][2] = 1;\r
+\r
+    preMultiply(tmp);\r
+  }\r
+\r
+  public void rotatey(float degrees) {\r
+    mycos = (float)(Math.cos(degrees*myconst));\r
+    mysin = (float)(Math.sin(degrees*myconst));\r
+\r
+    tmp[0][0] = mycos;\r
+    tmp[0][1] = 0;\r
+    tmp[0][2] = -mysin;\r
+    tmp[1][0] = 0;\r
+    tmp[1][1] = 1;\r
+    tmp[1][2] = 0;\r
+    tmp[2][0] = mysin;\r
+    tmp[2][1] = 0;\r
+    tmp[2][2] = mycos;\r
+\r
+    preMultiply(tmp);\r
+  }\r
+\r
+  public float[] vectorMultiply(float[] vect) {\r
+    float temp[] = new float[3];\r
+\r
+    temp[0] = vect[0];\r
+    temp[1] = vect[1];\r
+    temp[2] = vect[2];\r
+\r
+    for (int i = 0; i < 3; i++) {\r
+      temp[i] = (float)matrix[i][0]*vect[0] + (float)matrix[i][1]*vect[1] +(float)matrix[i][2]*vect[2];\r
+    }\r
+\r
+    vect[0] = temp[0];\r
+    vect[1] = temp[1];\r
+    vect[2] = temp[2];\r
+\r
+    return vect;\r
+  }\r
+\r
+  public void preMultiply(float mat[][]) {\r
+    float tmp[][]  = new float[3][3];\r
+\r
+    for (int i = 0; i < 3 ; i++) {\r
+      for (int j = 0; j < 3; j++ ) {\r
+        tmp[i][j] = mat[i][0]*matrix[0][j] +\r
+                    mat[i][1]*matrix[1][j] +\r
+                    mat[i][2]*matrix[2][j];\r
+      }\r
+    }\r
+\r
+    for (int i = 0; i < 3 ; i++) {\r
+      for (int j = 0; j < 3; j++ ) {\r
+        matrix[i][j] = tmp[i][j];\r
+      }\r
+    }\r
+  }\r
+\r
+  public void postMultiply(float mat[][]) {\r
+    float tmp[][]  = new float[3][3];\r
+\r
+    for (int i = 0; i < 3 ; i++) {\r
+      for (int j = 0; j < 3; j++ ) {\r
+        tmp[i][j] = matrix[i][0]*mat[0][j] +\r
+                    matrix[i][1]*mat[1][j] +\r
+                    matrix[i][2]*mat[2][j];\r
+      }\r
+    }\r
+\r
+    for (int i = 0; i < 3 ; i++) {\r
+      for (int j = 0; j < 3; j++ ) {\r
+        matrix[i][j] = tmp[i][j];\r
+      }\r
+    }\r
+  }\r
+\r
+  public void setIdentity() {\r
+    matrix[0][0] = 1;\r
+    matrix[1][1] = 1;\r
+    matrix[2][2] = 1;\r
+    matrix[0][1] = 0;\r
+    matrix[0][2] = 0;\r
+    matrix[1][0] = 0;\r
+    matrix[1][2] = 0;\r
+    matrix[2][0] = 0;\r
+    matrix[2][1] = 0;\r
+  }\r
+}\r
+\r
+\r
diff --git a/src/MCview/PDBChain.java b/src/MCview/PDBChain.java
new file mode 100755 (executable)
index 0000000..6a72786
--- /dev/null
@@ -0,0 +1,261 @@
+/* Copyright (C) 1998  Michele Clamp\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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
+ */\r
+package MCview;\r
+\r
+import jalview.datamodel.*;\r
+import jalview.schemes.ResidueProperties;\r
+import jalview.gui.*;\r
+\r
+import java.awt.*;\r
+import java.util.*;\r
+\r
+\r
+public class PDBChain {\r
+\r
+  public String id;\r
+  public Vector bonds = new Vector();\r
+  public Vector atoms = new Vector();\r
+  public Vector residues = new Vector();\r
+  public int offset;\r
+\r
+  public Sequence sequence;\r
+  public boolean isVisible = false;\r
+\r
+  //public DrawableSequence ds;\r
+\r
+  public PDBChain(String id) {\r
+    this.id = id;\r
+  }\r
+\r
+\r
+  public String print() {\r
+    String tmp = "";\r
+    for (int i=0; i < bonds.size() ;i++) {\r
+      tmp = tmp + ((Bond)bonds.elementAt(i)).at1.resName + " " + ((Bond)bonds.elementAt(i)).at1.resNumber +" " + offset+ "\n";\r
+    }\r
+    return tmp;\r
+  }\r
+  public void makeCaBondList() {\r
+    for (int i = 0; i < (residues.size() - 1) ; i++) {\r
+      Residue tmpres = (Residue)residues.elementAt(i);\r
+      Residue tmpres2 = (Residue)residues.elementAt(i+1);\r
+      myAtom at1 = tmpres.findAtom("CA");\r
+      myAtom at2 = tmpres2.findAtom("CA");\r
+      if ((at1 != null) && (at2 != null)) {\r
+        if (at1.chain.equals(at2.chain)) {\r
+          makeBond(at1,at2);\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  public void makeBond(myAtom at1, myAtom at2) {\r
+    float[] start = new float[3];\r
+    float[] end = new float[3];\r
+\r
+    start[0] = at1.x;\r
+    start[1] = at1.y;\r
+    start[2] = at1.z;\r
+\r
+    end[0] = at2.x;\r
+    end[1] = at2.y;\r
+    end[2] = at2.z;\r
+\r
+    bonds.addElement(new Bond(start, end, at1,at2));\r
+  }\r
+\r
+  public void makeResidueList() {\r
+    int count = 0;\r
+    String seq = "";\r
+    for (int i = 0; i < atoms.size(); i++) {\r
+\r
+      myAtom tmp = (myAtom)atoms.elementAt(i);\r
+      String resName = tmp.resName;\r
+      int resNumber = tmp.resNumber;\r
+      int res = resNumber;\r
+\r
+      if (i ==0) {\r
+        offset = resNumber;\r
+      }\r
+      Vector resAtoms = new Vector();\r
+\r
+      resAtoms.addElement((myAtom)atoms.elementAt(i));\r
+      i++;\r
+      resNumber = ((myAtom)atoms.elementAt(i)).resNumber;\r
+\r
+      //Add atoms to a vector while the residue number\r
+      //remains the same\r
+      while ((resNumber == res) && (i < atoms.size())) {\r
+\r
+        resAtoms.addElement((myAtom)atoms.elementAt(i));\r
+        i++;\r
+        if (i < atoms.size()) {\r
+          resNumber = ((myAtom)atoms.elementAt(i)).resNumber;\r
+        } else {\r
+          resNumber++;\r
+        }\r
+      }\r
+\r
+      //We need this to keep in step with the outer for i = loop\r
+      i--;\r
+\r
+      //Make a new Residue object with the new atoms vector\r
+      residues.addElement(new Residue(resAtoms, resNumber - 1,count));\r
+      count++;\r
+      Residue tmpres = (Residue)residues.lastElement();\r
+      myAtom tmpat = (myAtom)tmpres.atoms.elementAt(0);\r
+\r
+      // Keep totting up the sequence\r
+      if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null) {\r
+        System.out.println("Null aa3Hash for " + tmpat.resName);\r
+      } else {\r
+        String tmpres2 =\r
+          ResidueProperties.aa[((Integer)ResidueProperties.getAA3Hash().get(tmpat.resName)).intValue()];\r
+        seq = seq + tmpres2;\r
+      }\r
+      //      System.out.println(tmpat.resName + " " + tmpres2);\r
+    }\r
+    sequence = new Sequence("PDB_seq",seq,1,seq.length());\r
+    System.out.println("Sequence = " + seq);\r
+    System.out.println("No of residues = " +residues.size());\r
+  }\r
+\r
+  public void setChargeColours() {\r
+    for (int i = 0; i < bonds.size(); i++) {\r
+      try {\r
+        Bond b = (Bond)bonds.elementAt(i);\r
+\r
+        if (b.at1.resName.toUpperCase().equals("ASP") || b.at1.resName.toUpperCase().equals("GLU")) {\r
+          b.startCol = Color.red;\r
+        } else if (b.at1.resName.toUpperCase().equals("LYS") || b.at1.resName.toUpperCase().equals("ARG")) {\r
+          b.startCol = Color.blue;\r
+        } else if (b.at1.resName.toUpperCase().equals("CYS")) {\r
+          b.startCol = Color.yellow;\r
+        } else {\r
+          int atno = ((Integer)ResidueProperties.getAA3Hash().get(b.at1.resName.toUpperCase())).intValue();\r
+          b.startCol = Color.lightGray;\r
+        }\r
+        if (b.at2.resName.toUpperCase().equals("ASP") || b.at2.resName.toUpperCase().equals("GLU")) {\r
+          b.endCol = Color.red;\r
+        } else if (b.at2.resName.toUpperCase().equals("LYS") || b.at2.resName.toUpperCase().equals("ARG")) {\r
+          b.endCol = Color.blue;\r
+        } else if (b.at2.resName.toUpperCase().equals("CYS")) {\r
+          b.endCol = Color.yellow;\r
+        } else {\r
+          int atno = ((Integer)ResidueProperties.getAA3Hash().get(b.at2.resName.toUpperCase())).intValue();\r
+          b.endCol = Color.lightGray;\r
+        }\r
+      } catch (Exception e) {\r
+        Bond b = (Bond)bonds.elementAt(i);\r
+        b.startCol = Color.gray;\r
+        b.endCol = Color.gray;\r
+      }\r
+    }\r
+  }\r
+\r
+  public void setHydrophobicityColours() {\r
+    float hydmin = (float)ResidueProperties.getHydmin();\r
+    float hydmax = (float)ResidueProperties.getHydmax();\r
+    double[] hyd  = ResidueProperties.getHyd();\r
+\r
+    Hashtable AA3Hash = ResidueProperties.getAA3Hash();\r
+\r
+    for (int i = 0; i < bonds.size(); i++) {\r
+      try {\r
+        Bond b = (Bond)bonds.elementAt(i);\r
+\r
+        int   atno = ((Integer)AA3Hash.get(b.at1.resName.toUpperCase())).intValue();\r
+        float red  = ((float)hyd[atno] - hydmin)/(hydmax - hydmin);\r
+\r
+        if (red > (float)1.0) {\r
+          red = (float)1.0;\r
+        }\r
+        if (red < (float)0.0) {\r
+          red = (float)0.0;\r
+        }\r
+\r
+        b.startCol = new Color(red,(float)0.0,(float)1.0-red);\r
+        atno = ((Integer)AA3Hash.get(b.at2.resName.toUpperCase())).intValue();\r
+\r
+        red = ((float)hyd[atno] - hydmin)/(hydmax - hydmin);\r
+\r
+        if (red > (float)1.0) {\r
+          red = (float)1.0;\r
+        }\r
+        if (red < (float)0.0) {\r
+          red = (float)0.0;\r
+        }\r
+\r
+        b.endCol = new Color(red,(float)0.2,(float)1.0-red);\r
+      } catch (Exception e) {\r
+        Bond b = (Bond)bonds.elementAt(i);\r
+        b.startCol = Color.gray;\r
+        b.endCol = Color.gray;\r
+      }\r
+    }\r
+  }\r
+\r
+\r
+  public void colourBySequence(DrawableSequence seq) {\r
+\r
+//    for (int i = 0; i < bonds.size(); i++) {\r
+//      Bond tmp = (Bond)bonds.elementAt(i);\r
+//      try {\r
+//\r
+//        if (tmp.at1.resNumber >= (offset + seq.pdbstart - 1) && tmp.at1.resNumber <= (offset + seq.pdbend - 1)) {\r
+//\r
+//          int pos   = seq.seqtart() + (tmp.at1.resNumber - seq.pdbstart - offset) ;\r
+//          int index = seq.findIndex(pos);\r
+//\r
+//          tmp.startCol = (Color)seq.getResidueBoxColour(index);\r
+//\r
+//        } else {\r
+//          tmp.startCol = Color.gray;\r
+//        }\r
+//\r
+//        if (tmp.at2.resNumber >= (offset + seq.pdbstart -1) && tmp.at2.resNumber <= (seq.pdbend+offset-1)) {\r
+//\r
+//          int pos    = seq.seqstart + (tmp.at2.resNumber - seq.pdbstart-offset);\r
+//          int index  = seq.findIndex(pos);\r
+//\r
+//          tmp.endCol = (Color)seq.getResidueBoxColour(index);\r
+//\r
+//        } else {\r
+//          tmp.endCol = Color.gray;\r
+//        }\r
+//      } catch (Exception e) {\r
+//        tmp.startCol = Color.lightGray;\r
+//        tmp.endCol = Color.lightGray;\r
+//      }\r
+//    }\r
+  }\r
+\r
+  public void setChainColours() {\r
+    for (int i = 0; i < bonds.size(); i++) {\r
+      Bond tmp = (Bond)bonds.elementAt(i);\r
+      try {\r
+        tmp.startCol = (Color) ResidueProperties.getChainColours().get(id);\r
+        tmp.endCol   = (Color) ResidueProperties.getChainColours().get(id);\r
+      } catch (Exception e) {\r
+        tmp.startCol = Color.lightGray;\r
+        tmp.endCol   = Color.lightGray;\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+\r
diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java
new file mode 100755 (executable)
index 0000000..ce98a06
--- /dev/null
@@ -0,0 +1,137 @@
+package MCview;\r
+\r
+import jalview.gui.*;\r
+import java.io.*;\r
+import java.net.*;\r
+import java.util.*;\r
+\r
+\r
+public class PDBfile extends jalview.io.FileParse {\r
+\r
+  public Vector chains = new Vector();\r
+\r
+  Vector lineArray = new Vector();\r
+\r
+  public PDBfile(String inFile, String inType) throws IOException {\r
+\r
+    super(inFile,inType);\r
+\r
+    String line;\r
+    this.lineArray = new Vector();\r
+    BufferedReader dataIn;\r
+\r
+    if (inType.equals("File"))\r
+      dataIn =  new BufferedReader(new FileReader( inFile ));\r
+\r
+    else\r
+    {\r
+      URL url = new URL(inFile);\r
+      this.fileSize = 0;\r
+      dataIn = new BufferedReader(new InputStreamReader(url.openStream()));\r
+    }\r
+\r
+    while ((line = dataIn.readLine()) != null) {\r
+      lineArray.addElement(line);\r
+    }\r
+    noLines = lineArray.size();\r
+\r
+    parse();\r
+\r
+}\r
+\r
+\r
+  public void parse() {\r
+\r
+    System.out.println("Parsing");\r
+\r
+    for (int i = 0; i < lineArray.size(); i++) {\r
+      StringTokenizer str = new StringTokenizer(lineArray.elementAt(i).toString());\r
+      if (str.hasMoreTokens()) {\r
+        String inStr = str.nextToken();\r
+\r
+        if (inStr.indexOf("ATOM") != -1) {\r
+          try {\r
+            myAtom tmpatom = new myAtom(str);\r
+            if (findChain(tmpatom.chain) != null) {\r
+              System.out.println("Adding to chain " + tmpatom.chain);\r
+              findChain(tmpatom.chain).atoms.addElement(tmpatom);\r
+            } else {\r
+              System.out.println("Making chain " + tmpatom.chain);\r
+              PDBChain tmpchain = new PDBChain(tmpatom.chain);\r
+              chains.addElement(tmpchain);\r
+              tmpchain.atoms.addElement(tmpatom);\r
+            }\r
+          } catch(NumberFormatException e) {\r
+            System.out.println("Caught" +  e);\r
+            System.out.println("Atom not added");\r
+          }\r
+        }\r
+      }\r
+    }\r
+    makeResidueList();\r
+    makeCaBondList();\r
+    //    for (int i=0; i < chains.size() ; i++) {\r
+    //  String pog = ((PDBChain)chains.elementAt(i)).print();\r
+    //  System.out.println(pog);\r
+    // }\r
+  }\r
+\r
+  public void makeResidueList() {\r
+    for (int i=0; i < chains.size() ; i++) {\r
+      ((PDBChain)chains.elementAt(i)).makeResidueList();\r
+    }\r
+  }\r
+  public void makeCaBondList() {\r
+    for (int i=0; i < chains.size() ; i++) {\r
+      ((PDBChain)chains.elementAt(i)).makeCaBondList();\r
+    }\r
+  }\r
+\r
+  public PDBChain findChain(String id) {\r
+    for (int i=0; i < chains.size(); i++) {\r
+      // System.out.println("ID = " + id + " " +((PDBChain)chains.elementAt(i)).id);\r
+      if (((PDBChain)chains.elementAt(i)).id.equals(id)) {\r
+        return (PDBChain)chains.elementAt(i);\r
+      }\r
+    }\r
+    return null;\r
+  }\r
+\r
+\r
+  public void setChargeColours() {\r
+    for (int i=0; i < chains.size(); i++) {\r
+      ((PDBChain)chains.elementAt(i)).setChargeColours();\r
+    }\r
+  }\r
+\r
+  public void setHydrophobicityColours() {\r
+    for (int i=0; i < chains.size(); i++) {\r
+      ((PDBChain)chains.elementAt(i)).setHydrophobicityColours();\r
+    }\r
+  }\r
+\r
+  public void colourBySequence(DrawableSequence seq) {\r
+//SMJS TODO\r
+//    int max = seq.maxchain;\r
+//    if (seq.maxchain != -1) {\r
+//      ((PDBChain)chains.elementAt(max)).colourBySequence(seq);\r
+//    }\r
+  }\r
+\r
+  public void setChainColours() {\r
+    for (int i=0; i < chains.size(); i++) {\r
+      ((PDBChain)chains.elementAt(i)).setChainColours();\r
+    }\r
+  }\r
+  public static void main(String[] args) {\r
+    try {\r
+      PDBfile pdb = new PDBfile("enkp1.pdb","File");\r
+    } catch(IOException e) {\r
+      System.out.println(e);\r
+      System.exit(0);\r
+    }\r
+  }\r
+}\r
+\r
+\r
+\r
diff --git a/src/MCview/Residue.java b/src/MCview/Residue.java
new file mode 100755 (executable)
index 0000000..6e058f3
--- /dev/null
@@ -0,0 +1,28 @@
+package MCview;\r
+\r
+import java.util.*;\r
+\r
+\r
+public class Residue {\r
+  Vector atoms = new Vector();\r
+\r
+  int number;\r
+  int count;\r
+  int seqnumber;\r
+\r
+  public Residue(Vector atoms, int number, int count) {\r
+    this.atoms  = atoms;\r
+    this.number = number;\r
+    this.count  = count;\r
+  }\r
+\r
+  public myAtom findAtom(String name) {\r
+\r
+    for (int i = 0; i < atoms.size(); i++) {\r
+      if (((myAtom)atoms.elementAt(i)).name.equals(name)) {\r
+        return (myAtom)atoms.elementAt(i);\r
+      }\r
+    }\r
+    return null;\r
+  }\r
+}\r
diff --git a/src/MCview/Zsort.java b/src/MCview/Zsort.java
new file mode 100755 (executable)
index 0000000..4116ff3
--- /dev/null
@@ -0,0 +1,50 @@
+package MCview;\r
+\r
+import java.util.*;\r
+\r
+public class Zsort {\r
+\r
+  public static void Zsort(Vector bonds) {\r
+\r
+    sort(bonds,0,bonds.size()-1);\r
+  }\r
+\r
+\r
+\r
+  public static void sort(Vector bonds,int p, int r) {\r
+    int q;\r
+\r
+    if (p < r) {\r
+      q = partition(bonds,p,r);\r
+      sort(bonds,p,q);\r
+      sort(bonds,q+1,r);\r
+    }\r
+  }\r
+\r
+  private static int partition(Vector bonds, int p, int r) {\r
+    float x = ((Bond)bonds.elementAt(p)).start[2];\r
+    int i = p-1;\r
+    int j = r+1;\r
+\r
+    while(true) {\r
+      do {\r
+        j = j-1;\r
+      }        while (j >= 0  && ((Bond)bonds.elementAt(j)).start[2] > x);\r
+\r
+      do {\r
+        i = i+1;\r
+      } while (i < bonds.size() && ((Bond)bonds.elementAt(i)).start[2] < x);\r
+\r
+      if ( i < j) {\r
+        Bond tmp = (Bond)bonds.elementAt(i);\r
+        bonds.setElementAt(bonds.elementAt(j),i);\r
+        bonds.setElementAt(tmp,j);\r
+      } else {\r
+        return j;\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+\r
+\r
diff --git a/src/MCview/myAtom.java b/src/MCview/myAtom.java
new file mode 100755 (executable)
index 0000000..93166a5
--- /dev/null
@@ -0,0 +1,55 @@
+package MCview;\r
+\r
+import java.util.*;\r
+import java.awt.*;\r
+\r
+public class myAtom {\r
+  float x;\r
+  float y;\r
+  float z;\r
+\r
+  public int     number;\r
+  public String  name;\r
+  public String  resName;\r
+  public int     resNumber;\r
+  public int     type;\r
+  public Color   color;\r
+  public String  chain;\r
+  public boolean isSelected = false;\r
+\r
+  public myAtom(StringTokenizer str) {\r
+\r
+    this.number  = (new Integer(str.nextToken())).intValue();\r
+    this.name    = str.nextToken();\r
+    this.resName = str.nextToken();\r
+\r
+    String tmpstr = new String();\r
+\r
+    try {\r
+      tmpstr         = str.nextToken();\r
+      this.resNumber = (new Integer(tmpstr).intValue());\r
+      this.chain     = "A";\r
+      this.color     = Color.lightGray;\r
+\r
+    } catch(NumberFormatException e) {\r
+      this.chain = tmpstr;\r
+\r
+      if (tmpstr.equals("A")) {\r
+        this.color = Color.lightGray;\r
+\r
+      } else {\r
+        this.color = Color.red;\r
+      }\r
+\r
+      this.resNumber = (new Integer(str.nextToken()).intValue());\r
+    }\r
+\r
+    this.x = (float)(new Float(str.nextToken()).floatValue());\r
+    this.y = (float)(new Float(str.nextToken()).floatValue());\r
+    this.z = (float)(new Float(str.nextToken()).floatValue());\r
+  }\r
+\r
+  public void setColor(Color col) {\r
+    this.color = col;\r
+  }\r
+}\r
diff --git a/src/MCview/rotCanvas.java b/src/MCview/rotCanvas.java
new file mode 100755 (executable)
index 0000000..4690a15
--- /dev/null
@@ -0,0 +1,655 @@
+package MCview;\r
+\r
+import java.awt.*;\r
+import java.awt.event.*;\r
+import java.util.*;\r
+import java.io.*;\r
+import javax.swing.*;\r
+\r
+public class rotCanvas extends JPanel implements KeyListener,\r
+                                                 MouseListener,\r
+                                                 MouseMotionListener {\r
+  MCMatrix  idmat  = new MCMatrix(3,3);\r
+  MCMatrix  objmat = new MCMatrix(3,3);\r
+\r
+  boolean redrawneeded =true;\r
+\r
+  int omx = 0;\r
+  int mx = 0;\r
+  int omy = 0;\r
+  int my = 0;\r
+\r
+  public PDBfile pdb;\r
+\r
+  int bsize;\r
+\r
+  Image img;\r
+  Graphics ig;\r
+\r
+  Dimension prefsize;\r
+\r
+  float centre[] = new float[3];\r
+  float width[]  = new float[3];\r
+\r
+  float maxwidth;\r
+  float scale;\r
+\r
+  String inStr;\r
+  String inType;\r
+\r
+  boolean depthcue   = true;\r
+  boolean wire       = false;\r
+  boolean bymolecule = false;\r
+  boolean zbuffer    = true;\r
+\r
+  boolean dragging;\r
+\r
+  int xstart;\r
+  int xend;\r
+  int ystart;\r
+  int yend;\r
+  int xmid;\r
+  int ymid;\r
+\r
+  Font font = new Font("Helvetica",Font.PLAIN,10);\r
+\r
+  public rotCanvas(PDBfile pdb) throws IOException {\r
+\r
+    this.pdb      = pdb;\r
+    this.prefsize = new Dimension( getWidth(), getHeight());\r
+\r
+    //Initialize the matrices to identity\r
+\r
+    for (int i = 0; i < 3; i++) {\r
+      for (int j = 0; j < 3 ; j++) {\r
+        if (i != j) {\r
+          idmat.addElement(i,j,0);\r
+          objmat.addElement(i,j,0);\r
+        } else {\r
+          idmat.addElement(i,j,1);\r
+          objmat.addElement(i,j,1);\r
+        }\r
+      }\r
+    }\r
+\r
+    addMouseMotionListener(this);\r
+    addMouseListener(this);\r
+    addKeyListener(this);\r
+\r
+    addPDBfile();\r
+    ToolTipManager.sharedInstance().registerComponent(this);\r
+\r
+  }\r
+\r
+  public void addPDBfile() {\r
+    findCentre();\r
+    findWidth();\r
+\r
+    scale = findScale();\r
+\r
+    System.out.println("Scale factor = " + scale);\r
+  }\r
+\r
+  public void deleteBonds() {\r
+    scale     = 0;\r
+    maxwidth  = 0;\r
+\r
+    width[0] = 0;\r
+    width[1] = 0;\r
+    width[2] = 0;\r
+\r
+    centre[0] = 0;\r
+    centre[1] = 0;\r
+    centre[2] = 0;\r
+\r
+    for (int i=0; i < pdb.chains.size(); i++) {\r
+      ((PDBChain)pdb.chains.elementAt(i)).bonds = null;\r
+    }\r
+  }\r
+\r
+  public void findWidth() {\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
+      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
+          Bond tmp = (Bond)bonds.elementAt(i);\r
+\r
+          if (tmp.start[0] >= max[0])\r
+            max[0] = tmp.start[0];\r
+          if (tmp.start[1] >= max[1])\r
+            max[1] = tmp.start[1];\r
+          if (tmp.start[2] >= max[2])\r
+            max[2] = tmp.start[2];\r
+          if (tmp.start[0] <= min[0])\r
+            min[0] = tmp.start[0];\r
+          if (tmp.start[1] <= min[1])\r
+            min[1] = tmp.start[1];\r
+          if (tmp.start[2] <= min[2])\r
+            min[2] = tmp.start[2];\r
+\r
+          if (tmp.end[0] >= max[0])\r
+            max[0] = tmp.end[0];\r
+          if (tmp.end[1] >= max[1])\r
+            max[1] = tmp.end[1];\r
+          if (tmp.end[2] >= max[2])\r
+            max[2] = tmp.end[2];\r
+          if (tmp.end[0] <= min[0])\r
+            min[0] = tmp.end[0];\r
+          if (tmp.end[1] <= min[1])\r
+            min[1] = tmp.end[1];\r
+          if (tmp.end[2] <= min[2])\r
+            min[2] = tmp.end[2];\r
+        }\r
+      }\r
+    }\r
+\r
+    System.out.println("xmax " + max[0] + " min " + min[0]);\r
+    System.out.println("ymax " + max[1] + " min " + min[1]);\r
+    System.out.println("zmax " + max[2] + " min " + min[2]);\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
+      maxwidth = width[1];\r
+    if (width[2] > width[1])\r
+      maxwidth = width[2];\r
+\r
+    System.out.println("Maxwidth = " + maxwidth);\r
+  }\r
+\r
+  public float findScale() {\r
+    int dim, width, height;\r
+\r
+    if ( getWidth() != 0) {\r
+      width  = getWidth();\r
+      height = getHeight();\r
+\r
+    } else {\r
+      width  = prefsize.width;\r
+      height = prefsize.height;\r
+    }\r
+\r
+    if (width < height) {\r
+      dim = width;\r
+    } else {\r
+      dim = height;\r
+    }\r
+\r
+    return (float)(dim/(1.5d*maxwidth));\r
+  }\r
+\r
+\r
+\r
+  public void findCentre() {\r
+    float xtot = 0;\r
+    float ytot = 0;\r
+    float ztot = 0;\r
+\r
+    int bsize  = 0;\r
+    //Find centre coordinate\r
+\r
+    for (int ii = 0; ii < pdb.chains.size() ; ii++) {\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 paintComponent(Graphics g) {\r
+    //Only create the image at the beginning -\r
+    //this saves much memory usage\r
+    if ((img == null) || (prefsize.width != getWidth()) || (prefsize.height != getHeight())) {\r
+      prefsize.width  = getWidth();\r
+      prefsize.height = getHeight();\r
+\r
+      scale = findScale();\r
+      img   = createImage(prefsize.width,prefsize.height);\r
+      ig    = img.getGraphics();\r
+\r
+      redrawneeded = true;\r
+    }\r
+\r
+    if (redrawneeded == true) {\r
+      drawBackground(ig,Color.black);\r
+      drawScene(ig);\r
+      redrawneeded = false;\r
+    } else {\r
+      ig = img.getGraphics();\r
+    }\r
+\r
+    g.drawImage(img,0,0,this);\r
+  }\r
+\r
+  public void drawBackground(Graphics g, Color col) {\r
+    g.setColor(col);\r
+    g.fillRect(0,0,prefsize.width,prefsize.height);\r
+  }\r
+\r
+\r
+  public void drawScene(Graphics g) {\r
+    // Sort the bonds by z coord\r
+\r
+    Vector bonds = new Vector();\r
+\r
+\r
+    for (int ii = 0; ii < pdb.chains.size() ; ii++) {\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
+          bonds.addElement(tmp.elementAt(i));\r
+        }\r
+      }\r
+    }\r
+\r
+    if (zbuffer) {\r
+      Zsort.Zsort(bonds);\r
+    }\r
+\r
+    for (int i = 0; i < bonds.size(); i++) {\r
+      Bond tmpBond = (Bond)bonds.elementAt(i);\r
+\r
+      xstart = (int)((tmpBond.start[0] - centre[0])*scale + getWidth()/2);\r
+      ystart = (int)((tmpBond.start[1] - centre[1])*scale + getHeight()/2);\r
+\r
+      xend = (int)((tmpBond.end[0] - centre[0])*scale + getWidth()/2);\r
+      yend = (int)((tmpBond.end[1] - centre[1])*scale + getHeight()/2);\r
+\r
+      xmid = (xend+xstart)/2;\r
+      ymid = (yend+ystart)/2;\r
+\r
+\r
+      if (depthcue && !bymolecule) {\r
+\r
+        if (tmpBond.start[2] < (centre[2] - maxwidth/6))  {\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
+        } else if (tmpBond.start[2] < (centre[2]+maxwidth/6)) {\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
+        } else {\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
+      } else if (depthcue && bymolecule) {\r
+        if (tmpBond.start[2] < (centre[2] - maxwidth/6))  {\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
+          g.setColor(Color.green.darker());\r
+          drawLine(g,xstart,ystart,xend,yend);\r
+\r
+        } else {\r
+          g.setColor(Color.green);\r
+          drawLine(g,xstart,ystart,xend,yend);\r
+\r
+        }\r
+      } else if (!depthcue && !bymolecule) {\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
+        drawLine(g,xstart,ystart,xend,yend);\r
+      }\r
+    }\r
+  }\r
+\r
+  public void drawLine(Graphics g, int x1, int y1, int x2, int y2) {\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
+      } else {\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
+      g.drawLine(x1,y1,x2,y2);\r
+    }\r
+  }\r
+\r
+  public Dimension minimumsize() {\r
+    return prefsize;\r
+  }\r
+  public Dimension preferredsize() {\r
+    return prefsize;\r
+  }\r
+\r
+  public void keyTyped(KeyEvent evt) { }\r
+  public void keyReleased(KeyEvent evt) { }\r
+  public void keyPressed(KeyEvent evt) {\r
+    int key = evt.getKeyChar();\r
+\r
+    if (evt.getKeyCode() == KeyEvent.VK_UP) {\r
+      scale        = (float)(scale * 1.1);\r
+      redrawneeded = true;\r
+      repaint();\r
+\r
+    } else if (evt.getKeyCode() == KeyEvent.VK_DOWN) {\r
+      scale        = (float)(scale * 0.9);\r
+      redrawneeded = true;\r
+      repaint();\r
+\r
+    } else if (key == 'w') {\r
+\r
+      wire = !wire;\r
+      System.out.println("wireframe " + wire);\r
+      redrawneeded = true;\r
+      repaint();\r
+\r
+    } else if (key == 'd') {\r
+      depthcue = !depthcue;\r
+      System.out.println("Depth cueing is " + depthcue);\r
+      redrawneeded = true;\r
+      repaint();\r
+\r
+    } else if (key == 'm') {\r
+      bymolecule = !bymolecule;\r
+      System.out.println("Bymolecule is " + bymolecule);\r
+      redrawneeded = true;\r
+      repaint();\r
+\r
+    } else if (key == 'z') {\r
+      zbuffer = !zbuffer;\r
+      System.out.println("Z buffering is " + zbuffer);\r
+      redrawneeded = true;\r
+      repaint();\r
+\r
+    } else if (key == 'c') {\r
+      bymolecule = false;\r
+      pdb.setChainColours();\r
+      System.out.println("Colouring by chain");\r
+      redrawneeded = true;\r
+      repaint();\r
+\r
+    } else if (key == 'h') {\r
+      bymolecule = false;\r
+      pdb.setHydrophobicityColours();\r
+      System.out.println("Colouring by hydrophobicity");\r
+      redrawneeded = true;\r
+      repaint();\r
+\r
+    } else if (key == 'q') {\r
+      bymolecule = false;\r
+      pdb.setChargeColours();\r
+      System.out.println("Colouring charges and cysteines");\r
+      redrawneeded = true;\r
+      repaint();\r
+\r
+    }\r
+    return;\r
+  }\r
+\r
+  public void mousePressed(MouseEvent e)\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
+    myAtom fatom = null;\r
+    for (int ii = 0; ii < pdb.chains.size(); ii++)\r
+    {\r
+\r
+      PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
+      if (chain.isVisible)\r
+      {\r
+        Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;\r
+        for (int i = 0; i < bonds.size(); i++)\r
+        {\r
+          Bond tmpBond = (Bond) bonds.elementAt(i);\r
+          int truex = (int) ( (tmpBond.start[0] - centre[0]) * scale +\r
+                             getWidth() / 2);\r
+          if (Math.abs(truex - e.getX()) <= 2)\r
+          {\r
+            int truey = (int) ( (tmpBond.start[1] - centre[1]) * scale +\r
+                               getHeight() / 2);\r
+            if (Math.abs(truey - e.getY()) <= 2)\r
+              fatom = tmpBond.at1;\r
+          }\r
+        }\r
+      }\r
+    }\r
+    if(fatom!=null)\r
+       this.setToolTipText(fatom.resName);\r
+     else\r
+        this.setToolTipText(null);\r
+  }\r
+\r
+  public void mouseClicked(MouseEvent e) { }\r
+  public void mouseEntered(MouseEvent e) { }\r
+  public void mouseExited(MouseEvent e) { }\r
+\r
+  public void mouseDragged(MouseEvent evt) {\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
+      objmat.rotatez((float)((mx-omx)));\r
+    } else {\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
+      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
+    redrawneeded = true;\r
+\r
+    paint(this.getGraphics());\r
+\r
+    dragging = true;\r
+    return;\r
+  }\r
+\r
+  public void mouseReleased(MouseEvent evt) {\r
+    int x = evt.getX();\r
+    int y = evt.getY();\r
+\r
+    if (!dragging) {\r
+      myAtom tmp = findAtom(x,y);\r
+    }\r
+    drawLabels();\r
+    return;\r
+  }\r
+\r
+  public void drawLabels() {\r
+    redrawneeded = true;\r
+    paint(this.getGraphics());\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
+          Bond tmpBond = (Bond)bonds.elementAt(i);\r
+\r
+          if (tmpBond.at1.isSelected) {\r
+            labelAtom(img.getGraphics(),tmpBond,1);\r
+          }\r
+\r
+          if (tmpBond.at2.isSelected) {\r
+            labelAtom(img.getGraphics(),tmpBond,2);\r
+          }\r
+\r
+        }\r
+      }\r
+    }\r
+\r
+    this.getGraphics().drawImage(img,0,0,this);\r
+\r
+    dragging = false;\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 + getWidth()/2);\r
+      int ystart = (int)((b.start[1] - centre[1])*scale + getHeight()/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 + getWidth()/2);\r
+      int ystart = (int)((b.end[1] - centre[1])*scale + getHeight()/2);\r
+\r
+      g.setColor(Color.red);\r
+      g.drawString(b.at2.resName + "-" + b.at2.resNumber,xstart,ystart);\r
+    }\r
+  }\r
+\r
+\r
+  public myAtom findAtom(int x, int y) {\r
+    myAtom fatom = null;\r
+\r
+    int foundchain = -1;\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
+          Bond tmpBond = (Bond)bonds.elementAt(i);\r
+\r
+          int truex = (int)((tmpBond.start[0] - centre[0])*scale + getWidth()/2);\r
+\r
+          if (Math.abs(truex - x) <= 2) {\r
+\r
+            int truey = (int)((tmpBond.start[1] - centre[1])*scale + getHeight()/2);\r
+\r
+            if (Math.abs(truey - y) <= 2) {\r
+\r
+              System.out.println("Found match");\r
+              System.out.println(x + " " + y);\r
+              System.out.println(truex + " " + truey);\r
+              System.out.println(tmpBond.start[0] + " " + tmpBond.start[1]);\r
+              System.out.println("Atom 1 = " + tmpBond.at1.resName + " " +\r
+                                 tmpBond.at1.resNumber + " " + tmpBond.at1.chain);\r
+              fatom = tmpBond.at1;\r
+              fatom.isSelected = !fatom.isSelected;\r
+              foundchain = ii;\r
+            }\r
+          }\r
+        }\r
+      }\r
+\r
+      if (fatom != null) //)&& chain.ds != null)\r
+      {\r
+        chain = (PDBChain)pdb.chains.elementAt(foundchain);\r
+        // SMJS TODO\r
+        // int tmp = chain.ds.seqstart + fatom.resNumber - chain.offset;\r
+        // int pos = chain.ds.findIndex(tmp);\r
+        // System.out.println("Found seq " + chain.ds.name + " "  + tmp + " " + pos);\r
+      }\r
+\r
+    }\r
+    return fatom;\r
+  }\r
+\r
+  public void update(Graphics g) {\r
+    paint(g);\r
+  }\r
+\r
+}\r