diff --git a/validation/test-suite.py b/validation/test-suite.py index a45bfae201994a5e88bd22e39404c91ec3627eb1..2b67f4b3923dd77708e275f2d017c7a13c9f9ebd 100644 --- a/validation/test-suite.py +++ b/validation/test-suite.py @@ -355,8 +355,8 @@ def _main(): + '"atom_site"', ], }, - # duplicated item in _loop category # missing category (entity) + # duplicated item in _loop category # parent-child relationship issue (remove an atom_type.symbol) } diff --git a/validation/validate-mmcif-file.py b/validation/validate-mmcif-file.py index a23472a97008620806600fe2f2749756f65b3637..9fe748e52b4d1bf61d374638b92b43bccfc1bfa8 100755 --- a/validation/validate-mmcif-file.py +++ b/validation/validate-mmcif-file.py @@ -57,14 +57,24 @@ def _parse_command_line(): + "external files attached.", default=None, ) - parser.add_argument( + dic_grp = parser.add_mutually_exclusive_group() + dic_grp.add_argument( "--dict-sdb", "-d", type=str, metavar="<SDB FILE>", - help="The dictionary in SDB format used for checking.", + help="The dictionary in SDB format used for checking. Can't be " + + "combined with --modelcif-mode/-m and --pdbx-mmcif-mode/-p.", default="/usr/local/share/mmcif-dict-suite/mmcif_ma.sdb", ) + dic_grp.add_argument( + "--pdbx-mmcif-mode", + "-p", + action="store_true", + help="Check with the PDBX/mmCIF dictionary, for verbatim mmCIF files. " + + "Can't be combined with --dict-sdb/-d and --modelcif-mode/-m. " + + "Default is to check with the ModelCIF dictionary.", + ) parser.add_argument( "--out-file", "-o", @@ -106,6 +116,8 @@ def _parse_command_line(): if opts.extend_validated_file is not None: if opts.extend_validated_file == " same ": opts.extend_validated_file = opts.model_cif + if opts.pdbx_mmcif_mode is True: + opts.dict_sdb = "/usr/local/share/mmcif-dict-suite/mmcif_pdbx_v50.sdb" return opts @@ -135,42 +147,23 @@ def _parse_cifcheck_stderr(stderr): return error_lst -def _parse_parser_file(filename): - """Parse the parser output file of CifCheck.""" - parserfile = filename + "-parser.log" - if not os.path.exists(parserfile): - return [] - - error_lst = [] - with open(parserfile, encoding="utf-8") as dfh: - for line in dfh: - line = line.strip() - error_lst.append(line) - - # remove the diag file - os.unlink(parserfile) - - return error_lst - - -def _parse_diag_file(filename): +def _get_cifcheck_out(filename, suffix, encoding): """Parse the diagnosis file of CifCheck.""" # CifCheck places the diag file in the current working directory. - diagfile = filename + "-diag.log" - if not os.path.exists(diagfile): + cifcheck = filename + suffix + if not os.path.exists(cifcheck): return [] error_lst = [] # CifCheck outputs diag files as iso-8859 - with open(diagfile, encoding="iso-8859-1") as dfh: + with open(cifcheck, encoding=encoding) as dfh: for line in dfh: line = line.strip() if line == "": continue error_lst.append(line) - # remove the diag file - os.unlink(diagfile) + os.unlink(cifcheck) return error_lst @@ -592,12 +585,14 @@ class _CifCheck: error_lst = [] # get error messages on the command line error_lst.extend(_parse_cifcheck_stderr(cps.stderr)) - error_lst.extend(_parse_parser_file(filepath)) + error_lst.extend(_get_cifcheck_out(filepath, "-parser.log", "utf-8")) if len(error_lst) > 0: raise _CifCheckFailedError(cifcheck_cmd, error_lst) # get messages from diagnosis file - error_lst.extend(_parse_diag_file(filepath)) + error_lst.extend( + _get_cifcheck_out(filepath, "-diag.log", "iso-8859-1") + ) return error_lst