2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.ext.rbvi.chimera;
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertTrue;
26 import jalview.structure.AtomSpecModel;
27 import jalview.structure.StructureCommandI;
28 import jalview.structure.StructureCommandsI;
30 import java.awt.Color;
31 import java.util.HashMap;
32 import java.util.LinkedHashMap;
33 import java.util.List;
36 import org.testng.annotations.Test;
38 public class ChimeraXCommandsTest
40 @Test(groups = { "Functional" })
41 public void testColourByCharge()
43 List<StructureCommandI> cmd = new ChimeraXCommands().colourByCharge();
44 assertEquals(cmd.size(), 1);
45 assertEquals(cmd.get(0).getCommand(),
46 "color white;color :ASP,GLU red;color :LYS,ARG blue;color :CYS yellow");
49 @Test(groups = { "Functional" })
50 public void testColourByChain()
52 StructureCommandI cmd = new ChimeraXCommands().colourByChain();
53 assertEquals(cmd.getCommand(), "rainbow chain");
56 @Test(groups = { "Functional" })
57 public void testFocusView()
59 StructureCommandI cmd = new ChimeraXCommands().focusView();
60 assertEquals(cmd.getCommand(), "view");
63 @Test(groups = { "Functional" })
64 public void testColourBySequence()
66 Map<Object, AtomSpecModel> map = new LinkedHashMap<>();
67 ChimeraCommands.addAtomSpecRange(map, Color.blue, "1", 2, 5, "A");
68 ChimeraCommands.addAtomSpecRange(map, Color.blue, "1", 7, 7, "B");
69 ChimeraCommands.addAtomSpecRange(map, Color.blue, "1", 9, 23, "A");
70 ChimeraCommands.addAtomSpecRange(map, Color.blue, "2", 1, 1, "A");
71 ChimeraCommands.addAtomSpecRange(map, Color.blue, "2", 4, 7, "B");
72 ChimeraCommands.addAtomSpecRange(map, Color.yellow, "2", 8, 8, "A");
73 ChimeraCommands.addAtomSpecRange(map, Color.yellow, "2", 3, 5, "A");
74 ChimeraCommands.addAtomSpecRange(map, Color.red, "1", 3, 5, "A");
75 ChimeraCommands.addAtomSpecRange(map, Color.red, "1", 6, 9, "A");
78 * Colours should appear in the Chimera command in the order in which
79 * they were added; within colour, by model, by chain, ranges in start order
81 List<StructureCommandI> commands = new ChimeraXCommands()
82 .colourBySequence(map);
83 assertEquals(commands.size(), 3);
84 assertEquals(commands.get(0).getCommand(),
85 "color #1/A:2-5,9-23/B:7|#2/A:1/B:4-7 #0000ff");
86 assertEquals(commands.get(1).getCommand(), "color #2/A:3-5,8 #ffff00");
87 assertEquals(commands.get(2).getCommand(), "color #1/A:3-9 #ff0000");
90 @Test(groups = { "Functional" })
91 public void testSetAttributes()
94 * make a map of { featureType, {featureValue, {residue range specification } } }
96 Map<String, Map<Object, AtomSpecModel>> featuresMap = new LinkedHashMap<>();
97 Map<Object, AtomSpecModel> featureValues = new HashMap<>();
100 * start with just one feature/value...
102 featuresMap.put("chain", featureValues);
103 ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 8, 20, "A");
105 ChimeraXCommands commandGenerator = new ChimeraXCommands();
106 List<StructureCommandI> commands = commandGenerator
107 .setAttributes(featuresMap);
108 assertEquals(commands.size(), 1);
111 * feature name gets a jv_ namespace prefix
112 * feature value is quoted in case it contains spaces
114 assertEquals(commands.get(0).getCommand(),
115 "setattr #0/A:8-20 res jv_chain 'X' create true");
117 // add same feature value, overlapping range
118 ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 3, 9, "A");
119 // same feature value, contiguous range
120 ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "A");
121 commands = commandGenerator.setAttributes(featuresMap);
122 assertEquals(commands.size(), 1);
123 assertEquals(commands.get(0).getCommand(),
124 "setattr #0/A:3-25 res jv_chain 'X' create true");
126 // same feature value and model, different chain
127 ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "B");
128 // same feature value and chain, different model
129 ChimeraCommands.addAtomSpecRange(featureValues, "X", "1", 26, 30, "A");
130 commands = commandGenerator.setAttributes(featuresMap);
131 assertEquals(commands.size(), 1);
132 String expected1 = "setattr #0/A:3-25/B:21-25|#1/A:26-30 res jv_chain 'X' create true";
133 assertEquals(commands.get(0).getCommand(), expected1);
135 // same feature, different value
136 ChimeraCommands.addAtomSpecRange(featureValues, "Y", "0", 40, 50, "A");
137 commands = commandGenerator.setAttributes(featuresMap);
138 assertEquals(2, commands.size());
139 // commands are ordered by feature type but not by value
140 // so test for the expected command in either order
141 String cmd1 = commands.get(0).getCommand();
142 String cmd2 = commands.get(1).getCommand();
144 cmd1.equals(expected1) || cmd2.equals(expected1));
145 String expected2 = "setattr #0/A:40-50 res jv_chain 'Y' create true";
147 cmd1.equals(expected2) || cmd2.equals(expected2));
150 featureValues.clear();
151 featuresMap.put("side-chain binding!", featureValues);
152 ChimeraCommands.addAtomSpecRange(featureValues,
153 "<html>metal <a href=\"http:a.b.c/x\"> 'ion!", "0", 7, 15,
155 // feature names are sanitised to change non-alphanumeric to underscore
156 // feature values are sanitised to encode single quote characters
157 commands = commandGenerator.setAttributes(featuresMap);
158 assertEquals(commands.size(), 1);
159 String expected3 = "setattr #0/A:7-15 res jv_side_chain_binding_ '<html>metal <a href=\"http:a.b.c/x\"> 'ion!' create true";
160 assertTrue(commands.get(0).getCommand().equals(expected3));
163 @Test(groups = { "Functional" })
164 public void testSuperposeStructures()
166 StructureCommandsI testee = new ChimeraXCommands();
167 AtomSpecModel ref = new AtomSpecModel();
168 ref.addRange("1", 12, 14, "A");
169 ref.addRange("1", 18, 18, "B");
170 ref.addRange("1", 22, 23, "B");
171 AtomSpecModel toAlign = new AtomSpecModel();
172 toAlign.addRange("2", 15, 17, "B");
173 toAlign.addRange("2", 20, 21, "B");
174 toAlign.addRange("2", 22, 22, "C");
175 List<StructureCommandI> command = testee.superposeStructures(ref,
177 assertEquals(command.size(), 1);
178 String cmd = command.get(0).getCommand();
179 String refSpec = "#1/A:12-14/B:18,22-23";
180 String toAlignSpec = "#2/B:15-17,20-21/C:22";
183 * superposition arguments include AlphaCarbon restriction,
184 * ribbon command does not
186 String expected = String.format(
187 "align %s@CA|P toAtoms %s@CA|P; ribbon %s|%s; view",
188 refSpec, toAlignSpec, refSpec, toAlignSpec);
189 assertEquals(cmd, expected);
192 @Test(groups = "Functional")
193 public void testGetAtomSpec()
195 StructureCommandsI testee = new ChimeraXCommands();
196 AtomSpecModel model = new AtomSpecModel();
197 assertEquals(testee.getAtomSpec(model, false), "");
198 model.addRange("1", 2, 4, "A");
199 assertEquals(testee.getAtomSpec(model, false), "#1/A:2-4");
200 model.addRange("1", 8, 8, "A");
201 assertEquals(testee.getAtomSpec(model, false), "#1/A:2-4,8");
202 model.addRange("1", 5, 7, "B");
203 assertEquals(testee.getAtomSpec(model, false), "#1/A:2-4,8/B:5-7");
204 model.addRange("1", 3, 5, "A");
205 assertEquals(testee.getAtomSpec(model, false), "#1/A:2-5,8/B:5-7");
206 model.addRange("0", 1, 4, "B");
207 assertEquals(testee.getAtomSpec(model, false),
208 "#0/B:1-4|#1/A:2-5,8/B:5-7");
209 model.addRange("0", 5, 9, "C");
210 assertEquals(testee.getAtomSpec(model, false),
211 "#0/B:1-4/C:5-9|#1/A:2-5,8/B:5-7");
212 model.addRange("1", 8, 10, "B");
213 assertEquals(testee.getAtomSpec(model, false),
214 "#0/B:1-4/C:5-9|#1/A:2-5,8/B:5-10");
215 model.addRange("1", 8, 9, "B");
216 assertEquals(testee.getAtomSpec(model, false),
217 "#0/B:1-4/C:5-9|#1/A:2-5,8/B:5-10");
218 model.addRange("0", 3, 10, "C"); // subsumes 5-9
219 assertEquals(testee.getAtomSpec(model, false),
220 "#0/B:1-4/C:3-10|#1/A:2-5,8/B:5-10");
221 model.addRange("5", 25, 35, " ");
222 assertEquals(testee.getAtomSpec(model, false),
223 "#0/B:1-4/C:3-10|#1/A:2-5,8/B:5-10|#5/:25-35");
226 @Test(groups = "Functional")
227 public void testGetAtomSpec_alphaOnly()
229 StructureCommandsI testee = new ChimeraXCommands();
230 AtomSpecModel model = new AtomSpecModel();
231 assertEquals(testee.getAtomSpec(model, true), "");
232 model.addRange("1", 2, 4, "A");
233 assertEquals(testee.getAtomSpec(model, true), "#1/A:2-4@CA|P");
234 model.addRange("1", 8, 8, "A");
235 assertEquals(testee.getAtomSpec(model, true), "#1/A:2-4,8@CA|P");
236 model.addRange("1", 5, 7, "B");
237 assertEquals(testee.getAtomSpec(model, true), "#1/A:2-4,8/B:5-7@CA|P");
238 model.addRange("1", 3, 5, "A");
239 assertEquals(testee.getAtomSpec(model, true), "#1/A:2-5,8/B:5-7@CA|P");
240 model.addRange("0", 1, 4, "B");
241 assertEquals(testee.getAtomSpec(model, true),
242 "#0/B:1-4@CA|P|#1/A:2-5,8/B:5-7@CA|P");
243 model.addRange("0", 5, 9, "C");
244 assertEquals(testee.getAtomSpec(model, true),
245 "#0/B:1-4/C:5-9@CA|P|#1/A:2-5,8/B:5-7@CA|P");
246 model.addRange("1", 8, 10, "B");
247 assertEquals(testee.getAtomSpec(model, true),
248 "#0/B:1-4/C:5-9@CA|P|#1/A:2-5,8/B:5-10@CA|P");
249 model.addRange("1", 8, 9, "B");
250 assertEquals(testee.getAtomSpec(model, true),
251 "#0/B:1-4/C:5-9@CA|P|#1/A:2-5,8/B:5-10@CA|P");
252 model.addRange("0", 3, 10, "C"); // subsumes 5-9
253 assertEquals(testee.getAtomSpec(model, true),
254 "#0/B:1-4/C:3-10@CA|P|#1/A:2-5,8/B:5-10@CA|P");
255 model.addRange("5", 25, 35, " "); // empty chain code
256 assertEquals(testee.getAtomSpec(model, true),
257 "#0/B:1-4/C:3-10@CA|P|#1/A:2-5,8/B:5-10@CA|P|#5/:25-35@CA|P");
260 @Test(groups = "Functional")
261 public void testGetModelStartNo()
263 StructureCommandsI testee = new ChimeraXCommands();
264 assertEquals(testee.getModelStartNo(), 1);
267 @Test(groups = "Functional")
268 public void testGetResidueSpec()
270 ChimeraCommands testee = new ChimeraXCommands();
271 assertEquals(testee.getResidueSpec("ALA"), ":ALA");
274 @Test(groups = "Functional")
275 public void testShowBackbone()
277 ChimeraCommands testee = new ChimeraXCommands();
278 List<StructureCommandI> showBackbone = testee.showBackbone();
279 assertEquals(showBackbone.size(), 1);
280 assertEquals(showBackbone.get(0).getCommand(),
281 "~display all;show @CA|P pbonds");
284 @Test(groups = "Functional")
285 public void testOpenCommandFile()
287 ChimeraCommands testee = new ChimeraXCommands();
288 assertEquals(testee.openCommandFile("nowhere").getCommand(),
292 @Test(groups = "Functional")
293 public void testSaveSession()
295 ChimeraCommands testee = new ChimeraXCommands();
296 assertEquals(testee.saveSession("somewhere").getCommand(),
297 "save session somewhere");
300 @Test(groups = "Functional")
301 public void testGetColourCommand()
303 ChimeraCommands testee = new ChimeraXCommands();
304 assertEquals(testee.getColourCommand("something", Color.MAGENTA)
306 "color something #ff00ff");
309 @Test(groups = "Functional")
310 public void testSetAttribute()
312 ChimeraCommands testee = new ChimeraXCommands();
313 AtomSpecModel model = new AtomSpecModel();
314 model.addRange("1", 89, 92, "A");
315 model.addRange("2", 12, 20, "B");
316 model.addRange("2", 8, 9, "B");
317 assertEquals(testee.setAttribute("phi", "27.3", model).getCommand(),
318 "setattr #1/A:89-92|#2/B:8-9,12-20 res phi '27.3' create true");