Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 17:27:16 GMT
  2. Package mc_view

File AppletPDBCanvas.java

 

Coverage histogram

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

Code metrics

214
463
38
1
1,265
979
158
0.34
12.18
38
4.16

Classes

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