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] 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