Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 13:01:17 GMT
  2. Package mc_view

File PDBCanvas.java

 

Coverage histogram

../img/srcFileCovDistChart0.png
59% of files have more coverage

Code metrics

198
442
37
1
1,224
941
149
0.34
11.95
37
4.03

Classes

Class Line # Actions
PDBCanvas 58 442 149
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package mc_view;
22   
23    import jalview.analysis.AlignSeq;
24    import jalview.datamodel.PDBEntry;
25    import jalview.datamodel.SequenceI;
26    import jalview.gui.AlignmentPanel;
27    import jalview.gui.FeatureRenderer;
28    import jalview.gui.SequenceRenderer;
29    import jalview.io.DataSourceType;
30    import jalview.io.StructureFile;
31    import jalview.renderer.seqfeatures.FeatureColourFinder;
32    import jalview.structure.AtomSpec;
33    import jalview.structure.StructureListener;
34    import jalview.structure.StructureMapping;
35    import jalview.structure.StructureSelectionManager;
36   
37    import java.awt.Color;
38    import java.awt.Dimension;
39    import java.awt.Event;
40    import java.awt.Font;
41    import java.awt.Graphics;
42    import java.awt.Graphics2D;
43    // JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug
44    import java.awt.Image;
45    import java.awt.RenderingHints;
46    import java.awt.event.KeyAdapter;
47    import java.awt.event.KeyEvent;
48    import java.awt.event.MouseEvent;
49    import java.awt.event.MouseListener;
50    import java.awt.event.MouseMotionListener;
51    import java.io.PrintStream;
52    import java.util.List;
53    import java.util.Vector;
54   
55    import javax.swing.JPanel;
56    import javax.swing.ToolTipManager;
57   
 
58    public class PDBCanvas extends JPanel
59    implements MouseListener, MouseMotionListener, StructureListener
60    {
61    boolean redrawneeded = true;
62   
63    int omx = 0;
64   
65    int mx = 0;
66   
67    int omy = 0;
68   
69    int my = 0;
70   
71    public StructureFile pdb;
72   
73    PDBEntry pdbentry;
74   
75    int bsize;
76   
77    Image img;
78   
79    Graphics ig;
80   
81    Dimension prefsize;
82   
83    float[] centre = new float[3];
84   
85    float[] width = new float[3];
86   
87    float maxwidth;
88   
89    float scale;
90   
91    String inStr;
92   
93    String inType;
94   
95    boolean bysequence = true;
96   
97    boolean depthcue = true;
98   
99    boolean wire = false;
100   
101    boolean bymolecule = false;
102   
103    boolean zbuffer = true;
104   
105    boolean dragging;
106   
107    int xstart;
108   
109    int xend;
110   
111    int ystart;
112   
113    int yend;
114   
115    int xmid;
116   
117    int ymid;
118   
119    Font font = new Font("Helvetica", Font.PLAIN, 10);
120   
121    jalview.gui.SeqCanvas seqcanvas;
122   
123    public SequenceI[] sequence;
124   
125    final StringBuffer mappingDetails = new StringBuffer();
126   
127    PDBChain mainchain;
128   
129    Vector<String> highlightRes;
130   
131    boolean pdbAction = false;
132   
133    boolean seqColoursReady = false;
134   
135    jalview.renderer.seqfeatures.FeatureRenderer fr;
136   
137    Color backgroundColour = Color.black;
138   
139    AlignmentPanel ap;
140   
141    StructureSelectionManager ssm;
142   
143    String errorMessage;
144   
 
145  0 toggle void init(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
146    AlignmentPanel ap, DataSourceType protocol)
147    {
148  0 this.ap = ap;
149  0 this.pdbentry = pdbentry;
150  0 this.sequence = seq;
151   
152  0 ssm = ap.av.getStructureSelectionManager();
153   
154  0 try
155    {
156  0 pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol,
157    ap.alignFrame);
158   
159  0 if (protocol.equals(jalview.io.DataSourceType.PASTE))
160    {
161  0 pdbentry.setFile("INLINE" + pdb.getId());
162    }
163   
164    } catch (Exception ex)
165    {
166  0 ex.printStackTrace();
167  0 return;
168    }
169   
170  0 if (pdb == null)
171    {
172  0 errorMessage = "Error loading file: " + pdbentry.getId();
173  0 return;
174    }
175  0 pdbentry.setId(pdb.getId());
176   
177  0 ssm.addStructureViewerListener(this);
178   
179  0 colourBySequence();
180   
181  0 float max = -10;
182  0 int maxchain = -1;
183  0 int pdbstart = 0;
184  0 int pdbend = 0;
185  0 int seqstart = 0;
186  0 int seqend = 0;
187   
188    // JUST DEAL WITH ONE SEQUENCE FOR NOW
189  0 SequenceI sequence = seq[0];
190   
191  0 for (int i = 0; i < pdb.getChains().size(); i++)
192    {
193   
194  0 mappingDetails.append("\n\nPDB Sequence is :\nSequence = "
195    + pdb.getChains().elementAt(i).sequence
196    .getSequenceAsString());
197  0 mappingDetails.append("\nNo of residues = "
198    + pdb.getChains().elementAt(i).residues.size() + "\n\n");
199   
200    // Now lets compare the sequences to get
201    // the start and end points.
202    // Align the sequence to the pdb
203  0 AlignSeq as = new AlignSeq(sequence,
204    pdb.getChains().elementAt(i).sequence, "pep");
205  0 as.calcScoreMatrix();
206  0 as.traceAlignment();
207  0 PrintStream ps = new PrintStream(System.out)
208    {
 
209  0 toggle @Override
210    public void print(String x)
211    {
212  0 mappingDetails.append(x);
213    }
214   
 
215  0 toggle @Override
216    public void println()
217    {
218  0 mappingDetails.append("\n");
219    }
220    };
221   
222  0 as.printAlignment(ps);
223   
224  0 if (as.maxscore > max)
225    {
226  0 max = as.maxscore;
227  0 maxchain = i;
228   
229  0 pdbstart = as.seq2start;
230  0 pdbend = as.seq2end;
231  0 seqstart = as.seq1start + sequence.getStart() - 1;
232  0 seqend = as.seq1end + sequence.getEnd() - 1;
233    }
234   
235  0 mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);
236  0 mappingDetails.append("\nSEQ start/end " + seqstart + " " + seqend);
237    }
238   
239  0 mainchain = pdb.getChains().elementAt(maxchain);
240   
241  0 mainchain.pdbstart = pdbstart;
242  0 mainchain.pdbend = pdbend;
243  0 mainchain.seqstart = seqstart;
244  0 mainchain.seqend = seqend;
245  0 mainchain.isVisible = true;
246   
247  0 this.pdb = pdb;
248  0 this.prefsize = new Dimension(getSize().width, getSize().height);
249   
250  0 addMouseMotionListener(this);
251  0 addMouseListener(this);
252   
253  0 addKeyListener(new KeyAdapter()
254    {
 
255  0 toggle @Override
256    public void keyPressed(KeyEvent evt)
257    {
258  0 keyPressed(evt);
259    }
260    });
261   
262  0 findCentre();
263  0 findWidth();
264   
265  0 setupBonds();
266   
267  0 scale = findScale();
268   
269  0 ToolTipManager.sharedInstance().registerComponent(this);
270  0 ToolTipManager.sharedInstance().setInitialDelay(0);
271  0 ToolTipManager.sharedInstance().setDismissDelay(10000);
272    }
273   
274    Vector<Bond> visiblebonds;
275   
 
276  0 toggle void setupBonds()
277    {
278  0 seqColoursReady = false;
279    // Sort the bonds by z coord
280  0 visiblebonds = new Vector<Bond>();
281   
282  0 for (PDBChain chain : pdb.getChains())
283    {
284  0 if (chain.isVisible)
285    {
286  0 for (Bond bond : chain.bonds)
287    {
288  0 visiblebonds.addElement(bond);
289    }
290    }
291    }
292   
293  0 updateSeqColours();
294  0 seqColoursReady = true;
295  0 redrawneeded = true;
296  0 repaint();
297    }
298   
 
