Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:56:54 GMT
  2. Package jalview.ext.jmol

File JmolViewerTest.java

 

Code metrics

16
58
5
1
214
161
19
0.33
11.6
5
3.8

Classes

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