From bfff09800e17d2eac9bf5ca96a3dfde92349def7 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:38:37 -0800 Subject: [PATCH 1/3] update: add make slab if not --- src/py/mat3ra/made/tools/build/slab/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/py/mat3ra/made/tools/build/slab/__init__.py b/src/py/mat3ra/made/tools/build/slab/__init__.py index e93db5e1..eac6ff44 100644 --- a/src/py/mat3ra/made/tools/build/slab/__init__.py +++ b/src/py/mat3ra/made/tools/build/slab/__init__.py @@ -14,3 +14,11 @@ def create_slab(configuration: SlabConfiguration, termination: Optional[Terminat builder = SlabBuilder() termination = termination or builder.get_terminations(configuration)[0] return builder.get_material(configuration, selector_parameters=SlabSelectorParameters(termination=termination)) + + +def create_slab_if_not(material: Material, default_slab_configuration: SlabConfiguration): + slab = material + if not slab.metadata or slab.metadata["build"]["configuration"]["type"] != SlabConfiguration.__name__: + print("The material is not a slab. Creating a new slab...") + slab = create_slab(default_slab_configuration) + return slab From b30c7393ce0b068aa902d65ad4ae7a38ff9f9f33 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:26:16 -0800 Subject: [PATCH 2/3] update: fix an error --- src/py/mat3ra/made/tools/build/passivation/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/py/mat3ra/made/tools/build/passivation/__init__.py b/src/py/mat3ra/made/tools/build/passivation/__init__.py index 0f22274b..c26e63b0 100644 --- a/src/py/mat3ra/made/tools/build/passivation/__init__.py +++ b/src/py/mat3ra/made/tools/build/passivation/__init__.py @@ -22,4 +22,4 @@ def get_unique_coordination_numbers(configuration: PassivationConfiguration) -> """ Get the unique coordination numbers for the provided configuration as a set type. """ - return CoordinationBasedPassivationBuilder().get_unique_coordination_numbers(material=configuration.material) + return CoordinationBasedPassivationBuilder().get_unique_coordination_numbers(material=configuration.slab) From c7e810ae7ead666c13c5618e7fdd74b15f8086b2 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Mon, 25 Nov 2024 19:44:10 -0800 Subject: [PATCH 3/3] chore: add docstring --- src/py/mat3ra/made/tools/build/slab/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/py/mat3ra/made/tools/build/slab/__init__.py b/src/py/mat3ra/made/tools/build/slab/__init__.py index eac6ff44..9aba3c9a 100644 --- a/src/py/mat3ra/made/tools/build/slab/__init__.py +++ b/src/py/mat3ra/made/tools/build/slab/__init__.py @@ -16,7 +16,17 @@ def create_slab(configuration: SlabConfiguration, termination: Optional[Terminat return builder.get_material(configuration, selector_parameters=SlabSelectorParameters(termination=termination)) -def create_slab_if_not(material: Material, default_slab_configuration: SlabConfiguration): +def create_slab_if_not(material: Material, default_slab_configuration: SlabConfiguration) -> Material: + """ + Create a slab from the material if it is not a slab already. Otherwise, return the material. + + Args: + material (Material): The material to be checked. + default_slab_configuration (SlabConfiguration): The default configuration to be used for creating a new slab. + + Returns: + Material: The slab. + """ slab = material if not slab.metadata or slab.metadata["build"]["configuration"]["type"] != SlabConfiguration.__name__: print("The material is not a slab. Creating a new slab...")