--- /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
+ 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.SequenceRenderer sr;\r
+ jalview.appletgui.FeatureRenderer fr;\r
+ jalview.appletgui.SeqCanvas seqcanvas;\r
+ Sequence sequence;\r
+ final StringBuffer mappingDetails = new StringBuffer();\r
+ String appletToolTip = null;\r
+ int toolx, tooly;\r
+\r
+ public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq)\r
+ {\r
+ this.seqcanvas = seqcanvas;\r
+ this.sequence = seq;\r
+ sr = seqcanvas.getSequenceRenderer();\r
+ fr = seqcanvas.getFeatureRenderer();\r
+\r
+ seqcanvas.setPDBViewer(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
+ this.sr = sr;\r
+ this.fr = fr;\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
+ {\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
+ }\r
+\r
+ mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);\r
+ mappingDetails.append("\nSEQ 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
+\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
+ SequenceGroup sg = new SequenceGroup("PDB",\r
+ null, true,true,false,\r
+ sequence.findIndex(seqstart-1),\r
+ sequence.findIndex(seqend-1));\r
+ sg.addSequence(sequence, false);\r
+ sg.setOutlineColour(Color.black);\r
+ seqcanvas.getViewport().getAlignment().addGroup(sg);\r
+ */\r
+\r
+ findCentre();\r
+ findWidth();\r
+\r
+ scale = findScale();\r
+\r
+ updateSeqColours();\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
+ 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(pdb==null)\r
+ {\r
+ g.setColor(Color.black);\r
+ g.setFont(new Font("Verdana", Font.BOLD, 14));\r
+ g.drawString("Error Parsing Pasted PDB data!!", 50, getSize().height/2);\r
+ return;\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
+ prefsize.width = getSize().width;\r
+ prefsize.height = getSize().height;\r
+\r
+ scale = findScale();\r
+ img = createImage(prefsize.width, prefsize.height);\r
+ ig = img.getGraphics();\r
+\r
+ redrawneeded = true;\r
+ }\r
+\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
+\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(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
+ // 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
+\r
+ if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&\r
+ (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))\r
+ {\r
+ int pos = chain.seqstart +\r
+ (tmp.at1.resNumber - chain.pdbstart - chain.offset);\r
+\r
+ int index = sequence.findIndex(pos);\r
+\r
+ tmp.startCol = sr.findSequenceColour(sequence, index);\r
+\r
+ // tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);\r
+\r
+ }\r
+ else\r
+ {\r
+ tmp.startCol = Color.gray;\r
+ }\r
+\r
+ if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&\r
+ (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1)))\r
+ {\r
+ int pos = chain.seqstart +\r
+ (tmp.at2.resNumber - chain.pdbstart - chain.offset);\r
+ int index = sequence.findIndex(pos);\r
+\r
+ tmp.endCol = sr.findSequenceColour( sequence, index);\r
+ // tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);\r
+ }\r
+ else\r
+ {\r
+ tmp.endCol = Color.gray;\r
+ }\r
+ }\r
+ }\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
+ {\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
+ 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
+ (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
+ 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 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
+ myAtom fatom = findAtom(e.getX(), e.getY());\r
+ if(fatom!=null)\r
+ {\r
+ fatom.isSelected = !fatom.isSelected;\r
+ redrawneeded = true;\r
+ repaint();\r
+ }\r
+ mx = e.getX();\r
+ my = e.getY();\r
+ omx = mx;\r
+ omy = my;\r
+ dragging = false;\r
+ }\r
+\r
+ public void mouseMoved(MouseEvent e) {\r
+\r
+ myAtom fatom = findAtom(e.getX(), e.getY());\r
+\r
+ if(foundchain!=-1)\r
+ {\r
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
+ int pos = chain.seqstart +\r
+ (fatom.resNumber - chain.pdbstart - chain.offset)+1;\r
+\r
+ int index = seqcanvas.getViewport().getAlignment().findIndex(sequence);\r
+\r
+ seqcanvas.highlightSearchResults(new int[]{index, pos, pos});\r
+ }\r
+ else\r
+ seqcanvas.highlightSearchResults(null);\r
+\r
+ if (fatom != null) {\r
+ toolx = e.getX();\r
+ tooly = e.getY();\r
+ appletToolTip = fatom.resNumber+" "+ fatom.resName;\r
+ redrawneeded = true;\r
+ repaint();\r
+ } else {\r
+ appletToolTip = null;\r
+ redrawneeded = true;\r
+ repaint();\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 myAtom findAtom(int x, int y) {\r
+ myAtom fatom = null;\r
+\r
+ 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
+ (getSize().width / 2));\r
+\r
+ if (Math.abs(truex - x) <= 2) {\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
+\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
--- /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,\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, "Paste");\r
+ pdbcanvas.setPDBFile(pdbfile);\r
+ }catch(Exception ex){ex.printStackTrace();}\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.addItemListener(new ItemListener()\r
+ {\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ charge_actionPerformed();\r
+ }\r
+ });\r
+ hydro.setLabel("Hydrophobicity");\r
+ hydro.addItemListener(new ItemListener()\r
+ {\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ hydro_actionPerformed();\r
+ }\r
+ });\r
+ chain.setLabel("By Chain");\r
+ chain.addItemListener(new ItemListener()\r
+ {\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ chain_actionPerformed();\r
+ }\r
+ });\r
+ seqButton.setState(true);\r
+ seqButton.setLabel("By Sequence");\r
+ seqButton.addItemListener(new ItemListener()\r
+ {\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ seqButton_actionPerformed();\r
+ }\r
+ });\r
+ molecule.setLabel("By Molecule");\r
+ molecule.addItemListener(new ItemListener()\r
+ {\r
+ public void itemStateChanged(ItemEvent e)\r
+ {\r
+ molecule_actionPerformed();\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(molecule);\r
+\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
+ CheckboxMenuItem charge = new CheckboxMenuItem();\r
+\r
+\r
+ CheckboxMenuItem hydro = new CheckboxMenuItem();\r
+ CheckboxMenuItem chain = new CheckboxMenuItem();\r
+ CheckboxMenuItem seqButton = new CheckboxMenuItem();\r
+ CheckboxMenuItem molecule = 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 molecule_actionPerformed()\r
+ {\r
+ pdbcanvas.bymolecule = ! pdbcanvas.bymolecule;\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 = seqButton.getState();\r
+ pdbcanvas.updateSeqColours();\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