File indexing completed on 2026-05-27 07:24:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 from json_schema import geometry_schema
0011 from json_schema import homogeneous_material_schema
0012 from json_schema import material_map_schema
0013 from json_schema import surface_grid_schema
0014
0015
0016 import argparse
0017 import json
0018 import os
0019 import sys
0020 from jsonschema import validate
0021
0022
0023 def __main__():
0024
0025
0026 parser = argparse.ArgumentParser(description="Detray File Validation")
0027
0028 parser.add_argument(
0029 "--geometry_file", help=("Input geometry json file."), default="", type=str
0030 )
0031 parser.add_argument(
0032 "--homogeneous_material_file",
0033 help=("Input homogeneous material json file."),
0034 default="",
0035 type=str,
0036 )
0037 parser.add_argument(
0038 "--material_map_file",
0039 help=("Input material map json file."),
0040 default="",
0041 type=str,
0042 )
0043 parser.add_argument(
0044 "--grid_file", help=("Surface grid json file."), default="", type=str
0045 )
0046
0047 args = parser.parse_args()
0048
0049
0050 filename_dict = {}
0051
0052 geo_file = args.geometry_file
0053 if geo_file != "":
0054 if not os.path.isfile(geo_file):
0055 print(f"Geometry file does not exist! ({geo_file})")
0056 sys.exit(1)
0057 else:
0058 filename_dict[geo_file] = geometry_schema
0059
0060 hom_mat_file = args.homogeneous_material_file
0061 if hom_mat_file != "":
0062 if not os.path.isfile(hom_mat_file):
0063 print(f"Homogeneous material file does not exist! ({hom_mat_file})")
0064 sys.exit(1)
0065 else:
0066 filename_dict[hom_mat_file] = homogeneous_material_schema
0067
0068 mat_map_file = args.material_map_file
0069 if mat_map_file != "":
0070 if not os.path.isfile(mat_map_file):
0071 print(f"Material map file does not exist! ({mat_map_file})")
0072 sys.exit(1)
0073 else:
0074 filename_dict[mat_map_file] = material_map_schema
0075
0076 grid_file = args.grid_file
0077 if grid_file != "":
0078 if not os.path.isfile(grid_file):
0079 print(f"Surface grid file does not exist! ({grid_file})")
0080 sys.exit(1)
0081 else:
0082 filename_dict[grid_file] = surface_grid_schema
0083
0084
0085
0086 for filename, schema in filename_dict.items():
0087 with open(filename) as file:
0088 try:
0089 input_json = json.load(file)
0090 except json.decoder.JSONDecodeError:
0091 print(f"Invalid json file: {filename}")
0092 else:
0093 validate(instance=input_json, schema=schema)
0094 print(f"{filename}: OK")
0095
0096
0097
0098
0099 if __name__ == "__main__":
0100 __main__()
0101
0102