Package: mat3ra-esse
ESSEEssential Source of Schemas and Examples (ESSE) contains data format definitions (schemas) and examples for common entities used in digital materials science (see refs. [^1], [^2] below).Although the schemas are used to facilitate the operations ofmat3ra.com, they are designed to be generic and can be used in other applications. The open-source packages developed by Mat3ra.com use the schemas available in this repository.The latest variants of schemas and examples are available atschemas.mat3ra.com.ESSE has a dual-nature as both a Python and a Node.js package.1. Installation1.1. PythonESSE is compatible with Python 3.8+.1.1.1. PyPIpipinstallmat3ra-esse1.1.2. Repositoryvirtualenv.venvsource.venv/bin/activate
pipinstall-ePATH_TO_ESSE_REPOSITORY1.2. Node1.2.1. NPMnpminstall@mat3ra/esse2. UsageESSE contains separate but equivalent interfaces for Python and Javascript.
The package providesESSEclass that can be initialized and used as below.2.1. Usage in Pythonfrommat3ra.esseimportESSEhelper=ESSE()schema=helper.get_schema_by_id("material")2.2. Usage in Node/JS/TSconst{ESSE}=require("@mat3ra/esse/lib/js/esse");consthelper=newESSE();constschema=helper.getSchemaById("material");3. Directory StructureESSE contains 3 main directories,schema,exampleandsrcoutlined below.3.1. SchemaThe schema directory contains the schemas specifying the rules to structure data. A set of core schemas, outlined below, are defined to facilitate the schema modularity.Primitivedirectory contains a set of custom primitives that extends default standard primitive types allowed by schema, such as String and Number.
Primitives are solely defined by the default primitives and can not be re-constructed from each other.Abstractdirectory contains unit-less schemas that are constructed from default and custom primitives.Reusabledirectory contains the schemas that are widely used in other schemas to avoid duplication, constructed from the abstract and primitive schemas.Referencedirectory contains the schemas defining the rules to structure the references to data sources.3.2. ExampleThis directory contains the examples formed according to the schemas and implements the same directory structure as the schema directory.3.3. srcThis directory contains Python and Javascript interfaces implementing the functionality to access and validate schemas and examples.4. Conventions4.1. Generative vs Non-generative keysGenerative keys are the fields which allow for user input prior to calculation of the final property values. A flag is included in the schema comments on the fields inproperty schemas:isGenerative:truemarks which fields to use as subschemas in the generation of a user input schema. On properties allowing user inputs, additional fields may be tagged, as inthefile_contentproperty5. DevelopmentThe schemas and examples are stored as JSON assets. The JSON assets are used to generate JS/TS and PY modules that can be used to access the schemas and examples in the corresponding runtimes. The modules are generated using thebuild_schemas.pyandbuild_schema.jsscripts. The JS modules are generated during the transpilation step of the npm. The PY modules are generated during the development and distributed within the pip package.The following outlines the development process workflow:Setup: clone the repository and install the dependencies for both JS and PY (as explained below).Edit code and commit changes.Pre commit is used to regenerate the modules.Push the changes to GitHub.GH workflow is used to generate the fully resolved file (without "$ref"s and "$allOf" etc.) and examples and publish them toschemas.mat3ra.com.Publish the new version of the package to PyPI and npm.Thepre-commitis using both JS and PY runtime(s) to regenerate the schemas and examples.NOTE: The PY and JS modules are built from the same JSON sources, but using different runtimes (scripts) and thus may still be different. Only for JS the fully resolved schemas (with merged "$allOf") are created. They are used for the docs website.5.1. Development in PythonWhen developing in python the following should be taken into account:The modules containing the schemas and examples are generated using thebuild-schemas.pyscript. There is a setup for it to be run automatically on every commit, but it is recommended to run it manually before committing to make sure that the changes are reflected in the modules. This can be done withpre-commit run --all-files. The pre-commit package can be installed withpip install pre-commit. To rebuild schemas manually, run (note-ein install):virtualenv.venvsource.venv/bin/activate
pipinstall-e."[tests]"pythonbuild_schemas.pyTests can be run using the following commands:virtualenv.venvsource.venv/bin/activate
pipinstall."[tests]"python-munittestdiscover--verbose--catch--start-directorytests/py/esse/5.2. Development in Javascript/TypescriptSeepackage.jsonfor the list of available npm commands. The JS modules are generated using thebuild_schema.jsscript. There is a setup for it to be run automatically when the package is installed (see "transpile" directive). To rebuild schemas manually, run:npminstall
npmruntranspile5.3. General Dev SuggestionsThis repository is anopen-sourcework-in-progress and we welcome contributions. We suggest forking this repository and introducing the adjustments there, the changes in the fork can further be considered for merging into this repository as it is commonly done on GitHub (see [^3] below).Other suggestions:Use unique IDs for schemasDo not use circular references in the schemas, instead leave the type as object and add explanation to description.Links[^1]:Data-centric online ecosystem for digital materials science[^2]:CateCom: A Practical Data-Centric Approach to Categorization of Computational Models[^3]:GitHub Standard Fork & Pull Request Workflow