Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/qzhu2017/PyXtal
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhu2017 committed Dec 7, 2024
2 parents a239934 + 4684ca2 commit dadac4e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
8 changes: 5 additions & 3 deletions pyxtal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ def _from_pymatgen(self, struc, tol=1e-3, a_tol=5.0, style="pyxtal", hn=None):
specie = site[0].specie.number
# if wp.index>0: print(wp)
pos1 = wp.search_generator(pos, self.group[0], tol=tol)
# print(pos, pos1, self.group[0])
if pos1 is not None:
atom_sites.append(atom_site(wp, pos1, specie))
else:
Expand All @@ -530,9 +529,12 @@ def _from_pymatgen(self, struc, tol=1e-3, a_tol=5.0, style="pyxtal", hn=None):
raise RuntimeError(
"Cannot extract the right mapping from spglib")
# break
else:
atom_sites.append(atom_site(wp, pos1, specie))
#print(pos, pos1, self.group[0])

# if len(atom_sites) != len(sym_struc.equivalent_sites):
# else:
if len(atom_sites) != len(sym_struc.equivalent_sites):
raise RuntimeError("Fail to extract the atom site")
self.atom_sites = atom_sites
# import pymatgen.analysis.structure_matcher as sm
# self.dim = 3
Expand Down
8 changes: 5 additions & 3 deletions pyxtal/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,8 @@ def __init__(self, op, parse_trans=False, hexagonal=False):
self.axis = rotvec / self.angle
if self.hexagonal:
# print('convert hex', self.axis, np.dot(self.axis, hex_cell))
self.axis = np.dot(self.axis, hex_cell)
if np.linalg.norm(self.axis - np.array([1, 0, 0])) > 1e-4:
self.axis = np.dot(self.axis, hex_cell)
# parse symmetry direction
if self.parse_trans and not self.parse_axis():
self.axis *= -1
Expand Down Expand Up @@ -758,8 +759,9 @@ def __init__(self, op, parse_trans=False, hexagonal=False):
self.angle = np.linalg.norm(rotvec)
self.axis = rotvec / self.angle
if self.hexagonal:
# print('convert hex', self.axis, np.dot(self.axis, hex_cell))
self.axis = np.dot(self.axis, hex_cell)
if np.linalg.norm(self.axis - np.array([1, 0, 0])) > 1e-4:
# print('convert hex', self.axis, np.dot(self.axis, hex_cell))
self.axis = np.dot(self.axis, hex_cell)
if np.isclose(self.angle, 0):
self.symbol = "-1"
self.type = "inversion"
Expand Down
8 changes: 5 additions & 3 deletions pyxtal/optimize/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ def handler(signum, frame):
#logger.info(f"Rank-{args[-2]} after signal")

try:
logger.info(f"Rank-{args[-2]} running optimizer_par for PID {os.getpid()}")
if args[-2] > 0:
logger.info(f"Rank-{args[-2]} running optimizer_par for PID {os.getpid()}")
result = optimizer_par(*args[:-2])
logger.info(f"Rank-{args[-2]} finished optimizer_par for PID {os.getpid()}")
if args[-2] > 0:
logger.info(f"Rank-{args[-2]} finished optimizer_par for PID {os.getpid()}")
signal.alarm(0) # Disable the alarm
return result
except TimeoutError:
Expand Down Expand Up @@ -291,7 +293,7 @@ def __init__(
self.early_quit = early_quit
self.N_min_matches = 10 # The min_num_matches for early termination
self.E_max = E_max
self.tag = tag
self.tag = tag.lower()
self.suffix = f"{self.workdir:s}/{self.name:s}-{self.ff_style:s}"
if self.rank == 0:
if cif is None:
Expand Down
12 changes: 8 additions & 4 deletions pyxtal/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2414,7 +2414,7 @@ def get_site_symm_wo_translation(self):
return [SymmOp.from_rotation_and_translation(op.rotation_matrix, [0, 0, 0]) for op in self.symmetry[0]]

def get_site_symmetry_object(self, idx=0):
ops = self.get_site_symm_ops(idx)
ops = self.get_site_symm_ops(idx)#; print(self.number, self.index, self.letter)
return site_symmetry(ops, self.lattice_type, self.symbol[0])

def get_site_symmetry(self, idx=0):
Expand Down Expand Up @@ -3835,9 +3835,13 @@ def get_highest_symmetry(self, row):
for i, ref_array in enumerate(ref_arrays):
if np.array_equal(row, ref_array[0]):
return ref_array[1], i
symbols = ["1", "-1", "2", "m", "3", "4", "-4", "-3", "6", "-6"]
strs = [symbols[i] for i, x in enumerate(row) if x == 1]
raise ValueError("Incompatible symmetry list", strs)

if self.lattice_type not in ["hexagonal", "trigonal"]:
symbols = ["1", "-1", "2", "m", "3", "4", "-4", "-3", "6", "-6"]
strs = [symbols[i] for i, x in enumerate(row) if x == 1]
print(row)
#raise ValueError("Incompatible symmetry list", strs)
return ref_arrays[0][1], 0


def organized_wyckoffs(group):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def test_print_group_and_dof(self):
assert dof == dof_ref

def test_get_spg_symmetry_object(self):
spg_list = [14, 36, 62, 99, 143, 160, 182, 191, 225, 230]
ans = [32, 18, 36, 21, 16, 19, 24, 48, 62, 62]
spg_list = [14, 36, 62, 99, 143, 160, 225, 230] #182, 191,
ans = [32, 18, 36, 21, 16, 19, 62, 62] # 24, 48
for spg, num in zip(spg_list, ans):
g = Group(spg)
ss = g.get_spg_symmetry_object()
Expand Down
12 changes: 11 additions & 1 deletion tests/test_wyckoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,25 @@ def test_wp_check_translation(self):
def test_wp_site_symm(self):
data = [
(143, 1, "3.."),
(150, 1, ".2."),
(152, 1, ".2."),
(154, 1, ".2."),
(155, 1, ".2"),
(160, 1, ".m"),
(160, 2, "3m"),
(164, 4, ".2/m."),
(165, 1, ".2."),
(177, 3, ".2."),
(178, 2, ".2."),
(180, 3, ".2."),
(181, 3, ".2."),
(230, 6, ".32"),
]
for d in data:
(sg, i, symbol) = d
wp = Group(sg)[i]
wp.get_site_symmetry()
# print("\n========", wp.site_symm, symbol, "==========\n")
if wp.site_symm != symbol: print("\n========", wp.site_symm, d, "==========\n")
assert wp.site_symm == symbol

def test_wp_dof(self):
Expand Down

0 comments on commit dadac4e

Please sign in to comment.