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.pymol;
23 import static org.testng.Assert.assertEquals;
25 import jalview.structure.AtomSpecModel;
26 import jalview.structure.StructureCommandI;
27 import jalview.structure.StructureCommandsI;
29 import java.awt.Color;
30 import java.util.LinkedHashMap;
31 import java.util.List;
34 import org.testng.annotations.Test;
36 public class PymolCommandsTest
39 @Test(groups = { "Functional" })
40 public void testColourBySequence()
43 Map<Object, AtomSpecModel> map = new LinkedHashMap<>();
44 PymolCommands.addAtomSpecRange(map, Color.blue, "0", 2, 5, "A");
45 PymolCommands.addAtomSpecRange(map, Color.blue, "0", 7, 7, "B");
46 PymolCommands.addAtomSpecRange(map, Color.blue, "0", 9, 23, "A");
47 PymolCommands.addAtomSpecRange(map, Color.blue, "1", 1, 1, "A");
48 PymolCommands.addAtomSpecRange(map, Color.blue, "1", 4, 7, "B");
49 PymolCommands.addAtomSpecRange(map, Color.yellow, "1", 8, 8, "A");
50 PymolCommands.addAtomSpecRange(map, Color.yellow, "1", 3, 5, "A");
51 PymolCommands.addAtomSpecRange(map, Color.red, "0", 3, 5, "A");
52 PymolCommands.addAtomSpecRange(map, Color.red, "0", 6, 9, "A");
54 // Colours should appear in the Pymol command in the order in which
55 // they were added; within colour, by model, by chain, ranges in start order
56 List<StructureCommandI> commands = new PymolCommands()
57 .colourBySequence(map);
58 assertEquals(commands.size(), 3);
59 assertEquals(commands.get(0).toString(),
60 "color(0x0000ff,0//A/2-5+9-23/ 0//B/7/ 1//A/1/ 1//B/4-7/)");
61 assertEquals(commands.get(1).toString(), "color(0xffff00,1//A/3-5+8/)");
63 commands.get(2).toString(), "color(0xff0000,0//A/3-9/)");
66 @Test(groups = "Functional")
67 public void testGetAtomSpec()
69 StructureCommandsI testee = new PymolCommands();
70 AtomSpecModel model = new AtomSpecModel();
71 assertEquals(testee.getAtomSpec(model, false), "");
72 model.addRange("1", 2, 4, "A");
73 assertEquals(testee.getAtomSpec(model, false), "1//A/2-4/");
74 model.addRange("1", 8, 8, "A");
75 assertEquals(testee.getAtomSpec(model, false), "1//A/2-4+8/");
76 model.addRange("1", 5, 7, "B");
77 assertEquals(testee.getAtomSpec(model, false), "1//A/2-4+8/ 1//B/5-7/");
78 model.addRange("1", 3, 5, "A");
79 assertEquals(testee.getAtomSpec(model, false), "1//A/2-5+8/ 1//B/5-7/");
80 model.addRange("0", 1, 4, "B");
81 assertEquals(testee.getAtomSpec(model, false),
82 "0//B/1-4/ 1//A/2-5+8/ 1//B/5-7/");
83 model.addRange("0", 5, 9, "C");
84 assertEquals(testee.getAtomSpec(model, false),
85 "0//B/1-4/ 0//C/5-9/ 1//A/2-5+8/ 1//B/5-7/");
86 model.addRange("1", 8, 10, "B");
87 assertEquals(testee.getAtomSpec(model, false),
88 "0//B/1-4/ 0//C/5-9/ 1//A/2-5+8/ 1//B/5-10/");
89 model.addRange("1", 8, 9, "B");
90 assertEquals(testee.getAtomSpec(model, false),
91 "0//B/1-4/ 0//C/5-9/ 1//A/2-5+8/ 1//B/5-10/");
92 model.addRange("0", 3, 10, "C"); // subsumes 5-9
93 assertEquals(testee.getAtomSpec(model, false),
94 "0//B/1-4/ 0//C/3-10/ 1//A/2-5+8/ 1//B/5-10/");
95 model.addRange("5", 25, 35, " ");
96 assertEquals(testee.getAtomSpec(model, false),
97 "0//B/1-4/ 0//C/3-10/ 1//A/2-5+8/ 1//B/5-10/ 5///25-35/");
101 @Test(groups = { "Functional" })
102 public void testSuperposeStructures()
104 StructureCommandsI testee = new PymolCommands();
105 AtomSpecModel ref = new AtomSpecModel();
106 ref.addRange("1", 12, 14, "A");
107 ref.addRange("1", 18, 18, "B");
108 ref.addRange("1", 22, 23, "B");
109 AtomSpecModel toAlign = new AtomSpecModel();
110 toAlign.addRange("2", 15, 17, "B");
111 toAlign.addRange("2", 20, 21, "B");
112 toAlign.addRange("2", 22, 22, "C");
113 List<StructureCommandI> commands = testee.superposeStructures(ref,
115 assertEquals(commands.size(), 2);
116 String refSpecCA = "1//A/12-14/CA 1//B/18+22-23/CA";
117 String toAlignSpecCA = "2//B/15-17+20-21/CA 2//C/22/CA";
118 String refSpec = "1//A/12-14/ 1//B/18+22-23/";
119 String toAlignSpec = "2//B/15-17+20-21/ 2//C/22/";
120 String expected1 = String.format("super(%s,%s)", refSpecCA,
122 String expected2 = String.format("show(cartoon,%s %s)", refSpec,
124 assertEquals(commands.get(0).toString(), expected1);
125 assertEquals(commands.get(1).toString(), expected2);
128 @Test(groups = "Functional")
129 public void testGetAtomSpec_alphaOnly()
131 StructureCommandsI testee = new PymolCommands();
132 AtomSpecModel model = new AtomSpecModel();
133 assertEquals(testee.getAtomSpec(model, true), "");
134 model.addRange("1", 2, 4, "A");
135 assertEquals(testee.getAtomSpec(model, true), "1//A/2-4/CA");
136 model.addRange("1", 8, 8, "A");
137 assertEquals(testee.getAtomSpec(model, true), "1//A/2-4+8/CA");
138 model.addRange("1", 5, 7, "B");
139 assertEquals(testee.getAtomSpec(model, true),
140 "1//A/2-4+8/CA 1//B/5-7/CA");
141 model.addRange("1", 3, 5, "A");
142 assertEquals(testee.getAtomSpec(model, true),
143 "1//A/2-5+8/CA 1//B/5-7/CA");
144 model.addRange("0", 1, 4, "B");
145 assertEquals(testee.getAtomSpec(model, true),
146 "0//B/1-4/CA 1//A/2-5+8/CA 1//B/5-7/CA");
147 model.addRange("0", 5, 9, "C");
148 assertEquals(testee.getAtomSpec(model, true),
149 "0//B/1-4/CA 0//C/5-9/CA 1//A/2-5+8/CA 1//B/5-7/CA");
150 model.addRange("1", 8, 10, "B");
151 assertEquals(testee.getAtomSpec(model, true),
152 "0//B/1-4/CA 0//C/5-9/CA 1//A/2-5+8/CA 1//B/5-10/CA");
153 model.addRange("1", 8, 9, "B");
154 assertEquals(testee.getAtomSpec(model, true),
155 "0//B/1-4/CA 0//C/5-9/CA 1//A/2-5+8/CA 1//B/5-10/CA");
156 model.addRange("0", 3, 10, "C"); // subsumes 5-9
157 assertEquals(testee.getAtomSpec(model, true),
158 "0//B/1-4/CA 0//C/3-10/CA 1//A/2-5+8/CA 1//B/5-10/CA");
159 model.addRange("5", 25, 35, " ");
160 assertEquals(testee.getAtomSpec(model, true),
161 "0//B/1-4/CA 0//C/3-10/CA 1//A/2-5+8/CA 1//B/5-10/CA 5///25-35/CA");
164 @Test(groups = "Functional")
165 public void testGetModelStartNo()
167 StructureCommandsI testee = new PymolCommands();
168 assertEquals(testee.getModelStartNo(), 0);
171 @Test(groups = "Functional")
172 public void testGetResidueSpec()
174 PymolCommands testee = new PymolCommands();
175 assertEquals(testee.getResidueSpec("ALA"), "resn ALA");
178 @Test(groups = "Functional")
179 public void testShowBackbone()
181 PymolCommands testee = new PymolCommands();
182 List<StructureCommandI> cmds = testee.showBackbone();
183 assertEquals(cmds.size(), 2);
184 assertEquals(cmds.get(0).toString(), "hide(everything)");
185 assertEquals(cmds.get(1).toString(), "show(ribbon)");
188 @Test(groups = "Functional")
189 public void testColourByCharge()
191 PymolCommands testee = new PymolCommands();
192 List<StructureCommandI> cmds = testee.colourByCharge();
193 assertEquals(cmds.size(), 4);
194 assertEquals(cmds.get(0).toString(), "color(white,*)");
195 assertEquals(cmds.get(1).toString(), "color(red,resn ASP resn GLU)");
196 assertEquals(cmds.get(2).toString(), "color(blue,resn LYS resn ARG)");
197 assertEquals(cmds.get(3).toString(), "color(yellow,resn CYS)");
200 @Test(groups = "Functional")
201 public void testOpenCommandFile()
203 PymolCommands testee = new PymolCommands();
204 assertEquals(testee.openCommandFile("commands.pml").toString(),
208 @Test(groups = "Functional")
209 public void testSaveSession()
211 PymolCommands testee = new PymolCommands();
212 assertEquals(testee.saveSession("somewhere.pse").toString(),
213 "save(somewhere.pse)");
216 @Test(groups = "Functional")
217 public void testColourByChain()
219 PymolCommands testee = new PymolCommands();
220 assertEquals(testee.colourByChain().toString(), "spectrum(chain)");
223 @Test(groups = "Functional")
224 public void testGetColourCommand()
226 PymolCommands testee = new PymolCommands();
228 testee.getColourCommand("something", Color.MAGENTA).toString(),
229 "color(0xff00ff,something)");