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.assertNull;
43  import static org.junit.Assert.assertTrue;
44  
45  import ffx.algorithms.misc.AlgorithmsTest;
46  import ffx.crystal.Crystal;
47  import ffx.crystal.HKL;
48  import ffx.crystal.ReflectionList;
49  import ffx.crystal.Resolution;
50  import ffx.utilities.Keyword;
51  import ffx.xray.DiffractionRefinementData;
52  
53  import java.io.File;
54  
55  import org.apache.commons.configuration2.CompositeConfiguration;
56  import org.junit.Test;
57  
58  /**
59   * Test the CIF Filter.
60   *
61   * @author Timoth D. Fenn
62   */
63  public class CIFFilterTest extends AlgorithmsTest {
64  
65    @Test
66    public void testCIFFilter2DRM() {
67      File cifFile = getResourceFile("2DRM.cif");
68      // load any properties associated with it
69      CompositeConfiguration properties = Keyword.loadProperties(cifFile);
70  
71      CIFFilter cifFilter = new CIFFilter();
72      ReflectionList reflectionList = cifFilter.getReflectionList(cifFile);
73      assertNull(" Reflection list should be null", reflectionList);
74  
75      Crystal crystal = new Crystal(29.969, 37.861, 44.506, 90.28, 90.11, 90.64, "P1");
76      Resolution resolution = new Resolution(1.30);
77      reflectionList = new ReflectionList(crystal, resolution);
78      DiffractionRefinementData refinementData =
79          new DiffractionRefinementData(properties, reflectionList);
80  
81      assertTrue(
82          " CIF data not read correctly",
83          cifFilter.readFile(cifFile, reflectionList, refinementData, properties));
84  
85      HKL hkl = reflectionList.getHKL(-21, -6, 7);
86      assertEquals("-21 -6 7 F", 18.6, refinementData.getF(hkl.getIndex()), 0.01);
87      assertEquals("-21 -6 7 sigF", 3.6, refinementData.getSigF(hkl.getIndex()), 0.01);
88      assertEquals("-21 -6 7 freeR value", 0, refinementData.freeR[hkl.getIndex()]);
89  
90      hkl = reflectionList.getHKL(-21, -6, 8);
91      assertEquals("-21 -6 7 F", 20.2, refinementData.getF(hkl.getIndex()), 0.01);
92      assertEquals("-21 -6 7 sigF", 5.0, refinementData.getSigF(hkl.getIndex()), 0.01);
93      assertEquals("-21 -6 7 freeR value", 1, refinementData.freeR[hkl.getIndex()]);
94    }
95  
96    @Test
97    public void testCIFFilter3DYC() {
98      File cifFile = getResourceFile("3DYC.ent");
99      // load any properties associated with it
100     CompositeConfiguration properties = Keyword.loadProperties(cifFile);
101 
102     CIFFilter cifFilter = new CIFFilter();
103     ReflectionList reflectionList = cifFilter.getReflectionList(cifFile);
104     assertNotNull(" Reflection list should not be null", reflectionList);
105     DiffractionRefinementData refinementData =
106         new DiffractionRefinementData(properties, reflectionList);
107 
108     assertTrue(
109         " CIF data not read in correctly",
110         cifFilter.readFile(cifFile, reflectionList, refinementData, properties));
111 
112     HKL hkl = reflectionList.getHKL(58, 0, 13);
113     assertEquals("58 0 13 F", 99.7, refinementData.getF(hkl.getIndex()), 0.01);
114     assertEquals("58 0 13 sigF", 69.7, refinementData.getSigF(hkl.getIndex()), 0.01);
115     assertEquals("58 0 13 freeR value", 1, refinementData.freeR[hkl.getIndex()]);
116 
117     hkl = reflectionList.getHKL(28, 20, 5);
118     assertEquals("28 20 5 F", 428.1, refinementData.getF(hkl.getIndex()), 0.01);
119     assertEquals("28 20 5 sigF", 10.1, refinementData.getSigF(hkl.getIndex()), 0.01);
120     assertEquals("28 20 5 freeR value", 0, refinementData.freeR[hkl.getIndex()]);
121   }
122 }