ihmwg / python-ihm

Python package for handling IHM mmCIF and BinaryCIF files
MIT License
14 stars 7 forks source link

Validation does not work for BinaryCIF files #66

Closed benmwebb closed 2 years ago

benmwebb commented 2 years ago

Validation fails for BinaryCIF when trying to check any integer field (e.g. an ordinal ID) against the dictionary's regular expression:

Traceback (most recent call last):
  File "/Users/ben/python-ihm/validate-modbase.py", line 13, in <module>
    pdbx_ma.validate(fh, format='BCIF')
  File "/Users/ben/python-ihm/ihm/dictionary.py", line 214, in validate
    while r.read_file():
  File "/Users/ben/python-ihm/ihm/format_bcif.py", line 219, in read_file
    self._handle_category(handler, category, cat_name)
  File "/Users/ben/python-ihm/ihm/format_bcif.py", line 253, in _handle_category
    handler(*row_data)
  File "/Users/ben/python-ihm/ihm/dictionary.py", line 75, in __call__
    self.sysr.validate_data(self.category_obj, self._keys, args,
  File "/Users/ben/python-ihm/ihm/dictionary.py", line 114, in validate_data
    if kwobj.item_type and not kwobj.item_type.regex.match(value):
TypeError: expected string or bytes-like object

This is because value for mmCIF files is always a Python string, but for BinaryCIF it could also be a Python int or float.

Simplest solution would be to coerce all values to str before checking against the regex.