You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing a PDB file with B-factor values above 999, you will end up getting an invalid length B-factor value in the PDB. This is not a common occurence, however, with the rise of people using B-factor fields for other values - typically from computational tools, it is a real problem.
The issue arrises from the format string in Bio.PDB.PDBIO:
Particularly, the %6.2f format code for the B-factor. This ensures that the minimum string length is 6 characters, not the maximum. For cases where the B-factor is above 999, you will have additional characters.
I have verified this in python3.10.12, and according to PEP3101:
Therefore, I propose that when a B-factor value is over 999, we set the precision to 1, and when over 9999 we emit a warning. For normal cases this will have no effect as it is very rare to have B-factor values in such a range.
The 6.2f format actually comes from the PDB format itself (see here). Instead of changing the PDBWriter to accommodate a 'non-standard' format, I'd recommend you write the structures as mmCIF if you have such b-factors, since there you don't have any limitation on sizes. Would that work for your use case?
That spec gives it as a fixed width, whereas in python 6.2f only sets a min. The current implementation will create invalid PDBs. I don't see a reason to not implement this change.
I am doing this on behalf of someone else, who has insisted that they must use PDBs - I have already suggested they us mmCIFs - for exactly this reason.
As an alternative, I think it would be at least worth making biopython emit a warning if this happens, even if we don't clip the precision. I think the user should be made aware that they have violated the PDB standard, rather than it doing it quietly and you only know later when you use an ancient piece of software that only works with PDBs.
Oh I see what you mean, you mean when we have a number like 999999, you get two added decimal places and that breaks the format. Got it, I didn't understand it from your first message. Let me comment on your review then!
Activity
JoaoRodrigues commentedon Aug 28, 2025
Hi @OWissett,
The
6.2fformat actually comes from the PDB format itself (see here). Instead of changing the PDBWriter to accommodate a 'non-standard' format, I'd recommend you write the structures as mmCIF if you have such b-factors, since there you don't have any limitation on sizes. Would that work for your use case?OWissett commentedon Aug 28, 2025
That spec gives it as a fixed width, whereas in python 6.2f only sets a min. The current implementation will create invalid PDBs. I don't see a reason to not implement this change.
I am doing this on behalf of someone else, who has insisted that they must use PDBs - I have already suggested they us mmCIFs - for exactly this reason.
As an alternative, I think it would be at least worth making biopython emit a warning if this happens, even if we don't clip the precision. I think the user should be made aware that they have violated the PDB standard, rather than it doing it quietly and you only know later when you use an ancient piece of software that only works with PDBs.
JoaoRodrigues commentedon Aug 29, 2025
Oh I see what you mean, you mean when we have a number like
999999, you get two added decimal places and that breaks the format. Got it, I didn't understand it from your first message. Let me comment on your review then!OWissett commentedon Aug 29, 2025
Awesome thanks! Sorry if I wasn't clear enough in the original issue.