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-2025.
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     assertEquals("1 1 4 reflection should be correct", -753.5793258338429, a.re(), 0.0001);
102     assertEquals("1 1 4 reflection should be correct", -1012.0644582810149, a.im(), 0.0001);
103 
104     b.re(-70.4582);
105     b.im(-486.142);
106     hkl = reflectionList.getHKL(2, 1, 10);
107     a = refinementData.getFc(hkl.getIndex());
108     assertEquals("2 1 10 reflection should be correct", -69.31114217592258, a.re(), 0.0001);
109     assertEquals("2 1 10 reflection should be correct", -412.03857890421773, a.im(), 0.0001);
110   }
111 
112   @Test
113   public void test1NSFPermanent() {
114     // load the structure
115     String filename = "1NSF.pdb";
116     File structure = getResourceFile(filename);
117 
118     // load any properties associated with it
119     CompositeConfiguration properties = Keyword.loadProperties(structure);
120     Crystal crystal = new Crystal(115.996, 115.996, 44.13, 90.0, 90.0, 120.0, "P6");
121     Resolution resolution = new Resolution(1.89631);
122 
123     ReflectionList reflectionList = new ReflectionList(crystal, resolution);
124     DiffractionRefinementData refinementData =
125         new DiffractionRefinementData(properties, reflectionList);
126 
127     ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
128     ForceField forceField = forceFieldFilter.parse();
129 
130     // associate molecular assembly with the structure, set up forcefield
131     MolecularAssembly molecularAssembly = new MolecularAssembly(filename);
132     molecularAssembly.setFile(structure);
133     molecularAssembly.setForceField(forceField);
134     PDBFilter pdbFile = new PDBFilter(structure, molecularAssembly, forceField, properties);
135     pdbFile.readFile();
136     pdbFile.applyAtomProperties();
137     molecularAssembly.finalize(true, forceField);
138     ForceFieldEnergy.energyFactory(molecularAssembly);
139 
140     List<Atom> atomList = molecularAssembly.getAtomList();
141     Atom[] atomArray = atomList.toArray(new Atom[0]);
142 
143     // set up FFT and run it
144     ParallelTeam parallelTeam = new ParallelTeam();
145     CrystalReciprocalSpace crs =
146         new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam);
147     crs.computeAtomicDensity(refinementData.fc);
148 
149     // tests
150     ComplexNumber b = new ComplexNumber(-496.999, 431.817);
151     HKL hkl = reflectionList.getHKL(1, 9, 4);
152     ComplexNumber a = refinementData.getFc(hkl.getIndex());
153     // System.out.println("1 9 4: " + a + " | " + b + " | " + a.divides(b));
154     assertEquals("1 9 4 reflection should be correct", -493.7187045633783, a.re(), 0.0001);
155     assertEquals("1 9 4 reflection should be correct", 460.7338806590369, a.im(), 0.0001);
156 
157     b.re(-129.767);
158     b.im(-76.9812);
159     hkl = reflectionList.getHKL(5, 26, 8);
160     a = refinementData.getFc(hkl.getIndex());
161     assertEquals("5 26 8 reflection should be correct", -122.9964517142246, a.re(), 0.0001);
162     assertEquals("5 26 8 reflection should be correct", -74.56810279849924, a.im(), 0.0001);
163   }
164 }