From e0405948edeae1a4eaf565ea8598f90ac3b04b42 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Sun, 13 Oct 2024 18:16:08 -0700 Subject: [PATCH] update: add from dict to defect config --- .../mat3ra/made/tools/build/defect/configuration.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/py/mat3ra/made/tools/build/defect/configuration.py b/src/py/mat3ra/made/tools/build/defect/configuration.py index 43e49f25..6a2dbb98 100644 --- a/src/py/mat3ra/made/tools/build/defect/configuration.py +++ b/src/py/mat3ra/made/tools/build/defect/configuration.py @@ -68,6 +68,18 @@ def from_approximate_position( crystal=crystal, defect_type=defect_type, site_id=closest_site_id, chemical_element=chemical_element ) + @classmethod + def from_dict(cls, crystal: Material, data: dict): + if "site_id" in data: + config = PointDefectConfiguration.from_site_id(crystal=crystal, **data) + elif "coordinate" in data: + config = PointDefectConfiguration(crystal=crystal, **data) + elif "approximate_coordinate" in data: + config = PointDefectConfiguration.from_approximate_position(crystal=crystal, **data) + else: + raise ValueError(f"Invalid defect configuration: {data}") + return config + @property def _json(self): return {