int xmid;\r
int ymid;\r
Font font = new Font("Helvetica", Font.PLAIN, 10);\r
- jalview.gui.SequenceRenderer sr;\r
- jalview.gui.FeatureRenderer fr;\r
jalview.gui.SeqCanvas seqcanvas;\r
public Sequence sequence;\r
final StringBuffer mappingDetails = new StringBuffer();\r
PDBChain mainchain;\r
+ Vector highlightRes;\r
+ boolean pdbAction = false;\r
\r
public PDBCanvas(jalview.gui.SeqCanvas seqcanvas, Sequence seq)\r
{\r
this.seqcanvas = seqcanvas;\r
this.sequence = seq;\r
- sr = seqcanvas.getSequenceRenderer();\r
- fr = seqcanvas.getFeatureRenderer();\r
-\r
seqcanvas.setPDBCanvas(this);\r
}\r
\r
public void setPDBFile(PDBfile pdb)\r
{\r
- this.sr = sr;\r
- this.fr = fr;\r
int max = -10;\r
int maxchain = -1;\r
int pdbstart = 0;\r
int pdbend = 0;\r
int seqstart = 0;\r
int seqend = 0;\r
+ int [] mapping = null;\r
\r
for (int i = 0; i < pdb.chains.size(); i++)\r
{\r
\r
as.printAlignment(ps);\r
\r
- if (as.maxscore > max) {\r
+\r
+\r
+ if (as.maxscore > max)\r
+ {\r
max = as.maxscore;\r
maxchain = i;\r
-\r
pdbstart = as.seq2start;\r
pdbend = as.seq2end;\r
seqstart = as.seq1start + sequence.getStart()-1;\r
seqend = as.seq1end + sequence.getEnd()-1;\r
+ mapping = as.getExactMapping();\r
}\r
\r
mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);\r
mainchain.seqstart = seqstart;\r
mainchain.seqend = seqend;\r
mainchain.isVisible = true;\r
- mainchain.sequence = sequence;\r
+ mainchain.seqMapping = mapping;\r
+ // mainchain.sequence = sequence;\r
\r
- this.pdb = pdb;\r
+ this.pdb = pdb;\r
this.prefsize = new Dimension(getWidth(), getHeight());\r
\r
//Initialize the matrices to identity\r
findCentre();\r
findWidth();\r
\r
+ setupBonds();\r
+\r
scale = findScale();\r
\r
\r
ToolTipManager.sharedInstance().registerComponent(this);\r
ToolTipManager.sharedInstance().setInitialDelay(0);\r
ToolTipManager.sharedInstance().setDismissDelay(10000);\r
+ }\r
+\r
+ Vector visiblebonds;\r
+ void setupBonds()\r
+ {\r
+ // Sort the bonds by z coord\r
+ visiblebonds = new Vector();\r
+\r
+ for (int ii = 0; ii < pdb.chains.size(); ii++)\r
+ {\r
+ if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)\r
+ {\r
+ Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;\r
\r
+ for (int i = 0; i < tmp.size(); i++)\r
+ {\r
+ visiblebonds.addElement(tmp.elementAt(i));\r
+ }\r
+ }\r
+ }\r
}\r
\r
- public void deleteBonds() {\r
+ public void deleteBonds() {\r
scale = 0;\r
maxwidth = 0;\r
\r
centre[2] = ztot / (2 * (float) bsize);\r
}\r
\r
- public void paintComponent(Graphics g) {\r
-\r
+ public void paintComponent(Graphics g)\r
+ {\r
super.paintComponent(g);\r
\r
if(pdb==null)\r
\r
//Only create the image at the beginning -\r
//this saves much memory usage\r
- if ((img == null) || (prefsize.width != getWidth()) ||\r
- (prefsize.height != getHeight())) {\r
+ if ((img == null)\r
+ || (prefsize.width != getWidth())\r
+ || (prefsize.height != getHeight()))\r
+\r
+ {\r
prefsize.width = getWidth();\r
prefsize.height = getHeight();\r
\r
ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
RenderingHints.VALUE_ANTIALIAS_ON);\r
\r
-\r
redrawneeded = true;\r
}\r
\r
}\r
\r
g.drawImage(img, 0, 0, this);\r
+\r
+ pdbAction = false;\r
}\r
\r
public void drawAll(Graphics g, int width, int height)\r
\r
public void updateSeqColours()\r
{\r
+ if(pdbAction)\r
+ {\r
+ return;\r
+ }\r
+\r
+ // System.out.println("update seq colours");\r
if(bysequence && pdb!=null)\r
{\r
for (int ii = 0; ii < pdb.chains.size(); ii++)\r
\r
redrawneeded=true;\r
repaint();\r
-\r
}\r
\r
// This method has been taken out of PDBChain to allow\r
// Applet and Application specific sequence renderers to be used\r
void colourBySequence(PDBChain chain)\r
{\r
+ // System.out.println("colour by seq");\r
for (int i = 0; i < chain.bonds.size(); i++)\r
{\r
Bond tmp = (Bond) chain.bonds.elementAt(i);\r
+ tmp.startCol = Color.lightGray;\r
+ tmp.endCol = Color.lightGray;\r
\r
if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&\r
(tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))\r
{\r
- int pos = chain.seqstart +\r
- (tmp.at1.resNumber - chain.pdbstart - chain.offset);\r
-\r
- int index = sequence.findIndex(pos);\r
\r
- tmp.startCol = sr.findSequenceColour(Color.lightGray, sequence, index);\r
+ int pos = // chain.seqstart + Don't include seqstart here, start from 0\r
+ (tmp.at1.resNumber - chain.pdbstart - chain.offset)+1;\r
\r
- tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);\r
+ int index = chain.seqMapping[pos];\r
+ if (index != -1)\r
+ {\r
+ tmp.startCol = seqcanvas.getSequenceRenderer().findSequenceColour(\r
+ Color.lightGray, sequence, index);\r
\r
- }\r
- else\r
- {\r
- tmp.startCol = Color.gray;\r
+ tmp.startCol = seqcanvas.getFeatureRenderer().findFeatureColour(tmp.\r
+ startCol, sequence, index);\r
+ }\r
}\r
\r
if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&\r
(tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1)))\r
{\r
- int pos = chain.seqstart +\r
- (tmp.at2.resNumber - chain.pdbstart - chain.offset);\r
- int index = sequence.findIndex(pos);\r
+ int pos = // chain.seqstart + Don't include seqstart here, start from 0\r
+ (tmp.at2.resNumber - chain.pdbstart - chain.offset)+1;\r
\r
- tmp.endCol = sr.findSequenceColour(tmp.endCol, sequence, index);\r
- tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);\r
- }\r
- else\r
- {\r
- tmp.endCol = Color.gray;\r
+ int index = chain.seqMapping[pos];\r
+ if (index != -1)\r
+ {\r
+ tmp.endCol = seqcanvas.getSequenceRenderer().findSequenceColour(\r
+ tmp.endCol, sequence, index);\r
+ tmp.endCol = seqcanvas.getFeatureRenderer().findFeatureColour(tmp.\r
+ endCol, sequence, index);\r
+ }\r
}\r
}\r
}\r
\r
\r
- public void drawScene(Graphics g) {\r
- // Sort the bonds by z coord\r
- Vector bonds = new Vector();\r
-\r
- for (int ii = 0; ii < pdb.chains.size(); ii++)\r
- {\r
- if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)\r
- {\r
- Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;\r
+ public void drawScene(Graphics g)\r
+ {\r
\r
- for (int i = 0; i < tmp.size(); i++)\r
- {\r
- bonds.addElement(tmp.elementAt(i));\r
- }\r
- }\r
- }\r
\r
- if (zbuffer) {\r
- Zsort.Zsort(bonds);\r
+ if (zbuffer)\r
+ {\r
+ Zsort.Zsort(visiblebonds);\r
}\r
\r
Bond tmpBond=null;\r
- for (int i = 0; i < bonds.size(); i++) {\r
- tmpBond = (Bond) bonds.elementAt(i);\r
+ for (int i = 0; i < visiblebonds.size(); i++)\r
+ {\r
+ tmpBond = (Bond) visiblebonds.elementAt(i);\r
\r
xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) +\r
(getWidth() / 2));\r
xmid = (xend + xstart) / 2;\r
ymid = (yend + ystart) / 2;\r
\r
- if (depthcue && !bymolecule) {\r
+ if (depthcue && !bymolecule)\r
+ {\r
if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {\r
g.setColor(tmpBond.startCol.darker().darker());\r
drawLine(g, xstart, ystart, xmid, ymid);\r
}\r
}\r
\r
- public void mousePressed(MouseEvent e) {\r
+ public void mousePressed(MouseEvent e)\r
+ {\r
+ pdbAction = true;\r
Atom fatom = findAtom(e.getX(), e.getY());\r
if(fatom!=null)\r
{\r
fatom.isSelected = !fatom.isSelected;\r
+\r
redrawneeded = true;\r
repaint();\r
+ if (foundchain != -1)\r
+ {\r
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
+ if (chain == mainchain)\r
+ {\r
+ int pos = // chain.seqstart + Don't include seqstart here, start from 0\r
+ (fatom.resNumber - chain.pdbstart - chain.offset) +1 ;\r
+\r
+ if (chain.seqMapping[pos] != -1)\r
+ {\r
+ if (highlightRes == null)\r
+ highlightRes = new Vector();\r
+\r
+ if (highlightRes.contains((chain.seqMapping[pos]) + ""))\r
+ highlightRes.remove((chain.seqMapping[pos]) + "");\r
+ else\r
+ highlightRes.add((chain.seqMapping[pos]) + "");\r
+ }\r
+ }\r
+ }\r
+\r
}\r
mx = e.getX();\r
my = e.getY();\r
dragging = false;\r
}\r
\r
- public void mouseMoved(MouseEvent e) {\r
+ public void mouseMoved(MouseEvent e)\r
+ {\r
+ pdbAction = true;\r
+ if(highlightBond1!=null)\r
+ {\r
+ highlightBond1.at2.isSelected = false;\r
+ highlightBond2.at1.isSelected = false;\r
+ highlightBond1 = null;\r
+ highlightBond2 = null;\r
+ }\r
\r
Atom fatom = findAtom(e.getX(), e.getY());\r
\r
chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
if(chain == mainchain)\r
{\r
- int pos = chain.seqstart +\r
- (fatom.resNumber - chain.pdbstart - chain.offset) + 1;\r
-\r
- int index = seqcanvas.getViewport().getAlignment().findIndex(\r
- sequence);\r
+ int pos = // chain.seqstart + Don't include seqstart here, start from 0\r
+ (fatom.resNumber - chain.pdbstart - chain.offset) +1 ;\r
\r
- seqcanvas.highlightSearchResults(new int[]\r
- {index, pos, pos});\r
+ highlightSeqcanvas( chain.seqMapping[pos] );\r
}\r
}\r
- else\r
- seqcanvas.highlightSearchResults(null);\r
\r
if (fatom != null)\r
{\r
this.setToolTipText(chain.id+":"+ fatom.resNumber+" "+ fatom.resName);\r
} else\r
{\r
- this.setToolTipText("");\r
+ highlightSeqcanvas( -1);\r
+ this.setToolTipText(null);\r
}\r
}\r
\r
- public void mouseClicked(MouseEvent e) {\r
- }\r
\r
- public void mouseEntered(MouseEvent e) {\r
- }\r
+ void highlightSeqcanvas(int pos)\r
+ {\r
+ int index = seqcanvas.getViewport().getAlignment().findIndex(sequence);\r
\r
- public void mouseExited(MouseEvent e) {\r
+ int size = pos==-1?0:3;\r
+\r
+ if(highlightRes!=null)\r
+ size += highlightRes.size()*3;\r
+\r
+ int [] array = new int[size];\r
+ int i=0;\r
+ if(highlightRes!=null)\r
+ {\r
+ for (i = 0; i < highlightRes.size(); i++)\r
+ {\r
+ int a = Integer.parseInt(highlightRes.elementAt(\r
+ i).toString())+1;\r
+ array[i * 3] = index;\r
+ array[ (i * 3) + 1] = a;\r
+ array[ (i * 3) + 2] = a;\r
+ }\r
+ }\r
+\r
+ if(pos!=-1)\r
+ {\r
+ array[i * 3] = index;\r
+ array[i * 3 + 1] = pos+1;\r
+ array[i * 3 + 2] = pos+1;\r
+ }\r
+\r
+ seqcanvas.highlightSearchResults(array);\r
}\r
\r
- public void mouseDragged(MouseEvent evt) {\r
+\r
+ public void mouseClicked(MouseEvent e) { }\r
+\r
+ public void mouseEntered(MouseEvent e) { }\r
+\r
+ public void mouseExited(MouseEvent e) { }\r
+\r
+ public void mouseDragged(MouseEvent evt)\r
+ {\r
int x = evt.getX();\r
int y = evt.getY();\r
mx = x;\r
my = y;\r
\r
+\r
MCMatrix objmat = new MCMatrix(3, 3);\r
objmat.setIdentity();\r
\r
repaint();\r
}\r
\r
- public void mouseReleased(MouseEvent evt) {\r
+ public void mouseReleased(MouseEvent evt)\r
+ {\r
dragging = false;\r
return;\r
}\r
\r
if (chain.isVisible)\r
{\r
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;\r
\r
- for (int i = 0; i < bonds.size(); i++)\r
+ for (int i = 0; i < chain.bonds.size(); i++)\r
{\r
- Bond tmpBond = (Bond) bonds.elementAt(i);\r
+ Bond tmpBond = (Bond) chain.bonds.elementAt(i);\r
\r
if (tmpBond.at1.isSelected)\r
{\r
labelAtom(g, tmpBond, 1);\r
}\r
-\r
- if (tmpBond.at2.isSelected)\r
+ else if (tmpBond.at2.isSelected)\r
{\r
-\r
labelAtom(g, tmpBond, 2);\r
}\r
}\r
\r
public void labelAtom(Graphics g, Bond b, int n) {\r
g.setFont(font);\r
-\r
- if (n == 1) {\r
+ g.setColor(Color.red);\r
+ if (n == 1)\r
+ {\r
int xstart = (int) (((b.start[0] - centre[0]) * scale) +\r
(getWidth() / 2));\r
int ystart = (int) (((b.start[1] - centre[1]) * scale) +\r
(getHeight() / 2));\r
\r
- g.setColor(Color.red);\r
g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);\r
}\r
\r
int ystart = (int) (((b.end[1] - centre[1]) * scale) +\r
(getHeight() / 2));\r
\r
- g.setColor(Color.red);\r
g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);\r
}\r
}\r
}\r
\r
Bond highlightBond1, highlightBond2;\r
+ String alignMouseOver;\r
public void highlightRes(int ii)\r
{\r
+\r
+ int index = ii - mainchain.seqstart;\r
+\r
+ if (highlightRes!=null\r
+ && highlightRes.contains( mainchain.seqMapping[index]+ ""))\r
+ {\r
+ return;\r
+ }\r
+\r
+ if(highlightBond1!=null)\r
+ highlightBond1.at2.isSelected = false;\r
+\r
+ if(highlightBond2!=null)\r
+ highlightBond2.at1.isSelected = false;\r
+\r
highlightBond1 = null;\r
highlightBond2 = null;\r
\r
- int index = ii - mainchain.seqstart;\r
+\r
\r
if(index <0 )\r
return;\r
if(index>0)\r
{\r
highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);\r
+ highlightBond1.at2.isSelected = true;\r
+ // highlightBond1.at2.isSelected = true;\r
}\r
\r
if(index!=mainchain.bonds.size())\r
+ {\r
highlightBond2 = (Bond) mainchain.bonds.elementAt(index);\r
+ highlightBond2.at1.isSelected = true;\r
+ // highlightBond2.at2.isSelected = true;\r
+ }\r
}\r
\r
redrawneeded = true;\r
}\r
mainchain.isVisible = true;\r
findCentre();\r
+ setupBonds();\r
+ redrawneeded = true;\r
+ repaint();\r
}\r
}\r