From 1ec1a2bd8acf571af4c18309897dd4f5d2662a7c Mon Sep 17 00:00:00 2001 From: Joseph Kleinhenz Date: Wed, 21 May 2025 14:56:41 -0400 Subject: [PATCH 1/2] add test for reading from lines not padded to 80 chars --- tests/test_fastpdb.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_fastpdb.py b/tests/test_fastpdb.py index bd709c6..2a94fd1 100644 --- a/tests/test_fastpdb.py +++ b/tests/test_fastpdb.py @@ -194,4 +194,14 @@ def test_inferred_elements(tmp_path): guessed_pdb_file = fastpdb.PDBFile.read(temp) atoms_guessed_elements = guessed_pdb_file.get_structure() - assert atoms_guessed_elements.element.tolist() == atoms.element.tolist() \ No newline at end of file + assert atoms_guessed_elements.element.tolist() == atoms.element.tolist() + + +def test_non_80_char_columns(): + with open(DATA_PATH / "1l2y.pdb") as f: + lines = list(map(lambda s: s.rstrip(), f.readlines())) + + pdb_file = fastpdb.PDBFile.read(StringIO(str.join("\n", lines))) + atoms = pdb_file.get_structure() + + assert atoms is not None From b329533407e5316e63b2ea6d0275300f785ff35b Mon Sep 17 00:00:00 2001 From: Joseph Kleinhenz Date: Wed, 21 May 2025 14:58:22 -0400 Subject: [PATCH 2/2] pad to 80 characters This makes the behavior using io.StringIO match the behavior when reading from a file --- python-src/fastpdb/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-src/fastpdb/__init__.py b/python-src/fastpdb/__init__.py index 68bc1d9..4204f19 100644 --- a/python-src/fastpdb/__init__.py +++ b/python-src/fastpdb/__init__.py @@ -30,7 +30,7 @@ def read(file): else: if not is_text(file): raise TypeError("A file opened in 'text' mode is required") - pdb_file._pdb_file = RustPDBFile(file.read().splitlines()) + pdb_file._pdb_file = RustPDBFile([s.ljust(80) for s in file.read().splitlines()]) # Synchronize with PDB file representation in Rust pdb_file.lines = pdb_file._pdb_file.lines