Skip to content

Instantly share code, notes, and snippets.

@ISDementyev
Last active August 31, 2023 17:09
Show Gist options
  • Save ISDementyev/328d0f2fe9c9faa27791f4a35a26a36b to your computer and use it in GitHub Desktop.
Save ISDementyev/328d0f2fe9c9faa27791f4a35a26a36b to your computer and use it in GitHub Desktop.
Decodes and re-encodes PDBs to UTF-8
from glob import glob
def decode_encode_pdb(input_file, output_file):
with open(input_file, 'r', encoding='utf-8') as file:
lines = file.readlines()
decoded_lines = [line.encode('utf-8').decode('utf-8', 'replace') for line in lines]
with open(output_file, 'w', encoding='utf-8') as file:
file.writelines(decoded_lines)
print(f"Decoding and encoding complete. New PDB file saved as {output_file}")
if __name__ == "__main__":
pdbs = glob("*.pdb")
for pdb in pdbs:
decode_encode_pdb(pdb, pdb.split(".")[0] + "_utf.pdb")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment