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.potential.bonded;
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 org.junit.After;
46  import org.junit.Before;
47  import org.junit.Test;
48  
49  /** Unit tests for the Bond class. */
50  public class BondTest {
51  
52    private final double[] a1d = {0.0, 0.0, 0.0};
53    private final double[] a2d = {1.0, 0.0, 0.0};
54    private final double[] a3d = {1.0, 1.0, 0.0};
55    private final double[] a4d = {0.0, 1.0, 1.0};
56    private final double tolerance = 1.0e-14;
57    private Bond bond = null;
58    private Bond bond2 = null;
59    private Bond bond3 = null;
60    private Atom a1;
61    private Atom a2;
62    private Atom a3;
63    private Atom a4;
64    private Angle an1;
65  
66    @Test(timeout = 500)
67    public void Bond_constructor() {
68      bond = new Bond("Empty Bond");
69      assertNotNull(bond);
70    }
71  
72    @Test(timeout = 500)
73    public void Bond_formsAngleWith() {
74      boolean expectedReturn = true;
75      boolean actualReturn = bond.formsAngleWith(bond2);
76      assertEquals("return value", expectedReturn, actualReturn);
77      expectedReturn = false;
78      actualReturn = bond.formsAngleWith(bond3);
79      assertEquals("return value", expectedReturn, actualReturn);
80    }
81  
82    @Test(timeout = 500)
83    public void Bond_getCommonAtom() {
84      Atom expectedReturn = a2;
85      Atom actualReturn = bond.getCommonAtom(bond2);
86      assertEquals("return value", expectedReturn, actualReturn);
87      actualReturn = bond.getCommonAtom(bond3);
88      assertNull(actualReturn);
89      actualReturn = bond.getCommonAtom(null);
90      assertNull(actualReturn);
91      actualReturn = bond.getCommonAtom(bond);
92      assertNull(actualReturn);
93    }
94  
95    @Test(timeout = 500)
96    public void Bond_getOtherAtom() {
97      Atom expectedReturn = a2;
98      Atom actualReturn = bond.get1_2(a1);
99      assertEquals("return value", expectedReturn, actualReturn);
100     expectedReturn = a1;
101     actualReturn = bond.get1_2(a2);
102     assertEquals("return value", expectedReturn, actualReturn);
103     actualReturn = bond.get1_2(a3);
104     assertNull(actualReturn);
105     Atom nullAtom = null;
106     actualReturn = bond.get1_2(nullAtom);
107     assertNull(actualReturn);
108   }
109 
110   @Test(timeout = 500)
111   public void Bond_getOtherAtom2() {
112     Atom expectedReturn = a1;
113     Atom actualReturn = bond.getOtherAtom(bond2);
114     assertEquals("return value", expectedReturn, actualReturn);
115     actualReturn = bond.getOtherAtom(bond3);
116     assertNull(actualReturn);
117     Bond nullBond = null;
118     actualReturn = bond.getOtherAtom(nullBond);
119     assertNull(actualReturn);
120   }
121 
122   @Test(timeout = 500)
123   public void Bond_update() {
124     // Atom 2 position == Atom 1 position
125     a2.moveTo(a1.getX(), a1.getY(), a1.getZ());
126     bond.update();
127     assertEquals(0.0, bond.getValue(), tolerance);
128     // PI
129     a1.moveTo(0.0, 0.0, 0.0);
130     a2.moveTo(Math.PI, 0.0, 0.0);
131     bond.update();
132     assertEquals(Math.PI, bond.getValue(), tolerance);
133   }
134 
135   @Before
136   public void setUp() {
137     a1 = new Atom("A1");
138     a1.setXYZ(a1d);
139     a2 = new Atom("A2");
140     a2.setXYZ(a2d);
141     a3 = new Atom("A3");
142     a3.setXYZ(a3d);
143     a4 = new Atom("A4");
144     a4.setXYZ(a4d);
145     assertNotNull(a1);
146     assertNotNull(a2);
147     assertNotNull(a3);
148     assertNotNull(a4);
149     bond = new Bond(a1, a2);
150     bond2 = new Bond(a2, a3);
151     bond3 = new Bond(a3, a4);
152     assertNotNull(bond);
153     assertNotNull(bond2);
154     assertNotNull(bond3);
155     an1 = new Angle(bond, bond2);
156     assertNotNull(an1);
157   }
158 
159   @After
160   public void tearDown() {
161     assertTrue(a1.destroy());
162     assertTrue(a2.destroy());
163     assertTrue(a3.destroy());
164     assertTrue(a4.destroy());
165     assertTrue(bond.destroy());
166     assertTrue(bond2.destroy());
167     assertTrue(bond3.destroy());
168     assertTrue(an1.destroy());
169     a1 = null;
170     a2 = null;
171     a3 = null;
172     a4 = null;
173     bond = null;
174     bond2 = null;
175     bond3 = null;
176   }
177 }