JAL-3390 Chimera showStructures() respects visible/chain selections
[jalview.git] / src / jalview / structures / models / AAStructureBindingModel.java
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 jalview.structures.models;
22
23 import jalview.api.AlignViewportI;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.api.SequenceRenderer;
26 import jalview.api.StructureSelectionManagerProvider;
27 import jalview.api.structures.JalviewStructureDisplayI;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.HiddenColumns;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.SequenceI;
32 import jalview.io.DataSourceType;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.structure.AtomSpec;
35 import jalview.structure.StructureListener;
36 import jalview.structure.StructureMapping;
37 import jalview.structure.StructureMappingcommandSet;
38 import jalview.structure.StructureSelectionManager;
39 import jalview.util.Comparison;
40 import jalview.util.MessageManager;
41
42 import java.awt.Color;
43 import java.util.ArrayList;
44 import java.util.Arrays;
45 import java.util.BitSet;
46 import java.util.List;
47
48 /**
49  * 
50  * A base class to hold common function for protein structure model binding.
51  * Initial version created by refactoring JMol and Chimera binding models, but
52  * other structure viewers could in principle be accommodated in future.
53  * 
54  * @author gmcarstairs
55  *
56  */
57 public abstract class AAStructureBindingModel
58         extends SequenceStructureBindingModel
59         implements StructureListener, StructureSelectionManagerProvider
60 {
61
62   private StructureSelectionManager ssm;
63
64   /*
65    * distinct PDB entries (pdb files) associated
66    * with sequences
67    */
68   private PDBEntry[] pdbEntry;
69
70   /*
71    * sequences mapped to each pdbentry
72    */
73   private SequenceI[][] sequence;
74
75   /*
76    * array of target chains for sequences - tied to pdbentry and sequence[]
77    */
78   private String[][] chains;
79
80   /*
81    * datasource protocol for access to PDBEntrylatest
82    */
83   DataSourceType protocol = null;
84
85   protected boolean colourBySequence = true;
86
87   private boolean nucleotide;
88
89   private boolean finishedInit = false;
90
91   /**
92    * current set of model filenames loaded in the Jmol instance
93    */
94   protected String[] modelFileNames = null;
95
96   public String fileLoadingError;
97
98   private boolean showAlignmentOnly;
99
100   /*
101    * a list of chains "pdbid:chainid" to show in the viewer;
102    * empty means show all
103    */
104   // TODO make private once showStructures() deals with this
105   protected List<String> chainsToShow;
106
107   /**
108    * Data bean class to simplify parameterisation in superposeStructures
109    */
110   protected class SuperposeData
111   {
112     /**
113      * Constructor with alignment width argument
114      * 
115      * @param width
116      */
117     public SuperposeData(int width)
118     {
119       pdbResNo = new int[width];
120     }
121
122     public String filename;
123
124     public String pdbId;
125
126     public String chain = "";
127
128     public boolean isRna;
129
130     /*
131      * The pdb residue number (if any) mapped to each column of the alignment
132      */
133     public int[] pdbResNo;
134   }
135
136   /**
137    * Constructor
138    * 
139    * @param ssm
140    * @param seqs
141    */
142   public AAStructureBindingModel(StructureSelectionManager ssm,
143           SequenceI[][] seqs)
144   {
145     this.ssm = ssm;
146     this.sequence = seqs;
147     chainsToShow = new ArrayList<>();
148   }
149
150   /**
151    * Constructor
152    * 
153    * @param ssm
154    * @param pdbentry
155    * @param sequenceIs
156    * @param protocol
157    */
158   public AAStructureBindingModel(StructureSelectionManager ssm,
159           PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
160           DataSourceType protocol)
161   {
162     this.ssm = ssm;
163     this.sequence = sequenceIs;
164     this.nucleotide = Comparison.isNucleotide(sequenceIs);
165     this.pdbEntry = pdbentry;
166     this.protocol = protocol;
167     chainsToShow = new ArrayList<>();
168
169     resolveChains();
170   }
171
172   private boolean resolveChains()
173   {
174     /**
175      * final count of chain mappings discovered
176      */
177     int chainmaps = 0;
178     // JBPNote: JAL-2693 - this should be a list of chain mappings per
179     // [pdbentry][sequence]
180     String[][] newchains = new String[pdbEntry.length][];
181     int pe = 0;
182     for (PDBEntry pdb : pdbEntry)
183     {
184       SequenceI[] seqsForPdb = sequence[pe];
185       if (seqsForPdb != null)
186       {
187         newchains[pe] = new String[seqsForPdb.length];
188         int se = 0;
189         for (SequenceI asq : seqsForPdb)
190         {
191           String chain = (chains != null && chains[pe] != null)
192                   ? chains[pe][se]
193                   : null;
194           SequenceI sq = (asq.getDatasetSequence() == null) ? asq
195                   : asq.getDatasetSequence();
196           if (sq.getAllPDBEntries() != null)
197           {
198             for (PDBEntry pdbentry : sq.getAllPDBEntries())
199             {
200               if (pdb.getFile() != null && pdbentry.getFile() != null
201                       && pdb.getFile().equals(pdbentry.getFile()))
202               {
203                 String chaincode = pdbentry.getChainCode();
204                 if (chaincode != null && chaincode.length() > 0)
205                 {
206                   chain = chaincode;
207                   chainmaps++;
208                   break;
209                 }
210               }
211             }
212           }
213           newchains[pe][se] = chain;
214           se++;
215         }
216         pe++;
217       }
218     }
219
220     chains = newchains;
221     return chainmaps > 0;
222   }
223   public StructureSelectionManager getSsm()
224   {
225     return ssm;
226   }
227
228   /**
229    * Returns the i'th PDBEntry (or null)
230    * 
231    * @param i
232    * @return
233    */
234   public PDBEntry getPdbEntry(int i)
235   {
236     return (pdbEntry != null && pdbEntry.length > i) ? pdbEntry[i] : null;
237   }
238
239   /**
240    * Answers true if this binding includes the given PDB id, else false
241    * 
242    * @param pdbId
243    * @return
244    */
245   public boolean hasPdbId(String pdbId)
246   {
247     if (pdbEntry != null)
248     {
249       for (PDBEntry pdb : pdbEntry)
250       {
251         if (pdb.getId().equals(pdbId))
252         {
253           return true;
254         }
255       }
256     }
257     return false;
258   }
259
260   /**
261    * Returns the number of modelled PDB file entries.
262    * 
263    * @return
264    */
265   public int getPdbCount()
266   {
267     return pdbEntry == null ? 0 : pdbEntry.length;
268   }
269
270   public SequenceI[][] getSequence()
271   {
272     return sequence;
273   }
274
275   public String[][] getChains()
276   {
277     return chains;
278   }
279
280   public DataSourceType getProtocol()
281   {
282     return protocol;
283   }
284
285   // TODO may remove this if calling methods can be pulled up here
286   protected void setPdbentry(PDBEntry[] pdbentry)
287   {
288     this.pdbEntry = pdbentry;
289   }
290
291   protected void setSequence(SequenceI[][] sequence)
292   {
293     this.sequence = sequence;
294   }
295
296   protected void setChains(String[][] chains)
297   {
298     this.chains = chains;
299   }
300
301   /**
302    * Construct a title string for the viewer window based on the data Jalview
303    * knows about
304    * 
305    * @param viewerName
306    *          TODO
307    * @param verbose
308    * 
309    * @return
310    */
311   public String getViewerTitle(String viewerName, boolean verbose)
312   {
313     if (getSequence() == null || getSequence().length < 1
314             || getPdbCount() < 1 || getSequence()[0].length < 1)
315     {
316       return ("Jalview " + viewerName + " Window");
317     }
318     // TODO: give a more informative title when multiple structures are
319     // displayed.
320     StringBuilder title = new StringBuilder(64);
321     final PDBEntry pdbe = getPdbEntry(0);
322     title.append(viewerName + " view for " + getSequence()[0][0].getName()
323             + ":" + pdbe.getId());
324
325     if (verbose)
326     {
327       String method = (String) pdbe.getProperty("method");
328       if (method != null)
329       {
330         title.append(" Method: ").append(method);
331       }
332       String chain = (String) pdbe.getProperty("chains");
333       if (chain != null)
334       {
335         title.append(" Chain:").append(chain);
336       }
337     }
338     return title.toString();
339   }
340
341   /**
342    * Called by after closeViewer is called, to release any resources and
343    * references so they can be garbage collected. Override if needed.
344    */
345   protected void releaseUIResources()
346   {
347
348   }
349
350   public boolean isColourBySequence()
351   {
352     return colourBySequence;
353   }
354
355   public void setColourBySequence(boolean colourBySequence)
356   {
357     this.colourBySequence = colourBySequence;
358   }
359
360   protected void addSequenceAndChain(int pe, SequenceI[] seq,
361           String[] tchain)
362   {
363     if (pe < 0 || pe >= getPdbCount())
364     {
365       throw new Error(MessageManager.formatMessage(
366               "error.implementation_error_no_pdbentry_from_index",
367               new Object[]
368               { Integer.valueOf(pe).toString() }));
369     }
370     final String nullChain = "TheNullChain";
371     List<SequenceI> s = new ArrayList<>();
372     List<String> c = new ArrayList<>();
373     if (getChains() == null)
374     {
375       setChains(new String[getPdbCount()][]);
376     }
377     if (getSequence()[pe] != null)
378     {
379       for (int i = 0; i < getSequence()[pe].length; i++)
380       {
381         s.add(getSequence()[pe][i]);
382         if (getChains()[pe] != null)
383         {
384           if (i < getChains()[pe].length)
385           {
386             c.add(getChains()[pe][i]);
387           }
388           else
389           {
390             c.add(nullChain);
391           }
392         }
393         else
394         {
395           if (tchain != null && tchain.length > 0)
396           {
397             c.add(nullChain);
398           }
399         }
400       }
401     }
402     for (int i = 0; i < seq.length; i++)
403     {
404       if (!s.contains(seq[i]))
405       {
406         s.add(seq[i]);
407         if (tchain != null && i < tchain.length)
408         {
409           c.add(tchain[i] == null ? nullChain : tchain[i]);
410         }
411       }
412     }
413     SequenceI[] tmp = s.toArray(new SequenceI[s.size()]);
414     getSequence()[pe] = tmp;
415     if (c.size() > 0)
416     {
417       String[] tch = c.toArray(new String[c.size()]);
418       for (int i = 0; i < tch.length; i++)
419       {
420         if (tch[i] == nullChain)
421         {
422           tch[i] = null;
423         }
424       }
425       getChains()[pe] = tch;
426     }
427     else
428     {
429       getChains()[pe] = null;
430     }
431   }
432
433   /**
434    * add structures and any known sequence associations
435    * 
436    * @returns the pdb entries added to the current set.
437    */
438   public synchronized PDBEntry[] addSequenceAndChain(PDBEntry[] pdbe,
439           SequenceI[][] seq, String[][] chns)
440   {
441     List<PDBEntry> v = new ArrayList<>();
442     List<int[]> rtn = new ArrayList<>();
443     for (int i = 0; i < getPdbCount(); i++)
444     {
445       v.add(getPdbEntry(i));
446     }
447     for (int i = 0; i < pdbe.length; i++)
448     {
449       int r = v.indexOf(pdbe[i]);
450       if (r == -1 || r >= getPdbCount())
451       {
452         rtn.add(new int[] { v.size(), i });
453         v.add(pdbe[i]);
454       }
455       else
456       {
457         // just make sure the sequence/chain entries are all up to date
458         addSequenceAndChain(r, seq[i], chns[i]);
459       }
460     }
461     pdbe = v.toArray(new PDBEntry[v.size()]);
462     setPdbentry(pdbe);
463     if (rtn.size() > 0)
464     {
465       // expand the tied sequence[] and string[] arrays
466       SequenceI[][] sqs = new SequenceI[getPdbCount()][];
467       String[][] sch = new String[getPdbCount()][];
468       System.arraycopy(getSequence(), 0, sqs, 0, getSequence().length);
469       System.arraycopy(getChains(), 0, sch, 0, this.getChains().length);
470       setSequence(sqs);
471       setChains(sch);
472       pdbe = new PDBEntry[rtn.size()];
473       for (int r = 0; r < pdbe.length; r++)
474       {
475         int[] stri = (rtn.get(r));
476         // record the pdb file as a new addition
477         pdbe[r] = getPdbEntry(stri[0]);
478         // and add the new sequence/chain entries
479         addSequenceAndChain(stri[0], seq[stri[1]], chns[stri[1]]);
480       }
481     }
482     else
483     {
484       pdbe = null;
485     }
486     return pdbe;
487   }
488
489   /**
490    * Add sequences to the pe'th pdbentry's sequence set.
491    * 
492    * @param pe
493    * @param seq
494    */
495   public void addSequence(int pe, SequenceI[] seq)
496   {
497     addSequenceAndChain(pe, seq, null);
498   }
499
500   /**
501    * add the given sequences to the mapping scope for the given pdb file handle
502    * 
503    * @param pdbFile
504    *          - pdbFile identifier
505    * @param seq
506    *          - set of sequences it can be mapped to
507    */
508   public void addSequenceForStructFile(String pdbFile, SequenceI[] seq)
509   {
510     for (int pe = 0; pe < getPdbCount(); pe++)
511     {
512       if (getPdbEntry(pe).getFile().equals(pdbFile))
513       {
514         addSequence(pe, seq);
515       }
516     }
517   }
518
519   @Override
520   public abstract void highlightAtoms(List<AtomSpec> atoms);
521
522   protected boolean isNucleotide()
523   {
524     return this.nucleotide;
525   }
526
527   /**
528    * Returns a readable description of all mappings for the wrapped pdbfile to
529    * any mapped sequences
530    * 
531    * @param pdbfile
532    * @param seqs
533    * @return
534    */
535   public String printMappings()
536   {
537     if (pdbEntry == null)
538     {
539       return "";
540     }
541     StringBuilder sb = new StringBuilder(128);
542     for (int pdbe = 0; pdbe < getPdbCount(); pdbe++)
543     {
544       String pdbfile = getPdbEntry(pdbe).getFile();
545       List<SequenceI> seqs = Arrays.asList(getSequence()[pdbe]);
546       sb.append(getSsm().printMappings(pdbfile, seqs));
547     }
548     return sb.toString();
549   }
550
551   /**
552    * Returns the mapped structure position for a given aligned column of a given
553    * sequence, or -1 if the column is gapped, beyond the end of the sequence, or
554    * not mapped to structure.
555    * 
556    * @param seq
557    * @param alignedPos
558    * @param mapping
559    * @return
560    */
561   protected int getMappedPosition(SequenceI seq, int alignedPos,
562           StructureMapping mapping)
563   {
564     if (alignedPos >= seq.getLength())
565     {
566       return -1;
567     }
568
569     if (Comparison.isGap(seq.getCharAt(alignedPos)))
570     {
571       return -1;
572     }
573     int seqPos = seq.findPosition(alignedPos);
574     int pos = mapping.getPDBResNum(seqPos);
575     return pos;
576   }
577
578   /**
579    * Helper method to identify residues that can participate in a structure
580    * superposition command. For each structure, identify a sequence in the
581    * alignment which is mapped to the structure. Identify non-gapped columns in
582    * the sequence which have a mapping to a residue in the structure. Returns
583    * the index of the first structure that has a mapping to the alignment.
584    * 
585    * @param alignment
586    *          the sequence alignment which is the basis of structure
587    *          superposition
588    * @param matched
589    *          a BitSet, where bit j is set to indicate that every structure has
590    *          a mapped residue present in column j (so the column can
591    *          participate in structure alignment)
592    * @param structures
593    *          an array of data beans corresponding to pdb file index
594    * @return
595    */
596   protected int findSuperposableResidues(AlignmentI alignment,
597           BitSet matched, SuperposeData[] structures)
598   {
599     int refStructure = -1;
600     String[] files = getStructureFiles();
601     if (files == null)
602     {
603       return -1;
604     }
605     for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
606     {
607       StructureMapping[] mappings = getSsm().getMapping(files[pdbfnum]);
608       int lastPos = -1;
609
610       /*
611        * Find the first mapped sequence (if any) for this PDB entry which is in
612        * the alignment
613        */
614       final int seqCountForPdbFile = getSequence()[pdbfnum].length;
615       for (int s = 0; s < seqCountForPdbFile; s++)
616       {
617         for (StructureMapping mapping : mappings)
618         {
619           final SequenceI theSequence = getSequence()[pdbfnum][s];
620           if (mapping.getSequence() == theSequence
621                   && alignment.findIndex(theSequence) > -1)
622           {
623             if (refStructure < 0)
624             {
625               refStructure = pdbfnum;
626             }
627             for (int r = 0; r < alignment.getWidth(); r++)
628             {
629               if (!matched.get(r))
630               {
631                 continue;
632               }
633               int pos = getMappedPosition(theSequence, r, mapping);
634               if (pos < 1 || pos == lastPos)
635               {
636                 matched.clear(r);
637                 continue;
638               }
639               lastPos = pos;
640               structures[pdbfnum].pdbResNo[r] = pos;
641             }
642             String chain = mapping.getChain();
643             if (chain != null && chain.trim().length() > 0)
644             {
645               structures[pdbfnum].chain = chain;
646             }
647             structures[pdbfnum].pdbId = mapping.getPdbId();
648             structures[pdbfnum].isRna = theSequence.getRNA() != null;
649
650             /*
651              * move on to next pdb file (ignore sequences for other chains
652              * for the same structure)
653              */
654             s = seqCountForPdbFile;
655             break;
656           }
657         }
658       }
659     }
660     return refStructure;
661   }
662
663   /**
664    * Returns true if the structure viewer has loaded all of the files of
665    * interest (identified by the file mapping having been set up), or false if
666    * any are still not loaded after a timeout interval.
667    * 
668    * @param files
669    */
670   protected boolean waitForFileLoad(String[] files)
671   {
672     /*
673      * give up after 10 secs plus 1 sec per file
674      */
675     long starttime = System.currentTimeMillis();
676     long endTime = 10000 + 1000 * files.length + starttime;
677     String notLoaded = null;
678
679     boolean waiting = true;
680     while (waiting && System.currentTimeMillis() < endTime)
681     {
682       waiting = false;
683       for (String file : files)
684       {
685         notLoaded = file;
686         if (file == null)
687         {
688           continue;
689         }
690         try
691         {
692           StructureMapping[] sm = getSsm().getMapping(file);
693           if (sm == null || sm.length == 0)
694           {
695             waiting = true;
696           }
697         } catch (Throwable x)
698         {
699           waiting = true;
700         }
701       }
702     }
703
704     if (waiting)
705     {
706       System.err.println(
707               "Timed out waiting for structure viewer to load file "
708                       + notLoaded);
709       return false;
710     }
711     return true;
712   }
713
714   @Override
715   public boolean isListeningFor(SequenceI seq)
716   {
717     if (sequence != null)
718     {
719       for (SequenceI[] seqs : sequence)
720       {
721         if (seqs != null)
722         {
723           for (SequenceI s : seqs)
724           {
725             if (s == seq || (s.getDatasetSequence() != null
726                     && s.getDatasetSequence() == seq.getDatasetSequence()))
727             {
728               return true;
729             }
730           }
731         }
732       }
733     }
734     return false;
735   }
736
737   public boolean isFinishedInit()
738   {
739     return finishedInit;
740   }
741
742   public void setFinishedInit(boolean fi)
743   {
744     this.finishedInit = fi;
745   }
746
747   /**
748    * Returns a list of chains mapped in this viewer.
749    * 
750    * @return
751    */
752   public abstract List<String> getChainNames();
753
754   /**
755    * Returns the Jalview panel hosting the structure viewer (if any)
756    * 
757    * @return
758    */
759   public JalviewStructureDisplayI getViewer()
760   {
761     return null;
762   }
763
764   public abstract void setJalviewColourScheme(ColourSchemeI cs);
765
766   /**
767    * Constructs and sends a command to align structures against a reference
768    * structure, based on one or more sequence alignments. May optionally return
769    * an error or warning message for the alignment command.
770    * 
771    * @param alignments
772    *          an array of alignments to process
773    * @param structureIndices
774    *          an array of corresponding reference structures (index into pdb
775    *          file array); if a negative value is passed, the first PDB file
776    *          mapped to an alignment sequence is used as the reference for
777    *          superposition
778    * @param hiddenCols
779    *          an array of corresponding hidden columns for each alignment
780    * @return
781    */
782   public abstract String superposeStructures(AlignmentI[] alignments,
783           int[] structureIndices, HiddenColumns[] hiddenCols);
784
785   public abstract void setBackgroundColour(Color col);
786
787   protected abstract StructureMappingcommandSet[] getColourBySequenceCommands(
788           String[] files, SequenceRenderer sr, AlignmentViewPanel avp);
789
790   /**
791    * returns the current sequenceRenderer that should be used to colour the
792    * structures
793    * 
794    * @param alignment
795    * 
796    * @return
797    */
798   public abstract SequenceRenderer getSequenceRenderer(
799           AlignmentViewPanel alignment);
800
801   protected abstract void colourBySequence(
802           StructureMappingcommandSet[] colourBySequenceCommands);
803
804   public abstract void colourByChain();
805
806   public abstract void colourByCharge();
807
808   /**
809    * Recolours the displayed structures, if they are coloured by sequence, or
810    * 'show only visible alignment' is selected. This supports updating structure
811    * colours on either change of alignment colours, or change to the visible
812    * region of the alignment.
813    */
814   public void colourBySequence(AlignmentViewPanel alignmentv)
815   {
816     if (!isLoadingFinished())
817     {
818       return;
819     }
820     // todo: property change event for visibleAlignment
821     // to avoid unnecessary redraws here
822     if (!colourBySequence && !isShowAlignmentOnly())
823     {
824       return;
825     }
826     if (getSsm() == null)
827     {
828       return;
829     }
830     String[] files = getStructureFiles();
831
832     SequenceRenderer sr = getSequenceRenderer(alignmentv);
833
834     StructureMappingcommandSet[] colourBySequenceCommands = getColourBySequenceCommands(
835             files, sr, alignmentv);
836     colourBySequence(colourBySequenceCommands);
837   }
838
839   public boolean hasFileLoadingError()
840   {
841     return fileLoadingError != null && fileLoadingError.length() > 0;
842   }
843
844   public abstract jalview.api.FeatureRenderer getFeatureRenderer(
845           AlignmentViewPanel alignment);
846
847   /**
848    * Sets the flag for whether only mapped visible residues in the alignment
849    * should be visible in the structure viewer
850    * 
851    * @param b
852    */
853   public void setShowAlignmentOnly(boolean b)
854   {
855     showAlignmentOnly = b;
856   }
857
858   /**
859    * Answers true if only mapped visible residues in the alignment should be
860    * visible in the structure viewer, else false
861    * 
862    * @return
863    */
864   public boolean isShowAlignmentOnly()
865   {
866     return showAlignmentOnly;
867   }
868
869   /**
870    * Shows the structures in the viewer, without changing their colouring. This is
871    * to support toggling of whether the whole structure is shown, or only residues
872    * mapped to visible regions of the alignment.
873    * 
874    * @param alignViewportI
875    * @param refocus
876    *                         if true, refit the display to the viewer
877    */
878   public void showStructures(AlignViewportI alignViewportI, boolean refocus)
879   {
880     // override with implementation
881   }
882
883   @Override
884   public void updateColours(Object source)
885   {
886     AlignmentViewPanel ap = (AlignmentViewPanel) source;
887     // ignore events from panels not used to colour this view
888     if (!getViewer().isUsedforcolourby(ap))
889     {
890       return;
891     }
892     if (!isLoadingFromArchive())
893     {
894       colourBySequence(ap);
895     }
896   }
897
898   /**
899    * Sets the list of chains to display (as "pdbid:chain"), where an empty list
900    * means show all
901    * 
902    * @param chains
903    */
904   public void setChainsToShow(List<String> chains)
905   {
906     chainsToShow = chains;
907   }
908
909   /**
910    * Answers true if the specified structure and chain are selected to be shown in
911    * the viewer, else false
912    * 
913    * @param pdbId
914    * @param chainId
915    * @return
916    */
917   protected boolean isShowChain(String pdbId, String chainId)
918   {
919     if (chainsToShow.isEmpty())
920     {
921       return true;
922     }
923     return chainsToShow.contains(pdbId + ":" + chainId);
924   }
925 }