From 4fb3cf6ec91217576b6bcc6b069ad86cca4a353d Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Thu, 14 Dec 2023 13:04:33 -0800 Subject: [PATCH] Give an example for generating ASCII outputs Show how to use standard Python functionality to generate output that is ASCII or ISO-8859-1 rather than UTF-8. Closes #131. --- ihm/dumper.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ihm/dumper.py b/ihm/dumper.py index a79628f..a3f297c 100644 --- a/ihm/dumper.py +++ b/ihm/dumper.py @@ -3649,6 +3649,15 @@ def write(fh, systems, format='mmCIF', dumpers=[], variant=IHMVariant): with open('output.bcif', 'wb') as fh: ihm.dumper.write(fh, systems, format='BCIF') + If generating files for a tool that is sensitive to non-ASCII data, + a more restrictive encoding such as ASCII or ISO-8859-1 could also + be used (although note that this may lose some information such as + accented characters):: + + with open('output.cif', 'w', encoding='ascii', + errors='replace') as fh: + ihm.dumper.write(fh, systems) + :param file fh: The file handle to write to. :param list systems: The list of :class:`ihm.System` objects to write. :param str format: The format of the file. This can be 'mmCIF' (the