Ruijia Tan commited on
Commit
2225ea4
1 Parent(s): 6c6fbfb

Upload code.

Browse files
.idea/.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
.idea/COMP8604.iml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ </module>
.idea/inspectionProfiles/Project_Default.xml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
5
+ <option name="ignoredPackages">
6
+ <value>
7
+ <list size="26">
8
+ <item index="0" class="java.lang.String" itemvalue="yacs" />
9
+ <item index="1" class="java.lang.String" itemvalue="scikit-image" />
10
+ <item index="2" class="java.lang.String" itemvalue="numba" />
11
+ <item index="3" class="java.lang.String" itemvalue="filterpy" />
12
+ <item index="4" class="java.lang.String" itemvalue="joblib" />
13
+ <item index="5" class="java.lang.String" itemvalue="PyYAML" />
14
+ <item index="6" class="java.lang.String" itemvalue="yolov3-pytorch" />
15
+ <item index="7" class="java.lang.String" itemvalue="numpy" />
16
+ <item index="8" class="java.lang.String" itemvalue="llvmlite" />
17
+ <item index="9" class="java.lang.String" itemvalue="torchvision" />
18
+ <item index="10" class="java.lang.String" itemvalue="trimesh" />
19
+ <item index="11" class="java.lang.String" itemvalue="tensorflow" />
20
+ <item index="12" class="java.lang.String" itemvalue="gdown" />
21
+ <item index="13" class="java.lang.String" itemvalue="scipy" />
22
+ <item index="14" class="java.lang.String" itemvalue="multi-person-tracker" />
23
+ <item index="15" class="java.lang.String" itemvalue="smplx" />
24
+ <item index="16" class="java.lang.String" itemvalue="opencv-python" />
25
+ <item index="17" class="java.lang.String" itemvalue="h5py" />
26
+ <item index="18" class="java.lang.String" itemvalue="chumpy" />
27
+ <item index="19" class="java.lang.String" itemvalue="scikit-video" />
28
+ <item index="20" class="java.lang.String" itemvalue="tqdm" />
29
+ <item index="21" class="java.lang.String" itemvalue="tensorboard" />
30
+ <item index="22" class="java.lang.String" itemvalue="matplotlib" />
31
+ <item index="23" class="java.lang.String" itemvalue="pillow" />
32
+ <item index="24" class="java.lang.String" itemvalue="progress" />
33
+ <item index="25" class="java.lang.String" itemvalue="pyrender" />
34
+ </list>
35
+ </value>
36
+ </option>
37
+ </inspection_tool>
38
+ <inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
39
+ <option name="ignoredErrors">
40
+ <list>
41
+ <option value="E265" />
42
+ <option value="E251" />
43
+ <option value="E231" />
44
+ <option value="E225" />
45
+ <option value="E501" />
46
+ </list>
47
+ </option>
48
+ </inspection_tool>
49
+ <inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
50
+ <option name="ignoredIdentifiers">
51
+ <list>
52
+ <option value="services.csv_service" />
53
+ </list>
54
+ </option>
55
+ </inspection_tool>
56
+ </profile>
57
+ </component>
.idea/inspectionProfiles/profiles_settings.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="USE_PROJECT_PROFILE" value="false" />
4
+ <version value="1.0" />
5
+ </settings>
6
+ </component>
.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
4
+ </project>
.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/COMP8604.iml" filepath="$PROJECT_DIR$/.idea/COMP8604.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
Interface/empirical_parameter_calculator.py ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """empirical parameter calculator, includes calculation functions for 14 values:
2
+ 'Enthalpy(kJ/mol)', 'std_enthalpy(kJ/mol)', 'average_atomic_radius', 'Delta(%)', 'Omega', 'Entropy(J/K*mol)', 'Tm(K)',
3
+ 'std_Tm (%)', 'X', 'std_X(%)', 'VEC', 'std_VEC', 'Density(g/com^3)', 'Price(USD/kg)'
4
+ written by Will Nash and Zhipeng Li
5
+ version 2.1.1"""
6
+
7
+ import itertools
8
+ import numpy as np
9
+ import matminer.utils.data as mm_data
10
+
11
+
12
+ # the market price for most chemical elements, these data are retrieved from
13
+ # http://www.leonland.de/elements_by_price/en/list
14
+ price_dic = {
15
+ "Ag": 462, "Al": 1.91, "Au": 38189, "B": 2386, "Be": 831.6, "Bi": 10.34, "C": 24, "Ca": 5.93, "Cd": 1.98, "Ce": 7,
16
+ "Co": 59.5, "Cr": 7.64, "Cu": 5.9, "Dy": 350, "Er": 95, "Fe": 0.08, "Gd": 55, "Ge": 1833, "Hf": 1414, "Ho": 1400,
17
+ "In": 341.6, "Ir": 31186, "La": 7, "Li": 115.7, "Lu": 6269, "Mg": 2.26, "Mn": 2.06, "Mo": 16, "Nb": 42, "Nd": 60,
18
+ "Ni": 9.19, "Os": 12860, "P": 300, "Pb": 2.29, "Pd": 34401, "Pr": 85, "Pt": 26492, "Re": 1635, "Rh": 76840,
19
+ "Ru": 14720, "Sb": 7.05, "Sc": 15000, "Si": 1.91, "Sm": 14.35, "Sn": 20, "Sr": 5.4, "Ta": 238, "Tb": 550,
20
+ "Ti": 3.77, "Tm": 6200, "V": 22.6, "W": 25.52, "Y": 35, "Yb": 1600, "Zn": 2.83, "Zr": 23.14, "H": 23.64,
21
+ "He": 40.39, "N": 2.77, "O": 0.64, "F": 1900, "Ne": 629.9, "Na": 3.04, "S": 0.1, "Cl": 1.5, "Ar": 2.56, "K": 13.02,
22
+ "Ga": 278.2, "As": 1.74, "Se": 30.37, "Br": 4.4, "Kr": 1.4, "Rb": 14720, "Te": 55.68, "I": 28.00,
23
+ "Xe": 9.2, "Cs": 73400, "Ba": 550, "Eu": 258, "Hg": 38.44, "Tl": 7400, "Th": 176, "U": 57.76,
24
+ }
25
+
26
+
27
+ class EmpiricalParams(object):
28
+ """functions for returning the empirical parameters of alloy compositions where element list is a list of pymatgen
29
+ Elements that are in the alloy, and mol_ratio is their respective mole ratios """
30
+
31
+ def __init__(self, element_list, mol_ratio=None):
32
+ self.element_list = element_list
33
+ if mol_ratio is None: # assume that mol_ratio is evenly distributed amongst elements
34
+ mol_ratio = [1 / len(element_list)] * len(element_list)
35
+ self.mol_ratio = np.divide(mol_ratio, np.sum(mol_ratio))
36
+ self.a = self.mean_atomic_radius()
37
+ self.delta = self.atomic_size_difference()
38
+ self.Tm = self.average_melting_point()
39
+ self.mix_entropy = self.entropy_mixing()
40
+ self.mix_enthalpy = self.enthalpy_mixing()
41
+ self.omega = self.calc_omega()
42
+ self.x = self.mean_electronegativity()
43
+ self.std_x = self.std_electronegativity()
44
+ self.vec = self.average_vec()
45
+ self.density = self.calc_density()
46
+ self.price = self.calc_price()
47
+
48
+ # self.k = self.mean_bulk_modulus()
49
+ # self.std_k = self.std_bulk_modulus()
50
+ self.std_enthalpy = self.std_enthalpy_mixing()
51
+ self.std_Tm = self.std_melting_point()
52
+ self.vec_std = self.std_vec()
53
+
54
+ '''
55
+ 2. average atomic radius
56
+ '''
57
+ def mean_atomic_radius(self):
58
+ """function to return the mean atomic size radius 平均原子尺寸半径 (a) of the alloy"""
59
+ radii = []
60
+ for i in range(len(self.element_list)):
61
+ radii.append(self.element_list[i].atomic_radius)
62
+ avg_radii = np.dot(radii, self.mol_ratio)
63
+ return avg_radii
64
+
65
+ '''
66
+ 3. atomic size difference
67
+ '''
68
+ def atomic_size_difference(self):
69
+ """function to return the atomic size difference 原子半径差比率 (delta) of the alloy"""
70
+ delta = 0
71
+ radii = []
72
+ for i in range(len(self.element_list)):
73
+ radii.append(self.element_list[i].atomic_radius)
74
+
75
+ for j in range(len(self.element_list)):
76
+ delta += self.mol_ratio[j] * np.square((1 - np.divide(radii[j], self.a)))
77
+
78
+ return np.sqrt(delta)
79
+
80
+ '''
81
+ 6. average melting point
82
+ '''
83
+ def average_melting_point(self):
84
+ """function to return the average melting point 熔点的均值 (Tm) of the alloy"""
85
+ Tm = 0
86
+ for i in range(len(self.element_list)):
87
+ Tm += self.mol_ratio[i] * self.element_list[i].melting_point
88
+ return Tm
89
+
90
+ '''
91
+ 7. standard melting point
92
+ '''
93
+ def std_melting_point(self):
94
+ """function to return the standard deviation (in percentage) of melting points 熔点的标准偏差 (sigma_t) of the alloy"""
95
+ sigma_t = 0
96
+ T = []
97
+ for i in range(len(self.element_list)):
98
+ T.append(self.element_list[i].melting_point)
99
+
100
+ for j in range(len(self.element_list)):
101
+ sigma_t += self.mol_ratio[j] * np.square((1 - np.divide(T[j], self.Tm)))
102
+ return np.sqrt(sigma_t)
103
+
104
+ '''
105
+ 1. entropy of mixing
106
+ '''
107
+ def entropy_mixing(self):
108
+ """function to return entropy of mixing 混合熵 for alloy elements based on Boltzmann's hypothesis"""
109
+ entropy = 0
110
+ for i in range(len(self.mol_ratio)):
111
+ if self.mol_ratio[i] > 0:
112
+ entropy += self.mol_ratio[i] * np.log(self.mol_ratio[i])
113
+ return -8.31446261815324 * entropy
114
+
115
+ '''
116
+ 4. enthalpy of mixing
117
+ '''
118
+ def enthalpy_mixing(self):
119
+ """function to return the sum enthalpy of mixing 混合焓和 of an alloy system based on binary mixtures and the molar
120
+ ratio """
121
+ enthalpies = []
122
+ mol_coefficients = []
123
+
124
+ for pair in itertools.combinations(self.element_list, 2):
125
+ enthalpies.append(mm_data.MixingEnthalpy().get_mixing_enthalpy(*pair))
126
+
127
+ for molies in itertools.combinations(self.mol_ratio, 2):
128
+ mol_coefficients.append(4 * np.product(molies))
129
+
130
+ enthalpy = np.dot(enthalpies, mol_coefficients)
131
+ return enthalpy
132
+
133
+ '''
134
+ 5. standard deviation of enthalpy
135
+ '''
136
+ def std_enthalpy_mixing(self):
137
+ """function to return the standard deviation of enthalpy of mixing 混合焓的标准偏差 (sigma_h) of the alloy"""
138
+ sigma_h = 0
139
+ H = np.zeros((len(self.element_list), len(self.element_list)))
140
+ for i in range(len(self.element_list)):
141
+ for j in range(len(self.element_list)):
142
+ if i != j:
143
+ H[i][j] = mm_data.MixingEnthalpy().get_mixing_enthalpy(self.element_list[i], self.element_list[j])
144
+
145
+ for i in range(len(self.element_list)):
146
+ for j in range(len(self.element_list)):
147
+ if i != j:
148
+ sigma_h += self.mol_ratio[i] * self.mol_ratio[j] * np.square(H[i][j] - self.enthalpy_mixing())
149
+ sigma_h = sigma_h / 2
150
+ return np.sqrt(sigma_h)
151
+
152
+ '''
153
+ 12. Omega omega
154
+ '''
155
+ def calc_omega(self):
156
+ """function to return the omega value of the alloy"""
157
+ if np.abs(self.mix_enthalpy) < 1e-6:
158
+ self.mix_enthalpy = 1e-6
159
+ return self.Tm * self.mix_entropy / (np.abs(self.mix_enthalpy) * 1000)
160
+
161
+ '''
162
+ 8. average electronegativity
163
+ '''
164
+ def mean_electronegativity(self):
165
+ """function to return the mean electronegativity 电负性的均值 (x) of the alloy"""
166
+ x_list = []
167
+ for i in range(len(self.element_list)):
168
+ x_list.append(self.element_list[i].X)
169
+ x_avg = np.dot(x_list, self.mol_ratio)
170
+ return x_avg
171
+
172
+ '''
173
+ 9. standard deviation of electronegativity
174
+ '''
175
+ def std_electronegativity(self):
176
+ """function to return the standard deviation (in percentage) of electronegativity 电负性的标准偏差 (sigma_x) of the alloy"""
177
+ sigma_x = 0
178
+ x_list = []
179
+ for i in range(len(self.element_list)):
180
+ x_list.append(self.element_list[i].X)
181
+
182
+ for j in range(len(self.element_list)):
183
+ sigma_x += self.mol_ratio[j] * np.square(x_list[j] - self.x)
184
+ return np.sqrt(sigma_x) / self.x
185
+
186
+ '''
187
+ 10. valence electron concentration
188
+ '''
189
+ def num_ve(self, element):
190
+ """function to return the number of valence electron of the element元素的价电子"""
191
+ e_structure = element.full_electronic_structure
192
+ outer = element.full_electronic_structure[-1][0]
193
+ num_e = 0
194
+ for t in e_structure:
195
+ if t[0] == outer - 1 and t[1] == 'd':
196
+ num_e += t[2]
197
+ if t[0] == outer:
198
+ num_e += t[2]
199
+ return num_e
200
+
201
+ '''
202
+ average of valence electron concentration
203
+ '''
204
+ def average_vec(self):
205
+ """function to return the average of valence electron concentration 价电子浓度的均值 (vec) of the alloy"""
206
+ vec = 0
207
+ for i in range(len(self.element_list)):
208
+ vec += self.mol_ratio[i] * self.num_ve(self.element_list[i])
209
+ return vec
210
+
211
+ '''
212
+ 11. standard deviation of valence electron concentration
213
+ '''
214
+ def std_vec(self):
215
+ """function to return the standard deviation of valence electron concentration 价电子浓度的标准偏差 (sigma_vec) of the alloy"""
216
+ sigma_vec = 0
217
+ vec_list = []
218
+ for i in range(len(self.element_list)):
219
+ vec_list.append(self.num_ve(self.element_list[i]))
220
+
221
+ for j in range(len(self.element_list)):
222
+ sigma_vec += self.mol_ratio[j] * np.square(vec_list[j] - self.vec)
223
+ return np.sqrt(sigma_vec)
224
+
225
+ '''
226
+ average of bulk modulus
227
+ '''
228
+ def mean_bulk_modulus(self):
229
+ """function to return the average of bulk modulus (k)体积弹性模量 of the alloy"""
230
+ k = 0
231
+ for i in range(len(self.element_list)):
232
+ if self.element_list[i].bulk_modulus is None:
233
+ print(self.element_list[i])
234
+ else:
235
+ k += self.mol_ratio[i] * self.element_list[i].bulk_modulus
236
+ return k
237
+
238
+ '''
239
+ standard deviation of bulk modulus
240
+ '''
241
+ def std_bulk_modulus(self):
242
+ """function to return the standard deviation of bulk modulus (k)体积弹性模量 of the alloy"""
243
+ sigma_k = 0
244
+ k_list = []
245
+ for i in range(len(self.element_list)):
246
+ k_list.append(self.element_list[i].bulk_modulus)
247
+
248
+ for j in range(len(self.element_list)):
249
+ if self.element_list[i].bulk_modulus is None:
250
+ print(self.element_list[i])
251
+ else:
252
+ sigma_k += self.mol_ratio[j] * np.square(k_list[j] - self.k)
253
+ return np.sqrt(sigma_k)
254
+
255
+ '''
256
+ 13. density
257
+ '''
258
+ def calc_density(self):
259
+ """function to return the density (g/cm^3) of the alloy"""
260
+ mass = 0
261
+ volume = 0
262
+ for i in range(len(self.element_list)):
263
+ mass += float(self.element_list[i].atomic_mass) * self.mol_ratio[i]
264
+ volume += self.mol_ratio[i] * self.element_list[i].molar_volume
265
+ return mass / volume
266
+
267
+ '''
268
+ 14. price/element cost
269
+ '''
270
+ def calc_price(self):
271
+ """function to return the price (USD/kg) of the alloy"""
272
+ total_mass = 0
273
+ total_price = 0
274
+ for i in range(len(self.element_list)):
275
+ if not str(self.element_list[i]) in price_dic:
276
+ return 'unknown'
277
+ mass = float(self.element_list[i].atomic_mass) * self.mol_ratio[i]
278
+ total_mass += mass
279
+ total_price += mass * price_dic[str(self.element_list[i])]
280
+ return format(total_price / total_mass, '.2f')
Interface/saved_image/blank_interface.png ADDED
Interface/saved_image/gmm_interface.png ADDED
Interface/saved_image/kmeans_interface.png ADDED
Interface/saved_image/lr_interface.png ADDED
Model/saved_model/gmm_ssl/compressive_strength.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e02174ea35006e99f8b43e3a78d13e3d2f7673e9e439491ebfc4aad075f357b
3
+ size 2565375
Model/saved_model/gmm_ssl/elongation.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:57ae33c95007da01c562c761d11b6bcb000048f30a8b83335deeae2e2c202d36
3
+ size 726983
Model/saved_model/gmm_ssl/hardness.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b496e73fba46999e20f9ffd2403331798a3b34fa5f65a332e7501549bd7d2373
3
+ size 2349713
Model/saved_model/gmm_ssl/plasticity.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a53ad7ef355647acd95f17953ca1449aa8e226c6d8a251eb40c480ca2535a203
3
+ size 1110343
Model/saved_model/gmm_ssl/tensile_strength.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:68f28229724735e324cdd8c469179abb04196f5e88a757a4f5b65a314a613250
3
+ size 26876
Model/saved_model/gmm_ssl/yield_strength.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6260faf8a063c032a626dca7e95bf3147185882cf3fa8ee1e89d1fbf49a94657
3
+ size 540505
Model/saved_model/kmeans_ssl/compressive_strength.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c302a942c75e9f780382b9b07d80acf00960cff017a0a3f39f3a0ece3f33d1ae
3
+ size 1455669
Model/saved_model/kmeans_ssl/elongation.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:767918e24001e2d111526e1a86088b28ba28a768f6770b73e0bead8ab1dcacba
3
+ size 1600365
Model/saved_model/kmeans_ssl/hardness.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42bba0a5173fb494cfba42290969b41dbca355c47d1e8e238748bdf479cbe4e0
3
+ size 425195
Model/saved_model/kmeans_ssl/plasticity.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2253eaabc6a8ac03413e5f2c0aaee3338726c50399d667b7e04f011088da6a7b
3
+ size 377195
Model/saved_model/kmeans_ssl/tensile_strength.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:75401382feb034ca78043de863b3cab03f3047470f514c5cdb0144b224110d25
3
+ size 627655
Model/saved_model/kmeans_ssl/yield_strength.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb532096c4caad2df0fbef8de0653d34b732924e3a5195ae83e273c2934a554b
3
+ size 23804
Model/saved_model/lr/compressive_strength.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:550f45334ed9f0e7a21bc7f480f195f18435e9272d3852bf0bfa2df9a9a344ce
3
+ size 937
Model/saved_model/lr/elongation.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e9fe4f2045e678c286b66e7271a927f6532ab35774f71dab2f3a823d8fc846bf
3
+ size 42049
Model/saved_model/lr/hardness.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7fb61f94fc1e0becb7fc1125c54e21bb47e63658c49a2f4d685d5c759c962816
3
+ size 124771
Model/saved_model/lr/plasticity.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2523c8f36729ef800a9a9caea6b02c0a049ac012e4ce690115831891247eb065
3
+ size 101525
Model/saved_model/lr/tensile_strength.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:caad1f7df03626cf820eb00ad032cefd90375544356488de3fb7f58071c880f6
3
+ size 44408
Model/saved_model/lr/yield_strength.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:05516385450822deb25cf0d963021b3eb41503970e07a38f651b57eb77a26780
3
+ size 54432
app.py ADDED
@@ -0,0 +1,329 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from pandas import Series, DataFrame
4
+ import pandas as pd
5
+ import sys
6
+ import numpy as np
7
+ from Interface.empirical_parameter_calculator import EmpiricalParams
8
+ from pymatgen.core.periodic_table import Element
9
+ from pip._internal import main
10
+
11
+ main(['install', 'joblib'])
12
+ main(['install', 'matminer'])
13
+
14
+ import joblib
15
+
16
+ '''
17
+ Get the path of all of the saved models.
18
+ '''
19
+
20
+ lr_compressive_strength = "./Model/saved_model/lr/compressive_strength.pkl"
21
+ lr_elongation = "./Model/saved_model/lr/elongation.pkl"
22
+ lr_hardness = "./Model/saved_model/lr/hardness.pkl"
23
+ lr_plasticity ="./Model/saved_model/lr/plasticity.pkl"
24
+ lr_tensile_strength ="./Model/saved_model/lr/tensile_strength.pkl"
25
+ lr_yield_strength ="./Model/saved_model/lr/yield_strength.pkl"
26
+
27
+ kmeans_ssl_compressive_strength = "./Model/saved_model/kmeans_ssl/compressive_strength.pkl"
28
+ kmeans_ssl_elongation = "./Model/saved_model/kmeans_ssl/elongation.pkl"
29
+ kmeans_ssl_hardness = "./Model/saved_model/kmeans_ssl/hardness.pkl"
30
+ kmeans_ssl_plasticity = "./Model/saved_model/kmeans_ssl/plasticity.pkl"
31
+ kmeans_ssl_tensile_strength = "./Model/saved_model/kmeans_ssl/tensile_strength.pkl"
32
+ kmeans_ssl_yield_strength = "./Model/saved_model/kmeans_ssl/yield_strength.pkl"
33
+
34
+ gmm_ssl_compressive_strength = "./Model/saved_model/gmm_ssl/compressive_strength.pkl"
35
+ gmm_ssl_elongation = "./Model/saved_model/gmm_ssl/elongation.pkl"
36
+ gmm_ssl_hardness ="./Model/saved_model/gmm_ssl/hardness.pkl"
37
+ gmm_ssl_plasticity = "./Model/saved_model/gmm_ssl/plasticity.pkl"
38
+ gmm_ssl_tensile_strength = "./Model/saved_model/gmm_ssl/tensile_strength.pkl"
39
+ gmm_ssl_yield_strength = "./Model/saved_model/gmm_ssl/yield_strength.pkl"
40
+
41
+
42
+ '''
43
+ Get the composition of input alloy.
44
+ '''
45
+
46
+ def normalize_molar_ratios(ratios):
47
+ normalized_ratios = list()
48
+ ele_sum = sum(ratios)
49
+ for ele in ratios:
50
+ ele = float(ele / ele_sum)
51
+ normalized_ratios.append(ele)
52
+ return normalized_ratios
53
+
54
+
55
+ '''
56
+ Load the saved ML models.
57
+ '''
58
+
59
+ def predict_input(path):
60
+ with open(path, 'rb') as p:
61
+ loaded_model = joblib.load(p)
62
+ return loaded_model
63
+
64
+
65
+ '''
66
+ Predict the six properties of the input alloy,
67
+ with Linear Regression Models, K-Means Semi-supervised Model and GMM Semi-supervised Model.
68
+ '''
69
+
70
+ def pred(Al, B, C, Co, Cr, Cu, Fe, Ga, Ge, Hf, Li, Mg, Mn, Mo, N, Nb, Ni, Sc, Si, Sn, Ta, Ti, V, W, Y, Zn, Zr, operation):
71
+ # Get the model acceptable composition format.
72
+ # print(B)
73
+ comp = {"Al": Al, "B": B, "C": C, "Co": Co, "Cr": Cr, "Cu": Cu, "Fe": Fe, "Ga": Ga, "Ge": Ge, "Hf": Hf, "Li": Li,
74
+ "Mg": Mg, "Mn": Mn,
75
+ "Mo": Mo, "N": N, "Nb": Nb, "Ni": Ni, "Sc": Sc, "Si": Si, "Sn": Sn, "Ta": Ta, "Ti": Ti, "V": V, "W": W,
76
+ "Y": Y, "Zn": Zn, "Zr": Zr}
77
+
78
+ df_values = normalize_molar_ratios(comp.values())
79
+ df = pd.DataFrame(data=[df_values],
80
+ columns=["Al", "B", "C", "Co", "Cr", "Cu", "Fe", "Ga", "Ge", "Hf", "Li", "Mg", "Mn", "Mo", "N",
81
+ "Nb", "Ni",
82
+ "Sc", "Si", "Sn", "Ta", "Ti", "V", "W", "Y", "Zn", "Zr"])
83
+ # print(df)
84
+
85
+ Composition = ""
86
+ index = 0
87
+ for k, v in comp.items():
88
+ if v != 0:
89
+ Composition = Composition + k + str(round(df_values[index], 2))
90
+ index += 1
91
+ # print(Composition)
92
+ # print(comp.values())
93
+
94
+ if operation=="Linear Regression":
95
+ #Using RandomForest to predict properties.
96
+ Hardness = predict_input(lr_hardness).predict(df)
97
+ YieldStrength=predict_input(lr_yield_strength).predict(df)
98
+ TensileStrength=predict_input(lr_tensile_strength).predict(df)
99
+ Elongation=predict_input(lr_elongation).predict(df)
100
+ CompressiveStrength=predict_input(lr_compressive_strength).predict(df)
101
+ Plasticity=predict_input(lr_plasticity).predict(df)
102
+ # print("1")
103
+
104
+ elif operation=="K-Means Semi-supervisor Model":
105
+ #Using KNN & RandomForest to predict properties.
106
+ Hardness = predict_input(kmeans_ssl_hardness).predict(df)
107
+ YieldStrength = predict_input(kmeans_ssl_yield_strength).predict(df)
108
+ TensileStrength = predict_input(kmeans_ssl_tensile_strength).predict(df)
109
+ Elongation = predict_input(kmeans_ssl_elongation).predict(df)
110
+ CompressiveStrength = predict_input(kmeans_ssl_compressive_strength).predict(df)
111
+ Plasticity = predict_input(kmeans_ssl_plasticity).predict(df)
112
+ # print("2")
113
+
114
+ elif operation == "GMM Semi-supervisor Model":
115
+ # Using semi_supervisor Label Propagation to predict properties.
116
+ Hardness = predict_input(gmm_ssl_hardness).predict(df)
117
+ YieldStrength = predict_input(gmm_ssl_yield_strength).predict(df)
118
+ TensileStrength = predict_input(gmm_ssl_tensile_strength).predict(df)
119
+ Elongation = predict_input(gmm_ssl_elongation).predict(df)
120
+ CompressiveStrength = predict_input(gmm_ssl_compressive_strength).predict(df)
121
+ Plasticity = predict_input(gmm_ssl_plasticity).predict(df)
122
+
123
+ Hardness = round(float(Hardness),2)
124
+ YieldStrength = round(float(YieldStrength),2)
125
+ TensileStrength = round(float(TensileStrength),2)
126
+ Elongation = round(float(Elongation),2)
127
+ CompressiveStrength = round(float(CompressiveStrength),2)
128
+ Plasticity = round(float(Plasticity),2)
129
+
130
+ return Composition, Hardness, YieldStrength, TensileStrength, Elongation, CompressiveStrength, Plasticity
131
+
132
+
133
+ '''
134
+ Import the function to Calculate the empirical parameters.
135
+ '''
136
+
137
+ def empirical_parameter(Al, B, C, Co, Cr, Cu, Fe, Ga, Ge, Hf, Li, Mg, Mn, Mo, N, Nb, Ni, Sc, Si, Sn, Ta, Ti, V, W, Y, Zn, Zr):
138
+ # Get the model acceptable composition format.
139
+ # print(B)
140
+ comp = {"Al": Al, "B": B, "C": C, "Co": Co, "Cr": Cr, "Cu": Cu, "Fe": Fe, "Ga": Ga, "Ge": Ge, "Hf": Hf, "Li": Li,
141
+ "Mg": Mg, "Mn": Mn,
142
+ "Mo": Mo, "N": N, "Nb": Nb, "Ni": Ni, "Sc": Sc, "Si": Si, "Sn": Sn, "Ta": Ta, "Ti": Ti, "V": V, "W": W,
143
+ "Y": Y, "Zn": Zn, "Zr": Zr}
144
+
145
+ df_values = normalize_molar_ratios(comp.values())
146
+ print(df_values)
147
+
148
+ df_element=[]
149
+ df_ratio=[]
150
+ index = 0
151
+ for key, value in comp.items():
152
+ if int(value) != 0:
153
+ df_element.append(key)
154
+ df_ratio.append(df_values[index])
155
+ index += 1
156
+ print(df_element)
157
+ print(df_ratio)
158
+
159
+ df_elements = []
160
+ for i in df_element:
161
+ df_elements.append(Element[i])
162
+ print(df_elements)
163
+
164
+ input_ele = EmpiricalParams(element_list=df_elements,mol_ratio=df_ratio)
165
+
166
+ # 1. Calculate the entropy mixing.
167
+ para1 = round(float(input_ele.entropy_mixing()),2)
168
+
169
+ #2. Calculate the average atomic radius.
170
+ para2 = round(float(input_ele.mean_atomic_radius()),2)
171
+
172
+ #3. Calculate the atomic size difference.
173
+ para3 = round(float(input_ele.atomic_size_difference()),2)
174
+
175
+ #4. Calculate the enthalpy of mixing.
176
+ para4= round(float(input_ele.enthalpy_mixing()),2)
177
+
178
+ #5. Calculate the standard deviation of enthalpy.
179
+ para5= round(float(input_ele.std_enthalpy_mixing()),2)
180
+
181
+ #6. Calculate the average melting point.
182
+ para6= round(float(input_ele.average_melting_point()),2)
183
+
184
+ #7. Calculate the standard melting point.
185
+ para7= round(float(input_ele.std_melting_point()),2)
186
+
187
+ #8. Calculate the average electronegativity.
188
+ para8= round(float(input_ele.mean_electronegativity()),2)
189
+
190
+ #9. Calculate the standard deviation of electronegativity.
191
+ para9= round(float(input_ele.std_electronegativity()),2)
192
+
193
+ #10. Calculate the valence electron concentration.
194
+ para10= round(float(input_ele.average_vec()),2)
195
+
196
+ #11. Calculate the standard deviation of valence electron concentration.
197
+ para11= round(float(input_ele.std_vec()),2)
198
+
199
+ #12. Calculate the omega.
200
+ para12= round(float(input_ele.calc_omega()),2)
201
+
202
+ #13. Calculate the density.
203
+ para13= round(float(input_ele.calc_density()),2)
204
+
205
+ #14. Calculate the price.
206
+ para14= round(float(input_ele.calc_price()),2)
207
+
208
+ return para1, para2, para3, para4,para5, para6, para7, para8, para9, para10, para11, para12, para13, para14
209
+
210
+
211
+ '''
212
+ The function of Clear button.
213
+ '''
214
+
215
+ def clear_input():
216
+ return 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
217
+
218
+
219
+ '''
220
+ Interface Details
221
+ '''
222
+
223
+ with gr.Blocks() as demo:
224
+ # The title and description of interface.
225
+ gr.Markdown("# Multi Principal Element Alloy Property Predictor")
226
+ gr.Markdown("Input alloy composition to obtain output of alloy properties (sum of composition should be equal to 100)")
227
+
228
+ # The section to select the Machine Learning Model.
229
+ with gr.Row():
230
+ operation = gr.inputs.Radio(["Linear Regression","K-Means Semi-supervisor Model", "GMM Semi-supervisor Model"])
231
+
232
+ # The section to input the element ratio.
233
+ with gr.Row():
234
+ Al = gr.Number(label="Al")
235
+ B = gr.Number(label="B")
236
+ C = gr.Number(label="C")
237
+ Co = gr.Number(label="Co")
238
+ Cr = gr.Number(label="Cr")
239
+ Cu = gr.Number(label="Cu")
240
+ Fe = gr.Number(label="Fe")
241
+ Ga = gr.Number(label="Ga")
242
+ Ge = gr.Number(label="Ge")
243
+ Hf = gr.Number(label="Hf")
244
+ Li = gr.Number(label="Li")
245
+ Mg = gr.Number(label="Mg")
246
+ Mn = gr.Number(label="Mn")
247
+ Mo = gr.Number(label="Mo")
248
+ N = gr.Number(label="N")
249
+ Nb = gr.Number(label="Nb")
250
+ Ni = gr.Number(label="Ni")
251
+ Sc = gr.Number(label="Sc")
252
+ Si = gr.Number(label="Si")
253
+ Sn = gr.Number(label="Sn")
254
+ Ta = gr.Number(label="Ta")
255
+ Ti = gr.Number(label="Ti")
256
+ V = gr.Number(label="V")
257
+ W = gr.Number(label="W")
258
+ Y = gr.Number(label="Y")
259
+ Zn = gr.Number(label="Zn")
260
+ Zr = gr.Number(label="Zr")
261
+ Composition = gr.Text(label="Alloy Composition")
262
+
263
+ #Action buttons.("Clear" and "Prediction")
264
+ with gr.Row():
265
+ clear = gr.Button("Clear")
266
+ submit = gr.Button("Predict")
267
+
268
+ #The prediction result(Six mechanical properties) of ML models.
269
+ with gr.Row():
270
+ Hardness = gr.Number(label="Hardness (VHN)")
271
+ YieldStrength = gr.Number(label="Yield Strength (MPa)")
272
+ TensileStrength = gr.Number(label="Tensile Strength (MPa)")
273
+ Elongation = gr.Number(label="Elongation (%)")
274
+ CompressiveStrength = gr.Number(label="Compressive Strength (MPa)")
275
+ Plasticity = gr.Number(label="Plasticity (from compression)")
276
+
277
+ #Calculer resutl of empirical parameters.
278
+ with gr.Row():
279
+ entropy_mixing = gr.Number(label="Entropy of Mixing (J/K*mol)")
280
+ average_atomic_radius = gr.Number(label="Average Atomic Radius (Angstroms)")
281
+ atomic_size_dif = gr.Number(label="Atomic Size Difference")
282
+ enthalpy_mixing = gr.Number(label="Enthalpy of Mixing (kJ/mol)")
283
+ std_deviation_enthalpy = gr.Number(label="Standard Deviation of Enthalpy")
284
+ average_melting_point = gr.Number(label="Average Melting Point (Tm, in Celcius)")
285
+ std_deviation_melting_point = gr.Number(label="Standard Deviation of Melting Point")
286
+ average_electronegativity = gr.Number(label="Average Electronegativity (X)")
287
+ std_deviation_electronegativity= gr.Number(label="Standard Deviation of Electronegativity")
288
+ valence_electron_concentration = gr.Number(label="Valence Electron Concentration (VEC)")
289
+ std_deviation_valence_electron_concentration = gr.Number(label="Standard Deviation of Valence Electron Concentration (VEC)")
290
+ omega = gr.Number(label="The Unitless Parameter Omega")
291
+ density = gr.Number(label="Density (g/cm^3)")
292
+ price = gr.Number(label="Price (USD/kg)")
293
+
294
+ # Define the action of "Clear" button.
295
+ clear.click(fn=clear_input, inputs=[],
296
+ outputs=[Al, B, C, Co, Cr, Cu, Fe, Ga, Ge, Hf, Li, Mg, Mn, Mo, N, Nb, Ni, Sc, Si, Sn, Ta, Ti, V, W, Y,
297
+ Zn, Zr, Composition,
298
+ Hardness, YieldStrength, TensileStrength, Elongation, CompressiveStrength, Plasticity, entropy_mixing, average_atomic_radius, atomic_size_dif, enthalpy_mixing,
299
+ std_deviation_enthalpy, average_melting_point, std_deviation_melting_point,
300
+ average_electronegativity, std_deviation_electronegativity, valence_electron_concentration,
301
+ std_deviation_valence_electron_concentration, omega, density, price])
302
+
303
+ # Define the action of "Predict" button.
304
+ # 1.Predict the result of "Composition", "Hardness", "YieldStrength", "TensileStrength", "Elongation", "CompressiveStrength", "Plasticity".
305
+ submit.click(fn=pred,
306
+ inputs=[Al, B, C, Co, Cr, Cu, Fe, Ga, Ge, Hf, Li, Mg, Mn, Mo, N, Nb, Ni, Sc, Si, Sn, Ta, Ti, V, W, Y,
307
+ Zn, Zr,operation],
308
+ outputs=[Composition, Hardness, YieldStrength, TensileStrength, Elongation, CompressiveStrength,
309
+ Plasticity])
310
+
311
+ # 2.Activate the empirical parameter calculator.
312
+ submit.click(fn=empirical_parameter,
313
+ inputs=[Al, B, C, Co, Cr, Cu, Fe, Ga, Ge, Hf, Li, Mg, Mn, Mo, N, Nb, Ni, Sc, Si, Sn, Ta, Ti, V, W, Y,
314
+ Zn, Zr],
315
+ outputs=[entropy_mixing, average_atomic_radius, atomic_size_dif, enthalpy_mixing,
316
+ std_deviation_enthalpy, average_melting_point, std_deviation_melting_point,
317
+ average_electronegativity, std_deviation_electronegativity, valence_electron_concentration,
318
+ std_deviation_valence_electron_concentration, omega, density, price])
319
+
320
+
321
+ '''
322
+ Launch the interface.
323
+ '''
324
+ if __name__ == "__main__":
325
+ # Run the Alloy Property Predictor Interface, without public URL.
326
+ # demo.launch()
327
+
328
+ # Run the Alloy Property Predictor Interface, with a public URL.
329
+ demo.launch(share="True")