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.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 ImportCIF command to determine that files are being translated correctly.
48   *
49   * @author Aaron J. Nessler
50   */
51  
52  public class ImportCIFTest extends PotentialTest {
53  
54    /**
55     * Test a basic CIF to XYZ conversion.
56     */
57    @Test
58    public void testImportCIF() {
59      // Set up the input arguments for the ImportCIF script.
60      String cifpath = getResourcePath("CBZ16.cif");
61      String xyzpath = getResourcePath("cbz.xyz");
62      String[] args = {cifpath, xyzpath};
63      binding.setVariable("args", args);
64      binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
65  
66      // Construct and evaluate the ImportCIF script.
67  
68      ImportCIF ImportCIF = new ImportCIF(binding).run();
69      potentialScript = ImportCIF;
70  
71      assertEquals(1, ImportCIF.createdFiles.length);
72      assertTrue(ImportCIF.createdFiles[0].toUpperCase().contains(".XYZ"));
73    }
74  
75    /**
76     * Test writing out a CIF file (XYZ to CIF).
77     */
78    @Test
79    public void testImportCIFWriteAsCIF() {
80      // Set up the input arguments for the ImportCIF script.
81      String filepath = getResourcePath("paracetamol.xyz");
82      String[] args = {"--sc", filepath};
83      binding.setVariable("args", args);
84      binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
85  
86      // Construct and evaluate the ImportCIF script.
87      ImportCIF ImportCIF = new ImportCIF(binding).run();
88      potentialScript = ImportCIF;
89  
90      assertEquals(1, ImportCIF.createdFiles.length);
91      assertTrue(ImportCIF.createdFiles[0].toUpperCase().contains(".CIF"));
92    }
93  
94    /**
95     * Test ImportCIF when the CIF file is missing hydrogen atoms.
96     */
97    @Test
98    public void testImportCIFNoHydrogen() {
99      // Set up the input arguments for the ImportCIF script.
100     String cifpath = getResourcePath("CBZ03.cif");
101     String xyzpath = getResourcePath("cbz.xyz");
102     String[] args = {"--fl", cifpath, xyzpath};
103     binding.setVariable("args", args);
104     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
105 
106     // Construct and evaluate the ImportCIF script.
107     ImportCIF ImportCIF = new ImportCIF(binding).run();
108     potentialScript = ImportCIF;
109 
110     assertEquals(1, ImportCIF.createdFiles.length);
111     assertTrue(ImportCIF.createdFiles[0].toUpperCase().contains(".XYZ"));
112   }
113 
114   /**
115    * Test ImportCIF when several molecules are included in asymmetric unit.
116    */
117   @Test
118   public void testImportCIFMultipleMolecules() {
119     // Set up the input arguments for the ImportCIF script.
120     String cifpath = getResourcePath("1183240.cif");
121     String xyzpath = getResourcePath("asplyswat.xyz");
122     String[] args = {cifpath, xyzpath};
123     binding.setVariable("args", args);
124     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
125 
126     // Construct and evaluate the ImportCIF script.
127     ImportCIF ImportCIF = new ImportCIF(binding).run();
128     potentialScript = ImportCIF;
129 
130     assertEquals(1, ImportCIF.createdFiles.length);
131     assertTrue(ImportCIF.createdFiles[0].toUpperCase().contains(".XYZ"));
132   }
133 
134   /**
135    * Test ImportCIF when similar (but different) molecules are in asymmetric unit.
136    */
137   @Test
138   public void testImportCIFzPrimeChallenge() {
139     // Set up the input arguments for the ImportCIF script.
140     String cifpath = getResourcePath("1183241.cif");
141     String xyzpath = getResourcePath("glulys.xyz");
142     String[] args = {"--fl", cifpath, xyzpath};
143     binding.setVariable("args", args);
144     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
145 
146     // Construct and evaluate the ImportCIF script.
147     ImportCIF ImportCIF = new ImportCIF(binding).run();
148     potentialScript = ImportCIF;
149 
150     assertEquals(1, ImportCIF.createdFiles.length);
151     assertTrue(ImportCIF.createdFiles[0].toUpperCase().contains(".XYZ"));
152   }
153 
154   /**
155    * Test ImportCIF on concatenated CIF files (produces multiple ARC files).
156    */
157   @Test
158   public void testImportCIFarc() {
159     // Set up the input arguments for the ImportCIF script.
160     String cifpath = getResourcePath("cbzs.cif");
161     String xyzpath = getResourcePath("cbz.xyz");
162     String[] args = {"--fl", cifpath, xyzpath};
163     binding.setVariable("args", args);
164     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
165 
166     // Construct and evaluate the ImportCIF script.
167     ImportCIF ImportCIF = new ImportCIF(binding).run();
168     potentialScript = ImportCIF;
169 
170     assertEquals(3, ImportCIF.createdFiles.length);
171     assertTrue(ImportCIF.createdFiles[0].toUpperCase().contains(".ARC"));
172   }
173 
174   /**
175    * Test ImportCIF across a molecular disulfide bond.
176    */
177   @Test
178   public void testImportCIFdisulfide() {
179     // Set up the input arguments for the ImportCIF script.
180     String cifpath = getResourcePath("UFAGIS01.cif");
181     String xyzpath = getResourcePath("uf.xyz");
182     String[] args = {cifpath, xyzpath};
183     binding.setVariable("args", args);
184     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
185 
186     // Construct and evaluate the ImportCIF script.
187     ImportCIF ImportCIF = new ImportCIF(binding).run();
188     potentialScript = ImportCIF;
189 
190     assertEquals(1, ImportCIF.createdFiles.length);
191     assertTrue(ImportCIF.createdFiles[0].toUpperCase().contains(".XYZ"));
192   }
193 
194   /**
195    * Test ImportCIF conversion to PDB.
196    */
197   @Test
198   public void testImportCIFpdb() {
199     // Set up the input arguments for the ImportCIF script.
200     String cifpath = getResourcePath("288726.cif");
201     String pdbpath = getResourcePath("ALA-HIE.pdb");
202     String[] args = {cifpath, pdbpath};
203     binding.setVariable("args", args);
204     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
205 
206     // Construct and evaluate the ImportCIF script.
207     ImportCIF ImportCIF = new ImportCIF(binding).run();
208     potentialScript = ImportCIF;
209 
210     assertEquals(1, ImportCIF.createdFiles.length);
211     assertTrue(ImportCIF.createdFiles[0].toUpperCase().contains(".PDB"));
212   }
213 
214   /**
215    * Print out help message.
216    */
217   @Test
218   public void testImportCIFHelp() {
219     // Set up the input arguments for the ImportCIF script.
220     String[] args = {"-h"};
221     binding.setVariable("args", args);
222 
223     // Construct and evaluate the ImportCIF script.
224     potentialScript = new ImportCIF(binding).run();
225   }
226 }