$darkmode
DENOPTIM
RCOSocketServerClientTest.java
Go to the documentation of this file.
1package denoptim.integration.rcoserver;
2
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertFalse;
6import static org.junit.jupiter.api.Assertions.assertTrue;
7
8import java.util.HashMap;
9import java.util.Map;
10
11import org.junit.jupiter.api.Test;
12
13import com.google.gson.JsonArray;
14import com.google.gson.JsonElement;
15import com.google.gson.JsonObject;
16
17import denoptim.molecularmodeling.zmatrix.ZMatrix;
18import denoptim.molecularmodeling.zmatrix.ZMatrixAtom;
19
28{
29
30//------------------------------------------------------------------------------
31
32 @Test
34 {
35 ZMatrix zMatrix = new ZMatrix();
36
37 ZMatrixAtom atom0 = new ZMatrixAtom(
38 0, "H", "H.1", null, null, null,
39 null, null, null, null);
40
41 ZMatrixAtom atom1 = new ZMatrixAtom(
42 1, "O", "O.2", atom0, null, null,
43 1.5, null, null, null);
44
45 ZMatrixAtom atom2 = new ZMatrixAtom(
46 2, "C", "C.3", atom1, atom0, null,
47 1.4, 109.5, null, null);
48
49 ZMatrixAtom atom3 = new ZMatrixAtom(
50 3, "H", "H.1", atom2, atom1, atom0,
51 1.4, 109.5, 60.0, 0);
52
53 ZMatrixAtom atom4 = new ZMatrixAtom(
54 4, "H", "H.1", atom2, atom1, atom3,
55 1.4, 109.5, 109.0, 1);
56
57 ZMatrixAtom atom5 = new ZMatrixAtom(
58 5, "H", "H.1", atom4, atom2, atom1,
59 1.4, 109.5, 0.0, 0);
60
61 zMatrix.addAtom(atom0);
62 zMatrix.addAtom(atom1);
63 zMatrix.addAtom(atom2);
64 zMatrix.addAtom(atom3);
65 zMatrix.addAtom(atom4);
66 zMatrix.addAtom(atom5);
67
68 zMatrix.addBond(atom0, atom1);
69 zMatrix.addBond(atom1, atom2);
70 zMatrix.addBond(atom2, atom3);
71 zMatrix.addBond(atom2, atom4);
72 zMatrix.addBond(atom2, atom5);
73
74
75 JsonArray result = RCOSocketServerClient.getZMatrixAsJsonArray(zMatrix);
76
77 assertEquals(6, result.size());
78
79 Map<String,Integer> expectedNotNullFrom = new HashMap<String,Integer>();
80 expectedNotNullFrom.put("id", 0);
81 expectedNotNullFrom.put("element", 0);
82 expectedNotNullFrom.put("bond_ref", 1);
83 expectedNotNullFrom.put("bond_length", 1);
84 expectedNotNullFrom.put("angle_ref", 2);
85 expectedNotNullFrom.put("angle", 2);
86 expectedNotNullFrom.put("dihedral_ref", 3);
87 expectedNotNullFrom.put("dihedral", 3);
88 expectedNotNullFrom.put("chirality", 3);
89
90 int idx = 0;
91 for (JsonElement je : result.asList())
92 {
93 JsonObject jo = je.getAsJsonObject();
94 for (String key : expectedNotNullFrom.keySet())
95 {
96 if (idx >= expectedNotNullFrom.get(key))
97 {
98 assertTrue(jo.has(key), "Missing key '" + key + "' in " + jo);
99 assertFalse(jo.get(key).isJsonNull(), "JsonNull for '" + key + "': " + jo);
100 } else {
101 assertFalse(jo.has(key), "Unexpected key '" + key + "' in " + jo);
102 }
103 }
104 idx++;
105 }
106 }
107
108//------------------------------------------------------------------------------
109
110}
Sends the request to produce a socket server running the RingClosingMM service.
static JsonArray getZMatrixAsJsonArray(ZMatrix zmat)
Gets a JsonArray representation of the Z-matrix.
Representation of an atom in the ZMatrix.
Definition: ZMatrixAtom.java:9
Representation of an atom container's geometry with internal coordinates.
Definition: ZMatrix.java:27
void addBond(int a1, int a2)
Add a bond between the two atoms at the given indices.
Definition: ZMatrix.java:461
void addAtom(ZMatrixAtom atom)
Add an atom to the ZMatrix.
Definition: ZMatrix.java:61