Spaces:
Sleeping
Sleeping
import gradio as gr | |
#!/usr/bin/env python | |
# coding: utf-8 | |
import pandas as pd | |
import math | |
results = None | |
r_m = [] | |
r_l1 = [] | |
r_l2 = [] | |
r_ls = [] | |
if L2 == 0: | |
if LS == 0: | |
raise Exception('Error! L2 and LS cannot be both 0, please input again!') | |
else: | |
for m in range(math.ceil(2*A / M) + 1): | |
for l1 in range(math.ceil(2*A / L1) + 1): | |
for ls in range(math.ceil(2*A / LS) + 1): | |
total_mass = M * m + L1 * l1 + LS * ls | |
if (z * A - n <= total_mass <= z * A + n) and ls < m: | |
r_m.append(m) | |
r_l1.append(l1) | |
r_l2.append(None) | |
r_ls.append(ls) | |
results = { | |
'M': r_m, | |
'L1': r_l1, | |
'L2': r_l2, | |
'LS': r_ls, | |
} | |
df = pd.DataFrame(results) | |
print("符合 {} =< {}*m+{}*l1+{}*ls <= {} 并 LS < M 的所有自然数解有{}组,分别为:" | |
.format(A - n, M, L1, LS, A + n, len(r_m))) | |
print(df.to_markdown(tablefmt="grid")) | |
df.to_csv("result.csv", index=False) | |
else: | |
if LS == 0: | |
for m in range(math.ceil(2*A / M) + 1): | |
for l1 in range(math.ceil(2*A / L1) + 1): | |
for l2 in range(math.ceil(2*A / L2) + 1): | |
total_mass = M * m + L1 * l1 + L2 * l2 | |
if z * A - n <= total_mass <= z * A + n: | |
r_m.append(m) | |
r_l1.append(l1) | |
r_l2.append(l2) | |
r_ls.append(None) | |
results = { | |
'M': r_m, | |
'L1': r_l1, | |
'L2': r_l2, | |
'LS': r_ls, | |
} | |
df = pd.DataFrame(results) | |
print("符合 {} =< {}*m+{}*l1+{}*l2 <= {} 的所有自然数解有{}组,分别为:" | |
.format(A - n, M, L1, L2, A + n, len(r_m))) | |
print(df.to_markdown(tablefmt="grid")) | |
df.to_csv("result.csv", index=False) | |
else: | |
for m in range(math.ceil(2*A / M) + 1): | |
for l1 in range(math.ceil(2*A / L1) + 1): | |
for l2 in range(math.ceil(2*A / L2) + 1): | |
for ls in range(math.ceil(2*A / LS) + 1): | |
total_mass = M * m + L1 * l1 + L2 * l2 + LS * ls | |
if (z * A - n <= total_mass <= z * A + n) and ls < m: | |
r_m.append(m) | |
r_l1.append(l1) | |
r_l2.append(l2) | |
r_ls.append(ls) | |
results = { | |
'M': r_m, | |
'L1': r_l1, | |
'L2': r_l2, | |
'LS': r_ls, | |
} | |
df = pd.DataFrame(results) | |
print("符合 {} =< {}*m+{}*l1+{}*l2+{}*ls <= {} 并 LS < M 的所有自然数解有{}组,分别为:" | |
.format(A - n, M, L1, L2, LS, A + n, len(r_m))) | |
print(df.to_markdown(tablefmt="grid")) | |
df.to_csv("result.csv", index=False) | |
def greet(M, L1, L2, LS, A, z, n): | |
return "# 输入参数:" + "-"*82 + "\n" + "|-M: 金属| -L1: 配体1 | -L2: 配体2 | -LS: 含S配体的相对分子质量 | -A: 质谱上对应的分子量 | -z: 电荷 |" + f"M:{M}\nL1:{L1}\nL2:{L2}\nLS:{LS}\nA:{A}\nz:{z}\nn:{n}" | |
iface = gr.Interface(fn=greet, inputs=[ | |
gr.Textbox(lines=1), | |
gr.Textbox(lines=1), | |
gr.Textbox(lines=1), | |
gr.Textbox(lines=1), | |
gr.Textbox(lines=1), | |
gr.Textbox(lines=1), | |
gr.Textbox(lines=1) | |
], outputs="text") | |
iface.launch() | |