X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FAppletPDBCanvas.java;h=543d6802240037f8e121a081a19c059524b9ae86;hb=153dd62dc91da13ae732600e6ea55ddbe15eab39;hp=a61ecb2a63b25b9ed1ac2a8b61e43bb7ffa6be2e;hpb=269257481bdc261d6f99cb43dac33c10c3b4e9e1;p=jalview.git diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java index a61ecb2..543d680 100755 --- a/src/MCview/AppletPDBCanvas.java +++ b/src/MCview/AppletPDBCanvas.java @@ -1,20 +1,19 @@ /* - * 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 - * 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. - * - * 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 + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) + * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * 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. + * + * 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 Jalview. If not, see . */ package MCview; @@ -31,60 +30,102 @@ import jalview.datamodel.*; import jalview.appletgui.*; import jalview.structure.*; -public class AppletPDBCanvas - extends Panel implements MouseListener, MouseMotionListener, StructureListener +public class AppletPDBCanvas extends Panel 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); - public SequenceI [] sequence; + + public SequenceI[] sequence; + final StringBuffer mappingDetails = new StringBuffer(); + String appletToolTip = null; + int toolx, tooly; + PDBChain mainchain; + Vector highlightRes; + boolean pdbAction = false; + Bond highlightBond1, highlightBond2; + boolean errorLoading = false; + boolean seqColoursReady = false; + FeatureRenderer fr; + AlignmentPanel ap; + StructureSelectionManager ssm; - public AppletPDBCanvas(PDBEntry pdbentry, - SequenceI[] seq, - AlignmentPanel ap, - String protocol) + public AppletPDBCanvas(PDBEntry pdbentry, SequenceI[] seq, + String[] chains, AlignmentPanel ap, String protocol) { this.ap = ap; @@ -93,14 +134,14 @@ public class AppletPDBCanvas ssm = StructureSelectionManager.getStructureSelectionManager(); - try{ - pdb = ssm.setMapping(seq, pdbentry.getFile(), protocol); + try + { + pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol); - if(protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) - pdbentry.setFile("INLINE"+pdb.id); - //if (fr!=null) - // fr.featuresAdded(); - }catch(Exception ex) + if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) + pdbentry.setFile("INLINE" + pdb.id); + + } catch (Exception ex) { ex.printStackTrace(); return; @@ -110,9 +151,7 @@ public class AppletPDBCanvas ssm.addStructureViewerListener(this); - colourBySequence(ap.getSequenceRenderer(), - ap.av.getShowSequenceFeatures() ? - fr : null); + colourBySequence(); int max = -10; int maxchain = -1; @@ -120,27 +159,26 @@ public class AppletPDBCanvas int pdbend = 0; int seqstart = 0; int seqend = 0; - AlignSeq maxAlignseq = null; - //JUST DEAL WITH ONE SEQUENCE FOR NOW + // 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, - "pep"); + // TODO: DNa/Pep switch + AlignSeq as = new AlignSeq(sequence, ((PDBChain) pdb.chains + .elementAt(i)).sequence, ((PDBChain) pdb.chains.elementAt(i)).isNa ? AlignSeq.DNA : AlignSeq.PEP); as.calcScoreMatrix(); as.traceAlignment(); PrintStream ps = new PrintStream(System.out) @@ -167,7 +205,6 @@ public class AppletPDBCanvas pdbend = as.seq2end; seqstart = as.seq1start + sequence.getStart() - 1; seqend = as.seq1end + sequence.getEnd() - 1; - maxAlignseq = as; } mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend); @@ -181,12 +218,12 @@ public class AppletPDBCanvas mainchain.seqstart = seqstart; mainchain.seqend = seqend; mainchain.isVisible = true; - // mainchain.makeExactMapping(maxAlignseq, sequence); - // mainchain.transferRESNUMFeatures(sequence, null); + // mainchain.makeExactMapping(maxAlignseq, sequence); + // mainchain.transferRESNUMFeatures(sequence, null); this.pdb = pdb; this.prefsize = new Dimension(getSize().width, getSize().height); - //Initialize the matrices to identity + // Initialize the matrices to identity for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) @@ -224,6 +261,7 @@ public class AppletPDBCanvas } Vector visiblebonds; + void setupBonds() { seqColoursReady = false; @@ -232,9 +270,9 @@ public class AppletPDBCanvas 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++) { @@ -243,9 +281,7 @@ public class AppletPDBCanvas } } seqColoursReady = true; - colourBySequence(ap.getSequenceRenderer(), - ap.av.getShowSequenceFeatures() ? - fr : null); + colourBySequence(); redrawneeded = true; repaint(); } @@ -255,9 +291,9 @@ public class AppletPDBCanvas 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; @@ -265,9 +301,9 @@ public class AppletPDBCanvas 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++) { @@ -392,25 +428,25 @@ public class AppletPDBCanvas 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]; } } } @@ -441,10 +477,10 @@ public class AppletPDBCanvas return; } - //Only create the image at the beginning - - //this saves much memory usage - if ( (img == null) || (prefsize.width != getSize().width) || - (prefsize.height != getSize().height)) + // Only create the image at the beginning - + // this saves much memory usage + if ((img == null) || (prefsize.width != getSize().width) + || (prefsize.height != getSize().height)) { try @@ -457,8 +493,7 @@ public class AppletPDBCanvas ig = img.getGraphics(); redrawneeded = true; - } - catch (Exception ex) + } catch (Exception ex) { ex.printStackTrace(); } @@ -496,23 +531,23 @@ public class AppletPDBCanvas repaint(); } - - // This method has been taken out of PDBChain to allow // Applet and Application specific sequence renderers to be used - void colourBySequence(SequenceRenderer sr, FeatureRenderer seqcanvasfr) + void colourBySequence() { + SequenceRenderer sr = new SequenceRenderer(ap.av); + StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile()); boolean showFeatures = false; - if (seqcanvasfr!=null) + if (ap.av.getShowSequenceFeatures()) { if (fr == null) { fr = new jalview.appletgui.FeatureRenderer(ap.av); } - fr.transferSettings(seqcanvasfr); + fr.transferSettings(ap.getFeatureRenderer()); showFeatures = true; } @@ -540,7 +575,7 @@ public class AppletPDBCanvas { if (mapping[m].getSequence() == sequence[s]) { - int pos = mapping[m].getSeqPos(tmp.at1.resNumber)-1; + int pos = mapping[m].getSeqPos(tmp.at1.resNumber) - 1; if (pos > 0) { pos = sequence[s].findIndex(pos); @@ -548,11 +583,10 @@ public class AppletPDBCanvas if (showFeatures) { tmp.startCol = fr.findFeatureColour(tmp.startCol, - sequence[s], - pos); + sequence[s], pos); } } - pos = mapping[m].getSeqPos(tmp.at2.resNumber)-1; + pos = mapping[m].getSeqPos(tmp.at2.resNumber) - 1; if (pos > 0) { pos = sequence[s].findIndex(pos); @@ -560,8 +594,7 @@ public class AppletPDBCanvas if (showFeatures) { tmp.endCol = fr.findFeatureColour(tmp.endCol, - sequence[s], - pos); + sequence[s], pos); } } @@ -574,6 +607,7 @@ public class AppletPDBCanvas } Zsort zsort; + public void drawScene(Graphics g) { if (zbuffer) @@ -591,15 +625,11 @@ public class AppletPDBCanvas { tmpBond = (Bond) visiblebonds.elementAt(i); - xstart = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) + - (getSize().width / 2)); - ystart = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) + - (getSize().height / 2)); + xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getSize().width / 2)); + ystart = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getSize().height / 2)); - xend = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) + - (getSize().width / 2)); - yend = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) + - (getSize().height / 2)); + xend = (int) (((tmpBond.end[0] - centre[0]) * scale) + (getSize().width / 2)); + yend = (int) (((centre[1] - tmpBond.end[1]) * scale) + (getSize().height / 2)); xmid = (xend + xstart) / 2; ymid = (yend + ystart) / 2; @@ -681,7 +711,7 @@ public class AppletPDBCanvas { 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); @@ -797,13 +827,14 @@ public class AppletPDBCanvas toolx = e.getX(); tooly = e.getY(); - appletToolTip = chain.id + ":" + fatom.resNumber + " " + fatom.resName; + appletToolTip = chain.id + ":" + fatom.resNumber + " " + + fatom.resName; redrawneeded = true; repaint(); } else { - mouseOverStructure(-1, chain!=null?chain.id:null); + mouseOverStructure(-1, chain != null ? chain.id : null); appletToolTip = null; redrawneeded = true; repaint(); @@ -832,33 +863,33 @@ public class AppletPDBCanvas 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) ((omy - my))); + 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]); } } @@ -890,7 +921,7 @@ public class AppletPDBCanvas 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++) { @@ -917,10 +948,8 @@ public class AppletPDBCanvas if (n == 1) { - int xstart = (int) ( ( (b.start[0] - centre[0]) * scale) + - (getSize().width / 2)); - int ystart = (int) ( ( (b.start[1] - centre[1]) * scale) + - (getSize().height / 2)); + int xstart = (int) (((b.start[0] - centre[0]) * scale) + (getSize().width / 2)); + int ystart = (int) (((centre[1] - b.start[1]) * scale) + (getSize().height / 2)); g.setColor(Color.red); g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart); @@ -928,10 +957,8 @@ public class AppletPDBCanvas if (n == 2) { - int xstart = (int) ( ( (b.end[0] - centre[0]) * scale) + - (getSize().width / 2)); - int ystart = (int) ( ( (b.end[1] - centre[1]) * scale) + - (getSize().height / 2)); + int xstart = (int) (((b.end[0] - centre[0]) * scale) + (getSize().width / 2)); + int ystart = (int) (((centre[1] - b.end[1]) * scale) + (getSize().height / 2)); g.setColor(Color.red); g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart); @@ -939,6 +966,7 @@ public class AppletPDBCanvas } int foundchain = -1; + public Atom findAtom(int x, int y) { Atom fatom = null; @@ -953,19 +981,17 @@ public class AppletPDBCanvas 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) + - (getSize().width / 2)); + truex = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getSize().width / 2)); if (Math.abs(truex - x) <= 2) { - int truey = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) + - (getSize().height / 2)); + int truey = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getSize().height / 2)); if (Math.abs(truey - y) <= 2) { @@ -978,13 +1004,11 @@ public class AppletPDBCanvas // Still here? Maybe its the last bond - truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) + - (getSize().width / 2)); + truex = (int) (((tmpBond.end[0] - centre[0]) * scale) + (getSize().width / 2)); if (Math.abs(truex - x) <= 2) { - int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) + - (getSize().height / 2)); + int truey = (int) (((tmpBond.end[1] - centre[1]) * scale) + (getSize().height / 2)); if (Math.abs(truey - y) <= 2) { @@ -996,7 +1020,7 @@ public class AppletPDBCanvas } - if (fatom != null) //)&& chain.ds != null) + if (fatom != null) // )&& chain.ds != null) { chain = (PDBChain) pdb.chains.elementAt(foundchain); } @@ -1017,8 +1041,7 @@ public class AppletPDBCanvas return; } - if (highlightRes != null - && highlightRes.contains( (ii - 1) + "")) + if (highlightRes != null && highlightRes.contains((ii - 1) + "")) { return; } @@ -1075,36 +1098,36 @@ public class AppletPDBCanvas setupBonds(); } - - ////////////////////////////////// - ///StructureListener - public String getPdbFile() + // //////////////////////////////// + // /StructureListener + public String[] getPdbFile() { - return "???"; + 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()); + if (lastMessage == null || !lastMessage.equals(pdbResNum + chain)) + ssm.mouseOverStructure(pdbResNum, chain, pdbentry.getFile()); - lastMessage = pdbResNum+chain; + lastMessage = pdbResNum + chain; } StringBuffer resetLastRes = new StringBuffer(); + StringBuffer eval = new StringBuffer(); - public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile) + public void highlightAtom(int atomIndex, int pdbResNum, String chain, + String pdbfile) { if (!seqColoursReady) { return; } - if (highlightRes != null - && highlightRes.contains( (atomIndex - 1) + "")) + if (highlightRes != null && highlightRes.contains((atomIndex - 1) + "")) { return; } @@ -1149,25 +1172,21 @@ public class AppletPDBCanvas repaint(); } - - public Color getColour(int atomIndex, int pdbResNum, String chain, String pdbfile) + public Color getColour(int atomIndex, int pdbResNum, String chain, + String pdbfile) { return Color.white; - // if (!pdbfile.equals(pdbentry.getFile())) - // return null; + // if (!pdbfile.equals(pdbentry.getFile())) + // return null; - //return new Color(viewer.getAtomArgb(atomIndex)); + // return new Color(viewer.getAtomArgb(atomIndex)); } public void updateColours(Object source) { - AlignmentPanel ap = (AlignmentPanel) source; - colourBySequence(ap.getSequenceRenderer(), - ap.av.getShowSequenceFeatures() ? - fr : null); + colourBySequence(); redrawneeded = true; repaint(); } - }