Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add python model classes generation #311

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ then
npm run transpile-and-build-assets
fi

if -d .venv/bin/activate
then
echo "Python virtual environment not found. Running build scripts."
echo "Re-building JS and PY assets using JS script."
source .venv/bin/activate
# Note: resolved (no include statements) schemas have to exist by this time
datamodel-codegen --input ./dist/js/schema/ --input-file-type jsonschema --output ./dist/py --class-name ESSE --output-model-type pydantic_v2.BaseModel --use-field-description --use-double-quotes --enable-version-header --disable-timestamp --use-title-as-nam
else
echo "Python virtual environment found. Create one in '.venv'."
exit 1
fi

npx lint-staged --allow-empty

npm run lint:fix
Expand Down
4 changes: 1 addition & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ repos:
name: Regenerate data modules classes from static assets
# yamllint disable rule:line-length
entry: |
bash -c 'if ! [ "$(git diff --cached --name-only | grep -e "example|schema")" ]; then echo "Skipping model generation because static files were not changed."; exit 0; fi'
bash -c 'python build_schemas.py'
# yamllint enable rule:line-length
bash -c 'datamodel-codegen --input ./dist/js/schema/ --input-file-type jsonschema --output ./dist/py --class-name ESSE --output-model-type pydantic_v2.BaseModel --use-field-description --use-double-quotes --enable-version-header --disable-timestamp --use-title-as-nam'
language: system
pass_filenames: false
verbose: true
3 changes: 3 additions & 0 deletions dist/py/3pse/db/nist_jarvis/2024.3.13/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# generated by datamodel-codegen:
# filename: 3pse/db/nist_jarvis/2024.3.13/atoms.json
# version: 0.25.5

from __future__ import annotations

from typing import List, Optional

from pydantic import BaseModel, ConfigDict, Field

from ........ import ArrayOf3NumberElementsSchema


class ComArticlesDatasetMonolayerDataForHeterostructure22344571(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
lattice_mat: Optional[List[ArrayOf3NumberElementsSchema]] = Field(None, max_length=3, min_length=3)
"""
Crystal lattice vectors as a 3x3 matrix, in Angstroms
"""
coords: Optional[List[ArrayOf3NumberElementsSchema]] = Field(None, min_length=1)
"""
Atomic coordinates for each atom in the unit cell
"""
elements: Optional[List[str]] = Field(None, min_length=1)
"""
Atomic elements for each atom in the unit cell in the same order as `coords`
"""
abc: Optional[List[float]] = Field(None, max_length=3, min_length=3, title="array of 3 number elements schema")
angles: Optional[List[float]] = Field(None, max_length=3, min_length=3, title="array of 3 number elements schema")
cartesian: Optional[bool] = None
"""
True if the coordinates are in Cartesian space, false if in fractional space
"""
props: Optional[List[str]] = None
"""
Additional properties for each of the atoms
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
13 changes: 13 additions & 0 deletions dist/py/3pse/db/nist_jarvis/2024.3.13/atoms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# generated by datamodel-codegen:
# filename: 3pse/db/nist_jarvis/2024.3.13/atoms.json
# version: 0.25.5

from __future__ import annotations

from typing import Any, List

from pydantic import Field, RootModel


class ArrayOf3NumberElementsSchema(RootModel[List[Any]]):
root: List[Any] = Field(..., title="array of 3 number elements schema")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# generated by datamodel-codegen:
# filename: 3pse/db/nist_jarvis/2024.3.13/db_entry.json
# version: 0.25.5

from __future__ import annotations

from typing import List, Optional

from pydantic import BaseModel, ConfigDict, Field

from ........ import ArrayOf3NumberElementsSchema


class ComArticlesDatasetMonolayerDataForHeterostructure22344571(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
lattice_mat: Optional[List[ArrayOf3NumberElementsSchema]] = Field(None, max_length=3, min_length=3)
"""
Crystal lattice vectors as a 3x3 matrix, in Angstroms
"""
coords: Optional[List[ArrayOf3NumberElementsSchema]] = Field(None, min_length=1)
"""
Atomic coordinates for each atom in the unit cell
"""
elements: Optional[List[str]] = Field(None, min_length=1)
"""
Atomic elements for each atom in the unit cell in the same order as `coords`
"""
abc: Optional[List[float]] = Field(None, max_length=3, min_length=3, title="array of 3 number elements schema")
angles: Optional[List[float]] = Field(None, max_length=3, min_length=3, title="array of 3 number elements schema")
cartesian: Optional[bool] = None
"""
True if the coordinates are in Cartesian space, false if in fractional space
"""
props: Optional[List[str]] = None
"""
Additional properties for each of the atoms
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# generated by datamodel-codegen:
# filename: 3pse/db/nist_jarvis/2024.3.13/db_entry.json
# version: 0.25.5

from __future__ import annotations

from typing import Optional

from pydantic import BaseModel, ConfigDict, Field

from ..field_db_entry__atoms__key_schema import field_Based_on_https___figshare


class ComArticlesDatasetMonolayerDataForHeterostructure22344571(BaseModel):
model_config = ConfigDict(
extra="allow",
)
atoms: Optional[field_Based_on_https___figshare.ComArticlesDatasetMonolayerDataForHeterostructure22344571] = Field(
None,
title="NIST J.A.R.V.I.S. db entry `atoms` key schema. Based on https://figshare.com/articles/dataset/Monolayer_data_for_heterostructure/22344571",
)
jid: Optional[str] = None
"""
The id of the entry in the database, e.g. JVASP-677
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5

from __future__ import annotations
13 changes: 13 additions & 0 deletions dist/py/3pse/db/nist_jarvis/2024.3.13/db_entry/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# generated by datamodel-codegen:
# filename: 3pse/db/nist_jarvis/2024.3.13/db_entry.json
# version: 0.25.5

from __future__ import annotations

from typing import Any, List

from pydantic import Field, RootModel


class ArrayOf3NumberElementsSchema(RootModel[List[Any]]):
root: List[Any] = Field(..., title="array of 3 number elements schema")
3 changes: 3 additions & 0 deletions dist/py/3pse/file/applications/espresso/7.2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# generated by datamodel-codegen:
# filename: schema
# version: 0.25.5
Loading
Loading