|
|
|
|
|
|
|
import subprocess |
|
import sys |
|
|
|
def install_package(package): |
|
subprocess.check_call([sys.executable, "-m", "pip", "install", package]) |
|
|
|
install_package('matminer') |
|
|
|
import os |
|
import gradio as gr |
|
from pandas import Series, DataFrame |
|
import pandas as pd |
|
import sys |
|
import numpy as np |
|
|
|
import os |
|
|
|
from Interface.empirical_parameter_calculator import EmpiricalParams |
|
from pymatgen.core.periodic_table import Element |
|
|
|
|
|
|
|
install_package('scikit-learn==1.2.2') |
|
import joblib |
|
|
|
''' |
|
Get the path of all of the saved models. |
|
''' |
|
gmm_ssl_compressive_strength = "./Model/saved_model/gmm_ssl/compressive_strength.pkl" |
|
gmm_ssl_elongation = "./Model/saved_model/gmm_ssl/elongation.pkl" |
|
gmm_ssl_hardness ="./Model/saved_model/gmm_ssl/hardness.pkl" |
|
gmm_ssl_plasticity = "./Model/saved_model/gmm_ssl/plasticity.pkl" |
|
gmm_ssl_tensile_strength = "./Model/saved_model/gmm_ssl/tensile_strength.pkl" |
|
gmm_ssl_yield_strength = "./Model/saved_model/gmm_ssl/yield_strength.pkl" |
|
|
|
''' |
|
Get the composition of input alloy. |
|
''' |
|
|
|
def normalize_molar_ratios(ratios): |
|
normalized_ratios = list() |
|
ele_sum = sum(ratios) |
|
for ele in ratios: |
|
ele = float(ele / ele_sum) |
|
normalized_ratios.append(ele) |
|
return normalized_ratios |
|
|
|
|
|
''' |
|
Load the saved ML models. |
|
''' |
|
|
|
def predict_input(path): |
|
with open(path, 'rb') as p: |
|
loaded_model = joblib.load(p) |
|
return loaded_model |
|
|
|
|
|
''' |
|
Predict the six properties of the input alloy, |
|
with Linear Regression Models, K-Means Semi-supervised Model and GMM Semi-supervised Model. |
|
''' |
|
|
|
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): |
|
|
|
|
|
comp = {"Al": Al, "B": B, "C": C, "Co": Co, "Cr": Cr, "Cu": Cu, "Fe": Fe, "Ga": Ga, "Ge": Ge, "Hf": Hf, "Li": Li, |
|
"Mg": Mg, "Mn": Mn, |
|
"Mo": Mo, "N": N, "Nb": Nb, "Ni": Ni, "Sc": Sc, "Si": Si, "Sn": Sn, "Ta": Ta, "Ti": Ti, "V": V, "W": W, |
|
"Y": Y, "Zn": Zn, "Zr": Zr} |
|
|
|
df_values = normalize_molar_ratios(comp.values()) |
|
df = pd.DataFrame(data=[df_values], |
|
columns=["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"]) |
|
|
|
|
|
Composition = "" |
|
index = 0 |
|
for k, v in comp.items(): |
|
if v != 0: |
|
Composition = Composition + k + str(round(df_values[index], 2)) |
|
index += 1 |
|
|
|
|
|
|
|
Hardness = predict_input(gmm_ssl_hardness).predict(df) |
|
YieldStrength = predict_input(gmm_ssl_yield_strength).predict(df) |
|
TensileStrength = predict_input(gmm_ssl_tensile_strength).predict(df) |
|
Elongation = predict_input(gmm_ssl_elongation).predict(df) |
|
CompressiveStrength = predict_input(gmm_ssl_compressive_strength).predict(df) |
|
Plasticity = predict_input(gmm_ssl_plasticity).predict(df) |
|
|
|
Hardness = round(float(Hardness),2) |
|
YieldStrength = round(float(YieldStrength),2) |
|
TensileStrength = round(float(TensileStrength),2) |
|
Elongation = round(float(Elongation),2) |
|
CompressiveStrength = round(float(CompressiveStrength),2) |
|
Plasticity = round(float(Plasticity),2) |
|
|
|
return Composition, Hardness, YieldStrength, TensileStrength, Elongation, CompressiveStrength, Plasticity |
|
|
|
|
|
''' |
|
Import the function to Calculate the empirical parameters. |
|
''' |
|
|
|
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): |
|
|
|
|
|
comp = {"Al": Al, "B": B, "C": C, "Co": Co, "Cr": Cr, "Cu": Cu, "Fe": Fe, "Ga": Ga, "Ge": Ge, "Hf": Hf, "Li": Li, |
|
"Mg": Mg, "Mn": Mn, |
|
"Mo": Mo, "N": N, "Nb": Nb, "Ni": Ni, "Sc": Sc, "Si": Si, "Sn": Sn, "Ta": Ta, "Ti": Ti, "V": V, "W": W, |
|
"Y": Y, "Zn": Zn, "Zr": Zr} |
|
|
|
df_values = normalize_molar_ratios(comp.values()) |
|
print(df_values) |
|
|
|
df_element=[] |
|
df_ratio=[] |
|
index = 0 |
|
for key, value in comp.items(): |
|
if int(value) != 0: |
|
df_element.append(key) |
|
df_ratio.append(df_values[index]) |
|
index += 1 |
|
print(df_element) |
|
print(df_ratio) |
|
|
|
df_elements = [] |
|
for i in df_element: |
|
df_elements.append(Element[i]) |
|
print(df_elements) |
|
|
|
input_ele = EmpiricalParams(element_list=df_elements,mol_ratio=df_ratio) |
|
|
|
|
|
para1 = round(float(input_ele.entropy_mixing()),2) |
|
|
|
|
|
para2 = round(float(input_ele.mean_atomic_radius()),2) |
|
|
|
|
|
para3 = round(float(input_ele.atomic_size_difference()),2) |
|
|
|
|
|
para4= round(float(input_ele.enthalpy_mixing()),2) |
|
|
|
|
|
para5= round(float(input_ele.std_enthalpy_mixing()),2) |
|
|
|
|
|
para6= round(float(input_ele.average_melting_point()),2) |
|
|
|
|
|
para7= round(float(input_ele.std_melting_point()),2) |
|
|
|
|
|
para8= round(float(input_ele.mean_electronegativity()),2) |
|
|
|
|
|
para9= round(float(input_ele.std_electronegativity()),2) |
|
|
|
|
|
para10= round(float(input_ele.average_vec()),2) |
|
|
|
|
|
para11= round(float(input_ele.std_vec()),2) |
|
|
|
|
|
para12= round(float(input_ele.calc_omega()),2) |
|
|
|
|
|
para13= round(float(input_ele.calc_density()),2) |
|
|
|
|
|
para14= round(float(input_ele.calc_price()),2) |
|
|
|
return para1, para2, para3, para4,para5, para6, para7, para8, para9, para10, para11, para12, para13, para14 |
|
|
|
|
|
''' |
|
The function of Clear button. |
|
''' |
|
|
|
def clear_input(): |
|
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 |
|
|
|
|
|
''' |
|
Interface Details |
|
''' |
|
|
|
with gr.Blocks() as demo: |
|
|
|
gr.Markdown("# Multi Principal Element Alloy Property Predictor") |
|
gr.Markdown("Input alloy composition to obtain output of alloy properties (sum of composition should be equal to 100)") |
|
|
|
|
|
with gr.Row(): |
|
Al = gr.Number(label="Al") |
|
B = gr.Number(label="B") |
|
C = gr.Number(label="C") |
|
Co = gr.Number(label="Co") |
|
Cr = gr.Number(label="Cr") |
|
Cu = gr.Number(label="Cu") |
|
Fe = gr.Number(label="Fe") |
|
Ga = gr.Number(label="Ga") |
|
Ge = gr.Number(label="Ge") |
|
Hf = gr.Number(label="Hf") |
|
Li = gr.Number(label="Li") |
|
Mg = gr.Number(label="Mg") |
|
Mn = gr.Number(label="Mn") |
|
Mo = gr.Number(label="Mo") |
|
N = gr.Number(label="N") |
|
Nb = gr.Number(label="Nb") |
|
Ni = gr.Number(label="Ni") |
|
Sc = gr.Number(label="Sc") |
|
Si = gr.Number(label="Si") |
|
Sn = gr.Number(label="Sn") |
|
Ta = gr.Number(label="Ta") |
|
Ti = gr.Number(label="Ti") |
|
V = gr.Number(label="V") |
|
W = gr.Number(label="W") |
|
Y = gr.Number(label="Y") |
|
Zn = gr.Number(label="Zn") |
|
Zr = gr.Number(label="Zr") |
|
Composition = gr.Text(label="Alloy Composition") |
|
|
|
|
|
with gr.Row(): |
|
clear = gr.Button("Clear") |
|
submit = gr.Button("Predict") |
|
|
|
|
|
with gr.Row(): |
|
Hardness = gr.Number(label="Hardness (VHN)") |
|
YieldStrength = gr.Number(label="Yield Strength (MPa)") |
|
TensileStrength = gr.Number(label="Tensile Strength (MPa)") |
|
Elongation = gr.Number(label="Elongation (%)") |
|
CompressiveStrength = gr.Number(label="Compressive Strength (MPa)") |
|
Plasticity = gr.Number(label="Plasticity (from compression)") |
|
|
|
|
|
with gr.Row(): |
|
entropy_mixing = gr.Number(label="Entropy of Mixing (J/K*mol)") |
|
average_atomic_radius = gr.Number(label="Average Atomic Radius (Angstroms)") |
|
atomic_size_dif = gr.Number(label="Atomic Size Difference") |
|
enthalpy_mixing = gr.Number(label="Enthalpy of Mixing (kJ/mol)") |
|
std_deviation_enthalpy = gr.Number(label="Standard Deviation of Enthalpy") |
|
average_melting_point = gr.Number(label="Average Melting Point (Tm, in Celcius)") |
|
std_deviation_melting_point = gr.Number(label="Standard Deviation of Melting Point") |
|
average_electronegativity = gr.Number(label="Average Electronegativity (X)") |
|
std_deviation_electronegativity= gr.Number(label="Standard Deviation of Electronegativity") |
|
valence_electron_concentration = gr.Number(label="Valence Electron Concentration (VEC)") |
|
std_deviation_valence_electron_concentration = gr.Number(label="Standard Deviation of Valence Electron Concentration (VEC)") |
|
omega = gr.Number(label="The Unitless Parameter Omega") |
|
density = gr.Number(label="Density (g/cm^3)") |
|
price = gr.Number(label="Price (USD/kg)") |
|
|
|
|
|
clear.click(fn=clear_input, inputs=[], |
|
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, |
|
Zn, Zr, Composition, |
|
Hardness, YieldStrength, TensileStrength, Elongation, CompressiveStrength, Plasticity, entropy_mixing, average_atomic_radius, atomic_size_dif, enthalpy_mixing, |
|
std_deviation_enthalpy, average_melting_point, std_deviation_melting_point, |
|
average_electronegativity, std_deviation_electronegativity, valence_electron_concentration, |
|
std_deviation_valence_electron_concentration, omega, density, price]) |
|
|
|
|
|
|
|
submit.click(fn=pred, |
|
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, |
|
Zn, Zr], |
|
outputs=[Composition, Hardness, YieldStrength, TensileStrength, Elongation, CompressiveStrength, |
|
Plasticity]) |
|
|
|
|
|
submit.click(fn=empirical_parameter, |
|
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, |
|
Zn, Zr], |
|
outputs=[entropy_mixing, average_atomic_radius, atomic_size_dif, enthalpy_mixing, |
|
std_deviation_enthalpy, average_melting_point, std_deviation_melting_point, |
|
average_electronegativity, std_deviation_electronegativity, valence_electron_concentration, |
|
std_deviation_valence_electron_concentration, omega, density, price]) |
|
|
|
|
|
''' |
|
Launch the interface. |
|
''' |
|
if __name__ == "__main__": |
|
|
|
demo.launch() |
|
|
|
|
|
|
|
|