X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2FMCview%2FAppletPDBCanvas.java;h=dc69f43cd88925fb25e9f346c9d1a4dd231545cc;hb=1b806c7525927fc937d51b9eab81bd96a1eaa347;hp=609126ce8b816c63f4ebfa9c7796556abb93756a;hpb=b68dc1d95eeed4ab36914797f7d97c72ad54c11d;p=jalview.git
diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java
old mode 100755
new mode 100644
index 609126c..dc69f43
--- a/src/MCview/AppletPDBCanvas.java
+++ b/src/MCview/AppletPDBCanvas.java
@@ -1,1003 +1,1246 @@
/*
-* 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 ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package MCview;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Event;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Image;
+// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug
+import java.awt.Panel;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.io.PrintStream;
+import java.util.List;
+import java.util.Vector;
+
import jalview.analysis.AlignSeq;
+import jalview.appletgui.AlignmentPanel;
+import jalview.appletgui.FeatureRenderer;
+import jalview.appletgui.SequenceRenderer;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceI;
+import jalview.structure.AtomSpec;
+import jalview.structure.StructureListener;
+import jalview.structure.StructureMapping;
+import jalview.structure.StructureSelectionManager;
+import jalview.util.MessageManager;
+
+public class AppletPDBCanvas extends Panel implements MouseListener,
+ MouseMotionListener, StructureListener
+{
-import jalview.datamodel.*;
+ MCMatrix idmat = new MCMatrix(3, 3);
-// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug
-import java.awt.*;
-import java.awt.event.*;
+ MCMatrix objmat = new MCMatrix(3, 3);
-import java.io.*;
+ boolean redrawneeded = true;
-import java.util.*;
+ int omx = 0;
+ int mx = 0;
+ int omy = 0;
-public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotionListener
-{
+ int my = 0;
- 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 PDBfile pdb;
- public void keyPressed(KeyEvent evt)
- {
- doKeyPressed(evt);
- }
- });
- }
+ PDBEntry pdbentry;
+ int bsize;
- 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;;
+ Image img;
- for (int i = 0; i < pdb.chains.size(); i++)
- {
+ Graphics ig;
- 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;
- }
+ Dimension prefsize;
- mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);
- mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend);
- }
+ float[] centre = new float[3];
- 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);
- }
- }
- }
+ float[] width = new float[3];
- addMouseMotionListener(this);
- addMouseListener(this);
+ float maxwidth;
+ float scale;
- findCentre();
- findWidth();
+ String inStr;
- setupBonds();
+ String inType;
- scale = findScale();
- }
+ boolean bysequence = true;
+ boolean depthcue = true;
- Vector visiblebonds;
- void setupBonds()
- {
- seqColoursReady = false;
- // Sort the bonds by z coord
- visiblebonds = new Vector();
+ boolean wire = false;
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)
- {
- Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;
+ boolean bymolecule = false;
- for (int i = 0; i < tmp.size(); i++)
- {
- visiblebonds.addElement(tmp.elementAt(i));
- }
- }
- }
- updateSeqColours();
- seqColoursReady = true;
- redrawneeded = true;
- repaint();
- }
+ boolean zbuffer = true;
+ boolean dragging;
- public void findWidth() {
- float[] max = new float[3];
- float[] min = new float[3];
+ int xstart;
- max[0] = (float) -1e30;
- max[1] = (float) -1e30;
- max[2] = (float) -1e30;
+ int xend;
- min[0] = (float) 1e30;
- min[1] = (float) 1e30;
- min[2] = (float) 1e30;
+ int ystart;
- 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 yend;
- for (int i = 0; i < bonds.size(); i++) {
- Bond tmp = (Bond) bonds.elementAt(i);
+ int xmid;
- if (tmp.start[0] >= max[0]) {
- max[0] = tmp.start[0];
- }
+ int ymid;
- if (tmp.start[1] >= max[1]) {
- max[1] = tmp.start[1];
- }
+ Font font = new Font("Helvetica", Font.PLAIN, 10);
- if (tmp.start[2] >= max[2]) {
- max[2] = tmp.start[2];
- }
+ public SequenceI[] sequence;
- if (tmp.start[0] <= min[0]) {
- min[0] = tmp.start[0];
- }
+ final StringBuffer mappingDetails = new StringBuffer();
- if (tmp.start[1] <= min[1]) {
- min[1] = tmp.start[1];
- }
+ String appletToolTip = null;
- if (tmp.start[2] <= min[2]) {
- min[2] = tmp.start[2];
- }
+ int toolx, tooly;
- if (tmp.end[0] >= max[0]) {
- max[0] = tmp.end[0];
- }
+ PDBChain mainchain;
- if (tmp.end[1] >= max[1]) {
- max[1] = tmp.end[1];
- }
+ Vector highlightRes;
- if (tmp.end[2] >= max[2]) {
- max[2] = tmp.end[2];
- }
+ boolean pdbAction = false;
- if (tmp.end[0] <= min[0]) {
- min[0] = tmp.end[0];
- }
+ Bond highlightBond1, highlightBond2;
- if (tmp.end[1] <= min[1]) {
- min[1] = tmp.end[1];
- }
+ boolean errorLoading = false;
- if (tmp.end[2] <= min[2]) {
- min[2] = tmp.end[2];
- }
- }
- }
- }
+ boolean seqColoursReady = false;
- 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]);
+ FeatureRenderer fr;
- maxwidth = width[0];
+ AlignmentPanel ap;
- if (width[1] > width[0]) {
- maxwidth = width[1];
- }
+ StructureSelectionManager ssm;
- if (width[2] > width[1]) {
- maxwidth = width[2];
- }
+ public AppletPDBCanvas(PDBEntry pdbentry, SequenceI[] seq,
+ String[] chains, AlignmentPanel ap, String protocol)
- // System.out.println("Maxwidth = " + maxwidth);
- }
+ {
+ this.ap = ap;
+ this.pdbentry = pdbentry;
+ this.sequence = seq;
- public float findScale() {
- int dim;
- int width;
- int height;
+ ssm = StructureSelectionManager
+ .getStructureSelectionManager(ap.av.applet);
- if (getSize().width != 0) {
- width = getSize().width;
- height = getSize().height;
- } else {
- width = prefsize.width;
- height = prefsize.height;
- }
+ try
+ {
+ pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol);
- if (width < height) {
- dim = width;
- } else {
- dim = height;
- }
+ if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE))
+ {
+ pdbentry.setFile("INLINE" + pdb.id);
+ }
- return (float) (dim / (1.5d * maxwidth));
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ return;
}
- public void findCentre() {
- float xtot = 0;
- float ytot = 0;
- float ztot = 0;
+ pdbentry.setId(pdb.id);
- int bsize = 0;
+ ssm.addStructureViewerListener(this);
- //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;
+ colourBySequence();
- bsize += bonds.size();
+ int max = -10;
+ int maxchain = -1;
+ int pdbstart = 0;
+ int pdbend = 0;
+ int seqstart = 0;
+ int seqend = 0;
- for (int i = 0; i < bonds.size(); i++) {
- xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] +
- ((Bond) bonds.elementAt(i)).end[0];
+ // JUST DEAL WITH ONE SEQUENCE FOR NOW
+ SequenceI sequence = seq[0];
- ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] +
- ((Bond) bonds.elementAt(i)).end[1];
+ for (int i = 0; i < pdb.chains.size(); i++)
+ {
- ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] +
- ((Bond) bonds.elementAt(i)).end[2];
- }
- }
+ mappingDetails.append("\n\nPDB Sequence is :\nSequence = "
+ + pdb.chains.elementAt(i).sequence
+ .getSequenceAsString());
+ mappingDetails.append("\nNo of residues = "
+ + 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
+ // TODO: DNa/Pep switch
+ AlignSeq as = new AlignSeq(sequence,
+ pdb.chains.elementAt(i).sequence,
+ pdb.chains.elementAt(i).isNa ? AlignSeq.DNA
+ : AlignSeq.PEP);
+ as.calcScoreMatrix();
+ as.traceAlignment();
+ PrintStream ps = new PrintStream(System.out)
+ {
+ public void print(String x)
+ {
+ mappingDetails.append(x);
}
- centre[0] = xtot / (2 * (float) bsize);
- centre[1] = ytot / (2 * (float) bsize);
- centre[2] = ztot / (2 * (float) bsize);
- }
+ public void println()
+ {
+ mappingDetails.append("\n");
+ }
+ };
- public void paint(Graphics g)
- {
+ as.printAlignment(ps);
- if(errorLoading)
+ if (as.maxscore > max)
{
- 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;
- }
+ max = as.maxscore;
+ maxchain = i;
- if( !seqColoursReady )
- {
- g.setColor(Color.black);
- g.setFont(new Font("Verdana", Font.BOLD, 14));
- g.drawString("Fetching PDB data...", 50, getSize().height/2);
- return;
+ pdbstart = as.seq2start;
+ pdbend = as.seq2end;
+ seqstart = as.seq1start + sequence.getStart() - 1;
+ seqend = as.seq1end + sequence.getEnd() - 1;
}
+ mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);
+ mappingDetails.append("\nSEQ start/end " + seqstart + " " + seqend);
+ }
+ mainchain = pdb.chains.elementAt(maxchain);
- //Only create the image at the beginning -
- //this saves much memory usage
- if ((img == null) || (prefsize.width != getSize().width) ||
- (prefsize.height != getSize().height)) {
-
- try{ prefsize.width = getSize().width;
- prefsize.height = getSize().height;
-
- scale = findScale();
- img = createImage(prefsize.width, prefsize.height);
- ig = img.getGraphics();
-
- redrawneeded = true;
- }catch(Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
+ 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);
- if (redrawneeded)
+ // Initialize the matrices to identity
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 3; j++)
+ {
+ if (i != j)
{
- drawAll(ig, prefsize.width, prefsize.height);
- redrawneeded = false;
+ idmat.addElement(i, j, 0);
+ objmat.addElement(i, j, 0);
}
- if(appletToolTip!=null)
+ else
{
- ig.setColor(Color.red);
- ig.drawString(appletToolTip, toolx, tooly);
+ idmat.addElement(i, j, 1);
+ objmat.addElement(i, j, 1);
}
-
- 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);
- }
+ addMouseMotionListener(this);
+ addMouseListener(this);
- void setColours(jalview.schemes.ColourSchemeI cs)
- {
- bysequence = false;
- pdb.setColours(cs);
- redrawneeded = true;
- repaint();
- }
- public void updateSeqColours()
+ addKeyListener(new KeyAdapter()
{
- if (pdbAction)
+ public void keyPressed(KeyEvent evt)
{
- return;
+ doKeyPressed(evt);
}
+ });
- if(bysequence && pdb!=null)
+ findCentre();
+ findWidth();
+
+ setupBonds();
+
+ scale = findScale();
+ }
+
+ Vector visiblebonds;
+
+ void setupBonds()
+ {
+ seqColoursReady = false;
+ // Sort the bonds by z coord
+ visiblebonds = new Vector();
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ if (pdb.chains.elementAt(ii).isVisible)
{
- for (int ii = 0; ii < pdb.chains.size(); ii++)
+ Vector tmp = pdb.chains.elementAt(ii).bonds;
+
+ for (int i = 0; i < tmp.size(); i++)
{
- colourBySequence((PDBChain) pdb.chains.elementAt(ii));
+ visiblebonds.addElement(tmp.elementAt(i));
}
}
-
- redrawneeded=true;
- repaint();
}
-
-
- int findTrueIndex(int pos)
+ seqColoursReady = true;
+ colourBySequence();
+ 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++)
{
- // 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 (pdb.chains.elementAt(ii).isVisible)
{
- if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))
+ Vector bonds = pdb.chains.elementAt(ii).bonds;
+
+ for (Bond tmp : bonds)
{
- j++;
- }
+ if (tmp.start[0] >= max[0])
+ {
+ max[0] = tmp.start[0];
+ }
- i++;
- }
+ if (tmp.start[1] >= max[1])
+ {
+ max[1] = tmp.start[1];
+ }
- if(i>1)
- i--;
+ if (tmp.start[2] >= max[2])
+ {
+ max[2] = tmp.start[2];
+ }
- if ( (j == sequence.getEnd()) && (j < pos))
- {
- return sequence.getEnd() + 1;
- }
- else
- {
- return i;
- }
- }
+ if (tmp.start[0] <= min[0])
+ {
+ min[0] = tmp.start[0];
+ }
+ if (tmp.start[1] <= min[1])
+ {
+ min[1] = tmp.start[1];
+ }
- // 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;
+ if (tmp.start[2] <= min[2])
+ {
+ min[2] = tmp.start[2];
+ }
- if(seqcanvas.getViewport().getShowSequenceFeatures())
- {
- if(fr==null)
+ if (tmp.end[0] >= max[0])
{
- fr = new jalview.appletgui.FeatureRenderer(seqcanvas.getViewport());
+ max[0] = tmp.end[0];
}
- fr.transferSettings( seqcanvas.getFeatureRenderer());
- showFeatures = true;
- }
- 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 ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
- (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))
- {
+ if (tmp.end[1] >= max[1])
+ {
+ max[1] = tmp.end[1];
+ }
- int index = findTrueIndex(tmp.at1.alignmentMapping);
- //sequence.findIndex(tmp.at1.alignmentMapping);
- if (index != -1)
- {
- tmp.startCol = seqcanvas.getSequenceRenderer().
- getResidueBoxColour( sequence, index);
+ if (tmp.end[2] >= max[2])
+ {
+ max[2] = tmp.end[2];
+ }
- if(showFeatures)
- tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);
- }
- }
+ if (tmp.end[0] <= min[0])
+ {
+ min[0] = tmp.end[0];
+ }
- int index = findTrueIndex(tmp.at2.alignmentMapping);
- //sequence.findIndex( tmp.at2.alignmentMapping );
- if (index != -1)
- {
- tmp.endCol = seqcanvas.getSequenceRenderer().
- getResidueBoxColour( sequence, index);
+ if (tmp.end[1] <= min[1])
+ {
+ min[1] = tmp.end[1];
+ }
- if(showFeatures)
- tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);
+ if (tmp.end[2] <= min[2])
+ {
+ min[2] = tmp.end[2];
+ }
}
}
}
+ width[0] = Math.abs(max[0] - min[0]);
+ width[1] = Math.abs(max[1] - min[1]);
+ width[2] = Math.abs(max[2] - min[2]);
+
+ maxwidth = width[0];
- Zsort zsort;
- public void drawScene(Graphics g)
+ if (width[1] > width[0])
{
- if (zbuffer)
- {
- if(zsort ==null)
- zsort = new Zsort();
+ maxwidth = width[1];
+ }
- zsort.Zsort(visiblebonds);
- }
+ if (width[2] > width[1])
+ {
+ maxwidth = width[2];
+ }
+ // System.out.println("Maxwidth = " + maxwidth);
+ }
- Bond tmpBond=null;
- for (int i = 0; i < visiblebonds.size(); i++)
- {
- tmpBond = (Bond) visiblebonds.elementAt(i);
+ 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;
+ }
- xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) +
- (getSize().width / 2));
- ystart = (int) (((tmpBond.start[1] - centre[1]) * scale) +
- (getSize().height / 2));
+ if (width < height)
+ {
+ dim = width;
+ }
+ else
+ {
+ dim = height;
+ }
- xend = (int) (((tmpBond.end[0] - centre[0]) * scale) +
- (getSize().width / 2));
- yend = (int) (((tmpBond.end[1] - centre[1]) * scale) +
- (getSize().height / 2));
+ return (float) (dim / (1.5d * maxwidth));
+ }
- xmid = (xend + xstart) / 2;
- ymid = (yend + ystart) / 2;
+ public void findCentre()
+ {
+ float xtot = 0;
+ float ytot = 0;
+ float ztot = 0;
- 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);
- }
+ int bsize = 0;
- } 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);
- }
+ // Find centre coordinate
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ if (pdb.chains.elementAt(ii).isVisible)
+ {
+ Vector bonds = pdb.chains.elementAt(ii).bonds;
- 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);
- }
+ bsize += bonds.size();
+ for (Bond b : bonds)
+ {
+ xtot = xtot + b.start[0] + b.end[0];
+ ytot = ytot + b.start[1] + b.end[1];
+ ztot = ztot + b.start[2] + b.end[2];
}
+ }
}
- 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);
- }
- }
+ centre[0] = xtot / (2 * (float) bsize);
+ centre[1] = ytot / (2 * (float) bsize);
+ centre[2] = ztot / (2 * (float) bsize);
+ }
- public Dimension minimumsize() {
- return prefsize;
+ public void paint(Graphics g)
+ {
+
+ 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(
+ MessageManager.getString("label.error_loading_pdb_data"), 50,
+ getSize().height / 2);
+ return;
}
- public Dimension preferredsize() {
- return prefsize;
+ if (!seqColoursReady)
+ {
+ g.setColor(Color.black);
+ g.setFont(new Font("Verdana", Font.BOLD, 14));
+ g.drawString(MessageManager.getString("label.fetching_pdb_data"), 50,
+ getSize().height / 2);
+ return;
}
- public void doKeyPressed(KeyEvent evt)
+ // Only create the image at the beginning -
+ // this saves much memory usage
+ if ((img == null) || (prefsize.width != getSize().width)
+ || (prefsize.height != getSize().height))
{
- if (evt.getKeyCode() == KeyEvent.VK_UP)
+
+ try
{
- scale = (float) (scale * 1.1);
+ prefsize.width = getSize().width;
+ prefsize.height = getSize().height;
+
+ scale = findScale();
+ img = createImage(prefsize.width, prefsize.height);
+ ig = img.getGraphics();
+
redrawneeded = true;
- repaint();
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
}
- else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
+ }
+
+ 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);
+
+ 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);
+ }
+
+ public void setColours(jalview.schemes.ColourSchemeI cs)
+ {
+ bysequence = false;
+ pdb.setColours(cs);
+ redrawneeded = true;
+ repaint();
+ }
+
+ // This method has been taken out of PDBChain to allow
+ // Applet and Application specific sequence renderers to be used
+ void colourBySequence()
+ {
+ SequenceRenderer sr = new SequenceRenderer(ap.av);
+
+ StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());
+
+ boolean showFeatures = false;
+ if (ap.av.isShowSequenceFeatures())
+ {
+ if (fr == null)
{
- scale = (float) (scale * 0.9);
- redrawneeded = true;
- repaint();
+ fr = new jalview.appletgui.FeatureRenderer(ap.av);
}
+
+ fr.transferSettings(ap.getFeatureRenderer());
+
+ showFeatures = true;
}
- public void mousePressed(MouseEvent e) {
- pdbAction = true;
- Atom fatom = findAtom(e.getX(), e.getY());
- if(fatom!=null)
+ PDBChain chain;
+ if (bysequence && pdb != null)
+ {
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
{
- fatom.isSelected = !fatom.isSelected;
+ chain = pdb.chains.elementAt(ii);
- redrawneeded = true;
- repaint();
- if (foundchain != -1)
+ for (int i = 0; i < chain.bonds.size(); i++)
{
- PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);
- if (chain == mainchain)
+ Bond tmp = chain.bonds.elementAt(i);
+ tmp.startCol = Color.lightGray;
+ tmp.endCol = Color.lightGray;
+ if (chain != mainchain)
+ {
+ continue;
+ }
+
+ for (int s = 0; s < sequence.length; s++)
{
- if (fatom.alignmentMapping != -1)
+ for (int m = 0; m < mapping.length; m++)
{
- if (highlightRes == null)
- highlightRes = new Vector();
+ if (mapping[m].getSequence() == sequence[s])
+ {
+ int pos = mapping[m].getSeqPos(tmp.at1.resNumber) - 1;
+ if (pos > 0)
+ {
+ pos = sequence[s].findIndex(pos);
+ tmp.startCol = sr.getResidueBoxColour(sequence[s], pos);
+ if (showFeatures)
+ {
+ tmp.startCol = fr.findFeatureColour(tmp.startCol,
+ sequence[s], pos);
+ }
+ }
+ pos = mapping[m].getSeqPos(tmp.at2.resNumber) - 1;
+ if (pos > 0)
+ {
+ pos = sequence[s].findIndex(pos);
+ tmp.endCol = sr.getResidueBoxColour(sequence[s], pos);
+ if (showFeatures)
+ {
+ tmp.endCol = fr.findFeatureColour(tmp.endCol,
+ sequence[s], pos);
+ }
+ }
- 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;
+ }
}
+ }
- public void mouseMoved(MouseEvent e) {
- pdbAction = true;
- if(highlightBond1!=null)
+ Zsort zsort;
+
+ public void drawScene(Graphics g)
+ {
+ if (zbuffer)
+ {
+ if (zsort == null)
{
- highlightBond1.at2.isSelected = false;
- highlightBond2.at1.isSelected = false;
- highlightBond1 = null;
- highlightBond2 = null;
+ zsort = new Zsort();
}
- Atom fatom = findAtom(e.getX(), e.getY());
+ zsort.sort(visiblebonds);
+ }
- PDBChain chain = null;
- if(foundchain!=-1)
+ Bond tmpBond = null;
+ for (int i = 0; i < visiblebonds.size(); i++)
+ {
+ tmpBond = visiblebonds.elementAt(i);
+
+ xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getSize().width / 2));
+ ystart = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getSize().height / 2));
+
+ xend = (int) (((tmpBond.end[0] - centre[0]) * scale) + (getSize().width / 2));
+ yend = (int) (((centre[1] - tmpBond.end[1]) * scale) + (getSize().height / 2));
+
+ xmid = (xend + xstart) / 2;
+ ymid = (yend + ystart) / 2;
+
+ if (depthcue && !bymolecule)
+ {
+ if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))
{
- chain = (PDBChain) pdb.chains.elementAt(foundchain);
- if(chain == mainchain)
- {
- highlightSeqcanvas( fatom.alignmentMapping );
- }
+ 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);
- 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();
+ 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);
+ }
- void highlightSeqcanvas(int pos)
- {
- SearchResults searchResults = new SearchResults();
- if(highlightRes!=null)
+ }
+ else if (depthcue && bymolecule)
{
- for (int i = 0; i < highlightRes.size(); i++)
+ if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))
{
- int a = Integer.parseInt(highlightRes.elementAt(
- i).toString())+1;
-
- searchResults.addResult(sequence, a, a);
+ 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);
}
}
-
- if(pos!=-1)
+ 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
{
- searchResults.addResult(sequence, pos+1, pos+1);
+ drawLine(g, xstart, ystart, xend, yend);
}
- seqcanvas.highlightSearchResults(searchResults);
- }
+ 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 void mouseClicked(MouseEvent e) {
}
+ }
- public void mouseEntered(MouseEvent e) {
+ 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);
}
+ }
- public void mouseExited(MouseEvent e) {
+ public Dimension minimumsize()
+ {
+ return prefsize;
+ }
+
+ 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 mouseDragged(MouseEvent evt) {
- int x = evt.getX();
- int y = evt.getY();
- mx = x;
- my = y;
+ public void mousePressed(MouseEvent e)
+ {
+ pdbAction = true;
+ Atom fatom = findAtom(e.getX(), e.getY());
+ if (fatom != null)
+ {
+ fatom.isSelected = !fatom.isSelected;
- MCMatrix objmat = new MCMatrix(3, 3);
- objmat.setIdentity();
+ redrawneeded = true;
+ repaint();
+ if (foundchain != -1)
+ {
+ PDBChain chain = pdb.chains.elementAt(foundchain);
+ if (chain == mainchain)
+ {
+ if (fatom.alignmentMapping != -1)
+ {
+ if (highlightRes == null)
+ {
+ highlightRes = new Vector();
+ }
- if ((evt.getModifiers() & Event.META_MASK) != 0) {
- objmat.rotatez((float) ((mx - omx)));
- } else {
- objmat.rotatex((float) ((my - omy)));
- objmat.rotatey((float) ((omx - mx)));
+ final String atomString = Integer
+ .toString(fatom.alignmentMapping);
+ if (highlightRes.contains(atomString))
+ {
+ highlightRes.removeElement(atomString);
+ }
+ else
+ {
+ highlightRes.addElement(atomString);
+ }
+ }
}
+ }
- //Alter the bonds
- for (int ii = 0; ii < pdb.chains.size(); ii++) {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+ }
+ 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;
+ }
- for (int i = 0; i < bonds.size(); i++) {
- Bond tmpBond = (Bond) bonds.elementAt(i);
+ Atom fatom = findAtom(e.getX(), e.getY());
- //Translate the bond so the centre is 0,0,0
- tmpBond.translate(-centre[0], -centre[1], -centre[2]);
+ PDBChain chain = null;
+ if (foundchain != -1)
+ {
+ chain = pdb.chains.elementAt(foundchain);
+ if (chain == mainchain)
+ {
+ mouseOverStructure(fatom.resNumber, chain.id);
+ }
+ }
- //Now apply the rotation matrix
- tmpBond.start = objmat.vectorMultiply(tmpBond.start);
- tmpBond.end = objmat.vectorMultiply(tmpBond.end);
+ if (fatom != null)
+ {
+ toolx = e.getX();
+ tooly = e.getY();
- //Now translate back again
- tmpBond.translate(centre[0], centre[1], centre[2]);
- }
- }
+ appletToolTip = chain.id + ":" + fatom.resNumber + " "
+ + fatom.resName;
+ redrawneeded = true;
+ repaint();
+ }
+ else
+ {
+ mouseOverStructure(-1, chain != null ? chain.id : null);
+ appletToolTip = null;
+ redrawneeded = true;
+ repaint();
+ }
+ }
- objmat = null;
+ public void mouseClicked(MouseEvent e)
+ {
+ }
- omx = mx;
- omy = my;
+ public void mouseEntered(MouseEvent e)
+ {
+ }
- dragging = true;
+ public void mouseExited(MouseEvent e)
+ {
+ }
- redrawneeded = true;
+ 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();
- repaint();
+ if ((evt.getModifiers() & Event.META_MASK) != 0)
+ {
+ objmat.rotatez(((mx - omx)));
}
+ else
+ {
+ objmat.rotatex(((omy - my)));
+ objmat.rotatey(((omx - mx)));
+ }
+
+ // Alter the bonds
+ for (PDBChain chain : pdb.chains)
+ {
+ for (Bond tmpBond : chain.bonds)
+ {
+ // 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);
- public void mouseReleased(MouseEvent evt) {
- dragging = false;
- return;
+ // Now translate back again
+ tmpBond.translate(centre[0], centre[1], centre[2]);
+ }
}
- void drawLabels(Graphics g) {
+ objmat = null;
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+ omx = mx;
+ omy = my;
- if (chain.isVisible)
- {
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+ dragging = true;
- for (int i = 0; i < bonds.size(); i++)
- {
- Bond tmpBond = (Bond) bonds.elementAt(i);
+ redrawneeded = true;
- if (tmpBond.at1.isSelected)
- {
- labelAtom(g, tmpBond, 1);
- }
+ repaint();
+ }
- if (tmpBond.at2.isSelected)
- {
+ public void mouseReleased(MouseEvent evt)
+ {
+ dragging = false;
+ return;
+ }
- labelAtom(g, tmpBond, 2);
- }
- }
- }
+ void drawLabels(Graphics g)
+ {
+
+ for (PDBChain chain : pdb.chains)
+ {
+ if (chain.isVisible)
+ {
+ for (Bond tmpBond : chain.bonds)
+ {
+ if (tmpBond.at1.isSelected)
+ {
+ labelAtom(g, tmpBond, 1);
+ }
+
+ if (tmpBond.at2.isSelected)
+ {
+ 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) (((centre[1] - b.start[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) (((centre[1] - b.end[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;
+
+ foundchain = -1;
- int foundchain = -1;
- public Atom findAtom(int x, int y) {
- Atom fatom = null;
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = pdb.chains.elementAt(ii);
+ int truex;
+ Bond tmpBond = null;
- foundchain = -1;
+ if (chain.isVisible)
+ {
+ Vector bonds = 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 = bonds.elementAt(i);
+
+ truex = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getSize().width / 2));
- if (chain.isVisible)
+ if (Math.abs(truex - x) <= 2)
+ {
+ int truey = (int) (((centre[1] - tmpBond.start[1]) * scale) + (getSize().height / 2));
+
+ if (Math.abs(truey - y) <= 2)
{
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+ fatom = tmpBond.at1;
+ foundchain = ii;
+ break;
+ }
+ }
+ }
- 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
- // Still here? Maybe its the last bond
+ truex = (int) (((tmpBond.end[0] - centre[0]) * scale) + (getSize().width / 2));
- truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +
- (getSize().width / 2));
+ if (Math.abs(truex - x) <= 2)
+ {
+ int truey = (int) (((tmpBond.end[1] - centre[1]) * scale) + (getSize().height / 2));
- 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 (Math.abs(truey - y) <= 2)
- {
- fatom = tmpBond.at2;
- foundchain = ii;
- break;
- }
- }
+ }
- }
+ if (fatom != null) // )&& chain.ds != null)
+ {
+ chain = pdb.chains.elementAt(foundchain);
+ }
+ }
- if (fatom != null) //)&& chain.ds != null)
- {
- chain = (PDBChain) pdb.chains.elementAt(foundchain);
- }
- }
+ return fatom;
+ }
+
+ public void update(Graphics g)
+ {
+ paint(g);
+ }
- return fatom;
+ public void highlightRes(int ii)
+ {
+ if (!seqColoursReady)
+ {
+ return;
}
- public void update(Graphics g)
+ if (highlightRes != null && highlightRes.contains((ii - 1) + ""))
{
- paint(g);
+ return;
}
- public void highlightRes(int ii)
- {
- if(!seqColoursReady)
- return;
+ int index = -1;
+ Bond tmpBond;
+ for (index = 0; index < mainchain.bonds.size(); index++)
+ {
+ tmpBond = mainchain.bonds.elementAt(index);
+ if (tmpBond.at1.alignmentMapping == ii - 1)
+ {
+ if (highlightBond1 != null)
+ {
+ highlightBond1.at2.isSelected = false;
+ }
+
+ if (highlightBond2 != null)
+ {
+ highlightBond2.at1.isSelected = false;
+ }
- if (highlightRes != null
- && highlightRes.contains((ii-1) + ""))
- {
- return;
- }
+ highlightBond1 = null;
+ highlightBond2 = null;
- int index = -1;
- Bond tmpBond;
- for(index=0; index 0)
+ {
+ highlightBond1 = mainchain.bonds.elementAt(index - 1);
+ highlightBond1.at2.isSelected = true;
+ }
- if (highlightBond2 != null)
- highlightBond2.at1.isSelected = false;
+ if (index != mainchain.bonds.size())
+ {
+ highlightBond2 = 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;
- }
+ redrawneeded = true;
+ repaint();
+ }
- if (index != mainchain.bonds.size())
- {
- highlightBond2 = (Bond) mainchain.bonds.elementAt(index);
- highlightBond2.at1.isSelected = true;
- }
+ public void setAllchainsVisible(boolean b)
+ {
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = pdb.chains.elementAt(ii);
+ chain.isVisible = b;
+ }
+ mainchain.isVisible = true;
+ findCentre();
+ setupBonds();
+ }
+
+ // ////////////////////////////////
+ // /StructureListener
+ public String[] getPdbFile()
+ {
+ return new String[]
+ { pdbentry.getFile() };
+ }
+
+ String lastMessage;
+
+ public void mouseOverStructure(int pdbResNum, String chain)
+ {
+ if (lastMessage == null || !lastMessage.equals(pdbResNum + chain))
+ {
+ ssm.mouseOverStructure(pdbResNum, chain, pdbentry.getFile());
+ }
- break;
- }
- }
+ lastMessage = pdbResNum + chain;
+ }
- redrawneeded = true;
- repaint();
- }
+ StringBuffer resetLastRes = new StringBuffer();
+ StringBuffer eval = new StringBuffer();
- public void setAllchainsVisible(boolean b)
+ /**
+ * Highlight the specified atoms in the structure.
+ *
+ * @param atoms
+ */
+ @Override
+ public void highlightAtoms(List atoms)
+ {
+ if (!seqColoursReady)
{
- for (int ii = 0; ii < pdb.chains.size(); ii++)
+ return;
+ }
+ for (AtomSpec atom : atoms)
+ {
+ int atomIndex = atom.getAtomIndex();
+
+ if (highlightRes != null
+ && highlightRes.contains((atomIndex - 1) + ""))
{
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
- chain.isVisible = b;
+ continue;
}
- mainchain.isVisible = true;
- findCentre();
- setupBonds();
+
+ highlightAtom(atomIndex);
}
+ redrawneeded = true;
+ repaint();
+ }
+
+ /**
+ * @param atomIndex
+ */
+ protected void highlightAtom(int atomIndex)
+ {
+ int index = -1;
+ Bond tmpBond;
+ for (index = 0; index < mainchain.bonds.size(); index++)
+ {
+ tmpBond = mainchain.bonds.elementAt(index);
+ if (tmpBond.at1.atomIndex == atomIndex)
+ {
+ if (highlightBond1 != null)
+ {
+ highlightBond1.at2.isSelected = false;
+ }
+
+ if (highlightBond2 != null)
+ {
+ highlightBond2.at1.isSelected = false;
+ }
+
+ highlightBond1 = null;
+ highlightBond2 = null;
+
+ if (index > 0)
+ {
+ highlightBond1 = mainchain.bonds.elementAt(index - 1);
+ highlightBond1.at2.isSelected = true;
+ }
+
+ if (index != mainchain.bonds.size())
+ {
+ highlightBond2 = mainchain.bonds.elementAt(index);
+ highlightBond2.at1.isSelected = true;
+ }
+
+ break;
+ }
+ }
+ }
+
+ public Color getColour(int atomIndex, int pdbResNum, String chain,
+ String pdbfile)
+ {
+ return Color.white;
+ // if (!pdbfile.equals(pdbentry.getFile()))
+ // return null;
+
+ // return new Color(viewer.getAtomArgb(atomIndex));
+ }
+
+ public void updateColours(Object source)
+ {
+ colourBySequence();
+ redrawneeded = true;
+ repaint();
+ }
+
+ @Override
+ public void releaseReferences(Object svl)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean isListeningFor(SequenceI seq)
+ {
+ if (sequence != null)
+ {
+ for (SequenceI s : sequence)
+ {
+ if (s == seq)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}