Commit 35d283cf authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Fixed issues with 2D material hashes.

parent ee66ea18
Pipeline #78669 passed with stages
in 46 minutes and 8 seconds
......@@ -75,7 +75,7 @@ def find_match(pos: np.array, positions: np.array, eps: float) -> Union[int, Non
return None
def get_symmetry_string(space_group: int, wyckoff_sets: List[WyckoffSet]) -> str:
def get_symmetry_string(space_group: int, wyckoff_sets: List[WyckoffSet], is_2d: bool = False) -> str:
"""Used to serialize symmetry information into a string. The Wyckoff
positions are assumed to be normalized and ordered as is the case if using
the matid-library.
......@@ -84,6 +84,9 @@ def get_symmetry_string(space_group: int, wyckoff_sets: List[WyckoffSet]) -> str
space_group: 3D space group number
wyckoff_sets: Wyckoff sets that map a Wyckoff letter to related
information
is_2d: Whether the symmetry information is analyzed from a 2D
structure. If true, a prefix is added to the string to distinguish
2D from 3D.
Returns:
A string that encodes the symmetry properties of an atomistic
......@@ -97,7 +100,10 @@ def get_symmetry_string(space_group: int, wyckoff_sets: List[WyckoffSet]) -> str
i_string = "{} {} {}".format(element, wyckoff_letter, n_atoms)
wyckoff_strings.append(i_string)
wyckoff_string = ", ".join(sorted(wyckoff_strings))
string = "{} {}".format(space_group, wyckoff_string)
if is_2d:
string = "2D {} {}".format(space_group, wyckoff_string)
else:
string = "{} {}".format(space_group, wyckoff_string)
return string
......
......@@ -427,7 +427,7 @@ class Material2DNormalizer(MaterialNormalizer):
# is treated as a 3D structure. Due to this the hash may overlap with
# real 3D structures unless we include a distinguishing label for 2D
# structures in the hash seed.
norm_hash_string = "2D " + atomutils.get_symmetry_string(spg_number, wyckoff_sets)
norm_hash_string = atomutils.get_symmetry_string(spg_number, wyckoff_sets, is_2d=True)
material.material_id = hash(norm_hash_string)
def lattice_vectors(self, ideal: IdealizedStructure, std_atoms: Atoms) -> None:
......
......@@ -197,7 +197,7 @@ def test_2d_material_identification():
indices=[0, 1]
)]
space_group_number = 191
norm_hash_string = atomutils.get_symmetry_string(space_group_number, wyckoff_sets)
norm_hash_string = atomutils.get_symmetry_string(space_group_number, wyckoff_sets, is_2d=True)
graphene_material_id = hash(norm_hash_string)
# Graphene orthogonal cell
......@@ -285,7 +285,7 @@ def test_2d_material_identification():
)
]
space_group_number = 11
norm_hash_string = atomutils.get_symmetry_string(space_group_number, wyckoff_sets)
norm_hash_string = atomutils.get_symmetry_string(space_group_number, wyckoff_sets, is_2d=True)
mos2_material_id = hash(norm_hash_string)
# MoS2 orthogonal cell
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment