-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from Exabyte-io/update/SOF-7321-clean
update/SOF 7321 clean
- Loading branch information
Showing
16 changed files
with
221 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/sh | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-checkout'.\n"; exit 2; } | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } | ||
git lfs post-checkout "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/sh | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-commit'.\n"; exit 2; } | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } | ||
git lfs post-commit "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/sh | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-merge'.\n"; exit 2; } | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } | ||
git lfs post-merge "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/sh | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/pre-push'.\n"; exit 2; } | ||
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } | ||
git lfs pre-push "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
repos: | ||
- repo: https://github.com/Exabyte-io/pre-commit-hooks | ||
rev: 2023.6.28 | ||
hooks: | ||
- id: ruff | ||
exclude: ^tests/fixtures* | ||
- id: black | ||
exclude: ^tests/fixtures* | ||
- id: isort | ||
exclude: ^tests/fixtures* | ||
- id: mypy | ||
exclude: ^tests/fixtures* | ||
- id: check-yaml | ||
exclude: ^tests/fixtures* | ||
- id: end-of-file-fixer | ||
exclude: ^tests/fixtures* | ||
- id: trailing-whitespace | ||
exclude: ^tests/fixtures* | ||
- repo: local | ||
hooks: | ||
- id: lint-staged | ||
name: lint-staged | ||
language: node | ||
entry: npx lint-staged | ||
verbose: true # to see familiar lint-staged output | ||
pass_filenames: false # lint-staged has its own glob expression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +0,0 @@ | ||
import numpy as np | ||
|
||
|
||
def get_length(vec: np.ndarray) -> np.float_: | ||
return np.linalg.norm(vec) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from typing import Any, Dict, List, Union | ||
|
||
from mat3ra.code.constants import AtomicCoordinateUnits, Units | ||
from mat3ra.code.entity import HasDescriptionHasMetadataNamedDefaultableInMemoryEntity | ||
from mat3ra.esse.models.material import MaterialSchema | ||
|
||
defaultMaterialConfig = { | ||
"name": "Silicon FCC", | ||
"basis": { | ||
"elements": [ | ||
{ | ||
"id": 1, | ||
"value": "Si", | ||
}, | ||
{ | ||
"id": 2, | ||
"value": "Si", | ||
}, | ||
], | ||
"coordinates": [ | ||
{ | ||
"id": 1, | ||
"value": [0.0, 0.0, 0.0], | ||
}, | ||
{ | ||
"id": 2, | ||
"value": [0.25, 0.25, 0.25], | ||
}, | ||
], | ||
"units": AtomicCoordinateUnits.crystal, | ||
}, | ||
"lattice": { | ||
"type": "FCC", | ||
"a": 3.867, | ||
"b": 3.867, | ||
"c": 3.867, | ||
"alpha": 60, | ||
"beta": 60, | ||
"gamma": 60, | ||
"units": { | ||
"length": Units.angstrom, | ||
"angle": Units.degree, | ||
}, | ||
}, | ||
} | ||
|
||
MaterialSchemaJSON = Dict[str, Union[MaterialSchema, Any]] | ||
|
||
|
||
class Material(HasDescriptionHasMetadataNamedDefaultableInMemoryEntity): | ||
jsonSchema: MaterialSchemaJSON | ||
default_config = defaultMaterialConfig | ||
|
||
def __init__(self, config: Any) -> None: | ||
super().__init__(config) | ||
self.name = super().name or self.formula | ||
|
||
def to_json(self, exclude: List[str] = []) -> MaterialSchemaJSON: | ||
return {**super().to_json()} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import Any, Dict, Union | ||
|
||
from mat3ra.made.material import Material | ||
from pymatgen.core.structure import Lattice, Structure | ||
|
||
|
||
def to_pymatgen(material_or_material_data: Union[Material, Dict[str, Any]]) -> Structure: | ||
""" | ||
Converts material object in ESSE format to a pymatgen Structure object. | ||
Args: | ||
material_data (dict): A dictionary containing the material information in ESSE format. | ||
Returns: | ||
Structure: A pymatgen Structure object. | ||
""" | ||
material_data = material_or_material_data | ||
|
||
if isinstance(material_or_material_data, Material): | ||
material_data = material_or_material_data.to_json() | ||
|
||
lattice_params = material_data["lattice"] | ||
a = lattice_params["a"] | ||
b = lattice_params["b"] | ||
c = lattice_params["c"] | ||
alpha = lattice_params["alpha"] | ||
beta = lattice_params["beta"] | ||
gamma = lattice_params["gamma"] | ||
|
||
# Create a Lattice from parameters | ||
lattice = Lattice.from_parameters(a, b, c, alpha, beta, gamma) | ||
|
||
# Extract the basis information | ||
basis = material_data["basis"] | ||
elements = [element["value"] for element in basis["elements"]] | ||
coordinates = [coord["value"] for coord in basis["coordinates"]] | ||
|
||
# Assuming that the basis units are fractional since it's a crystal basis | ||
coords_are_cartesian = "units" in basis and basis["units"].lower() == "angstrom" | ||
|
||
# Create the Structure | ||
structure = Structure(lattice, elements, coordinates, coords_are_cartesian=coords_are_cartesian) | ||
|
||
return structure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from mat3ra.made.material import Material | ||
|
||
REFERENCE_OBJECT_1 = {"key1": "value1", "key2": "value2"} | ||
|
||
|
||
def test_create(): | ||
material = Material.create(Material.default_config) | ||
assert material.to_json() == Material.default_config | ||
assert material.name == Material.default_config["name"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from mat3ra.made.material import Material | ||
from mat3ra.made.tools.material import to_pymatgen | ||
from pymatgen.core.structure import Element, Lattice, Structure | ||
|
||
|
||
def test_to_pymatgen(): | ||
material = Material.create(Material.default_config) | ||
structure = to_pymatgen(material) | ||
assert isinstance(structure, Structure) | ||
assert structure.lattice == Lattice.from_parameters(3.867, 3.867, 3.867, 60, 60, 60) | ||
assert structure.species == [Element("Si"), Element("Si")] | ||
assert (structure.frac_coords == [[0.0, 0.0, 0.0], [0.25, 0.25, 0.25]]).all() |