Skip to content

Commit

Permalink
update: add from dict to defect config
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Oct 14, 2024
1 parent 4b4d910 commit e040594
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/py/mat3ra/made/tools/build/defect/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e040594

Please sign in to comment.