Skip to content
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

create a hcp mg grain boundary mgΣ7[0001](0001) too many values to unpack (expected 3) #3733

Closed
TongaoY opened this issue Apr 2, 2024 · 2 comments
Labels

Comments

@TongaoY
Copy link

TongaoY commented Apr 2, 2024

Python version

Python3.10

Pymatgen version

2024.3.1

Operating system version

ubuntu22.04-py310-torch2.1.2-tf2.14.0-1.13.1

Current behavior

from pymatgen.core import Structure, Element
from pymatgen.analysis.gb.grain import GrainBoundary, GrainBoundaryGenerator

angle = GrainBoundaryGenerator.get_rotation_angle_from_sigma(7,[0,0,0,1], lat_type='H',ratio=None)
struc = Structure.from_file("mg.cif")
generator = GrainBoundaryGenerator(struc)
gb = generator.gb_from_parameters(
rotation_axis=[0,0,0,1],
rotation_angle=angle[0],
expand_times=8,
vacuum_thickness=0.0,
plane=None,
)
gb.to(filename="Mg_GB.cif")


ValueError Traceback (most recent call last)
Cell In[19], line 10
8 generator = GrainBoundaryGenerator(struc)
9 #gb = generator.gb_from_parameters([0,0,0,1],angle[0], plane = None, expand_times=8, vacuum_thickness=0.0)
---> 10 gb = generator.gb_from_parameters(
11 rotation_axis=[0,0,0,1], # 旋转轴向量,应为长度为3的列表
12 rotation_angle=angle[0], # 旋转角度,假设 angle 已经定义并包含所需角度
13 expand_times=8, # 扩展次数
14 vacuum_thickness=0.0, # 真空厚度
15 plane=None, # 平面信息
16 )
17 gb.to(filename="Mg_GB.cif")

File /opt/conda/lib/python3.10/site-packages/pymatgen/analysis/gb/grain.py:567, in GrainBoundaryGenerator.gb_from_parameters(self, rotation_axis, rotation_angle, expand_times, vacuum_thickness, ab_shift, normal, ratio, plane, max_search, tol_coi, rm_ratio, quick_gen)
564 index = reduce(gcd, plane)
565 plane = [int(round(x / index)) for x in plane]
--> 567 t1, t2 = self.get_trans_mat(
568 r_axis=rotation_axis,
569 angle=rotation_angle,
570 normal=normal,
571 trans_cry=trans_cry,
572 lat_type=lat_type,
573 ratio=ratio,
574 surface=plane,
575 max_search=max_search,
576 quick_gen=quick_gen,
577 )
579 # find the join_plane
580 if lat_type.lower() != "c":

File /opt/conda/lib/python3.10/site-packages/pymatgen/analysis/gb/grain.py:1110, in GrainBoundaryGenerator.get_trans_mat(r_axis, angle, normal, trans_cry, lat_type, ratio, surface, max_search, quick_gen)
1108 r_matrix = (np.array(r_list) / com_fac / sigma).reshape(3, 3)
1109 else:
-> 1110 u, v, w = r_axis
1111 if lat_type.lower() == "c":
1112 mu = 1

ValueError: too many values to unpack (expected 3)

Expected Behavior

generate gbs

Minimal example

No response

Relevant files to reproduce this bug

No response

@TongaoY TongaoY added the bug label Apr 2, 2024
@shyuep
Copy link
Member

shyuep commented Apr 2, 2024

You need to use the 3-integer specification of the rotation axis. Not 4. In hexagonal structures, one of the indices (the third) is redundant.

@shyuep shyuep closed this as completed Apr 2, 2024
@TongaoY
Copy link
Author

TongaoY commented Apr 2, 2024

You need to use the 3-integer specification of the rotation axis. Not 4. In hexagonal structures, one of the indices (the third) is redundant.
when I change code as you say:
from pymatgen.core import Structure, Element
from pymatgen.analysis.gb.grain import GrainBoundary, GrainBoundaryGenerator
#找到给定西格玛值的所有可能的旋转角度。
angle = GrainBoundaryGenerator.get_rotation_angle_from_sigma(7, [0, 0, 0, 1], lat_type='h')

struc = Structure.from_file("mg.cif")
generator = GrainBoundaryGenerator(struc)
gb = generator.gb_from_parameters(
[0,0,1],angle[0],
expand_times=4,
vacuum_thickness=1.0,
plane=None
)

gb.to(filename="Mg_GB.cif")

It turns a new wrong:

RuntimeError Traceback (most recent call last)
Cell In[4], line 8
6 struc = Structure.from_file("mg.cif")
7 generator = GrainBoundaryGenerator(struc)
----> 8 gb = generator.gb_from_parameters(
9 [0,0,1],21.79,
10 expand_times=4,
11 vacuum_thickness=1.0,
12 plane=None
13 )
14 #gb = generator.gb_from_parameters([[1, 0, -1, 0], rotation_angle,angle[0],plane=[1,-2,1,4] , expand_times=4,vacuum_thickness=1.0)
15 gb.to(filename="Mg_GB.cif")

File /opt/conda/lib/python3.10/site-packages/pymatgen/analysis/gb/grain.py:567, in GrainBoundaryGenerator.gb_from_parameters(self, rotation_axis, rotation_angle, expand_times, vacuum_thickness, ab_shift, normal, ratio, plane, max_search, tol_coi, rm_ratio, quick_gen)
564 index = reduce(gcd, plane)
565 plane = [int(round(x / index)) for x in plane]
--> 567 t1, t2 = self.get_trans_mat(
568 r_axis=rotation_axis,
569 angle=rotation_angle,
570 normal=normal,
571 trans_cry=trans_cry,
572 lat_type=lat_type,
573 ratio=ratio,
574 surface=plane,
575 max_search=max_search,
576 quick_gen=quick_gen,
577 )
579 # find the join_plane
580 if lat_type.lower() != "c":

File /opt/conda/lib/python3.10/site-packages/pymatgen/analysis/gb/grain.py:1202, in GrainBoundaryGenerator.get_trans_mat(r_axis, angle, normal, trans_cry, lat_type, ratio, surface, max_search, quick_gen)
1199 r_matrix = (np.array(r_list) / com_fac / sigma).reshape(3, 3)
1201 if sigma > 1000:
-> 1202 raise RuntimeError("Sigma >1000 too large. Are you sure what you are doing, Please check the GB if exist")
1203 # transform surface, r_axis, r_matrix in terms of primitive lattice
1204 surface = np.matmul(surface, np.transpose(trans_cry))

RuntimeError: Sigma >1000 too large. Are you sure what you are doing, Please check the GB if exist

But
image
exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants