Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atom param rep #29

Merged
merged 9 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 28 additions & 0 deletions src/xtal2txt/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions tests/test_get_atom_params.py
Original file line number Diff line number Diff line change
@@ -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
Loading