Merge branch 'feature/JAL-3551Pymol' into develop
[jalview.git] / test / jalview / ext / rbvi / chimera / JalviewChimeraView.java
index 449b219..d397a6b 100644 (file)
@@ -25,6 +25,16 @@ import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Vector;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
 import jalview.api.FeatureRenderer;
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
@@ -35,31 +45,30 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
+import jalview.gui.JvOptionPane;
 import jalview.gui.Preferences;
 import jalview.gui.StructureViewer;
 import jalview.gui.StructureViewer.ViewerType;
+import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
-import jalview.io.FormatAdapter;
+import jalview.structure.StructureCommand;
 import jalview.structure.StructureMapping;
 import jalview.structure.StructureSelectionManager;
 import jalview.ws.sifts.SiftsClient;
 import jalview.ws.sifts.SiftsException;
 import jalview.ws.sifts.SiftsSettings;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Vector;
-
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
 @Test(singleThreaded = true)
 public class JalviewChimeraView
 {
 
+  @BeforeClass(alwaysRun = true)
+  public void setUpJvOptionPane()
+  {
+    JvOptionPane.setInteractiveMode(false);
+    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+  }
+
   private JalviewStructureDisplayI chimeraViewer;
 
   /**
@@ -111,7 +120,7 @@ public class JalviewChimeraView
   {
     String inFile = "examples/1gaq.txt";
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     assertNotNull(af, "Failed to create AlignFrame");
     SequenceI sq = af.getViewport().getAlignment().getSequenceAt(0);
     assertEquals(sq.getName(), "1GAQ|A");
@@ -140,7 +149,7 @@ public class JalviewChimeraView
       }
     }
 
-    assertTrue(binding.isChimeraRunning(), "Failed to start Chimera");
+    assertTrue(binding.isViewerRunning(), "Failed to start Chimera");
 
     assertEquals(chimeraViewer.getBinding().getPdbCount(), 1);
     chimeraViewer.closeViewer(true);
@@ -162,7 +171,7 @@ public class JalviewChimeraView
   {
     String inFile = "examples/uniref50.fa";
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     assertNotNull(af, "Failed to create AlignFrame");
     SequenceI sq = af.getViewport().getAlignment().findName("FER2_ARATH");
     assertNotNull(sq, "Didn't find FER2_ARATH");
@@ -200,7 +209,7 @@ public class JalviewChimeraView
       }
     } while (!binding.isFinishedInit());
 
-    assertTrue(binding.isChimeraRunning(), "Failed to launch Chimera");
+    assertTrue(binding.isViewerRunning(), "Failed to launch Chimera");
 
     assertEquals(binding.getPdbCount(), 1);
 
@@ -209,7 +218,7 @@ public class JalviewChimeraView
      * (or possibly 52-145 to 1-94 - see JAL-2319)
      */
     StructureSelectionManager ssm = binding.getSsm();
-    String pdbFile = binding.getPdbFile()[0];
+    String pdbFile = binding.getStructureFiles()[0];
     StructureMapping[] mappings = ssm.getMapping(pdbFile);
     assertTrue(mappings[0].getMappingDetailsOutput().contains("SIFTS"),
             "Failed to perform SIFTS mapping");
@@ -282,7 +291,8 @@ public class JalviewChimeraView
     /*
      * ask Chimera for its residue attribute names
      */
-    List<String> reply = binding.sendChimeraCommand("list resattr", true);
+    List<String> reply = binding
+            .executeCommand(new StructureCommand("list resattr"), true);
     // prefixed and sanitised attribute names for Jalview features:
     assertTrue(reply.contains("resattr jv_domain"));
     assertTrue(reply.contains("resattr jv_metal_ion_binding_site"));
@@ -298,8 +308,9 @@ public class JalviewChimeraView
      * ask Chimera for residues with an attribute
      * 91 and 96 on sequence --> residues 40 and 45 on chains A and B
      */
-    reply = binding.sendChimeraCommand(
-            "list resi att jv_metal_ion_binding_site", true);
+    reply = binding.executeCommand(
+            new StructureCommand("list resi att jv_metal_ion_binding_site"),
+            true);
     assertEquals(reply.size(), 4);
     assertTrue(reply
             .contains("residue id #0:40.A jv_metal_ion_binding_site \"Iron-Sulfur (2Fe-2S)\" index 40"));
@@ -314,7 +325,8 @@ public class JalviewChimeraView
      * check attributes with score values
      * sequence positions 62 and 65 --> residues 11 and 14 on chains A and B
      */
-    reply = binding.sendChimeraCommand("list resi att jv_kd", true);
+    reply = binding.executeCommand(
+            new StructureCommand("list resi att jv_kd"), true);
     assertEquals(reply.size(), 4);
     assertTrue(reply.contains("residue id #0:11.A jv_kd -2.1 index 11"));
     assertTrue(reply.contains("residue id #0:14.A jv_kd 3.6 index 14"));
@@ -324,8 +336,9 @@ public class JalviewChimeraView
     /*
      * list residues with positive kd score 
      */
-    reply = binding.sendChimeraCommand(
-            "list resi spec :*/jv_kd>0 attr jv_kd", true);
+    reply = binding.executeCommand(
+            new StructureCommand("list resi spec :*/jv_kd>0 attr jv_kd"),
+            true);
     assertEquals(reply.size(), 2);
     assertTrue(reply.contains("residue id #0:14.A jv_kd 3.6 index 14"));
     assertTrue(reply.contains("residue id #0:14.B jv_kd 3.6 index 14"));
@@ -349,7 +362,7 @@ public class JalviewChimeraView
   {
     String inFile = "examples/uniref50.fa";
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile,
-            FormatAdapter.FILE);
+            DataSourceType.FILE);
     assertNotNull(af, "Failed to create AlignFrame");
     SequenceI fer2Arath = af.getViewport().getAlignment()
             .findName("FER2_ARATH");
