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" diff --git a/src/xtal2txt/core.py b/src/xtal2txt/core.py index 84064dd..c0c924c 100644 --- a/src/xtal2txt/core.py +++ b/src/xtal2txt/core.py @@ -571,6 +571,34 @@ 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) -> 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 + 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 = [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:]] + output.extend(params) + + return " ".join(output) + + def get_all_text_reps(self, decimal_places: int = 2): """ Returns all the Text representations of the crystal structure in a dictionary. diff --git a/tests/test_get_atom_params.py b/tests/test_get_atom_params.py new file mode 100644 index 0000000..3df4857 --- /dev/null +++ b/tests/test_get_atom_params.py @@ -0,0 +1,16 @@ +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")) +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 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