diff --git a/tools/json/README.md b/tools/json/README.md new file mode 100644 index 0000000000..0958923246 --- /dev/null +++ b/tools/json/README.md @@ -0,0 +1,45 @@ +This folder contains files and tools for creating, modifying, and validating +files in JSON format. This is work in progress while we are adding JSON +support + +# JSON file format validation. + +## JSON-Schema files + +We provide schema files for the file formats that LAMMPS supports following +the specifications available on [JSON-Schema](https://json-schema.org) webpage. +The following files are currently available. + +- `molecule-schema.json` Schema file for the JSON format molecule files. + +These files provide a concise description of the hierarchy and supported fields +in JSON file formats. Thus they provide a detailed documentation and can also +be used for validating JSON files. + +## Validation of JSON files + +There are multiple tools for JSON file validation available. Here are instructions +for how to use a tool called `check-jsonschema` which is available via +[PyPi](https://pypi.org/). + +``` bash +# Installation into a virtual environment. +# Once installed only the activation should be needed +python3 -m venv validate-json +source validata-json/bin/activate +pip install --upgrade pip +pip install check-jsonschema + +# Validation of two molecule files "rxn1.json" and "twomols.json" with "molecule-schema.json" +check-jsonschema --schemafile molecule-schema.json rxn1.json twomols.json +``` + +If the files are conforming there should be the output: +``` +ok -- validation done +``` +Otherwise details about the non-conforming fields are given. + +------- + +updated by Axel Kohlmeyer, 2025-05-22 diff --git a/tools/json/molecule-schema.json b/tools/json/molecule-schema.json new file mode 100644 index 0000000000..b88883a46d --- /dev/null +++ b/tools/json/molecule-schema.json @@ -0,0 +1,134 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://download.lammps.org/json/molecule-schema.json", + "type": "object", + "properties": { + "application": { "enum": ["LAMMPS"]}, + "format": {"enum": ["molecule"]}, + "revision": { + "type": "integer", + "minimum": 1, + "maximum": 1 + }, + "title": {"type": "string"}, + "docs": {"type": "string"}, + "schema": {"type": "string"}, + "com": {"type": "array", + "prefixItems": [ + {"type": "number"}, + {"type": "number"}, + {"type": "number"} + ], + "items": false + }, + "masstotal": {"type": "number"}, + "body": {"type": "array", + "prefixItems": [ + {"type": "integer"}, + {"type": "integer"} + ], + "items": false + }, + "inertia": {"type": "array", + "prefixItems": [ + {"type": "number"}, + {"type": "number"}, + {"type": "number"}, + {"type": "number"}, + {"type": "number"}, + {"type": "number"} + ], + "items": false + }, + "coords": { + "type": "object", + "properties": { + "format": { + "type": "array", + "prefixItems": [ + {"enum": ["atom-id"]}, + {"enum": ["x"]}, + {"enum": ["y"]}, + {"enum": ["z"]} + ], + "items": false + }, + "data": { + "type": "array", + "items": { + "type": "array", + "prefixItems": [ + {"type": "integer"}, + {"type": "number"}, + {"type": "number"}, + {"type": "number"} + ], + "items": false + } + } + } + }, + "types": { + "type": "object", + "properties": { + "format": { + "type": "array", + "items": { + "type": "string" + } + }, + "data": { + "type": "array", + "items": { + "type": "array", + "prefixItems": [ + {"type": "number"}, + {"type": ["number", "string"]} + ], + "items": false + } + } + } + }, + "molecules": { + "type": "object", + "properties": { + "format": { + "type": "array", + "items": { + "type": "string" + } + }, + "data": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + } + } + } + }, + "charges": { + "type": "object", + "properties": { + "format": { + "type": "array", + "items": { + "type": "string" + } + }, + "data": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + } + } + } + } + } +}