2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.ext.jmol;
23 import static org.junit.Assert.assertNotNull;
24 import static org.testng.Assert.assertEquals;
25 import static org.testng.AssertJUnit.assertTrue;
27 import java.lang.reflect.InvocationTargetException;
29 import org.testng.annotations.AfterClass;
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.Test;
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;
49 @Test(singleThreaded = true)
50 public class JmolViewerTest
53 @BeforeClass(alwaysRun = true)
54 public void setUpJvOptionPane()
56 JvOptionPane.setInteractiveMode(false);
57 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
61 * @throws java.lang.Exception
63 @BeforeClass(alwaysRun = true)
64 public static void setUpBeforeClass() throws Exception
68 { "-noquestionnaire", "-nonews", "-props",
69 "test/jalview/ext/rbvi/chimera/testProps.jvprops" });
73 * @throws java.lang.Exception
75 @AfterClass(alwaysRun = true)
76 public static void tearDownAfterClass() throws Exception
78 if (Desktop.instance != null)
79 Desktop.instance.closeAll_actionPerformed(null);
82 @Test(groups = { "Functional" })
83 public void testSingleSeqViewJMol()
85 Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
86 ViewerType.JMOL.name());
87 String inFile = "examples/1gaq.txt";
88 AlignFrame af = new jalview.io.FileLoader()
89 .LoadFileWaitTillLoaded(inFile, DataSourceType.FILE);
90 assertTrue("Didn't read input file " + inFile, af != null);
91 for (SequenceI sq : af.getViewport().getAlignment().getSequences())
93 SequenceI dsq = sq.getDatasetSequence();
94 while (dsq.getDatasetSequence() != null)
96 dsq = dsq.getDatasetSequence();
98 if (dsq.getAllPDBEntries() != null
99 && dsq.getAllPDBEntries().size() > 0)
101 for (int q = 0; q < dsq.getAllPDBEntries().size(); q++)
103 final StructureViewer structureViewer = new StructureViewer(
104 af.getViewport().getStructureSelectionManager());
105 structureViewer.setViewerType(ViewerType.JMOL);
106 JalviewStructureDisplayI jmolViewer = structureViewer
107 .viewStructures(dsq.getAllPDBEntries().elementAt(q),
109 { sq }, af.getCurrentView().getAlignPanel());
111 * Wait for viewer load thread to complete
115 while (!jmolViewer.getBinding().isFinishedInit())
119 } catch (InterruptedException e)
123 jmolViewer.closeViewer(true);
124 // todo: break here means only once through this loop?
132 @Test(groups = { "Functional" })
133 public void testAddStrToSingleSeqViewJMol()
134 throws InvocationTargetException, InterruptedException
136 Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
137 ViewerType.JMOL.name());
138 String inFile = "examples/1gaq.txt";
139 AlignFrame af = new jalview.io.FileLoader(true)
140 .LoadFileWaitTillLoaded(inFile, DataSourceType.FILE);
141 assertTrue("Didn't read input file " + inFile, af != null);
142 // show a structure for 4th Sequence
143 SequenceI sq1 = af.getViewport().getAlignment().getSequences().get(0);
144 final StructureViewer structureViewer = new StructureViewer(
145 af.getViewport().getStructureSelectionManager());
146 structureViewer.setViewerType(ViewerType.JMOL);
147 JalviewStructureDisplayI jmolViewer = structureViewer.viewStructures(
148 sq1.getDatasetSequence().getAllPDBEntries().elementAt(0),
150 { sq1 }, af.getCurrentView().getAlignPanel());
152 * Wait for viewer load thread to complete
156 while (!jmolViewer.getBinding().isFinishedInit())
160 } catch (InterruptedException e)
164 assertTrue(jmolViewer.isVisible());
166 // add another pdb file and add it to view
167 final String _inFile = "examples/3W5V.pdb";
169 FileLoader fl = new FileLoader();
170 fl.LoadFile(af.getCurrentView(), _inFile, DataSourceType.FILE,
177 Thread.sleep(50); // hope we can avoid race condition
180 && af.getViewport().getAlignment().getHeight() == 3);
181 } catch (Exception q)
185 assertTrue("Didn't paste additional structure" + inFile,
186 af.getViewport().getAlignment().getHeight() > 3);
187 SequenceI sq2 = af.getViewport().getAlignment().getSequenceAt(3);
188 PDBEntry pdbe = sq2.getDatasetSequence().getAllPDBEntries().get(0);
189 assertTrue(pdbe.getFile().contains(inFile));
190 structureViewer.viewStructures(pdbe, new SequenceI[] { sq2 },
193 * Wait for viewer load thread to complete
197 while (structureViewer.isBusy())
201 } catch (InterruptedException e)
204 assertEquals(jmolViewer.getBinding().getPdbCount(), 2);
205 String mouseOverTest = "[GLY]293:A.CA/2.1 #2164";
206 ((JalviewJmolBinding) jmolViewer.getBinding()).mouseOverStructure(2164,
208 SearchResultsI highlight = af.alignPanel.getSeqPanel()
209 .getLastSearchResults();
210 assertNotNull("Didn't find highlight from second structure mouseover",
211 highlight.getResults(sq2, sq2.getStart(), sq2.getEnd()));