299  0 toggle public void findWidth()
300    {
301  0 float[] max = new float[3];
302  0 float[] min = new float[3];
303   
304  0 max[0] = (float) -1e30;
305  0 max[1] = (float) -1e30;
306  0 max[2] = (float) -1e30;
307   
308  0 min[0] = (float) 1e30;
309  0 min[1] = (float) 1e30;
310  0 min[2] = (float) 1e30;
311   
312  0 for (PDBChain chain : pdb.getChains())
313    {
314  0 if (chain.isVisible)
315    {
316  0 for (Bond tmp : chain.bonds)
317    {
318  0 if (tmp.start[0] >= max[0])
319    {
320  0 max[0] = tmp.start[0];
321    }
322   
323  0 if (tmp.start[1] >= max[1])
324    {
325  0 max[1] = tmp.start[1];
326    }
327   
328  0 if (tmp.start[2] >= max[2])
329    {
330  0 max[2] = tmp.start[2];
331    }
332   
333  0 if (tmp.start[0] <= min[0])
334    {
335  0 min[0] = tmp.start[0];
336    }
337   
338  0 if (tmp.start[1] <= min[1])
339    {
340  0 min[1] = tmp.start[1];
341    }
342   
343  0 if (tmp.start[2] <= min[2])
344    {
345  0 min[2] = tmp.start[2];
346    }
347   
348  0 if (tmp.end[0] >= max[0])
349    {
350  0 max[0] = tmp.end[0];
351    }
352   
353  0 if (tmp.end[1] >= max[1])
354    {
355  0 max[1] = tmp.end[1];
356    }
357   
358  0 if (tmp.end[2] >= max[2])
359    {
360  0 max[2] = tmp.end[2];
361    }
362   
363  0 if (tmp.end[0] <= min[0])
364    {
365  0 min[0] = tmp.end[0];
366    }
367   
368  0 if (tmp.end[1] <= min[1])
369    {
370  0 min[1] = tmp.end[1];
371    }
372   
373  0 if (tmp.end[2] <= min[2])
374    {
375  0 min[2] = tmp.end[2];
376    }
377    }
378    }
379    }
380    /*
381    * System.out.println("xmax " + max[0] + " min " + min[0]);
382    * System.out.println("ymax " + max[1] + " min " + min[1]);
383    * System.out.println("zmax " + max[2] + " min " + min[2]);
384    */
385   
386  0 width[0] = Math.abs(max[0] - min[0]);
387  0 width[1] = Math.abs(max[1] - min[1]);
388  0 width[2] = Math.abs(max[2] - min[2]);
389   
390  0 maxwidth = width[0];
391   
392  0 if (width[1] > width[0])
393    {
394  0 maxwidth = width[1];
395    }
396   
397  0 if (width[2] > width[1])
398    {
399  0 maxwidth = width[2];
400    }
401   
402    // System.out.println("Maxwidth = " + maxwidth);
403    }
404   
 
405  0 toggle public float findScale()
406    {
407  0 int dim;
408  0 int width;
409  0 int height;
410   
411  0 if (getWidth() != 0)
412    {
413  0 width = getWidth();
414  0 height = getHeight();
415    }
416    else
417    {
418  0 width = prefsize.width;
419  0 height = prefsize.height;
420    }
421   
422  0 if (width < height)
423    {
424  0 dim = width;
425    }
426    else
427    {
428  0 dim = height;
429    }
430   
431  0 return (float) (dim / (1.5d * maxwidth));
432    }
433   
 
434  0 toggle public void findCentre()
435    {
436  0 float xtot = 0;
437  0 float ytot = 0;
438  0 float ztot = 0;
439   
440  0 int bsize = 0;
441   
442    // Find centre coordinate
443  0 for (PDBChain chain : pdb.getChains())
444    {
445  0 if (chain.isVisible)
446    {
447  0 bsize += chain.bonds.size();
448   
449  0 for (Bond bond : chain.bonds)
450    {
451  0 xtot = xtot + bond.start[0] + bond.end[0];
452  0 ytot = ytot + bond.start[1] + bond.end[1];
453  0 ztot = ztot + bond.start[2] + bond.end[2];
454    }
455    }
456    }
457   
458  0 centre[0] = xtot / (2 * (float) bsize);
459  0 centre[1] = ytot / (2 * (float) bsize);
460  0 centre[2] = ztot / (2 * (float) bsize);
461    }
462   
 
