--- /dev/null
+/*\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 jalview.analysis.AlignSeq;\r
+\r
+import jalview.datamodel.*;\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 java.io.*;\r
+\r
+import java.util.*;\r
+\r
+\r
+\r
+public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotionListener\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
+ 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
+ jalview.appletgui.SeqCanvas seqcanvas;\r
+ public Sequence 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
+\r
+ public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq)\r
+ {\r
+ this.seqcanvas = seqcanvas;\r
+ this.sequence = seq;\r
+\r
+ seqcanvas.setPDBCanvas(this);\r
+ addKeyListener(new KeyAdapter()\r
+ {\r
+\r
+ public void keyPressed(KeyEvent evt)\r
+ {\r
+ doKeyPressed(evt);\r
+ }\r
+ });\r
+ }\r
+\r
+\r
+ public void setPDBFile(PDBfile pdb)\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
+ for (int i = 0; i < pdb.chains.size(); i++)\r
+ {\r
+\r
+ mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + ((PDBChain) pdb.chains.elementAt(i)).sequence.getSequence());\r
+ mappingDetails.append("\nNo of residues = " + ((PDBChain) pdb.chains.elementAt(i)).residues.size()+"\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, "pep");\r
+ as.calcScoreMatrix();\r
+ as.traceAlignment();\r
+ PrintStream ps = new PrintStream(System.out)\r
+ {\r
+ public void print(String x) {\r
+ mappingDetails.append(x);\r
+ }\r
+ public void println()\r
+ {\r
+ mappingDetails.append("\n");\r
+ }\r
+ };\r
+\r
+ as.printAlignment(ps);\r
+\r
+ if (as.maxscore > max) {\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
+\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
+ 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
+\r
+\r
+ findCentre();\r
+ findWidth();\r
+\r
+ setupBonds();\r
+\r
+ scale = findScale();\r
+ }\r
+\r
+\r
+ Vector visiblebonds;\r
+ void setupBonds()\r
+ {\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
+ updateSeqColours();\r
+ redrawneeded = true;\r
+ repaint();\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
+ 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
+ }\r
+\r
+ if (tmp.start[1] >= max[1]) {\r
+ max[1] = tmp.start[1];\r
+ }\r
+\r
+ if (tmp.start[2] >= max[2]) {\r
+ max[2] = tmp.start[2];\r
+ }\r
+\r
+ if (tmp.start[0] <= min[0]) {\r
+ min[0] = tmp.start[0];\r
+ }\r
+\r
+ if (tmp.start[1] <= min[1]) {\r
+ min[1] = tmp.start[1];\r
+ }\r
+\r
+ if (tmp.start[2] <= min[2]) {\r
+ min[2] = tmp.start[2];\r
+ }\r
+\r
+ if (tmp.end[0] >= max[0]) {\r
+ max[0] = tmp.end[0];\r
+ }\r
+\r
+ if (tmp.end[1] >= max[1]) {\r
+ max[1] = tmp.end[1];\r
+ }\r
+\r
+ if (tmp.end[2] >= max[2]) {\r
+ max[2] = tmp.end[2];\r
+ }\r
+\r
+ if (tmp.end[0] <= min[0]) {\r
+ min[0] = tmp.end[0];\r
+ }\r
+\r
+ if (tmp.end[1] <= min[1]) {\r
+ min[1] = tmp.end[1];\r
+ }\r
+\r
+ if (tmp.end[2] <= min[2]) {\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
+ maxwidth = width[1];\r
+ }\r
+\r
+ if (width[2] > width[1]) {\r
+ maxwidth = width[2];\r
+ }\r
+\r
+ // System.out.println("Maxwidth = " + maxwidth);\r
+ }\r
+\r
+ public float findScale() {\r
+ int dim;\r
+ int width;\r
+ int height;\r
+\r
+ if (getSize().width != 0) {\r
+ width = getSize().width;\r
+ height = getSize().height;\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
+ public void findCentre() {\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
+ if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {\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
+ 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
+ else if(visiblebonds==null)\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
+\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
+ try{ 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
+ }catch(Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\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
+\r
+ public void updateSeqColours()\r
+ {\r
+ if (pdbAction)\r
+ {\r
+ return;\r
+ }\r
+\r
+ if(bysequence && pdb!=null)\r
+ {\r
+ for (int ii = 0; ii < pdb.chains.size(); ii++)\r
+ {\r
+ colourBySequence((PDBChain) pdb.chains.elementAt(ii));\r
+ }\r
+ }\r
+\r
+ redrawneeded=true;\r
+ repaint();\r
+ }\r
+\r
+\r
+ int findTrueIndex(int pos)\r
+ {\r
+ // returns the alignment position for a residue\r
+ int j = sequence.getStart();\r
+ int i = 0;\r
+\r
+ while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && (j <= pos+1))\r
+ {\r
+ if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))\r
+ {\r
+ j++;\r
+ }\r
+\r
+ i++;\r
+ }\r
+\r
+ if(i>1)\r
+ i--;\r
+\r
+ if ( (j == sequence.getEnd()) && (j < pos))\r
+ {\r
+ return sequence.getEnd() + 1;\r
+ }\r
+ else\r
+ {\r
+ return i;\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(PDBChain chain)\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
+ continue;\r
+\r
+ if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&\r
+ (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))\r
+ {\r
+\r
+ int index = findTrueIndex(tmp.at1.alignmentMapping);\r
+ //sequence.findIndex(tmp.at1.alignmentMapping);\r
+ if (index != -1)\r
+ {\r
+ tmp.startCol = seqcanvas.getSequenceRenderer().\r
+ getResidueBoxColour( sequence, index);\r
+\r
+ // tmp.startCol = seqcanvas.getFeatureRenderer().\r
+ // findFeatureColour(tmp.startCol, sequence, index);\r
+ }\r
+ }\r
+\r
+ int index = findTrueIndex(tmp.at2.alignmentMapping);\r
+ //sequence.findIndex( tmp.at2.alignmentMapping );\r
+ if (index != -1)\r
+ {\r
+ tmp.endCol = seqcanvas.getSequenceRenderer().\r
+ getResidueBoxColour( sequence, index);\r
+ // tmp.endCol = seqcanvas.getFeatureRenderer().\r
+ // findFeatureColour(tmp.endCol, sequence, index);\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ public void drawScene(Graphics g)\r
+ {\r
+\r
+ if (zbuffer) {\r
+ Zsort.Zsort(visiblebonds);\r
+ }\r
+\r
+\r
+ Bond tmpBond=null;\r
+ for (int i = 0; i < visiblebonds.size(); i++)\r
+ {\r
+ tmpBond = (Bond) visiblebonds.elementAt(i);\r
+\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
+ 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
+\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
+ } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {\r
+ g.setColor(Color.green.darker());\r
+ drawLine(g, xstart, ystart, xend, yend);\r
+ } else {\r
+ g.setColor(Color.green);\r
+ drawLine(g, xstart, ystart, xend, yend);\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
+ } else {\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
+ if (!wire) {\r
+ if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) {\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
+ } else {\r
+ g.drawLine(x1, y1, x2, y2);\r
+ }\r
+ }\r
+\r
+ public Dimension minimumsize() {\r
+ return prefsize;\r
+ }\r
+\r
+ public Dimension preferredsize() {\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
+ 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
+ highlightRes = new Vector();\r
+\r
+ if (highlightRes.contains(fatom.alignmentMapping+"" + ""))\r
+ highlightRes.removeElement(fatom.alignmentMapping + "");\r
+ else\r
+ highlightRes.addElement(fatom.alignmentMapping + "");\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
+ 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
+ highlightSeqcanvas( fatom.alignmentMapping );\r
+ }\r
+ }\r
+\r
+ if (fatom != null) {\r
+ toolx = e.getX();\r
+ tooly = e.getY();\r
+\r
+ appletToolTip = chain.id+":"+ fatom.resNumber+" "+ fatom.resName;\r
+ redrawneeded = true;\r
+ repaint();\r
+ } else {\r
+ highlightSeqcanvas( -1);\r
+ appletToolTip = null;\r
+ redrawneeded = true;\r
+ repaint();\r
+ }\r
+ }\r
+\r
+\r
+ void highlightSeqcanvas(int pos)\r
+ {\r
+ int index = seqcanvas.getViewport().getAlignment().findIndex(sequence);\r
+\r
+ int size = pos==-1?0:3;\r
+\r
+ if(highlightRes!=null)\r
+ size += highlightRes.size()*3;\r
+\r
+ int [] array = new int[size];\r
+ int i=0;\r
+ if(highlightRes!=null)\r
+ {\r
+ for (i = 0; i < highlightRes.size(); i++)\r
+ {\r
+ int a = Integer.parseInt(highlightRes.elementAt(\r
+ i).toString())+1;\r
+ array[i * 3] = index;\r
+ array[ (i * 3) + 1] = a;\r
+ array[ (i * 3) + 2] = a;\r
+ }\r
+ }\r
+\r
+ if(pos!=-1)\r
+ {\r
+ array[i * 3] = index;\r
+ array[i * 3 + 1] = pos+1;\r
+ array[i * 3 + 2] = pos+1;\r
+ }\r
+\r
+ seqcanvas.highlightSearchResults(array);\r
+ }\r
+\r
+\r
+ public void mouseClicked(MouseEvent e) {\r
+ }\r
+\r
+ public void mouseEntered(MouseEvent e) {\r
+ }\r
+\r
+ public void mouseExited(MouseEvent e) {\r
+ }\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
+ 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
+ dragging = false;\r
+ return;\r
+ }\r
+\r
+ void drawLabels(Graphics g) {\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
+ g.setFont(font);\r
+\r
+ if (n == 1) {\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
+ 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
+ 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
+\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
+ highlightBond1.at2.isSelected = false;\r
+\r
+ if (highlightBond2 != null)\r
+ highlightBond2.at1.isSelected = false;\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
+\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
--- /dev/null
+package MCview;\r
+\r
+import java.awt.*;\r
+\r
+import java.awt.event.*;\r
+import jalview.datamodel.*;\r
+import jalview.appletgui.*;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.ActionEvent;\r
+\r
+\r
+public class AppletPDBViewer extends Frame\r
+{\r
+ PDBEntry pdb;\r
+ Sequence sequence;\r
+ AppletPDBCanvas pdbcanvas;\r
+\r
+\r
+ public AppletPDBViewer(String pdbtext,String type,\r
+ Sequence seq,\r
+ SeqCanvas seqcanvas)\r
+ {\r
+ sequence = seq;\r
+\r
+ try\r
+ {\r
+ jbInit();\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+\r
+ pdbcanvas = new AppletPDBCanvas(seqcanvas, seq);\r
+\r
+ add(pdbcanvas, BorderLayout.CENTER);\r
+\r
+ StringBuffer title = new StringBuffer(sequence.getName() + ":");\r
+\r
+ jalview.bin.JalviewLite.addFrame(this,title.toString(),400, 400);\r
+\r
+ try{\r
+ PDBfile pdbfile = new PDBfile(pdbtext, type);\r
+ pdbcanvas.setPDBFile(pdbfile);\r
+ }\r
+ catch(Exception ex){\r
+ pdbcanvas.errorLoading = true;\r
+ pdbcanvas.repaint();\r
+ }\r
+ }\r
+\r
+\r
+ private void jbInit()\r
+ throws Exception\r
+ {\r
+ this.setMenuBar(jMenuBar1);\r
+ fileMenu.setLabel("File");\r
+ coloursMenu.setLabel("Colours");\r
+ mapping.setLabel("View Mapping");\r
+ mapping.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ mapping_actionPerformed();\r
+ }\r
+ });\r
+ wire.setLabel("Wireframe");\r
+ wire.addItemListener(new ItemListener()\r
+ {\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ wire_actionPerformed();\r
+ }\r
+ });\r
+ depth.setState(true);\r
+ depth.setLabel("Depthcue");\r
+ depth.addItemListener(new ItemListener()\r
+ {\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ depth_actionPerformed();\r
+ }\r
+ });\r
+ zbuffer.setState(true);\r
+ zbuffer.setLabel("Z Buffering");\r
+ zbuffer.addItemListener(new ItemListener()\r
+ {\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ zbuffer_actionPerformed();\r
+ }\r
+ });\r
+ charge.setLabel("Charge & Cysteine");\r
+ charge.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ charge_actionPerformed();\r
+ }\r
+ });\r
+ hydro.setLabel("Hydrophobicity");\r
+ hydro.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ hydro_actionPerformed();\r
+ }\r
+ });\r
+ chain.setLabel("By Chain");\r
+ chain.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ chain_actionPerformed();\r
+ }\r
+ });\r
+ seqButton.setLabel("By Sequence");\r
+ seqButton.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e){\r
+ seqButton_actionPerformed();\r
+ }\r
+ });\r
+ allchains.setLabel("All Chains Visible");\r
+ allchains.addItemListener(new ItemListener()\r
+ {\r
+ public void itemStateChanged(ItemEvent itemEvent)\r
+ {\r
+ allchains_itemStateChanged(itemEvent);\r
+ }\r
+ });\r
+ jMenuBar1.add(fileMenu);\r
+ jMenuBar1.add(coloursMenu);\r
+ fileMenu.add(mapping);;\r
+\r
+ coloursMenu.add(seqButton);\r
+ coloursMenu.add(chain);\r
+ coloursMenu.add(hydro);\r
+ coloursMenu.add(charge);\r
+ coloursMenu.addSeparator();\r
+ coloursMenu.add(wire);\r
+ coloursMenu.add(depth);\r
+ coloursMenu.add(zbuffer);\r
+ coloursMenu.add(allchains);\r
+ allchains.setState(true);\r
+ }\r
+\r
+ MenuBar jMenuBar1 = new MenuBar();\r
+ Menu fileMenu = new Menu();\r
+ Menu coloursMenu = new Menu();\r
+ MenuItem mapping = new MenuItem();\r
+ CheckboxGroup bg = new CheckboxGroup();\r
+ CheckboxMenuItem wire = new CheckboxMenuItem();\r
+ CheckboxMenuItem depth = new CheckboxMenuItem();\r
+ CheckboxMenuItem zbuffer = new CheckboxMenuItem();\r
+\r
+ MenuItem charge = new MenuItem();\r
+ MenuItem hydro = new MenuItem();\r
+ MenuItem chain = new MenuItem();\r
+ MenuItem seqButton = new MenuItem();\r
+\r
+ CheckboxMenuItem allchains = new CheckboxMenuItem();\r
+\r
+ public void charge_actionPerformed()\r
+ {\r
+ clearButtonGroup();\r
+ pdbcanvas.pdb.setChargeColours();\r
+ pdbcanvas.redrawneeded=true;\r
+ pdbcanvas.repaint();\r
+ }\r
+\r
+ public void hydro_actionPerformed()\r
+ {\r
+ clearButtonGroup();\r
+ pdbcanvas.pdb.setHydrophobicityColours();\r
+ pdbcanvas.redrawneeded=true;\r
+ pdbcanvas.repaint();\r
+ }\r
+\r
+ public void chain_actionPerformed()\r
+ {\r
+ clearButtonGroup();\r
+ pdbcanvas.pdb.setChainColours();\r
+ pdbcanvas.redrawneeded=true;\r
+ pdbcanvas.repaint();\r
+ }\r
+\r
+ public void zbuffer_actionPerformed()\r
+ {\r
+ pdbcanvas.zbuffer = ! pdbcanvas.zbuffer;\r
+ pdbcanvas.redrawneeded=true;\r
+ pdbcanvas.repaint();\r
+ }\r
+\r
+ public void depth_actionPerformed()\r
+ {\r
+ pdbcanvas.depthcue = ! pdbcanvas.depthcue;\r
+ pdbcanvas.redrawneeded=true;\r
+ pdbcanvas.repaint();\r
+ }\r
+\r
+ public void wire_actionPerformed()\r
+ {\r
+ pdbcanvas.wire = ! pdbcanvas.wire;\r
+ pdbcanvas.redrawneeded=true;\r
+ pdbcanvas.repaint();\r
+ }\r
+\r
+ public void seqButton_actionPerformed()\r
+ {\r
+ clearButtonGroup();\r
+ pdbcanvas.bysequence = true;\r
+ pdbcanvas.updateSeqColours();\r
+ pdbcanvas.repaint();\r
+ }\r
+\r
+ void clearButtonGroup()\r
+ {\r
+ pdbcanvas.bysequence = false;\r
+ pdbcanvas.bymolecule = false;\r
+ }\r
+\r
+ public void mapping_actionPerformed()\r
+ {\r
+ jalview.appletgui.CutAndPasteTransfer cap\r
+ = new jalview.appletgui.CutAndPasteTransfer(false, null);\r
+ Frame frame = new Frame();\r
+ frame.add(cap);\r
+ jalview.bin.JalviewLite.addFrame(frame, "PDB - Sequence Mapping", 500, 600);\r
+ cap.setText(pdbcanvas.mappingDetails.toString());\r
+ }\r
+\r
+ public void allchains_itemStateChanged(ItemEvent itemEvent)\r
+ {\r
+ pdbcanvas.setAllchainsVisible(allchains.getState());\r
+ }\r
+}\r
\r
import java.awt.*;\r
\r
-import java.util.*;\r
-\r
\r
public class Atom {\r
- double x;\r
- double y;\r
- double z;\r
+ float x;\r
+ float y;\r
+ float z;\r
int number;\r
String name;\r
String resName;\r
int type;\r
Color color;\r
String chain;\r
+ int alignmentMapping=-1;\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
+ public boolean isSelected = false;\r
\r
- String tmpstr = new String();\r
+ public Atom(String str)\r
+ {\r
+ name = str.substring(12,15).trim();\r
\r
- try {\r
- tmpstr = str.nextToken();\r
+ resName = str.substring(17,20);\r
\r
- this.resNumber = (new Integer(tmpstr).intValue());\r
- this.chain = "A";\r
- this.color = Color.green;\r
- } catch (NumberFormatException e) {\r
- this.chain = tmpstr;\r
+ chain = str.substring(21,22);\r
\r
- if (tmpstr.equals("A")) {\r
- this.color = new Color((float) Math.random(),\r
- (float) Math.random(), (float) Math.random());\r
- } else {\r
- this.color = Color.red;\r
- }\r
+ resNumber = Integer.parseInt(str.substring(22,26).trim());\r
\r
- this.resNumber = (new Integer(str.nextToken()).intValue());\r
- }\r
+ this.x = (float) (new Float(str.substring(30,38).trim()).floatValue());\r
+ this.y = (float) (new Float(str.substring(38,46).trim()).floatValue());\r
+ this.z = (float) (new Float(str.substring(47,55).trim()).floatValue());\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
public void setColor(Color col) {\r
float[] end;\r
Color startCol;\r
Color endCol;\r
- public myAtom at1;\r
- public myAtom at2;\r
+ public Atom at1;\r
+ public Atom at2;\r
\r
- public Bond(float[] start, float[] end, myAtom at1, myAtom at2) {\r
+ public Bond(float[] start, float[] end, Atom at1, Atom at2) {\r
this.start = start;\r
this.end = end;\r
this.startCol = at1.color;\r
this.endCol = bond.endCol;\r
}\r
\r
- public void print() {\r
- System.out.println("Start " + start[0] + " " + start[1] + " " +\r
- 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
matrix[i][j] = value;\r
}\r
\r
- public void print() {\r
- System.out.println(matrix[0][0] + " " + matrix[0][1] + " " +\r
- matrix[0][2]);\r
- System.out.println(matrix[1][0] + " " + matrix[1][1] + " " +\r
- matrix[1][2]);\r
- System.out.println(matrix[2][0] + " " + matrix[2][1] + " " +\r
- 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
--- /dev/null
+/*\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 jalview.analysis.AlignSeq;\r
+\r
+import jalview.datamodel.*;\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 java.io.*;\r
+\r
+import java.util.*;\r
+\r
+import javax.swing.*;\r
+\r
+\r
+public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListener\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
+ 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
+ jalview.gui.SeqCanvas seqcanvas;\r
+ public Sequence sequence;\r
+ final StringBuffer mappingDetails = new StringBuffer();\r
+ PDBChain mainchain;\r
+ Vector highlightRes;\r
+ boolean pdbAction = false;\r
+\r
+ public PDBCanvas(jalview.gui.SeqCanvas seqcanvas, Sequence seq)\r
+ {\r
+ this.seqcanvas = seqcanvas;\r
+ this.sequence = seq;\r
+ seqcanvas.setPDBCanvas(this);\r
+ }\r
+\r
+ public void setPDBFile(PDBfile pdb)\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
+ for (int i = 0; i < pdb.chains.size(); i++)\r
+ {\r
+\r
+ mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + ((PDBChain) pdb.chains.elementAt(i)).sequence.getSequence());\r
+ mappingDetails.append("\nNo of residues = " + ((PDBChain) pdb.chains.elementAt(i)).residues.size()+"\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, "pep");\r
+ as.calcScoreMatrix();\r
+ as.traceAlignment();\r
+ PrintStream ps = new PrintStream(System.out)\r
+ {\r
+ public void print(String x) {\r
+ mappingDetails.append(x);\r
+ }\r
+ public void println()\r
+ {\r
+ mappingDetails.append("\n");\r
+ }\r
+ };\r
+\r
+ as.printAlignment(ps);\r
+\r
+\r
+\r
+ if (as.maxscore > max)\r
+ {\r
+ max = as.maxscore;\r
+ maxchain = i;\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
+\r
+ this.pdb = pdb;\r
+ this.prefsize = new Dimension(getWidth(), getHeight());\r
+\r
+ //Initialize the matrices to identity\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
+\r
+ addMouseWheelListener(new MouseWheelListener()\r
+ {\r
+ public void mouseWheelMoved(MouseWheelEvent e)\r
+ {\r
+ if (e.getWheelRotation() > 0)\r
+ {\r
+ scale = (float) (scale * 1.1);\r
+ redrawneeded = true;\r
+ repaint();\r
+ }\r
+\r
+ else\r
+ {\r
+ scale = (float) (scale * 0.9);\r
+ redrawneeded = true;\r
+ repaint();\r
+ }\r
+ }\r
+ });\r
+\r
+\r
+ findCentre();\r
+ findWidth();\r
+\r
+ setupBonds();\r
+\r
+ scale = findScale();\r
+\r
+ ToolTipManager.sharedInstance().registerComponent(this);\r
+ ToolTipManager.sharedInstance().setInitialDelay(0);\r
+ ToolTipManager.sharedInstance().setDismissDelay(10000);\r
+ }\r
+\r
+\r
+ Vector visiblebonds;\r
+ void setupBonds()\r
+ {\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
+\r
+ updateSeqColours();\r
+ redrawneeded = true;\r
+ repaint();\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
+ 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
+ }\r
+\r
+ if (tmp.start[1] >= max[1]) {\r
+ max[1] = tmp.start[1];\r
+ }\r
+\r
+ if (tmp.start[2] >= max[2]) {\r
+ max[2] = tmp.start[2];\r
+ }\r
+\r
+ if (tmp.start[0] <= min[0]) {\r
+ min[0] = tmp.start[0];\r
+ }\r
+\r
+ if (tmp.start[1] <= min[1]) {\r
+ min[1] = tmp.start[1];\r
+ }\r
+\r
+ if (tmp.start[2] <= min[2]) {\r
+ min[2] = tmp.start[2];\r
+ }\r
+\r
+ if (tmp.end[0] >= max[0]) {\r
+ max[0] = tmp.end[0];\r
+ }\r
+\r
+ if (tmp.end[1] >= max[1]) {\r
+ max[1] = tmp.end[1];\r
+ }\r
+\r
+ if (tmp.end[2] >= max[2]) {\r
+ max[2] = tmp.end[2];\r
+ }\r
+\r
+ if (tmp.end[0] <= min[0]) {\r
+ min[0] = tmp.end[0];\r
+ }\r
+\r
+ if (tmp.end[1] <= min[1]) {\r
+ min[1] = tmp.end[1];\r
+ }\r
+\r
+ if (tmp.end[2] <= min[2]) {\r
+ min[2] = tmp.end[2];\r
+ }\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
+ }\r
+\r
+ if (width[2] > width[1]) {\r
+ maxwidth = width[2];\r
+ }\r
+\r
+ // System.out.println("Maxwidth = " + maxwidth);\r
+ }\r
+\r
+ public float findScale() {\r
+ int dim;\r
+ int width;\r
+ int height;\r
+\r
+ if (getWidth() != 0) {\r
+ width = getWidth();\r
+ height = getHeight();\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
+ public void findCentre() {\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
+ if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {\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
+ 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
+ {\r
+ super.paintComponent(g);\r
+\r
+ if(visiblebonds==null)\r
+ {\r
+ g.setColor(Color.black);\r
+ g.setFont(new Font("Verdana", Font.BOLD, 14));\r
+ g.drawString("Retrieving PDB data....", 20, getHeight()/2);\r
+ return;\r
+ }\r
+\r
+\r
+ //Only create the image at the beginning -\r
+ //this saves much memory usage\r
+ if ((img == null)\r
+ || (prefsize.width != getWidth())\r
+ || (prefsize.height != getHeight()))\r
+\r
+ {\r
+ prefsize.width = getWidth();\r
+ prefsize.height = getHeight();\r
+\r
+ scale = findScale();\r
+ img = createImage(prefsize.width, prefsize.height);\r
+ ig = img.getGraphics();\r
+ Graphics2D ig2 = (Graphics2D) ig;\r
+\r
+ ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
+ RenderingHints.VALUE_ANTIALIAS_ON);\r
+\r
+ redrawneeded = true;\r
+ }\r
+\r
+\r
+ if (redrawneeded)\r
+ {\r
+ drawAll(ig, prefsize.width, prefsize.height);\r
+ redrawneeded = false;\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
+ g.setColor(Color.black);\r
+ g.fillRect(0, 0, width, height);\r
+ drawScene(g);\r
+ drawLabels(g);\r
+ }\r
+\r
+\r
+ public void updateSeqColours()\r
+ {\r
+ if(pdbAction)\r
+ {\r
+ return;\r
+ }\r
+\r
+ // System.out.println("update seq colours");\r
+ if(bysequence && pdb!=null)\r
+ {\r
+ for (int ii = 0; ii < pdb.chains.size(); ii++)\r
+ {\r
+ colourBySequence( (PDBChain) pdb.chains.elementAt(ii));\r
+ }\r
+ }\r
+\r
+ redrawneeded=true;\r
+ repaint();\r
+ }\r
+\r
+ int findTrueIndex(int pos)\r
+ {\r
+ // returns the alignment position for a residue\r
+ int j = sequence.getStart();\r
+ int i = 0;\r
+\r
+ while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && (j <= pos+1))\r
+ {\r
+ if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))\r
+ {\r
+ j++;\r
+ }\r
+\r
+ i++;\r
+ }\r
+\r
+ if(i>1)\r
+ i--;\r
+\r
+ if ( (j == sequence.getEnd()) && (j < pos))\r
+ {\r
+ return sequence.getEnd() + 1;\r
+ }\r
+ else\r
+ {\r
+ return i;\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(PDBChain chain)\r
+ {\r
+ // System.out.println("colour by seq");\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
+\r
+ if(chain!=mainchain)\r
+ continue;\r
+\r
+ if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&\r
+ (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))\r
+ {\r
+ int index = findTrueIndex(tmp.at1.alignmentMapping);\r
+ //sequence.findIndex(tmp.at1.alignmentMapping);\r
+ if (index != -1)\r
+ {\r
+ tmp.startCol = seqcanvas.getSequenceRenderer().\r
+ getResidueBoxColour( sequence, index);\r
+ if(tmp.startCol==null)\r
+ tmp.startCol = Color.white;\r
+\r
+ tmp.startCol = seqcanvas.getFeatureRenderer().\r
+ findFeatureColour(tmp.startCol, sequence, index);\r
+ }\r
+ }\r
+\r
+ if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&\r
+ (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1)))\r
+ {\r
+\r
+ int index = findTrueIndex(tmp.at2.alignmentMapping);\r
+ //sequence.findIndex( tmp.at2.alignmentMapping );\r
+ if (index != -1)\r
+ {\r
+ tmp.endCol = seqcanvas.getSequenceRenderer().\r
+ getResidueBoxColour( sequence, index);\r
+ if(tmp.endCol==null)\r
+ tmp.endCol = Color.white;\r
+ tmp.endCol = seqcanvas.getFeatureRenderer().\r
+ findFeatureColour(tmp.endCol, sequence, index);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ public void drawScene(Graphics g)\r
+ {\r
+ if (zbuffer)\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
+ (getWidth() / 2));\r
+ ystart = (int) (((tmpBond.start[1] - centre[1]) * scale) +\r
+ (getHeight() / 2));\r
+\r
+ xend = (int) (((tmpBond.end[0] - centre[0]) * scale) +\r
+ (getWidth() / 2));\r
+ yend = (int) (((tmpBond.end[1] - centre[1]) * scale) +\r
+ (getHeight() / 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
+ g.setColor(tmpBond.startCol.darker().darker());\r
+ drawLine(g, xstart, ystart, xmid, ymid);\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
+ } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {\r
+ g.setColor(Color.green.darker());\r
+ drawLine(g, xstart, ystart, xend, yend);\r
+ } else {\r
+ g.setColor(Color.green);\r
+ drawLine(g, xstart, ystart, xend, yend);\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
+ } else {\r
+ drawLine(g, xstart, ystart, xend, yend);\r
+ }\r
+\r
+ if(highlightBond1!=null && highlightBond1==tmpBond)\r
+ {\r
+ g.setColor(tmpBond.endCol.brighter().brighter().brighter().brighter());\r
+ drawLine(g, xmid, ymid, xend, yend);\r
+ }\r
+\r
+ if(highlightBond2!=null && highlightBond2==tmpBond)\r
+ {\r
+ g.setColor(tmpBond.startCol.brighter().brighter().brighter().brighter());\r
+ drawLine(g, xstart, ystart, xmid, ymid);\r
+ }\r
+\r
+ }\r
+\r
+\r
+ }\r
+\r
+ public void drawLine(Graphics g, int x1, int y1, int x2, int y2) {\r
+ if (!wire) {\r
+ if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) {\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
+ } else {\r
+ g.drawLine(x1, y1, x2, y2);\r
+ }\r
+ }\r
+\r
+ public Dimension minimumsize() {\r
+ return prefsize;\r
+ }\r
+\r
+ public Dimension preferredsize() {\r
+ return prefsize;\r
+ }\r
+\r
+ public void keyPressed(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
+ highlightRes = new Vector();\r
+\r
+ if (highlightRes.contains(fatom.alignmentMapping+"" + ""))\r
+ highlightRes.remove(fatom.alignmentMapping + "");\r
+ else\r
+ highlightRes.add(fatom.alignmentMapping + "");\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
+ highlightSeqcanvas( fatom.alignmentMapping );\r
+ }\r
+ }\r
+\r
+ if (fatom != null)\r
+ {\r
+ this.setToolTipText(chain.id+":"+ fatom.resNumber+" "+ fatom.resName);\r
+ } else\r
+ {\r
+ highlightSeqcanvas( -1);\r
+ this.setToolTipText(null);\r
+ }\r
+ }\r
+\r
+\r
+ void highlightSeqcanvas(int pos)\r
+ {\r
+ int index = seqcanvas.getViewport().getAlignment().findIndex(sequence);\r
+\r
+ int size = pos==-1?0:3;\r
+\r
+ if(highlightRes!=null)\r
+ size += highlightRes.size()*3;\r
+\r
+ int [] array = new int[size];\r
+ int i=0;\r
+ if(highlightRes!=null)\r
+ {\r
+ for (i = 0; i < highlightRes.size(); i++)\r
+ {\r
+ int a = Integer.parseInt(highlightRes.elementAt(\r
+ i).toString())+1;\r
+ array[i * 3] = index;\r
+ array[ (i * 3) + 1] = a;\r
+ array[ (i * 3) + 2] = a;\r
+ }\r
+ }\r
+\r
+ if(pos!=-1)\r
+ {\r
+ array[i * 3] = index;\r
+ array[i * 3 + 1] = pos+1;\r
+ array[i * 3 + 2] = pos+1;\r
+ }\r
+\r
+ seqcanvas.highlightSearchResults(array);\r
+ }\r
+\r
+\r
+ public void mouseClicked(MouseEvent e) { }\r
+\r
+ public void mouseEntered(MouseEvent e) { }\r
+\r
+ public void mouseExited(MouseEvent e) { }\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
+\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
+ 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
+ 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
+ g.setFont(font);\r
+ g.setColor(Color.red);\r
+ if (n == 1)\r
+ {\r
+ int xstart = (int) (((b.start[0] - centre[0]) * scale) +\r
+ (getWidth() / 2));\r
+ int ystart = (int) (((b.start[1] - centre[1]) * scale) +\r
+ (getHeight() / 2));\r
+\r
+ g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);\r
+ }\r
+\r
+ if (n == 2) {\r
+ int xstart = (int) (((b.end[0] - centre[0]) * scale) +\r
+ (getWidth() / 2));\r
+ int ystart = (int) (((b.end[1] - centre[1]) * scale) +\r
+ (getHeight() / 2));\r
+\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
+ 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
+ (getWidth() / 2));\r
+\r
+ if (Math.abs(truex - x) <= 2)\r
+ {\r
+ int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +\r
+ (getHeight() / 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
+ (getWidth() / 2));\r
+\r
+ if (Math.abs(truex - x) <= 2)\r
+ {\r
+ int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +\r
+ (getHeight() / 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
+ Bond highlightBond1, highlightBond2;\r
+ public void highlightRes(int ii)\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
+ highlightBond1.at2.isSelected = false;\r
+\r
+ if (highlightBond2 != null)\r
+ highlightBond2.at1.isSelected = false;\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
import java.awt.*;\r
\r
import java.util.*;\r
+import jalview.analysis.AlignSeq;\r
\r
\r
public class PDBChain {\r
public Vector residues = new Vector();\r
public int offset;\r
public Sequence sequence;\r
- public boolean isVisible = false;\r
+ public boolean isVisible = true;\r
public int pdbstart = 0;\r
public int pdbend = 0;\r
public int seqstart = 0;\r
public int seqend = 0;\r
\r
- //public DrawableSequence ds;\r
public PDBChain(String id) {\r
this.id = id;\r
}\r
return tmp;\r
}\r
\r
- public void makeCaBondList() {\r
- for (int i = 0; i < (residues.size() - 1); i++) {\r
+ void makeExactMapping(AlignSeq as, Sequence s1)\r
+ {\r
+ int pdbpos = as.getSeq2Start()-2;\r
+ int alignpos = s1.getStart() + as.getSeq1Start()-3;\r
+\r
+ for(int i=0; i<as.astr1.length(); i++)\r
+ {\r
+ if (as.astr1.charAt(i) != '-')\r
+ {\r
+ alignpos++;\r
+ }\r
+\r
+ if (as.astr2.charAt(i) != '-')\r
+ {\r
+ pdbpos++;\r
+ }\r
+\r
+ if (as.astr1.charAt(i) == as.astr2.charAt(i))\r
+ {\r
+ Residue res = (Residue) residues.elementAt(pdbpos);\r
+ Enumeration en = res.atoms.elements();\r
+ while (en.hasMoreElements())\r
+ {\r
+ Atom atom = (Atom) en.nextElement();\r
+ atom.alignmentMapping = alignpos;\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+\r
+ public void makeCaBondList()\r
+ {\r
+ for (int i = 0; i < (residues.size() - 1); i++)\r
+ {\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
+ Atom at1 = tmpres.findAtom("CA");\r
+ Atom at2 = tmpres2.findAtom("CA");\r
\r
- if ((at1 != null) && (at2 != null)) {\r
- if (at1.chain.equals(at2.chain)) {\r
+ if ((at1 != null) && (at2 != null))\r
+ {\r
+ if (at1.chain.equals(at2.chain))\r
+ {\r
makeBond(at1, at2);\r
}\r
}\r
+ else\r
+ System.out.println("not found "+i);\r
}\r
}\r
\r
- public void makeBond(myAtom at1, myAtom at2) {\r
+ public void makeBond(Atom at1, Atom at2) {\r
float[] start = new float[3];\r
float[] end = new float[3];\r
\r
\r
public void makeResidueList() {\r
int count = 0;\r
- String seq = "";\r
+ StringBuffer seq = new StringBuffer();\r
\r
- for (int i = 0; i < atoms.size(); i++) {\r
- myAtom tmp = (myAtom) atoms.elementAt(i);\r
- //String resName = tmp.resName;\r
+ int i, iSize = atoms.size()-1;\r
+ for (i = 0; i < iSize; i++)\r
+ {\r
+ Atom tmp = (Atom) atoms.elementAt(i);\r
int resNumber = tmp.resNumber;\r
int res = resNumber;\r
\r
\r
Vector resAtoms = new Vector();\r
\r
- resAtoms.addElement((myAtom) atoms.elementAt(i));\r
+ resAtoms.addElement((Atom) atoms.elementAt(i));\r
i++;\r
- resNumber = ((myAtom) atoms.elementAt(i)).resNumber;\r
+ resNumber = ((Atom) 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
- resAtoms.addElement((myAtom) atoms.elementAt(i));\r
+ resAtoms.addElement((Atom) atoms.elementAt(i));\r
i++;\r
\r
if (i < atoms.size()) {\r
- resNumber = ((myAtom) atoms.elementAt(i)).resNumber;\r
+ resNumber = ((Atom) atoms.elementAt(i)).resNumber;\r
} else {\r
resNumber++;\r
}\r
count++;\r
\r
Residue tmpres = (Residue) residues.lastElement();\r
- myAtom tmpat = (myAtom) tmpres.atoms.elementAt(0);\r
+ Atom tmpat = (Atom) tmpres.atoms.elementAt(0);\r
\r
// Keep totting up the sequence\r
- if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null) {\r
- System.err.println("PDBReader:Null aa3Hash for " +\r
- tmpat.resName);\r
+ if (ResidueProperties.getAA3Hash().get(tmpat.resName) == null)\r
+ {\r
+ seq.append("X") ;\r
+ // System.err.println("PDBReader:Null aa3Hash for " +\r
+ // tmpat.resName);\r
} else {\r
- String tmpres2 = ResidueProperties.aa[((Integer) ResidueProperties.getAA3Hash()\r
- .get(tmpat.resName)).intValue()];\r
- seq = seq + tmpres2;\r
- }\r
\r
- // System.out.println(tmpat.resName + " " + tmpres2);\r
+ seq.append(ResidueProperties.aa[((Integer) ResidueProperties.getAA3Hash()\r
+ .get(tmpat.resName)).intValue()]);\r
+ }\r
}\r
\r
- sequence = new Sequence("PDB_seq", seq, 1, seq.length());\r
- System.out.println("PDB Sequence is :\nSequence = " + seq);\r
- System.out.println("No of residues = " + residues.size());\r
+ if(id.length()<1 || id.equals(" "))\r
+ id = "_";\r
+\r
+ sequence = new Sequence(id, seq.toString(), 1, seq.length());\r
+ // System.out.println("PDB Sequence is :\nSequence = " + seq);\r
+ // System.out.println("No of residues = " + residues.size());\r
}\r
\r
public void setChargeColours() {\r
}\r
}\r
\r
- public void colourBySequence(jalview.gui.AlignViewport av, Sequence seq) {\r
- jalview.gui.SequenceRenderer sr = new jalview.gui.SequenceRenderer(av);\r
-\r
- for (int i = 0; i < bonds.size(); i++) {\r
- Bond tmp = (Bond) bonds.elementAt(i);\r
-\r
- try {\r
- if ((tmp.at1.resNumber >= ((offset + pdbstart) - 1)) &&\r
- (tmp.at1.resNumber <= ((offset + pdbend) - 1))) {\r
- int pos = seqstart +\r
- (tmp.at1.resNumber - pdbstart - offset);\r
- int index = seq.findIndex(pos);\r
-\r
- tmp.startCol = sr.getResidueBoxColour(av.getGlobalColourScheme(),\r
- seq, index);\r
- } else {\r
- tmp.startCol = Color.gray;\r
- }\r
\r
- if ((tmp.at2.resNumber >= ((offset + pdbstart) - 1)) &&\r
- (tmp.at2.resNumber <= ((pdbend + offset) - 1))) {\r
- int pos = seqstart +\r
- (tmp.at2.resNumber - pdbstart - offset);\r
- int index = seq.findIndex(pos);\r
\r
- tmp.endCol = sr.getResidueBoxColour(av.getGlobalColourScheme(),\r
- seq, index);\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
+ public void setChainColours(Color col)\r
+ {\r
+ for (int i = 0; i < bonds.size(); i++)\r
+ {\r
Bond tmp = (Bond) bonds.elementAt(i);\r
-\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
+ tmp.startCol = col;\r
+ tmp.endCol = col;\r
}\r
}\r
}\r
--- /dev/null
+package MCview;\r
+\r
+import javax.swing.*;\r
+import java.awt.event.*;\r
+import jalview.datamodel.*;\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
+\r
+ pdb = entry;\r
+ sequence = seq;\r
+\r
+ Thread worker = new Thread(this);\r
+ worker.start();\r
+\r
+ try\r
+ {\r
+ jbInit();\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\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
+ }\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
+ hydro.setText("Hydrophobicity");\r
+ hydro.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ hydro_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
+ molecule.setText("By Molecule");\r
+ molecule.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ molecule_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
+ jMenuBar1.add(fileMenu);\r
+ jMenuBar1.add(coloursMenu);\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(hydro);\r
+ coloursMenu.add(charge);\r
+ coloursMenu.addSeparator();\r
+ coloursMenu.add(wire);\r
+ coloursMenu.add(depth);\r
+ coloursMenu.add(zbuffer);\r
+ coloursMenu.add(molecule);\r
+ coloursMenu.add(allchains);\r
+ ButtonGroup bg = new ButtonGroup();\r
+ bg.add(seqButton);\r
+ bg.add(chain);\r
+ bg.add(hydro);\r
+ bg.add(charge);\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
+ JRadioButtonMenuItem charge = new JRadioButtonMenuItem();\r
+ JRadioButtonMenuItem hydro = new JRadioButtonMenuItem();\r
+ JRadioButtonMenuItem chain = new JRadioButtonMenuItem();\r
+ JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem();\r
+ JCheckBoxMenuItem molecule = new JCheckBoxMenuItem();\r
+ JCheckBoxMenuItem allchains = new JCheckBoxMenuItem();\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
+ clearButtonGroup();\r
+ pdbcanvas.pdb.setChargeColours();\r
+ pdbcanvas.redrawneeded=true;\r
+ pdbcanvas.repaint();\r
+ }\r
+\r
+ public void hydro_actionPerformed(ActionEvent e)\r
+ {\r
+ clearButtonGroup();\r
+ pdbcanvas.pdb.setHydrophobicityColours();\r
+ pdbcanvas.redrawneeded=true;\r
+ pdbcanvas.repaint();\r
+ }\r
+\r
+ public void chain_actionPerformed(ActionEvent e)\r
+ {\r
+ clearButtonGroup();\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
+ clearButtonGroup();\r
+ pdbcanvas.bysequence = seqButton.isSelected();\r
+ pdbcanvas.updateSeqColours();\r
+ }\r
+\r
+ void clearButtonGroup()\r
+ {\r
+ pdbcanvas.bysequence = false;\r
+ pdbcanvas.bymolecule = false;\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
*/\r
package MCview;\r
\r
-import jalview.datamodel.*;\r
-\r
import java.io.*;\r
\r
import java.net.*;\r
\r
import java.util.*;\r
+import java.awt.Color;\r
\r
\r
public class PDBfile extends jalview.io.FileParse {\r
public Vector chains = new Vector();\r
Vector lineArray = new Vector();\r
+ String id;\r
\r
public PDBfile(String[] lines) {\r
for (int i = 0; i < lines.length; i++)\r
if (inType.equals("File")) {\r
dataIn = new BufferedReader(new FileReader(inFile));\r
}\r
+ else if(inType.equals("Paste"))\r
+ {\r
+ dataIn = new BufferedReader(new StringReader(inFile));\r
+ }\r
else {\r
URL url = new URL(inFile);\r
this.fileSize = 0;\r
noLines = lineArray.size();\r
\r
parse();\r
+ lineArray = null;\r
}\r
\r
- public void parse() {\r
- for (int i = 0; i < lineArray.size(); i++) {\r
- StringTokenizer str = new StringTokenizer(lineArray.elementAt(i)\r
- .toString());\r
-\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
-\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.err.println("Caught" + e);\r
- System.err.println("Record not added to PDB model:" +\r
- lineArray.elementAt(i).toString());\r
- }\r
- }\r
- }\r
- }\r
+ public void parse()\r
+ {\r
+ PDBChain tmpchain;\r
+ String line;\r
+ boolean modelFlag = false;\r
+ boolean terFlag = false;\r
+\r
+\r
+ for (int i = 0; i < lineArray.size(); i++)\r
+ {\r
+\r
+ line = lineArray.elementAt(i).toString();\r
+\r
+\r
+ if (line.indexOf("HEADER") == 0)\r
+ {\r
+ id = line.substring(62, 67).trim();\r
+ continue;\r
+ }\r
+\r
+ if(line.indexOf("MODEL")==0)\r
+ modelFlag = true;\r
\r
- makeResidueList();\r
- makeCaBondList();\r
+ if(line.indexOf("TER")==0)\r
+ terFlag = true;\r
\r
- // for (int i=0; i < chains.size() ; i++) {\r
- // String pog = ((PDBChain)chains.elementAt(i)).print();\r
- // System.out.println(pog);\r
- // }\r
+ if(modelFlag && line.indexOf("ENDMDL")==0)\r
+ break;\r
+\r
+ if ( line.indexOf("ATOM")==0\r
+ || (line.indexOf("HETATM")==0 && !terFlag)\r
+ )\r
+ {\r
+ terFlag = false;\r
+\r
+\r
+ //Jalview is only interested in CA bonds????\r
+ if (!line.substring(12, 15).trim().equals("CA"))\r
+ {\r
+ continue;\r
+ }\r
+\r
+ Atom tmpatom = new Atom(line);\r
+\r
+ tmpchain = findChain(tmpatom.chain);\r
+ if (tmpchain != null)\r
+ {\r
+ tmpchain.atoms.addElement(tmpatom);\r
+ }\r
+ else\r
+ {\r
+ tmpchain = new PDBChain(tmpatom.chain);\r
+ chains.addElement(tmpchain);\r
+ tmpchain.atoms.addElement(tmpatom);\r
+ }\r
+\r
+ }\r
+ }\r
+\r
+ makeResidueList();\r
+ makeCaBondList();\r
}\r
\r
public void makeResidueList() {\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
}\r
\r
- public void colourBySequence(Sequence 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
+ public void setChainColours()\r
+ {\r
+ for (int i = 0; i < chains.size(); i++)\r
+ {\r
+ ((PDBChain) chains.elementAt(i)).setChainColours(\r
+ Color.getHSBColor(1.0f / (float)i, .4f, 1.0f)\r
+ );\r
}\r
}\r
}\r
this.count = count;\r
}\r
\r
- public myAtom findAtom(String name) {\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
+ public Atom findAtom(String name)\r
+ {\r
+ for (int i = 0; i < atoms.size(); i++)\r
+ {\r
+ if (((Atom) atoms.elementAt(i)).name.equals(name))\r
+ {\r
+ return (Atom) atoms.elementAt(i);\r
}\r
}\r
\r
+++ /dev/null
-/*\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 java.awt.*;\r
-\r
-import java.util.*;\r
-\r
-\r
-public class myAtom {\r
- float x;\r
- float y;\r
- float z;\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
- 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
- } catch (NumberFormatException e) {\r
- this.chain = tmpstr;\r
-\r
- if (tmpstr.equals("A")) {\r
- this.color = Color.lightGray;\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
+++ /dev/null
-/*\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 jalview.analysis.AlignSeq;\r
-\r
-import jalview.datamodel.*;\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 java.io.*;\r
-\r
-import java.util.*;\r
-\r
-import javax.swing.*;\r
-\r
-\r
-public class rotCanvas extends JPanel implements KeyListener, MouseListener,\r
- MouseMotionListener {\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
- 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 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
-\r
- public rotCanvas(PDBfile pdb, Sequence sequence,\r
- jalview.gui.AlignViewport av) throws IOException {\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
-\r
- for (int i = 0; i < pdb.chains.size(); i++) {\r
- // Now lets compare the sequences to get\r
- // the start and end points.\r
- java.util.StringTokenizer str = new java.util.StringTokenizer(sequence.getSequence(),\r
- ".");\r
- String newString = "";\r
-\r
- while (str.hasMoreTokens()) {\r
- newString += str.nextToken();\r
- }\r
-\r
- // Align the sequence to the pdb\r
- AlignSeq as = new AlignSeq(sequence,\r
- ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep");\r
- as.calcScoreMatrix();\r
- as.traceAlignment();\r
- as.printAlignment();\r
-\r
- if (as.maxscore > max) {\r
- max = as.maxscore;\r
- maxchain = i;\r
-\r
- pdbstart = as.seq2start;\r
- pdbend = as.seq2end;\r
- seqstart = as.seq1start - 1;\r
- seqend = as.seq1end - 1;\r
- }\r
-\r
- System.out.println("PDB start/end " + pdbstart + " " + pdbend);\r
- System.out.println("SEQ start/end " + seqstart + " " + seqend);\r
- }\r
-\r
- ((PDBChain) pdb.chains.elementAt(maxchain)).pdbstart = pdbstart;\r
- ((PDBChain) pdb.chains.elementAt(maxchain)).pdbend = pdbend;\r
- ((PDBChain) pdb.chains.elementAt(maxchain)).seqstart = seqstart;\r
- ((PDBChain) pdb.chains.elementAt(maxchain)).seqend = seqend;\r
- ((PDBChain) pdb.chains.elementAt(maxchain)).isVisible = true;\r
- ((PDBChain) pdb.chains.elementAt(maxchain)).sequence = sequence;\r
- ((PDBChain) pdb.chains.elementAt(maxchain)).colourBySequence(av,\r
- sequence);\r
-\r
- this.pdb = pdb;\r
- this.prefsize = new Dimension(getWidth(), getHeight());\r
-\r
- //Initialize the matrices to identity\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
- ToolTipManager.sharedInstance().setInitialDelay(0);\r
- ToolTipManager.sharedInstance().setDismissDelay(10000);\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
- 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
- }\r
-\r
- if (tmp.start[1] >= max[1]) {\r
- max[1] = tmp.start[1];\r
- }\r
-\r
- if (tmp.start[2] >= max[2]) {\r
- max[2] = tmp.start[2];\r
- }\r
-\r
- if (tmp.start[0] <= min[0]) {\r
- min[0] = tmp.start[0];\r
- }\r
-\r
- if (tmp.start[1] <= min[1]) {\r
- min[1] = tmp.start[1];\r
- }\r
-\r
- if (tmp.start[2] <= min[2]) {\r
- min[2] = tmp.start[2];\r
- }\r
-\r
- if (tmp.end[0] >= max[0]) {\r
- max[0] = tmp.end[0];\r
- }\r
-\r
- if (tmp.end[1] >= max[1]) {\r
- max[1] = tmp.end[1];\r
- }\r
-\r
- if (tmp.end[2] >= max[2]) {\r
- max[2] = tmp.end[2];\r
- }\r
-\r
- if (tmp.end[0] <= min[0]) {\r
- min[0] = tmp.end[0];\r
- }\r
-\r
- if (tmp.end[1] <= min[1]) {\r
- min[1] = tmp.end[1];\r
- }\r
-\r
- if (tmp.end[2] <= min[2]) {\r
- min[2] = tmp.end[2];\r
- }\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
- }\r
-\r
- if (width[2] > width[1]) {\r
- maxwidth = width[2];\r
- }\r
-\r
- System.out.println("Maxwidth = " + maxwidth);\r
- }\r
-\r
- public float findScale() {\r
- int dim;\r
- int width;\r
- int height;\r
-\r
- if (getWidth() != 0) {\r
- width = getWidth();\r
- height = getHeight();\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
- public void findCentre() {\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
- if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {\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
- 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
- //Only create the image at the beginning -\r
- //this saves much memory usage\r
- if ((img == null) || (prefsize.width != getWidth()) ||\r
- (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
- public void drawScene(Graphics g) {\r
- // Sort the bonds by z coord\r
- Vector bonds = new Vector();\r
-\r
- for (int ii = 0; ii < pdb.chains.size(); ii++) {\r
- if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {\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) +\r
- (getWidth() / 2));\r
- ystart = (int) (((tmpBond.start[1] - centre[1]) * scale) +\r
- (getHeight() / 2));\r
-\r
- xend = (int) (((tmpBond.end[0] - centre[0]) * scale) +\r
- (getWidth() / 2));\r
- yend = (int) (((tmpBond.end[1] - centre[1]) * scale) +\r
- (getHeight() / 2));\r
-\r
- xmid = (xend + xstart) / 2;\r
- ymid = (yend + ystart) / 2;\r
-\r
- if (depthcue && !bymolecule) {\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
- } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {\r
- g.setColor(Color.green.darker());\r
- drawLine(g, xstart, ystart, xend, yend);\r
- } else {\r
- g.setColor(Color.green);\r
- drawLine(g, xstart, ystart, xend, yend);\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
- } 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
- if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) {\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
- } else {\r
- g.drawLine(x1, y1, x2, y2);\r
- }\r
- }\r
-\r
- public Dimension minimumsize() {\r
- return prefsize;\r
- }\r
-\r
- public Dimension preferredsize() {\r
- return prefsize;\r
- }\r
-\r
- public void keyTyped(KeyEvent evt) {\r
- }\r
-\r
- public void keyReleased(KeyEvent evt) {\r
- }\r
-\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
- } else if (evt.getKeyCode() == KeyEvent.VK_DOWN) {\r
- scale = (float) (scale * 0.9);\r
- redrawneeded = true;\r
- repaint();\r
- } else if (key == 'w') {\r
- wire = !wire;\r
- System.out.println("wireframe " + wire);\r
- redrawneeded = true;\r
- repaint();\r
- } else if (key == 'd') {\r
- depthcue = !depthcue;\r
- System.out.println("Depth cueing is " + depthcue);\r
- redrawneeded = true;\r
- repaint();\r
- } else if (key == 'm') {\r
- bymolecule = !bymolecule;\r
- System.out.println("Bymolecule is " + bymolecule);\r
- redrawneeded = true;\r
- repaint();\r
- } else if (key == 'z') {\r
- zbuffer = !zbuffer;\r
- System.out.println("Z buffering is " + zbuffer);\r
- redrawneeded = true;\r
- repaint();\r
- } else if (key == 'c') {\r
- bymolecule = false;\r
- pdb.setChainColours();\r
- System.out.println("Colouring by chain");\r
- redrawneeded = true;\r
- repaint();\r
- } else if (key == 'h') {\r
- bymolecule = false;\r
- pdb.setHydrophobicityColours();\r
- System.out.println("Colouring by hydrophobicity");\r
- redrawneeded = true;\r
- repaint();\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
- 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
- myAtom fatom = null;\r
-\r
- for (int ii = 0; ii < pdb.chains.size(); ii++) {\r
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
-\r
- if (chain.isVisible) {\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
- int truex = (int) (((tmpBond.start[0] - centre[0]) * scale) +\r
- (getWidth() / 2));\r
-\r
- if (Math.abs(truex - e.getX()) <= 2) {\r
- int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +\r
- (getHeight() / 2));\r
-\r
- if (Math.abs(truey - e.getY()) <= 2) {\r
- fatom = tmpBond.at1;\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- if (fatom != null) {\r
- this.setToolTipText(fatom.resName);\r
- } else {\r
- this.setToolTipText(null);\r
- }\r
- }\r
-\r
- public void mouseClicked(MouseEvent e) {\r
- }\r
-\r
- public void mouseEntered(MouseEvent e) {\r
- }\r
-\r
- public void mouseExited(MouseEvent e) {\r
- }\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
- 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
-\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
-\r
- drawLabels();\r
-\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
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
-\r
- if (chain.isVisible) {\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
- this.getGraphics().drawImage(img, 0, 0, this);\r
-\r
- dragging = false;\r
- }\r
-\r
- public void labelAtom(Graphics g, Bond b, int n) {\r
- g.setFont(font);\r
-\r
- if (n == 1) {\r
- int xstart = (int) (((b.start[0] - centre[0]) * scale) +\r
- (getWidth() / 2));\r
- int ystart = (int) (((b.start[1] - centre[1]) * scale) +\r
- (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
- int xstart = (int) (((b.end[0] - centre[0]) * scale) +\r
- (getWidth() / 2));\r
- int ystart = (int) (((b.end[1] - centre[1]) * scale) +\r
- (getHeight() / 2));\r
-\r
- g.setColor(Color.red);\r
- g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);\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
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
-\r
- if (chain.isVisible) {\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) +\r
- (getWidth() / 2));\r
-\r
- if (Math.abs(truex - x) <= 2) {\r
- int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +\r
- (getHeight() / 2));\r
-\r
- if (Math.abs(truey - y) <= 2) {\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] + " " +\r
- tmpBond.start[1]);\r
- System.out.println("Atom 1 = " +\r
- tmpBond.at1.resName + " " +\r
- tmpBond.at1.resNumber + " " +\r
- 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
-\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