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;
39  
40  import static org.junit.Assert.assertEquals;
41  
42  import edu.rit.pj.ParallelTeam;
43  import ffx.algorithms.misc.AlgorithmsTest;
44  import ffx.crystal.Crystal;
45  import ffx.crystal.HKL;
46  import ffx.crystal.ReflectionList;
47  import ffx.crystal.Resolution;
48  import ffx.numerics.math.ComplexNumber;
49  import ffx.potential.ForceFieldEnergy;
50  import ffx.potential.MolecularAssembly;
51  import ffx.potential.bonded.Atom;
52  import ffx.potential.parameters.ForceField;
53  import ffx.potential.parsers.ForceFieldFilter;
54  import ffx.potential.parsers.PDBFilter;
55  import ffx.potential.utils.PotentialsUtils;
56  import ffx.utilities.Keyword;
57  
58  import java.io.File;
59  import java.util.List;
60  
61  import org.apache.commons.configuration2.CompositeConfiguration;
62  import org.junit.Test;
63  
64  /**
65   * @author Timothy D. Fenn
66   */
67  public class CrystalReciprocalSpaceTest extends AlgorithmsTest {
68  
69    /**
70     * Test of permanent method, of class CrystalReciprocalSpace.
71     */
72    @Test
73    public void test1N7SPermanent() {
74      // load the structure
75      File structure = getResourceFile("1N7S.pdb");
76      PotentialsUtils potutil = new PotentialsUtils();
77      MolecularAssembly mola = potutil.open(structure);
78      CompositeConfiguration properties = mola.getProperties();
79  
80      Crystal crystal = new Crystal(39.767, 51.750, 132.938, 90.00, 90.00, 90.00, "P212121");
81      Resolution resolution = new Resolution(1.45);
82  
83      ReflectionList reflectionList = new ReflectionList(crystal, resolution);
84      DiffractionRefinementData refinementData =
85          new DiffractionRefinementData(properties, reflectionList);
86  
87      mola.finalize(true, mola.getForceField());
88      List<Atom> atomList = mola.getAtomList();
89      Atom[] atomArray = atomList.toArray(new Atom[0]);
90  
91      // set up FFT and run it
92      ParallelTeam parallelTeam = new ParallelTeam();
93      CrystalReciprocalSpace crs =
94          new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam);
95      crs.computeAtomicDensity(refinementData.fc);
96  
97      // tests
98      ComplexNumber b = new ComplexNumber(-828.584, -922.704);
99      HKL hkl = reflectionList.getHKL(1, 1, 4);
100     ComplexNumber a = refinementData.getFc(hkl.getIndex());
101     // System.out.println("1 1 4: " + a + " | " + b + " | " + a.divides(b));
102 
103     // This uses FFT Factors 2, 3, 4, 5
104     // assertEquals("1 1 4 reflection should be correct", -753.4722104328415, a.re(), 0.0001);
105     // assertEquals("1 1 4 reflection should be correct", -1012.1341308707798, a.im(), 0.0001);
106     // This uses FFT Factors 2, 3, 4, 5, 6, and 7
107     assertEquals("1 1 4 reflection should be correct", -753.5167129023503, a.re(), 0.0001);
108     assertEquals("1 1 4 reflection should be correct", -1012.107931155532, a.im(), 0.0001);
109 
110     b.re(-70.4582);
111     b.im(-486.142);
112     hkl = reflectionList.getHKL(2, 1, 10);
113     a = refinementData.getFc(hkl.getIndex());
114     // System.out.println("2 1 10: " + a + " | " + b + " | " + a.divides(b));
115 
116     // This uses FFT Factors 2, 3, 4, 5
117     // assertEquals("2 1 10 reflection should be correct", -69.3966088405437, a.re(), 0.0001);
118     // assertEquals("2 1 10 reflection should be correct", -412.0147625765327, a.im(), 0.0001);
119     // This uses FFT Factors 2, 3, 4, 5, 6, and 7
120     assertEquals("2 1 10 reflection should be correct", -69.38705883664473, a.re(), 0.0001);
121     assertEquals("2 1 10 reflection should be correct", -412.01967983851665, a.im(), 0.0001);
122   }
123 
124   @Test
125   public void test1NSFPermanent() {
126     // load the structure
127     String filename = "1NSF.pdb";
128     File structure = getResourceFile(filename);
129 
130     // load any properties associated with it
131     CompositeConfiguration properties = Keyword.loadProperties(structure);
132     Crystal crystal = new Crystal(115.996, 115.996, 44.13, 90.0, 90.0, 120.0, "P6");
133     Resolution resolution = new Resolution(1.89631);
134 
135     ReflectionList reflectionList = new ReflectionList(crystal, resolution);
136     DiffractionRefinementData refinementData =
137         new DiffractionRefinementData(properties, reflectionList);
138 
139     ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
140     ForceField forceField = forceFieldFilter.parse();
141 
142     // associate molecular assembly with the structure, set up forcefield
143     MolecularAssembly molecularAssembly = new MolecularAssembly(filename);
144     molecularAssembly.setFile(structure);
145     molecularAssembly.setForceField(forceField);
146     PDBFilter pdbFile = new PDBFilter(structure, molecularAssembly, forceField, properties);
147     pdbFile.readFile();
148     pdbFile.applyAtomProperties();
149     molecularAssembly.finalize(true, forceField);
150     ForceFieldEnergy.energyFactory(molecularAssembly);
151 
152     List<Atom> atomList = molecularAssembly.getAtomList();
153     Atom[] atomArray = atomList.toArray(new Atom[0]);
154 
155     // set up FFT and run it
156     ParallelTeam parallelTeam = new ParallelTeam();
157     CrystalReciprocalSpace crs =
158         new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam);
159     crs.computeAtomicDensity(refinementData.fc);
160 
161     // tests
162     ComplexNumber b = new ComplexNumber(-496.999, 431.817);
163     HKL hkl = reflectionList.getHKL(1, 9, 4);
164     ComplexNumber a = refinementData.getFc(hkl.getIndex());
165     // System.out.println("1 9 4: " + a + " | " + b + " | " + a.divides(b));
166 
167     // This uses FFT Factors 2, 3, 4, 5
168     // assertEquals("1 9 4 reflection should be correct", -493.7799429881329, a.re(), 0.0001);
169     // assertEquals("1 9 4 reflection should be correct", 460.7022632345927, a.im(), 0.0001);
170     // This uses FFT Factors 2, 3, 4, 5, 6, and 7
171     assertEquals("1 9 4 reflection should be correct", -493.71908655557087, a.re(), 0.0001);
172     assertEquals("1 9 4 reflection should be correct", 460.7406135181142, a.im(), 0.0001);
173 
174     b.re(-129.767);
175     b.im(-76.9812);
176     hkl = reflectionList.getHKL(5, 26, 8);
177     a = refinementData.getFc(hkl.getIndex());
178     // System.out.println("5 26 8: " + a + " | " + b + " | " + a.divides(b));
179 
180     // This uses FFT Factors 2, 3, 4, 5
181     // assertEquals("5 26 8 reflection should be correct", -123.05535567943379, a.re(), 0.0001);
182     // assertEquals("5 26 8 reflection should be correct", -74.59007322382718, a.im(), 0.0001);
183     // This uses FFT Factors 2, 3, 4, 5, 6, and 7
184     assertEquals("5 26 8 reflection should be correct", -122.99479244281358, a.re(), 0.0001);
185     assertEquals("5 26 8 reflection should be correct", -74.567914170119, a.im(), 0.0001);
186 
187   }
188 }