463  0 toggle @Override
464    public void paintComponent(Graphics g)
465    {
466  0 super.paintComponent(g);
467   
468  0 if (!seqColoursReady || errorMessage != null)
469    {
470  0 g.setColor(Color.black);
471  0 g.setFont(new Font("Verdana", Font.BOLD, 14));
472  0 g.drawString(errorMessage == null ? "Retrieving PDB data...."
473    : errorMessage, 20, getHeight() / 2);
474  0 return;
475    }
476   
477    // Only create the image at the beginning -
478    // this saves much memory usage
479  0 if ((img == null) || (prefsize.width != getWidth())
480    || (prefsize.height != getHeight()))
481   
482    {
483  0 prefsize.width = getWidth();
484  0 prefsize.height = getHeight();
485   
486  0 scale = findScale();
487  0 img = createImage(prefsize.width, prefsize.height);
488  0 ig = img.getGraphics();
489  0 Graphics2D ig2 = (Graphics2D) ig;
490   
491  0 ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
492    RenderingHints.VALUE_ANTIALIAS_ON);
493   
494  0 redrawneeded = true;
495    }
496   
497  0 if (redrawneeded)
498    {
499  0 drawAll(ig, prefsize.width, prefsize.height);
500  0 redrawneeded = false;
501    }
502   
503  0 g.drawImage(img, 0, 0, this);
504   
505  0 pdbAction = false;
506    }
507   
 
508  0 toggle public void drawAll(Graphics g, int width, int height)
509    {
510  0 g.setColor(backgroundColour);
511  0 g.fillRect(0, 0, width, height);
512  0 drawScene(g);
513  0 drawLabels(g);
514    }
515   
 
516  0 toggle public void updateSeqColours()
517    {
518  0 if (pdbAction)
519    {
520  0 return;
521    }
522   
523  0 colourBySequence();
524   
525  0 redrawneeded = true;
526  0 repaint();
527    }
528   
529    // This method has been taken out of PDBChain to allow
530    // Applet and Application specific sequence renderers to be used
 
531  0 toggle void colourBySequence()
532    {
533  0 SequenceRenderer sr = new SequenceRenderer(ap.av);
534   
535  0 StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());
536   
537  0 boolean showFeatures = false;
538  0 if (ap.av.isShowSequenceFeatures())
539    {
540  0 if (fr == null)
541    {
542  0 fr = new FeatureRenderer(ap);
543    }
544   
545  0 fr.transferSettings(ap.alignFrame.getFeatureRenderer());
546   
547  0 showFeatures = true;
548    }
549   
550  0 FeatureColourFinder finder = new FeatureColourFinder(fr);
551  0 PDBChain chain;
552  0 if (bysequence && pdb != null)
553    {
554  0 for (int ii = 0; ii < pdb.getChains().size(); ii++)
555    {
556  0 chain = pdb.getChains().elementAt(ii);
557   
558  0 for (int i = 0; i < chain.bonds.size(); i++)
559    {
560  0 Bond tmp = chain.bonds.elementAt(i);
561  0 tmp.startCol = Color.lightGray;
562  0 tmp.endCol = Color.lightGray;
563  0 if (chain != mainchain)
564    {
565  0 continue;
566    }
567   
568  0 for (int s = 0; s < sequence.length; s++)
569    {
570  0 for (int m = 0; m < mapping.length; m++)
571    {
572  0 if (mapping[m].getSequence() == sequence[s])
573    {
574  0 int pos = mapping[m].getSeqPos(tmp.at1.resNumber) - 1;
575  0 if (pos > 0)
576    {
577  0 pos = sequence[s].findIndex(pos);
578  0 tmp.startCol = sr.getResidueColour(sequence[s], pos,
579    finder);
580    }
581  0 pos = mapping[m].getSeqPos(tmp.at2.resNumber) - 1;
582  0 if (pos > 0)
583    {
584  0 pos = sequence[s].findIndex(pos);
585  0 tmp.endCol = sr.getResidueColour(sequence[s], pos,
586    finder);
587    }
588   
589    }
590    }
591    }
592    }
593    }
594    }
595    }
596   
597    Zsort zsort;
598   
 
