Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.ext.jmol

File JmolViewerTest.java

 

Code metrics

14
57
5
1
212
159
18
0.32
11.4
5
3.6

Classes

Class Line # Actions
JmolViewerTest 49 57 18 4
0.9473684494.7%
 

Contributing tests

This file is covered by 2 tests. .

Source view

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.junit.Assert.assertNotNull;
24    import static org.testng.Assert.assertEquals;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import jalview.api.structures.JalviewStructureDisplayI;
28    import jalview.bin.Cache;
29    import jalview.bin.Jalview;
30    import jalview.datamodel.PDBEntry;
31    import jalview.datamodel.SearchResultsI;
32    import jalview.datamodel.SequenceI;
33    import jalview.gui.AlignFrame;
34    import jalview.gui.JvOptionPane;
35    import jalview.gui.Preferences;
36    import jalview.gui.StructureViewer;
37    import jalview.gui.StructureViewer.ViewerType;
38    import jalview.io.DataSourceType;
39    import jalview.io.FileFormat;
40    import jalview.io.FileLoader;
41   
42    import java.lang.reflect.InvocationTargetException;
43   
44    import org.testng.annotations.AfterClass;
45    import org.testng.annotations.BeforeClass;
46    import org.testng.annotations.Test;
47   
48    @Test(singleThreaded = true)
 
49    public class JmolViewerTest
50    {
51   
 
52  1 toggle @BeforeClass(alwaysRun = true)
53    public void setUpJvOptionPane()
54    {
55  1 JvOptionPane.setInteractiveMode(false);
56  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
57    }
58   
59    /**
60    * @throws java.lang.Exception
61    */
 
62  1 toggle @BeforeClass(alwaysRun = true)
63    public static void setUpBeforeClass() throws Exception
64    {
65  1 Jalview.main(
66    new String[]
67    { "-noquestionnaire", "-nonews", "-props",
68    "test/jalview/ext/rbvi/chimera/testProps.jvprops" });
69    }
70   
71    /**
72    * @throws java.lang.Exception
73    */
 
74  1 toggle @AfterClass(alwaysRun = true)
75    public static void tearDownAfterClass() throws Exception
76    {
77  1 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
78    }
79   
 
80  1 toggle @Test(groups = { "Functional" })
81    public void testSingleSeqViewJMol()
82    {
83  1 Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
84    ViewerType.JMOL.name());
85  1 String inFile = "examples/1gaq.txt";
86  1 AlignFrame af = new jalview.io.FileLoader()
87    .LoadFileWaitTillLoaded(inFile, DataSourceType.FILE);
88  1 assertTrue("Didn't read input file " + inFile, af != null);
89  1 for (SequenceI sq : af.getViewport().getAlignment().getSequences())
90    {
91  1 SequenceI dsq = sq.getDatasetSequence();
92  1 while (dsq.getDatasetSequence() != null)
93    {
94  0 dsq = dsq.getDatasetSequence();
95    }
96  1 if (dsq.getAllPDBEntries() != null
97    && dsq.getAllPDBEntries().size() > 0)
98    {
99  1 for (int q = 0; q < dsq.getAllPDBEntries().size(); q++)
100    {
101  1 final StructureViewer structureViewer = new StructureViewer(
102    af.getViewport().getStructureSelectionManager());
103  1 structureViewer.setViewerType(ViewerType.JMOL);
104  1 JalviewStructureDisplayI jmolViewer = structureViewer
105    .viewStructures(dsq.getAllPDBEntries().elementAt(q),
106    new SequenceI[]
107    { sq }, af.getCurrentView().getAlignPanel());
108    /*
109    * Wait for viewer load thread to complete
110    */
111  1 try
112    {
113  3 while (!jmolViewer.getBinding().isFinishedInit())
114    {
115  2 Thread.sleep(500);
116    }
117    } catch (InterruptedException e)
118    {
119    }
120   
121  1 jmolViewer.closeViewer(true);
122    // todo: break here means only once through this loop?
123  1 break;
124    }
125  1 break;
126    }
127    }
128    }
129   
 
130  1 toggle @Test(groups = { "Functional" })
131    public void testAddStrToSingleSeqViewJMol()
132    throws InvocationTargetException, InterruptedException
133    {
134  1 Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
135    ViewerType.JMOL.name());
136  1 String inFile = "examples/1gaq.txt";
137  1 AlignFrame af = new jalview.io.FileLoader(true)
138    .LoadFileWaitTillLoaded(inFile, DataSourceType.FILE);
139  1 assertTrue("Didn't read input file " + inFile, af != null);
140    // show a structure for 4th Sequence
141  1 SequenceI sq1 = af.getViewport().getAlignment().getSequences().get(0);
142  1 final StructureViewer structureViewer = new StructureViewer(
143    af.getViewport().getStructureSelectionManager());
144  1 structureViewer.setViewerType(ViewerType.JMOL);
145  1 JalviewStructureDisplayI jmolViewer = structureViewer.viewStructures(
146    sq1.getDatasetSequence().getAllPDBEntries().elementAt(0),
147    new SequenceI[]
148    { sq1 }, af.getCurrentView().getAlignPanel());
149    /*
150    * Wait for viewer load thread to complete
151    */
152  1 try
153    {
154  3 while (!jmolViewer.getBinding().isFinishedInit())
155    {
156  2 Thread.sleep(500);
157    }
158    } catch (InterruptedException e)
159    {
160    }
161   
162  1 assertTrue(jmolViewer.isVisible());
163   
164    // add another pdb file and add it to view
165  1 final String _inFile = "examples/3W5V.pdb";
166  1 inFile = _inFile;
167  1 FileLoader fl = new FileLoader();
168  1 fl.LoadFile(af.getCurrentView(), _inFile, DataSourceType.FILE,
169    FileFormat.PDB);
170  1 try
171    {
172  1 int time = 0;
173  1 do
174    {
175  4 Thread.sleep(50); // hope we can avoid race condition
176   
177  4 } while (++time < 30
178    && af.getViewport().getAlignment().getHeight() == 3);
179    } catch (Exception q)
180    {
181    }
182  1 ;
183  1 assertTrue("Didn't paste additional structure" + inFile,
184    af.getViewport().getAlignment().getHeight() > 3);
185  1 SequenceI sq2 = af.getViewport().getAlignment().getSequenceAt(3);
186  1 PDBEntry pdbe = sq2.getDatasetSequence().getAllPDBEntries().get(0);
187  1 assertTrue(pdbe.getFile().contains(inFile));
188  1 structureViewer.viewStructures(pdbe, new SequenceI[] { sq2 },
189    af.alignPanel);
190    /*
191    * Wait for viewer load thread to complete
192    */
193  1 try
194    {
195  3 while (structureViewer.isBusy())
196    {
197  2 Thread.sleep(500);
198    }
199    } catch (InterruptedException e)
200    {
201    }
202  1 assertEquals(jmolViewer.getBinding().getPdbCount(), 2);
203  1 String mouseOverTest = "[GLY]293:A.CA/2.1 #2164";
204  1 ((JalviewJmolBinding) jmolViewer.getBinding()).mouseOverStructure(2164,
205    mouseOverTest);
206  1 SearchResultsI highlight = af.alignPanel.getSeqPanel()
207    .getLastSearchResults();
208  1 assertNotNull("Didn't find highlight from second structure mouseover",
209    highlight.getResults(sq2, sq2.getStart(), sq2.getEnd()));
210    }
211   
212    }