Skip to content

Commit

Permalink
update: reuse placement method key for multiple defects
Browse files Browse the repository at this point in the history
  • Loading branch information
VsevolodX committed Jan 1, 2025
1 parent d789d20 commit e429974
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/py/mat3ra/made/tools/build/defect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
from .factories import DefectBuilderFactory


def create_defect(
configuration: Union[PointDefectConfiguration, AdatomSlabPointDefectConfiguration],
builder_parameters: Union[PointDefectBuilderParameters, SlabDefectBuilderParameters, None] = None,
) -> Material:
def get_material_with_defect(configuration, builder_parameters):
"""
Return a material with a selected defect added.
Expand All @@ -38,6 +35,23 @@ def create_defect(
return builder.get_material(configuration) if builder else configuration.crystal


def create_defect(
configuration: Union[PointDefectConfiguration, AdatomSlabPointDefectConfiguration],
builder_parameters: Union[PointDefectBuilderParameters, SlabDefectBuilderParameters, None] = None,
) -> Material:
"""
Return a material with a selected defect added.
Args:
configuration: The configuration of the defect to be added.
builder_parameters: The parameters to be used by the defect builder.
Returns:
The material with the defect added.
"""
return get_material_with_defect(configuration, builder_parameters)


def create_defects(
configurations: Union[List[PointDefectConfiguration], List[AdatomSlabPointDefectConfiguration]],
builder_parameters: Union[PointDefectBuilderParameters, SlabDefectBuilderParameters, None] = None,
Expand All @@ -57,10 +71,7 @@ def create_defects(
for configuration in configurations:
if material_with_defect:
configuration.crystal = material_with_defect

BuilderClass = DefectBuilderFactory.get_class_by_name(configuration.defect_type)
builder = BuilderClass(builder_parameters)
material_with_defect = builder.get_material(configuration) if builder else configuration.crystal
material_with_defect = get_material_with_defect(configuration, builder_parameters)

return material_with_defect

Expand Down

0 comments on commit e429974

Please sign in to comment.