Update src/streamlit_app.py
Browse files- src/streamlit_app.py +337 -37
src/streamlit_app.py
CHANGED
|
@@ -6,10 +6,14 @@ import math
|
|
| 6 |
LANGUAGES = {
|
| 7 |
"中文": {
|
| 8 |
"page_title": "溶剂分数转换器",
|
| 9 |
-
"main_title": "🧪
|
| 10 |
"conversion_mode": "转换模式",
|
| 11 |
"mode_mole_to_vol": "摩尔分数 → 体积分数",
|
| 12 |
"mode_vol_to_mole": "体积分数 → 摩尔分数",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
"select_conversion": "选择转换方向:",
|
| 14 |
"solvent_selection": "溶剂选择",
|
| 15 |
"select_solvents": "选择两种溶剂或自定义参数:",
|
|
@@ -20,34 +24,46 @@ LANGUAGES = {
|
|
| 20 |
"density": "密度",
|
| 21 |
"input_mole_fraction": "输入摩尔分数",
|
| 22 |
"input_volume_fraction": "输入体积分数",
|
|
|
|
| 23 |
"mole_fraction_of": "摩尔分数",
|
| 24 |
"volume_fraction_of": "体积分数",
|
|
|
|
| 25 |
"result_volume_fraction": "计算结果 - 体积分数",
|
| 26 |
"result_mole_fraction": "计算结果 - 摩尔分数",
|
|
|
|
| 27 |
"verification": "验证",
|
| 28 |
"detailed_info": "详细信息",
|
| 29 |
"solvent_params": "溶剂参数",
|
| 30 |
"solvent": "溶剂",
|
| 31 |
"mole_fraction": "摩尔分数",
|
| 32 |
"volume_fraction": "体积分数",
|
|
|
|
| 33 |
"calculation_formula": "计算公式",
|
| 34 |
"formula_mole_to_vol_title": "**摩尔分数转换为体积分数:**",
|
| 35 |
"formula_vol_to_mole_title": "**体积分数转换为摩尔分数:**",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
"formula_where": "其中:",
|
| 37 |
"usage_instructions": "使用说明",
|
| 38 |
"instruction_1": "1. **选择转换模式**: 在侧边栏选择转换方向",
|
| 39 |
"instruction_2": "2. **选择溶剂**: 从预设的常见溶剂中选择,或选择\"自定义\"输入参数",
|
| 40 |
-
"instruction_3": "3. **输入数值**:
|
| 41 |
"instruction_4": "4. **查看结果**: 右侧显示转换结果和详细信息",
|
| 42 |
"note": "**注意**: 本计算假设理想混合,实际情况可能存在偏差。",
|
| 43 |
"language": "语言"
|
| 44 |
},
|
| 45 |
"English": {
|
| 46 |
"page_title": "Solvent Fraction Converter",
|
| 47 |
-
"main_title": "🧪 Solvent Mole Fraction &
|
| 48 |
"conversion_mode": "Conversion Mode",
|
| 49 |
"mode_mole_to_vol": "Mole Fraction → Volume Fraction",
|
| 50 |
"mode_vol_to_mole": "Volume Fraction → Mole Fraction",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
"select_conversion": "Select conversion direction:",
|
| 52 |
"solvent_selection": "Solvent Selection",
|
| 53 |
"select_solvents": "Select two solvents or customize parameters:",
|
|
@@ -58,24 +74,32 @@ LANGUAGES = {
|
|
| 58 |
"density": "Density",
|
| 59 |
"input_mole_fraction": "Input Mole Fraction",
|
| 60 |
"input_volume_fraction": "Input Volume Fraction",
|
|
|
|
| 61 |
"mole_fraction_of": "Mole fraction of",
|
| 62 |
"volume_fraction_of": "Volume fraction of",
|
|
|
|
| 63 |
"result_volume_fraction": "Results - Volume Fraction",
|
| 64 |
"result_mole_fraction": "Results - Mole Fraction",
|
|
|
|
| 65 |
"verification": "Verification",
|
| 66 |
"detailed_info": "Detailed Information",
|
| 67 |
"solvent_params": "Solvent Parameters",
|
| 68 |
"solvent": "Solvent",
|
| 69 |
"mole_fraction": "Mole Fraction",
|
| 70 |
"volume_fraction": "Volume Fraction",
|
|
|
|
| 71 |
"calculation_formula": "Calculation Formula",
|
| 72 |
"formula_mole_to_vol_title": "**Mole Fraction to Volume Fraction:**",
|
| 73 |
"formula_vol_to_mole_title": "**Volume Fraction to Mole Fraction:**",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
"formula_where": "Where:",
|
| 75 |
"usage_instructions": "Usage Instructions",
|
| 76 |
"instruction_1": "1. **Select Conversion Mode**: Choose conversion direction in sidebar",
|
| 77 |
"instruction_2": "2. **Select Solvents**: Choose from preset common solvents or select 'Custom' to input parameters",
|
| 78 |
-
"instruction_3": "3. **Input Values**:
|
| 79 |
"instruction_4": "4. **View Results**: Results and detailed information are displayed on the right",
|
| 80 |
"note": "**Note**: This calculation assumes ideal mixing; actual situations may deviate.",
|
| 81 |
"language": "Language"
|
|
@@ -145,7 +169,9 @@ st.markdown("---")
|
|
| 145 |
st.sidebar.header(lang["conversion_mode"])
|
| 146 |
conversion_mode = st.sidebar.radio(
|
| 147 |
lang["select_conversion"],
|
| 148 |
-
[lang["mode_mole_to_vol"], lang["mode_vol_to_mole"]
|
|
|
|
|
|
|
| 149 |
)
|
| 150 |
|
| 151 |
# 溶剂选择
|
|
@@ -189,6 +215,7 @@ else:
|
|
| 189 |
# 主界面内容
|
| 190 |
col1, col2 = st.columns(2)
|
| 191 |
|
|
|
|
| 192 |
if conversion_mode == lang["mode_mole_to_vol"]:
|
| 193 |
with col1:
|
| 194 |
st.header(lang["input_mole_fraction"])
|
|
@@ -218,11 +245,10 @@ if conversion_mode == lang["mode_mole_to_vol"]:
|
|
| 218 |
st.header(lang["result_volume_fraction"])
|
| 219 |
st.metric(f"{lang['volume_fraction_of']} {solvent_a_name} (φ_A)", f"{phi_a:.4f}")
|
| 220 |
st.metric(f"{lang['volume_fraction_of']} {solvent_b_name} (φ_B)", f"{phi_b:.4f}")
|
| 221 |
-
|
| 222 |
-
# 验证
|
| 223 |
st.write(f"{lang['verification']}: φ_A + φ_B = {phi_a + phi_b:.4f}")
|
| 224 |
|
| 225 |
-
|
|
|
|
| 226 |
with col1:
|
| 227 |
st.header(lang["input_volume_fraction"])
|
| 228 |
phi_a = st.number_input(
|
|
@@ -251,10 +277,136 @@ else: # 体积分数 → 摩尔分数
|
|
| 251 |
st.header(lang["result_mole_fraction"])
|
| 252 |
st.metric(f"{lang['mole_fraction_of']} {solvent_a_name} (x_A)", f"{x_a:.4f}")
|
| 253 |
st.metric(f"{lang['mole_fraction_of']} {solvent_b_name} (x_B)", f"{x_b:.4f}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
st.write(f"{lang['verification']}: x_A + x_B = {x_a + x_b:.4f}")
|
| 257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
# 详细信息展示
|
| 259 |
st.markdown("---")
|
| 260 |
st.header(lang["detailed_info"])
|
|
@@ -271,36 +423,95 @@ with col1:
|
|
| 271 |
st.dataframe(df_params)
|
| 272 |
|
| 273 |
with col2:
|
| 274 |
-
if
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
with col3:
|
| 290 |
if conversion_mode == lang["mode_mole_to_vol"]:
|
| 291 |
st.subheader(lang["volume_fraction"])
|
| 292 |
-
|
| 293 |
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 294 |
lang["volume_fraction"]: [phi_a, phi_b]
|
| 295 |
})
|
| 296 |
-
st.dataframe(
|
| 297 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
st.subheader(lang["mole_fraction"])
|
| 299 |
-
|
| 300 |
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 301 |
lang["mole_fraction"]: [x_a, x_b]
|
| 302 |
})
|
| 303 |
-
st.dataframe(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
| 305 |
# 公式说明
|
| 306 |
st.markdown("---")
|
|
@@ -313,8 +524,6 @@ if conversion_mode == lang["mode_mole_to_vol"]:
|
|
| 313 |
|
| 314 |
$$\\phi_A = \\frac{{x_A \\cdot M_A / \\rho_A}}{{x_A \\cdot M_A / \\rho_A + x_B \\cdot M_B / \\rho_B}}$$
|
| 315 |
|
| 316 |
-
$$\\phi_B = \\frac{{x_B \\cdot M_B / \\rho_B}}{{x_A \\cdot M_A / \\rho_A + x_B \\cdot M_B / \\rho_B}}$$
|
| 317 |
-
|
| 318 |
{lang["formula_where"]}
|
| 319 |
- $x_A, x_B$: 摩尔分数
|
| 320 |
- $\\phi_A, \\phi_B$: 体积分数
|
|
@@ -327,23 +536,20 @@ if conversion_mode == lang["mode_mole_to_vol"]:
|
|
| 327 |
|
| 328 |
$$\\phi_A = \\frac{{x_A \\cdot M_A / \\rho_A}}{{x_A \\cdot M_A / \\rho_A + x_B \\cdot M_B / \\rho_B}}$$
|
| 329 |
|
| 330 |
-
$$\\phi_B = \\frac{{x_B \\cdot M_B / \\rho_B}}{{x_A \\cdot M_A / \\rho_A + x_B \\cdot M_B / \\rho_B}}$$
|
| 331 |
-
|
| 332 |
{lang["formula_where"]}
|
| 333 |
- $x_A, x_B$: Mole fractions
|
| 334 |
- $\\phi_A, \\phi_B$: Volume fractions
|
| 335 |
- $M_A, M_B$: Molar mass (g/mol)
|
| 336 |
- $\\rho_A, \\rho_B$: Density (g/cm³)
|
| 337 |
""")
|
| 338 |
-
|
|
|
|
| 339 |
if language == "中文":
|
| 340 |
st.markdown(f"""
|
| 341 |
{lang["formula_vol_to_mole_title"]}
|
| 342 |
|
| 343 |
$$x_A = \\frac{{\\phi_A \\cdot \\rho_A / M_A}}{{\\phi_A \\cdot \\rho_A / M_A + \\phi_B \\cdot \\rho_B / M_B}}$$
|
| 344 |
|
| 345 |
-
$$x_B = \\frac{{\\phi_B \\cdot \\rho_B / M_B}}{{\\phi_A \\cdot \\rho_A / M_A + \\phi_B \\cdot \\rho_B / M_B}}$$
|
| 346 |
-
|
| 347 |
{lang["formula_where"]}
|
| 348 |
- $\\phi_A, \\phi_B$: 体积分数
|
| 349 |
- $x_A, x_B$: 摩尔分数
|
|
@@ -356,8 +562,6 @@ else:
|
|
| 356 |
|
| 357 |
$$x_A = \\frac{{\\phi_A \\cdot \\rho_A / M_A}}{{\\phi_A \\cdot \\rho_A / M_A + \\phi_B \\cdot \\rho_B / M_B}}$$
|
| 358 |
|
| 359 |
-
$$x_B = \\frac{{\\phi_B \\cdot \\rho_B / M_B}}{{\\phi_A \\cdot \\rho_A / M_A + \\phi_B \\cdot \\rho_B / M_B}}$$
|
| 360 |
-
|
| 361 |
{lang["formula_where"]}
|
| 362 |
- $\\phi_A, \\phi_B$: Volume fractions
|
| 363 |
- $x_A, x_B$: Mole fractions
|
|
@@ -365,6 +569,102 @@ else:
|
|
| 365 |
- $\\rho_A, \\rho_B$: Density (g/cm³)
|
| 366 |
""")
|
| 367 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
# 使用说明
|
| 369 |
st.markdown("---")
|
| 370 |
st.header(lang["usage_instructions"])
|
|
|
|
| 6 |
LANGUAGES = {
|
| 7 |
"中文": {
|
| 8 |
"page_title": "溶剂分数转换器",
|
| 9 |
+
"main_title": "🧪 溶剂摩尔分数、体积分数与质量分数转换器",
|
| 10 |
"conversion_mode": "转换模式",
|
| 11 |
"mode_mole_to_vol": "摩尔分数 → 体积分数",
|
| 12 |
"mode_vol_to_mole": "体积分数 → 摩尔分数",
|
| 13 |
+
"mode_mole_to_mass": "摩尔分数 → 质量分数",
|
| 14 |
+
"mode_mass_to_mole": "质量分数 → 摩尔分数",
|
| 15 |
+
"mode_vol_to_mass": "体积分数 → 质量分数",
|
| 16 |
+
"mode_mass_to_vol": "质量分数 → 体积分数",
|
| 17 |
"select_conversion": "选择转换方向:",
|
| 18 |
"solvent_selection": "溶剂选择",
|
| 19 |
"select_solvents": "选择两种溶剂或自定义参数:",
|
|
|
|
| 24 |
"density": "密度",
|
| 25 |
"input_mole_fraction": "输入摩尔分数",
|
| 26 |
"input_volume_fraction": "输入体积分数",
|
| 27 |
+
"input_mass_fraction": "输入质量分数",
|
| 28 |
"mole_fraction_of": "摩尔分数",
|
| 29 |
"volume_fraction_of": "体积分数",
|
| 30 |
+
"mass_fraction_of": "质量分数",
|
| 31 |
"result_volume_fraction": "计算结果 - 体积分数",
|
| 32 |
"result_mole_fraction": "计算结果 - 摩尔分数",
|
| 33 |
+
"result_mass_fraction": "计算结果 - 质量分数",
|
| 34 |
"verification": "验证",
|
| 35 |
"detailed_info": "详细信息",
|
| 36 |
"solvent_params": "溶剂参数",
|
| 37 |
"solvent": "溶剂",
|
| 38 |
"mole_fraction": "摩尔分数",
|
| 39 |
"volume_fraction": "体积分数",
|
| 40 |
+
"mass_fraction": "质量分数",
|
| 41 |
"calculation_formula": "计算公式",
|
| 42 |
"formula_mole_to_vol_title": "**摩尔分数转换为体积分数:**",
|
| 43 |
"formula_vol_to_mole_title": "**体积分数转换为摩尔分数:**",
|
| 44 |
+
"formula_mole_to_mass_title": "**摩尔分数转换为质量分数:**",
|
| 45 |
+
"formula_mass_to_mole_title": "**质量分数转换为摩尔分数:**",
|
| 46 |
+
"formula_vol_to_mass_title": "**体积分数转换为质量分数:**",
|
| 47 |
+
"formula_mass_to_vol_title": "**质量分数转换为体积分数:**",
|
| 48 |
"formula_where": "其中:",
|
| 49 |
"usage_instructions": "使用说明",
|
| 50 |
"instruction_1": "1. **选择转换模式**: 在侧边栏选择转换方向",
|
| 51 |
"instruction_2": "2. **选择溶剂**: 从预设的常见溶剂中选择,或选择\"自定义\"输入参数",
|
| 52 |
+
"instruction_3": "3. **输入数值**: 输入摩尔分数、体积分数或质量分数",
|
| 53 |
"instruction_4": "4. **查看结果**: 右侧显示转换结果和详细信息",
|
| 54 |
"note": "**注意**: 本计算假设理想混合,实际情况可能存在偏差。",
|
| 55 |
"language": "语言"
|
| 56 |
},
|
| 57 |
"English": {
|
| 58 |
"page_title": "Solvent Fraction Converter",
|
| 59 |
+
"main_title": "🧪 Solvent Mole Fraction, Volume Fraction & Mass Fraction Converter",
|
| 60 |
"conversion_mode": "Conversion Mode",
|
| 61 |
"mode_mole_to_vol": "Mole Fraction → Volume Fraction",
|
| 62 |
"mode_vol_to_mole": "Volume Fraction → Mole Fraction",
|
| 63 |
+
"mode_mole_to_mass": "Mole Fraction → Mass Fraction",
|
| 64 |
+
"mode_mass_to_mole": "Mass Fraction → Mole Fraction",
|
| 65 |
+
"mode_vol_to_mass": "Volume Fraction → Mass Fraction",
|
| 66 |
+
"mode_mass_to_vol": "Mass Fraction → Volume Fraction",
|
| 67 |
"select_conversion": "Select conversion direction:",
|
| 68 |
"solvent_selection": "Solvent Selection",
|
| 69 |
"select_solvents": "Select two solvents or customize parameters:",
|
|
|
|
| 74 |
"density": "Density",
|
| 75 |
"input_mole_fraction": "Input Mole Fraction",
|
| 76 |
"input_volume_fraction": "Input Volume Fraction",
|
| 77 |
+
"input_mass_fraction": "Input Mass Fraction",
|
| 78 |
"mole_fraction_of": "Mole fraction of",
|
| 79 |
"volume_fraction_of": "Volume fraction of",
|
| 80 |
+
"mass_fraction_of": "Mass fraction of",
|
| 81 |
"result_volume_fraction": "Results - Volume Fraction",
|
| 82 |
"result_mole_fraction": "Results - Mole Fraction",
|
| 83 |
+
"result_mass_fraction": "Results - Mass Fraction",
|
| 84 |
"verification": "Verification",
|
| 85 |
"detailed_info": "Detailed Information",
|
| 86 |
"solvent_params": "Solvent Parameters",
|
| 87 |
"solvent": "Solvent",
|
| 88 |
"mole_fraction": "Mole Fraction",
|
| 89 |
"volume_fraction": "Volume Fraction",
|
| 90 |
+
"mass_fraction": "Mass Fraction",
|
| 91 |
"calculation_formula": "Calculation Formula",
|
| 92 |
"formula_mole_to_vol_title": "**Mole Fraction to Volume Fraction:**",
|
| 93 |
"formula_vol_to_mole_title": "**Volume Fraction to Mole Fraction:**",
|
| 94 |
+
"formula_mole_to_mass_title": "**Mole Fraction to Mass Fraction:**",
|
| 95 |
+
"formula_mass_to_mole_title": "**Mass Fraction to Mole Fraction:**",
|
| 96 |
+
"formula_vol_to_mass_title": "**Volume Fraction to Mass Fraction:**",
|
| 97 |
+
"formula_mass_to_vol_title": "**Mass Fraction to Volume Fraction:**",
|
| 98 |
"formula_where": "Where:",
|
| 99 |
"usage_instructions": "Usage Instructions",
|
| 100 |
"instruction_1": "1. **Select Conversion Mode**: Choose conversion direction in sidebar",
|
| 101 |
"instruction_2": "2. **Select Solvents**: Choose from preset common solvents or select 'Custom' to input parameters",
|
| 102 |
+
"instruction_3": "3. **Input Values**: Input mole fraction, volume fraction or mass fraction",
|
| 103 |
"instruction_4": "4. **View Results**: Results and detailed information are displayed on the right",
|
| 104 |
"note": "**Note**: This calculation assumes ideal mixing; actual situations may deviate.",
|
| 105 |
"language": "Language"
|
|
|
|
| 169 |
st.sidebar.header(lang["conversion_mode"])
|
| 170 |
conversion_mode = st.sidebar.radio(
|
| 171 |
lang["select_conversion"],
|
| 172 |
+
[lang["mode_mole_to_vol"], lang["mode_vol_to_mole"],
|
| 173 |
+
lang["mode_mole_to_mass"], lang["mode_mass_to_mole"],
|
| 174 |
+
lang["mode_vol_to_mass"], lang["mode_mass_to_vol"]]
|
| 175 |
)
|
| 176 |
|
| 177 |
# 溶剂选择
|
|
|
|
| 215 |
# 主界面内容
|
| 216 |
col1, col2 = st.columns(2)
|
| 217 |
|
| 218 |
+
# 摩尔分数 → 体积分数
|
| 219 |
if conversion_mode == lang["mode_mole_to_vol"]:
|
| 220 |
with col1:
|
| 221 |
st.header(lang["input_mole_fraction"])
|
|
|
|
| 245 |
st.header(lang["result_volume_fraction"])
|
| 246 |
st.metric(f"{lang['volume_fraction_of']} {solvent_a_name} (φ_A)", f"{phi_a:.4f}")
|
| 247 |
st.metric(f"{lang['volume_fraction_of']} {solvent_b_name} (φ_B)", f"{phi_b:.4f}")
|
|
|
|
|
|
|
| 248 |
st.write(f"{lang['verification']}: φ_A + φ_B = {phi_a + phi_b:.4f}")
|
| 249 |
|
| 250 |
+
# 体积分数 → 摩尔分数
|
| 251 |
+
elif conversion_mode == lang["mode_vol_to_mole"]:
|
| 252 |
with col1:
|
| 253 |
st.header(lang["input_volume_fraction"])
|
| 254 |
phi_a = st.number_input(
|
|
|
|
| 277 |
st.header(lang["result_mole_fraction"])
|
| 278 |
st.metric(f"{lang['mole_fraction_of']} {solvent_a_name} (x_A)", f"{x_a:.4f}")
|
| 279 |
st.metric(f"{lang['mole_fraction_of']} {solvent_b_name} (x_B)", f"{x_b:.4f}")
|
| 280 |
+
st.write(f"{lang['verification']}: x_A + x_B = {x_a + x_b:.4f}")
|
| 281 |
+
|
| 282 |
+
# 摩尔分数 → 质量分数
|
| 283 |
+
elif conversion_mode == lang["mode_mole_to_mass"]:
|
| 284 |
+
with col1:
|
| 285 |
+
st.header(lang["input_mole_fraction"])
|
| 286 |
+
x_a = st.number_input(
|
| 287 |
+
f"{lang['mole_fraction_of']} {solvent_a_name} (x_A):",
|
| 288 |
+
min_value=0.0,
|
| 289 |
+
max_value=1.0,
|
| 290 |
+
value=0.5,
|
| 291 |
+
step=0.001,
|
| 292 |
+
format="%.4f"
|
| 293 |
+
)
|
| 294 |
+
x_b = 1.0 - x_a
|
| 295 |
+
st.write(f"{lang['mole_fraction_of']} {solvent_b_name} (x_B): {x_b:.4f}")
|
| 296 |
+
|
| 297 |
+
# 计算质量分数
|
| 298 |
+
mass_a = x_a * M_a
|
| 299 |
+
mass_b = x_b * M_b
|
| 300 |
+
mass_total = mass_a + mass_b
|
| 301 |
+
|
| 302 |
+
if mass_total > 0:
|
| 303 |
+
w_a = mass_a / mass_total
|
| 304 |
+
w_b = mass_b / mass_total
|
| 305 |
+
else:
|
| 306 |
+
w_a = w_b = 0
|
| 307 |
|
| 308 |
+
with col2:
|
| 309 |
+
st.header(lang["result_mass_fraction"])
|
| 310 |
+
st.metric(f"{lang['mass_fraction_of']} {solvent_a_name} (w_A)", f"{w_a:.4f}")
|
| 311 |
+
st.metric(f"{lang['mass_fraction_of']} {solvent_b_name} (w_B)", f"{w_b:.4f}")
|
| 312 |
+
st.write(f"{lang['verification']}: w_A + w_B = {w_a + w_b:.4f}")
|
| 313 |
+
|
| 314 |
+
# 质量分数 → 摩尔分数
|
| 315 |
+
elif conversion_mode == lang["mode_mass_to_mole"]:
|
| 316 |
+
with col1:
|
| 317 |
+
st.header(lang["input_mass_fraction"])
|
| 318 |
+
w_a = st.number_input(
|
| 319 |
+
f"{lang['mass_fraction_of']} {solvent_a_name} (w_A):",
|
| 320 |
+
min_value=0.0,
|
| 321 |
+
max_value=1.0,
|
| 322 |
+
value=0.5,
|
| 323 |
+
step=0.001,
|
| 324 |
+
format="%.4f"
|
| 325 |
+
)
|
| 326 |
+
w_b = 1.0 - w_a
|
| 327 |
+
st.write(f"{lang['mass_fraction_of']} {solvent_b_name} (w_B): {w_b:.4f}")
|
| 328 |
+
|
| 329 |
+
# 计算摩尔分数
|
| 330 |
+
n_ratio_a = w_a / M_a
|
| 331 |
+
n_ratio_b = w_b / M_b
|
| 332 |
+
n_total = n_ratio_a + n_ratio_b
|
| 333 |
+
|
| 334 |
+
if n_total > 0:
|
| 335 |
+
x_a = n_ratio_a / n_total
|
| 336 |
+
x_b = n_ratio_b / n_total
|
| 337 |
+
else:
|
| 338 |
+
x_a = x_b = 0
|
| 339 |
+
|
| 340 |
+
with col2:
|
| 341 |
+
st.header(lang["result_mole_fraction"])
|
| 342 |
+
st.metric(f"{lang['mole_fraction_of']} {solvent_a_name} (x_A)", f"{x_a:.4f}")
|
| 343 |
+
st.metric(f"{lang['mole_fraction_of']} {solvent_b_name} (x_B)", f"{x_b:.4f}")
|
| 344 |
st.write(f"{lang['verification']}: x_A + x_B = {x_a + x_b:.4f}")
|
| 345 |
|
| 346 |
+
# 体积分数 → 质量分数
|
| 347 |
+
elif conversion_mode == lang["mode_vol_to_mass"]:
|
| 348 |
+
with col1:
|
| 349 |
+
st.header(lang["input_volume_fraction"])
|
| 350 |
+
phi_a = st.number_input(
|
| 351 |
+
f"{lang['volume_fraction_of']} {solvent_a_name} (φ_A):",
|
| 352 |
+
min_value=0.0,
|
| 353 |
+
max_value=1.0,
|
| 354 |
+
value=0.5,
|
| 355 |
+
step=0.001,
|
| 356 |
+
format="%.4f"
|
| 357 |
+
)
|
| 358 |
+
phi_b = 1.0 - phi_a
|
| 359 |
+
st.write(f"{lang['volume_fraction_of']} {solvent_b_name} (φ_B): {phi_b:.4f}")
|
| 360 |
+
|
| 361 |
+
# 计算质量分数
|
| 362 |
+
mass_a = phi_a * rho_a
|
| 363 |
+
mass_b = phi_b * rho_b
|
| 364 |
+
mass_total = mass_a + mass_b
|
| 365 |
+
|
| 366 |
+
if mass_total > 0:
|
| 367 |
+
w_a = mass_a / mass_total
|
| 368 |
+
w_b = mass_b / mass_total
|
| 369 |
+
else:
|
| 370 |
+
w_a = w_b = 0
|
| 371 |
+
|
| 372 |
+
with col2:
|
| 373 |
+
st.header(lang["result_mass_fraction"])
|
| 374 |
+
st.metric(f"{lang['mass_fraction_of']} {solvent_a_name} (w_A)", f"{w_a:.4f}")
|
| 375 |
+
st.metric(f"{lang['mass_fraction_of']} {solvent_b_name} (w_B)", f"{w_b:.4f}")
|
| 376 |
+
st.write(f"{lang['verification']}: w_A + w_B = {w_a + w_b:.4f}")
|
| 377 |
+
|
| 378 |
+
# 质量分数 → 体积分数
|
| 379 |
+
elif conversion_mode == lang["mode_mass_to_vol"]:
|
| 380 |
+
with col1:
|
| 381 |
+
st.header(lang["input_mass_fraction"])
|
| 382 |
+
w_a = st.number_input(
|
| 383 |
+
f"{lang['mass_fraction_of']} {solvent_a_name} (w_A):",
|
| 384 |
+
min_value=0.0,
|
| 385 |
+
max_value=1.0,
|
| 386 |
+
value=0.5,
|
| 387 |
+
step=0.001,
|
| 388 |
+
format="%.4f"
|
| 389 |
+
)
|
| 390 |
+
w_b = 1.0 - w_a
|
| 391 |
+
st.write(f"{lang['mass_fraction_of']} {solvent_b_name} (w_B): {w_b:.4f}")
|
| 392 |
+
|
| 393 |
+
# 计算体积分数
|
| 394 |
+
vol_a = w_a / rho_a
|
| 395 |
+
vol_b = w_b / rho_b
|
| 396 |
+
vol_total = vol_a + vol_b
|
| 397 |
+
|
| 398 |
+
if vol_total > 0:
|
| 399 |
+
phi_a = vol_a / vol_total
|
| 400 |
+
phi_b = vol_b / vol_total
|
| 401 |
+
else:
|
| 402 |
+
phi_a = phi_b = 0
|
| 403 |
+
|
| 404 |
+
with col2:
|
| 405 |
+
st.header(lang["result_volume_fraction"])
|
| 406 |
+
st.metric(f"{lang['volume_fraction_of']} {solvent_a_name} (φ_A)", f"{phi_a:.4f}")
|
| 407 |
+
st.metric(f"{lang['volume_fraction_of']} {solvent_b_name} (φ_B)", f"{phi_b:.4f}")
|
| 408 |
+
st.write(f"{lang['verification']}: φ_A + φ_B = {phi_a + phi_b:.4f}")
|
| 409 |
+
|
| 410 |
# 详细信息展示
|
| 411 |
st.markdown("---")
|
| 412 |
st.header(lang["detailed_info"])
|
|
|
|
| 423 |
st.dataframe(df_params)
|
| 424 |
|
| 425 |
with col2:
|
| 426 |
+
if "mole" in conversion_mode:
|
| 427 |
+
if conversion_mode in [lang["mode_mole_to_vol"], lang["mode_mole_to_mass"]]:
|
| 428 |
+
st.subheader(lang["mole_fraction"])
|
| 429 |
+
df_input = pd.DataFrame({
|
| 430 |
+
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 431 |
+
lang["mole_fraction"]: [x_a, x_b]
|
| 432 |
+
})
|
| 433 |
+
st.dataframe(df_input)
|
| 434 |
+
else:
|
| 435 |
+
st.subheader(lang["mole_fraction"])
|
| 436 |
+
df_result = pd.DataFrame({
|
| 437 |
+
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 438 |
+
lang["mole_fraction"]: [x_a, x_b]
|
| 439 |
+
})
|
| 440 |
+
st.dataframe(df_result)
|
| 441 |
+
elif "vol" in conversion_mode:
|
| 442 |
+
if conversion_mode in [lang["mode_vol_to_mole"], lang["mode_vol_to_mass"]]:
|
| 443 |
+
st.subheader(lang["volume_fraction"])
|
| 444 |
+
df_input = pd.DataFrame({
|
| 445 |
+
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 446 |
+
lang["volume_fraction"]: [phi_a, phi_b]
|
| 447 |
+
})
|
| 448 |
+
st.dataframe(df_input)
|
| 449 |
+
else:
|
| 450 |
+
st.subheader(lang["volume_fraction"])
|
| 451 |
+
df_result = pd.DataFrame({
|
| 452 |
+
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 453 |
+
lang["volume_fraction"]: [phi_a, phi_b]
|
| 454 |
+
})
|
| 455 |
+
st.dataframe(df_result)
|
| 456 |
+
elif "mass" in conversion_mode:
|
| 457 |
+
if conversion_mode in [lang["mode_mass_to_mole"], lang["mode_mass_to_vol"]]:
|
| 458 |
+
st.subheader(lang["mass_fraction"])
|
| 459 |
+
df_input = pd.DataFrame({
|
| 460 |
+
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 461 |
+
lang["mass_fraction"]: [w_a, w_b]
|
| 462 |
+
})
|
| 463 |
+
st.dataframe(df_input)
|
| 464 |
+
else:
|
| 465 |
+
st.subheader(lang["mass_fraction"])
|
| 466 |
+
df_result = pd.DataFrame({
|
| 467 |
+
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 468 |
+
lang["mass_fraction"]: [w_a, w_b]
|
| 469 |
+
})
|
| 470 |
+
st.dataframe(df_result)
|
| 471 |
|
| 472 |
with col3:
|
| 473 |
if conversion_mode == lang["mode_mole_to_vol"]:
|
| 474 |
st.subheader(lang["volume_fraction"])
|
| 475 |
+
df_result = pd.DataFrame({
|
| 476 |
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 477 |
lang["volume_fraction"]: [phi_a, phi_b]
|
| 478 |
})
|
| 479 |
+
st.dataframe(df_result)
|
| 480 |
+
elif conversion_mode == lang["mode_mole_to_mass"]:
|
| 481 |
+
st.subheader(lang["mass_fraction"])
|
| 482 |
+
df_result = pd.DataFrame({
|
| 483 |
+
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 484 |
+
lang["mass_fraction"]: [w_a, w_b]
|
| 485 |
+
})
|
| 486 |
+
st.dataframe(df_result)
|
| 487 |
+
elif conversion_mode == lang["mode_vol_to_mole"]:
|
| 488 |
+
st.subheader(lang["mole_fraction"])
|
| 489 |
+
df_result = pd.DataFrame({
|
| 490 |
+
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 491 |
+
lang["mole_fraction"]: [x_a, x_b]
|
| 492 |
+
})
|
| 493 |
+
st.dataframe(df_result)
|
| 494 |
+
elif conversion_mode == lang["mode_vol_to_mass"]:
|
| 495 |
+
st.subheader(lang["mass_fraction"])
|
| 496 |
+
df_result = pd.DataFrame({
|
| 497 |
+
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 498 |
+
lang["mass_fraction"]: [w_a, w_b]
|
| 499 |
+
})
|
| 500 |
+
st.dataframe(df_result)
|
| 501 |
+
elif conversion_mode == lang["mode_mass_to_mole"]:
|
| 502 |
st.subheader(lang["mole_fraction"])
|
| 503 |
+
df_result = pd.DataFrame({
|
| 504 |
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 505 |
lang["mole_fraction"]: [x_a, x_b]
|
| 506 |
})
|
| 507 |
+
st.dataframe(df_result)
|
| 508 |
+
elif conversion_mode == lang["mode_mass_to_vol"]:
|
| 509 |
+
st.subheader(lang["volume_fraction"])
|
| 510 |
+
df_result = pd.DataFrame({
|
| 511 |
+
lang["solvent"]: [solvent_a_name, solvent_b_name],
|
| 512 |
+
lang["volume_fraction"]: [phi_a, phi_b]
|
| 513 |
+
})
|
| 514 |
+
st.dataframe(df_result)
|
| 515 |
|
| 516 |
# 公式说明
|
| 517 |
st.markdown("---")
|
|
|
|
| 524 |
|
| 525 |
$$\\phi_A = \\frac{{x_A \\cdot M_A / \\rho_A}}{{x_A \\cdot M_A / \\rho_A + x_B \\cdot M_B / \\rho_B}}$$
|
| 526 |
|
|
|
|
|
|
|
| 527 |
{lang["formula_where"]}
|
| 528 |
- $x_A, x_B$: 摩尔分数
|
| 529 |
- $\\phi_A, \\phi_B$: 体积分数
|
|
|
|
| 536 |
|
| 537 |
$$\\phi_A = \\frac{{x_A \\cdot M_A / \\rho_A}}{{x_A \\cdot M_A / \\rho_A + x_B \\cdot M_B / \\rho_B}}$$
|
| 538 |
|
|
|
|
|
|
|
| 539 |
{lang["formula_where"]}
|
| 540 |
- $x_A, x_B$: Mole fractions
|
| 541 |
- $\\phi_A, \\phi_B$: Volume fractions
|
| 542 |
- $M_A, M_B$: Molar mass (g/mol)
|
| 543 |
- $\\rho_A, \\rho_B$: Density (g/cm³)
|
| 544 |
""")
|
| 545 |
+
|
| 546 |
+
elif conversion_mode == lang["mode_vol_to_mole"]:
|
| 547 |
if language == "中文":
|
| 548 |
st.markdown(f"""
|
| 549 |
{lang["formula_vol_to_mole_title"]}
|
| 550 |
|
| 551 |
$$x_A = \\frac{{\\phi_A \\cdot \\rho_A / M_A}}{{\\phi_A \\cdot \\rho_A / M_A + \\phi_B \\cdot \\rho_B / M_B}}$$
|
| 552 |
|
|
|
|
|
|
|
| 553 |
{lang["formula_where"]}
|
| 554 |
- $\\phi_A, \\phi_B$: 体积分数
|
| 555 |
- $x_A, x_B$: 摩尔分数
|
|
|
|
| 562 |
|
| 563 |
$$x_A = \\frac{{\\phi_A \\cdot \\rho_A / M_A}}{{\\phi_A \\cdot \\rho_A / M_A + \\phi_B \\cdot \\rho_B / M_B}}$$
|
| 564 |
|
|
|
|
|
|
|
| 565 |
{lang["formula_where"]}
|
| 566 |
- $\\phi_A, \\phi_B$: Volume fractions
|
| 567 |
- $x_A, x_B$: Mole fractions
|
|
|
|
| 569 |
- $\\rho_A, \\rho_B$: Density (g/cm³)
|
| 570 |
""")
|
| 571 |
|
| 572 |
+
elif conversion_mode == lang["mode_mole_to_mass"]:
|
| 573 |
+
if language == "中文":
|
| 574 |
+
st.markdown(f"""
|
| 575 |
+
{lang["formula_mole_to_mass_title"]}
|
| 576 |
+
|
| 577 |
+
$$w_A = \\frac{{x_A \\cdot M_A}}{{x_A \\cdot M_A + x_B \\cdot M_B}}$$
|
| 578 |
+
|
| 579 |
+
{lang["formula_where"]}
|
| 580 |
+
- $x_A, x_B$: 摩尔分数
|
| 581 |
+
- $w_A, w_B$: 质量分数
|
| 582 |
+
- $M_A, M_B$: 摩尔质量 (g/mol)
|
| 583 |
+
""")
|
| 584 |
+
else:
|
| 585 |
+
st.markdown(f"""
|
| 586 |
+
{lang["formula_mole_to_mass_title"]}
|
| 587 |
+
|
| 588 |
+
$$w_A = \\frac{{x_A \\cdot M_A}}{{x_A \\cdot M_A + x_B \\cdot M_B}}$$
|
| 589 |
+
|
| 590 |
+
{lang["formula_where"]}
|
| 591 |
+
- $x_A, x_B$: Mole fractions
|
| 592 |
+
- $w_A, w_B$: Mass fractions
|
| 593 |
+
- $M_A, M_B$: Molar mass (g/mol)
|
| 594 |
+
""")
|
| 595 |
+
|
| 596 |
+
elif conversion_mode == lang["mode_mass_to_mole"]:
|
| 597 |
+
if language == "中文":
|
| 598 |
+
st.markdown(f"""
|
| 599 |
+
{lang["formula_mass_to_mole_title"]}
|
| 600 |
+
|
| 601 |
+
$$x_A = \\frac{{w_A / M_A}}{{w_A / M_A + w_B / M_B}}$$
|
| 602 |
+
|
| 603 |
+
{lang["formula_where"]}
|
| 604 |
+
- $w_A, w_B$: 质量分数
|
| 605 |
+
- $x_A, x_B$: 摩尔分数
|
| 606 |
+
- $M_A, M_B$: 摩尔质量 (g/mol)
|
| 607 |
+
""")
|
| 608 |
+
else:
|
| 609 |
+
st.markdown(f"""
|
| 610 |
+
{lang["formula_mass_to_mole_title"]}
|
| 611 |
+
|
| 612 |
+
$$x_A = \\frac{{w_A / M_A}}{{w_A / M_A + w_B / M_B}}$$
|
| 613 |
+
|
| 614 |
+
{lang["formula_where"]}
|
| 615 |
+
- $w_A, w_B$: Mass fractions
|
| 616 |
+
- $x_A, x_B$: Mole fractions
|
| 617 |
+
- $M_A, M_B$: Molar mass (g/mol)
|
| 618 |
+
""")
|
| 619 |
+
|
| 620 |
+
elif conversion_mode == lang["mode_vol_to_mass"]:
|
| 621 |
+
if language == "中文":
|
| 622 |
+
st.markdown(f"""
|
| 623 |
+
{lang["formula_vol_to_mass_title"]}
|
| 624 |
+
|
| 625 |
+
$$w_A = \\frac{{\\phi_A \\cdot \\rho_A}}{{\\phi_A \\cdot \\rho_A + \\phi_B \\cdot \\rho_B}}$$
|
| 626 |
+
|
| 627 |
+
{lang["formula_where"]}
|
| 628 |
+
- $\\phi_A, \\phi_B$: 体积分数
|
| 629 |
+
- $w_A, w_B$: 质量分数
|
| 630 |
+
- $\\rho_A, \\rho_B$: 密度 (g/cm³)
|
| 631 |
+
""")
|
| 632 |
+
else:
|
| 633 |
+
st.markdown(f"""
|
| 634 |
+
{lang["formula_vol_to_mass_title"]}
|
| 635 |
+
|
| 636 |
+
$$w_A = \\frac{{\\phi_A \\cdot \\rho_A}}{{\\phi_A \\cdot \\rho_A + \\phi_B \\cdot \\rho_B}}$$
|
| 637 |
+
|
| 638 |
+
{lang["formula_where"]}
|
| 639 |
+
- $\\phi_A, \\phi_B$: Volume fractions
|
| 640 |
+
- $w_A, w_B$: Mass fractions
|
| 641 |
+
- $\\rho_A, \\rho_B$: Density (g/cm³)
|
| 642 |
+
""")
|
| 643 |
+
|
| 644 |
+
elif conversion_mode == lang["mode_mass_to_vol"]:
|
| 645 |
+
if language == "中文":
|
| 646 |
+
st.markdown(f"""
|
| 647 |
+
{lang["formula_mass_to_vol_title"]}
|
| 648 |
+
|
| 649 |
+
$$\\phi_A = \\frac{{w_A / \\rho_A}}{{w_A / \\rho_A + w_B / \\rho_B}}$$
|
| 650 |
+
|
| 651 |
+
{lang["formula_where"]}
|
| 652 |
+
- $w_A, w_B$: 质量分数
|
| 653 |
+
- $\\phi_A, \\phi_B$: 体积分数
|
| 654 |
+
- $\\rho_A, \\rho_B$: 密度 (g/cm³)
|
| 655 |
+
""")
|
| 656 |
+
else:
|
| 657 |
+
st.markdown(f"""
|
| 658 |
+
{lang["formula_mass_to_vol_title"]}
|
| 659 |
+
|
| 660 |
+
$$\\phi_A = \\frac{{w_A / \\rho_A}}{{w_A / \\rho_A + w_B / \\rho_B}}$$
|
| 661 |
+
|
| 662 |
+
{lang["formula_where"]}
|
| 663 |
+
- $w_A, w_B$: Mass fractions
|
| 664 |
+
- $\\phi_A, \\phi_B$: Volume fractions
|
| 665 |
+
- $\\rho_A, \\rho_B$: Density (g/cm³)
|
| 666 |
+
""")
|
| 667 |
+
|
| 668 |
# 使用说明
|
| 669 |
st.markdown("---")
|
| 670 |
st.header(lang["usage_instructions"])
|