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