599  0 toggle public void drawScene(Graphics g)
600    {
601  0 if (zbuffer)
602    {
603  0 if (zsort == null)
604    {
605  0 zsort = new Zsort();
606    }
607   
608  0 zsort.sort(visiblebonds);
609    }
610   
611  0 Bond tmpBond = null;
612  0 for (int i = 0; i < visiblebonds.size(); i++)
613    {
614  0 tmpBond = visiblebonds.elementAt(i);
615   
616  0 xstart = (int) (((tmpBond.start[0] - centre[0]) * scale)
617    + (getWidth() / 2));
618  0 ystart = (int) (((centre[1] - tmpBond.start[1]) * scale)
619    + (getHeight() / 2));
620   
621  0 xend = (int) (((tmpBond.end[0] - centre[0]) * scale)
622    + (getWidth() / 2));
623  0 yend = (int) (((centre[1] - tmpBond.end[1]) * scale)
624    + (getHeight() / 2));
625   
626  0 xmid = (xend + xstart) / 2;
627  0 ymid = (yend + ystart) / 2;
628  0 if (depthcue && !bymolecule)
629    {
630  0 if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))
631    {
632   
633  0 g.setColor(tmpBond.startCol.darker().darker());
634  0 drawLine(g, xstart, ystart, xmid, ymid);
635  0 g.setColor(tmpBond.endCol.darker().darker());
636  0 drawLine(g, xmid, ymid, xend, yend);
637   
638    }
639  0 else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))
640    {
641  0 g.setColor(tmpBond.startCol.darker());
642  0 drawLine(g, xstart, ystart, xmid, ymid);
643   
644  0 g.setColor(tmpBond.endCol.darker());
645  0 drawLine(g, xmid, ymid, xend, yend);
646    }
647    else
648    {
649  0 g.setColor(tmpBond.startCol);
650  0 drawLine(g, xstart, ystart, xmid, ymid);
651   
652  0 g.setColor(tmpBond.endCol);
653  0 drawLine(g, xmid, ymid, xend, yend);
654    }
655    }
656  0 else if (depthcue && bymolecule)
657    {
658  0 if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))
659    {
660  0 g.setColor(Color.green.darker().darker());
661  0 drawLine(g, xstart, ystart, xend, yend);
662    }
663  0 else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))
664    {
665  0 g.setColor(Color.green.darker());
666  0 drawLine(g, xstart, ystart, xend, yend);
667    }
668    else
669    {
670  0 g.setColor(Color.green);
671  0 drawLine(g, xstart, ystart, xend, yend);
672    }
673    }
674  0 else if (!depthcue && !bymolecule)
675    {
676  0 g.setColor(tmpBond.startCol);
677  0 drawLine(g, xstart, ystart, xmid, ymid);
678  0 g.setColor(tmpBond.endCol);
679  0 drawLine(g, xmid, ymid, xend, yend);
680    }
681    else
682    {
683  0 drawLine(g, xstart, ystart, xend, yend);
684    }
685   
686  0 if (highlightBond1 != null && highlightBond1 == tmpBond)
687    {
688  0 g.setColor(
689    tmpBond.endCol.brighter().brighter().brighter().brighter());
690  0 drawLine(g, xmid, ymid, xend, yend);
691    }
692   
693  0 if (highlightBond2 != null && highlightBond2 == tmpBond)
694    {
695  0 g.setColor(tmpBond.startCol.brighter().brighter().brighter()
696    .brighter());
697  0 drawLine(g, xstart, ystart, xmid, ymid);
698    }
699   
700    }
701   
702    }
703   
 
704  0 toggle public void drawLine(Graphics g, int x1, int y1, int x2, int y2)
705    {
706  0 if (!wire)
707    {
708  0 if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5)
709    {
710  0 g.drawLine(x1, y1, x2, y2);
711  0 g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1);
712  0 g.drawLine(x1, y1 - 1, x2, y2 - 1);
713    }
714    else
715    {
716  0 g.setColor(g.getColor().brighter());
717  0 g.drawLine(x1, y1, x2, y2);
718  0 g.drawLine(x1 + 1, y1, x2 + 1, y2);
719  0 g.drawLine(x1 - 1, y1, x2 - 1, y2);
720    }
721    }
722    else
723    {
724  0 g.drawLine(x1, y1, x2, y2);
725    }
726    }
727   
 
728  0 toggle public Dimension minimumsize()
729    {
730  0 return prefsize;
731    }
732   
 
733  0 toggle public Dimension preferredsize()
734    {
735  0 return prefsize;
736    }
737   
 
738  0 toggle public void keyPressed(KeyEvent evt)
739    {
740  0 if (evt.getKeyCode() == KeyEvent.VK_UP)
741    {
742  0 scale = (float) (scale * 1.1);
743  0 redrawneeded = true;
744  0 repaint();
745    }
746  0 else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
747    {
748  0 scale = (float) (scale * 0.9);
749  0 redrawneeded = true;
750  0 repaint();
751    }
752    }
753   
 
