c9b2980b054844989e56296f96f1856558f2236b
[jalview.git] / test / jalview / ext / jmol / JmolViewerTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.ext.jmol;
22
23 import static org.testng.AssertJUnit.assertTrue;
24
25 import jalview.api.structures.JalviewStructureDisplayI;
26 import jalview.bin.Cache;
27 import jalview.datamodel.SequenceI;
28 import jalview.gui.AlignFrame;
29 import jalview.gui.Preferences;
30 import jalview.gui.StructureViewer;
31 import jalview.gui.StructureViewer.ViewerType;
32 import jalview.io.FormatAdapter;
33
34 import org.testng.annotations.AfterClass;
35 import org.testng.annotations.BeforeClass;
36 import org.testng.annotations.Test;
37
38 @Test(singleThreaded = true)
39 public class JmolViewerTest
40 {
41
42   /**
43    * @throws java.lang.Exception
44    */
45   @BeforeClass(alwaysRun = true)
46   public static void setUpBeforeClass() throws Exception
47   {
48     jalview.bin.Jalview.main(new String[] {
49         "-noquestionnaire -nonews -props",
50         "test/jalview/ext/rbvi/chimera/testProps.jvprops" });
51   }
52
53   /**
54    * @throws java.lang.Exception
55    */
56   @AfterClass
57   public static void tearDownAfterClass() throws Exception
58   {
59     jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
60   }
61
62   @Test(groups = { "Functional" })
63   public void testSingleSeqViewJMol()
64   {
65     Cache.setProperty(Preferences.STRUCTURE_DISPLAY, ViewerType.JMOL.name());
66     String inFile = "examples/1gaq.txt";
67     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
68             inFile, FormatAdapter.FILE);
69     assertTrue("Didn't read input file " + inFile, af != null);
70     for (SequenceI sq : af.getViewport().getAlignment().getSequences())
71     {
72       SequenceI dsq = sq.getDatasetSequence();
73       while (dsq.getDatasetSequence() != null)
74       {
75         dsq = dsq.getDatasetSequence();
76       }
77       if (dsq.getAllPDBEntries() != null
78               && dsq.getAllPDBEntries().size() > 0)
79       {
80         for (int q = 0; q < dsq.getAllPDBEntries().size(); q++)
81         {
82           final StructureViewer structureViewer = new StructureViewer(af
83                   .getViewport().getStructureSelectionManager());
84           structureViewer.setViewerType(ViewerType.JMOL);
85           JalviewStructureDisplayI jmolViewer = structureViewer
86                   .viewStructures(dsq.getAllPDBEntries().elementAt(q),
87                           new SequenceI[] { sq }, af.getCurrentView()
88                                   .getAlignPanel());
89           /*
90            * Wait for viewer load thread to complete
91            */
92           try
93           {
94             while (!jmolViewer.getBinding().isFinishedInit())
95             {
96               Thread.sleep(500);
97             }
98           } catch (InterruptedException e)
99           {
100           }
101
102           jmolViewer.closeViewer(true);
103           // todo: break here means only once through this loop?
104           break;
105         }
106         break;
107       }
108     }
109   }
110 }