}
@Override
- public StructureCommandI setBackgroundColour(Color col)
- {
- // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/set.html
- return new StructureCommand("set bgColor " + ColorUtils.toTkCode(col));
- }
-
- @Override
public StructureCommandI colourResidues(String atomSpec, Color colour)
{
// https://www.cgl.ucsf.edu/chimerax/docs/user/commands/color.html
return sb.toString();
}
+ @Override
+ public int hashCode()
+ {
+ int h = command.hashCode();
+ if (parameters != null)
+ {
+ for (String p : parameters)
+ {
+ h = h * 37 + p.hashCode();
+ }
+ }
+ return h;
+ }
+
+ /**
+ * Answers true if {@code obj} is a {@code StructureCommand} with the same
+ * command and parameters as this one, else false
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null || !(obj instanceof StructureCommand))
+ {
+ return false;
+ }
+ StructureCommand sc = (StructureCommand) obj;
+
+ if (!command.equals(sc.command))
+ {
+ return false;
+ }
+ if (parameters == null || sc.parameters == null)
+ {
+ return (parameters == null) && (sc.parameters == null);
+ }
+
+ int j = parameters.size();
+ if (j != sc.parameters.size())
+ {
+ return false;
+ }
+ for (int i = 0; i < j; i++)
+ {
+ if (!parameters.get(i).equals(sc.parameters.get(i)))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
}
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
-import jalview.gui.JvOptionPane;
import jalview.gui.SequenceRenderer;
import jalview.schemes.JalviewColourScheme;
import jalview.structure.AtomSpecModel;
import jalview.structure.StructureCommandI;
-import jalview.structure.StructureCommandsI;
import jalview.structure.StructureMapping;
import jalview.structure.StructureSelectionManager;
public class JmolCommandsTest
{
+ private JmolCommands testee;
- @BeforeClass(alwaysRun = true)
- public void setUpJvOptionPane()
+ @BeforeClass
+ public void setUp()
{
- JvOptionPane.setInteractiveMode(false);
- JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ testee = new JmolCommands();
}
@Test(groups = { "Functional" })
"B", map, null);
ssm.addStructureMapping(sm2);
- String[] commands = new JmolCommands().colourBySequence(ssm, files,
+ String[] commands = testee.colourBySequence(ssm,
+ files,
seqs, sr, af.alignPanel);
assertEquals(commands.length, 2);
@Test(groups = "Functional")
public void testGetAtomSpec()
{
- StructureCommandsI testee = new JmolCommands();
AtomSpecModel model = new AtomSpecModel();
assertEquals(testee.getAtomSpec(model, false), "");
model.addRange("1", 2, 4, "A");
model.addRange("5", 25, 35, " ");
assertEquals(testee.getAtomSpec(model, false),
"2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|3-10:C/2.1|25-35:/5.1");
-
+
}
@Test(groups = { "Functional" })
// Colours should appear in the Jmol command in the order in which
// they were added; within colour, by model, by chain, ranges in start order
- List<StructureCommandI> commands = new JmolCommands()
- .colourBySequence(map);
+ List<StructureCommandI> commands = testee.colourBySequence(map);
assertEquals(commands.size(), 1);
String expected1 = "select 2-5:A/1.1|9-23:A/1.1|7:B/1.1|1:A/2.1|4-7:B/2.1;color[0,0,255]";
String expected2 = "select 3-5:A/2.1|8:A/2.1;color[255,255,0]";
@Test(groups = { "Functional" })
public void testSuperposeStructures()
{
- StructureCommandsI testee = new JmolCommands();
AtomSpecModel ref = new AtomSpecModel();
ref.addRange("1", 12, 14, "A");
ref.addRange("1", 18, 18, "B");
@Test(groups = "Functional")
public void testGetModelStartNo()
{
- StructureCommandsI testee = new JmolCommands();
assertEquals(testee.getModelStartNo(), 1);
}
+
+ @Test(groups = "Functional")
+ public void testColourByChain()
+ {
+ StructureCommandI cmd = testee.colourByChain();
+ assertEquals(cmd.getCommand(), "select *;color chain");
+ }
+
+ @Test(groups = "Functional")
+ public void testColourByCharge()
+ {
+ List<StructureCommandI> cmds = testee.colourByCharge();
+ assertEquals(cmds.size(), 1);
+ assertEquals(cmds.get(0).getCommand(),
+ "select *;color white;select ASP,GLU;color red;"
+ + "select LYS,ARG;color blue;select CYS;color yellow");
+ }
+
+ @Test(groups = "Functional")
+ public void testSetBackgroundColour()
+ {
+ StructureCommandI cmd = testee.setBackgroundColour(Color.PINK);
+ assertEquals(cmd.getCommand(), "background [255, 175, 175]");
+ }
+
+ @Test(groups = "Functional")
+ public void testFocusView()
+ {
+ StructureCommandI cmd = testee.focusView();
+ assertEquals(cmd.getCommand(), "zoom 0");
+ }
+
+ @Test(groups = "Functional")
+ public void testSaveSession()
+ {
+ StructureCommandI cmd = testee.saveSession("/some/filepath");
+ assertEquals(cmd.getCommand(), "write STATE \"/some/filepath\"");
+ }
+
+ @Test(groups = "Functional")
+ public void testShowBackbone()
+ {
+ List<StructureCommandI> cmds = testee.showBackbone();
+ assertEquals(cmds.size(), 1);
+ assertEquals(cmds.get(0).getCommand(),
+ "select *; cartoons off; backbone");
+ }
+
+ @Test(groups = "Functional")
+ public void testLoadFile()
+ {
+ StructureCommandI cmd = testee.loadFile("/some/filepath");
+ assertEquals(cmd.getCommand(), "load FILES \"/some/filepath\"");
+
+ // single backslash gets escaped to double
+ cmd = testee.loadFile("\\some\\filepath");
+ assertEquals(cmd.getCommand(), "load FILES \"\\\\some\\\\filepath\"");
+ }
+
+ @Test(groups = "Functional")
+ public void testOpenSession()
+ {
+ StructureCommandI cmd = testee.openSession("/some/filepath");
+ assertEquals(cmd.getCommand(), "load FILES \"/some/filepath\"");
+
+ // single backslash gets escaped to double
+ cmd = testee.openSession("\\some\\filepath");
+ assertEquals(cmd.getCommand(), "load FILES \"\\\\some\\\\filepath\"");
+ }
}
package jalview.ext.pymol;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
import java.awt.Color;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import jalview.ext.rbvi.chimera.ChimeraCommands;
import jalview.structure.AtomSpecModel;
+import jalview.structure.StructureCommand;
import jalview.structure.StructureCommandI;
-import jalview.structure.StructureCommandsI;
public class PymolCommandsTest
{
+ private PymolCommands testee;
+
+ @BeforeClass
+ public void setUp()
+ {
+ testee = new PymolCommands();
+ }
@Test(groups = { "Functional" })
public void testColourBySequence()
// Colours should appear in the Pymol command in the order in which
// they were added; within colour, by model, by chain, ranges in start order
- List<StructureCommandI> commands = new PymolCommands()
- .colourBySequence(map);
+ List<StructureCommandI> commands = testee.colourBySequence(map);
assertEquals(commands.size(), 3);
- assertEquals(commands.get(0).toString(),
- "color(0x0000ff,0//A/2-5+9-23/ 0//B/7/ 1//A/1/ 1//B/4-7/)");
- assertEquals(commands.get(1).toString(), "color(0xffff00,1//A/3-5+8/)");
- assertEquals(
- commands.get(2).toString(), "color(0xff0000,0//A/3-9/)");
+ assertEquals(commands.get(0), new StructureCommand("color", "0x0000ff",
+ "0//A/2-5+9-23/ 0//B/7/ 1//A/1/ 1//B/4-7/"));
+ assertEquals(commands.get(
+ 1),
+ new StructureCommand("color", "0xffff00", "1//A/3-5+8/"));
+ assertEquals(commands.get(
+ 2),
+ new StructureCommand("color", "0xff0000", "0//A/3-9/"));
}
@Test(groups = "Functional")
public void testGetAtomSpec()
{
- StructureCommandsI testee = new PymolCommands();
AtomSpecModel model = new AtomSpecModel();
assertEquals(testee.getAtomSpec(model, false), "");
model.addRange("1", 2, 4, "A");
@Test(groups = { "Functional" })
public void testSuperposeStructures()
{
- StructureCommandsI testee = new PymolCommands();
AtomSpecModel ref = new AtomSpecModel();
ref.addRange("1", 12, 14, "A");
ref.addRange("1", 18, 18, "B");
String toAlignSpecCA = "2//B/15-17+20-21/CA 2//C/22/CA";
String refSpec = "1//A/12-14/ 1//B/18+22-23/";
String toAlignSpec = "2//B/15-17+20-21/ 2//C/22/";
- String expected1 = String.format("super(%s,%s)", refSpecCA,
- toAlignSpecCA);
- String expected2 = String.format("show(cartoon,%s %s)", refSpec,
- toAlignSpec);
- assertEquals(commands.get(0).toString(), expected1);
- assertEquals(commands.get(1).toString(), expected2);
+
+ // super command: separate arguments for regions to align
+ assertEquals(commands.get(0),
+ new StructureCommand("super", refSpecCA, toAlignSpecCA));
+ // show aligned regions: one argument for combined atom specs
+ assertEquals(commands.get(1), new StructureCommand("show", "cartoon",
+ refSpec + " " + toAlignSpec));
}
@Test(groups = "Functional")
public void testGetAtomSpec_alphaOnly()
{
- StructureCommandsI testee = new PymolCommands();
AtomSpecModel model = new AtomSpecModel();
assertEquals(testee.getAtomSpec(model, true), "");
model.addRange("1", 2, 4, "A");
@Test(groups = "Functional")
public void testGetModelStartNo()
{
- StructureCommandsI testee = new PymolCommands();
assertEquals(testee.getModelStartNo(), 0);
}
@Test(groups = "Functional")
public void testGetResidueSpec()
{
- PymolCommands testee = new PymolCommands();
assertEquals(testee.getResidueSpec("ALA"), "resn ALA");
}
@Test(groups = "Functional")
public void testShowBackbone()
{
- PymolCommands testee = new PymolCommands();
List<StructureCommandI> cmds = testee.showBackbone();
assertEquals(cmds.size(), 2);
- assertEquals(cmds.get(0).toString(), "hide(everything)");
- assertEquals(cmds.get(1).toString(), "show(ribbon)");
+ assertEquals(cmds.get(0), new StructureCommand("hide", "everything"));
+ assertEquals(cmds.get(1), new StructureCommand("show", "ribbon"));
}
@Test(groups = "Functional")
public void testColourByCharge()
{
- PymolCommands testee = new PymolCommands();
List<StructureCommandI> cmds = testee.colourByCharge();
assertEquals(cmds.size(), 4);
- assertEquals(cmds.get(0).toString(), "color(white,*)");
- assertEquals(cmds.get(1).toString(), "color(red,resn ASP resn GLU)");
- assertEquals(cmds.get(2).toString(), "color(blue,resn LYS resn ARG)");
- assertEquals(cmds.get(3).toString(), "color(yellow,resn CYS)");
+ assertEquals(cmds.get(0), new StructureCommand("color", "white", "*"));
+ assertEquals(cmds.get(1),
+ new StructureCommand("color", "red", "resn ASP resn GLU"));
+ assertEquals(cmds.get(2),
+ new StructureCommand("color", "blue", "resn LYS resn ARG"));
+ assertEquals(cmds.get(3),
+ new StructureCommand("color", "yellow", "resn CYS"));
}
@Test(groups = "Functional")
public void testOpenCommandFile()
{
- PymolCommands testee = new PymolCommands();
- assertEquals(testee.openCommandFile("commands.pml").toString(),
- "run(commands.pml)");
+ assertEquals(testee.openCommandFile("commands.pml"),
+ new StructureCommand("run", "commands.pml"));
}
@Test(groups = "Functional")
public void testSaveSession()
{
- PymolCommands testee = new PymolCommands();
- assertEquals(testee.saveSession("somewhere.pse").toString(),
- "save(somewhere.pse)");
+ assertEquals(testee.saveSession("somewhere.pse"),
+ new StructureCommand("save", "somewhere.pse"));
+ }
+
+ @Test(groups = "Functional")
+ public void testOpenSession()
+ {
+ assertEquals(testee.openSession("/some/path"),
+ new StructureCommand("load", "/some/path", "", "0", "pse"));
}
@Test(groups = "Functional")
public void testColourByChain()
{
- PymolCommands testee = new PymolCommands();
- assertEquals(testee.colourByChain().toString(), "spectrum(chain)");
+ assertEquals(testee.colourByChain(),
+ new StructureCommand("spectrum", "chain"));
+ }
+
+ @Test(groups = "Functional")
+ public void testColourResidues()
+ {
+ assertEquals(testee.colourResidues("something",
+ Color.MAGENTA),
+ new StructureCommand("color", "0xff00ff", "something"));
+ }
+
+ @Test(groups = "Functional")
+ public void testLoadFile()
+ {
+ assertEquals(testee.loadFile("/some/path"),
+ new StructureCommand("load", "/some/path"));
}
@Test(groups = "Functional")
- public void testGetColourCommand()
+ public void testSetBackgroundColour()
{
- PymolCommands testee = new PymolCommands();
- assertEquals(
- testee.colourResidues("something", Color.MAGENTA).toString(),
- "color(0xff00ff,something)");
+ assertEquals(testee.setBackgroundColour(
+ Color.PINK),
+ new StructureCommand("bg_color", "0xffafaf"));
+ }
+
+ @Test(groups = "Functional")
+ public void testSetAttribute()
+ {
+ AtomSpecModel model = new AtomSpecModel();
+ model.addRange("1", 89, 92, "A");
+ model.addRange("2", 12, 20, "B");
+ model.addRange("2", 8, 9, "B");
+ assertEquals(testee.setAttribute("jv_kd", "27.3", model),
+ new StructureCommand("iterate", "1//A/89-92/ 2//B/8-9+12-20/",
+ "p.jv_kd='27.3'"));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testSetAttributes()
+ {
+ /*
+ * make a map of { featureType, {featureValue, {residue range specification } } }
+ */
+ Map<String, Map<Object, AtomSpecModel>> featuresMap = new LinkedHashMap<>();
+ Map<Object, AtomSpecModel> featureValues = new HashMap<>();
+
+ /*
+ * start with just one feature/value...
+ */
+ featuresMap.put("chain", featureValues);
+ ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 8, 20, "A");
+
+ List<StructureCommandI> commands = testee.setAttributes(featuresMap);
+ assertEquals(commands.size(), 1);
+
+ /*
+ * feature name gets a jv_ namespace prefix
+ */
+ assertEquals(commands.get(0), new StructureCommand("iterate",
+ "0//A/8-20/", "p.jv_chain='X'"));
+
+ // add same feature value, overlapping range
+ ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 3, 9, "A");
+ // same feature value, contiguous range
+ ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "A");
+ commands = testee.setAttributes(featuresMap);
+ assertEquals(commands.size(), 1);
+ assertEquals(commands.get(0), new StructureCommand("iterate",
+ "0//A/3-25/", "p.jv_chain='X'"));
+
+ // same feature value and model, different chain
+ ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "B");
+ // same feature value and chain, different model
+ ChimeraCommands.addAtomSpecRange(featureValues, "X", "1", 26, 30, "A");
+ commands = testee.setAttributes(featuresMap);
+ assertEquals(commands.size(), 1);
+ StructureCommand expected1 = new StructureCommand("iterate",
+ "0//A/3-25/ 0//B/21-25/ 1//A/26-30/", "p.jv_chain='X'");
+ assertEquals(commands.get(0), expected1);
+
+ // same feature, different value
+ ChimeraCommands.addAtomSpecRange(featureValues, "Y", "0", 40, 50, "A");
+ commands = testee.setAttributes(featuresMap);
+ assertEquals(2, commands.size());
+ // commands are ordered by feature type but not by value
+ // so test for the expected command in either order
+ StructureCommandI cmd1 = commands.get(0);
+ StructureCommandI cmd2 = commands.get(1);
+ StructureCommand expected2 = new StructureCommand("iterate",
+ "0//A/40-50/", "p.jv_chain='Y'");
+ assertTrue(cmd1.equals(expected1) || cmd2.equals(expected1));
+ // String expected2 = "setattr #0/A:40-50 res jv_chain 'Y' create true";
+ assertTrue(cmd1.equals(expected2) || cmd2.equals(expected2));
+
+ featuresMap.clear();
+ featureValues.clear();
+ featuresMap.put("side-chain binding!", featureValues);
+ ChimeraCommands.addAtomSpecRange(featureValues,
+ "<html>metal <a href=\"http:a.b.c/x\"> 'ion!", "0", 7, 15, "A");
+ // feature names are sanitised to change non-alphanumeric to underscore
+ // feature values are sanitised to encode single quote characters
+ commands = testee.setAttributes(featuresMap);
+ assertEquals(commands.size(), 1);
+ StructureCommandI expected3 = new StructureCommand("iterate",
+ "0//A/7-15/",
+ "p.jv_side_chain_binding_='<html>metal <a href=\"http:a.b.c/x\"> 'ion!'");
+ assertEquals(commands.get(0), expected3);
}
}
import java.util.List;
import java.util.Map;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import jalview.structure.AtomSpecModel;
import jalview.structure.StructureCommandI;
-import jalview.structure.StructureCommandsI;
public class ChimeraCommandsTest
{
+ private ChimeraCommands testee;
+
+ @BeforeClass
+ public void setUp()
+ {
+ testee = new ChimeraCommands();
+ }
@Test(groups = { "Functional" })
public void testColourBySequence()
// Colours should appear in the Chimera command in the order in which
// they were added; within colour, by model, by chain, ranges in start order
- List<StructureCommandI> commands = new ChimeraCommands()
- .colourBySequence(map);
+ List<StructureCommandI> commands = testee.colourBySequence(map);
assertEquals(commands.size(), 1);
assertEquals(commands.get(0).getCommand(),
"color #0000ff #0:2-5.A,9-23.A,7.B|#1:1.A,4-7.B;color #ffff00 #1:3-5.A,8.A;color #ff0000 #0:3-9.A");
*/
Map<String, Map<Object, AtomSpecModel>> featuresMap = new LinkedHashMap<>();
Map<Object, AtomSpecModel> featureValues = new HashMap<>();
-
+
/*
* start with just one feature/value...
*/
featuresMap.put("chain", featureValues);
ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 8, 20, "A");
-
- ChimeraCommands commandGenerator = new ChimeraCommands();
- List<StructureCommandI> commands = commandGenerator
- .setAttributes(featuresMap);
+
+ List<StructureCommandI> commands = testee.setAttributes(featuresMap);
assertEquals(1, commands.size());
/*
ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 3, 9, "A");
// same feature value, contiguous range
ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "A");
- commands = commandGenerator.setAttributes(featuresMap);
+ commands = testee.setAttributes(featuresMap);
assertEquals(1, commands.size());
assertEquals(commands.get(0).getCommand(),
"setattr res jv_chain 'X' #0:3-25.A");
ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "B");
// same feature value and chain, different model
ChimeraCommands.addAtomSpecRange(featureValues, "X", "1", 26, 30, "A");
- commands = commandGenerator.setAttributes(featuresMap);
+ commands = testee.setAttributes(featuresMap);
assertEquals(1, commands.size());
String expected1 = "setattr res jv_chain 'X' #0:3-25.A,21-25.B|#1:26-30.A";
assertEquals(commands.get(0).getCommand(), expected1);
// same feature, different value
ChimeraCommands.addAtomSpecRange(featureValues, "Y", "0", 40, 50, "A");
- commands = commandGenerator.setAttributes(featuresMap);
+ commands = testee.setAttributes(featuresMap);
assertEquals(2, commands.size());
// commands are ordered by feature type but not by value
// so test for the expected command in either order
featureValues.clear();
featuresMap.put("side-chain binding!", featureValues);
ChimeraCommands.addAtomSpecRange(featureValues,
- "<html>metal <a href=\"http:a.b.c/x\"> 'ion!", "0", 7, 15,
- "A");
+ "<html>metal <a href=\"http:a.b.c/x\"> 'ion!", "0", 7, 15, "A");
// feature names are sanitised to change non-alphanumeric to underscore
// feature values are sanitised to encode single quote characters
- commands = commandGenerator.setAttributes(featuresMap);
+ commands = testee.setAttributes(featuresMap);
assertEquals(commands.size(), 1);
String expected3 = "setattr res jv_side_chain_binding_ '<html>metal <a href=\"http:a.b.c/x\"> 'ion!' #0:7-15.A";
assertTrue(commands.get(0).getCommand().equals(expected3));
@Test(groups = { "Functional" })
public void testMakeAttributeName()
{
- ChimeraCommands testee = new ChimeraCommands();
assertEquals(testee.makeAttributeName(null), "jv_");
assertEquals(testee.makeAttributeName(""), "jv_");
assertEquals(testee.makeAttributeName("helix"), "jv_helix");
assertEquals(testee.makeAttributeName(
"Hello World 24"),
"jv_Hello_World_24");
- assertEquals(
- testee.makeAttributeName(
- "!this is-a_very*{odd(name"),
+ assertEquals(testee.makeAttributeName(
+ "!this is-a_very*{odd(name"),
"jv__this_is_a_very__odd_name");
// name ending in color gets underscore appended
- assertEquals(testee.makeAttributeName("helixColor"),
- "jv_helixColor_");
+ assertEquals(testee.makeAttributeName("helixColor"), "jv_helixColor_");
}
@Test(groups = "Functional")
public void testGetAtomSpec()
{
- StructureCommandsI testee = new ChimeraCommands();
AtomSpecModel model = new AtomSpecModel();
assertEquals(testee.getAtomSpec(model, false), "");
model.addRange("1", 2, 4, "A");
@Test(groups = { "Functional" })
public void testSuperposeStructures()
{
- StructureCommandsI testee = new ChimeraCommands();
AtomSpecModel ref = new AtomSpecModel();
ref.addRange("1", 12, 14, "A");
ref.addRange("1", 18, 18, "B");
String carbonAlphas = "@CA&~@.B-Z&~@.2-9";
String refSpec = "#1:12-14.A,18.B,22-23.B";
String toAlignSpec = "#2:15-17.B,20-21.B,22.C";
- String expected = String.format(
- "match %s%s %s%s; ribbon %s|%s; focus", toAlignSpec,
- carbonAlphas, refSpec, carbonAlphas, toAlignSpec, refSpec);
+ String expected = String.format("match %s%s %s%s; ribbon %s|%s; focus",
+ toAlignSpec, carbonAlphas, refSpec, carbonAlphas, toAlignSpec,
+ refSpec);
assertEquals(command.get(0).getCommand(), expected);
}
@Test(groups = "Functional")
public void testGetAtomSpec_alphaOnly()
{
- StructureCommandsI testee = new ChimeraCommands();
AtomSpecModel model = new AtomSpecModel();
assertEquals(testee.getAtomSpec(model, true), "");
model.addRange("1", 2, 4, "A");
model.addRange("5", 25, 35, " "); // empty chain code
assertEquals(testee.getAtomSpec(model, true),
"#0:1-4.B,3-10.C@CA&~@.B-Z&~@.2-9|#1:2-5.A,8.A,5-10.B@CA&~@.B-Z&~@.2-9|#5:25-35.@CA&~@.B-Z&~@.2-9");
-
+
}
@Test(groups = "Functional")
public void testGetModelStartNo()
{
- StructureCommandsI testee = new ChimeraCommands();
assertEquals(testee.getModelStartNo(), 0);
}
@Test(groups = "Functional")
public void testGetResidueSpec()
{
- ChimeraCommands testee = new ChimeraCommands();
assertEquals(testee.getResidueSpec("ALA"), "::ALA");
}
@Test(groups = "Functional")
public void testShowBackbone()
{
- ChimeraCommands testee = new ChimeraCommands();
List<StructureCommandI> cmds = testee.showBackbone();
assertEquals(cmds.size(), 1);
assertEquals(cmds.get(0).getCommand(),
@Test(groups = "Functional")
public void testOpenCommandFile()
{
- ChimeraCommands testee = new ChimeraCommands();
assertEquals(testee.openCommandFile("nowhere").getCommand(),
"open cmd:nowhere");
}
@Test(groups = "Functional")
public void testSaveSession()
{
- ChimeraCommands testee = new ChimeraCommands();
assertEquals(testee.saveSession("somewhere").getCommand(),
"save somewhere");
}
@Test(groups = "Functional")
+ public void testColourByChain()
+ {
+ assertEquals(testee.colourByChain().getCommand(), "rainbow chain");
+ }
+
+ @Test(groups = { "Functional" })
+ public void testSetBackgroundColour()
+ {
+ StructureCommandI cmd = testee.setBackgroundColour(Color.PINK);
+ assertEquals(cmd.getCommand(), "set bgColor #ffafaf");
+ }
+
+ @Test(groups = { "Functional" })
+ public void testLoadFile()
+ {
+ StructureCommandI cmd = testee.loadFile("/some/filepath");
+ assertEquals(cmd.getCommand(), "open /some/filepath");
+ }
+
+ @Test(groups = { "Functional" })
+ public void testOpenSession()
+ {
+ StructureCommandI cmd = testee.openSession("/some/filepath");
+ assertEquals(cmd.getCommand(), "open chimera:/some/filepath");
+ }
+
+ @Test(groups = "Functional")
+ public void testColourByCharge()
+ {
+ List<StructureCommandI> cmds = testee.colourByCharge();
+ assertEquals(cmds.size(), 1);
+ assertEquals(cmds.get(0)
+ .getCommand(),
+ "color white;color red ::ASP,GLU;color blue ::LYS,ARG;color yellow ::CYS");
+ }
+
+ @Test(groups = "Functional")
public void testGetColourCommand()
{
- ChimeraCommands testee = new ChimeraCommands();
assertEquals(testee.colourResidues("something", Color.MAGENTA)
.getCommand(),
"color #ff00ff something");
}
@Test(groups = "Functional")
+ public void testFocusView()
+ {
+ assertEquals(testee.focusView().getCommand(), "focus");
+ }
+
+ @Test(groups = "Functional")
public void testSetAttribute()
{
- ChimeraCommands testee = new ChimeraCommands();
AtomSpecModel model = new AtomSpecModel();
model.addRange("1", 89, 92, "A");
model.addRange("2", 12, 20, "B");
model.addRange("2", 8, 9, "B");
- assertEquals(testee.setAttribute("phi", "27.3", model).getCommand(),
- "setattr res phi '27.3' #1:89-92.A|#2:8-9.B,12-20.B");
+ assertEquals(testee.setAttribute("jv_kd", "27.3", model).getCommand(),
+ "setattr res jv_kd '27.3' #1:89-92.A|#2:8-9.B,12-20.B");
}
}
import java.util.List;
import java.util.Map;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import jalview.structure.AtomSpecModel;
import jalview.structure.StructureCommandI;
-import jalview.structure.StructureCommandsI;
public class ChimeraXCommandsTest
{
+ private ChimeraXCommands testee;
+
+ @BeforeClass
+ public void setUp()
+ {
+ testee = new ChimeraXCommands();
+ }
+
@Test(groups = { "Functional" })
public void testColourByCharge()
{
- List<StructureCommandI> cmd = new ChimeraXCommands().colourByCharge();
+ List<StructureCommandI> cmd = testee.colourByCharge();
assertEquals(cmd.size(), 1);
assertEquals(cmd.get(0).getCommand(),
"color white;color :ASP,GLU red;color :LYS,ARG blue;color :CYS yellow");
@Test(groups = { "Functional" })
public void testColourByChain()
{
- StructureCommandI cmd = new ChimeraXCommands().colourByChain();
+ StructureCommandI cmd = testee.colourByChain();
assertEquals(cmd.getCommand(), "rainbow chain");
}
@Test(groups = { "Functional" })
public void testFocusView()
{
- StructureCommandI cmd = new ChimeraXCommands().focusView();
+ StructureCommandI cmd = testee.focusView();
assertEquals(cmd.getCommand(), "view");
}
@Test(groups = { "Functional" })
+ public void testSetBackgroundColour()
+ {
+ StructureCommandI cmd = testee.setBackgroundColour(Color.PINK);
+ assertEquals(cmd.getCommand(), "set bgColor #ffafaf");
+ }
+
+ @Test(groups = { "Functional" })
+ public void testOpenSession()
+ {
+ StructureCommandI cmd = testee.openSession("/some/filepath");
+ assertEquals(cmd.getCommand(), "open /some/filepath format session");
+ }
+
+ @Test(groups = { "Functional" })
public void testColourBySequence()
{
Map<Object, AtomSpecModel> map = new LinkedHashMap<>();
* Colours should appear in the Chimera command in the order in which
* they were added; within colour, by model, by chain, ranges in start order
*/
- List<StructureCommandI> commands = new ChimeraXCommands()
- .colourBySequence(map);
+ List<StructureCommandI> commands = testee.colourBySequence(map);
assertEquals(commands.size(), 1);
assertEquals(commands.get(0).getCommand(),
"color #1/A:2-5,9-23/B:7|#2/A:1/B:4-7 #0000ff;color #2/A:3-5,8 #ffff00;color #1/A:3-9 #ff0000");
*/
Map<String, Map<Object, AtomSpecModel>> featuresMap = new LinkedHashMap<>();
Map<Object, AtomSpecModel> featureValues = new HashMap<>();
-
+
/*
* start with just one feature/value...
*/
featuresMap.put("chain", featureValues);
ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 8, 20, "A");
-
- ChimeraXCommands commandGenerator = new ChimeraXCommands();
- List<StructureCommandI> commands = commandGenerator
- .setAttributes(featuresMap);
+
+ List<StructureCommandI> commands = testee.setAttributes(featuresMap);
assertEquals(commands.size(), 1);
/*
ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 3, 9, "A");
// same feature value, contiguous range
ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "A");
- commands = commandGenerator.setAttributes(featuresMap);
+ commands = testee.setAttributes(featuresMap);
assertEquals(commands.size(), 1);
assertEquals(commands.get(0).getCommand(),
"setattr #0/A:3-25 res jv_chain 'X' create true");
ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "B");
// same feature value and chain, different model
ChimeraCommands.addAtomSpecRange(featureValues, "X", "1", 26, 30, "A");
- commands = commandGenerator.setAttributes(featuresMap);
+ commands = testee.setAttributes(featuresMap);
assertEquals(commands.size(), 1);
String expected1 = "setattr #0/A:3-25/B:21-25|#1/A:26-30 res jv_chain 'X' create true";
assertEquals(commands.get(0).getCommand(), expected1);
// same feature, different value
ChimeraCommands.addAtomSpecRange(featureValues, "Y", "0", 40, 50, "A");
- commands = commandGenerator.setAttributes(featuresMap);
+ commands = testee.setAttributes(featuresMap);
assertEquals(2, commands.size());
// commands are ordered by feature type but not by value
// so test for the expected command in either order
String cmd1 = commands.get(0).getCommand();
String cmd2 = commands.get(1).getCommand();
- assertTrue(
- cmd1.equals(expected1) || cmd2.equals(expected1));
+ assertTrue(cmd1.equals(expected1) || cmd2.equals(expected1));
String expected2 = "setattr #0/A:40-50 res jv_chain 'Y' create true";
- assertTrue(
- cmd1.equals(expected2) || cmd2.equals(expected2));
+ assertTrue(cmd1.equals(expected2) || cmd2.equals(expected2));
featuresMap.clear();
featureValues.clear();
featuresMap.put("side-chain binding!", featureValues);
ChimeraCommands.addAtomSpecRange(featureValues,
- "<html>metal <a href=\"http:a.b.c/x\"> 'ion!", "0", 7, 15,
- "A");
+ "<html>metal <a href=\"http:a.b.c/x\"> 'ion!", "0", 7, 15, "A");
// feature names are sanitised to change non-alphanumeric to underscore
// feature values are sanitised to encode single quote characters
- commands = commandGenerator.setAttributes(featuresMap);
+ commands = testee.setAttributes(featuresMap);
assertEquals(commands.size(), 1);
String expected3 = "setattr #0/A:7-15 res jv_side_chain_binding_ '<html>metal <a href=\"http:a.b.c/x\"> 'ion!' create true";
assertTrue(commands.get(0).getCommand().equals(expected3));
@Test(groups = { "Functional" })
public void testSuperposeStructures()
{
- StructureCommandsI testee = new ChimeraXCommands();
AtomSpecModel ref = new AtomSpecModel();
ref.addRange("1", 12, 14, "A");
ref.addRange("1", 18, 18, "B");
* ribbon command does not
*/
String expected = String.format(
- "align %s@CA toAtoms %s@CA; ribbon %s|%s; view",
- toAlignSpec, refSpec, toAlignSpec, refSpec);
+ "align %s@CA toAtoms %s@CA; ribbon %s|%s; view", toAlignSpec,
+ refSpec, toAlignSpec, refSpec);
assertEquals(cmd, expected);
}
@Test(groups = "Functional")
public void testGetAtomSpec()
{
- StructureCommandsI testee = new ChimeraXCommands();
AtomSpecModel model = new AtomSpecModel();
assertEquals(testee.getAtomSpec(model, false), "");
model.addRange("1", 2, 4, "A");
@Test(groups = "Functional")
public void testGetAtomSpec_alphaOnly()
{
- StructureCommandsI testee = new ChimeraXCommands();
AtomSpecModel model = new AtomSpecModel();
assertEquals(testee.getAtomSpec(model, true), "");
model.addRange("1", 2, 4, "A");
@Test(groups = "Functional")
public void testGetModelStartNo()
{
- StructureCommandsI testee = new ChimeraXCommands();
assertEquals(testee.getModelStartNo(), 1);
}
@Test(groups = "Functional")
public void testGetResidueSpec()
{
- ChimeraCommands testee = new ChimeraXCommands();
assertEquals(testee.getResidueSpec("ALA"), ":ALA");
}
@Test(groups = "Functional")
public void testShowBackbone()
{
- ChimeraCommands testee = new ChimeraXCommands();
List<StructureCommandI> showBackbone = testee.showBackbone();
assertEquals(showBackbone.size(), 1);
assertEquals(showBackbone.get(0).getCommand(),
@Test(groups = "Functional")
public void testOpenCommandFile()
{
- ChimeraCommands testee = new ChimeraXCommands();
assertEquals(testee.openCommandFile("nowhere").getCommand(),
"open nowhere");
}
@Test(groups = "Functional")
public void testSaveSession()
{
- ChimeraCommands testee = new ChimeraXCommands();
assertEquals(testee.saveSession("somewhere").getCommand(),
"save somewhere format session");
}
@Test(groups = "Functional")
public void testGetColourCommand()
{
- ChimeraCommands testee = new ChimeraXCommands();
assertEquals(testee.colourResidues("something", Color.MAGENTA)
.getCommand(),
"color something #ff00ff");
@Test(groups = "Functional")
public void testSetAttribute()
{
- ChimeraCommands testee = new ChimeraXCommands();
AtomSpecModel model = new AtomSpecModel();
model.addRange("1", 89, 92, "A");
model.addRange("2", 12, 20, "B");
model.addRange("2", 8, 9, "B");
- assertEquals(testee.setAttribute("phi", "27.3", model).getCommand(),
- "setattr #1/A:89-92|#2/B:8-9,12-20 res phi '27.3' create true");
+ assertEquals(testee.setAttribute("jv_kd", "27.3", model)
+ .getCommand(),
+ "setattr #1/A:89-92|#2/B:8-9,12-20 res jv_kd '27.3' create true");
}
}
--- /dev/null
+package jalview.structure;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import org.testng.annotations.Test;
+
+public class StructureCommandTest
+{
+ @Test(groups = "Functional")
+ public void testEquals()
+ {
+ StructureCommand sc1 = new StructureCommand("open");
+ assertTrue(sc1.equals(sc1));
+ assertTrue(sc1.equals(new StructureCommand("open")));
+ assertFalse(sc1.equals(null));
+ assertFalse(sc1.equals(new StructureCommand("Open")));
+ assertFalse(sc1.equals("Open"));
+
+ StructureCommand sc3 = new StructureCommand("Open", "file",
+ "/some/path");
+ StructureCommand sc2 = new StructureCommand("Open", "file",
+ "/some/path");
+ assertFalse(sc1.equals(sc2));
+ assertTrue(sc3.equals(sc2));
+ assertEquals(sc2.hashCode(), sc3.hashCode());
+ assertFalse(
+ new StructureCommand("Open file", "/some/path").equals(sc2));
+ }
+}