Spaces:
Runtime error
Runtime error
Andrei tomut
commited on
Commit
•
c3760cf
1
Parent(s):
a0c085b
angle+
Browse files- Example_LatmatherExample.py +52 -0
- app.py +1 -1
- backend/latmathcher/pipeline.py +3 -1
- interface_connection/latmatcher_interface.py +6 -5
Example_LatmatherExample.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.environ['KMP_DUPLICATE_LIB_OK']='True'
|
3 |
+
|
4 |
+
from backend.latmathcher import PipelineLatMatch
|
5 |
+
from backend.db_utils.parse_c2db import from_c2db_structure, read_c2db_json
|
6 |
+
from backend.db_utils.utils import structure_ato_list
|
7 |
+
from backend.latmathcher.plots import plot_atom_list
|
8 |
+
from backend.latmathcher import atoms_to_greed
|
9 |
+
import matplotlib.pyplot as plt
|
10 |
+
import matplotlib.patches as patches
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
filepathA = "EXAMPLES/WSe2-1cfbe6183886.json"
|
15 |
+
filepathB = "EXAMPLES/C2-a6735a4a3797.json"
|
16 |
+
|
17 |
+
|
18 |
+
A_structure = from_c2db_structure(read_c2db_json(filepathA))
|
19 |
+
B_structure = from_c2db_structure(read_c2db_json(filepathB))
|
20 |
+
|
21 |
+
min_supercel = PipelineLatMatch(A_structure["cell"],B_structure["cell"],
|
22 |
+
Aatoms3D=structure_ato_list(A_structure),
|
23 |
+
Batoms3D=structure_ato_list(B_structure),
|
24 |
+
dim=(10, 10), optimize_angle=True, optimize_strain=True)
|
25 |
+
|
26 |
+
|
27 |
+
print(min_supercel.Alat)
|
28 |
+
print(min_supercel.Blat)
|
29 |
+
new_structure = min_supercel.get_new_structure()
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
super_xyz = structure_ato_list(new_structure)
|
34 |
+
|
35 |
+
atoms = atoms_to_greed(super_xyz, lat_v=min_supercel.sc_vec3, dim=(10,10,0))
|
36 |
+
print(atoms)
|
37 |
+
plot_atom_list(atoms, marker=".")
|
38 |
+
x = [0.0,min_supercel.sc_vec3[0][0],min_supercel.sc_vec3[0][0]+min_supercel.sc_vec3[0][1],min_supercel.sc_vec3[0][1],0.0]
|
39 |
+
y = [0.0,min_supercel.sc_vec3[1][0],min_supercel.sc_vec3[1][0]+min_supercel.sc_vec3[1][1],min_supercel.sc_vec3[1][1],0.0]
|
40 |
+
plt.gca().add_patch(patches.Polygon(xy=list(zip(x,y)), fill=True, alpha=0.4,color="green"))
|
41 |
+
plt.ylim(min(y) - 10, max(y) + 10)
|
42 |
+
plt.xlim(min(x) - 10, max(x) + 10)
|
43 |
+
|
44 |
+
super_a = [super_xyz[i] for i in range(len(new_structure["host_guest"])) if new_structure["host_guest"][i] == "host"]
|
45 |
+
super_b = [super_xyz[i] for i in range(len(new_structure["host_guest"])) if new_structure["host_guest"][i] == "guest"]
|
46 |
+
|
47 |
+
plt.show()
|
48 |
+
print(min_supercel.sc_vec)
|
49 |
+
print(min_supercel.Alat)
|
50 |
+
print(min_supercel.Blat)
|
51 |
+
print(new_structure)
|
52 |
+
plt.show()
|
app.py
CHANGED
@@ -18,7 +18,7 @@ with gr.Blocks() as latmatcher:
|
|
18 |
example_file_b = gr.File(label="example file:",value="EXAMPLES/2C-1.xyz" )
|
19 |
file_material_b = gr.File(label="material B file", )
|
20 |
|
21 |
-
max_angle = gr.Slider(0, 180, label="
|
22 |
max_strain = gr.Slider(0, 1, label=" max Strain:", step=0.05)
|
23 |
inter_distance = gr.Slider(-0.05, 10, label=" Inter-layer distance:",info="If set to -0.05 is computed automatically.", step=0.05)
|
24 |
|
|
|
18 |
example_file_b = gr.File(label="example file:",value="EXAMPLES/2C-1.xyz" )
|
19 |
file_material_b = gr.File(label="material B file", )
|
20 |
|
21 |
+
max_angle = gr.Slider(0, 180, label=" min Angle:", step=1)
|
22 |
max_strain = gr.Slider(0, 1, label=" max Strain:", step=0.05)
|
23 |
inter_distance = gr.Slider(-0.05, 10, label=" Inter-layer distance:",info="If set to -0.05 is computed automatically.", step=0.05)
|
24 |
|
backend/latmathcher/pipeline.py
CHANGED
@@ -8,7 +8,7 @@ from .latmatcher import LatMatch, SR
|
|
8 |
class PipelineLatMatch:
|
9 |
|
10 |
def __init__(self, Alat3D, Blat3D, Aatoms3D=None, Batoms3D=None, dim=10, sc_vec=None, optimize_angle=True,
|
11 |
-
optimize_strain=True, dz=4):
|
12 |
|
13 |
self.Alat3D = Alat3D
|
14 |
self.Blat3D = Blat3D
|
@@ -24,6 +24,8 @@ class PipelineLatMatch:
|
|
24 |
else:
|
25 |
self.matcher4 = LatMatch(scdim=dim, reference=self.Alat, target=self.Blat,
|
26 |
optimize_angle=optimize_angle, optimize_strain=optimize_strain)
|
|
|
|
|
27 |
self.sc_vec = self.matcher4.supercell()
|
28 |
self.rez = self.matcher4.result
|
29 |
|
|
|
8 |
class PipelineLatMatch:
|
9 |
|
10 |
def __init__(self, Alat3D, Blat3D, Aatoms3D=None, Batoms3D=None, dim=10, sc_vec=None, optimize_angle=True,
|
11 |
+
optimize_strain=True, dz=4, min_angle=5 * np.pi / 180, max_strain=0.1):
|
12 |
|
13 |
self.Alat3D = Alat3D
|
14 |
self.Blat3D = Blat3D
|
|
|
24 |
else:
|
25 |
self.matcher4 = LatMatch(scdim=dim, reference=self.Alat, target=self.Blat,
|
26 |
optimize_angle=optimize_angle, optimize_strain=optimize_strain)
|
27 |
+
self.matcher4.setMaxStrain([max_strain, max_strain])
|
28 |
+
self.matcher4.setMaxStrain(min_angle)
|
29 |
self.sc_vec = self.matcher4.supercell()
|
30 |
self.rez = self.matcher4.result
|
31 |
|
interface_connection/latmatcher_interface.py
CHANGED
@@ -82,7 +82,8 @@ def compute_supercell_a(file_material_a, file_material_b,inter_distance , max_an
|
|
82 |
B_cell=B_structure["cell"]
|
83 |
|
84 |
inter_distance=[0,0,inter_distance]
|
85 |
-
super_xyz, min_supercel, new_structure= compute_supercell(A_cell, B_cell, A_structure, B_structure, inter_distance
|
|
|
86 |
rez=min_supercel.rez
|
87 |
|
88 |
# Write the new file:
|
@@ -103,7 +104,7 @@ def compute_supercell_a(file_material_a, file_material_b,inter_distance , max_an
|
|
103 |
# Write the content to a file
|
104 |
with open(file12, 'w') as file:
|
105 |
file.write(xyz_content)
|
106 |
-
atoms= atoms_to_greed(super_xyz, lat_v=min_supercel.sc_vec3, dim=(
|
107 |
xyz_content_dd=generate_xyz_text(atoms)
|
108 |
|
109 |
plot=plot_supercel(super_xyz, min_supercel)
|
@@ -112,11 +113,11 @@ def compute_supercell_a(file_material_a, file_material_b,inter_distance , max_an
|
|
112 |
def compute_supercell_b():
|
113 |
pass
|
114 |
|
115 |
-
def compute_supercell(A_cell, B_cell,A_structure,B_structure,inter_distance ):
|
116 |
-
|
117 |
min_supercel = PipelineLatMatch(A_cell, B_cell, Aatoms3D=structure_ato_list(A_structure),
|
118 |
Batoms3D=structure_ato_list(B_structure), dim=(10, 10), optimize_angle=True,
|
119 |
-
optimize_strain=True)
|
120 |
|
121 |
new_structure = min_supercel.get_new_structure(inter_distance)
|
122 |
super_xyz = structure_ato_list(new_structure)
|
|
|
82 |
B_cell=B_structure["cell"]
|
83 |
|
84 |
inter_distance=[0,0,inter_distance]
|
85 |
+
super_xyz, min_supercel, new_structure= compute_supercell(A_cell, B_cell, A_structure, B_structure, inter_distance,
|
86 |
+
max_angle, max_strain )
|
87 |
rez=min_supercel.rez
|
88 |
|
89 |
# Write the new file:
|
|
|
104 |
# Write the content to a file
|
105 |
with open(file12, 'w') as file:
|
106 |
file.write(xyz_content)
|
107 |
+
atoms= atoms_to_greed(super_xyz, lat_v=min_supercel.sc_vec3, dim=(3,3,0))
|
108 |
xyz_content_dd=generate_xyz_text(atoms)
|
109 |
|
110 |
plot=plot_supercel(super_xyz, min_supercel)
|
|
|
113 |
def compute_supercell_b():
|
114 |
pass
|
115 |
|
116 |
+
def compute_supercell(A_cell, B_cell,A_structure,B_structure,inter_distance,min_angle, max_strain):
|
117 |
+
min_angle=min_angle/180*np.pi
|
118 |
min_supercel = PipelineLatMatch(A_cell, B_cell, Aatoms3D=structure_ato_list(A_structure),
|
119 |
Batoms3D=structure_ato_list(B_structure), dim=(10, 10), optimize_angle=True,
|
120 |
+
optimize_strain=True,min_angle=min_angle, max_strain=max_strain)
|
121 |
|
122 |
new_structure = min_supercel.get_new_structure(inter_distance)
|
123 |
super_xyz = structure_ato_list(new_structure)
|