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.crystal;
39  
40  import static org.apache.commons.math3.util.FastMath.PI;
41  
42  import java.util.Objects;
43  
44  /**
45   * The HKL class represents a single reflection.
46   *
47   * @author Timothy D. Fenn
48   * @see ReflectionList
49   * @since 1.0
50   */
51  public class HKL {
52  
53    /** Constant <code>ndiv=12.0</code> */
54    static final double ndiv = 12.0;
55  
56    protected int h;
57    protected int k;
58    protected int l;
59    protected int epsilon;
60    protected int allowed;
61    protected int bin;
62    protected int index;
63  
64    /** Constructor for HKL. */
65    public HKL() {
66    }
67  
68    /**
69     * Constructor for HKL.
70     *
71     * @param h an int.
72     * @param k an int.
73     * @param l an int.
74     */
75    public HKL(int h, int k, int l) {
76      this.h = h;
77      this.k = k;
78      this.l = l;
79      allowed = 255;
80    }
81  
82    /**
83     * Constructor for HKL.
84     *
85     * @param h an int.
86     * @param k an int.
87     * @param l an int.
88     * @param eps an int.
89     * @param allowed an int.
90     */
91    public HKL(int h, int k, int l, int eps, int allowed) {
92      this.h = h;
93      this.k = k;
94      this.l = l;
95      this.epsilon = eps;
96      this.allowed = allowed;
97    }
98  
99    /**
100    * neg
101    *
102    * @return a {@link ffx.crystal.HKL} object.
103    */
104   public HKL neg() {
105     return new HKL(-h, -k, -l);
106   }
107 
108   /**
109    * sysAbs
110    *
111    * @return a boolean.
112    */
113   public boolean sysAbs() {
114     return (epsilon == 0);
115   }
116 
117   /**
118    * quadForm
119    *
120    * @param mat an array of double.
121    * @return a double.
122    */
123   public double quadForm(double[][] mat) {
124     return h * (h * mat[0][0] + 2 * (k * mat[0][1] + l * mat[0][2]))
125         + k * (k * mat[1][1] + 2 * (l * mat[1][2]))
126         + l * l * mat[2][2];
127   }
128 
129   /**
130    * getAllowed
131    *
132    * @return a double.
133    */
134   public double getAllowed() {
135     return ((double) allowed) * (PI / ndiv);
136   }
137 
138   /**
139    * setAllowed
140    *
141    * @param allowed an int.
142    */
143   public void setAllowed(int allowed) {
144     this.allowed = allowed;
145   }
146 
147   /**
148    * getBin
149    *
150    * @return an int.
151    */
152   public int getBin() {
153     return bin;
154   }
155 
156   /**
157    * setBin
158    *
159    * @param bin an int.
160    */
161   public void setBin(int bin) {
162     this.bin = bin;
163   }
164 
165   /**
166    * centric
167    *
168    * @return a boolean.
169    */
170   public boolean centric() {
171     return (allowed != 255);
172   }
173 
174   /**
175    * getEpsilon
176    *
177    * @return an int.
178    */
179   public int getEpsilon() {
180     return epsilon;
181   }
182 
183   /**
184    * setEpsilon
185    *
186    * @param eps an int.
187    */
188   public void setEpsilon(int eps) {
189     this.epsilon = eps;
190   }
191 
192   /**
193    * epsilonc
194    *
195    * @return an int.
196    */
197   public int epsilonc() {
198     if (centric()) {
199       return 2 * epsilon;
200     } else {
201       return epsilon;
202     }
203   }
204 
205   /** {@inheritDoc} */
206   @Override
207   public boolean equals(Object o) {
208     if (this == o) {
209       return true;
210     }
211     if (o == null || getClass() != o.getClass()) {
212       return false;
213     }
214     HKL hkl = (HKL) o;
215     return (h == hkl.getH() && k == hkl.getK() && l == hkl.getL());
216   }
217 
218   /**
219    * h
220    *
221    * @return an int.
222    */
223   public int getH() {
224     return h;
225   }
226 
227   /**
228    * h
229    *
230    * @param h an int.
231    */
232   public void setH(int h) {
233     this.h = h;
234   }
235 
236   /** {@inheritDoc} */
237   @Override
238   public int hashCode() {
239     return Objects.hash(h, k, l);
240   }
241 
242   /**
243    * index
244    *
245    * @return an int.
246    */
247   public int getIndex() {
248     return index;
249   }
250 
251   /**
252    * index
253    *
254    * @param index an int.
255    */
256   public void setIndex(int index) {
257     this.index = index;
258   }
259 
260   /**
261    * k
262    *
263    * @return an int.
264    */
265   public int getK() {
266     return k;
267   }
268 
269   /**
270    * k
271    *
272    * @param k an int.
273    */
274   public void setK(int k) {
275     this.k = k;
276   }
277 
278   /**
279    * l
280    *
281    * @return an int.
282    */
283   public int getL() {
284     return l;
285   }
286 
287   /**
288    * l
289    *
290    * @param l an int.
291    */
292   public void setL(int l) {
293     this.l = l;
294   }
295 
296   /** {@inheritDoc} */
297   @Override
298   public String toString() {
299     return h + " " + k + " " + l
300         + "(allowed: " + allowed + " eps: " + epsilon + ") ";
301   }
302 }