754  0 toggle @Override
755    public void mousePressed(MouseEvent e)
756    {
757  0 pdbAction = true;
758  0 Atom fatom = findAtom(e.getX(), e.getY());
759  0 if (fatom != null)
760    {
761  0 fatom.isSelected = !fatom.isSelected;
762   
763  0 redrawneeded = true;
764  0 repaint();
765  0 if (foundchain != -1)
766    {
767  0 PDBChain chain = pdb.getChains().elementAt(foundchain);
768  0 if (chain == mainchain)
769    {
770  0 if (fatom.alignmentMapping != -1)
771    {
772  0 if (highlightRes == null)
773    {
774  0 highlightRes = new Vector<String>();
775    }
776   
777  0 final String atomString = Integer
778    .toString(fatom.alignmentMapping);
779  0 if (highlightRes.contains(atomString))
780    {
781  0 highlightRes.remove(atomString);
782    }
783    else
784    {
785  0 highlightRes.add(atomString);
786    }
787    }
788    }
789    }
790   
791    }
792  0 mx = e.getX();
793  0 my = e.getY();
794  0 omx = mx;
795  0 omy = my;
796  0 dragging = false;
797    }
798   
 
799  0 toggle @Override
800    public void mouseMoved(MouseEvent e)
801    {
802  0 pdbAction = true;
803  0 if (highlightBond1 != null)
804    {
805  0 highlightBond1.at2.isSelected = false;
806  0 highlightBond2.at1.isSelected = false;
807  0 highlightBond1 = null;
808  0 highlightBond2 = null;
809    }
810   
811  0 Atom fatom = findAtom(e.getX(), e.getY());
812   
813  0 PDBChain chain = null;
814  0 if (foundchain != -1)
815    {
816  0 chain = pdb.getChains().elementAt(foundchain);
817  0 if (chain == mainchain)
818    {
819  0 mouseOverStructure(fatom.resNumber, chain.id);
820    }
821    }
822   
823  0 if (fatom != null)
824    {
825  0 this.setToolTipText(
826    chain.id + ":" + fatom.resNumber + " " + fatom.resName);
827    }
828    else
829    {
830  0 mouseOverStructure(-1, chain != null ? chain.id : null);
831  0 this.setToolTipText(null);
832    }
833    }
834   
 
835  0 toggle @Override
836    public void mouseClicked(MouseEvent e)
837    {
838    }
839   
 
840  0 toggle @Override
841    public void mouseEntered(MouseEvent e)
842    {
843    }
844   
 
845  0 toggle @Override
846    public void mouseExited(MouseEvent e)
847    {
848    }
849   
 
850  0 toggle @Override
851    public void mouseDragged(MouseEvent evt)
852    {
853  0 int x = evt.getX();
854  0 int y = evt.getY();
855  0 mx = x;
856  0 my = y;
857   
858  0 MCMatrix objmat = new MCMatrix(3, 3);
859  0 objmat.setIdentity();
860   
861  0 if ((evt.getModifiers() & Event.META_MASK) != 0)
862    {
863  0 objmat.rotatez(((mx - omx)));
864    }
865    else
866    {
867  0 objmat.rotatex(((my - omy)));
868  0 objmat.rotatey(((omx - mx)));
869    }
870   
871    // Alter the bonds
872  0 for (PDBChain chain : pdb.getChains())
873    {
874  0 for (Bond tmpBond : chain.bonds)
875    {
876    // Translate the bond so the centre is 0,0,0
877  0 tmpBond.translate(-centre[0], -centre[1], -centre[2]);
878   
879    // Now apply the rotation matrix
880  0 tmpBond.start = objmat.vectorMultiply(tmpBond.start);
881  0 tmpBond.end = objmat.vectorMultiply(tmpBond.end);
882   
883    // Now translate back again
884  0 tmpBond.translate(centre[0], centre[1], centre[2]);
885    }
886    }
887   
888  0 objmat = null;
889   
890  0 omx = mx;
891  0 omy = my;
892   
893  0 dragging = true;
894   
895  0 redrawneeded = true;
896   
897  0 repaint();
898    }
899   
 
900  0 toggle @Override
901    public void mouseReleased(MouseEvent evt)
902    {
903  0 dragging = false;
904  0 return;
905    }
906   
 
907  0 toggle void drawLabels(Graphics g)
908    {
909   
910  0 for (PDBChain chain : pdb.getChains())
911    {
912  0 if (chain.isVisible)
913    {
914  0 for (Bond tmpBond : chain.bonds)
915    {
916  0 if (tmpBond.at1.isSelected)
917    {
918  0 labelAtom(g, tmpBond, 1);
919    }
920   
921  0 if (tmpBond.at2.isSelected)
922    {
923  0 labelAtom(g, tmpBond, 2);
924    }
925    }
926    }
927    }
928    }
929   
 
