JAL-3158 superseded superposeStructures methods removed
[jalview.git] / src / jalview / ext / rbvi / chimera / JalviewChimeraBinding.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.ext.rbvi.chimera;
22
23 import jalview.api.AlignmentViewPanel;
24 import jalview.api.structures.JalviewStructureDisplayI;
25 import jalview.bin.Cache;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.HiddenColumns;
28 import jalview.datamodel.PDBEntry;
29 import jalview.datamodel.SearchResultMatchI;
30 import jalview.datamodel.SearchResultsI;
31 import jalview.datamodel.SequenceFeature;
32 import jalview.datamodel.SequenceI;
33 import jalview.gui.StructureViewer.ViewerType;
34 import jalview.httpserver.AbstractRequestHandler;
35 import jalview.io.DataSourceType;
36 import jalview.structure.AtomSpec;
37 import jalview.structure.StructureCommandsI.SuperposeData;
38 import jalview.structure.StructureSelectionManager;
39 import jalview.structures.models.AAStructureBindingModel;
40 import jalview.util.MessageManager;
41
42 import java.io.File;
43 import java.io.FileOutputStream;
44 import java.io.IOException;
45 import java.io.PrintWriter;
46 import java.net.BindException;
47 import java.util.ArrayList;
48 import java.util.BitSet;
49 import java.util.Collections;
50 import java.util.Iterator;
51 import java.util.LinkedHashMap;
52 import java.util.List;
53 import java.util.Map;
54
55 import ext.edu.ucsf.rbvi.strucviz2.ChimeraManager;
56 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
57 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
58 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
59
60 public abstract class JalviewChimeraBinding extends AAStructureBindingModel
61 {
62   public static final String CHIMERA_FEATURE_GROUP = "Chimera";
63
64   // Chimera clause to exclude alternate locations in atom selection
65   private static final String NO_ALTLOCS = "&~@.B-Z&~@.2-9";
66
67   private static final boolean debug = false;
68
69   private static final String PHOSPHORUS = "P";
70
71   private static final String ALPHACARBON = "CA";
72
73   /*
74    * Object through which we talk to Chimera
75    */
76   private ChimeraManager chimeraManager;
77
78   /*
79    * Object which listens to Chimera notifications
80    */
81   private AbstractRequestHandler chimeraListener;
82
83   /*
84    * Map of ChimeraModel objects keyed by PDB full local file name
85    */
86   protected Map<String, List<ChimeraModel>> chimeraMaps = new LinkedHashMap<>();
87
88   String lastHighlightCommand;
89
90   private Thread chimeraMonitor;
91
92   /**
93    * Open a PDB structure file in Chimera and set up mappings from Jalview.
94    * 
95    * We check if the PDB model id is already loaded in Chimera, if so don't reopen
96    * it. This is the case if Chimera has opened a saved session file.
97    * 
98    * @param pe
99    * @return
100    */
101   public boolean openFile(PDBEntry pe)
102   {
103     String file = pe.getFile();
104     try
105     {
106       List<ChimeraModel> modelsToMap = new ArrayList<>();
107       List<ChimeraModel> oldList = chimeraManager.getModelList();
108       boolean alreadyOpen = false;
109
110       /*
111        * If Chimera already has this model, don't reopen it, but do remap it.
112        */
113       for (ChimeraModel open : oldList)
114       {
115         if (open.getModelName().equals(pe.getId()))
116         {
117           alreadyOpen = true;
118           modelsToMap.add(open);
119         }
120       }
121
122       /*
123        * If Chimera doesn't yet have this model, ask it to open it, and retrieve
124        * the model name(s) added by Chimera.
125        */
126       if (!alreadyOpen)
127       {
128         chimeraManager.openModel(file, pe.getId(), ModelType.PDB_MODEL);
129         addChimeraModel(pe, modelsToMap);
130       }
131
132       chimeraMaps.put(file, modelsToMap);
133
134       if (getSsm() != null)
135       {
136         getSsm().addStructureViewerListener(this);
137       }
138       return true;
139     } catch (Exception q)
140     {
141       log("Exception when trying to open model " + file + "\n"
142               + q.toString());
143       q.printStackTrace();
144     }
145     return false;
146   }
147
148   /**
149    * Adds the ChimeraModel corresponding to the given PDBEntry, based on model
150    * name matching PDB id
151    * 
152    * @param pe
153    * @param modelsToMap
154    */
155   protected void addChimeraModel(PDBEntry pe,
156           List<ChimeraModel> modelsToMap)
157   {
158     /*
159      * Chimera: query for actual models and find the one with
160      * matching model name - already set in viewer.openModel()
161      */
162     List<ChimeraModel> newList = chimeraManager.getModelList();
163     // JAL-1728 newList.removeAll(oldList) does not work
164     for (ChimeraModel cm : newList)
165     {
166       if (cm.getModelName().equals(pe.getId()))
167       {
168         modelsToMap.add(cm);
169       }
170     }
171   }
172
173   /**
174    * Constructor
175    * 
176    * @param ssm
177    * @param pdbentry
178    * @param sequenceIs
179    * @param protocol
180    */
181   public JalviewChimeraBinding(StructureSelectionManager ssm,
182           PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
183           DataSourceType protocol)
184   {
185     super(ssm, pdbentry, sequenceIs, protocol);
186     chimeraManager = new ChimeraManager(new StructureManager(true));
187     chimeraManager.setChimeraX(ViewerType.CHIMERAX.equals(getViewerType()));
188     setStructureCommands(new ChimeraCommands());
189   }
190
191   @Override
192   protected ViewerType getViewerType()
193   {
194     return ViewerType.CHIMERA;
195   }
196
197   /**
198    * Starts a thread that waits for the Chimera process to finish, so that we can
199    * then close the associated resources. This avoids leaving orphaned Chimera
200    * viewer panels in Jalview if the user closes Chimera.
201    */
202   protected void startChimeraProcessMonitor()
203   {
204     final Process p = chimeraManager.getChimeraProcess();
205     chimeraMonitor = new Thread(new Runnable()
206     {
207
208       @Override
209       public void run()
210       {
211         try
212         {
213           p.waitFor();
214           JalviewStructureDisplayI display = getViewer();
215           if (display != null)
216           {
217             display.closeViewer(false);
218           }
219         } catch (InterruptedException e)
220         {
221           // exit thread if Chimera Viewer is closed in Jalview
222         }
223       }
224     });
225     chimeraMonitor.start();
226   }
227
228   /**
229    * Start a dedicated HttpServer to listen for Chimera notifications, and tell it
230    * to start listening
231    */
232   public void startChimeraListener()
233   {
234     try
235     {
236       chimeraListener = new ChimeraListener(this);
237       chimeraManager.startListening(chimeraListener.getUri());
238     } catch (BindException e)
239     {
240       System.err.println(
241               "Failed to start Chimera listener: " + e.getMessage());
242     }
243   }
244
245   /**
246    * Close down the Jalview viewer and listener, and (optionally) the associated
247    * Chimera window.
248    */
249   public void closeViewer(boolean closeChimera)
250   {
251     getSsm().removeStructureViewerListener(this, this.getStructureFiles());
252     if (closeChimera)
253     {
254       chimeraManager.exitChimera();
255     }
256     if (this.chimeraListener != null)
257     {
258       chimeraListener.shutdown();
259       chimeraListener = null;
260     }
261     chimeraManager = null;
262
263     if (chimeraMonitor != null)
264     {
265       chimeraMonitor.interrupt();
266     }
267     releaseUIResources();
268   }
269
270   /**
271    * Helper method to construct model spec in Chimera format:
272    * <ul>
273    * <li>#0 (#1 etc) for a PDB file with no sub-models</li>
274    * <li>#0.1 (#1.1 etc) for a PDB file with sub-models</li>
275    * <ul>
276    * Note for now we only ever choose the first of multiple models. This
277    * corresponds to the hard-coded Jmol equivalent (compare {1.1}). Refactor in
278    * future if there is a need to select specific sub-models.
279    * 
280    * @param pdbfnum
281    * @return
282    */
283   protected String getModelSpec(int pdbfnum)
284   {
285     if (pdbfnum < 0 || pdbfnum >= getPdbCount())
286     {
287       return "#" + pdbfnum; // temp hack for ChimeraX
288     }
289
290     /*
291      * For now, the test for having sub-models is whether multiple Chimera
292      * models are mapped for the PDB file; the models are returned as a response
293      * to the Chimera command 'list models type molecule', see
294      * ChimeraManager.getModelList().
295      */
296     List<ChimeraModel> maps = chimeraMaps.get(getStructureFiles()[pdbfnum]);
297     boolean hasSubModels = maps != null && maps.size() > 1;
298     return "#" + String.valueOf(pdbfnum) + (hasSubModels ? ".1" : "");
299   }
300
301   /**
302    * Launch Chimera, unless an instance linked to this object is already
303    * running. Returns true if Chimera is successfully launched, or already
304    * running, else false.
305    * 
306    * @return
307    */
308   public boolean launchChimera()
309   {
310     if (chimeraManager.isChimeraLaunched())
311     {
312       return true;
313     }
314
315     boolean launched = chimeraManager.launchChimera(getChimeraPaths());
316     if (launched)
317     {
318       startChimeraProcessMonitor();
319     }
320     else
321     {
322       log("Failed to launch Chimera!");
323     }
324     return launched;
325   }
326
327   /**
328    * Returns a list of candidate paths to the Chimera program executable
329    * 
330    * @return
331    */
332   protected List<String> getChimeraPaths()
333   {
334     return StructureManager.getChimeraPaths(false);
335   }
336
337   /**
338    * Answers true if the Chimera process is still running, false if ended or not
339    * started.
340    * 
341    * @return
342    */
343   public boolean isChimeraRunning()
344   {
345     return chimeraManager.isChimeraLaunched();
346   }
347
348   /**
349    * Send a command to Chimera, and optionally log and return any responses.
350    * 
351    * @param command
352    * @param getResponse
353    */
354   @Override
355   public List<String> executeCommand(final String command,
356           boolean getResponse)
357   {
358     if (chimeraManager == null || command == null)
359     {
360       // ? thread running after viewer shut down
361       return null;
362     }
363     List<String> reply = null;
364     // trim command or it may never find a match in the replyLog!!
365     List<String> lastReply = chimeraManager
366             .sendChimeraCommand(command.trim(), getResponse);
367     if (getResponse)
368     {
369       reply = lastReply;
370       if (debug)
371       {
372         log("Response from command ('" + command + "') was:\n" + lastReply);
373       }
374     }
375
376     return reply;
377   }
378
379   /**
380    * @param command
381    */
382   protected void executeWhenReady(String command)
383   {
384     waitForChimera();
385     executeCommand(command, false);
386     waitForChimera();
387   }
388
389   private void waitForChimera()
390   {
391     while (chimeraManager != null && chimeraManager.isBusy())
392     {
393       try
394       {
395         Thread.sleep(15);
396       } catch (InterruptedException q)
397       {
398       }
399     }
400   }
401
402   @Override
403   public synchronized String[] getStructureFiles()
404   {
405     if (chimeraManager == null)
406     {
407       return new String[0];
408     }
409
410     return chimeraMaps.keySet()
411             .toArray(modelFileNames = new String[chimeraMaps.size()]);
412   }
413
414   /**
415    * Construct and send a command to highlight zero, one or more atoms. We do this
416    * by sending an "rlabel" command to show the residue label at that position.
417    */
418   @Override
419   public void highlightAtoms(List<AtomSpec> atoms)
420   {
421     if (atoms == null || atoms.size() == 0)
422     {
423       return;
424     }
425
426     boolean forChimeraX = chimeraManager.isChimeraX();
427     StringBuilder cmd = new StringBuilder(128);
428     boolean first = true;
429     boolean found = false;
430
431     for (AtomSpec atom : atoms)
432     {
433       int pdbResNum = atom.getPdbResNum();
434       String chain = atom.getChain();
435       String pdbfile = atom.getPdbFile();
436       List<ChimeraModel> cms = chimeraMaps.get(pdbfile);
437       if (cms != null && !cms.isEmpty())
438       {
439         if (first)
440         {
441           cmd.append(forChimeraX ? "label #" : "rlabel #");
442         }
443         else
444         {
445           cmd.append(",");
446         }
447         first = false;
448         if (forChimeraX)
449         {
450           cmd.append(cms.get(0).getModelNumber())
451                   .append("/").append(chain).append(":").append(pdbResNum);
452         }
453         else
454         {
455           cmd.append(cms.get(0).getModelNumber())
456                   .append(":").append(pdbResNum);
457           if (!chain.equals(" ") && !forChimeraX)
458           {
459             cmd.append(".").append(chain);
460           }
461         }
462         found = true;
463       }
464     }
465     String command = cmd.toString();
466
467     /*
468      * avoid repeated commands for the same residue
469      */
470     if (command.equals(lastHighlightCommand))
471     {
472       return;
473     }
474
475     /*
476      * unshow the label for the previous residue
477      */
478     if (lastHighlightCommand != null)
479     {
480       chimeraManager.sendChimeraCommand("~" + lastHighlightCommand, false);
481     }
482     if (found)
483     {
484       chimeraManager.sendChimeraCommand(command, false);
485     }
486     this.lastHighlightCommand = command;
487   }
488
489   /**
490    * Query Chimera for its current selection, and highlight it on the alignment
491    */
492   public void highlightChimeraSelection()
493   {
494     /*
495      * Ask Chimera for its current selection
496      */
497     List<String> selection = chimeraManager.getSelectedResidueSpecs();
498
499     /*
500      * Parse model number, residue and chain for each selected position,
501      * formatted as #0:123.A or #1.2:87.B (#model.submodel:residue.chain)
502      */
503     List<AtomSpec> atomSpecs = convertStructureResiduesToAlignment(
504             selection);
505
506     /*
507      * Broadcast the selection (which may be empty, if the user just cleared all
508      * selections)
509      */
510     getSsm().mouseOverStructure(atomSpecs);
511   }
512
513   /**
514    * Converts a list of Chimera atomspecs to a list of AtomSpec representing the
515    * corresponding residues (if any) in Jalview
516    * 
517    * @param structureSelection
518    * @return
519    */
520   protected List<AtomSpec> convertStructureResiduesToAlignment(
521           List<String> structureSelection)
522   {
523     boolean chimeraX = chimeraManager.isChimeraX();
524     List<AtomSpec> atomSpecs = new ArrayList<>();
525     for (String atomSpec : structureSelection)
526     {
527       try
528       {
529         AtomSpec spec = AtomSpec.fromChimeraAtomspec(atomSpec, chimeraX);
530         String pdbfilename = getPdbFileForModel(spec.getModelNumber());
531         spec.setPdbFile(pdbfilename);
532         atomSpecs.add(spec);
533       } catch (IllegalArgumentException e)
534       {
535         System.err.println("Failed to parse atomspec: " + atomSpec);
536       }
537     }
538     return atomSpecs;
539   }
540
541   /**
542    * @param modelId
543    * @return
544    */
545   protected String getPdbFileForModel(int modelId)
546   {
547     /*
548      * Work out the pdbfilename from the model number
549      */
550     String pdbfilename = modelFileNames[0];
551     findfileloop: for (String pdbfile : this.chimeraMaps.keySet())
552     {
553       for (ChimeraModel cm : chimeraMaps.get(pdbfile))
554       {
555         if (cm.getModelNumber() == modelId)
556         {
557           pdbfilename = pdbfile;
558           break findfileloop;
559         }
560       }
561     }
562     return pdbfilename;
563   }
564
565   private void log(String message)
566   {
567     System.err.println("## Chimera log: " + message);
568   }
569
570   /**
571    * Ask Chimera to save its session to the given file. Returns true if
572    * successful, else false.
573    * 
574    * @param filepath
575    * @return
576    */
577   public boolean saveSession(String filepath)
578   {
579     if (isChimeraRunning())
580     {
581       /*
582        * Chimera:  https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/save.html
583        * ChimeraX: https://www.cgl.ucsf.edu/chimerax/docs/user/commands/save.html
584        */
585       String command = getCommandGenerator().saveSession(filepath);
586       List<String> reply = chimeraManager.sendChimeraCommand(command, true);
587       if (reply.contains("Session written"))
588       {
589         return true;
590       }
591       else
592       {
593         Cache.log
594                 .error("Error saving Chimera session: " + reply.toString());
595       }
596     }
597     return false;
598   }
599
600   /**
601    * Ask Chimera to open a session file. Returns true if successful, else false.
602    * The filename must have a .py (Chimera) or .cxs (ChimeraX) extension for
603    * this command to work.
604    * 
605    * @param filepath
606    * @return
607    */
608   public boolean openSession(String filepath)
609   {
610     /*
611      * Chimera:  https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/open.html
612      * ChimeraX: https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html
613      */
614     executeCommand("open " + filepath, true);
615     // todo: test for failure - how?
616     return true;
617   }
618
619   /**
620    * Send a 'show' command for all atoms in the currently selected columns
621    * 
622    * TODO: pull up to abstract structure viewer interface
623    * 
624    * @param vp
625    */
626   public void highlightSelection(AlignmentViewPanel vp)
627   {
628     List<Integer> cols = vp.getAlignViewport().getColumnSelection()
629             .getSelected();
630     AlignmentI alignment = vp.getAlignment();
631     StructureSelectionManager sm = getSsm();
632     for (SequenceI seq : alignment.getSequences())
633     {
634       /*
635        * convert selected columns into sequence positions
636        */
637       int[] positions = new int[cols.size()];
638       int i = 0;
639       for (Integer col : cols)
640       {
641         positions[i++] = seq.findPosition(col);
642       }
643       sm.highlightStructure(this, seq, positions);
644     }
645   }
646
647   /**
648    * Constructs and send commands to Chimera to set attributes on residues for
649    * features visible in Jalview
650    * 
651    * @param avp
652    * @return
653    */
654   public int sendFeaturesToViewer(AlignmentViewPanel avp)
655   {
656     // TODO refactor as required to pull up to an interface
657     String[] files = getStructureFiles();
658     if (files == null)
659     {
660       return 0;
661     }
662
663     String[] commands = getCommandGenerator()
664             .setAttributesForFeatures(getSsm(), files, getSequence(), avp);
665     if (commands.length > 10)
666     {
667       sendCommandsByFile(commands);
668     }
669     else
670     {
671       for (String command : commands)
672       {
673         sendAsynchronousCommand(command, null);
674       }
675     }
676     return commands.length;
677   }
678
679   /**
680    * Write commands to a temporary file, and send a command to Chimera to open the
681    * file as a commands script. For use when sending a large number of separate
682    * commands would overload the REST interface mechanism.
683    * 
684    * @param commands
685    */
686   protected void sendCommandsByFile(String[] commands)
687   {
688     try
689     {
690       File tmp = File.createTempFile("chim", getCommandFileExtension());
691       tmp.deleteOnExit();
692       PrintWriter out = new PrintWriter(new FileOutputStream(tmp));
693       for (String command : commands)
694       {
695         out.println(command);
696       }
697       out.flush();
698       out.close();
699       String path = tmp.getAbsolutePath();
700       String command = getCommandGenerator().openCommandFile(path);
701       sendAsynchronousCommand(command, null);
702     } catch (IOException e)
703     {
704       System.err.println("Sending commands to Chimera via file failed with "
705               + e.getMessage());
706     }
707   }
708
709   /**
710    * Returns the file extension required for a file of commands to be read by
711    * the structure viewer
712    * @return
713    */
714   protected String getCommandFileExtension()
715   {
716     return ".com";
717   }
718
719   /**
720    * Get Chimera residues which have the named attribute, find the mapped
721    * positions in the Jalview sequence(s), and set as sequence features
722    * 
723    * @param attName
724    * @param alignmentPanel
725    */
726   public void copyStructureAttributesToFeatures(String attName,
727           AlignmentViewPanel alignmentPanel)
728   {
729     // todo pull up to AAStructureBindingModel (and interface?)
730
731     /*
732      * ask Chimera to list residues with the attribute, reporting its value
733      */
734     // this alternative command
735     // list residues spec ':*/attName' attr attName
736     // doesn't report 'None' values (which is good), but
737     // fails for 'average.bfactor' (which is bad):
738
739     String cmd = "list residues attr '" + attName + "'";
740     List<String> residues = executeCommand(cmd, true);
741
742     boolean featureAdded = createFeaturesForAttributes(attName, residues);
743     if (featureAdded)
744     {
745       alignmentPanel.getFeatureRenderer().featuresAdded();
746     }
747   }
748
749   /**
750    * Create features in Jalview for the given attribute name and structure
751    * residues.
752    * 
753    * <pre>
754    * The residue list should be 0, 1 or more reply lines of the format: 
755    *     residue id #0:5.A isHelix -155.000836316 index 5 
756    * or 
757    *     residue id #0:6.A isHelix None
758    * </pre>
759    * 
760    * @param attName
761    * @param residues
762    * @return
763    */
764   protected boolean createFeaturesForAttributes(String attName,
765           List<String> residues)
766   {
767     boolean featureAdded = false;
768     String featureGroup = getViewerFeatureGroup();
769     boolean chimeraX = chimeraManager.isChimeraX();
770
771     for (String residue : residues)
772     {
773       AtomSpec spec = null;
774       String[] tokens = residue.split(" ");
775       if (tokens.length < 5)
776       {
777         continue;
778       }
779       String atomSpec = tokens[2];
780       String attValue = tokens[4];
781
782       /*
783        * ignore 'None' (e.g. for phi) or 'False' (e.g. for isHelix)
784        */
785       if ("None".equalsIgnoreCase(attValue)
786               || "False".equalsIgnoreCase(attValue))
787       {
788         continue;
789       }
790
791       try
792       {
793         spec = AtomSpec.fromChimeraAtomspec(atomSpec, chimeraX);
794       } catch (IllegalArgumentException e)
795       {
796         System.err.println("Problem parsing atomspec " + atomSpec);
797         continue;
798       }
799
800       String chainId = spec.getChain();
801       String description = attValue;
802       float score = Float.NaN;
803       try
804       {
805         score = Float.valueOf(attValue);
806         description = chainId;
807       } catch (NumberFormatException e)
808       {
809         // was not a float value
810       }
811
812       String pdbFile = getPdbFileForModel(spec.getModelNumber());
813       spec.setPdbFile(pdbFile);
814
815       List<AtomSpec> atoms = Collections.singletonList(spec);
816
817       /*
818        * locate the mapped position in the alignment (if any)
819        */
820       SearchResultsI sr = getSsm()
821               .findAlignmentPositionsForStructurePositions(atoms);
822
823       /*
824        * expect one matched alignment position, or none 
825        * (if the structure position is not mapped)
826        */
827       for (SearchResultMatchI m : sr.getResults())
828       {
829         SequenceI seq = m.getSequence();
830         int start = m.getStart();
831         int end = m.getEnd();
832         SequenceFeature sf = new SequenceFeature(attName, description,
833                 start, end, score, featureGroup);
834         // todo: should SequenceFeature have an explicit property for chain?
835         // note: repeating the action shouldn't duplicate features
836         featureAdded |= seq.addSequenceFeature(sf);
837       }
838     }
839     return featureAdded;
840   }
841
842   /**
843    * Answers the feature group name to apply to features created in Jalview from
844    * Chimera attributes
845    * 
846    * @return
847    */
848   protected String getViewerFeatureGroup()
849   {
850     // todo pull up to interface
851     return CHIMERA_FEATURE_GROUP;
852   }
853
854   @Override
855   public int getModelNoForFile(String pdbFile)
856   {
857     List<ChimeraModel> foundModels = chimeraMaps.get(pdbFile);
858     if (foundModels != null && !foundModels.isEmpty())
859     {
860       return foundModels.get(0).getModelNumber();
861     }
862     return -1;
863   }
864
865   /**
866    * Answers a (possibly empty) list of attribute names in Chimera[X], excluding
867    * any which were added from Jalview
868    * 
869    * @return
870    */
871   public List<String> getChimeraAttributes()
872   {
873     List<String> atts = chimeraManager.getAttrList();
874     Iterator<String> it = atts.iterator();
875     while (it.hasNext())
876     {
877       if (it.next().startsWith(ChimeraCommands.NAMESPACE_PREFIX))
878       {
879         /*
880          * attribute added from Jalview - exclude it
881          */
882         it.remove();
883       }
884     }
885     return atts;
886   }
887
888   /**
889    * Returns the file extension to use for a saved viewer session file
890    * 
891    * @return
892    */
893   public String getSessionFileExtension()
894   {
895     return ".py";
896   }
897
898   public String getHelpURL()
899   {
900     return "https://www.cgl.ucsf.edu/chimera/docs/UsersGuide";
901   }
902 }