19package denoptim.integration.tinker;
21import static org.junit.jupiter.api.Assertions.assertEquals;
22import static org.junit.jupiter.api.Assertions.assertTrue;
25import java.nio.file.Files;
26import java.nio.file.Path;
27import java.util.ArrayList;
30import org.junit.jupiter.api.Test;
31import org.junit.jupiter.api.io.TempDir;
33import denoptim.molecularmodeling.zmatrix.ZMatrix;
34import denoptim.molecularmodeling.zmatrix.ZMatrixAtom;
53 zmat.
setId(
"TestMolecule");
55 0,
"C",
"C.3",
null,
null,
null,
56 null,
null,
null,
null);
58 1,
"C",
"C.3", zAtom0,
null,
null,
59 1.0,
null,
null,
null);
61 2,
"H",
"H.1", zAtom1, zAtom0,
null,
62 1.0, 90.0,
null,
null);
64 3,
"H",
"H.1", zAtom2, zAtom1, zAtom0,
67 4,
"P",
"P.3", zAtom3, zAtom2, zAtom1,
70 5,
"O",
"O.3", zAtom4, zAtom3, zAtom2,
73 6,
"Cl",
"Cl.1", zAtom4, zAtom3, zAtom5,
76 7,
"H",
"H.1", zAtom4, zAtom3, zAtom5,
96 File outputFile =
tempDir.resolve(
"output.int").toFile();
101 assertTrue(readInZMat.
equals(zmat));
110 zmat.
setId(
"TestMolecule");
112 0,
"C",
"C.3",
null,
null,
null,
113 null,
null,
null,
null);
115 1,
"C",
"C.3", zAtom0,
null,
null,
116 1.0,
null,
null,
null);
118 2,
"H",
"H.1", zAtom1, zAtom0,
null,
119 1.0, 90.0,
null,
null);
121 3,
"H",
"H.1", zAtom2, zAtom1, zAtom0,
124 4,
"P",
"P.3", zAtom3, zAtom2, zAtom1,
125 1.0, 90.0, -90.0, 0);
127 5,
"O",
"O.3", zAtom4, zAtom3, zAtom2,
128 1.0, 90.0, 180.0, 0);
130 6,
"Cl",
"Cl.1", zAtom4, zAtom3, zAtom5,
133 7,
"H",
"H.1", zAtom4, zAtom3, zAtom5,
134 1.0, 90.0, 90.0, -1);
153 File outputFile =
tempDir.resolve(
"output.int").toFile();
156 assertTrue(outputFile.exists(),
"Output file should be created");
157 assertTrue(outputFile.length() > 0,
"Output file should not be empty");
160 String content = Files.readString(outputFile.toPath());
161 String[] allLines = content.split(
"\\r?\\n");
162 List<String> strippedLines =
new ArrayList<>();
163 for (String line : allLines)
165 String stripped = line.trim();
166 if (!stripped.isEmpty())
168 strippedLines.add(stripped);
173 assertEquals(
"8 TestMolecule", strippedLines.get(0));
174 assertEquals(
"1 C C.3", strippedLines.get(1));
175 assertEquals(
"2 C C.3 1 1.00000", strippedLines.get(2));
176 assertEquals(
"3 H H.1 2 1.00000 1 90.0000", strippedLines.get(3));
177 assertEquals(
"8 H H.1 5 1.00000 4 90.0000 6 90.0000 -1",
178 strippedLines.get(8));
181 int bondSectionStart = -1;
182 for (
int i = 0; i < strippedLines.size(); i++)
184 if (strippedLines.get(i).isEmpty() && i + 1 < strippedLines.size())
186 bondSectionStart = i + 1;
190 if (bondSectionStart >= 0)
192 assertTrue(strippedLines.contains(
"1 7"));
193 assertTrue(strippedLines.contains(
"5 4"));
Toolbox of utilities for Tinker style molecular representation.
static ZMatrix readTinkerINT(String filename)
Reads a Tinker INT file.
static void writeTinkerINT(String filename, ZMatrix zmat)
Write Tinker INT file.
Unit test for TinkerUtils.
void testWriteTinkerINT()
Representation of an atom in the ZMatrix.
Representation of an atom container's geometry with internal coordinates.
void setId(String id)
Set the id of the ZMatrix.
void addBond(int a1, int a2)
Add a bond between the two atoms at the given indices.
void addAtom(ZMatrixAtom atom)
Add an atom to the ZMatrix.