930  0 toggle public void labelAtom(Graphics g, Bond b, int n)
931    {
932  0 g.setFont(font);
933  0 g.setColor(Color.red);
934  0 if (n == 1)
935    {
936  0 int xstart = (int) (((b.start[0] - centre[0]) * scale)
937    + (getWidth() / 2));
938  0 int ystart = (int) (((centre[1] - b.start[1]) * scale)
939    + (getHeight() / 2));
940   
941  0 g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);
942    }
943   
944  0 if (n == 2)
945    {
946  0 int xstart = (int) (((b.end[0] - centre[0]) * scale)
947    + (getWidth() / 2));
948  0 int ystart = (int) (((centre[1] - b.end[1]) * scale)
949    + (getHeight() / 2));
950   
951  0 g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);
952    }
953    }
954   
955    int foundchain = -1;
956   
 
957  0 toggle public Atom findAtom(int x, int y)
958    {
959  0 Atom fatom = null;
960   
961  0 foundchain = -1;
962   
963  0 for (int ii = 0; ii < pdb.getChains().size(); ii++)
964    {
965  0 PDBChain chain = pdb.getChains().elementAt(ii);
966  0 int truex;
967  0 Bond tmpBond = null;
968   
969  0 if (chain.isVisible)
970    {
971  0 for (Bond bond : chain.bonds)
972    {
973  0 tmpBond = bond;
974   
975  0 truex = (int) (((tmpBond.start[0] - centre[0]) * scale)
976    + (getWidth() / 2));
977   
978  0 if (Math.abs(truex - x) <= 2)
979    {
980  0 int truey = (int) (((centre[1] - tmpBond.start[1]) * scale)
981    + (getHeight() / 2));
982   
983  0 if (Math.abs(truey - y) <= 2)
984    {
985  0 fatom = tmpBond.at1;
986  0 foundchain = ii;
987  0 break;
988    }
989    }
990    }
991   
992    // Still here? Maybe its the last bond
993   
994  0 truex = (int) (((tmpBond.end[0] - centre[0]) * scale)
995    + (getWidth() / 2));
996   
997  0 if (Math.abs(truex - x) <= 2)
998    {
999  0 int truey = (int) (((tmpBond.end[1] - centre[1]) * scale)
1000    + (getHeight() / 2));
1001   
1002  0 if (Math.abs(truey - y) <= 2)
1003    {
1004  0 fatom = tmpBond.at2;
1005  0 foundchain = ii;
1006  0 break;
1007    }
1008    }
1009   
1010    }
1011   
1012  0 if (fatom != null) // )&& chain.ds != null)
1013    { // dead code? value of chain is either overwritten or discarded
1014  0 chain = pdb.getChains().elementAt(foundchain);
1015    }
1016    }
1017   
1018  0 return fatom;
1019    }
1020   
1021    Bond highlightBond1, highlightBond2;
1022   
 
1023  0 toggle public void highlightRes(int ii)
1024    {
1025  0 if (!seqColoursReady)
1026    {
1027  0 return;
1028    }
1029   
1030  0 if (highlightRes != null && highlightRes.contains((ii - 1) + ""))
1031    {
1032  0 return;
1033    }
1034   
1035  0 int index = -1;
1036  0 Bond tmpBond;
1037  0 for (index = 0; index < mainchain.bonds.size(); index++)
1038    {
1039  0 tmpBond = mainchain.bonds.elementAt(index);
1040  0 if (tmpBond.at1.alignmentMapping == ii - 1)
1041    {
1042  0 if (highlightBond1 != null)
1043    {
1044  0 highlightBond1.at2.isSelected = false;
1045    }
1046   
1047  0 if (highlightBond2 != null)
1048    {
1049  0 highlightBond2.at1.isSelected = false;
1050    }
1051   
1052  0 highlightBond1 = null;
1053  0 highlightBond2 = null;
1054   
1055  0 if (index > 0)
1056    {
1057  0 highlightBond1 = mainchain.bonds.elementAt(index - 1);
1058  0 highlightBond1.at2.isSelected = true;
1059    }
1060   
1061  0 if (index != mainchain.bonds.size())
1062    {
1063  0 highlightBond2 = mainchain.bonds.elementAt(index);
1064  0 highlightBond2.at1.isSelected = true;
1065    }
1066   
1067  0 break;
1068    }
1069    }
1070   
1071  0 redrawneeded = true;
1072  0 repaint();
1073    }
1074   
 
