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 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;
42 import java.lang.reflect.InvocationTargetException;
44 import org.testng.annotations.AfterClass;
45 import org.testng.annotations.BeforeClass;
46 import org.testng.annotations.Test;
48 @Test(singleThreaded = true)
49 public class JmolViewerTest
52 @BeforeClass(alwaysRun = true)
53 public void setUpJvOptionPane()
55 JvOptionPane.setInteractiveMode(false);
56 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
60 * @throws java.lang.Exception
62 @BeforeClass(alwaysRun = true)
63 public static void setUpBeforeClass() throws Exception
67 { "-noquestionnaire", "-nonews", "-props",
68 "test/jalview/ext/rbvi/chimera/testProps.jvprops" });
72 * @throws java.lang.Exception
74 @AfterClass(alwaysRun = true)
75 public static void tearDownAfterClass() throws Exception
77 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
80 @Test(groups = { "Functional" })
81 public void testSingleSeqViewJMol()
83 Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
84 ViewerType.JMOL.name());
85 String inFile = "examples/1gaq.txt";
86 AlignFrame af = new jalview.io.FileLoader()
87 .LoadFileWaitTillLoaded(inFile, DataSourceType.FILE);
88 assertTrue("Didn't read input file " + inFile, af != null);
89 for (SequenceI sq : af.getViewport().getAlignment().getSequences())
91 SequenceI dsq = sq.getDatasetSequence();
92 while (dsq.getDatasetSequence() != null)
94 dsq = dsq.getDatasetSequence();
96 if (dsq.getAllPDBEntries() != null
97 && dsq.getAllPDBEntries().size() > 0)
99 for (int q = 0; q < dsq.getAllPDBEntries().size(); q++)
101 final StructureViewer structureViewer = new StructureViewer(
102 af.getViewport().getStructureSelectionManager());
103 structureViewer.setViewerType(ViewerType.JMOL);
104 JalviewStructureDisplayI jmolViewer = structureViewer
105 .viewStructures(dsq.getAllPDBEntries().elementAt(q),
107 { sq }, af.getCurrentView().getAlignPanel());
109 * Wait for viewer load thread to complete
113 while (!jmolViewer.getBinding().isFinishedInit())
117 } catch (InterruptedException e)
121 jmolViewer.closeViewer(true);
122 // todo: break here means only once through this loop?
130 @Test(groups = { "Functional" })
131 public void testAddStrToSingleSeqViewJMol()
132 throws InvocationTargetException, InterruptedException
134 Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
135 ViewerType.JMOL.name());
136 String inFile = "examples/1gaq.txt";
137 AlignFrame af = new jalview.io.FileLoader(true)
138 .LoadFileWaitTillLoaded(inFile, DataSourceType.FILE);
139 assertTrue("Didn't read input file " + inFile, af != null);
140 // show a structure for 4th Sequence
141 SequenceI sq1 = af.getViewport().getAlignment().getSequences().get(0);
142 final StructureViewer structureViewer = new StructureViewer(
143 af.getViewport().getStructureSelectionManager());
144 structureViewer.setViewerType(ViewerType.JMOL);
145 JalviewStructureDisplayI jmolViewer = structureViewer.viewStructures(
146 sq1.getDatasetSequence().getAllPDBEntries().elementAt(0),
148 { sq1 }, af.getCurrentView().getAlignPanel());
150 * Wait for viewer load thread to complete
154 while (!jmolViewer.getBinding().isFinishedInit())
158 } catch (InterruptedException e)
162 assertTrue(jmolViewer.isVisible());
164 // add another pdb file and add it to view
165 final String _inFile = "examples/3W5V.pdb";
167 FileLoader fl = new FileLoader();
168 fl.LoadFile(af.getCurrentView(), _inFile, DataSourceType.FILE,
175 Thread.sleep(50); // hope we can avoid race condition
178 && af.getViewport().getAlignment().getHeight() == 3);
179 } catch (Exception q)
183 assertTrue("Didn't paste additional structure" + inFile,
184 af.getViewport().getAlignment().getHeight() > 3);
185 SequenceI sq2 = af.getViewport().getAlignment().getSequenceAt(3);
186 PDBEntry pdbe = sq2.getDatasetSequence().getAllPDBEntries().get(0);
187 assertTrue(pdbe.getFile().contains(inFile));
188 structureViewer.viewStructures(pdbe, new SequenceI[] { sq2 },
191 * Wait for viewer load thread to complete
195 while (structureViewer.isBusy())
199 } catch (InterruptedException e)
202 assertEquals(jmolViewer.getBinding().getPdbCount(), 2);
203 String mouseOverTest = "[GLY]293:A.CA/2.1 #2164";
204 ((JalviewJmolBinding) jmolViewer.getBinding()).mouseOverStructure(2164,
206 SearchResultsI highlight = af.alignPanel.getSeqPanel()
207 .getLastSearchResults();
208 assertNotNull("Didn't find highlight from second structure mouseover",
209 highlight.getResults(sq2, sq2.getStart(), sq2.getEnd()));