Skip to content

Commit 9d1a872

Browse files
committed
enable get subgroup_comp function
1 parent 833af52 commit 9d1a872

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

pyxtal/symmetry.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,58 @@ def get_spg_representation(self):
521521
one_hot: a (15, 26) numpy (0, 1) array
522522
"""
523523
return self.lattice_id, self.get_spg_symmetry_object().to_one_hot()
524+
525+
def get_subgroup_composition(self, ids=None, g_types=['t', 'k'], max_atoms=100,
526+
verbose=False):
527+
"""
528+
Get the composition of the subgroup Wyckoff positions.
529+
530+
Args:
531+
ids (list, optional): List of Wyckoff position indices.
532+
verbose (bool): Whether to print debug information.
533+
g_types (list): List of subgroup types to consider ('t' for translationengleiche, 'k' for klassengleiche).
534+
max_atoms (int): Maximum number of atoms to consider for subgroup search.
535+
536+
Returns:
537+
list: List of multiplicities of the Wyckoff positions.
538+
"""
539+
if verbose:
540+
strs = f"{self.number} ({self.symbol}): "
541+
for id in ids:
542+
wp = self[id]
543+
strs += f"{wp.multiplicity}{wp.letter}"
544+
print(strs)
545+
sub_symmetries = []
546+
N_atoms = sum([self[id].multiplicity for id in ids])
547+
548+
for g_type in g_types:
549+
if g_type == 't':
550+
sub = self.get_max_t_subgroup()
551+
else:
552+
sub = self.get_max_k_subgroup()
553+
554+
for i, sub_g in enumerate(sub['subgroup']):
555+
if N_atoms * sub['index'][i] > max_atoms:
556+
continue
557+
sub_gg = Group(sub_g)
558+
relation = sub['relations'][i]#; print(relation)
559+
sub_ids = []
560+
for id in ids:
561+
true_id = len(self)-id-1
562+
relation[true_id].sort()
563+
for r in relation[true_id]:
564+
letter = r[-1]#; print("test letter:", relation[true_id])
565+
sub_ids.append(len(sub_gg) - letters.index(letter) - 1)
566+
data = (sub_g, sub_ids)
567+
if data not in sub_symmetries:
568+
sub_symmetries.append(data)
569+
if verbose:
570+
strs = f"{sub_gg.number} ({sub_gg.symbol}): "
571+
for id in sub_ids:
572+
wp = sub_gg[id]
573+
strs += f"{wp.multiplicity}{wp.letter} "
574+
print(strs, data)
575+
return sub_symmetries
524576

525577
def get_lattice_id(self):
526578
"""

tests/test_group.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ def test_check_compatible(self):
8585
assert Group(221).check_compatible([15, 16, 17, 21]) == (True, True)
8686
assert Group(221).check_compatible([15, 16, 2, 2]) == (False, False)
8787

88+
def test_subgroup_composition(self):
89+
g = Group(154)
90+
comps = g.get_subgroup_composition([2, 0], g_types=["t", "k"])
91+
assert comps[0] == (5, [2, 0, 0, 0, 0])
92+
assert comps[1] == (145, [0, 0, 0])
93+
assert comps[2] == (152, [0, 0, 0])
94+
assert comps[3] == (152, [2, 1, 0, 0])
95+
assert len(comps) == 8
8896

8997
def test_search_supergroup_paths(self):
9098
paths = Group(59, quick=True).search_supergroup_paths(139, 2)

0 commit comments

Comments
 (0)