diff --git a/dpti/lib/dump.py b/dpti/lib/dump.py index 68c9940..55d4759 100644 --- a/dpti/lib/dump.py +++ b/dpti/lib/dump.py @@ -82,14 +82,18 @@ def get_posi(lines): def get_dumpbox(lines): + """Return LAMMPS dump bounds and optional triclinic tilt factors.""" blk, h = _get_block(lines, "BOX BOUNDS") bounds = np.zeros([3, 2]) tilt = np.zeros([3]) for dd in range(3): info = [float(jj) for jj in blk[dd].split()] + if len(info) < 2: + raise ValueError("each BOX BOUNDS line must contain lower and upper bounds") bounds[dd][0] = info[0] bounds[dd][1] = info[1] - tilt[dd] = info[2] + if len(info) >= 3: + tilt[dd] = info[2] return bounds, tilt diff --git a/tests/test_dump.py b/tests/test_dump.py new file mode 100644 index 0000000..e3c53d7 --- /dev/null +++ b/tests/test_dump.py @@ -0,0 +1,26 @@ +import unittest + +import numpy as np + +from dpti.lib.dump import get_dumpbox + + +class TestDumpBox(unittest.TestCase): + def test_orthogonal_box_defaults_to_zero_tilt(self): + """Standard two-column BOX BOUNDS lines describe an orthogonal box.""" + lines = [ + "ITEM: BOX BOUNDS pp pp pp", + "0 10", + "-1 9", + "2 12", + "ITEM: ATOMS id type x y z", + ] + + bounds, tilt = get_dumpbox(lines) + + np.testing.assert_allclose(bounds, [[0, 10], [-1, 9], [2, 12]]) + np.testing.assert_allclose(tilt, [0, 0, 0]) + + +if __name__ == "__main__": + unittest.main()