JAL-1742 suppress 'add chain' option for Jmol, pull up shared code for
[jalview.git] / test / jalview / ext / rbvi / chimera / JalviewChimeraView.java
1 package jalview.ext.rbvi.chimera;
2
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertTrue;
5
6 import jalview.api.structures.JalviewStructureDisplayI;
7 import jalview.bin.Cache;
8 import jalview.datamodel.SequenceI;
9 import jalview.gui.AlignFrame;
10 import jalview.gui.Preferences;
11 import jalview.gui.StructureViewer;
12 import jalview.gui.StructureViewer.ViewerType;
13 import jalview.io.FormatAdapter;
14
15 import org.testng.annotations.AfterClass;
16 import org.testng.annotations.BeforeClass;
17 import org.testng.annotations.Test;
18
19 public class JalviewChimeraView
20 {
21
22   /**
23    * @throws java.lang.Exception
24    */
25   @BeforeClass(alwaysRun = true)
26   public static void setUpBeforeClass() throws Exception
27   {
28     jalview.bin.Jalview.main(new String[]
29     { "-noquestionnaire -nonews -props", "test/src/jalview/ext/rbvi/chimera/testProps.jvprops" });
30   }
31
32   /**
33    * @throws java.lang.Exception
34    */
35   @AfterClass
36   public static void tearDownAfterClass() throws Exception
37   {
38     jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
39   }
40
41   @Test(groups ={ "Functional" })
42   public void testSingleSeqViewJMol()
43   {
44     Cache.setProperty(Preferences.STRUCTURE_DISPLAY, ViewerType.JMOL.name());
45     String inFile = "examples/1gaq.txt";
46     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
47             inFile, FormatAdapter.FILE);
48     assertTrue("Didn't read input file " + inFile, af != null);
49     for (SequenceI sq : af.getViewport().getAlignment().getSequences())
50     {
51       SequenceI dsq = sq.getDatasetSequence();
52       while (dsq.getDatasetSequence() != null)
53       {
54         dsq = dsq.getDatasetSequence();
55       }
56       if (dsq.getAllPDBEntries() != null && dsq.getAllPDBEntries().size() > 0)
57       {
58         for (int q = 0; q < dsq.getAllPDBEntries().size(); q++)
59         {
60           final StructureViewer structureViewer = new StructureViewer(af
61                   .getViewport().getStructureSelectionManager());
62           structureViewer.setViewerType(ViewerType.JMOL);
63           JalviewStructureDisplayI jmolViewer = structureViewer
64                   .viewStructures(dsq.getAllPDBEntries().elementAt(q),
65                           new SequenceI[]
66                   { sq }, af.getCurrentView().getAlignPanel());
67           /*
68            * Wait for viewer load thread to complete
69            */
70           try
71           {
72             while (!jmolViewer.getBinding().isFinishedInit())
73             {
74               Thread.sleep(500);
75             }
76           } catch (InterruptedException e)
77           {
78           }
79
80           jmolViewer.closeViewer(true);
81           // todo: break here means only once through this loop?
82           break;
83         }
84         break;
85       }
86     }
87   }
88
89   @Test(groups ={ "Functional" })
90   public void testSingleSeqViewChimera()
91   {
92     Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
93             ViewerType.CHIMERA.name());
94     String inFile = "examples/1gaq.txt";
95     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
96             inFile, FormatAdapter.FILE);
97     assertTrue("Didn't read input file " + inFile, af != null);
98     for (SequenceI sq : af.getViewport().getAlignment().getSequences())
99     {
100       System.out.println("** sq=" + sq.getName());
101       SequenceI dsq = sq.getDatasetSequence();
102       while (dsq.getDatasetSequence() != null)
103       {
104         dsq = dsq.getDatasetSequence();
105       }
106       if (dsq.getAllPDBEntries() != null && dsq.getAllPDBEntries().size() > 0)
107       {
108         for (int q = 0; q < dsq.getAllPDBEntries().size(); q++)
109         {
110           final StructureViewer structureViewer = new StructureViewer(af
111                   .getViewport().getStructureSelectionManager());
112           structureViewer.setViewerType(ViewerType.CHIMERA);
113           JalviewStructureDisplayI chimeraViewer = structureViewer
114                   .viewStructures(dsq.getAllPDBEntries().elementAt(q),
115                           new SequenceI[]
116                           { sq }, af.getCurrentView().getAlignPanel());
117           /*
118            * Wait for viewer load thread to complete
119            */
120           while (!chimeraViewer.getBinding().isFinishedInit())
121           {
122             try
123             {
124               Thread.sleep(500);
125             } catch (InterruptedException e)
126             {
127             }
128           }
129           assertEquals(1, chimeraViewer.getBinding().getPdbCount());
130           chimeraViewer.closeViewer(true);
131           // todo: break here means only once through this loop?
132           break;
133         }
134         break;
135       }
136     }
137   }
138 }