1   // ******************************************************************************
2   //
3   // Title:       Force Field X.
4   // Description: Force Field X - Software for Molecular Biophysics.
5   // Copyright:   Copyright (c) Michael J. Schnieders 2001-2023.
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.potential.groovy;
39  
40  import ffx.potential.utils.PotentialTest;
41  import org.junit.Test;
42  
43  import static org.junit.Assert.assertEquals;
44  import static org.junit.Assert.assertTrue;
45  
46  /**
47   * Tests CIFtoXYZ command to determine that files are being translated correctly.
48   *
49   * @author Aaron J. Nessler
50   */
51  
52  public class CIFtoXYZTest extends PotentialTest {
53  
54    /**
55     * Test a basic CIF to XYZ conversion.
56     */
57    @Test
58    public void testCIFtoXYZ() {
59      // Set up the input arguments for the CIFtoXYZ script.
60      String[] args = {"src/main/java/ffx/potential/structures/CBZ16.cif",
61          "src/main/java/ffx/potential/structures/cbz.xyz"};
62      binding.setVariable("args", args);
63      binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
64  
65      // Construct and evaluate the CIFtoXYZ script.
66  
67      CIFtoXYZ cifToXYZ = new CIFtoXYZ(binding).run();
68      potentialScript = cifToXYZ;
69  
70      assertEquals(1, cifToXYZ.createdFiles.length);
71      assertTrue(cifToXYZ.createdFiles[0].toUpperCase().contains(".XYZ"));
72    }
73  
74    /**
75     * Test writing out a CIF file (XYZ to CIF).
76     */
77    @Test
78    public void testCIFtoXYZWriteAsCIF() {
79      // Set up the input arguments for the CIFtoXYZ script.
80      String[] args = {"--sc", "src/main/java/ffx/potential/structures/paracetamol.xyz"};
81      binding.setVariable("args", args);
82      binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
83  
84      // Construct and evaluate the CIFtoXYZ script.
85      CIFtoXYZ cifToXYZ = new CIFtoXYZ(binding).run();
86      potentialScript = cifToXYZ;
87  
88      assertEquals(1, cifToXYZ.createdFiles.length);
89      assertTrue(cifToXYZ.createdFiles[0].toUpperCase().contains(".CIF"));
90    }
91  
92    /**
93     * Test CIFtoXYZ when the CIF file is missing hydrogen atoms.
94     */
95    @Test
96    public void testCIFtoXYZNoHydrogen() {
97      // Set up the input arguments for the CIFtoXYZ script.
98      String[] args = {"--fl","src/main/java/ffx/potential/structures/CBZ03.cif",
99          "src/main/java/ffx/potential/structures/cbz.xyz"};
100     binding.setVariable("args", args);
101     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
102 
103     // Construct and evaluate the CIFtoXYZ script.
104     CIFtoXYZ cifToXYZ = new CIFtoXYZ(binding).run();
105     potentialScript = cifToXYZ;
106 
107     assertEquals(1, cifToXYZ.createdFiles.length);
108     assertTrue(cifToXYZ.createdFiles[0].toUpperCase().contains(".XYZ"));
109   }
110 
111   /**
112    * Test CIFtoXYZ when several molecules are included in asymmetric unit.
113    */
114   @Test
115   public void testCIFtoXYZMultipleMolecules() {
116     // Set up the input arguments for the CIFtoXYZ script.
117     String[] args = {"src/main/java/ffx/potential/structures/1183240.cif",
118             "src/main/java/ffx/potential/structures/asplyswat.xyz"};
119     binding.setVariable("args", args);
120     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
121 
122     // Construct and evaluate the CIFtoXYZ script.
123     CIFtoXYZ cifToXYZ = new CIFtoXYZ(binding).run();
124     potentialScript = cifToXYZ;
125 
126     assertEquals(1, cifToXYZ.createdFiles.length);
127     assertTrue(cifToXYZ.createdFiles[0].toUpperCase().contains(".XYZ"));
128   }
129 
130   /**
131    * Test CIFtoXYZ when similar (but different) molecules are in asymmetric unit.
132    */
133   @Test
134   public void testCIFtoXYZzPrimeChallenge() {
135     // Set up the input arguments for the CIFtoXYZ script.
136     String[] args = {"--fl","src/main/java/ffx/potential/structures/1183241.cif",
137             "src/main/java/ffx/potential/structures/glulys.xyz"};
138     binding.setVariable("args", args);
139     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
140 
141     // Construct and evaluate the CIFtoXYZ script.
142     CIFtoXYZ cifToXYZ = new CIFtoXYZ(binding).run();
143     potentialScript = cifToXYZ;
144 
145     assertEquals(1, cifToXYZ.createdFiles.length);
146     assertTrue(cifToXYZ.createdFiles[0].toUpperCase().contains(".XYZ"));
147   }
148 
149   /**
150    * Test CIFtoXYZ on concatenated CIF files (produces multiple ARC files).
151    */
152   @Test
153   public void testCIFtoXYZarc() {
154     // Set up the input arguments for the CIFtoXYZ script.
155     String[] args = {"--fl","src/main/java/ffx/potential/structures/cbzs.cif",
156             "src/main/java/ffx/potential/structures/cbz.xyz"};
157     binding.setVariable("args", args);
158     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
159 
160     // Construct and evaluate the CIFtoXYZ script.
161     CIFtoXYZ cifToXYZ = new CIFtoXYZ(binding).run();
162     potentialScript = cifToXYZ;
163 
164     assertEquals(3, cifToXYZ.createdFiles.length);
165     assertTrue(cifToXYZ.createdFiles[0].toUpperCase().contains(".ARC"));
166   }
167 
168   /**
169    * Test CIFtoXYZ across a molecular disulfide bond.
170    */
171   @Test
172   public void testCIFtoXYZdisulfide() {
173     // Set up the input arguments for the CIFtoXYZ script.
174     String[] args = {"src/main/java/ffx/potential/structures/UFAGIS01.cif",
175             "src/main/java/ffx/potential/structures/uf.xyz"};
176     binding.setVariable("args", args);
177     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
178 
179     // Construct and evaluate the CIFtoXYZ script.
180     CIFtoXYZ cifToXYZ = new CIFtoXYZ(binding).run();
181     potentialScript = cifToXYZ;
182 
183     assertEquals(1, cifToXYZ.createdFiles.length);
184     assertTrue(cifToXYZ.createdFiles[0].toUpperCase().contains(".XYZ"));
185   }
186 
187   /**
188    * Print out help message.
189    */
190   @Test
191   public void testCIFtoXYZHelp() {
192     // Set up the input arguments for the CIFtoXYZ script.
193     String[] args = {"-h"};
194     binding.setVariable("args", args);
195 
196     // Construct and evaluate the CIFtoXYZ script.
197     potentialScript = new CIFtoXYZ(binding).run();
198   }
199 }