From dd74fc4938723fe5ec48d4e5fdcfbe58ac42a48d Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 7 Feb 2007 14:59:46 +0000 Subject: [PATCH] formatting --- src/MCview/AppletPDBCanvas.java | 1659 +++++++++++++++++++++------------------ src/MCview/AppletPDBViewer.java | 382 +++++---- src/MCview/Atom.java | 100 +-- src/MCview/Bond.java | 84 +- src/MCview/MCMatrix.java | 293 +++---- src/MCview/PDBCanvas.java | 1552 +++++++++++++++++++----------------- src/MCview/PDBChain.java | 594 +++++++------- src/MCview/PDBViewer.java | 248 +++--- src/MCview/PDBfile.java | 283 ++++--- src/MCview/Residue.java | 77 +- src/MCview/Zsort.java | 112 +-- 11 files changed, 2859 insertions(+), 2525 deletions(-) diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java index 609126c..dd33b0c 100755 --- a/src/MCview/AppletPDBCanvas.java +++ b/src/MCview/AppletPDBCanvas.java @@ -1,1003 +1,1100 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 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 + * 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 + */ package MCview; -import jalview.analysis.AlignSeq; - -import jalview.datamodel.*; +import java.io.*; +import java.util.*; // JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug import java.awt.*; import java.awt.event.*; -import java.io.*; - -import java.util.*; - - +import jalview.analysis.*; +import jalview.datamodel.*; -public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotionListener +public class AppletPDBCanvas + extends Panel implements MouseListener, MouseMotionListener { - 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; - 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.appletgui.SeqCanvas seqcanvas; - public Sequence 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; - jalview.appletgui.FeatureRenderer fr; - - public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq) - { - this.seqcanvas = seqcanvas; - this.sequence = seq; - - seqcanvas.setPDBCanvas(this); - addKeyListener(new KeyAdapter() - { - - public void keyPressed(KeyEvent evt) - { - doKeyPressed(evt); - } - }); - } + 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; + 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.appletgui.SeqCanvas seqcanvas; + public Sequence 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; + jalview.appletgui.FeatureRenderer fr; + + public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq) + { + this.seqcanvas = seqcanvas; + this.sequence = seq; + + seqcanvas.setPDBCanvas(this); + addKeyListener(new KeyAdapter() + { + public void keyPressed(KeyEvent evt) + { + doKeyPressed(evt); + } + }); + } public void setPDBFile(PDBfile pdb) - { - int max = -10; - int maxchain = -1; - int pdbstart = 0; - int pdbend = 0; - int seqstart = 0; - int seqend = 0; - AlignSeq maxAlignseq = null;; - - 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"); - - // 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"); - as.calcScoreMatrix(); - as.traceAlignment(); - PrintStream ps = new PrintStream(System.out) - { - public void print(String x) { - mappingDetails.append(x); - } - public void println() - { - mappingDetails.append("\n"); - } - }; - - as.printAlignment(ps); - - if (as.maxscore > max) { - 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; - } + { + int max = -10; + int maxchain = -1; + int pdbstart = 0; + int pdbend = 0; + int seqstart = 0; + int seqend = 0; + AlignSeq maxAlignseq = null; ; + + for (int i = 0; i < pdb.chains.size(); i++) + { - mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend); - mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend); + 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"); + as.calcScoreMatrix(); + as.traceAlignment(); + PrintStream ps = new PrintStream(System.out) + { + public void print(String x) + { + mappingDetails.append(x); } - mainchain = (PDBChain) pdb.chains.elementAt(maxchain); - - mainchain.pdbstart = pdbstart; - mainchain.pdbend = pdbend; - mainchain.seqstart = seqstart; - mainchain.seqend = seqend; - mainchain.isVisible = true; - mainchain.makeExactMapping(maxAlignseq, sequence); - mainchain.transferRESNUMFeatures(sequence, null); - this.pdb = pdb; - this.prefsize = new Dimension(getSize().width, getSize().height); - - //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); - } - } + public void println() + { + mappingDetails.append("\n"); } + }; - addMouseMotionListener(this); - addMouseListener(this); + as.printAlignment(ps); + if (as.maxscore > max) + { + 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; + } - findCentre(); - findWidth(); - - setupBonds(); - - scale = findScale(); + mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend); + mappingDetails.append("\nSEQ start/end " + seqstart + " " + seqend); } + mainchain = (PDBChain) pdb.chains.elementAt(maxchain); - Vector visiblebonds; - void setupBonds() - { - seqColoursReady = false; - // Sort the bonds by z coord - visiblebonds = new Vector(); + mainchain.pdbstart = pdbstart; + mainchain.pdbend = pdbend; + mainchain.seqstart = seqstart; + mainchain.seqend = seqend; + mainchain.isVisible = true; + mainchain.makeExactMapping(maxAlignseq, sequence); + mainchain.transferRESNUMFeatures(sequence, null); + this.pdb = pdb; + this.prefsize = new Dimension(getSize().width, getSize().height); - for (int ii = 0; ii < pdb.chains.size(); ii++) + //Initialize the matrices to identity + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) { - if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + if (i != j) { - Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - - for (int i = 0; i < tmp.size(); i++) - { - visiblebonds.addElement(tmp.elementAt(i)); - } + idmat.addElement(i, j, 0); + objmat.addElement(i, j, 0); + } + else + { + idmat.addElement(i, j, 1); + objmat.addElement(i, j, 1); } } - updateSeqColours(); - seqColoursReady = true; - redrawneeded = true; - repaint(); } + addMouseMotionListener(this); + addMouseListener(this); - public void findWidth() { - float[] max = new float[3]; - float[] min = new float[3]; - - max[0] = (float) -1e30; - max[1] = (float) -1e30; - max[2] = (float) -1e30; - - min[0] = (float) 1e30; - min[1] = (float) 1e30; - min[2] = (float) 1e30; + findCentre(); + findWidth(); - for (int ii = 0; ii < pdb.chains.size(); ii++) { - if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) { - Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + setupBonds(); - for (int i = 0; i < bonds.size(); i++) { - Bond tmp = (Bond) bonds.elementAt(i); + scale = findScale(); + } - if (tmp.start[0] >= max[0]) { - max[0] = tmp.start[0]; - } + Vector visiblebonds; + void setupBonds() + { + seqColoursReady = false; + // Sort the bonds by z coord + visiblebonds = new Vector(); - if (tmp.start[1] >= max[1]) { - max[1] = tmp.start[1]; - } + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + { + Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - if (tmp.start[2] >= max[2]) { - max[2] = tmp.start[2]; - } + for (int i = 0; i < tmp.size(); i++) + { + visiblebonds.addElement(tmp.elementAt(i)); + } + } + } + updateSeqColours(); + seqColoursReady = true; + redrawneeded = true; + repaint(); + } + + public void findWidth() + { + float[] max = new float[3]; + float[] min = new float[3]; + + max[0] = (float) - 1e30; + max[1] = (float) - 1e30; + max[2] = (float) - 1e30; + + min[0] = (float) 1e30; + min[1] = (float) 1e30; + min[2] = (float) 1e30; + + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + { + Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - if (tmp.start[0] <= min[0]) { - min[0] = tmp.start[0]; - } + for (int i = 0; i < bonds.size(); i++) + { + Bond tmp = (Bond) bonds.elementAt(i); - if (tmp.start[1] <= min[1]) { - min[1] = tmp.start[1]; - } + if (tmp.start[0] >= max[0]) + { + max[0] = tmp.start[0]; + } - if (tmp.start[2] <= min[2]) { - min[2] = tmp.start[2]; - } + if (tmp.start[1] >= max[1]) + { + max[1] = tmp.start[1]; + } - if (tmp.end[0] >= max[0]) { - max[0] = tmp.end[0]; - } + if (tmp.start[2] >= max[2]) + { + max[2] = tmp.start[2]; + } - if (tmp.end[1] >= max[1]) { - max[1] = tmp.end[1]; - } + if (tmp.start[0] <= min[0]) + { + min[0] = tmp.start[0]; + } - if (tmp.end[2] >= max[2]) { - max[2] = tmp.end[2]; - } + if (tmp.start[1] <= min[1]) + { + min[1] = tmp.start[1]; + } - if (tmp.end[0] <= min[0]) { - min[0] = tmp.end[0]; - } + if (tmp.start[2] <= min[2]) + { + min[2] = tmp.start[2]; + } - if (tmp.end[1] <= min[1]) { - min[1] = tmp.end[1]; - } + if (tmp.end[0] >= max[0]) + { + max[0] = tmp.end[0]; + } - if (tmp.end[2] <= min[2]) { - min[2] = tmp.end[2]; - } - } - } - } + if (tmp.end[1] >= max[1]) + { + max[1] = tmp.end[1]; + } - width[0] = (float) Math.abs(max[0] - min[0]); - width[1] = (float) Math.abs(max[1] - min[1]); - width[2] = (float) Math.abs(max[2] - min[2]); + if (tmp.end[2] >= max[2]) + { + max[2] = tmp.end[2]; + } - maxwidth = width[0]; + if (tmp.end[0] <= min[0]) + { + min[0] = tmp.end[0]; + } - if (width[1] > width[0]) { - maxwidth = width[1]; - } + if (tmp.end[1] <= min[1]) + { + min[1] = tmp.end[1]; + } - if (width[2] > width[1]) { - maxwidth = width[2]; + if (tmp.end[2] <= min[2]) + { + min[2] = tmp.end[2]; + } } - - // System.out.println("Maxwidth = " + maxwidth); + } } - public float findScale() { - int dim; - int width; - int height; - - if (getSize().width != 0) { - width = getSize().width; - height = getSize().height; - } else { - width = prefsize.width; - height = prefsize.height; - } + width[0] = (float) Math.abs(max[0] - min[0]); + width[1] = (float) Math.abs(max[1] - min[1]); + width[2] = (float) Math.abs(max[2] - min[2]); - if (width < height) { - dim = width; - } else { - dim = height; - } + maxwidth = width[0]; - return (float) (dim / (1.5d * maxwidth)); + if (width[1] > width[0]) + { + maxwidth = width[1]; } - public void findCentre() { - float xtot = 0; - float ytot = 0; - float ztot = 0; - - int bsize = 0; - - //Find centre coordinate - for (int ii = 0; ii < pdb.chains.size(); ii++) { - if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) { - 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]; + if (width[2] > width[1]) + { + maxwidth = width[2]; + } - ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] + - ((Bond) bonds.elementAt(i)).end[1]; + // System.out.println("Maxwidth = " + maxwidth); + } - ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] + - ((Bond) bonds.elementAt(i)).end[2]; - } - } - } + public float findScale() + { + int dim; + int width; + int height; - centre[0] = xtot / (2 * (float) bsize); - centre[1] = ytot / (2 * (float) bsize); - centre[2] = ztot / (2 * (float) bsize); + if (getSize().width != 0) + { + width = getSize().width; + height = getSize().height; + } + else + { + width = prefsize.width; + height = prefsize.height; } - public void paint(Graphics g) + if (width < height) { + dim = width; + } + else + { + dim = height; + } - if(errorLoading) - { - g.setColor(Color.white); - g.fillRect(0,0,getSize().width, getSize().height); - g.setColor(Color.black); - g.setFont(new Font("Verdana", Font.BOLD, 14)); - g.drawString("Error loading PDB data!!", 50, getSize().height/2); - return; - } + return (float) (dim / (1.5d * maxwidth)); + } - if( !seqColoursReady ) - { - g.setColor(Color.black); - g.setFont(new Font("Verdana", Font.BOLD, 14)); - g.drawString("Fetching PDB data...", 50, getSize().height/2); - return; - } + public void findCentre() + { + float xtot = 0; + float ytot = 0; + float ztot = 0; + int bsize = 0; + //Find centre coordinate + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + { + Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - //Only create the image at the beginning - - //this saves much memory usage - if ((img == null) || (prefsize.width != getSize().width) || - (prefsize.height != getSize().height)) { + bsize += bonds.size(); - try{ prefsize.width = getSize().width; - prefsize.height = getSize().height; + for (int i = 0; i < bonds.size(); i++) + { + xtot = xtot + ( (Bond) bonds.elementAt(i)).start[0] + + ( (Bond) bonds.elementAt(i)).end[0]; - scale = findScale(); - img = createImage(prefsize.width, prefsize.height); - ig = img.getGraphics(); + ytot = ytot + ( (Bond) bonds.elementAt(i)).start[1] + + ( (Bond) bonds.elementAt(i)).end[1]; - redrawneeded = true; - }catch(Exception ex) - { - ex.printStackTrace(); - } + ztot = ztot + ( (Bond) bonds.elementAt(i)).start[2] + + ( (Bond) bonds.elementAt(i)).end[2]; } + } + } + centre[0] = xtot / (2 * (float) bsize); + centre[1] = ytot / (2 * (float) bsize); + centre[2] = ztot / (2 * (float) bsize); + } - if (redrawneeded) - { - drawAll(ig, prefsize.width, prefsize.height); - redrawneeded = false; - } - if(appletToolTip!=null) - { - ig.setColor(Color.red); - ig.drawString(appletToolTip, toolx, tooly); - } - - g.drawImage(img, 0, 0, this); + public void paint(Graphics g) + { - pdbAction = false; + if (errorLoading) + { + g.setColor(Color.white); + g.fillRect(0, 0, getSize().width, getSize().height); + g.setColor(Color.black); + g.setFont(new Font("Verdana", Font.BOLD, 14)); + g.drawString("Error loading PDB data!!", 50, getSize().height / 2); + return; } - public void drawAll(Graphics g, int width, int height) + if (!seqColoursReady) { - ig.setColor(Color.black); - ig.fillRect(0, 0, width, height); - drawScene(ig); - drawLabels(ig); + g.setColor(Color.black); + g.setFont(new Font("Verdana", Font.BOLD, 14)); + g.drawString("Fetching PDB data...", 50, getSize().height / 2); + return; } - void setColours(jalview.schemes.ColourSchemeI cs) - { - bysequence = false; - pdb.setColours(cs); - redrawneeded = true; - repaint(); - } - public void updateSeqColours() + //Only create the image at the beginning - + //this saves much memory usage + if ( (img == null) || (prefsize.width != getSize().width) || + (prefsize.height != getSize().height)) { - if (pdbAction) + + try { - return; - } + prefsize.width = getSize().width; + prefsize.height = getSize().height; + + scale = findScale(); + img = createImage(prefsize.width, prefsize.height); + ig = img.getGraphics(); - if(bysequence && pdb!=null) + redrawneeded = true; + } + catch (Exception ex) { - for (int ii = 0; ii < pdb.chains.size(); ii++) - { - colourBySequence((PDBChain) pdb.chains.elementAt(ii)); - } + ex.printStackTrace(); } - - redrawneeded=true; - repaint(); } + if (redrawneeded) + { + drawAll(ig, prefsize.width, prefsize.height); + redrawneeded = false; + } + if (appletToolTip != null) + { + ig.setColor(Color.red); + ig.drawString(appletToolTip, toolx, tooly); + } - int findTrueIndex(int pos) + g.drawImage(img, 0, 0, this); + + pdbAction = false; + } + + public void drawAll(Graphics g, int width, int height) + { + ig.setColor(Color.black); + ig.fillRect(0, 0, width, height); + drawScene(ig); + drawLabels(ig); + } + + void setColours(jalview.schemes.ColourSchemeI cs) + { + bysequence = false; + pdb.setColours(cs); + redrawneeded = true; + repaint(); + } + + public void updateSeqColours() + { + if (pdbAction) { - // returns the alignment position for a residue - int j = sequence.getStart(); - int i = 0; + return; + } - while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && (j <= pos+1)) + if (bysequence && pdb != null) + { + for (int ii = 0; ii < pdb.chains.size(); ii++) { - if (!jalview.util.Comparison.isGap(sequence.getCharAt(i))) - { - j++; - } - - i++; + colourBySequence( (PDBChain) pdb.chains.elementAt(ii)); } + } - if(i>1) - i--; + redrawneeded = true; + repaint(); + } - if ( (j == sequence.getEnd()) && (j < pos)) - { - return sequence.getEnd() + 1; - } - else + int findTrueIndex(int pos) + { + // returns the alignment position for a residue + int j = sequence.getStart(); + int i = 0; + + while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && + (j <= pos + 1)) + { + if (!jalview.util.Comparison.isGap(sequence.getCharAt(i))) { - return i; + j++; } + + i++; } + if (i > 1) + { + i--; + } - // This method has been taken out of PDBChain to allow - // Applet and Application specific sequence renderers to be used - void colourBySequence(PDBChain chain) + if ( (j == sequence.getEnd()) && (j < pos)) + { + return sequence.getEnd() + 1; + } + else { - boolean showFeatures = false; + return i; + } + } - if(seqcanvas.getViewport().getShowSequenceFeatures()) - { - if(fr==null) - { - fr = new jalview.appletgui.FeatureRenderer(seqcanvas.getViewport()); - } - fr.transferSettings( seqcanvas.getFeatureRenderer()); - showFeatures = true; - } + // This method has been taken out of PDBChain to allow + // Applet and Application specific sequence renderers to be used + void colourBySequence(PDBChain chain) + { + boolean showFeatures = false; - for (int i = 0; i < chain.bonds.size(); i++) + if (seqcanvas.getViewport().getShowSequenceFeatures()) + { + if (fr == null) { - Bond tmp = (Bond) chain.bonds.elementAt(i); - tmp.startCol = Color.lightGray; - tmp.endCol = Color.lightGray; - if(chain!=mainchain) - continue; - - if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) && - (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1))) - { + fr = new jalview.appletgui.FeatureRenderer(seqcanvas.getViewport()); + } + fr.transferSettings(seqcanvas.getFeatureRenderer()); + showFeatures = true; + } - int index = findTrueIndex(tmp.at1.alignmentMapping); - //sequence.findIndex(tmp.at1.alignmentMapping); - if (index != -1) - { - tmp.startCol = seqcanvas.getSequenceRenderer(). - getResidueBoxColour( sequence, index); + for (int i = 0; i < chain.bonds.size(); i++) + { + Bond tmp = (Bond) chain.bonds.elementAt(i); + tmp.startCol = Color.lightGray; + tmp.endCol = Color.lightGray; + if (chain != mainchain) + { + continue; + } - if(showFeatures) - tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index); - } - } + if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) && + (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1))) + { - int index = findTrueIndex(tmp.at2.alignmentMapping); - //sequence.findIndex( tmp.at2.alignmentMapping ); + int index = findTrueIndex(tmp.at1.alignmentMapping); + //sequence.findIndex(tmp.at1.alignmentMapping); if (index != -1) { - tmp.endCol = seqcanvas.getSequenceRenderer(). - getResidueBoxColour( sequence, index); + tmp.startCol = seqcanvas.getSequenceRenderer(). + getResidueBoxColour(sequence, index); - if(showFeatures) - tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index); + if (showFeatures) + { + tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index); + } } } - } + int index = findTrueIndex(tmp.at2.alignmentMapping); + //sequence.findIndex( tmp.at2.alignmentMapping ); + if (index != -1) + { + tmp.endCol = seqcanvas.getSequenceRenderer(). + getResidueBoxColour(sequence, index); - Zsort zsort; - public void drawScene(Graphics g) - { - if (zbuffer) + if (showFeatures) { - if(zsort ==null) - zsort = new Zsort(); - - zsort.Zsort(visiblebonds); + tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index); } + } + } + } + Zsort zsort; + public void drawScene(Graphics g) + { + if (zbuffer) + { + if (zsort == null) + { + zsort = new Zsort(); + } - Bond tmpBond=null; - for (int i = 0; i < visiblebonds.size(); i++) - { - tmpBond = (Bond) visiblebonds.elementAt(i); + zsort.Zsort(visiblebonds); + } + Bond tmpBond = null; + for (int i = 0; i < visiblebonds.size(); i++) + { + 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) ( ( (tmpBond.start[1] - centre[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) ( ( (tmpBond.end[1] - centre[1]) * scale) + + (getSize().height / 2)); - xmid = (xend + xstart) / 2; - ymid = (yend + ystart) / 2; + xmid = (xend + xstart) / 2; + ymid = (yend + ystart) / 2; - if (depthcue && !bymolecule) - { - if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) { - g.setColor(tmpBond.startCol.darker().darker()); - drawLine(g, xstart, ystart, xmid, ymid); - - g.setColor(tmpBond.endCol.darker().darker()); - drawLine(g, xmid, ymid, xend, yend); - } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) { - g.setColor(tmpBond.startCol.darker()); - drawLine(g, xstart, ystart, xmid, ymid); - - g.setColor(tmpBond.endCol.darker()); - drawLine(g, xmid, ymid, xend, yend); - } else { - g.setColor(tmpBond.startCol); - drawLine(g, xstart, ystart, xmid, ymid); - - g.setColor(tmpBond.endCol); - drawLine(g, xmid, ymid, xend, yend); - } - - } else if (depthcue && bymolecule) { - if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) { - g.setColor(Color.green.darker().darker()); - drawLine(g, xstart, ystart, xend, yend); - } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) { - g.setColor(Color.green.darker()); - drawLine(g, xstart, ystart, xend, yend); - } else { - g.setColor(Color.green); - drawLine(g, xstart, ystart, xend, yend); - } - } else if (!depthcue && !bymolecule) { - g.setColor(tmpBond.startCol); - drawLine(g, xstart, ystart, xmid, ymid); - g.setColor(tmpBond.endCol); - drawLine(g, xmid, ymid, xend, yend); - } else { - drawLine(g, xstart, ystart, xend, yend); - } + if (depthcue && !bymolecule) + { + if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) + { + g.setColor(tmpBond.startCol.darker().darker()); + drawLine(g, xstart, ystart, xmid, ymid); - if(highlightBond1!=null && highlightBond1==tmpBond) - { - g.setColor(Color.white); - drawLine(g, xmid, ymid, xend, yend); - } + g.setColor(tmpBond.endCol.darker().darker()); + drawLine(g, xmid, ymid, xend, yend); + } + else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) + { + g.setColor(tmpBond.startCol.darker()); + drawLine(g, xstart, ystart, xmid, ymid); - if(highlightBond2!=null && highlightBond2==tmpBond) - { - g.setColor(Color.white); - drawLine(g, xstart, ystart, xmid, ymid); - } + g.setColor(tmpBond.endCol.darker()); + drawLine(g, xmid, ymid, xend, yend); + } + else + { + g.setColor(tmpBond.startCol); + drawLine(g, xstart, ystart, xmid, ymid); + g.setColor(tmpBond.endCol); + drawLine(g, xmid, ymid, xend, yend); } - } - public void drawLine(Graphics g, int x1, int y1, int x2, int y2) { - if (!wire) { - 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); - g.drawLine(x1, y1 - 1, x2, y2 - 1); - } else { - g.setColor(g.getColor().brighter()); - g.drawLine(x1, y1, x2, y2); - g.drawLine(x1 + 1, y1, x2 + 1, y2); - g.drawLine(x1 - 1, y1, x2 - 1, y2); - } - } else { - g.drawLine(x1, y1, x2, y2); + } + else if (depthcue && bymolecule) + { + if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) + { + g.setColor(Color.green.darker().darker()); + drawLine(g, xstart, ystart, xend, yend); } - } + else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) + { + g.setColor(Color.green.darker()); + drawLine(g, xstart, ystart, xend, yend); + } + else + { + g.setColor(Color.green); + drawLine(g, xstart, ystart, xend, yend); + } + } + else if (!depthcue && !bymolecule) + { + g.setColor(tmpBond.startCol); + drawLine(g, xstart, ystart, xmid, ymid); + g.setColor(tmpBond.endCol); + drawLine(g, xmid, ymid, xend, yend); + } + else + { + drawLine(g, xstart, ystart, xend, yend); + } - public Dimension minimumsize() { - return prefsize; - } + if (highlightBond1 != null && highlightBond1 == tmpBond) + { + g.setColor(Color.white); + drawLine(g, xmid, ymid, xend, yend); + } + + if (highlightBond2 != null && highlightBond2 == tmpBond) + { + g.setColor(Color.white); + drawLine(g, xstart, ystart, xmid, ymid); + } - public Dimension preferredsize() { - return prefsize; } + } - public void doKeyPressed(KeyEvent evt) + public void drawLine(Graphics g, int x1, int y1, int x2, int y2) + { + if (!wire) { - if (evt.getKeyCode() == KeyEvent.VK_UP) + if ( ( (float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) { - scale = (float) (scale * 1.1); - redrawneeded = true; - repaint(); + g.drawLine(x1, y1, x2, y2); + g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1); + g.drawLine(x1, y1 - 1, x2, y2 - 1); } - else if (evt.getKeyCode() == KeyEvent.VK_DOWN) + else { - scale = (float) (scale * 0.9); - redrawneeded = true; - repaint(); + g.setColor(g.getColor().brighter()); + g.drawLine(x1, y1, x2, y2); + g.drawLine(x1 + 1, y1, x2 + 1, y2); + g.drawLine(x1 - 1, y1, x2 - 1, y2); } } + else + { + g.drawLine(x1, y1, x2, y2); + } + } - public void mousePressed(MouseEvent e) { - pdbAction = true; - Atom fatom = findAtom(e.getX(), e.getY()); - if(fatom!=null) - { - fatom.isSelected = !fatom.isSelected; + public Dimension minimumsize() + { + return prefsize; + } - redrawneeded = true; - repaint(); - if (foundchain != -1) + public Dimension preferredsize() + { + return prefsize; + } + + public void doKeyPressed(KeyEvent evt) + { + if (evt.getKeyCode() == KeyEvent.VK_UP) + { + scale = (float) (scale * 1.1); + redrawneeded = true; + repaint(); + } + else if (evt.getKeyCode() == KeyEvent.VK_DOWN) + { + scale = (float) (scale * 0.9); + redrawneeded = true; + repaint(); + } + } + + public void mousePressed(MouseEvent e) + { + pdbAction = true; + Atom fatom = findAtom(e.getX(), e.getY()); + if (fatom != null) + { + fatom.isSelected = !fatom.isSelected; + + redrawneeded = true; + repaint(); + if (foundchain != -1) + { + PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain); + if (chain == mainchain) { - PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain); - if (chain == mainchain) + if (fatom.alignmentMapping != -1) { - if (fatom.alignmentMapping != -1) + if (highlightRes == null) { - if (highlightRes == null) - highlightRes = new Vector(); + highlightRes = new Vector(); + } - if (highlightRes.contains(fatom.alignmentMapping+"" + "")) - highlightRes.removeElement(fatom.alignmentMapping + ""); - else - highlightRes.addElement(fatom.alignmentMapping + ""); + if (highlightRes.contains(fatom.alignmentMapping + "" + "")) + { + highlightRes.removeElement(fatom.alignmentMapping + ""); + } + else + { + highlightRes.addElement(fatom.alignmentMapping + ""); } } } + } - } - mx = e.getX(); - my = e.getY(); - omx = mx; - omy = my; - dragging = false; } + mx = e.getX(); + my = e.getY(); + omx = mx; + omy = my; + dragging = false; + } + + public void mouseMoved(MouseEvent e) + { + pdbAction = true; + if (highlightBond1 != null) + { + highlightBond1.at2.isSelected = false; + highlightBond2.at1.isSelected = false; + highlightBond1 = null; + highlightBond2 = null; + } + + Atom fatom = findAtom(e.getX(), e.getY()); - public void mouseMoved(MouseEvent e) { - pdbAction = true; - if(highlightBond1!=null) + PDBChain chain = null; + if (foundchain != -1) + { + chain = (PDBChain) pdb.chains.elementAt(foundchain); + if (chain == mainchain) { - highlightBond1.at2.isSelected = false; - highlightBond2.at1.isSelected = false; - highlightBond1 = null; - highlightBond2 = null; + highlightSeqcanvas(fatom.alignmentMapping); } + } - Atom fatom = findAtom(e.getX(), e.getY()); - - PDBChain chain = null; - if(foundchain!=-1) - { - chain = (PDBChain) pdb.chains.elementAt(foundchain); - if(chain == mainchain) - { - highlightSeqcanvas( fatom.alignmentMapping ); - } - } + if (fatom != null) + { + toolx = e.getX(); + tooly = e.getY(); - if (fatom != null) { - toolx = e.getX(); - tooly = e.getY(); - - appletToolTip = chain.id+":"+ fatom.resNumber+" "+ fatom.resName; - redrawneeded = true; - repaint(); - } else { - highlightSeqcanvas( -1); - appletToolTip = null; - redrawneeded = true; - repaint(); - } + appletToolTip = chain.id + ":" + fatom.resNumber + " " + fatom.resName; + redrawneeded = true; + repaint(); } + else + { + highlightSeqcanvas( -1); + appletToolTip = null; + redrawneeded = true; + repaint(); + } + } - - void highlightSeqcanvas(int pos) + void highlightSeqcanvas(int pos) + { + SearchResults searchResults = new SearchResults(); + if (highlightRes != null) { - SearchResults searchResults = new SearchResults(); - if(highlightRes!=null) + for (int i = 0; i < highlightRes.size(); i++) { - for (int i = 0; i < highlightRes.size(); i++) - { - int a = Integer.parseInt(highlightRes.elementAt( - i).toString())+1; + int a = Integer.parseInt(highlightRes.elementAt( + i).toString()) + 1; - searchResults.addResult(sequence, a, a); - } - } - - if(pos!=-1) - { - searchResults.addResult(sequence, pos+1, pos+1); + searchResults.addResult(sequence, a, a); } + } - seqcanvas.highlightSearchResults(searchResults); + if (pos != -1) + { + searchResults.addResult(sequence, pos + 1, pos + 1); } + seqcanvas.highlightSearchResults(searchResults); + } - public void mouseClicked(MouseEvent e) { - } + public void mouseClicked(MouseEvent e) + { + } - public void mouseEntered(MouseEvent e) { - } + public void mouseEntered(MouseEvent e) + { + } - public void mouseExited(MouseEvent e) { - } + public void mouseExited(MouseEvent e) + { + } - public void mouseDragged(MouseEvent evt) { - int x = evt.getX(); - int y = evt.getY(); - mx = x; - my = y; + public void mouseDragged(MouseEvent evt) + { + int x = evt.getX(); + int y = evt.getY(); + mx = x; + my = y; - MCMatrix objmat = new MCMatrix(3, 3); - objmat.setIdentity(); + MCMatrix objmat = new MCMatrix(3, 3); + objmat.setIdentity(); - if ((evt.getModifiers() & Event.META_MASK) != 0) { - objmat.rotatez((float) ((mx - omx))); - } else { - objmat.rotatex((float) ((my - omy))); - objmat.rotatey((float) ((omx - mx))); - } + if ( (evt.getModifiers() & Event.META_MASK) != 0) + { + objmat.rotatez( (float) ( (mx - omx))); + } + else + { + objmat.rotatex( (float) ( (my - omy))); + objmat.rotatey( (float) ( (omx - mx))); + } - //Alter the bonds - for (int ii = 0; ii < pdb.chains.size(); ii++) { - Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + //Alter the bonds + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - for (int i = 0; i < bonds.size(); i++) { - Bond tmpBond = (Bond) bonds.elementAt(i); + 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 - tmpBond.start = objmat.vectorMultiply(tmpBond.start); - tmpBond.end = objmat.vectorMultiply(tmpBond.end); + //Now apply the rotation matrix + tmpBond.start = objmat.vectorMultiply(tmpBond.start); + tmpBond.end = objmat.vectorMultiply(tmpBond.end); - //Now translate back again - tmpBond.translate(centre[0], centre[1], centre[2]); - } - } + //Now translate back again + tmpBond.translate(centre[0], centre[1], centre[2]); + } + } - objmat = null; + objmat = null; - omx = mx; - omy = my; + omx = mx; + omy = my; - dragging = true; + dragging = true; - redrawneeded = true; + redrawneeded = true; - repaint(); - } + repaint(); + } - public void mouseReleased(MouseEvent evt) { - dragging = false; - return; - } + public void mouseReleased(MouseEvent evt) + { + dragging = false; + return; + } - void drawLabels(Graphics g) { + void drawLabels(Graphics g) + { - for (int ii = 0; ii < pdb.chains.size(); ii++) - { - PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); - if (chain.isVisible) - { - Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + if (chain.isVisible) + { + Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - for (int i = 0; i < bonds.size(); i++) - { - Bond tmpBond = (Bond) bonds.elementAt(i); + for (int i = 0; i < bonds.size(); i++) + { + Bond tmpBond = (Bond) bonds.elementAt(i); - if (tmpBond.at1.isSelected) - { - labelAtom(g, tmpBond, 1); - } + if (tmpBond.at1.isSelected) + { + labelAtom(g, tmpBond, 1); + } - if (tmpBond.at2.isSelected) - { + if (tmpBond.at2.isSelected) + { - labelAtom(g, tmpBond, 2); - } - } - } + labelAtom(g, tmpBond, 2); + } } + } } + } - public void labelAtom(Graphics g, Bond b, int n) { - g.setFont(font); + public void labelAtom(Graphics g, Bond b, int n) + { + g.setFont(font); - 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)); + 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)); - g.setColor(Color.red); - g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart); - } + g.setColor(Color.red); + g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart); + } - 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)); + 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)); - g.setColor(Color.red); - g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart); - } + g.setColor(Color.red); + g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart); } + } - int foundchain = -1; - public Atom findAtom(int x, int y) { - Atom fatom = null; + int foundchain = -1; + public Atom findAtom(int x, int y) + { + Atom fatom = null; - foundchain = -1; + foundchain = -1; - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); + int truex; + Bond tmpBond = null; + + if (chain.isVisible) + { + Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; + + for (int i = 0; i < bonds.size(); i++) { - PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); - int truex; - Bond tmpBond=null; + tmpBond = (Bond) bonds.elementAt(i); - if (chain.isVisible) - { - 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)); - - if (Math.abs(truex - x) <= 2) - { - int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) + - (getSize().height / 2)); - - if (Math.abs(truey - y) <= 2) - { - fatom = tmpBond.at1; - foundchain = ii; - break; - } - } - } - - // Still here? Maybe its the last bond - - 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)); - - if (Math.abs(truey - y) <= 2) - { - fatom = tmpBond.at2; - foundchain = ii; - break; - } - } + 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)); - if (fatom != null) //)&& chain.ds != null) - { - chain = (PDBChain) pdb.chains.elementAt(foundchain); + if (Math.abs(truey - y) <= 2) + { + fatom = tmpBond.at1; + foundchain = ii; + break; } + } } - return fatom; - } + // Still here? Maybe its the last bond - public void update(Graphics g) - { - paint(g); + 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)); + + if (Math.abs(truey - y) <= 2) + { + fatom = tmpBond.at2; + foundchain = ii; + break; + } + } + + } + + if (fatom != null) //)&& chain.ds != null) + { + chain = (PDBChain) pdb.chains.elementAt(foundchain); + } } - public void highlightRes(int ii) - { - if(!seqColoursReady) - return; + return fatom; + } - if (highlightRes != null - && highlightRes.contains((ii-1) + "")) - { - return; - } + public void update(Graphics g) + { + paint(g); + } - int index = -1; - Bond tmpBond; - for(index=0; index 0) - { - highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1); - highlightBond1.at2.isSelected = true; - } + if (highlightBond2 != null) + { + highlightBond2.at1.isSelected = false; + } - if (index != mainchain.bonds.size()) - { - highlightBond2 = (Bond) mainchain.bonds.elementAt(index); - highlightBond2.at1.isSelected = true; - } + highlightBond1 = null; + highlightBond2 = null; - break; - } - } + 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; + } - redrawneeded = true; - repaint(); - } + break; + } + } + redrawneeded = true; + repaint(); + } - public void setAllchainsVisible(boolean b) + public void setAllchainsVisible(boolean b) + { + for (int ii = 0; ii < pdb.chains.size(); ii++) { - for (int ii = 0; ii < pdb.chains.size(); ii++) - { - PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); - chain.isVisible = b; - } - mainchain.isVisible = true; - findCentre(); - setupBonds(); + PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); + chain.isVisible = b; } + mainchain.isVisible = true; + findCentre(); + setupBonds(); + } } diff --git a/src/MCview/AppletPDBViewer.java b/src/MCview/AppletPDBViewer.java index ce2083a..907a6fe 100755 --- a/src/MCview/AppletPDBViewer.java +++ b/src/MCview/AppletPDBViewer.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * 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 @@ -19,126 +19,161 @@ package MCview; import java.awt.*; - import java.awt.event.*; -import jalview.datamodel.*; + import jalview.appletgui.*; +import jalview.datamodel.*; import jalview.schemes.*; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; - -public class AppletPDBViewer extends Frame implements ActionListener, ItemListener +public class AppletPDBViewer + extends Frame implements ActionListener, ItemListener { - AppletPDBCanvas pdbcanvas; - public AppletPDBViewer(String pdbtext,String type, - Sequence seq, - SeqCanvas seqcanvas) - { + AppletPDBCanvas pdbcanvas; + public AppletPDBViewer(String pdbtext, String type, + Sequence seq, + SeqCanvas seqcanvas) + { - try - { - jbInit(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } + try + { + jbInit(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } - pdbcanvas = new AppletPDBCanvas(seqcanvas, seq); + pdbcanvas = new AppletPDBCanvas(seqcanvas, seq); - add(pdbcanvas, BorderLayout.CENTER); + add(pdbcanvas, BorderLayout.CENTER); - StringBuffer title = new StringBuffer(seq.getName() + ":"); + StringBuffer title = new StringBuffer(seq.getName() + ":"); - jalview.bin.JalviewLite.addFrame(this,title.toString(),400, 400); + jalview.bin.JalviewLite.addFrame(this, title.toString(), 400, 400); - try{ - PDBfile pdbfile = new PDBfile(pdbtext, type); - pdbcanvas.setPDBFile(pdbfile); - } - catch(Exception ex){ - ex.printStackTrace(); - pdbcanvas.errorLoading = true; - pdbcanvas.repaint(); - } - } - - public void actionPerformed(ActionEvent evt) - { - if(evt.getSource()==mapping) - mapping_actionPerformed(); - else if(evt.getSource()==wire) - wire_actionPerformed(); - else if(evt.getSource()==depth) - depth_actionPerformed(); - else if(evt.getSource()==zbuffer) - zbuffer_actionPerformed(); - else if(evt.getSource()==charge) - charge_actionPerformed(); + try + { + PDBfile pdbfile = new PDBfile(pdbtext, type); + pdbcanvas.setPDBFile(pdbfile); + } + catch (Exception ex) + { + ex.printStackTrace(); + pdbcanvas.errorLoading = true; + pdbcanvas.repaint(); + } + } - else if(evt.getSource()==chain) - chain_actionPerformed(); - else if(evt.getSource()==seqButton) - seqButton_actionPerformed(); - else if(evt.getSource()==zappo) - pdbcanvas.setColours(new ZappoColourScheme()); - else if(evt.getSource()==taylor) - pdbcanvas.setColours(new TaylorColourScheme()); - else if(evt.getSource()==hydro) - pdbcanvas.setColours(new HydrophobicColourScheme()); - else if(evt.getSource()==helix) - pdbcanvas.setColours(new HelixColourScheme()); - else if(evt.getSource()==strand) - pdbcanvas.setColours(new StrandColourScheme()); - else if(evt.getSource()==turn) - pdbcanvas.setColours(new TurnColourScheme()); - else if(evt.getSource()==buried) - pdbcanvas.setColours(new BuriedColourScheme()); - else if(evt.getSource()==user) - { - pdbcanvas.bysequence = false; - new jalview.appletgui.UserDefinedColours(pdbcanvas); - } - } + public void actionPerformed(ActionEvent evt) + { + if (evt.getSource() == mapping) + { + mapping_actionPerformed(); + } + else if (evt.getSource() == wire) + { + wire_actionPerformed(); + } + else if (evt.getSource() == depth) + { + depth_actionPerformed(); + } + else if (evt.getSource() == zbuffer) + { + zbuffer_actionPerformed(); + } + else if (evt.getSource() == charge) + { + charge_actionPerformed(); + } - public void itemStateChanged(ItemEvent evt) - { - if (evt.getSource() == allchains) - allchains_itemStateChanged(); - else if (evt.getSource() == wire) - wire_actionPerformed(); - else if (evt.getSource() == depth) - depth_actionPerformed(); - else if (evt.getSource() == zbuffer) - zbuffer_actionPerformed(); - } + else if (evt.getSource() == chain) + { + chain_actionPerformed(); + } + else if (evt.getSource() == seqButton) + { + seqButton_actionPerformed(); + } + else if (evt.getSource() == zappo) + { + pdbcanvas.setColours(new ZappoColourScheme()); + } + else if (evt.getSource() == taylor) + { + pdbcanvas.setColours(new TaylorColourScheme()); + } + else if (evt.getSource() == hydro) + { + pdbcanvas.setColours(new HydrophobicColourScheme()); + } + else if (evt.getSource() == helix) + { + pdbcanvas.setColours(new HelixColourScheme()); + } + else if (evt.getSource() == strand) + { + pdbcanvas.setColours(new StrandColourScheme()); + } + else if (evt.getSource() == turn) + { + pdbcanvas.setColours(new TurnColourScheme()); + } + else if (evt.getSource() == buried) + { + pdbcanvas.setColours(new BuriedColourScheme()); + } + else if (evt.getSource() == user) + { + pdbcanvas.bysequence = false; + new jalview.appletgui.UserDefinedColours(pdbcanvas); + } + } + public void itemStateChanged(ItemEvent evt) + { + if (evt.getSource() == allchains) + { + allchains_itemStateChanged(); + } + else if (evt.getSource() == wire) + { + wire_actionPerformed(); + } + else if (evt.getSource() == depth) + { + depth_actionPerformed(); + } + else if (evt.getSource() == zbuffer) + { + zbuffer_actionPerformed(); + } + } - private void jbInit() - throws Exception - { - setMenuBar(jMenuBar1); - fileMenu.setLabel("File"); - coloursMenu.setLabel("Colours"); - mapping.setLabel("View Mapping"); - mapping.addActionListener(this); - wire.setLabel("Wireframe"); - wire.addItemListener(this); - depth.setState(true); - depth.setLabel("Depthcue"); - depth.addItemListener(this); - zbuffer.setState(true); - zbuffer.setLabel("Z Buffering"); - zbuffer.addItemListener(this); - charge.setLabel("Charge & Cysteine"); - charge.addActionListener(this); - hydro.setLabel("Hydrophobicity"); - hydro.addActionListener(this); - chain.setLabel("By Chain"); - chain.addActionListener(this); - seqButton.setLabel("By Sequence"); - seqButton.addActionListener(this); + private void jbInit() + throws Exception + { + setMenuBar(jMenuBar1); + fileMenu.setLabel("File"); + coloursMenu.setLabel("Colours"); + mapping.setLabel("View Mapping"); + mapping.addActionListener(this); + wire.setLabel("Wireframe"); + wire.addItemListener(this); + depth.setState(true); + depth.setLabel("Depthcue"); + depth.addItemListener(this); + zbuffer.setState(true); + zbuffer.setLabel("Z Buffering"); + zbuffer.addItemListener(this); + charge.setLabel("Charge & Cysteine"); + charge.addActionListener(this); + hydro.setLabel("Hydrophobicity"); + hydro.addActionListener(this); + chain.setLabel("By Chain"); + chain.addActionListener(this); + seqButton.setLabel("By Sequence"); + seqButton.addActionListener(this); allchains.setLabel("All Chains Visible"); allchains.addItemListener(this); viewMenu.setLabel("View"); @@ -157,12 +192,12 @@ public class AppletPDBViewer extends Frame implements ActionListener, ItemListen user.setLabel("User Defined..."); user.addActionListener(this); jMenuBar1.add(fileMenu); - jMenuBar1.add(coloursMenu); + jMenuBar1.add(coloursMenu); jMenuBar1.add(viewMenu); - fileMenu.add(mapping);; + fileMenu.add(mapping); ; - coloursMenu.add(seqButton); - coloursMenu.add(chain); + coloursMenu.add(seqButton); + coloursMenu.add(chain); coloursMenu.add(charge); coloursMenu.add(zappo); coloursMenu.add(taylor); @@ -179,21 +214,21 @@ public class AppletPDBViewer extends Frame implements ActionListener, ItemListen allchains.setState(true); } - MenuBar jMenuBar1 = new MenuBar(); - Menu fileMenu = new Menu(); - Menu coloursMenu = new Menu(); - MenuItem mapping = new MenuItem(); - CheckboxGroup bg = new CheckboxGroup(); - CheckboxMenuItem wire = new CheckboxMenuItem(); - CheckboxMenuItem depth = new CheckboxMenuItem(); - CheckboxMenuItem zbuffer = new CheckboxMenuItem(); + MenuBar jMenuBar1 = new MenuBar(); + Menu fileMenu = new Menu(); + Menu coloursMenu = new Menu(); + MenuItem mapping = new MenuItem(); + CheckboxGroup bg = new CheckboxGroup(); + CheckboxMenuItem wire = new CheckboxMenuItem(); + CheckboxMenuItem depth = new CheckboxMenuItem(); + CheckboxMenuItem zbuffer = new CheckboxMenuItem(); - MenuItem charge = new MenuItem(); - MenuItem hydro = new MenuItem(); - MenuItem chain = new MenuItem(); - MenuItem seqButton = new MenuItem(); + MenuItem charge = new MenuItem(); + MenuItem hydro = new MenuItem(); + MenuItem chain = new MenuItem(); + MenuItem seqButton = new MenuItem(); - CheckboxMenuItem allchains = new CheckboxMenuItem(); + CheckboxMenuItem allchains = new CheckboxMenuItem(); Menu viewMenu = new Menu(); MenuItem turn = new MenuItem(); MenuItem strand = new MenuItem(); @@ -204,63 +239,62 @@ public class AppletPDBViewer extends Frame implements ActionListener, ItemListen MenuItem user = new MenuItem(); public void charge_actionPerformed() - { - pdbcanvas.bysequence = false; - pdbcanvas.pdb.setChargeColours(); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void chain_actionPerformed() - { - pdbcanvas.bysequence = false; - pdbcanvas.pdb.setChainColours(); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setChargeColours(); + pdbcanvas.redrawneeded = true; + pdbcanvas.repaint(); + } - public void zbuffer_actionPerformed() - { - pdbcanvas.zbuffer = ! pdbcanvas.zbuffer; - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } + public void chain_actionPerformed() + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setChainColours(); + pdbcanvas.redrawneeded = true; + pdbcanvas.repaint(); + } - public void depth_actionPerformed() - { - pdbcanvas.depthcue = ! pdbcanvas.depthcue; - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } + public void zbuffer_actionPerformed() + { + pdbcanvas.zbuffer = !pdbcanvas.zbuffer; + pdbcanvas.redrawneeded = true; + pdbcanvas.repaint(); + } - public void wire_actionPerformed() - { - pdbcanvas.wire = ! pdbcanvas.wire; - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } + public void depth_actionPerformed() + { + pdbcanvas.depthcue = !pdbcanvas.depthcue; + pdbcanvas.redrawneeded = true; + pdbcanvas.repaint(); + } - public void seqButton_actionPerformed() - { - pdbcanvas.bysequence = true; - pdbcanvas.updateSeqColours(); - pdbcanvas.repaint(); - } + public void wire_actionPerformed() + { + pdbcanvas.wire = !pdbcanvas.wire; + pdbcanvas.redrawneeded = true; + pdbcanvas.repaint(); + } + public void seqButton_actionPerformed() + { + pdbcanvas.bysequence = true; + pdbcanvas.updateSeqColours(); + pdbcanvas.repaint(); + } - public void mapping_actionPerformed() - { - jalview.appletgui.CutAndPasteTransfer cap - = new jalview.appletgui.CutAndPasteTransfer(false, null); - Frame frame = new Frame(); - frame.add(cap); - jalview.bin.JalviewLite.addFrame(frame, "PDB - Sequence Mapping", 500, 600); - cap.setText(pdbcanvas.mappingDetails.toString()); - } + public void mapping_actionPerformed() + { + jalview.appletgui.CutAndPasteTransfer cap + = new jalview.appletgui.CutAndPasteTransfer(false, null); + Frame frame = new Frame(); + frame.add(cap); + jalview.bin.JalviewLite.addFrame(frame, "PDB - Sequence Mapping", 500, 600); + cap.setText(pdbcanvas.mappingDetails.toString()); + } - public void allchains_itemStateChanged() - { - pdbcanvas.setAllchainsVisible(allchains.getState()); - } + public void allchains_itemStateChanged() + { + pdbcanvas.setAllchainsVisible(allchains.getState()); + } } diff --git a/src/MCview/Atom.java b/src/MCview/Atom.java index 54e0dc8..c15455e 100755 --- a/src/MCview/Atom.java +++ b/src/MCview/Atom.java @@ -1,64 +1,66 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 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 + * 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 + */ package MCview; import java.awt.*; +public class Atom +{ + public float x; + public float y; + public float z; + public int number; + public String name; + public String resName; + public int resNumber; + public char insCode = ' '; + public String resNumIns = null; + public int type; + Color color = Color.lightGray; + public String chain; + int alignmentMapping = -1; -public class Atom { - public float x; - public float y; - public float z; - public int number; - public String name; - public String resName; - public int resNumber; - public char insCode=' '; - public String resNumIns=null; - public int type; - Color color = Color.lightGray; - public String chain; - int alignmentMapping=-1; + public boolean isSelected = false; - public boolean isSelected = false; + public Atom(String str) + { + name = str.substring(12, 15).trim(); - public Atom(String str) - { - name = str.substring(12,15).trim(); + resName = str.substring(17, 20); - resName = str.substring(17,20); + chain = str.substring(21, 22); - chain = str.substring(21,22); + resNumber = Integer.parseInt(str.substring(22, 26).trim()); + resNumIns = str.substring(22, 27); + insCode = str.substring(26, 27).charAt(0); + this.x = (float) (new Float(str.substring(30, 38).trim()).floatValue()); + this.y = (float) (new Float(str.substring(38, 46).trim()).floatValue()); + this.z = (float) (new Float(str.substring(47, 55).trim()).floatValue()); - resNumber = Integer.parseInt(str.substring(22,26).trim()); - resNumIns=str.substring(22,27); - insCode = str.substring(26,27).charAt(0); - this.x = (float) (new Float(str.substring(30,38).trim()).floatValue()); - this.y = (float) (new Float(str.substring(38,46).trim()).floatValue()); - this.z = (float) (new Float(str.substring(47,55).trim()).floatValue()); + } - } - public Atom(float x,float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } + public Atom(float x, float y, float z) + { + this.x = x; + this.y = y; + this.z = z; + } // public void setColor(Color col) { // this.color = col; // } diff --git a/src/MCview/Bond.java b/src/MCview/Bond.java index fd36446..8e95c1b 100755 --- a/src/MCview/Bond.java +++ b/src/MCview/Bond.java @@ -1,42 +1,43 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 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 + * 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 + */ package MCview; import java.awt.*; +public class Bond +{ + float[] start; + float[] end; + Color startCol = Color.lightGray; + Color endCol = Color.lightGray; + public Atom at1; + public Atom at2; -public class Bond { - float[] start; - float[] end; - Color startCol = Color.lightGray; - Color endCol= Color.lightGray; - public Atom at1; - public Atom at2; - - public Bond(float[] start, float[] end, Atom at1, Atom at2) { - this.start = start; - this.end = end; - this.startCol = at1.color; - this.endCol = at2.color; - this.at1 = at1; - this.at2 = at2; - } + public Bond(float[] start, float[] end, Atom at1, Atom at2) + { + this.start = start; + this.end = end; + this.startCol = at1.color; + this.endCol = at2.color; + this.at1 = at1; + this.at2 = at2; + } /* public Bond(Bond bond) { this.start = new float[3]; @@ -65,14 +66,15 @@ public class Bond { return len; }*/ - public void translate(float x, float y, float z) { - start[0] = (start[0] + x); - end[0] = (end[0] + x); + public void translate(float x, float y, float z) + { + start[0] = (start[0] + x); + end[0] = (end[0] + x); - start[1] = (start[1] + y); - end[1] = (end[1] + y); + start[1] = (start[1] + y); + end[1] = (end[1] + y); - start[2] = (start[2] + z); - end[2] = (end[2] + z); - } + start[2] = (start[2] + z); + end[2] = (end[2] + z); + } } diff --git a/src/MCview/MCMatrix.java b/src/MCview/MCMatrix.java index 1dbec22..9eba886 100755 --- a/src/MCview/MCMatrix.java +++ b/src/MCview/MCMatrix.java @@ -1,152 +1,171 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 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 + * 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 + */ package MCview; -public class MCMatrix { - float[][] matrix; - float[][] tmp; - float mycos; - float mysin; - float myconst = (float) (Math.PI / 180); - - public MCMatrix(int rows, int cols) { - matrix = new float[rows][cols]; - tmp = new float[rows][cols]; +public class MCMatrix +{ + float[][] matrix; + float[][] tmp; + float mycos; + float mysin; + float myconst = (float) (Math.PI / 180); + + public MCMatrix(int rows, int cols) + { + matrix = new float[rows][cols]; + tmp = new float[rows][cols]; + } + + public void addElement(int i, int j, float value) + { + matrix[i][j] = value; + } + + public void rotatex(float degrees) + { + mycos = (float) (Math.cos(degrees * myconst)); + mysin = (float) (Math.sin(degrees * myconst)); + + tmp[0][0] = 1; + tmp[0][1] = 0; + tmp[0][2] = 0; + tmp[1][0] = 0; + tmp[1][1] = mycos; + tmp[1][2] = mysin; + tmp[2][0] = 0; + tmp[2][1] = -mysin; + tmp[2][2] = mycos; + preMultiply(tmp); + } + + public void rotatez(float degrees) + { + mycos = (float) (Math.cos(degrees * myconst)); + mysin = (float) (Math.sin(degrees * myconst)); + + tmp[0][0] = mycos; + tmp[0][1] = -mysin; + tmp[0][2] = 0; + tmp[1][0] = mysin; + tmp[1][1] = mycos; + tmp[1][2] = 0; + tmp[2][0] = 0; + tmp[2][1] = 0; + tmp[2][2] = 1; + + preMultiply(tmp); + } + + public void rotatey(float degrees) + { + mycos = (float) (Math.cos(degrees * myconst)); + mysin = (float) (Math.sin(degrees * myconst)); + + tmp[0][0] = mycos; + tmp[0][1] = 0; + tmp[0][2] = -mysin; + tmp[1][0] = 0; + tmp[1][1] = 1; + tmp[1][2] = 0; + tmp[2][0] = mysin; + tmp[2][1] = 0; + tmp[2][2] = mycos; + + preMultiply(tmp); + } + + public float[] vectorMultiply(float[] vect) + { + float[] temp = new float[3]; + + temp[0] = vect[0]; + temp[1] = vect[1]; + temp[2] = vect[2]; + + for (int i = 0; i < 3; i++) + { + temp[i] = ( (float) matrix[i][0] * vect[0]) + + ( (float) matrix[i][1] * vect[1]) + + ( (float) matrix[i][2] * vect[2]); } - public void addElement(int i, int j, float value) { - matrix[i][j] = value; - } + vect[0] = temp[0]; + vect[1] = temp[1]; + vect[2] = temp[2]; - public void rotatex(float degrees) { - mycos = (float) (Math.cos(degrees * myconst)); - mysin = (float) (Math.sin(degrees * myconst)); - - tmp[0][0] = 1; - tmp[0][1] = 0; - tmp[0][2] = 0; - tmp[1][0] = 0; - tmp[1][1] = mycos; - tmp[1][2] = mysin; - tmp[2][0] = 0; - tmp[2][1] = -mysin; - tmp[2][2] = mycos; - preMultiply(tmp); - } + return vect; + } - public void rotatez(float degrees) { - mycos = (float) (Math.cos(degrees * myconst)); - mysin = (float) (Math.sin(degrees * myconst)); - - tmp[0][0] = mycos; - tmp[0][1] = -mysin; - tmp[0][2] = 0; - tmp[1][0] = mysin; - tmp[1][1] = mycos; - tmp[1][2] = 0; - tmp[2][0] = 0; - tmp[2][1] = 0; - tmp[2][2] = 1; - - preMultiply(tmp); - } + public void preMultiply(float[][] mat) + { + float[][] tmp = new float[3][3]; - public void rotatey(float degrees) { - mycos = (float) (Math.cos(degrees * myconst)); - mysin = (float) (Math.sin(degrees * myconst)); - - tmp[0][0] = mycos; - tmp[0][1] = 0; - tmp[0][2] = -mysin; - tmp[1][0] = 0; - tmp[1][1] = 1; - tmp[1][2] = 0; - tmp[2][0] = mysin; - tmp[2][1] = 0; - tmp[2][2] = mycos; - - preMultiply(tmp); + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + tmp[i][j] = (mat[i][0] * matrix[0][j]) + + (mat[i][1] * matrix[1][j]) + (mat[i][2] * matrix[2][j]); + } } - public float[] vectorMultiply(float[] vect) { - float[] temp = new float[3]; - - temp[0] = vect[0]; - temp[1] = vect[1]; - temp[2] = vect[2]; - - for (int i = 0; i < 3; i++) { - temp[i] = ((float) matrix[i][0] * vect[0]) + - ((float) matrix[i][1] * vect[1]) + - ((float) matrix[i][2] * vect[2]); - } - - vect[0] = temp[0]; - vect[1] = temp[1]; - vect[2] = temp[2]; - - return vect; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + matrix[i][j] = tmp[i][j]; + } } - - public void preMultiply(float[][] mat) { - float[][] tmp = new float[3][3]; - - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - tmp[i][j] = (mat[i][0] * matrix[0][j]) + - (mat[i][1] * matrix[1][j]) + (mat[i][2] * matrix[2][j]); - } - } - - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - matrix[i][j] = tmp[i][j]; - } - } - } - - public void postMultiply(float[][] mat) { - float[][] tmp = new float[3][3]; - - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - tmp[i][j] = (matrix[i][0] * mat[0][j]) + - (matrix[i][1] * mat[1][j]) + (matrix[i][2] * mat[2][j]); - } - } - - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - matrix[i][j] = tmp[i][j]; - } - } + } + + public void postMultiply(float[][] mat) + { + float[][] tmp = new float[3][3]; + + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + tmp[i][j] = (matrix[i][0] * mat[0][j]) + + (matrix[i][1] * mat[1][j]) + (matrix[i][2] * mat[2][j]); + } } - public void setIdentity() { - matrix[0][0] = 1; - matrix[1][1] = 1; - matrix[2][2] = 1; - matrix[0][1] = 0; - matrix[0][2] = 0; - matrix[1][0] = 0; - matrix[1][2] = 0; - matrix[2][0] = 0; - matrix[2][1] = 0; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + matrix[i][j] = tmp[i][j]; + } } + } + + public void setIdentity() + { + matrix[0][0] = 1; + matrix[1][1] = 1; + matrix[2][2] = 1; + matrix[0][1] = 0; + matrix[0][2] = 0; + matrix[1][0] = 0; + matrix[1][2] = 0; + matrix[2][0] = 0; + matrix[2][1] = 0; + } } diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java index ee556a3..18afbb9 100755 --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -1,983 +1,1059 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 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 + * 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 + */ package MCview; -import jalview.analysis.AlignSeq; - -import jalview.datamodel.*; +import java.io.*; +import java.util.*; // JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug import java.awt.*; import java.awt.event.*; - -import java.io.*; - -import java.util.*; - import javax.swing.*; +import jalview.analysis.*; +import jalview.datamodel.*; -public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListener +public class PDBCanvas + extends JPanel implements MouseListener, MouseMotionListener { - 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; - 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; - 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) - { - this.seqcanvas = seqcanvas; - this.sequence = seq; - seqcanvas.setPDBCanvas(this); - } + 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; + 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; + 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) + { + this.seqcanvas = seqcanvas; + this.sequence = seq; + seqcanvas.setPDBCanvas(this); + } public void setPDBFile(PDBfile pdb) - { - int max = -10; - int maxchain = -1; - int pdbstart = 0; - int pdbend = 0; - int seqstart = 0; - int seqend = 0; - AlignSeq maxAlignseq = null; - - 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"); + { + int max = -10; + int maxchain = -1; + int pdbstart = 0; + int pdbend = 0; + int seqstart = 0; + int seqend = 0; + AlignSeq maxAlignseq = null; + + for (int i = 0; i < pdb.chains.size(); i++) + { - // 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); - as.calcScoreMatrix(); - as.traceAlignment(); - PrintStream ps = new PrintStream(System.out) - { - public void print(String x) { - mappingDetails.append(x); - } - public void println() - { - mappingDetails.append("\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); + as.calcScoreMatrix(); + as.traceAlignment(); + PrintStream ps = new PrintStream(System.out) + { + public void print(String x) + { + mappingDetails.append(x); + } - as.printAlignment(ps); + public void println() + { + mappingDetails.append("\n"); + } + }; + as.printAlignment(ps); + if (as.maxscore > max) + { + 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; + } - if (as.maxscore > max) - { - 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); + mappingDetails.append("\nSEQ start/end " + seqstart + " " + seqend); + } - mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend); - mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend); + mainchain = (PDBChain) pdb.chains.elementAt(maxchain); + + mainchain.pdbstart = pdbstart; + mainchain.pdbend = pdbend; + 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); } - - mainchain = (PDBChain) pdb.chains.elementAt(maxchain); - - mainchain.pdbstart = pdbstart; - mainchain.pdbend = pdbend; - 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); - } - } + else + { + idmat.addElement(i, j, 1); + objmat.addElement(i, j, 1); } + } + } - addMouseMotionListener(this); - addMouseListener(this); + addMouseMotionListener(this); + addMouseListener(this); - addMouseWheelListener(new MouseWheelListener() + addMouseWheelListener(new MouseWheelListener() + { + public void mouseWheelMoved(MouseWheelEvent e) + { + if (e.getWheelRotation() > 0) { - public void mouseWheelMoved(MouseWheelEvent e) - { - if (e.getWheelRotation() > 0) - { - scale = (float) (scale * 1.1); - redrawneeded = true; - repaint(); - } - - else - { - scale = (float) (scale * 0.9); - redrawneeded = true; - repaint(); - } - } - }); + scale = (float) (scale * 1.1); + redrawneeded = true; + repaint(); + } + else + { + scale = (float) (scale * 0.9); + redrawneeded = true; + repaint(); + } + } + }); - findCentre(); - findWidth(); + findCentre(); + findWidth(); - setupBonds(); + setupBonds(); - scale = findScale(); + scale = findScale(); - ToolTipManager.sharedInstance().registerComponent(this); - ToolTipManager.sharedInstance().setInitialDelay(0); - ToolTipManager.sharedInstance().setDismissDelay(10000); - } + ToolTipManager.sharedInstance().registerComponent(this); + ToolTipManager.sharedInstance().setInitialDelay(0); + ToolTipManager.sharedInstance().setDismissDelay(10000); + } + Vector visiblebonds; + void setupBonds() + { + seqColoursReady = false; + // Sort the bonds by z coord + visiblebonds = new Vector(); - Vector visiblebonds; - void setupBonds() + for (int ii = 0; ii < pdb.chains.size(); ii++) { - seqColoursReady = false; - // Sort the bonds by z coord - visiblebonds = new Vector(); - - 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++) - { - visiblebonds.addElement(tmp.elementAt(i)); - } + for (int i = 0; i < tmp.size(); i++) + { + visiblebonds.addElement(tmp.elementAt(i)); } } - - updateSeqColours(); - seqColoursReady = true; - redrawneeded = true; - repaint(); } + updateSeqColours(); + seqColoursReady = true; + redrawneeded = true; + repaint(); + } - public void findWidth() { - float[] max = new float[3]; - float[] min = new float[3]; + public void findWidth() + { + 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; - min[2] = (float) 1e30; + min[0] = (float) 1e30; + min[1] = (float) 1e30; + min[2] = (float) 1e30; - for (int ii = 0; ii < pdb.chains.size(); ii++) { - if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) { - Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + { + Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - for (int i = 0; i < bonds.size(); i++) { - Bond tmp = (Bond) bonds.elementAt(i); + for (int i = 0; i < bonds.size(); i++) + { + Bond tmp = (Bond) bonds.elementAt(i); - if (tmp.start[0] >= max[0]) { - max[0] = tmp.start[0]; - } + if (tmp.start[0] >= max[0]) + { + max[0] = tmp.start[0]; + } - if (tmp.start[1] >= max[1]) { - max[1] = tmp.start[1]; - } + if (tmp.start[1] >= max[1]) + { + max[1] = tmp.start[1]; + } - if (tmp.start[2] >= max[2]) { - max[2] = tmp.start[2]; - } + if (tmp.start[2] >= max[2]) + { + max[2] = tmp.start[2]; + } - if (tmp.start[0] <= min[0]) { - min[0] = tmp.start[0]; - } + if (tmp.start[0] <= min[0]) + { + min[0] = tmp.start[0]; + } - if (tmp.start[1] <= min[1]) { - min[1] = tmp.start[1]; - } + if (tmp.start[1] <= min[1]) + { + min[1] = tmp.start[1]; + } - if (tmp.start[2] <= min[2]) { - min[2] = tmp.start[2]; - } + if (tmp.start[2] <= min[2]) + { + min[2] = tmp.start[2]; + } - if (tmp.end[0] >= max[0]) { - max[0] = tmp.end[0]; - } + if (tmp.end[0] >= max[0]) + { + max[0] = tmp.end[0]; + } - if (tmp.end[1] >= max[1]) { - max[1] = tmp.end[1]; - } + if (tmp.end[1] >= max[1]) + { + max[1] = tmp.end[1]; + } - if (tmp.end[2] >= max[2]) { - max[2] = tmp.end[2]; - } + if (tmp.end[2] >= max[2]) + { + max[2] = tmp.end[2]; + } - if (tmp.end[0] <= min[0]) { - min[0] = tmp.end[0]; - } + if (tmp.end[0] <= min[0]) + { + min[0] = tmp.end[0]; + } - if (tmp.end[1] <= min[1]) { - min[1] = tmp.end[1]; - } + if (tmp.end[1] <= min[1]) + { + min[1] = tmp.end[1]; + } - if (tmp.end[2] <= min[2]) { - min[2] = tmp.end[2]; - } - } - } + if (tmp.end[2] <= min[2]) + { + min[2] = tmp.end[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]); - width[2] = (float) Math.abs(max[2] - 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]);*/ - maxwidth = width[0]; + width[0] = (float) Math.abs(max[0] - min[0]); + width[1] = (float) Math.abs(max[1] - min[1]); + width[2] = (float) Math.abs(max[2] - min[2]); - if (width[1] > width[0]) { - maxwidth = width[1]; - } + maxwidth = width[0]; - if (width[2] > width[1]) { - maxwidth = width[2]; - } + if (width[1] > width[0]) + { + maxwidth = width[1]; + } - // System.out.println("Maxwidth = " + maxwidth); + if (width[2] > width[1]) + { + maxwidth = width[2]; } - public float findScale() { - int dim; - int width; - int height; + // System.out.println("Maxwidth = " + maxwidth); + } - if (getWidth() != 0) { - width = getWidth(); - height = getHeight(); - } else { - width = prefsize.width; - height = prefsize.height; - } + public float findScale() + { + int dim; + int width; + int height; - if (width < height) { - dim = width; - } else { - dim = height; - } + if (getWidth() != 0) + { + width = getWidth(); + height = getHeight(); + } + else + { + width = prefsize.width; + height = prefsize.height; + } - return (float) (dim / (1.5d * maxwidth)); + if (width < height) + { + dim = width; + } + else + { + dim = height; } - public void findCentre() { - float xtot = 0; - float ytot = 0; - float ztot = 0; + return (float) (dim / (1.5d * maxwidth)); + } - int bsize = 0; + public void findCentre() + { + float xtot = 0; + float ytot = 0; + float ztot = 0; - //Find centre coordinate - for (int ii = 0; ii < pdb.chains.size(); ii++) { - if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) { - Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + int bsize = 0; - bsize += bonds.size(); + //Find centre coordinate + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + { + Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - for (int i = 0; i < bonds.size(); i++) { - xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] + - ((Bond) bonds.elementAt(i)).end[0]; + bsize += bonds.size(); - ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] + - ((Bond) bonds.elementAt(i)).end[1]; + for (int i = 0; i < bonds.size(); i++) + { + xtot = xtot + ( (Bond) bonds.elementAt(i)).start[0] + + ( (Bond) bonds.elementAt(i)).end[0]; - ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] + - ((Bond) bonds.elementAt(i)).end[2]; - } - } - } + ytot = ytot + ( (Bond) bonds.elementAt(i)).start[1] + + ( (Bond) bonds.elementAt(i)).end[1]; - centre[0] = xtot / (2 * (float) bsize); - centre[1] = ytot / (2 * (float) bsize); - centre[2] = ztot / (2 * (float) bsize); + ztot = ztot + ( (Bond) bonds.elementAt(i)).start[2] + + ( (Bond) bonds.elementAt(i)).end[2]; + } + } } - public void paintComponent(Graphics g) - { - super.paintComponent(g); + centre[0] = xtot / (2 * (float) bsize); + centre[1] = ytot / (2 * (float) bsize); + centre[2] = ztot / (2 * (float) bsize); + } - if(!seqColoursReady) - { - g.setColor(Color.black); - g.setFont(new Font("Verdana", Font.BOLD, 14)); - g.drawString("Retrieving PDB data....", 20, getHeight()/2); - return; - } + public void paintComponent(Graphics g) + { + super.paintComponent(g); + if (!seqColoursReady) + { + g.setColor(Color.black); + g.setFont(new Font("Verdana", Font.BOLD, 14)); + g.drawString("Retrieving PDB data....", 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(); - prefsize.height = getHeight(); + { + prefsize.width = getWidth(); + prefsize.height = getHeight(); - scale = findScale(); - img = createImage(prefsize.width, prefsize.height); - ig = img.getGraphics(); - Graphics2D ig2 = (Graphics2D) ig; + scale = findScale(); + img = createImage(prefsize.width, prefsize.height); + ig = img.getGraphics(); + Graphics2D ig2 = (Graphics2D) ig; - ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); - redrawneeded = true; - } + redrawneeded = true; + } + if (redrawneeded) + { + drawAll(ig, prefsize.width, prefsize.height); + redrawneeded = false; + } - if (redrawneeded) - { - drawAll(ig, prefsize.width, prefsize.height); - redrawneeded = false; - } + g.drawImage(img, 0, 0, this); - g.drawImage(img, 0, 0, this); + pdbAction = false; + } - pdbAction = false; - } + public void drawAll(Graphics g, int width, int height) + { + g.setColor(backgroundColour); + g.fillRect(0, 0, width, height); + drawScene(g); + drawLabels(g); + } - public void drawAll(Graphics g, int width, int height) + public void updateSeqColours() + { + if (pdbAction) { - g.setColor(backgroundColour); - g.fillRect(0, 0, width, height); - drawScene(g); - drawLabels(g); + return; } - - public void updateSeqColours() + // System.out.println("update seq colours"); + if (bysequence && pdb != null) { - if(pdbAction) + for (int ii = 0; ii < pdb.chains.size(); ii++) { - return; + colourBySequence( (PDBChain) pdb.chains.elementAt(ii)); } + } + + 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; - // System.out.println("update seq colours"); - if(bysequence && pdb!=null) + while ( (i < sequence.getLength()) && (j <= pos + 1)) + { + if (!jalview.util.Comparison.isGap(sequence.getCharAt(i))) { - for (int ii = 0; ii < pdb.chains.size(); ii++) - { - colourBySequence( (PDBChain) pdb.chains.elementAt(ii)); - } + j++; } - redrawneeded=true; - repaint(); + i++; } - int findTrueIndex(int pos) + if (i > 1) { - // 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++; - } + i--; + } - if(i>1) - i--; + if (j < pos) + { + return sequence.getEnd() + 1; + } + else + { + return i; + } + } - if (j < pos) - { - return sequence.getEnd() + 1; - } - else + // This method has been taken out of PDBChain to allow + // Applet and Application specific sequence renderers to be used + void colourBySequence(PDBChain chain) + { + // System.out.println("colour by seq"); + boolean showFeatures = false; + if (seqcanvas.getViewport().getShowSequenceFeatures()) + { + showFeatures = true; + if (fr == null) { - return i; + fr = new jalview.gui.FeatureRenderer(seqcanvas.getViewport()); } + + fr.transferSettings(seqcanvas.getFeatureRenderer()); } - // This method has been taken out of PDBChain to allow - // Applet and Application specific sequence renderers to be used - void colourBySequence(PDBChain chain) + Bond tmp; + for (int i = 0; i < chain.bonds.size(); i++) { - // System.out.println("colour by seq"); - boolean showFeatures = false; - if(seqcanvas.getViewport().getShowSequenceFeatures()) - { - showFeatures = true; - if (fr == null) - fr = new jalview.gui.FeatureRenderer(seqcanvas.getViewport()); - - fr.transferSettings( seqcanvas.getFeatureRenderer() ); - } + tmp = (Bond) chain.bonds.elementAt(i); - Bond tmp; - for (int i = 0; i < chain.bonds.size(); i++) + if (chain != mainchain) { - tmp = (Bond) chain.bonds.elementAt(i); - - if(chain!=mainchain) - continue; + continue; + } - //if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) && - // (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1))) + //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) { - int index = findTrueIndex(tmp.at1.alignmentMapping); - //sequence.findIndex(tmp.at1.alignmentMapping); - if (index != -1) - { - tmp.startCol = seqcanvas.getSequenceRenderer(). - getResidueBoxColour( sequence, index); + tmp.startCol = seqcanvas.getSequenceRenderer(). + getResidueBoxColour(sequence, index); - if(showFeatures) - tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index); + if (showFeatures) + { + tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index); + } - if(tmp.startCol==null) - tmp.startCol = Color.white; - } + 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))) - { + //if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) && + // (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1))) + { - int index = findTrueIndex(tmp.at2.alignmentMapping); - //sequence.findIndex( tmp.at2.alignmentMapping ); - if (index != -1) - { - tmp.endCol = seqcanvas.getSequenceRenderer(). - getResidueBoxColour( sequence, index); + int index = findTrueIndex(tmp.at2.alignmentMapping); + //sequence.findIndex( tmp.at2.alignmentMapping ); + if (index != -1) + { + tmp.endCol = seqcanvas.getSequenceRenderer(). + getResidueBoxColour(sequence, index); - if(showFeatures) - tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index); + if (showFeatures) + { + tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index); + } - if(tmp.endCol==null) - tmp.endCol = Color.white; - } + if (tmp.endCol == null) + { + tmp.endCol = Color.white; + } } } } + } - - Zsort zsort; - public void drawScene(Graphics g) + Zsort zsort; + public void drawScene(Graphics g) + { + if (zbuffer) { - if (zbuffer) + if (zsort == null) { - if (zsort == null) - zsort = new Zsort(); - - zsort.Zsort(visiblebonds); + zsort = new Zsort(); } - Bond tmpBond = null; - for (int i = 0; i < visiblebonds.size(); i++) - { - tmpBond = (Bond) visiblebonds.elementAt(i); + zsort.Zsort(visiblebonds); + } - xstart = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) + - (getWidth() / 2)); - ystart = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) + - (getHeight() / 2)); + Bond tmpBond = null; + for (int i = 0; i < visiblebonds.size(); i++) + { + tmpBond = (Bond) visiblebonds.elementAt(i); - xend = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) + + xstart = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) + (getWidth() / 2)); - yend = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) + + ystart = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) + (getHeight() / 2)); - xmid = (xend + xstart) / 2; - ymid = (yend + ystart) / 2; - if (depthcue && !bymolecule) - { - if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) - { - - g.setColor(tmpBond.startCol.darker().darker()); - drawLine(g, xstart, ystart, xmid, ymid); - g.setColor(tmpBond.endCol.darker().darker()); - drawLine(g, xmid, ymid, xend, yend); + xend = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) + + (getWidth() / 2)); + yend = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) + + (getHeight() / 2)); - } - else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) - { - g.setColor(tmpBond.startCol.darker()); - drawLine(g, xstart, ystart, xmid, ymid); + xmid = (xend + xstart) / 2; + ymid = (yend + ystart) / 2; + if (depthcue && !bymolecule) + { + if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) + { - g.setColor(tmpBond.endCol.darker()); - drawLine(g, xmid, ymid, xend, yend); - } - else - { - g.setColor(tmpBond.startCol); - drawLine(g, xstart, ystart, xmid, ymid); + g.setColor(tmpBond.startCol.darker().darker()); + drawLine(g, xstart, ystart, xmid, ymid); + g.setColor(tmpBond.endCol.darker().darker()); + drawLine(g, xmid, ymid, xend, yend); - g.setColor(tmpBond.endCol); - drawLine(g, xmid, ymid, xend, yend); - } } - else if (depthcue && bymolecule) + else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) { - if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) - { - g.setColor(Color.green.darker().darker()); - drawLine(g, xstart, ystart, xend, yend); - } - else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) - { - g.setColor(Color.green.darker()); - drawLine(g, xstart, ystart, xend, yend); - } - else - { - g.setColor(Color.green); - drawLine(g, xstart, ystart, xend, yend); - } + g.setColor(tmpBond.startCol.darker()); + drawLine(g, xstart, ystart, xmid, ymid); + + g.setColor(tmpBond.endCol.darker()); + drawLine(g, xmid, ymid, xend, yend); } - else if (!depthcue && !bymolecule) + else { g.setColor(tmpBond.startCol); drawLine(g, xstart, ystart, xmid, ymid); + g.setColor(tmpBond.endCol); drawLine(g, xmid, ymid, xend, yend); } - else + } + else if (depthcue && bymolecule) + { + if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) { + g.setColor(Color.green.darker().darker()); drawLine(g, xstart, ystart, xend, yend); } - - if (highlightBond1 != null && highlightBond1 == tmpBond) + else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) { - g.setColor(tmpBond.endCol.brighter().brighter().brighter().brighter()); - drawLine(g, xmid, ymid, xend, yend); + g.setColor(Color.green.darker()); + drawLine(g, xstart, ystart, xend, yend); } - - if (highlightBond2 != null && highlightBond2 == tmpBond) + else { - g.setColor(tmpBond.startCol.brighter().brighter().brighter().brighter()); - drawLine(g, xstart, ystart, xmid, ymid); + g.setColor(Color.green); + drawLine(g, xstart, ystart, xend, yend); } - + } + else if (!depthcue && !bymolecule) + { + g.setColor(tmpBond.startCol); + drawLine(g, xstart, ystart, xmid, ymid); + g.setColor(tmpBond.endCol); + drawLine(g, xmid, ymid, xend, yend); + } + else + { + drawLine(g, xstart, ystart, xend, yend); } + if (highlightBond1 != null && highlightBond1 == tmpBond) + { + g.setColor(tmpBond.endCol.brighter().brighter().brighter().brighter()); + drawLine(g, xmid, ymid, xend, yend); + } - } - - public void drawLine(Graphics g, int x1, int y1, int x2, int y2) { - if (!wire) { - 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); - g.drawLine(x1, y1 - 1, x2, y2 - 1); - } else { - g.setColor(g.getColor().brighter()); - g.drawLine(x1, y1, x2, y2); - g.drawLine(x1 + 1, y1, x2 + 1, y2); - g.drawLine(x1 - 1, y1, x2 - 1, y2); - } - } else { - g.drawLine(x1, y1, x2, y2); - } - } + if (highlightBond2 != null && highlightBond2 == tmpBond) + { + g.setColor(tmpBond.startCol.brighter().brighter().brighter().brighter()); + drawLine(g, xstart, ystart, xmid, ymid); + } - public Dimension minimumsize() { - return prefsize; } - public Dimension preferredsize() { - return prefsize; - } + } - public void keyPressed(KeyEvent evt) + public void drawLine(Graphics g, int x1, int y1, int x2, int y2) + { + if (!wire) { - if (evt.getKeyCode() == KeyEvent.VK_UP) + if ( ( (float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) { - scale = (float) (scale * 1.1); - redrawneeded = true; - repaint(); + g.drawLine(x1, y1, x2, y2); + g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1); + g.drawLine(x1, y1 - 1, x2, y2 - 1); } - else if (evt.getKeyCode() == KeyEvent.VK_DOWN) + else { - scale = (float) (scale * 0.9); - redrawneeded = true; - repaint(); + g.setColor(g.getColor().brighter()); + g.drawLine(x1, y1, x2, y2); + g.drawLine(x1 + 1, y1, x2 + 1, y2); + g.drawLine(x1 - 1, y1, x2 - 1, y2); } } - - public void mousePressed(MouseEvent e) + else { - pdbAction = true; - Atom fatom = findAtom(e.getX(), e.getY()); - if(fatom!=null) - { - fatom.isSelected = !fatom.isSelected; + g.drawLine(x1, y1, x2, y2); + } + } - redrawneeded = true; - repaint(); - if (foundchain != -1) - { - PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain); - if (chain == mainchain) - { - if (fatom.alignmentMapping != -1) - { - if (highlightRes == null) - highlightRes = new Vector(); - - if (highlightRes.contains(fatom.alignmentMapping+"")) - highlightRes.remove(fatom.alignmentMapping + ""); - else - highlightRes.add(fatom.alignmentMapping + ""); - } - } - } + public Dimension minimumsize() + { + return prefsize; + } - } - mx = e.getX(); - my = e.getY(); - omx = mx; - omy = my; - dragging = false; - } + public Dimension preferredsize() + { + return prefsize; + } - public void mouseMoved(MouseEvent e) + public void keyPressed(KeyEvent evt) + { + if (evt.getKeyCode() == KeyEvent.VK_UP) { - pdbAction = true; - if(highlightBond1!=null) - { - highlightBond1.at2.isSelected = false; - highlightBond2.at1.isSelected = false; - highlightBond1 = null; - highlightBond2 = null; - } + scale = (float) (scale * 1.1); + redrawneeded = true; + repaint(); + } + else if (evt.getKeyCode() == KeyEvent.VK_DOWN) + { + scale = (float) (scale * 0.9); + redrawneeded = true; + repaint(); + } + } - Atom fatom = findAtom(e.getX(), e.getY()); + public void mousePressed(MouseEvent e) + { + pdbAction = true; + Atom fatom = findAtom(e.getX(), e.getY()); + if (fatom != null) + { + fatom.isSelected = !fatom.isSelected; - PDBChain chain = null; - if(foundchain!=-1) + redrawneeded = true; + repaint(); + if (foundchain != -1) + { + PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain); + if (chain == mainchain) { - chain = (PDBChain) pdb.chains.elementAt(foundchain); - if(chain == mainchain) + if (fatom.alignmentMapping != -1) { - highlightSeqcanvas( fatom.alignmentMapping ); + if (highlightRes == null) + { + highlightRes = new Vector(); + } + + if (highlightRes.contains(fatom.alignmentMapping + "")) + { + highlightRes.remove(fatom.alignmentMapping + ""); + } + else + { + highlightRes.add(fatom.alignmentMapping + ""); + } } } + } - if (fatom != null) - { - this.setToolTipText(chain.id+":"+ fatom.resNumber+" "+ fatom.resName); - } else - { - highlightSeqcanvas( -1); - this.setToolTipText(null); - } + } + mx = e.getX(); + my = e.getY(); + omx = mx; + omy = my; + dragging = false; + } + + public void mouseMoved(MouseEvent e) + { + pdbAction = true; + if (highlightBond1 != null) + { + highlightBond1.at2.isSelected = false; + highlightBond2.at1.isSelected = false; + highlightBond1 = null; + highlightBond2 = null; } + Atom fatom = findAtom(e.getX(), e.getY()); - void highlightSeqcanvas(int pos) + PDBChain chain = null; + if (foundchain != -1) { - SearchResults searchResults = new SearchResults(); - if(highlightRes!=null) + chain = (PDBChain) pdb.chains.elementAt(foundchain); + if (chain == mainchain) { - for (int i = 0; i < highlightRes.size(); i++) - { - int a = Integer.parseInt(highlightRes.elementAt( - i).toString())+1; - - searchResults.addResult(sequence, a, a); - } + highlightSeqcanvas(fatom.alignmentMapping); } + } + + if (fatom != null) + { + this.setToolTipText(chain.id + ":" + fatom.resNumber + " " + + fatom.resName); + } + else + { + highlightSeqcanvas( -1); + this.setToolTipText(null); + } + } - if(pos!=-1) + void highlightSeqcanvas(int pos) + { + SearchResults searchResults = new SearchResults(); + if (highlightRes != null) + { + for (int i = 0; i < highlightRes.size(); i++) { - searchResults.addResult(sequence, pos+1, pos+1); + int a = Integer.parseInt(highlightRes.elementAt( + i).toString()) + 1; + + searchResults.addResult(sequence, a, a); } + } - seqcanvas.highlightSearchResults(searchResults); + if (pos != -1) + { + searchResults.addResult(sequence, pos + 1, pos + 1); } + seqcanvas.highlightSearchResults(searchResults); + } - public void mouseClicked(MouseEvent e) { } + public void mouseClicked(MouseEvent e) + {} - public void mouseEntered(MouseEvent e) { } + public void mouseEntered(MouseEvent e) + {} - public void mouseExited(MouseEvent e) { } + public void mouseExited(MouseEvent e) + {} - public void mouseDragged(MouseEvent evt) - { - int x = evt.getX(); - int y = evt.getY(); - mx = x; - my = y; + public void mouseDragged(MouseEvent evt) + { + int x = evt.getX(); + int y = evt.getY(); + mx = x; + my = y; + MCMatrix objmat = new MCMatrix(3, 3); + objmat.setIdentity(); - MCMatrix objmat = new MCMatrix(3, 3); - objmat.setIdentity(); + if ( (evt.getModifiers() & Event.META_MASK) != 0) + { + objmat.rotatez( (float) ( (mx - omx))); + } + else + { + objmat.rotatex( (float) ( (my - omy))); + objmat.rotatey( (float) ( (omx - mx))); + } - if ((evt.getModifiers() & Event.META_MASK) != 0) { - objmat.rotatez((float) ((mx - omx))); - } else { - objmat.rotatex((float) ((my - omy))); - objmat.rotatey((float) ((omx - mx))); - } + //Alter the bonds + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - //Alter the bonds - for (int ii = 0; ii < pdb.chains.size(); ii++) { - Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + for (int i = 0; i < bonds.size(); i++) + { + Bond tmpBond = (Bond) bonds.elementAt(i); - 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 + tmpBond.start = objmat.vectorMultiply(tmpBond.start); + tmpBond.end = objmat.vectorMultiply(tmpBond.end); - //Now apply the rotation matrix - tmpBond.start = objmat.vectorMultiply(tmpBond.start); - tmpBond.end = objmat.vectorMultiply(tmpBond.end); + //Now translate back again + tmpBond.translate(centre[0], centre[1], centre[2]); + } + } - //Now translate back again - tmpBond.translate(centre[0], centre[1], centre[2]); - } - } + objmat = null; - objmat = null; + omx = mx; + omy = my; - omx = mx; - omy = my; + dragging = true; - dragging = true; + redrawneeded = true; - redrawneeded = true; + repaint(); + } - repaint(); - } + public void mouseReleased(MouseEvent evt) + { + dragging = false; + return; + } + + void drawLabels(Graphics g) + { - public void mouseReleased(MouseEvent evt) + for (int ii = 0; ii < pdb.chains.size(); ii++) { - dragging = false; - return; - } + PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); - void drawLabels(Graphics g) { + if (chain.isVisible) + { + Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int i = 0; i < bonds.size(); i++) { - PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); - - if (chain.isVisible) - { - Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; - - for (int i = 0; i < bonds.size(); i++) - { - Bond tmpBond = (Bond) bonds.elementAt(i); + Bond tmpBond = (Bond) bonds.elementAt(i); - if (tmpBond.at1.isSelected) - { - labelAtom(g, tmpBond, 1); - } + if (tmpBond.at1.isSelected) + { + labelAtom(g, tmpBond, 1); + } - if (tmpBond.at2.isSelected) - { + if (tmpBond.at2.isSelected) + { - labelAtom(g, tmpBond, 2); - } - } - } + labelAtom(g, tmpBond, 2); + } } + } } + } - public void labelAtom(Graphics g, Bond b, int n) { - g.setFont(font); - 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)); + public void labelAtom(Graphics g, Bond b, int n) + { + g.setFont(font); + 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)); - g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart); - } + 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)); + 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)); - g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart); - } + g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart); } + } + + int foundchain = -1; + public Atom findAtom(int x, int y) + { + Atom fatom = null; - int foundchain = -1; - public Atom findAtom(int x, int y) { - Atom fatom = null; + foundchain = -1; + + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); + int truex; + Bond tmpBond = null; - foundchain = -1; + if (chain.isVisible) + { + Vector bonds = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int i = 0; i < bonds.size(); i++) { - PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); - int truex; - Bond tmpBond=null; + tmpBond = (Bond) bonds.elementAt(i); - if (chain.isVisible) - { - 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)); - - if (Math.abs(truex - x) <= 2) - { - int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) + - (getHeight() / 2)); - - if (Math.abs(truey - y) <= 2) - { - fatom = tmpBond.at1; - foundchain = ii; - break; - } - } - } - - // Still here? Maybe its the last bond - - 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)); - - if (Math.abs(truey - y) <= 2) - { - fatom = tmpBond.at2; - foundchain = ii; - break; - } - } + 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)); - if (fatom != null) //)&& chain.ds != null) - { - chain = (PDBChain) pdb.chains.elementAt(foundchain); + if (Math.abs(truey - y) <= 2) + { + fatom = tmpBond.at1; + foundchain = ii; + break; } + } } - return fatom; + // Still here? Maybe its the last bond + + 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)); + + if (Math.abs(truey - y) <= 2) + { + fatom = tmpBond.at2; + foundchain = ii; + break; + } + } + + } + + if (fatom != null) //)&& chain.ds != null) + { + chain = (PDBChain) pdb.chains.elementAt(foundchain); + } } - Bond highlightBond1, highlightBond2; - public void highlightRes(int ii) + return fatom; + } + + Bond highlightBond1, highlightBond2; + public void highlightRes(int ii) { - if( !seqColoursReady ) + if (!seqColoursReady) + { return; + } if (highlightRes != null - && highlightRes.contains((ii-1) + "")) + && highlightRes.contains( (ii - 1) + "")) { return; } int index = -1; Bond tmpBond; - for(index=0; index") > -1 || data.indexOf("") > -1) + ) { - if ( - !( data.indexOf("
") > -1 || data.indexOf("
") > -1) - ) - out.println(data); + out.println(data); } - out.close(); - } - catch (Exception ex) - { - ex.printStackTrace(); } + out.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); } + } } } diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java index 26d44b1..6fdd978 100755 --- a/src/MCview/PDBfile.java +++ b/src/MCview/PDBfile.java @@ -1,170 +1,195 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 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 + * 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 + */ package MCview; -import jalview.datamodel.*; - import java.io.*; - import java.util.*; -import java.awt.Color; +import java.awt.*; -public class PDBfile extends jalview.io.AlignFile { - public Vector chains; - public String id; +import jalview.datamodel.*; - public PDBfile(String inFile, String inType) throws IOException +public class PDBfile + extends jalview.io.AlignFile +{ + public Vector chains; + public String id; + + public PDBfile(String inFile, String inType) + throws IOException + { + super(inFile, inType); + } + + public String print() + { + return null; + } + + public void parse() + throws IOException + { + try { - super(inFile, inType); - } + chains = new Vector(); - public String print() - { - return null; - } + PDBChain tmpchain; + String line; + boolean modelFlag = false; + boolean terFlag = false; - public void parse() throws IOException - { - try{ - chains = new Vector(); + int index = 0; + while ( (line = nextLine()) != null) + { + if (line.indexOf("HEADER") == 0) + { + id = line.substring(62, 67).trim(); + continue; + } + // Were we to do anything with SEQRES - we start it here + if (line.indexOf("SEQRES") == 0) + { + } + + if (line.indexOf("MODEL") == 0) + { + modelFlag = true; + } - PDBChain tmpchain; - String line; - boolean modelFlag = false; - boolean terFlag = false; + if (line.indexOf("TER") == 0) + { + terFlag = true; + } - int index = 0; - while ( (line = nextLine()) != null) + if (modelFlag && line.indexOf("ENDMDL") == 0) { - if (line.indexOf("HEADER") == 0) + break; + } + if (line.indexOf("ATOM") == 0 + || (line.indexOf("HETATM") == 0 && !terFlag) + ) + { + terFlag = false; + + //Jalview is only interested in CA bonds???? + if (!line.substring(12, 15).trim().equals("CA")) { - id = line.substring(62, 67).trim(); continue; } - // Were we to do anything with SEQRES - we start it here - if (line.indexOf("SEQRES") == 0) { + + Atom tmpatom = new Atom(line); + tmpchain = findChain(tmpatom.chain); + if (tmpchain != null) + { + tmpchain.atoms.addElement(tmpatom); } - - if (line.indexOf("MODEL") == 0) - modelFlag = true; - - if (line.indexOf("TER") == 0) - terFlag = true; - - if (modelFlag && line.indexOf("ENDMDL") == 0) - break; - if (line.indexOf("ATOM") == 0 - || (line.indexOf("HETATM") == 0 && !terFlag) - ) + else { - terFlag = false; - - //Jalview is only interested in CA bonds???? - if (!line.substring(12, 15).trim().equals("CA")) - { - continue; - } - - Atom tmpatom = new Atom(line); - tmpchain = findChain(tmpatom.chain); - if (tmpchain != null) - { - tmpchain.atoms.addElement(tmpatom); - } - else - { - tmpchain = new PDBChain(id,tmpatom.chain); - chains.addElement(tmpchain); - tmpchain.atoms.addElement(tmpatom); - } + tmpchain = new PDBChain(id, tmpatom.chain); + chains.addElement(tmpchain); + tmpchain.atoms.addElement(tmpatom); } - index++; } + index++; + } - makeResidueList(); - makeCaBondList(); + makeResidueList(); + makeCaBondList(); - if (id == null) - { - id = inFile.getName(); - } - for (int i = 0; i < chains.size(); i++) + if (id == null) + { + id = inFile.getName(); + } + for (int i = 0; i < chains.size(); i++) + { + SequenceI dataset = ( (PDBChain) chains.elementAt(i)). + sequence; + dataset.setName(id + "|" + dataset.getName()); + PDBEntry entry = new PDBEntry(); + entry.setId(id); + if (inFile != null) { - SequenceI dataset = ( (PDBChain) chains.elementAt(i)). - sequence; - dataset.setName(id + "|" + dataset.getName()); - PDBEntry entry = new PDBEntry(); - entry.setId(id); - if (inFile != null) - entry.setFile(inFile.getAbsolutePath()); - dataset.addPDBId(entry); - getSeqs().addElement(dataset.deriveSequence()); // PDBChain objects maintain reference to dataset + entry.setFile(inFile.getAbsolutePath()); } - }catch(OutOfMemoryError er) - { - System.out.println("OUT OF MEMORY LOADING PDB FILE"); - throw new IOException("Out of memory loading PDB File"); + dataset.addPDBId(entry); + getSeqs().addElement(dataset.deriveSequence()); // PDBChain objects maintain reference to dataset } } - - public void makeResidueList() { - for (int i = 0; i < chains.size(); i++) { - ((PDBChain) chains.elementAt(i)).makeResidueList(); - } + catch (OutOfMemoryError er) + { + System.out.println("OUT OF MEMORY LOADING PDB FILE"); + throw new IOException("Out of memory loading PDB File"); } + } - public void makeCaBondList() { - for (int i = 0; i < chains.size(); i++) { - ((PDBChain) chains.elementAt(i)).makeCaBondList(); - } + public void makeResidueList() + { + for (int i = 0; i < chains.size(); i++) + { + ( (PDBChain) chains.elementAt(i)).makeResidueList(); } + } - public PDBChain findChain(String id) { - for (int i = 0; i < chains.size(); i++) { - if (((PDBChain) chains.elementAt(i)).id.equals(id)) { - return (PDBChain) chains.elementAt(i); - } - } + public void makeCaBondList() + { + for (int i = 0; i < chains.size(); i++) + { + ( (PDBChain) chains.elementAt(i)).makeCaBondList(); + } + } - return null; + public PDBChain findChain(String id) + { + for (int i = 0; i < chains.size(); i++) + { + if ( ( (PDBChain) chains.elementAt(i)).id.equals(id)) + { + return (PDBChain) chains.elementAt(i); + } } - public void setChargeColours() { - for (int i = 0; i < chains.size(); i++) { - ((PDBChain) chains.elementAt(i)).setChargeColours(); - } + return null; + } + + public void setChargeColours() + { + for (int i = 0; i < chains.size(); i++) + { + ( (PDBChain) chains.elementAt(i)).setChargeColours(); } + } - public void setColours(jalview.schemes.ColourSchemeI cs) { - for (int i = 0; i < chains.size(); i++) { - ((PDBChain) chains.elementAt(i)).setChainColours(cs); - } + public void setColours(jalview.schemes.ColourSchemeI cs) + { + for (int i = 0; i < chains.size(); i++) + { + ( (PDBChain) chains.elementAt(i)).setChainColours(cs); } + } - public void setChainColours() + public void setChainColours() + { + for (int i = 0; i < chains.size(); i++) { - for (int i = 0; i < chains.size(); i++) - { - ((PDBChain) chains.elementAt(i)).setChainColours( - Color.getHSBColor(1.0f / (float)i, .4f, 1.0f) - ); - } + ( (PDBChain) chains.elementAt(i)).setChainColours( + Color.getHSBColor(1.0f / (float) i, .4f, 1.0f) + ); } + } } diff --git a/src/MCview/Residue.java b/src/MCview/Residue.java index 4bd66af..e99c746 100755 --- a/src/MCview/Residue.java +++ b/src/MCview/Residue.java @@ -1,48 +1,49 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 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 + * 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 + */ package MCview; import java.util.*; +public class Residue +{ + Vector atoms = new Vector(); + int number; + int count; + int seqnumber; -public class Residue { - Vector atoms = new Vector(); - int number; - int count; - int seqnumber; + public Residue(Vector atoms, int number, int count) + { + this.atoms = atoms; + this.number = number; + this.count = count; + } - public Residue(Vector atoms, int number, int count) { - this.atoms = atoms; - this.number = number; - this.count = count; - } - - public Atom findAtom(String name) + public Atom findAtom(String name) + { + for (int i = 0; i < atoms.size(); i++) { - for (int i = 0; i < atoms.size(); i++) - { - if (((Atom) atoms.elementAt(i)).name.equals(name)) - { - return (Atom) atoms.elementAt(i); - } - } - - return null; + if ( ( (Atom) atoms.elementAt(i)).name.equals(name)) + { + return (Atom) atoms.elementAt(i); + } } + + return null; + } } diff --git a/src/MCview/Zsort.java b/src/MCview/Zsort.java index 8325f9a..f7f2c39 100755 --- a/src/MCview/Zsort.java +++ b/src/MCview/Zsort.java @@ -1,63 +1,75 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2006 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 + * 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 + */ package MCview; import java.util.*; +public class Zsort +{ + public void Zsort(Vector bonds) + { + sort(bonds, 0, bonds.size() - 1); + } -public class Zsort { - public void Zsort(Vector bonds) { - sort(bonds, 0, bonds.size() - 1); - } - - public void sort(Vector bonds, int p, int r) { - int q; + public void sort(Vector bonds, int p, int r) + { + int q; - if (p < r) { - q = partition(bonds, p, r); - sort(bonds, p, q); - sort(bonds, q + 1, r); - } + if (p < r) + { + q = partition(bonds, p, r); + sort(bonds, p, q); + sort(bonds, q + 1, r); } + } - private int partition(Vector bonds, int p, int r) { - float x = ((Bond) bonds.elementAt(p)).start[2]; - int i = p - 1; - int j = r + 1; - Bond tmp; - while (true) { - do { - j --; - } while ((j >= 0) && (((Bond) bonds.elementAt(j)).start[2] > x)); + private int partition(Vector bonds, int p, int r) + { + float x = ( (Bond) bonds.elementAt(p)).start[2]; + int i = p - 1; + int j = r + 1; + Bond tmp; + while (true) + { + do + { + j--; + } + while ( (j >= 0) && ( ( (Bond) bonds.elementAt(j)).start[2] > x)); - do { - i ++; - } while ((i < bonds.size()) && - (((Bond) bonds.elementAt(i)).start[2] < x)); + do + { + i++; + } + while ( (i < bonds.size()) && + ( ( (Bond) bonds.elementAt(i)).start[2] < x)); - if (i < j) { - tmp = (Bond) bonds.elementAt(i); - bonds.setElementAt(bonds.elementAt(j), i); - bonds.setElementAt(tmp, j); - } else { - return j; - } - } + if (i < j) + { + tmp = (Bond) bonds.elementAt(i); + bonds.setElementAt(bonds.elementAt(j), i); + bonds.setElementAt(tmp, j); + } + else + { + return j; + } } + } } -- 1.7.10.2