AndreiVoicuT commited on
Commit
eeecfa5
1 Parent(s): b74fcc2

Delete interface_connection

Browse files
interface_connection/__init__.py DELETED
@@ -1,3 +0,0 @@
1
-
2
- from .latmatcher_interface import compute_supercell, compute_supercell_a, compute_supercell_b
3
- from .gpaw_interface import gpaw_calc_energy
 
 
 
 
interface_connection/__pycache__/__init__.cpython-310.pyc DELETED
Binary file (354 Bytes)
 
interface_connection/__pycache__/__init__.cpython-311.pyc DELETED
Binary file (341 Bytes)
 
interface_connection/__pycache__/gpaw_interface.cpython-310.pyc DELETED
Binary file (1.53 kB)
 
interface_connection/__pycache__/latmatcher_interface.cpython-310.pyc DELETED
Binary file (5.66 kB)
 
interface_connection/__pycache__/latmatcher_interface.cpython-311.pyc DELETED
Binary file (10.5 kB)
 
interface_connection/gpaw_interface.py DELETED
@@ -1,66 +0,0 @@
1
- from gpaw import GPAW
2
- import periodictable
3
- from .latmatcher_interface import extract_from_xyz, process_file, extract_from_bespoke
4
- from backend.soft_gpaw.experiment import bespoke_structure_to_ase
5
-
6
-
7
- def get_atomic_number(element_name):
8
- # Find the element
9
- element = getattr(periodictable, element_name, None)
10
-
11
- # Check if the element exists
12
- if element is not None and hasattr(element, 'number'):
13
- return element.number
14
- else:
15
- return "Element not found"
16
-
17
-
18
- def gpaw_calc_energy(file_gpaw_format,
19
- file_gpaw,
20
- convergence_forces,
21
- hund,
22
- xc, basis,
23
- beta, method,
24
- weight, backend,
25
- ecut, mode_name,
26
- maxiter, kpts,
27
- log_file_name, mail):
28
- path_to_move = "/Users/voicutomut/Documents/GitHub/BespokeMaterials/DB/OnlineGPAW"
29
- # https://wiki.fysik.dtu.dk/gpaw/documentation/basic.html
30
-
31
- # TODO: ad proper kpts:
32
- kpts = None
33
- mode = {"name": mode_name,
34
- "ecut": ecut}
35
- mixer = {"beta": beta, "method": method,
36
- "weight": weight, "backend": backend}
37
- poissonsolver = {}#{'dipolelayer': 'xy',}
38
-
39
- log_file_name = path_to_move + "/{}".format(log_file_name)
40
- calc = GPAW(mode=mode,
41
- xc=xc,
42
- basis=basis,
43
- convergence={'forces': convergence_forces},
44
- poissonsolver=poissonsolver,
45
- hund=hund,
46
- mixer=mixer,
47
- maxiter=maxiter,
48
- txt=log_file_name,
49
-
50
- )
51
-
52
- file1 = process_file(file_gpaw, path_to_move + "/")
53
- if file_gpaw_format == ".xyz":
54
- structure = extract_from_xyz(file1)
55
- elif file_gpaw_format == "bespoke.json":
56
- structure = extract_from_bespoke(file1)
57
-
58
- print("structure:", structure)
59
- lattice = bespoke_structure_to_ase(b_structure=structure)
60
- print("lattice", lattice)
61
-
62
- lattice.calc = calc
63
-
64
- energy = lattice.get_potential_energy()
65
-
66
- return energy
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
interface_connection/latmatcher_interface.py DELETED
@@ -1,191 +0,0 @@
1
-
2
-
3
- from backend.latmathcher.plots import plot_atom_list
4
- from backend.latmathcher import atoms_to_greed
5
- from backend.latmathcher import PipelineLatMatch
6
- from backend.db_utils.utils import structure_ato_list
7
- from backend.db_utils.parse_c2db import from_c2db_structure, read_c2db_json
8
- from backend.db_utils.structure_database import DBInstance
9
-
10
-
11
- import matplotlib.pyplot as plt
12
- import matplotlib.patches as patches
13
- import os
14
- import shutil
15
- import numpy as np
16
- import periodictable
17
- import ast
18
-
19
- def get_atomic_number(element_symbol):
20
- # Find the element in the periodic table and return its atomic number
21
- element = getattr(periodictable, element_symbol)
22
- return element.number
23
-
24
-
25
- def compute_supercell_a(file_material_a, file_material_b, file_source_a, file_source_b, max_angle, max_strain):
26
-
27
-
28
- #
29
- ip = "test_ip" # get_client_ip(response)
30
-
31
- db_latmatcher_path = "/Users/voicutomut/Documents/GitHub/BespokeMaterials/DB/LatMatcher"
32
- new_directory = db_latmatcher_path + "/{}__ma{}__ms{}_on{}".format(ip, max_angle, max_strain,
33
- len(os.listdir(db_latmatcher_path)))
34
- if not os.path.exists(new_directory):
35
- os.makedirs(new_directory)
36
- path_to_move = new_directory
37
-
38
- file1 = process_file(file_material_a, path_to_move+"/")
39
- file2 = process_file(file_material_b, path_to_move+"/")
40
-
41
-
42
- if file_source_a == "c2db.json":
43
- A_structure = from_c2db_structure(read_c2db_json(file1))
44
- A_cell=A_structure["cell"]
45
- if file_source_b == "c2db.json":
46
- B_structure = from_c2db_structure(read_c2db_json(file2))
47
- B_cell=B_structure["cell"]
48
-
49
-
50
-
51
- if file_source_a == ".xyz":
52
- A_structure = extract_from_xyz(file1)
53
- A_cell = A_structure["cell"]
54
- if file_source_b == ".xyz":
55
- B_structure = extract_from_xyz(file2)
56
- B_cell=B_structure["cell"]
57
-
58
-
59
- if file_source_a == "bespoke.json":
60
- A_structure = extract_from_bespoke(file1)
61
- A_cell = A_structure["cell"]
62
- if file_source_b == "bespoke.json":
63
- B_structure = extract_from_bespoke(file2)
64
- B_cell=B_structure["cell"]
65
-
66
-
67
- super_xyz, min_supercel= compute_supercell(A_cell, B_cell, A_structure, B_structure )
68
- rez=min_supercel.rez
69
-
70
- # Write the new file:
71
- name = "solution"
72
- file12 = path_to_move + "/" + name + ".xyz"
73
-
74
- xyz_content = "{"+"'lattice_vectors':{}".format(np.array2string(min_supercel.get_new_structure()['lattice_vectors'],
75
- separator=', ',
76
- max_line_width=np.inf).replace("\n"," "))+"}\n\n"
77
-
78
- xyz_content += f"{len(super_xyz)}\n\n"
79
- xyz_content += "\n".join([f"{atom[0]} {' '.join(map(str, atom[1]))}" for atom in super_xyz])
80
-
81
- # Write the content to a file
82
- with open(file12, 'w') as file:
83
- file.write(xyz_content)
84
-
85
-
86
- plot=plot_supercel(super_xyz, min_supercel)
87
- return file12, str(rez[0]), str((rez[1], rez[2])),plot
88
-
89
- def compute_supercell_b():
90
- pass
91
-
92
- def compute_supercell(A_cell, B_cell,A_structure,B_structure ):
93
-
94
- min_supercel = PipelineLatMatch(A_cell, B_cell, Aatoms3D=structure_ato_list(A_structure),
95
- Batoms3D=structure_ato_list(B_structure), dim=(10, 10), optimize_angle=True,
96
- optimize_strain=True)
97
-
98
- new_structure = min_supercel.get_new_structure()
99
- super_xyz = structure_ato_list(new_structure)
100
- return super_xyz, min_supercel
101
-
102
-
103
-
104
-
105
- def plot_supercel(super_xyz, min_supercel):
106
- fig = plt.figure()
107
- new_structure=min_supercel.get_new_structure()
108
- super_a = [super_xyz[i] for i in range(len(new_structure["host_guest"])) if
109
- new_structure["host_guest"][i] == "host"]
110
- super_b = [super_xyz[i] for i in range(len(new_structure["host_guest"])) if
111
- new_structure["host_guest"][i] == "guest"]
112
-
113
- atoms = atoms_to_greed(super_a, lat_v=min_supercel.sc_vec3, dim=(10, 10, 0))
114
- plot_atom_list(atoms, marker=".")
115
- atoms = atoms_to_greed(super_b, lat_v=min_supercel.sc_vec3, dim=(10, 10, 0))
116
- plot_atom_list(atoms, marker="*")
117
-
118
- x = [0.0, min_supercel.sc_vec3[0][0], min_supercel.sc_vec3[0][0] + min_supercel.sc_vec3[0][1],
119
- min_supercel.sc_vec3[0][1], 0.0]
120
- y = [0.0, min_supercel.sc_vec3[1][0], min_supercel.sc_vec3[1][0] + min_supercel.sc_vec3[1][1],
121
- min_supercel.sc_vec3[1][1], 0.0]
122
- plt.gca().add_patch(patches.Polygon(xy=list(zip(x, y)), fill=True, alpha=0.4, color="green"))
123
- plt.ylim(-15, 15)
124
- plt.xlim(-15, 15)
125
- return fig
126
-
127
-
128
-
129
- # Utility tools for working with files
130
- def file_json(file_path):
131
- file = file_path.split("/")[-1]
132
- ext = file.split(".")[-1]
133
- if ext == "json":
134
- return True
135
- else:
136
- return False
137
-
138
-
139
- def get_file_name(file_path):
140
- file = file_path.split("/")[-1]
141
- file_name = file.split(".")[-2]
142
- return file_name
143
-
144
-
145
- def process_file(fileobj, path_to_move):
146
- file_path = path_to_move + os.path.basename(fileobj.name)
147
- shutil.copyfile(fileobj.name, file_path)
148
- return file_path
149
-
150
-
151
- def extract_from_xyz(file):
152
-
153
- structure={'cell':[], 'atoms':[],
154
- 'positions':[],
155
- "pbc":[ True, True, False] }
156
-
157
- with open(file, 'r') as xyz_file:
158
- lines = xyz_file.readlines()[4:] # Skipping the first two line
159
-
160
- with open(file, 'r') as xyz_file:
161
- dict_string = xyz_file.readlines()[:1][0]
162
- print(dict_string)
163
-
164
-
165
- lattice = ast.literal_eval(dict_string)['lattice_vectors']
166
-
167
-
168
- structure["cell"]=np.array([[lattice[0][0], lattice[0][1], 0],
169
- [lattice[1][0], lattice[1][1], 0],
170
- [0,0,1]])
171
-
172
-
173
- atom_xyz=np.array([line.split()[1:4] for line in lines], dtype=float)
174
-
175
- atomic_symbols = []
176
- for line in lines:
177
- atomic_symbols.append(line.split()[0])
178
- structure['atoms']=[get_atomic_number(element_symbol) for element_symbol in atomic_symbols]
179
-
180
- structure['positions']=atom_xyz
181
-
182
-
183
-
184
- return structure
185
-
186
-
187
- def extract_from_bespoke(file):
188
- read_element = DBInstance().from_json_file(file)
189
- structure = read_element.structure
190
- structure["cell"]=np.array(structure["cell"])
191
- return structure