JAL-3746 apply copyright to source
[jalview.git] / src / jalview / gui / JalviewChimeraXBindingModel.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.gui;
22
23 import java.util.List;
24
25 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
26 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
27 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
28 import jalview.datamodel.PDBEntry;
29 import jalview.datamodel.SequenceI;
30 import jalview.ext.rbvi.chimera.ChimeraXCommands;
31 import jalview.gui.StructureViewer.ViewerType;
32 import jalview.io.DataSourceType;
33 import jalview.structure.AtomSpec;
34 import jalview.structure.StructureCommand;
35 import jalview.structure.StructureSelectionManager;
36
37 public class JalviewChimeraXBindingModel extends JalviewChimeraBindingModel
38 {
39   public static final String CHIMERAX_SESSION_EXTENSION = ".cxs";
40
41   public JalviewChimeraXBindingModel(ChimeraViewFrame chimeraViewFrame,
42           StructureSelectionManager ssm, PDBEntry[] pdbentry,
43           SequenceI[][] sequenceIs, DataSourceType protocol)
44   {
45     super(chimeraViewFrame, ssm, pdbentry, sequenceIs, protocol);
46     setStructureCommands(new ChimeraXCommands());
47   }
48
49   @Override
50   protected List<String> getChimeraPaths()
51   {
52     return StructureManager.getChimeraPaths(true);
53   }
54
55   @Override
56   protected void addChimeraModel(PDBEntry pe,
57           List<ChimeraModel> modelsToMap)
58   {
59     /*
60      * ChimeraX hack: force chimera model name to pdbId here
61      */
62     int modelNumber = chimeraMaps.size() + 1;
63     String command = "setattr #" + modelNumber + " models name "
64             + pe.getId();
65     executeCommand(new StructureCommand(command), false);
66     modelsToMap.add(new ChimeraModel(pe.getId(), ModelType.PDB_MODEL,
67             modelNumber, 0));
68   }
69
70   /**
71    * {@inheritDoc}
72    * 
73    * @return
74    */
75   @Override
76   protected String getCommandFileExtension()
77   {
78     return ".cxc";
79   }
80
81   /**
82    * Returns the file extension to use for a saved viewer session file (.cxs)
83    * 
84    * @return
85    * @see https://www.cgl.ucsf.edu/chimerax/docs/user/commands/save.html#sesformat
86    */
87   @Override
88   public String getSessionFileExtension()
89   {
90     return CHIMERAX_SESSION_EXTENSION;
91   }
92
93   @Override
94   public String getHelpURL()
95   {
96     return "http://www.rbvi.ucsf.edu/chimerax/docs/user/index.html";
97   }
98
99   @Override
100   protected ViewerType getViewerType()
101   {
102     return ViewerType.CHIMERAX;
103   }
104
105   @Override
106   protected String getModelId(int pdbfnum, String file)
107   {
108     return String.valueOf(pdbfnum + 1);
109   }
110
111   /**
112    * Returns a model of the structure positions described by the ChimeraX format
113    * atomspec
114    * 
115    * @param atomSpec
116    * @return
117    */
118   @Override
119   protected AtomSpec parseAtomSpec(String atomSpec)
120   {
121     return AtomSpec.fromChimeraXAtomspec(atomSpec);
122   }
123
124 }