1075  0 toggle public void setAllchainsVisible(boolean b)
1076    {
1077  0 for (int ii = 0; ii < pdb.getChains().size(); ii++)
1078    {
1079  0 PDBChain chain = pdb.getChains().elementAt(ii);
1080  0 chain.isVisible = b;
1081    }
1082  0 mainchain.isVisible = true;
1083  0 findCentre();
1084  0 setupBonds();
1085    }
1086   
1087    // ////////////////////////////////
1088    // /StructureListener
 
1089  0 toggle @Override
1090    public String[] getStructureFiles()
1091    {
1092  0 return new String[] { pdbentry.getFile() };
1093    }
1094   
1095    String lastMessage;
1096   
 
1097  0 toggle public void mouseOverStructure(int pdbResNum, String chain)
1098    {
1099  0 if (lastMessage == null || !lastMessage.equals(pdbResNum + chain))
1100    {
1101  0 ssm.mouseOverStructure(pdbResNum, chain, pdbentry.getFile());
1102    }
1103   
1104  0 lastMessage = pdbResNum + chain;
1105    }
1106   
1107    StringBuffer resetLastRes = new StringBuffer();
1108   
1109    StringBuffer eval = new StringBuffer();
1110   
1111    /**
1112    * Highlight the specified atoms in the structure.
1113    *
1114    * @param atoms
1115    */
 
1116  0 toggle @Override
1117    public void highlightAtoms(List<AtomSpec> atoms)
1118    {
1119  0 if (!seqColoursReady)
1120    {
1121  0 return;
1122    }
1123   
1124  0 for (AtomSpec atom : atoms)
1125    {
1126  0 int atomIndex = atom.getAtomIndex();
1127  0 if (highlightRes != null
1128    && highlightRes.contains((atomIndex - 1) + ""))
1129    {
1130  0 continue;
1131    }
1132   
1133  0 highlightAtom(atomIndex);
1134    }
1135   
1136  0 redrawneeded = true;
1137  0 repaint();
1138    }
1139   
1140    /**
1141    * Highlight the atom at the specified index.
1142    *
1143    * @param atomIndex
1144    */
 
1145  0 toggle protected void highlightAtom(int atomIndex)
1146    {
1147  0 int index = -1;
1148  0 Bond tmpBond;
1149  0 for (index = 0; index < mainchain.bonds.size(); index++)
1150    {
1151  0 tmpBond = mainchain.bonds.elementAt(index);
1152  0 if (tmpBond.at1.atomIndex == atomIndex)
1153    {
1154  0 if (highlightBond1 != null)
1155    {
1156  0 highlightBond1.at2.isSelected = false;
1157    }
1158   
1159  0 if (highlightBond2 != null)
1160    {
1161  0 highlightBond2.at1.isSelected = false;
1162    }
1163   
1164  0 highlightBond1 = null;
1165  0 highlightBond2 = null;
1166   
1167  0 if (index > 0)
1168    {
1169  0 highlightBond1 = mainchain.bonds.elementAt(index - 1);
1170  0 highlightBond1.at2.isSelected = true;
1171    }
1172   
1173  0 if (index != mainchain.bonds.size())
1174    {
1175  0 highlightBond2 = mainchain.bonds.elementAt(index);
1176  0 highlightBond2.at1.isSelected = true;
1177    }
1178   
1179  0 break;
1180    }
1181    }
1182    }
1183   
 
1184  0 toggle public Color getColour(int atomIndex, int pdbResNum, String chain,
1185    String pdbfile)
1186    {
1187  0 return Color.white;
1188    // if (!pdbfile.equals(pdbentry.getFile()))
1189    // return null;
1190   
1191    // return new Color(viewer.getAtomArgb(atomIndex));
1192    }
1193   
 
1194  0 toggle @Override
1195    public void updateColours(Object source)
1196    {
1197  0 colourBySequence();
1198  0 redrawneeded = true;
1199  0 repaint();
1200    }
1201   
 
1202  0 toggle @Override
1203    public void releaseReferences(Object svl)
1204    {
1205    // TODO Auto-generated method stub
1206   
1207    }
1208   
 
1209  0 toggle @Override
1210    public boolean isListeningFor(SequenceI seq)
1211    {
1212  0 if (sequence != null)
1213    {
1214  0 for (SequenceI s : sequence)
1215    {
1216  0 if (s == seq)
1217    {
1218  0 return true;
1219    }
1220    }
1221    }
1222  0 return false;
1223    }
1224    }