Skip to content

Commit

Permalink
continue to fix #273 with speed up
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Aug 31, 2024
1 parent 981b785 commit 43e8565
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
34 changes: 28 additions & 6 deletions pyxtal/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,24 @@ def get_min_supergroup(self, group_type="t", G=None):
msg = "Only supports the supergroups for space group"
raise NotImplementedError(msg)

@classmethod
def _get_max_subgroup_numbers(cls, number, max_cell=9):
"""
Returns the minimal supergroups as a dictionary
"""
groups = []
sub_k = Group._get_max_k_subgroup(number)
sub_t = Group._get_max_t_subgroup(number)
k = sub_k["subgroup"]
t = sub_t["subgroup"]
for i, n in enumerate(t):
if np.linalg.det(sub_t["transformation"][i][:3, :3]) <= max_cell:
groups.append(n)
for i, n in enumerate(k):
if np.linalg.det(sub_k["transformation"][i][:3, :3]) <= max_cell:
groups.append(n)
return groups

def get_max_subgroup_numbers(self, max_cell=9):
"""
Returns the minimal supergroups as a dictionary
Expand Down Expand Up @@ -1550,8 +1568,8 @@ def search_supergroup_paths(self, H, max_layer=5):
groups = []
subgroups = []
for g in previous_layer_groups:
subgroup_numbers = np.unique(
Group(g, quick=True).get_max_subgroup_numbers())
#subgroup_numbers = np.unique(Group(g, quick=True).get_max_subgroup_numbers())
subgroup_numbers = np.unique(Group._get_max_subgroup_numbers(g))

# If a subgroup list has been found with H
# trace a path through the dictionary to build the path
Expand Down Expand Up @@ -1605,6 +1623,7 @@ def search_supergroup_paths(self, H, max_layer=5):
# path_list.append((g_type, id, p))
# g0 = g1
# return path_list

def path_to_subgroup(self, H):
"""
For a given a path, extract the
Expand Down Expand Up @@ -1693,7 +1712,6 @@ def path_to_general_wp(self, index=1, max_steps=1):
Find the path to transform the special wp into general site
Args:
group: Group object
index: the index of starting wp
max_steps: the number of steps to search
Expand Down Expand Up @@ -1748,11 +1766,11 @@ def path_to_general_wp(self, index=1, max_steps=1):
[
deepcopy(p)[1:]
for p in potential
if (len(set(p[-1][3])) == 1 and p[-1][3][0][-1] == Group(p[-1][2])[0].letter)
if (len(set(p[-1][3])) == 1 and p[-1][3][0][-1] == Wyckoff_position.from_group_and_index(p[-1][2], 0).letter)
]
)
potential = [
p for p in potential if not (len(set(p[-1][3])) == 1 and p[-1][3][0][-1] == Group(p[-1][2])[0].letter)
p for p in potential if not (len(set(p[-1][3])) == 1 and p[-1][3][0][-1] == Wyckoff_position.from_group_and_index(p[-1][2], 0).letter)
]

return solutions
Expand Down Expand Up @@ -2325,7 +2343,11 @@ def transform_from_matrix(self, trans=None, reset=True, update=False):
trans = np.array([[1, 0, 1], [0, 1, 0], [1, 0, 1]])

if 2 < self.number < 16:
ops = Group(self.number)[self.index] if reset else self.ops
#ops = Group(self.number)[self.index] if reset else self.ops
if reset:
ops = Wyckoff_position.from_group_and_index(self.number, self.index)
else:
ops = self.ops

for j, op in enumerate(ops):
vec = op.translation_vector.dot(trans)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,10 @@ def test_get_wyckoff_position_from_xyz(self):
else:
assert wp.get_label() == wp0

def test_short_path_to_general_wp():
data = [('t', 0, 141, ['16h']), ('t', 6, 122, ['16e'])]
G = Group(227)
assert G.short_path_to_general_wp(4) == data

if __name__ == "__main__":
unittest.main()
24 changes: 24 additions & 0 deletions tests/test_mem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import psutil
import os

def print_memory_usage():
process = psutil.Process(os.getpid())
mem_info = process.memory_info()
print(f"Memory usage: {mem_info.rss / 1024 ** 2:.2f} MB") # RSS is the Resident Set Size

if __name__ == "__main__":
print_memory_usage()
from pyxtal.symmetry import Group
print_memory_usage()
g = Group(4, quick=True)
print_memory_usage()
g = Group(227)
print_memory_usage()

from pyxtal import pyxtal
xtal = pyxtal()
xtal.from_spg_wps_rep(194, ['2c', '2b'], [2.46, 6.70])
print_memory_usage()

xtal.subgroup_once()
print_memory_usage()

0 comments on commit 43e8565

Please sign in to comment.