From eeac1376f0ab4504c65641cdafe535f98363ba4a Mon Sep 17 00:00:00 2001 From: "[RezaAliakbari]" Date: Sun, 3 Mar 2024 22:54:49 +0100 Subject: [PATCH 1/7] chore: add atom_params rep to core.py --- src/xtal2txt/core.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/xtal2txt/core.py b/src/xtal2txt/core.py index 4ad4f99..21281ec 100644 --- a/src/xtal2txt/core.py +++ b/src/xtal2txt/core.py @@ -239,6 +239,39 @@ def get_robocrys_rep(self): def get_wycryst(): pass + + def get_atom_params(self, lattice_params: bool = False, decimal_places: int = 2): + """ + Generating a string with the elements of composition inside the crystal lattice with the option to... + get the lattice parameters as angles (int) and lengths (float) in a string with a space... + between them + + Params: + lattice_params: boolean, optional + To specify whether use lattice parameters in generating crystal structure. + Defaults to False + decimal_places : int, optional, + to specify the rounding digit for float numbers. + Defaults to 2 + + Returns: + output: str + An oneline string. + """ + + output = "" + for site in self.structure.sites: + output += site.specie.element.symbol + " " + + if lattice_params: + params = self.get_lattice_parameters(decimal_places=decimal_places) + params[3:] = [str(int(float(i))) for i in params[3:]] + for i in [3, 4, 5, 0, 1, 2]: + output += params[i] + " " + + return output[:-1] + + def get_all_text_reps(self, decimal_places: int = 2): """ Returns all the Text representations of the crystal structure in a dictionary. From daca3fc0ddb8e41c820511a7d2c1bfad70747d42 Mon Sep 17 00:00:00 2001 From: "[RezaAliakbari]" Date: Sun, 3 Mar 2024 22:58:25 +0100 Subject: [PATCH 2/7] chore: add test for atom_params rep --- tests/test_get_atom_params.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/test_get_atom_params.py diff --git a/tests/test_get_atom_params.py b/tests/test_get_atom_params.py new file mode 100644 index 0000000..b8b9273 --- /dev/null +++ b/tests/test_get_atom_params.py @@ -0,0 +1,13 @@ +from xtal2txt.core import TextRep +import os + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + +srtio3_p1 = TextRep.from_input(os.path.join(THIS_DIR, "data", "SrTiO3_p1.cif")) + + +def test_get_atom_params() -> None: + expected_wo_params = "Sr Ti O O O" + expected_w_params = "Sr Ti O O O 90 90 90 3.91 3.91 3.91" + assert srtio3_p1.get_atom_params() == expected_wo_params + assert srtio3_p1.get_atom_params(lattice_params=True) == expected_w_params \ No newline at end of file From d234008c8a445fb026c2e3aaddfe557fd750b729 Mon Sep 17 00:00:00 2001 From: Reza Aliakbari <144531635+r3zak@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:06:54 +0100 Subject: [PATCH 3/7] Update core.py --- src/xtal2txt/core.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/xtal2txt/core.py b/src/xtal2txt/core.py index 21281ec..f5f6150 100644 --- a/src/xtal2txt/core.py +++ b/src/xtal2txt/core.py @@ -236,9 +236,6 @@ def get_robocrys_rep(self): condensed_structure = condenser.condense_structure(self.structure) return describer.describe(condensed_structure) - def get_wycryst(): - pass - def get_atom_params(self, lattice_params: bool = False, decimal_places: int = 2): """ From 06eeb1ceec8a0359116068b161621e7469abd4dd Mon Sep 17 00:00:00 2001 From: n0w0f Date: Fri, 22 Mar 2024 11:31:02 +0100 Subject: [PATCH 4/7] chore: update dependency --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 274831a..b7efae1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ dependencies = [ "transformers>=4.37.2", "pyshtools==4.10", "pyxtal==0.5.7", + "keras==2.15.0" ] requires-python = ">=3.9,<3.11" readme = "README.md" From 597966d876a4de40f8d4e09c6dae41b0dfe076eb Mon Sep 17 00:00:00 2001 From: n0w0f Date: Fri, 22 Mar 2024 12:13:32 +0100 Subject: [PATCH 5/7] test: update unit test --- tests/test_get_atom_params.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_get_atom_params.py b/tests/test_get_atom_params.py index b8b9273..3df4857 100644 --- a/tests/test_get_atom_params.py +++ b/tests/test_get_atom_params.py @@ -4,10 +4,13 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) srtio3_p1 = TextRep.from_input(os.path.join(THIS_DIR, "data", "SrTiO3_p1.cif")) +tiCrSe_p1 = TextRep.from_input(os.path.join(THIS_DIR, "data", "TlCr5Se8_p1.cif")) def test_get_atom_params() -> None: expected_wo_params = "Sr Ti O O O" - expected_w_params = "Sr Ti O O O 90 90 90 3.91 3.91 3.91" - assert srtio3_p1.get_atom_params() == expected_wo_params - assert srtio3_p1.get_atom_params(lattice_params=True) == expected_w_params \ No newline at end of file + expected_w_params = "Sr Ti O O O 3.91 3.91 3.91 90 90 90" + expected_tiCrSe_p1 = "Tl Tl Cr Cr Cr Cr Cr Cr Cr Cr Cr Cr Se Se Se Se Se Se Se Se Se Se Se Se Se Se Se Se" + assert srtio3_p1.get_atoms_params_rep() == expected_wo_params + assert tiCrSe_p1.get_atoms_params_rep() == expected_tiCrSe_p1 + assert srtio3_p1.get_atoms_params_rep(lattice_params=True) == expected_w_params \ No newline at end of file From 664931a702d66c166ef0c5c36d71b12969012c9c Mon Sep 17 00:00:00 2001 From: n0w0f Date: Fri, 22 Mar 2024 12:14:27 +0100 Subject: [PATCH 6/7] chore: refactor --- src/xtal2txt/core.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/xtal2txt/core.py b/src/xtal2txt/core.py index 5c198eb..2e4b51e 100644 --- a/src/xtal2txt/core.py +++ b/src/xtal2txt/core.py @@ -571,10 +571,10 @@ def cif_string_matcher_sym(self, input: str, ltol = 0.2, stol = 0.5, angle_tol = return StructureMatcher(ltol, stol, angle_tol, primitive_cell, scale, allow_subset, attempt_supercell).fit(output_struct, original_struct) - def get_atom_params(self, lattice_params: bool = False, decimal_places: int = 2): + def get_atoms_params_rep(self, lattice_params: bool = False, decimal_places: int = 2): """ - Generating a string with the elements of composition inside the crystal lattice with the option to... - get the lattice parameters as angles (int) and lengths (float) in a string with a space... + Generating a string with the elements of composition inside the crystal lattice with the option to + get the lattice parameters as angles (int) and lengths (float) in a string with a space between them Params: @@ -590,17 +590,13 @@ def get_atom_params(self, lattice_params: bool = False, decimal_places: int = 2) An oneline string. """ - output = "" - for site in self.structure.sites: - output += site.specie.element.symbol + " " - + output = [site.specie.element.symbol for site in self.structure.sites] if lattice_params: params = self.get_lattice_parameters(decimal_places=decimal_places) params[3:] = [str(int(float(i))) for i in params[3:]] - for i in [3, 4, 5, 0, 1, 2]: - output += params[i] + " " + output.extend(params) - return output[:-1] + return " ".join(output) def get_all_text_reps(self, decimal_places: int = 2): From 20fd5256b997d80c5feab99ba491027e892eeec7 Mon Sep 17 00:00:00 2001 From: n0w0f Date: Fri, 22 Mar 2024 12:18:10 +0100 Subject: [PATCH 7/7] chore: refactor --- src/xtal2txt/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xtal2txt/core.py b/src/xtal2txt/core.py index 2e4b51e..c0c924c 100644 --- a/src/xtal2txt/core.py +++ b/src/xtal2txt/core.py @@ -571,7 +571,7 @@ def cif_string_matcher_sym(self, input: str, ltol = 0.2, stol = 0.5, angle_tol = return StructureMatcher(ltol, stol, angle_tol, primitive_cell, scale, allow_subset, attempt_supercell).fit(output_struct, original_struct) - def get_atoms_params_rep(self, lattice_params: bool = False, decimal_places: int = 2): + def get_atoms_params_rep(self, lattice_params: bool = False, decimal_places: int = 2) -> str: """ Generating a string with the elements of composition inside the crystal lattice with the option to get the lattice parameters as angles (int) and lengths (float) in a string with a space