Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float columns in PDBFile.set_structure() are not bounded #559

Closed
padix-key opened this issue May 10, 2024 · 0 comments · Fixed by #588
Closed

Float columns in PDBFile.set_structure() are not bounded #559

padix-key opened this issue May 10, 2024 · 0 comments · Fixed by #588
Labels

Comments

@padix-key
Copy link
Member

Currently PDBFile.set_structure() does not restrict the upper bound of float values in the atom annotations (e.g. coordinates). However the fixed columns in PDB only allow for a certain value range: For example the value 10000 does not fit into a 4 character string.

Attempting to write such high values would currently lead to a shift in all following columns.
Hence, the created PDB file becomes invalid.
To fix this, the function should raise an exception if setting such an AtomArray is attempted.

Example:

import biotite.structure.io.pdb as pdb
import biotite.structure as struc


atoms = struc.AtomArray(10)
# Keep the first five ATOM records correct for comparison
atoms.coord[:5] = 100
atoms.coord[5:] = 1000000
pdb_file = pdb.PDBFile()
pdb_file.set_structure(atoms)
print(pdb_file)

Output:

ATOM      1             0      100.000 100.000 100.000  1.00  0.00              
ATOM      2             0      100.000 100.000 100.000  1.00  0.00              
ATOM      3             0      100.000 100.000 100.000  1.00  0.00              
ATOM      4             0      100.000 100.000 100.000  1.00  0.00              
ATOM      5             0      100.000 100.000 100.000  1.00  0.00              
ATOM      6             0     1000000.0001000000.0001000000.000  1.00  0.00              
ATOM      7             0     1000000.0001000000.0001000000.000  1.00  0.00              
ATOM      8             0     1000000.0001000000.0001000000.000  1.00  0.00              
ATOM      9             0     1000000.0001000000.0001000000.000  1.00  0.00              
ATOM     10             0     1000000.0001000000.0001000000.000  1.00  0.00

This affects the following atom annotations:

  • coord
  • b_factor
  • occupancy

Note that negative value allow one numeric character less due to the added '-' character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant