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