Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dpti/lib/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
26 changes: 26 additions & 0 deletions tests/test_dump.py
Original file line number Diff line number Diff line change
@@ -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()
Loading