View Javadoc
1   // ******************************************************************************
2   //
3   // Title:       Force Field X.
4   // Description: Force Field X - Software for Molecular Biophysics.
5   // Copyright:   Copyright (c) Michael J. Schnieders 2001-2024.
6   //
7   // This file is part of Force Field X.
8   //
9   // Force Field X is free software; you can redistribute it and/or modify it
10  // under the terms of the GNU General Public License version 3 as published by
11  // the Free Software Foundation.
12  //
13  // Force Field X is distributed in the hope that it will be useful, but WITHOUT
14  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16  // details.
17  //
18  // You should have received a copy of the GNU General Public License along with
19  // Force Field X; if not, write to the Free Software Foundation, Inc., 59 Temple
20  // Place, Suite 330, Boston, MA 02111-1307 USA
21  //
22  // Linking this library statically or dynamically with other modules is making a
23  // combined work based on this library. Thus, the terms and conditions of the
24  // GNU General Public License cover the whole combination.
25  //
26  // As a special exception, the copyright holders of this library give you
27  // permission to link this library with independent modules to produce an
28  // executable, regardless of the license terms of these independent modules, and
29  // to copy and distribute the resulting executable under terms of your choice,
30  // provided that you also meet, for each linked independent module, the terms
31  // and conditions of the license of that module. An independent module is a
32  // module which is not derived from or based on this library. If you modify this
33  // library, you may extend this exception to your version of the library, but
34  // you are not obligated to do so. If you do not wish to do so, delete this
35  // exception statement from your version.
36  //
37  // ******************************************************************************
38  package ffx.algorithms.groovy;
39  
40  import static org.junit.Assert.assertEquals;
41  
42  import ffx.algorithms.misc.AlgorithmsTest;
43  import org.junit.Test;
44  
45  /**
46   * Tests SuperposeCrystals command to verify crystals are being aligned and compared.
47   *
48   * @author Aaron J. Nessler
49   */
50  public class SuperposeCrystalsTest extends AlgorithmsTest {
51  
52    private final double TOLERANCE = 0.005;
53  
54    /**
55     * Tests the SuperposeCrystals script with default settings.
56     */
57    @Test
58    public void testBaseSingleSuperposeCrystals() {
59  
60      // Set up the input arguments for the SuperposeCrystals script.
61      String[] args = {"-l", "0", getResourcePath("C23.arc")};
62      binding.setVariable("args", args);
63      binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
64  
65      // Construct and evaluate the SuperposeCrystals script.
66      SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
67      algorithmsScript = superposeCrystals;
68  
69      // Only off-diagonal values.
70      assertEquals(6, superposeCrystals.runningStatistics.getCount());
71      // Mean RMSD for 6 comparisons.
72      assertEquals(0.087248318, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
73      assertEquals(0.226387, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
74    }
75  
76    /**
77     * Tests the SuperposeCrystals script with RMSD size of one.
78     */
79    @Test
80    public void testBaseSingleAUSuperposeCrystals() {
81  
82      // Set up the input arguments for the SuperposeCrystals script.
83      String[] args = {"--na", "1", "-l", "0", getResourcePath("C23.arc")};
84      binding.setVariable("args", args);
85      binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
86  
87      // Construct and evaluate the SuperposeCrystals script.
88      SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
89      algorithmsScript = superposeCrystals;
90  
91      // Only off-diagonal values.
92      assertEquals(6, superposeCrystals.runningStatistics.getCount());
93      // Mean RMSD for 6 comparisons.
94      assertEquals(0.055486, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
95      assertEquals(0.161867, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
96    }
97  
98    /**
99     * Tests the SuperposeCrystals script with small symmetric molecules (can be tricky to determine conformations).
100    */
101   @Test
102   public void testBaseSingleMTSuperposeCrystals() {
103 
104     // Set up the input arguments for the SuperposeCrystals script.
105     String[] args = {"-l", "0",
106         getResourcePath("ace.arc_s"),
107         getResourcePath("ace.arc_sx")};
108     binding.setVariable("args", args);
109     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
110 
111     // Construct and evaluate the SuperposeCrystals script.
112     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
113     algorithmsScript = superposeCrystals;
114 
115     // Only off-diagonal values.
116     assertEquals(100, superposeCrystals.runningStatistics.getCount());
117     // Mean RMSD for 100 comparisons (10 by 10).
118     assertEquals(0.199630, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
119     assertEquals(0.199630, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
120   }
121 
122   /**
123    * Tests the SuperposeCrystals script with small symmetric molecules (can be tricky to determine conformations).
124    */
125   @Test
126   public void testBaseSingleMTSuperposeCrystals2() {
127 
128     // Set up the input arguments for the SuperposeCrystals script.
129     String[] args = {getResourcePath("ace.arc"), getResourcePath("ace.arc_x")};
130     binding.setVariable("args", args);
131     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
132 
133     // Construct and evaluate the SuperposeCrystals script.
134     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
135     algorithmsScript = superposeCrystals;
136 
137     // Only off-diagonal values.
138     assertEquals(4, superposeCrystals.runningStatistics.getCount());
139     // Mean RMSD for 100 comparisons (10 by 10).
140     assertEquals(0.224877, superposeCrystals.runningStatistics.getMin(), TOLERANCE);
141     assertEquals(0.224877, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
142     assertEquals(0.224877, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
143   }
144 
145   /**
146    * Tests the SuperposeCrystals script with default settings and average linkage.
147    */
148   @Test
149   public void testBaseAverageSuperposeCrystals() {
150 
151     // Set up the input arguments for the SuperposeCrystals script.
152     String[] args = {"-l", "1", getResourcePath("C23.arc")};
153     binding.setVariable("args", args);
154     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
155 
156     // Construct and evaluate the SuperposeCrystals script.
157     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
158     algorithmsScript = superposeCrystals;
159 
160     // Only off-diagonal values.
161     assertEquals(6, superposeCrystals.runningStatistics.getCount());
162     // Mean RMSD for 6 comparisons.
163     assertEquals(0.0830895, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
164     assertEquals(0.217224949, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
165   }
166 
167   /**
168    * Tests the SuperposeCrystals script with hydrogens.
169    */
170   @Test
171   public void testBaseAverageSuperposeCrystalsHydrogen() {
172 
173     // Set up the input arguments for the SuperposeCrystals script.
174     String[] args = {"--ih", "-l", "1", getResourcePath("C23.arc")};
175     binding.setVariable("args", args);
176     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
177 
178     // Construct and evaluate the SuperposeCrystals script.
179     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
180     algorithmsScript = superposeCrystals;
181 
182     // Only off-diagonal values.
183     assertEquals(6, superposeCrystals.runningStatistics.getCount());
184     // Mean RMSD for 6 comparisons.
185     assertEquals(0.111014, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
186     assertEquals(0.297522, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
187   }
188 
189   /**
190    * Tests the SuperposeCrystals script with hydrogens.
191    */
192   @Test
193   public void testBaseSingleSuperposeCrystalsHydrogen() {
194 
195     // Set up the input arguments for the SuperposeCrystals script.
196     String[] args = {"--ih", "-l", "0", getResourcePath("C23.arc")};
197     binding.setVariable("args", args);
198     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
199 
200     // Construct and evaluate the SuperposeCrystals script.
201     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
202     algorithmsScript = superposeCrystals;
203 
204     // Only off-diagonal values.
205     assertEquals(6, superposeCrystals.runningStatistics.getCount());
206     // Mean RMSD for 6 comparisons.
207     assertEquals(0.1125556, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
208     assertEquals(0.30190515, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
209   }
210 
211   /**
212    * Tests the SuperposeCrystals script in Sohncke group.
213    */
214   @Test
215   public void testBaseAverageSuperposeCrystalsSohnckeGroup() {
216 
217     // Set up the input arguments for the SuperposeCrystals script.
218     String[] args = {"-l", "1", getResourcePath("dap.xyz"), getResourcePath("dap.xyz_close")};
219     binding.setVariable("args", args);
220     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
221 
222     // Construct and evaluate the SuperposeCrystals script.
223     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
224     algorithmsScript = superposeCrystals;
225 
226     assertEquals(0.066569, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
227   }
228 
229   /**
230    * Tests the SuperposeCrystals script in Sohncke group.
231    */
232   @Test
233   public void testBaseSingleSuperposeCrystalsSohnckeGroup() {
234 
235     // Set up the input arguments for the SuperposeCrystals script.
236     String[] args = {"-l", "0", getResourcePath("dap.xyz"), getResourcePath("dap.xyz_close")};
237     binding.setVariable("args", args);
238     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
239 
240     // Construct and evaluate the SuperposeCrystals script.
241     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
242     algorithmsScript = superposeCrystals;
243 
244     assertEquals(0.073036, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
245   }
246 
247   /**
248    * Tests the SuperposeCrystals script on tricky handedness case.
249    */
250   @Test
251   public void testBaseAverageSuperposeCrystalsHandedness() {
252 
253     // Set up the input arguments for the SuperposeCrystals script.
254     String[] args = {"-l", "1", getResourcePath("dap2.xyz"), getResourcePath("dap2.xyz_2")};
255     binding.setVariable("args", args);
256     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
257 
258     // Construct and evaluate the SuperposeCrystals script.
259     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
260     algorithmsScript = superposeCrystals;
261 
262     assertEquals(0.112274, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
263   }
264 
265   /**
266    * Tests the SuperposeCrystals script on tricky handedness case.
267    */
268   @Test
269   public void testBaseSingleSuperposeCrystalsHandedness() {
270 
271     // Set up the input arguments for the SuperposeCrystals script.
272     String[] args = {"-l", "0", getResourcePath("dap2.xyz"), getResourcePath("dap2.xyz_2")};
273     binding.setVariable("args", args);
274     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
275 
276     // Construct and evaluate the SuperposeCrystals script.
277     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
278     algorithmsScript = superposeCrystals;
279 
280     assertEquals(0.098483, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
281   }
282 
283   /**
284    * Tests the SuperposeCrystals script on asymmetric unit greater than one.
285    */
286   @Test
287   public void testBaseAverageSuperposeCrystalsZPrime2() {
288 
289     // Set up the input arguments for the SuperposeCrystals script.
290     String[] args = {"-l", "1", getResourcePath("XAFPAY02.arc")};
291     binding.setVariable("args", args);
292     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
293 
294     // Construct and evaluate the SuperposeCrystals script.
295     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
296     algorithmsScript = superposeCrystals;
297 
298     assertEquals(6, superposeCrystals.runningStatistics.getCount());
299     // Mean RMSD for 6 comparisons.
300 
301     assertEquals(0.151675, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
302     assertEquals(0.375328, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
303   }
304 
305   /**
306    * Tests the SuperposeCrystals script on asymmetric unit greater than one.
307    */
308   @Test
309   public void testBaseSingleSuperposeCrystalsZPrime2() {
310 
311     // Set up the input arguments for the SuperposeCrystals script.
312     String[] args = {"-l", "0", getResourcePath("XAFPAY02.arc")};
313     binding.setVariable("args", args);
314     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
315 
316     // Construct and evaluate the SuperposeCrystals script.
317     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
318     algorithmsScript = superposeCrystals;
319 
320     assertEquals(6, superposeCrystals.runningStatistics.getCount());
321     // Mean RMSD for 6 comparisons.
322 
323     assertEquals(0.142474326, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
324     assertEquals(0.355770508, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
325   }
326 
327   /**
328    * Tests the SuperposeCrystals script on protein crystal.
329    */
330   @Test
331   public void testBaseSingleSuperposeCrystalsSmallProtein() {
332 
333     // Set up the input arguments for the SuperposeCrystals script.
334     String[] args = {"-l", "0", getResourcePath("2olx.arc")};
335     binding.setVariable("args", args);
336     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
337 
338     // Construct and evaluate the SuperposeCrystals script.
339     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
340     algorithmsScript = superposeCrystals;
341 
342     assertEquals(6, superposeCrystals.runningStatistics.getCount());
343     // Mean RMSD for 6 comparisons.
344 
345     assertEquals(0.478175, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
346     assertEquals(1.383652, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
347   }
348 
349   /**
350    * Tests the SuperposeCrystals script on protein crystal.
351    */
352   @Test
353   public void testBaseAverageSuperposeCrystalsSmallProtein() {
354 
355     // Set up the input arguments for the SuperposeCrystals script.
356     String[] args = {"-l", "1", getResourcePath("2olx.arc")};
357     binding.setVariable("args", args);
358     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
359 
360     // Construct and evaluate the SuperposeCrystals script.
361     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
362     algorithmsScript = superposeCrystals;
363 
364     assertEquals(6, superposeCrystals.runningStatistics.getCount());
365     // Mean RMSD for 6 comparisons.
366 
367     assertEquals(0.441851, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
368     assertEquals(1.269418376, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
369   }
370 
371   /**
372    * Tests the SuperposeCrystals script print symmetry operator functionality.
373    */
374   @Test
375   public void testBaseAverageSuperposeCrystalsPrintSym() {
376 
377     // Set up the input arguments for the SuperposeCrystals script.
378     String[] args = {"--na", "1", "--ps", "1.0", getResourcePath("CBZ01_P1.xyz"), getResourcePath("cbz11.xyz")};
379     binding.setVariable("args", args);
380     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
381 
382     // Construct and evaluate the SuperposeCrystals script.
383     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
384     algorithmsScript = superposeCrystals;
385 
386     assertEquals(1, superposeCrystals.runningStatistics.getCount());
387     // Mean RMSD for 6 comparisons.
388 
389     assertEquals(0.10510735, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
390     assertEquals(0.10510735, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
391   }
392 
393   /**
394    * Tests the SuperposeCrystals script alchemical atoms functionality.
395    */
396   @Test
397   public void testBaseAverageSuperposeCrystalsAlchemicalAtoms() {
398 
399     // Set up the input arguments for the SuperposeCrystals script.
400     String[] args = {"--na", "1", "--ps", "1.0", "--ac", "4,7,9,11,13,15,17,19,21,23,25,27",
401         getResourcePath("ZEYBIO01.xyz_amoebax"),
402         getResourcePath("ZEYBIO04_zero.xyz_amoebax")};
403     binding.setVariable("args", args);
404     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
405 
406     // Construct and evaluate the SuperposeCrystals script.
407     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
408     algorithmsScript = superposeCrystals;
409 
410     assertEquals(1, superposeCrystals.runningStatistics.getCount());
411     // Mean RMSD for 6 comparisons.
412     assertEquals(0.14180274, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
413     assertEquals(0.14180274, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
414   }
415 
416   /**
417    * Tests the SuperposeCrystals script on long molecule (potential issue with inflation factor).
418    */
419   @Test
420   public void testSuperposeCrystalsLongMolecule() {
421 
422     // Set up the input arguments for the SuperposeCrystals script.
423     String[] args = {getResourcePath("dameda.arc")};
424     binding.setVariable("args", args);
425     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
426 
427     // Construct and evaluate the SuperposeCrystals script.
428     SuperposeCrystals superposeCrystals = new SuperposeCrystals(binding).run();
429     algorithmsScript = superposeCrystals;
430 
431     assertEquals(3, superposeCrystals.runningStatistics.getCount());
432     // Mean RMSD for 6 comparisons.
433 
434     assertEquals(0.200420, superposeCrystals.runningStatistics.getMean(), TOLERANCE);
435     assertEquals(0.601259, superposeCrystals.runningStatistics.getMax(), TOLERANCE);
436   }
437 
438   @Test
439   public void testSuperposeCrystalsHelp() {
440     // Set up the input arguments for the SuperposeCrystals script.
441     String[] args = {"-h"};
442     binding.setVariable("args", args);
443 
444     // Construct and evaluate the SuperposeCrystals script.
445     SuperposeCrystals SuperposeCrystals = new SuperposeCrystals(binding).run();
446     algorithmsScript = SuperposeCrystals;
447   }
448 }