1 package jalview.ext.jmol;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertNotNull;
6 import jalview.datamodel.PDBEntry;
7 import jalview.datamodel.SequenceI;
8 import jalview.gui.AlignFrame;
9 import jalview.gui.AlignViewport;
10 import jalview.gui.AppJmolBinding;
11 import jalview.io.DataSourceType;
12 import jalview.io.FileLoader;
13 import jalview.structure.StructureMapping;
14 import jalview.structure.StructureSelectionManager;
16 import java.util.HashMap;
17 import java.util.List;
20 import org.testng.annotations.BeforeTest;
21 import org.testng.annotations.Test;
23 import junit.extensions.PA;
25 public class JalviewJmolBindingTest
27 private AlignFrame af;
29 @BeforeTest(alwaysRun = true)
32 af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
36 @Test(groups = "Functional")
37 public void testBuildShowStructuresCommand()
39 AlignViewport av = af.getViewport();
40 PDBEntry[] pdbs = new PDBEntry[] {};
41 SequenceI seq1 = av.getAlignment().findSequenceMatch("FER1_SPIOL")[0];
43 SequenceI seq2 = av.getAlignment().findSequenceMatch("FER2_ARATH")[0];
45 StructureSelectionManager ssm = new StructureSelectionManager();
46 SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
47 AppJmolBinding testee = new AppJmolBinding(null, ssm, pdbs, seqs,
51 * map FER1_SPIOL residues 51-100 to residues 1-50 (atoms 1-250) in 1A70
52 * and residues 110-147 to structure residues 60-97
53 * (in fact there is no gap, added here for test purposes)
55 HashMap<Integer, int[]> map = new HashMap<>();
56 for (int pos = 51; pos <= 100; pos++)
58 map.put(pos, new int[] { pos - 50, 5 * (pos - 50) });
60 for (int pos = 110; pos <= 147; pos++)
62 map.put(pos, new int[] { pos - 50, 5 * (pos - 50) });
64 StructureMapping sm1 = new StructureMapping(seq1, "1a70.pdb", "1A70",
66 ssm.addStructureMapping(sm1);
69 * map FER2_ARATH residues 53-148 to residues 2-97 in 4ZHO
71 map = new HashMap<>();
72 for (int pos = 53; pos <= 148; pos++)
74 map.put(pos, new int[] { pos - 51, 5 * (pos - 51) });
76 StructureMapping sm2 = new StructureMapping(seq2, "4zho.pdb", "4ZHO",
78 ssm.addStructureMapping(sm2);
83 String cmd = testee.buildShowStructuresCommand(av, true);
84 assertEquals(cmd, "display *; cartoon only; zoom 0");
85 cmd = testee.buildShowStructuresCommand(av, false);
86 assertEquals(cmd, "display *; cartoon only");
89 * stub out modelFileNames - array index is Jmol
92 PA.setValue(testee, "modelFileNames",
94 { "1a70.pdb", "4zho.pdb" });
97 * stub out lookup map from pdb:chain to filename
99 Map<String, String> chainFiles = new HashMap<>();
100 PA.setValue(testee, "chainFile", chainFiles);
101 chainFiles.put("1A70:A", "1a70.pdb");
102 chainFiles.put("1A70:B", "1a70.pdb");
103 chainFiles.put("4ZHO:B", "4zho.pdb");
104 chainFiles.put("4ZHO:C", "4zho.pdb");
107 * show all except for selected chains to hide
109 List<String> chainsToHide = (List<String>) PA.getValue(testee,
111 chainsToHide.add("1A70:B");
112 chainsToHide.add("4ZHO:C");
113 cmd = testee.buildShowStructuresCommand(av, true);
115 "display *; hide add :B/1.1,:C/2.1; cartoon only; zoom 0");
118 * show alignment only, no chains hidden
120 chainsToHide.clear();
121 testee.setShowAlignmentOnly(true);
122 cmd = testee.buildShowStructuresCommand(av, false);
124 "hide *;display (1-50,60-97)&:A/1.1,2-97:B/2.1; select displayed; cartoon only");
127 * now with a chain hidden
129 chainsToHide.add("4ZHO:C");
130 cmd = testee.buildShowStructuresCommand(av, false);
131 String expected = "hide *;display (1-50,60-97)&:A/1.1,2-97:B/2.1; select displayed; hide add :C/2.1; cartoon only";
132 assertEquals(cmd, expected);
135 * hide columns in the mapped region - should not change the command (yet)
137 int fromCol = seq1.findIndex(60); // structure residue 10
138 int toCol = seq1.findIndex(70); // structure residue 20
139 av.hideColumns(fromCol - 1, toCol - 1);
140 cmd = testee.buildShowStructuresCommand(av, false);
141 assertEquals(cmd, expected);
144 * select 'hide hidden columns'
145 * command should now exclude these in both mapped sequences
147 testee.setHideHiddenRegions(true);
148 cmd = testee.buildShowStructuresCommand(av, false);
149 expected = "hide *;display (1-9,21-50,60-97)&:A/1.1,(2-10,22-97)&:B/2.1; select displayed; hide add :C/2.1; cartoon only";
150 assertEquals(cmd, expected);
153 * deselect 'show alignment only'
154 * hide hidden columns is now ignored
156 testee.setShowAlignmentOnly(false);
157 cmd = testee.buildShowStructuresCommand(av, false);
158 assertEquals(cmd, "display *; hide add :C/2.1; cartoon only");