-
Notifications
You must be signed in to change notification settings - Fork 61
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
Cannot extract the right mapping from spglib #228
Comments
I suppose that there maybe some error in _from_pymatgen #if wp.index>0: print(wp)
pos1 = wp.search_generator(pos, self.group[0], tol=tol)
if pos1 is not None:
atom_sites.append(atom_site(wp, pos1, specie))
else:
break the way we choose representation location in an orbital may be wrong |
I have written a snippet of code to transform the parent crystal to a derivative crystal according to transformation matrix, I choose another way to select the representative site in one orbital def transform_crystal_ugly_way(parent_crystal, Pmat, subgroup_num):
Rns = get_R_in_P(Pmat)
cry_ase = parent_crystal.to_ase()
# get all scaled position in supercell, first 3 rows of site_mat are positions, the last row is element number
site_mat = np.zeros((4, len(cry_ase.symbols.numbers) * Rns.shape[1]))
for i in range(Rns.shape[1]):
site_mat[
:3,
i * len(cry_ase.symbols.numbers) : (i + 1) * len(cry_ase.symbols.numbers),
] = (
cry_ase.get_scaled_positions().T
+ np.tile(Rns[:, i], (len(cry_ase.symbols.numbers), 1)).T
)
site_mat[
-1,
i * len(cry_ase.symbols.numbers) : (i + 1) * len(cry_ase.symbols.numbers),
] = cry_ase.symbols.numbers
site_mat[:3, :] = np.linalg.inv(Pmat[:3, :3]) @ (
site_mat[:3, :] - np.tile(Pmat[:3, -1], (site_mat.shape[1], 1)).T
)
site_mat[:3, :] = rescale_zero_one(site_mat[:3, :])
_, index = np.unique(site_mat.round(decimals=5), axis=1, return_index=True)
site_mat = site_mat[:, index]
# split all sites into several orbitals, through the orbital labels are not known at the moment
equivalent = [-1] * site_mat.shape[1]
for i in range(site_mat.shape[1]):
if equivalent[i] != -1:
continue
else:
other_site_on_orb = [
rescale_zero_one(op.operate(site_mat[:3, i]))
for op in Group(subgroup_num).wyckoffs[0]
]
# any symm operation can only translate one site to places on the orbitals it belongs to
# so we set the sites that could be related by symm ops with the mark(!=-1)
for j in range(len(other_site_on_orb)):
diff = (
site_mat[:3, :]
- np.tile(other_site_on_orb[j], (site_mat.shape[1], 1)).T
)
equivalent[np.argmin(np.sum(np.abs(diff), axis=0))] = i
equivalent = np.array(equivalent)
# set correct orbital label
site_dict = {}
for i in set(equivalent):
site_dict[i] = [site_mat[:, equivalent == i]]
for wyckoff in Group(subgroup_num).Wyckoff_positions:
for site_index_on_orb in range(site_dict[i][0].shape[1]):
# so, why there is a loop over sites on each orbital?
# Group(49).Wyckoff_positions[1]
"""
Wyckoff position 4q in space group 49 with site symmetry ..m
x, y, 0
-x, -y, 0
-x, y, 1/2
x, -y, 1/2
"""
# Group(49).Wyckoff_positions[1].ops
"""
[Rot:
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 0.]]
tau[0. 0. 0.],
Rot:
[[-1. 0. 0.]
[ 0. -1. 0.]
[ 0. 0. 0.]]
tau
[0. 0. 0.],
Rot:
[[-1. 0. 0.]
[ 0. 1. 0.]
[ 0. 0. 0.]]
tau
[0. 0. 0.5],
Rot:
[[ 1. 0. 0.]
[ 0. -1. 0.]
[ 0. 0. 0.]]
tau
[0. 0. 0.5]]
"""
# say you have
# (0.3,0.4,0),(0.7,0.6,0),(0.7,0.4,0.5),(0.3,0.6,0.5)
# and you start with (0.7,0.4,0.5)
# you will get
# (0.7,0.4,0.0),(0.3,0.6,0.0),(0.7,0.4,0.5),(0.7,0.6,0.5)
# which is not the same orb
other_site_on_orb = [
rescale_zero_one(op.operate(site_dict[i][0][:3, site_index_on_orb]))
for op in wyckoff.ops
]
other_site_on_orb = np.array(other_site_on_orb).T
true_label, _ = test_if_2_array_column_wise_same(
other_site_on_orb, site_dict[i][0][:3, :]
)
# translate ith site to sites using ops of chosen wyckoff position
if true_label:
site_dict[i].extend(
[str(wyckoff.multiplicity) + wyckoff.letter, site_index_on_orb]
)
break
site_dict = dict(sorted(site_dict.items(), key=lambda x: -x[1][0][-1, 0]))
# sort sites according to element number
new_cry = pyxtal()
# new_cry.build(
# group=subgroup_num,
# species=[
# Element(int(item[0][-1, 0])).short_name for item in site_dict.values()
# ],
# numIons=[int(item[1][:-1]) for item in site_dict.values()],
# lattice=Lattice.from_matrix(
# np.dot(Pmat[:3, :3].T, cry_ase.cell.array),
# ltype=Group(subgroup_num).lattice_type,
# ),
# sites=[{item[1]: item[0][:3, item[2]]} for item in site_dict.values()],
# )
new_cry.build(
group=subgroup_num,
species=[
Element(int(item[0][-1, 0])).short_name for item in site_dict.values()
],
numIons=[int(item[1][:-1]) for item in site_dict.values()],
lattice=Lattice.from_matrix(
np.dot(Pmat[:3, :3].T, cry_ase.cell.array),
ltype=Group(subgroup_num).lattice_type,
),
sites=[[{item[1]: item[0][:3, item[2]]}] for item in site_dict.values()],
)
return new_cry |
One more failed example
|
@XinYu73 This issue should have been fixed if you update the code. Let me know if you have any problem. |
the poscar
I run
and I got following error
but findsym gives the result
The text was updated successfully, but these errors were encountered: