X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FPDBCanvas.java;h=dc0f718232f60d84697d3818a62daf3357cedbe8;hb=47168f025aefdaa044802bd5f8f510ffe43a4808;hp=d38aa2ab3f5064f6f9866319f22fdc2d6a51fac4;hpb=5e1c62d9da464c55d118d4d1155545017bf6feb5;p=jalview.git diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java old mode 100755 new mode 100644 index d38aa2a..dc0f718 --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -1,20 +1,22 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) + * Copyright (C) 2014 The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package MCview; @@ -28,83 +30,154 @@ import javax.swing.*; import jalview.analysis.*; import jalview.datamodel.*; +import jalview.gui.*; +import jalview.structure.*; -public class PDBCanvas - extends JPanel implements MouseListener, MouseMotionListener +public class PDBCanvas extends JPanel implements MouseListener, + MouseMotionListener, StructureListener { - MCMatrix idmat = new MCMatrix(3, 3); - MCMatrix objmat = new MCMatrix(3, 3); boolean redrawneeded = true; + int omx = 0; + int mx = 0; + int omy = 0; + int my = 0; + public PDBfile pdb; + + PDBEntry pdbentry; + int bsize; + Image img; + Graphics ig; + Dimension prefsize; + float[] centre = new float[3]; + float[] width = new float[3]; + float maxwidth; + float scale; + String inStr; + String inType; + boolean bysequence = true; + boolean depthcue = true; + boolean wire = false; + boolean bymolecule = false; + boolean zbuffer = true; + boolean dragging; + int xstart; + int xend; + int ystart; + int yend; + int xmid; + int ymid; + Font font = new Font("Helvetica", Font.PLAIN, 10); + jalview.gui.SeqCanvas seqcanvas; - public Sequence sequence; + + public SequenceI[] sequence; + final StringBuffer mappingDetails = new StringBuffer(); + PDBChain mainchain; + Vector highlightRes; + boolean pdbAction = false; + boolean seqColoursReady = false; + jalview.gui.FeatureRenderer fr; + Color backgroundColour = Color.black; - public PDBCanvas(jalview.gui.SeqCanvas seqcanvas, Sequence seq) + AlignmentPanel ap; + + StructureSelectionManager ssm; + + String errorMessage; + + void init(PDBEntry pdbentry, SequenceI[] seq, String[] chains, + AlignmentPanel ap, String protocol) { - this.seqcanvas = seqcanvas; + this.ap = ap; + this.pdbentry = pdbentry; this.sequence = seq; - } - public void setPDBFile(PDBfile pdb) - { + ssm = ap.av.getStructureSelectionManager(); + + try + { + pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol); + + if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) + pdbentry.setFile("INLINE" + pdb.id); + + } catch (Exception ex) + { + ex.printStackTrace(); + return; + } + + if (pdb == null) + { + errorMessage = "Error loading file: " + pdbentry.getId(); + return; + } + pdbentry.setId(pdb.id); + + ssm.addStructureViewerListener(this); + + colourBySequence(); + int max = -10; int maxchain = -1; int pdbstart = 0; int pdbend = 0; int seqstart = 0; int seqend = 0; - AlignSeq maxAlignseq = null; + + // JUST DEAL WITH ONE SEQUENCE FOR NOW + SequenceI sequence = seq[0]; for (int i = 0; i < pdb.chains.size(); i++) { - mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + - ( (PDBChain) pdb.chains.elementAt(i)).sequence. - getSequenceAsString()); - mappingDetails.append("\nNo of residues = " + - ( (PDBChain) pdb.chains.elementAt(i)).residues.size() + - "\n\n"); + mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + + ((PDBChain) pdb.chains.elementAt(i)).sequence + .getSequenceAsString()); + mappingDetails.append("\nNo of residues = " + + ((PDBChain) pdb.chains.elementAt(i)).residues.size() + + "\n\n"); // Now lets compare the sequences to get // the start and end points. // Align the sequence to the pdb AlignSeq as = new AlignSeq(sequence, - ( (PDBChain) pdb.chains.elementAt(i)).sequence, - AlignSeq.PEP); + ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep"); as.calcScoreMatrix(); as.traceAlignment(); PrintStream ps = new PrintStream(System.out) @@ -126,11 +199,11 @@ public class PDBCanvas { max = as.maxscore; maxchain = i; + pdbstart = as.seq2start; pdbend = as.seq2end; seqstart = as.seq1start + sequence.getStart() - 1; seqend = as.seq1end + sequence.getEnd() - 1; - maxAlignseq = as; } mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend); @@ -144,50 +217,18 @@ public class PDBCanvas mainchain.seqstart = seqstart; mainchain.seqend = seqend; mainchain.isVisible = true; - mainchain.makeExactMapping(maxAlignseq, sequence); - mainchain.transferRESNUMFeatures(sequence, null); - seqcanvas.getFeatureRenderer().featuresAdded(); - this.pdb = pdb; - this.prefsize = new Dimension(getWidth(), getHeight()); - //Initialize the matrices to identity - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - if (i != j) - { - idmat.addElement(i, j, 0); - objmat.addElement(i, j, 0); - } - else - { - idmat.addElement(i, j, 1); - objmat.addElement(i, j, 1); - } - } - } + this.pdb = pdb; + this.prefsize = new Dimension(getSize().width, getSize().height); addMouseMotionListener(this); addMouseListener(this); - addMouseWheelListener(new MouseWheelListener() + addKeyListener(new KeyAdapter() { - public void mouseWheelMoved(MouseWheelEvent e) + public void keyPressed(KeyEvent evt) { - if (e.getWheelRotation() > 0) - { - scale = (float) (scale * 1.1); - redrawneeded = true; - repaint(); - } - - else - { - scale = (float) (scale * 0.9); - redrawneeded = true; - repaint(); - } + keyPressed(evt); } }); @@ -204,6 +245,7 @@ public class PDBCanvas } Vector visiblebonds; + void setupBonds() { seqColoursReady = false; @@ -212,9 +254,9 @@ public class PDBCanvas for (int ii = 0; ii < pdb.chains.size(); ii++) { - if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) { - Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; + Vector tmp = ((PDBChain) pdb.chains.elementAt(ii)).bonds; for (int i = 0; i < tmp.size(); i++) { @@ -234,9 +276,9 @@ public class PDBCanvas float[] max = new float[3]; float[] min = new float[3]; - max[0] = (float) - 1e30; - max[1] = (float) - 1e30; - max[2] = (float) - 1e30; + max[0] = (float) -1e30; + max[1] = (float) -1e30; + max[2] = (float) -1e30; min[0] = (float) 1e30; min[1] = (float) 1e30; @@ -244,9 +286,9 @@ public class PDBCanvas for (int ii = 0; ii < pdb.chains.size(); ii++) { - if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) { - Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; + Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; for (int i = 0; i < bonds.size(); i++) { @@ -315,9 +357,10 @@ public class PDBCanvas } } /* - System.out.println("xmax " + max[0] + " min " + min[0]); - System.out.println("ymax " + max[1] + " min " + min[1]); - System.out.println("zmax " + max[2] + " min " + min[2]);*/ + * System.out.println("xmax " + max[0] + " min " + min[0]); + * System.out.println("ymax " + max[1] + " min " + min[1]); + * System.out.println("zmax " + max[2] + " min " + min[2]); + */ width[0] = (float) Math.abs(max[0] - min[0]); width[1] = (float) Math.abs(max[1] - min[1]); @@ -375,25 +418,25 @@ public class PDBCanvas int bsize = 0; - //Find centre coordinate + // Find centre coordinate for (int ii = 0; ii < pdb.chains.size(); ii++) { - if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) { - Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; + Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; bsize += bonds.size(); for (int i = 0; i < bonds.size(); i++) { - xtot = xtot + ( (Bond) bonds.elementAt(i)).start[0] + - ( (Bond) bonds.elementAt(i)).end[0]; + xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] + + ((Bond) bonds.elementAt(i)).end[0]; - ytot = ytot + ( (Bond) bonds.elementAt(i)).start[1] + - ( (Bond) bonds.elementAt(i)).end[1]; + ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] + + ((Bond) bonds.elementAt(i)).end[1]; - ztot = ztot + ( (Bond) bonds.elementAt(i)).start[2] + - ( (Bond) bonds.elementAt(i)).end[2]; + ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] + + ((Bond) bonds.elementAt(i)).end[2]; } } } @@ -407,19 +450,19 @@ public class PDBCanvas { super.paintComponent(g); - if (!seqColoursReady) + if (!seqColoursReady || errorMessage != null) { g.setColor(Color.black); g.setFont(new Font("Verdana", Font.BOLD, 14)); - g.drawString("Retrieving PDB data....", 20, getHeight() / 2); + g.drawString(errorMessage == null ? "Retrieving PDB data...." + : errorMessage, 20, getHeight() / 2); return; } - //Only create the image at the beginning - - //this saves much memory usage - if ( (img == null) - || (prefsize.width != getWidth()) - || (prefsize.height != getHeight())) + // Only create the image at the beginning - + // this saves much memory usage + if ((img == null) || (prefsize.width != getWidth()) + || (prefsize.height != getHeight())) { prefsize.width = getWidth(); @@ -431,7 +474,7 @@ public class PDBCanvas Graphics2D ig2 = (Graphics2D) ig; ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + RenderingHints.VALUE_ANTIALIAS_ON); redrawneeded = true; } @@ -462,118 +505,81 @@ public class PDBCanvas return; } - // System.out.println("update seq colours"); - if (bysequence && pdb != null) - { - for (int ii = 0; ii < pdb.chains.size(); ii++) - { - colourBySequence( (PDBChain) pdb.chains.elementAt(ii)); - } - } + colourBySequence(); redrawneeded = true; repaint(); } - int findTrueIndex(int pos) - { - // returns the alignment position for a residue - int j = sequence.getStart(); // first position in PDB atom coordinate sequence - int i = 0; - - while ( (i < sequence.getLength()) && (j <= pos + 1)) - { - if (!jalview.util.Comparison.isGap(sequence.getCharAt(i))) - { - j++; - } - - i++; - } - - if (i > 1) - { - i--; - } - - if (j < pos) - { - return sequence.getEnd() + 1; - } - else - { - return i; - } - } - // This method has been taken out of PDBChain to allow // Applet and Application specific sequence renderers to be used - void colourBySequence(PDBChain chain) + void colourBySequence() { - // System.out.println("colour by seq"); + SequenceRenderer sr = new SequenceRenderer(ap.av); + + StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile()); + boolean showFeatures = false; - if (seqcanvas.getViewport().getShowSequenceFeatures()) + if (ap.av.getShowSequenceFeatures()) { - showFeatures = true; if (fr == null) { - fr = new jalview.gui.FeatureRenderer(seqcanvas.getViewport()); + fr = new FeatureRenderer(ap); } - fr.transferSettings(seqcanvas.getFeatureRenderer()); + fr.transferSettings(ap.alignFrame.getFeatureRenderer()); + + showFeatures = true; } - Bond tmp; - for (int i = 0; i < chain.bonds.size(); i++) + PDBChain chain; + if (bysequence && pdb != null) { - tmp = (Bond) chain.bonds.elementAt(i); - - if (chain != mainchain) - { - continue; - } - - //if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) && - // (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1))) - { - int index = findTrueIndex(tmp.at1.alignmentMapping); - //sequence.findIndex(tmp.at1.alignmentMapping); - if (index != -1) - { - tmp.startCol = seqcanvas.getSequenceRenderer(). - getResidueBoxColour(sequence, index); - - if (showFeatures) - { - tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index); - } - - if (tmp.startCol == null) - { - tmp.startCol = Color.white; - } - } - } - - //if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) && - // (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1))) + for (int ii = 0; ii < pdb.chains.size(); ii++) { + chain = (PDBChain) pdb.chains.elementAt(ii); - int index = findTrueIndex(tmp.at2.alignmentMapping); - //sequence.findIndex( tmp.at2.alignmentMapping ); - if (index != -1) + for (int i = 0; i < chain.bonds.size(); i++) { - tmp.endCol = seqcanvas.getSequenceRenderer(). - getResidueBoxColour(sequence, index); - - if (showFeatures) + Bond tmp = (Bond) chain.bonds.elementAt(i); + tmp.startCol = Color.lightGray; + tmp.endCol = Color.lightGray; + if (chain != mainchain) { - tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index); + continue; } - if (tmp.endCol == null) + for (int s = 0; s < sequence.length; s++) { - tmp.endCol = Color.white; + for (int m = 0; m < mapping.length; m++) + { + if (mapping[m].getSequence() == sequence[s]) + { + int pos = mapping[m].getSeqPos(tmp.at1.resNumber) - 1; + if (pos > 0) + { + pos = sequence[s].findIndex(pos); + tmp.startCol = sr.getResidueBoxColour(sequence[s], pos); + if (showFeatures) + { + tmp.startCol = fr.findFeatureColour(tmp.startCol, + sequence[s], pos); + } + } + pos = mapping[m].getSeqPos(tmp.at2.resNumber) - 1; + if (pos > 0) + { + pos = sequence[s].findIndex(pos); + tmp.endCol = sr.getResidueBoxColour(sequence[s], pos); + if (showFeatures) + { + tmp.endCol = fr.findFeatureColour(tmp.endCol, + sequence[s], pos); + } + } + + } + } } } } @@ -581,6 +587,7 @@ public class PDBCanvas } Zsort zsort; + public void drawScene(Graphics g) { if (zbuffer) @@ -598,15 +605,11 @@ public class PDBCanvas { tmpBond = (Bond) visiblebonds.elementAt(i); - xstart = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) + - (getWidth() / 2)); - ystart = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) + - (getHeight() / 2)); + xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getWidth() / 2)); + ystart = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getHeight() / 2)); - xend = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) + - (getWidth() / 2)); - yend = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) + - (getHeight() / 2)); + xend = (int) (((tmpBond.end[0] - centre[0]) * scale) + (getWidth() / 2)); + yend = (int) (((centre[1] - tmpBond.end[1]) * scale) + (getHeight() / 2)); xmid = (xend + xstart) / 2; ymid = (yend + ystart) / 2; @@ -670,13 +673,15 @@ public class PDBCanvas if (highlightBond1 != null && highlightBond1 == tmpBond) { - g.setColor(tmpBond.endCol.brighter().brighter().brighter().brighter()); + g.setColor(tmpBond.endCol.brighter().brighter().brighter() + .brighter()); drawLine(g, xmid, ymid, xend, yend); } if (highlightBond2 != null && highlightBond2 == tmpBond) { - g.setColor(tmpBond.startCol.brighter().brighter().brighter().brighter()); + g.setColor(tmpBond.startCol.brighter().brighter().brighter() + .brighter()); drawLine(g, xstart, ystart, xmid, ymid); } @@ -688,7 +693,7 @@ public class PDBCanvas { if (!wire) { - if ( ( (float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) + if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) { g.drawLine(x1, y1, x2, y2); g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1); @@ -795,52 +800,33 @@ public class PDBCanvas chain = (PDBChain) pdb.chains.elementAt(foundchain); if (chain == mainchain) { - highlightSeqcanvas(fatom.alignmentMapping); + mouseOverStructure(fatom.resNumber, chain.id); } } if (fatom != null) { - this.setToolTipText(chain.id + ":" + fatom.resNumber + " " + - fatom.resName); + this.setToolTipText(chain.id + ":" + fatom.resNumber + " " + + fatom.resName); } else { - highlightSeqcanvas( -1); + mouseOverStructure(-1, chain != null ? chain.id : null); this.setToolTipText(null); } } - void highlightSeqcanvas(int pos) + public void mouseClicked(MouseEvent e) { - SearchResults searchResults = new SearchResults(); - if (highlightRes != null) - { - for (int i = 0; i < highlightRes.size(); i++) - { - int a = Integer.parseInt(highlightRes.elementAt( - i).toString()) + 1; - - searchResults.addResult(sequence, a, a); - } - } - - if (pos != -1) - { - searchResults.addResult(sequence, pos + 1, pos + 1); - } - - seqcanvas.highlightSearchResults(searchResults); } - public void mouseClicked(MouseEvent e) - {} - public void mouseEntered(MouseEvent e) - {} + { + } public void mouseExited(MouseEvent e) - {} + { + } public void mouseDragged(MouseEvent evt) { @@ -852,33 +838,33 @@ public class PDBCanvas MCMatrix objmat = new MCMatrix(3, 3); objmat.setIdentity(); - if ( (evt.getModifiers() & Event.META_MASK) != 0) + if ((evt.getModifiers() & Event.META_MASK) != 0) { - objmat.rotatez( (float) ( (mx - omx))); + objmat.rotatez((float) ((mx - omx))); } else { - objmat.rotatex( (float) ( (my - omy))); - objmat.rotatey( (float) ( (omx - mx))); + objmat.rotatex((float) ((my - omy))); + objmat.rotatey((float) ((omx - mx))); } - //Alter the bonds + // Alter the bonds for (int ii = 0; ii < pdb.chains.size(); ii++) { - Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; + Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; for (int i = 0; i < bonds.size(); i++) { Bond tmpBond = (Bond) bonds.elementAt(i); - //Translate the bond so the centre is 0,0,0 - tmpBond.translate( -centre[0], -centre[1], -centre[2]); + // Translate the bond so the centre is 0,0,0 + tmpBond.translate(-centre[0], -centre[1], -centre[2]); - //Now apply the rotation matrix + // Now apply the rotation matrix tmpBond.start = objmat.vectorMultiply(tmpBond.start); tmpBond.end = objmat.vectorMultiply(tmpBond.end); - //Now translate back again + // Now translate back again tmpBond.translate(centre[0], centre[1], centre[2]); } } @@ -910,7 +896,7 @@ public class PDBCanvas if (chain.isVisible) { - Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; + Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; for (int i = 0; i < bonds.size(); i++) { @@ -937,26 +923,23 @@ public class PDBCanvas g.setColor(Color.red); if (n == 1) { - int xstart = (int) ( ( (b.start[0] - centre[0]) * scale) + - (getWidth() / 2)); - int ystart = (int) ( ( (b.start[1] - centre[1]) * scale) + - (getHeight() / 2)); + int xstart = (int) (((b.start[0] - centre[0]) * scale) + (getWidth() / 2)); + int ystart = (int) (((centre[1] - b.start[1]) * scale) + (getHeight() / 2)); g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart); } if (n == 2) { - int xstart = (int) ( ( (b.end[0] - centre[0]) * scale) + - (getWidth() / 2)); - int ystart = (int) ( ( (b.end[1] - centre[1]) * scale) + - (getHeight() / 2)); + int xstart = (int) (((b.end[0] - centre[0]) * scale) + (getWidth() / 2)); + int ystart = (int) (((centre[1] - b.end[1]) * scale) + (getHeight() / 2)); g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart); } } int foundchain = -1; + public Atom findAtom(int x, int y) { Atom fatom = null; @@ -971,19 +954,17 @@ public class PDBCanvas if (chain.isVisible) { - Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; + Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; for (int i = 0; i < bonds.size(); i++) { tmpBond = (Bond) bonds.elementAt(i); - truex = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) + - (getWidth() / 2)); + truex = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getWidth() / 2)); if (Math.abs(truex - x) <= 2) { - int truey = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) + - (getHeight() / 2)); + int truey = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getHeight() / 2)); if (Math.abs(truey - y) <= 2) { @@ -996,13 +977,11 @@ public class PDBCanvas // Still here? Maybe its the last bond - truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) + - (getWidth() / 2)); + truex = (int) (((tmpBond.end[0] - centre[0]) * scale) + (getWidth() / 2)); if (Math.abs(truex - x) <= 2) { - int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) + - (getHeight() / 2)); + int truey = (int) (((tmpBond.end[1] - centre[1]) * scale) + (getHeight() / 2)); if (Math.abs(truey - y) <= 2) { @@ -1014,7 +993,7 @@ public class PDBCanvas } - if (fatom != null) //)&& chain.ds != null) + if (fatom != null) // )&& chain.ds != null) { chain = (PDBChain) pdb.chains.elementAt(foundchain); } @@ -1024,6 +1003,7 @@ public class PDBCanvas } Bond highlightBond1, highlightBond2; + public void highlightRes(int ii) { if (!seqColoursReady) @@ -1031,8 +1011,7 @@ public class PDBCanvas return; } - if (highlightRes != null - && highlightRes.contains( (ii - 1) + "")) + if (highlightRes != null && highlightRes.contains((ii - 1) + "")) { return; } @@ -1088,4 +1067,104 @@ public class PDBCanvas findCentre(); setupBonds(); } + + // //////////////////////////////// + // /StructureListener + public String[] getPdbFile() + { + return new String[] + { pdbentry.getFile() }; + } + + String lastMessage; + + public void mouseOverStructure(int pdbResNum, String chain) + { + if (lastMessage == null || !lastMessage.equals(pdbResNum + chain)) + ssm.mouseOverStructure(pdbResNum, chain, pdbentry.getFile()); + + lastMessage = pdbResNum + chain; + } + + StringBuffer resetLastRes = new StringBuffer(); + + StringBuffer eval = new StringBuffer(); + + public void highlightAtom(int atomIndex, int pdbResNum, String chain, + String pdbfile) + { + if (!seqColoursReady) + { + return; + } + + if (highlightRes != null && highlightRes.contains((atomIndex - 1) + "")) + { + return; + } + + int index = -1; + Bond tmpBond; + for (index = 0; index < mainchain.bonds.size(); index++) + { + tmpBond = (Bond) mainchain.bonds.elementAt(index); + if (tmpBond.at1.atomIndex == atomIndex) + { + if (highlightBond1 != null) + { + highlightBond1.at2.isSelected = false; + } + + if (highlightBond2 != null) + { + highlightBond2.at1.isSelected = false; + } + + highlightBond1 = null; + highlightBond2 = null; + + if (index > 0) + { + highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1); + highlightBond1.at2.isSelected = true; + } + + if (index != mainchain.bonds.size()) + { + highlightBond2 = (Bond) mainchain.bonds.elementAt(index); + highlightBond2.at1.isSelected = true; + } + + break; + } + } + + redrawneeded = true; + repaint(); + } + + public Color getColour(int atomIndex, int pdbResNum, String chain, + String pdbfile) + { + return Color.white; + // if (!pdbfile.equals(pdbentry.getFile())) + // return null; + + // return new Color(viewer.getAtomArgb(atomIndex)); + } + + public void updateColours(Object source) + { + colourBySequence(); + redrawneeded = true; + repaint(); + } + + @Override + public void releaseReferences(Object svl) + { + // TODO Auto-generated method stub + + } + }