@@ -389,13 +402,13 @@ public class JalviewChimeraView
       }
     } while (!binding.isFinishedInit());
   
-    assertTrue(binding.isChimeraRunning(), "Failed to launch Chimera");
+    assertTrue(binding.isViewerRunning(), "Failed to launch Chimera");
   
     assertEquals(binding.getPdbCount(), 1);
   
     /*
-     * 'perform' menu action to copy visible features to
-     * attributes in Chimera
+     * 'perform' menu action to copy Chimera attributes
+     * to features in Jalview
      */
     // TODO rename and pull up method to binding interface
     // once functionality is added for Jmol as well
@@ -432,15 +445,13 @@ public class JalviewChimeraView
     binding.copyStructureAttributesToFeatures("phi", af.getViewport()
             .getAlignPanel());
     fr.setVisible("phi");
-    List<SequenceFeature> fs = fr.findFeaturesAtRes(fer2Arath, 54);
-    assertEquals(fs.size(), 3);
-    assertEquals(fs.get(0).getType(), "RESNUM");
-    assertEquals(fs.get(1).getType(), "phi");
-    assertEquals(fs.get(2).getType(), "phi");
-    assertEquals(fs.get(1).getDescription(), "A"); // chain
-    assertEquals(fs.get(2).getDescription(), "B");
-    assertEquals(fs.get(1).getScore(), -131.0713f, 0.001f);
-    assertEquals(fs.get(2).getScore(), -127.39512, 0.001f);
+    List<SequenceFeature> fs = fer2Arath.getFeatures().findFeatures(54, 54,
+            "phi");
+    assertEquals(fs.size(), 2);
+    assertTrue(fs.contains(new SequenceFeature("phi", "A", 54, 54,
+            -131.0713f, "Chimera")));
+    assertTrue(fs.contains(new SequenceFeature("phi", "B", 54, 54,
+            -127.39512f, "Chimera")));
 
     /*
      * tear down - also in AfterMethod
@@ -462,10 +473,11 @@ public class JalviewChimeraView
           int res, String featureType)
   {
     String where = "at position " + res;
-    List<SequenceFeature> fs = fr.findFeaturesAtRes(seq, res);
-    assertEquals(fs.size(), 2, where);
-    assertEquals(fs.get(0).getType(), "RESNUM", where);
-    SequenceFeature sf = fs.get(1);
+    List<SequenceFeature> fs = seq.getFeatures().findFeatures(res, res,
+            featureType);
+
+    assertEquals(fs.size(), 1, where);
+    SequenceFeature sf = fs.get(0);
     assertEquals(sf.getType(), featureType, where);
     assertEquals(sf.getFeatureGroup(), "Chimera", where);
     assertEquals(sf.getDescription(), "True", where);