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.xray.parsers;
39  
40  import static org.junit.Assert.assertEquals;
41  import static org.junit.Assert.assertNotNull;
42  import static org.junit.Assert.assertTrue;
43  
44  import ffx.algorithms.misc.AlgorithmsTest;
45  import ffx.crystal.Crystal;
46  import ffx.crystal.HKL;
47  import ffx.crystal.ReflectionList;
48  import ffx.crystal.Resolution;
49  import ffx.utilities.Keyword;
50  import ffx.xray.DiffractionRefinementData;
51  
52  import java.io.File;
53  
54  import org.apache.commons.configuration2.CompositeConfiguration;
55  import org.junit.Test;
56  
57  /**
58   * Test the MTZ Filter.
59   *
60   * @author Timothy D. Fenn
61   */
62  public class MTZFilterTest extends AlgorithmsTest {
63  
64    private final File mtzFile = getResourceFile("2DRM.mtz");
65    // Load any properties associated with it
66    private final CompositeConfiguration properties = Keyword.loadProperties(mtzFile);
67    // set up the crystal data
68    private final Crystal crystal = new Crystal(29.97, 37.86, 44.51, 90.28, 90.11, 90.64, "P1");
69    private final Resolution resolution = new Resolution(1.30);
70    private final ReflectionList reflectionList = new ReflectionList(crystal, resolution);
71    private final DiffractionRefinementData refinementData =
72        new DiffractionRefinementData(properties, reflectionList);
73  
74    @Test
75    public void testMTZHKL() {
76      MTZFilter mtzFilter = new MTZFilter();
77      assertTrue(
78          "mtz file errors", mtzFilter.readFile(mtzFile, reflectionList, refinementData, null));
79      HKL hkl = reflectionList.getHKL(-10, 1, 1);
80      assertEquals("-10 1 1 FP value", 229.90, refinementData.getF(hkl.getIndex()), 0.02);
81      assertEquals("-10 1 1 SIGFP value", 2.50, refinementData.getSigF(hkl.getIndex()), 0.02);
82      assertEquals("-10 1 1 FREE value", 1, refinementData.getFreeR(hkl.getIndex()));
83      hkl = reflectionList.getHKL(-10, 1, 10);
84      assertEquals(
85          "-10 1 10 FP value should be NaN", Double.NaN, refinementData.getF(hkl.getIndex()), 0.1);
86      assertEquals(
87          "-10 1 10 SIGFP value should be NaN", Double.NaN, refinementData.getSigF(hkl.getIndex()), 0.1);
88    }
89  
90    @Test
91    public void testMTZParams() {
92      MTZFilter mtzFilter = new MTZFilter();
93      assertTrue(
94          "mtz file should be read in without errors",
95          mtzFilter.readFile(mtzFile, reflectionList, refinementData, null));
96      assertEquals("mtz file number of columns", 6, mtzFilter.getnColumns());
97      assertEquals("mtz file number of reflections", 48115, mtzFilter.getnReflections());
98      assertEquals("mtz file space group number", 1, mtzFilter.getSpaceGroupNum());
99    }
100 
101   @Test
102   public void testMTZReadFile() {
103     MTZFilter mtzFilter = new MTZFilter();
104     assertTrue(
105         "mtz file should be read in without errors",
106         mtzFilter.readFile(mtzFile, reflectionList, refinementData, null));
107   }
108 
109   @Test
110   public void testMTZReflectionList() {
111     MTZFilter mtzFilter = new MTZFilter();
112     ReflectionList tmp = mtzFilter.getReflectionList(mtzFile);
113     assertNotNull("mtz file should return a reflection list", tmp);
114     assertEquals("reflection list space group", 1, tmp.spaceGroup.number);
115     assertEquals("reflection list cell dimension", 29.969, tmp.crystal.a, 0.01);
116     assertEquals("reflection list resolution", 1.30, tmp.resolution.resolutionLimit(), 0.01);
117   }
118 }