Skip to content

Commit f11d0c4

Browse files
committed
Wrap atoms in box in PDB output
1 parent e52212b commit f11d0c4

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
### Changed
1616

1717
- By default, run only 100 optimization steps in `build_random_cell`.
18+
- Wrap atoms back into the cell when writing PDB trajectory files, for nicer visual.
19+
1820

1921
## [0.0.0] - 2024-10-06
2022

src/tinyff/trajectory.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,12 @@ def dump_single(self, path_pdb: str, atpos: ArrayLike, cell_lengths: ArrayLike):
9393
self._dump_low(fh, atpos, cell_lengths)
9494

9595
def _dump_low(self, fh: TextIO, atpos: ArrayLike, cell_lengths: ArrayLike):
96+
# Process arguments
9697
atpos = parse_atpos(atpos, len(self.atnums))
9798
cell_lengths = parse_cell_lengths(cell_lengths)
99+
# Wrap atoms in cell for nicer visual
100+
atpos -= np.floor(atpos / cell_lengths) * cell_lengths
101+
# Actual writing
98102
a, b, c = cell_lengths * self.to_angstrom
99103
print(f"CRYST1{a:9.3f}{b:9.3f}{c:9.3f} 90.00 90.00 90.00 P 1 1", file=fh)
100104
for i, (x, y, z) in enumerate(atpos * self.to_angstrom):

tests/test_trajectory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
PDB_REF_DATA = """\
2929
CRYST1 30.000 30.000 30.000 90.00 90.00 90.00 P 1 1
3030
HETATM 1 Ar ATM 1 0.000 20.000 5.000 1.00 1.00 Ar
31-
HETATM 2 Ar ATM 1 10.000 33.000 24.400 1.00 1.00 Ar
32-
HETATM 3 Ar ATM 1 -10.000 28.000 17.000 1.00 1.00 Ar
31+
HETATM 2 Ar ATM 1 10.000 3.000 24.400 1.00 1.00 Ar
32+
HETATM 3 Ar ATM 1 20.000 28.000 17.000 1.00 1.00 Ar
3333
END
3434
CRYST1 30.000 30.000 30.000 90.00 90.00 90.00 P 1 1
3535
HETATM 1 Ar ATM 1 0.100 20.300 0.000 1.00 1.00 Ar
36-
HETATM 2 Ar ATM 1 12.000 30.500 32.100 1.00 1.00 Ar
37-
HETATM 3 Ar ATM 1 -10.300 35.800 20.300 1.00 1.00 Ar
36+
HETATM 2 Ar ATM 1 12.000 0.500 2.100 1.00 1.00 Ar
37+
HETATM 3 Ar ATM 1 19.700 5.800 20.300 1.00 1.00 Ar
3838
END
3939
"""
4040

0 commit comments

Comments
 (0)