Skip to content

Commit aee752f

Browse files
committed
Fix leaking of wrapped coordinates when writing PDB file
1 parent 78da2ea commit aee752f

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fix leaking of wrapped coordinates when writing PDB file.
13+
14+
1015
## [0.2.1] - 2024-10-08
1116

12-
## Fixed
17+
### Fixed
1318

1419
- Fix bug in `PairwiseForceField` class: use `rmax` only, never `rcut`.
1520
- Fix version import.
@@ -18,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1823

1924
## [0.2.0] - 2024-10-07
2025

21-
## Changed
26+
### Changed
2227

2328
- Add mandatory `rcut` option to `build_random_cell`.
2429

src/tinyff/trajectory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _dump_low(self, fh: TextIO, atpos: ArrayLike, cell_lengths: ArrayLike):
9797
atpos = parse_atpos(atpos, len(self.atnums))
9898
cell_lengths = parse_cell_lengths(cell_lengths)
9999
# Wrap atoms in cell for nicer visual
100-
atpos -= np.floor(atpos / cell_lengths) * cell_lengths
100+
atpos = atpos - np.floor(atpos / cell_lengths) * cell_lengths
101101
# Actual writing
102102
a, b, c = cell_lengths * self.to_angstrom
103103
print(f"CRYST1{a:9.3f}{b:9.3f}{c:9.3f} 90.00 90.00 90.00 P 1 1", file=fh)

tests/test_trajectory.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ def test_pdb_writer_stride(tmpdir):
7979
assert fh.read().count("CRYST1") == 3
8080

8181

82+
def test_pdb_writer_no_modify(tmpdir):
83+
cell_length = 3.0
84+
atpos0 = np.array([[0.0, 2.0, 0.5], [1.0, 3.3, 2.44], [-1.0, 2.8, 1.7]])
85+
atpos1 = atpos0.copy()
86+
path_pdb = os.path.join(tmpdir, "test.pdb")
87+
pdb_writer = PDBWriter(path_pdb, to_angstrom=10.0, atnums=[18] * len(atpos0))
88+
pdb_writer.dump(atpos0, cell_length)
89+
assert atpos0 == pytest.approx(atpos1)
90+
91+
8292
PDB_REF_SINGLE = """\
8393
CRYST1 10.000 10.000 10.000 90.00 90.00 90.00 P 1 1
8494
HETATM 1 Ar ATM 1 3.000 4.000 5.000 1.00 1.00 Ar

0 commit comments

Comments
 (0)