diff options
Diffstat (limited to 'examples/validate_mmcif.py')
| -rwxr-xr-x | examples/validate_mmcif.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/validate_mmcif.py b/examples/validate_mmcif.py new file mode 100755 index 0000000..32a5fba --- /dev/null +++ b/examples/validate_mmcif.py @@ -0,0 +1,27 @@ +# This example demonstrates the use of the Python IHM library's validator +# to validate a user-provided input mmCIF file. +# See also validate_modbase.py for a more detailed example. + +import sys +import ihm.dictionary +import urllib.request + + +if len(sys.argv) != 2: + print("Usage: %s input.cif" % sys.argv[0], file=sys.stderr) + sys.exit(1) +fname = sys.argv[1] + +# Read in the ModelCIF and PDBx dictionary from https://mmcif.wwpdb.org/ +with urllib.request.urlopen( + 'https://mmcif.wwpdb.org/dictionaries/ascii/mmcif_ma.dic') as fh: + pdbx_mcif = ihm.dictionary.read(fh) + +# Validate the mmCIF file assuming it is UTF8 encoded. +# See validate_modbase.py for code to fallback to ASCII for non-UTF8 files. +with open(fname, encoding='UTF-8') as fh: + pdbx_mcif.validate(fh) + +# Similarly, to validate a BinaryCIF file, use: +# with open(fname, 'rb') as fh: +# pdbx_mcif.validate(fh, format='BCIF') |
