計算化学(日記)


```python
# Program Name: electrolysis_and_iron_calculation.py
# Creation Date: 20250111
# Overview: A program to perform electrolysis gas volume and iron oxidation mass calculations based on chemical equations
# Usage: Run this script with `python electrolysis_and_iron_calculation.py` in the terminal

# ライブラリインストール / Install required libraries
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# 定数・条件設定 / Constants and Conditions
# -----------------------------
# Electrolysis Parameters
current_mA = 50.0               # 電流 (mA) / Current (mA)
time_seconds = 8 * 60 + 2 * 60 + 30  # 時間 (s) / Time (s)
faraday_constant = 9.65e4       # ファラデー定数 (C/mol) / Faraday constant (C/mol)
volume_per_mol = 22.4e-3        # 標準状態モル体積 (m^3/mol) / Molar volume at STP (m^3/mol)

# Iron Reaction Parameters
pressure_Pa = 1.013e5            # 圧力 (Pa) / Pressure (Pa)
volume_ml = 750                  # 酸素の体積 (mL) / Volume of oxygen (mL)
temperature_C = 27.0             # 温度 (℃) / Temperature (Celsius)
gas_constant = 8.31e3            # 気体定数 (Pa*cm^3/mol*K) / Gas constant (Pa*cm^3/mol*K)
molar_mass_Fe = 55.9             # 鉄のモル質量 (g/mol) / Molar mass of iron (g/mol)

# -----------------------------
# 水素発生量の計算 / Hydrogen Production Calculation
# -----------------------------
# 電気量 (Q) = 電流 * 時間 / Electric charge (Q) = Current * Time
Q = current_mA * 1e-3 * time_seconds  # mA to A conversion

# 生成される水素のモル数 / Moles of hydrogen produced
n_H2 = Q / faraday_constant / (2 / 2)  # 2H2O + 2e- → H2 + 2OH-

# 水素の体積 / Volume of hydrogen gas at STP
V_H2 = n_H2 * volume_per_mol

# -----------------------------
# 鉄酸化による質量計算 / Iron Oxidation Mass Calculation
# -----------------------------
# 酸素体積を m^3 に変換 / Convert oxygen volume to m^3
V_O2 = volume_ml / 1000 / 1000  # mL to m^3

# モル数計算 / Calculate moles of oxygen gas
n_O2 = (pressure_Pa * V_O2) / (gas_constant * (273 + temperature_C))

# 鉄のモル数 / Moles of iron based on 4-electron reaction
n_Fe = n_O2 * 4  # O2 + 4e- → 2O^2-

# 鉄の質量 / Mass of iron reacted
mass_Fe = n_Fe * molar_mass_Fe

# -----------------------------
# 計算結果出力 / Output Results
# -----------------------------
print(f"Hydrogen gas volume (m^3): {V_H2:.3e}")
print(f"Iron mass reacted (g): {mass_Fe:.3f}")

# -----------------------------
# グラフ作成 / Visualization
# -----------------------------
# Prepare data for bar chart
labels = ['Hydrogen Gas Volume (m^3)', 'Iron Mass (g)']
values = [V_H2, mass_Fe]

# Create bar chart
plt.figure(figsize=(6, 4))
plt.bar(labels, values, color=['skyblue', 'lightcoral'])
plt.title('Electrolysis and Iron Reaction Results')
plt.ylabel('Value')
plt.tight_layout()
plt.show()


```

```python
# Program Name: ammonia_synthesis_equilibrium_simulation.py
# Creation Date: 20250111
# Overview: A program to simulate ammonia synthesis equilibrium behavior under different temperature conditions
# Usage: Run with `python ammonia_synthesis_equilibrium_simulation.py` in the terminal

# 必要なライブラリのインストール / Install required libraries
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# 定数・パラメータ設定 / Constants and Parameters
# -----------------------------
# 初期条件 / Initial Conditions
max_conversion_high = 0.25  # 高温時平衡変化率 / Equilibrium conversion at high temperature
max_conversion_low = 0.75   # 低温時平衡変化率 / Equilibrium conversion at low temperature

rate_constant_high = 0.1    # 高温時反応速度定数 / Reaction rate constant at high temperature
rate_constant_low = 0.03    # 低温時反応速度定数 / Reaction rate constant at low temperature

time = np.linspace(0, 50, 500)  # 時間軸 / Time axis

# -----------------------------
# 反応進行度モデル / Reaction Progress Model
# -----------------------------
# 反応進行度の計算 / Calculate reaction progress over time
def reaction_progress(max_conversion, rate_constant, time_array):
    # 1次遅れ系のモデル：Equilibrium curve as 1st order approach to equilibrium
    return max_conversion * (1 - np.exp(-rate_constant * time_array))

# 高温と低温の進行度 / Calculate progress for high and low temperature
progress_high = reaction_progress(max_conversion_high, rate_constant_high, time)
progress_low = reaction_progress(max_conversion_low, rate_constant_low, time)

# -----------------------------
# グラフ描画 / Plotting the Results
# -----------------------------
plt.figure(figsize=(8, 5))

# 高温 / High Temperature
plt.plot(time, progress_high * 100, label='High Temperature (Higher Rate, Lower Yield)', color='red')

# 低温 / Low Temperature
plt.plot(time, progress_low * 100, label='Low Temperature (Lower Rate, Higher Yield)', color='blue')

# グラフ設定 / Graph Configuration
plt.title('Ammonia Synthesis: Equilibrium Yield vs Time')
plt.xlabel('Time (arbitrary units)')
plt.ylabel('Ammonia Yield [%]')
plt.legend()
plt.grid(True)
plt.tight_layout()

# グラフ表示 / Show plot
plt.show()


```

```python
# Program Name: chemical_balance_calculation.py
# Creation Date: 20250111
# Overview: A program to perform multiple chemical calculations based on provided problem data
# Usage: Run with `python chemical_balance_calculation.py` in the terminal

# 必要なライブラリのインストール / Install required libraries
# pip install numpy matplotlib
import numpy as np

# -----------------------------
# 定数・条件設定 / Constants and Parameters
# -----------------------------
# 演習3用パラメータ / Parameters for Exercise 3
conc_NaOH = 0.600  # mol/L
vol_NaOH = 0.470 - 0.320  # L
mass_AgCl = 12.69  # g
molar_mass_AgCl = 143.32  # g/mol
vol_solution_L = 0.500  # L

# 演習4用パラメータ / Parameters for Exercise 4
Kp = 0.25
P_A = 1.2e5  # Pa
P_B = 0.32e5  # Pa
V_a = 20.0  # mL
V_b = 28.0  # mL
mass_dry_substance = 112.5  # g
mass_initial_substance = 122.2  # g
vapor_pressure_30C = 4.2e3  # Pa
vapor_pressure_15C = 1.7e3  # Pa
volume_steam = 133.6  # mol
volume_air = 224.0  # L

# -----------------------------
# 演習3 計算 / Exercise 3 Calculations
# -----------------------------
n_NaOH = conc_NaOH * vol_NaOH  # NaOHのモル数 / Moles of NaOH
print(f"[Exercise 3] Moles of NaOH: {n_NaOH:.3f} mol")

n_AgCl = mass_AgCl / molar_mass_AgCl  # AgClのモル数 / Moles of AgCl
print(f"[Exercise 3] Moles of AgCl: {n_AgCl:.3f} mol")

# 水酸化物イオン濃度 / Hydroxide ion concentration
OH_concentration = (n_NaOH - n_AgCl) / vol_solution_L
print(f"[Exercise 3] [OH-] concentration: {OH_concentration:.3f} mol/L")

# pH 計算 / pH calculation
pOH = -np.log10(OH_concentration)
pH = 14 - pOH
print(f"[Exercise 3] pH: {pH:.2f}")

# 水素気体体積計算 / Hydrogen gas volume calculation
n_H2 = 0.180  # mol
molar_volume = 22.4  # L/mol at STP
V_H2 = n_H2 * molar_volume * 0.5  # 半分なので1/2 / Half volume
print(f"[Exercise 3] Volume of H2: {V_H2:.3f} L")

# -----------------------------
# 演習4 計算 / Exercise 4 Calculations
# -----------------------------
# 平衡定数計算 / Equilibrium constant calculation
Kp_calc = (P_B / P_A) ** 2 * (4 * Kp ** 2) / (1 - Kp ** 2)
print(f"[Exercise 4] Equilibrium constant (calculated): {Kp_calc:.3e} Pa")

# 物質量計算 / Substances volume and mass calculation
n_steam_30C = (vapor_pressure_30C * 0.3 * 1000) / (8.31 * (273 + 30))
n_steam_15C = (vapor_pressure_15C * 0.8 * 1000) / (8.31 * (273 + 15))
water_mass_evaporated = (n_steam_30C - n_steam_15C) * 18.0
print(f"[Exercise 4] Mass of evaporated water: {water_mass_evaporated:.2f} g")

# 水溶液の水分量 / Water content of solution
water_content_solution = (mass_dry_substance / mass_initial_substance) * 100
print(f"[Exercise 4] Water content of solution: {water_content_solution:.2f} %")

# 空気体積 / Air volume calculation
air_volume = (0.500 * 0.2 * 5) * 22.4 * 5
print(f"[Exercise 4] Air volume: {air_volume:.1f} L")

# -----------------------------
# 結果まとめ / Summary of Results
# -----------------------------
print("\nSummary:")
print(f"NaOH moles: {n_NaOH:.3f} mol, AgCl moles: {n_AgCl:.3f} mol, [OH-]: {OH_concentration:.3f} mol/L, pH: {pH:.2f}")
print(f"Hydrogen volume: {V_H2:.3f} L, Equilibrium constant: {Kp_calc:.3e} Pa")
print(f"Evaporated water mass: {water_mass_evaporated:.2f} g, Solution water content: {water_content_solution:.2f} %")
print(f"Air volume: {air_volume:.1f} L")


```
```python
# Program Name: chemical_process_simulation.py
# Creation Date: 20250111
# Overview: A program to automate combustion analysis, mole ratio calculations, volume contraction estimation, and mass balance with visualization
# Usage: Run with `python chemical_process_simulation.py` in the terminal

# Install required packages
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# --------------------------------------
# Parameters / 設定パラメータ
# --------------------------------------
mass_C8H4O4_mg = 20.5  # mg
molar_mass_C8H4O4 = 164  # g/mol
molar_mass_CO2 = 44.0  # g/mol
molar_mass_H2O = 18.0  # g/mol

# Reaction coefficients for C8H4O4 + 7O2 -> 8CO2 + 2H2O
coefficient_CO2 = 8
coefficient_H2O = 2

# Additional conditions for mass balance
concentration_H2SO4 = 1.83  # g/mL
volume_H2SO4_L = 1.0  # L
purity_H2SO4 = 0.80  # 80%
molar_mass_H2SO4 = 98.1  # g/mol
volume_fraction_conversion = 1 / 266  # per degree Celsius

# --------------------------------------
# Combustion Product Calculation / 燃焼生成物計算
# --------------------------------------
w = mass_C8H4O4_mg / 1000  # mg to g
n_C8H4O4 = w / molar_mass_C8H4O4  # mol

# Calculate masses of CO2 and H2O produced
mass_CO2 = n_C8H4O4 * coefficient_CO2 * molar_mass_CO2
mass_H2O = n_C8H4O4 * coefficient_H2O * molar_mass_H2O

# --------------------------------------
# Sulfuric Acid Mass Calculation / 硫酸質量計算
# --------------------------------------
mass_H2SO4 = concentration_H2SO4 * volume_H2SO4_L * 1000 * purity_H2SO4  # g
n_H2SO4 = mass_H2SO4 / molar_mass_H2SO4  # mol

# --------------------------------------
# Volume Contraction Calculation / 体積収縮計算
# --------------------------------------
def calculate_contraction_rate(v_initial, temperature_change):
    # V(1 + γθ) = V0 + ΔV, γ = 1/266
    contraction_rate = (v_initial * (1 + volume_fraction_conversion * temperature_change) - v_initial) / v_initial * 100
    return contraction_rate

contraction_100C = calculate_contraction_rate(1.0, -100)

# --------------------------------------
# Print Results / 結果表示
# --------------------------------------
print(f"CO2 produced: {mass_CO2:.2f} g")
print(f"H2O produced: {mass_H2O:.2f} g")
print(f"Mass of H2SO4 used: {mass_H2SO4:.2f} g ({n_H2SO4:.2f} mol)")
print(f"Volume contraction rate from 100°C to 0°C: {contraction_100C:.2f} %")

# --------------------------------------
# Visualization / 可視化
# --------------------------------------
labels = ['CO2 Produced (g)', 'H2O Produced (g)', 'H2SO4 Used (g)']
values = [mass_CO2, mass_H2O, mass_H2SO4]

plt.figure(figsize=(8, 5))
plt.bar(labels, values, color=['skyblue', 'lightgreen', 'lightcoral'])
plt.title('Chemical Process Results')
plt.ylabel('Mass (g)')
plt.tight_layout()
plt.show()


```

```python
# Program Name: integrated_chemical_analysis.py
# Creation Date: 20250111
# Overview: A program to automate thermochemical, gas solubility, acid dissociation, and mass balance calculations with visualization
# Usage: Run with `python integrated_chemical_analysis.py` in the terminal

# Install required packages
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# --------------------------------------
# Parameter Definitions / 定数設定
# --------------------------------------
# Thermochemical parameters
energy_per_mol_kJ = 1561  # kJ/mol
fraction_1 = 0.160
fraction_2 = 0.150
fraction_3 = 0.420
fraction_4 = 0.270
molar_volume = 22.4  # L/mol

# Gas solubility parameters
co2_mol = 2.86e-3  # mol
water_volume_mL = 4.834  # mL
density_water_g_per_mL = 0.998  # g/mL

# Acid dissociation parameters
Ka = 1.0e-3
H_concentration = 0.03e-2  # mol/L
ratio_1 = 100 / (20 + 30)
K3 = 7.0e-4  # mol/L

# Mass calculation parameters
mass_mol_ratio = 3.00 / 342.2
volume_L = 15.00
molar_mass = 143
mass_factor = 2.0

# --------------------------------------
# Thermochemical Energy Calculation / 熱量計算
energy_total = 5.00 / molar_volume * (fraction_1 * energy_per_mol_kJ + fraction_2 * 141 + fraction_3 * 286)
print(f"Total released energy: {energy_total:.2f} kJ")

# --------------------------------------
# CO2 Gas Calculations / CO2計算
n_CO2 = 5.00 / molar_volume * (fraction_1 * 2 + fraction_2 * 3 + fraction_3 * 0.5 + fraction_4)
print(f"Total CO2 moles: {n_CO2:.4f} mol")

# Water produced / 水の体積計算
water_volume = 5.00 / molar_volume * (fraction_1 * 2 + fraction_2 * 2 + fraction_3 * 0.5 + fraction_4) * 18.02 / density_water_g_per_mL
print(f"Produced water volume: {water_volume:.3f} mL")

# Dissolved CO2 calculation / 溶けたCO2の割合
dissolved_ratio = (co2_mol * water_volume_mL / 100) / n_CO2 * 100
print(f"Dissolved CO2 ratio: {dissolved_ratio:.3f} %")

# --------------------------------------
# Acid Dissociation Calculation / 酸解離計算
n_H_plus = Ka * H_concentration * ratio_1
print(f"Hydrogen ion concentration: {n_H_plus:.1e} mol")

# pKa calculation
pKa = -np.log10(K3)
print(f"pKa value: {pKa:.2f}")

# --------------------------------------
# Mass Calculation / 質量計算
mass_result = mass_mol_ratio * volume_L * mass_factor * molar_mass
print(f"Calculated mass: {mass_result:.3f} g")

# --------------------------------------
# Visualization / 可視化
labels = ['Energy (kJ)', 'CO2 (mol)', 'Water (mL)', 'Dissolved CO2 (%)', 'Mass (g)']
values = [energy_total, n_CO2, water_volume, dissolved_ratio, mass_result]

plt.figure(figsize=(8, 5))
plt.bar(labels, values, color=['orange', 'blue', 'cyan', 'green', 'purple'])
plt.title('Integrated Chemical Analysis Results')
plt.ylabel('Values')
plt.tight_layout()
plt.show()


```

```python
# Program Name: full_chemical_solver.py
# Creation Date: 20250111
# Overview: Fully integrated program for chemical calculations including energy, gas solubility, equilibrium, mass, and vapor pressure effects
# Usage: Run with `python full_chemical_solver.py` in the terminal

# Install required packages
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# Parameter Definitions / パラメータ設定
# -----------------------------
# pH/pKa calculation parameters
K1_acidic = 3.0e-4
K2_acidic = 2.0e-4
K1_basic = 1.0e-10
K2_basic = 1.5e-10

# Thermochemical parameters
energy_per_mol_kJ = 1561
fraction_1 = 0.160
fraction_2 = 0.150
fraction_3 = 0.420
fraction_4 = 0.270
molar_volume = 22.4

# Gas solubility parameters
co2_mol = 2.86e-3
water_volume_mL = 4.834
density_water = 0.998

# Molecular weight calculation parameters
mass_percent_1 = 85.1
mass_percent_2 = 44.0
molar_mass_1 = 192
molar_mass_2 = 62

# Density and height calculation parameters
thickness = 0.3  # cm
width = 13.6  # cm
length = 3.0  # cm
concentration = 0.5  # mol/L
molar_mass_solute = 76.0  # g/mol

# Vapor pressure parameters
pressure_solution = 350  # Pa
pressure_pure = 400  # Pa
solvent_mass = 40  # g
solute_mass = 10  # g
molar_mass_solvent = 18  # g/mol
molar_mass_solute_vapor = 160  # g/mol

# -----------------------------
# pH Calculation / pH計算
# -----------------------------
H_conc_acidic = np.sqrt(K1_acidic * K2_acidic)
pH_acidic = -np.log10(H_conc_acidic)

H_conc_basic = np.sqrt(K1_basic * K2_basic)
pH_basic = -np.log10(H_conc_basic)

print(f"Acidic pH: {pH_acidic:.2f}")
print(f"Basic pH: {pH_basic:.2f}")

# -----------------------------
# Thermochemical Energy Calculation / 熱量計算
# -----------------------------
energy_total = 5.00 / molar_volume * (fraction_1 * energy_per_mol_kJ + fraction_2 * 141 + fraction_3 * 286)
print(f"Total released energy: {energy_total:.2f} kJ")

# -----------------------------
# CO2 Calculation / CO2計算
# -----------------------------
n_CO2 = 5.00 / molar_volume * (fraction_1 * 2 + fraction_2 * 3 + fraction_3 * 0.5 + fraction_4)
water_volume = 5.00 / molar_volume * (fraction_1 * 2 + fraction_2 * 2 + fraction_3 * 0.5 + fraction_4) * 18.02 / density_water
dissolved_ratio = (co2_mol * water_volume_mL / 100) / n_CO2 * 100
print(f"CO2 moles: {n_CO2:.4f} mol, Water volume: {water_volume:.2f} mL, Dissolved CO2 ratio: {dissolved_ratio:.2f} %")

# -----------------------------
# Molecular Weight Calculation / 平均分子量計算
# -----------------------------
average_molar_mass = (mass_percent_1 * molar_mass_1 + mass_percent_2 * molar_mass_2) / (mass_percent_1 + mass_percent_2)
print(f"Average molecular weight: {average_molar_mass:.2f} g/mol")

# -----------------------------
# Density and Height Calculation / 密度・高さ計算
# -----------------------------
volume = thickness * width * length  # cm^3
solute_mass_g = concentration * volume * molar_mass_solute  # g
print(f"Solute mass for the given volume: {solute_mass_g:.2f} g")

# -----------------------------
# Vapor Pressure Effect Calculation / 蒸気圧計算
# -----------------------------
X_solvent = solvent_mass / molar_mass_solvent / (solvent_mass / molar_mass_solvent + solute_mass / molar_mass_solute_vapor)
reduction_rate = (1 - X_solvent) * 100
print(f"Vapor pressure reduction: {reduction_rate:.2f} %")

# -----------------------------
# Visualization / グラフ化
# -----------------------------
labels = ['Acidic pH', 'Basic pH', 'Energy (kJ)', 'CO2 (mol)', 'Dissolved CO2 (%)', 'Avg Mol. Wt.', 'Vapor Pressure Red. (%)']
values = [pH_acidic, pH_basic, energy_total, n_CO2, dissolved_ratio, average_molar_mass, reduction_rate]

plt.figure(figsize=(10, 5))
plt.bar(labels, values, color=['blue', 'green', 'orange', 'red', 'purple', 'cyan', 'gray'])
plt.title('Comprehensive Chemical Calculations Summary')
plt.ylabel('Values')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()


```

```python

# Program Name: full_chemical_solver.py
# Creation Date: 20250111
# Overview: Fully integrated program for chemical calculations including energy, gas solubility, equilibrium, mass, and vapor pressure effects
# Usage: Run with `python full_chemical_solver.py` in the terminal

# Install required packages
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# Parameter Definitions / パラメータ設定
# -----------------------------
# pH/pKa calculation parameters
K1_acidic = 3.0e-4
K2_acidic = 2.0e-4
K1_basic = 1.0e-10
K2_basic = 1.5e-10

# Thermochemical parameters
energy_per_mol_kJ = 1561
fraction_1 = 0.160
fraction_2 = 0.150
fraction_3 = 0.420
fraction_4 = 0.270
molar_volume = 22.4

# Gas solubility parameters
co2_mol = 2.86e-3
water_volume_mL = 4.834
density_water = 0.998

# Molecular weight calculation parameters
mass_percent_1 = 85.1
mass_percent_2 = 44.0
molar_mass_1 = 192
molar_mass_2 = 62

# Density and height calculation parameters
thickness = 0.3  # cm
width = 13.6  # cm
length = 3.0  # cm
concentration = 0.5  # mol/L
molar_mass_solute = 76.0  # g/mol

# Vapor pressure parameters
pressure_solution = 350  # Pa
pressure_pure = 400  # Pa
solvent_mass = 40  # g
solute_mass = 10  # g
molar_mass_solvent = 18  # g/mol
molar_mass_solute_vapor = 160  # g/mol

# -----------------------------
# pH Calculation / pH計算
# -----------------------------
H_conc_acidic = np.sqrt(K1_acidic * K2_acidic)
pH_acidic = -np.log10(H_conc_acidic)

H_conc_basic = np.sqrt(K1_basic * K2_basic)
pH_basic = -np.log10(H_conc_basic)

print(f"Acidic pH: {pH_acidic:.2f}")
print(f"Basic pH: {pH_basic:.2f}")

# -----------------------------
# Thermochemical Energy Calculation / 熱量計算
# -----------------------------
energy_total = 5.00 / molar_volume * (fraction_1 * energy_per_mol_kJ + fraction_2 * 141 + fraction_3 * 286)
print(f"Total released energy: {energy_total:.2f} kJ")

# -----------------------------
# CO2 Calculation / CO2計算
# -----------------------------
n_CO2 = 5.00 / molar_volume * (fraction_1 * 2 + fraction_2 * 3 + fraction_3 * 0.5 + fraction_4)
water_volume = 5.00 / molar_volume * (fraction_1 * 2 + fraction_2 * 2 + fraction_3 * 0.5 + fraction_4) * 18.02 / density_water
dissolved_ratio = (co2_mol * water_volume_mL / 100) / n_CO2 * 100
print(f"CO2 moles: {n_CO2:.4f} mol, Water volume: {water_volume:.2f} mL, Dissolved CO2 ratio: {dissolved_ratio:.2f} %")

# -----------------------------
# Molecular Weight Calculation / 平均分子量計算
# -----------------------------
average_molar_mass = (mass_percent_1 * molar_mass_1 + mass_percent_2 * molar_mass_2) / (mass_percent_1 + mass_percent_2)
print(f"Average molecular weight: {average_molar_mass:.2f} g/mol")

# -----------------------------
# Density and Height Calculation / 密度・高さ計算
# -----------------------------
volume = thickness * width * length  # cm^3
solute_mass_g = concentration * volume * molar_mass_solute  # g
print(f"Solute mass for the given volume: {solute_mass_g:.2f} g")

# -----------------------------
# Vapor Pressure Effect Calculation / 蒸気圧計算
# -----------------------------
X_solvent = solvent_mass / molar_mass_solvent / (solvent_mass / molar_mass_solvent + solute_mass / molar_mass_solute_vapor)
reduction_rate = (1 - X_solvent) * 100
print(f"Vapor pressure reduction: {reduction_rate:.2f} %")

# -----------------------------
# Visualization / グラフ化
# -----------------------------
labels = ['Acidic pH', 'Basic pH', 'Energy (kJ)', 'CO2 (mol)', 'Dissolved CO2 (%)', 'Avg Mol. Wt.', 'Vapor Pressure Red. (%)']
values = [pH_acidic, pH_basic, energy_total, n_CO2, dissolved_ratio, average_molar_mass, reduction_rate]

plt.figure(figsize=(10, 5))
plt.bar(labels, values, color=['blue', 'green', 'orange', 'red', 'purple', 'cyan', 'gray'])
plt.title('Comprehensive Chemical Calculations Summary')
plt.ylabel('Values')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()

```
```python
# Program Name: ultimate_chemical_solver.py
# Creation Date: 20250111
# Overview: Ultimate chemical solver integrating buffer pH, hydrolysis equilibrium, Henry's law, and gas solubility calculations
# Usage: Run with `python ultimate_chemical_solver.py` in the terminal

# Install required packages
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# Buffer pH Calculation / 緩衝液pH計算
# -----------------------------
# Henderson-Hasselbalch equation: pH = pKa + log([A-]/[HA])
pKa = 4.75  # Example value for acetic acid
HA_conc = 0.20  # [HA] mol/L
A_conc = 0.20  # [A-] mol/L
pH_buffer = pKa + np.log10(A_conc / HA_conc)

print(f"Buffer pH (Henderson-Hasselbalch): {pH_buffer:.2f}")

# -----------------------------
# Hydrolysis Equilibrium Calculation / 加水分解平衡計算
# -----------------------------
Kw = 1.0e-14  # Ion product of water at 25°C
Ka = 2.0e-5   # Acid dissociation constant
Kb = Kw / Ka  # Base dissociation constant
C = 0.20  # mol/L

# [OH-] = sqrt(Kb * C)
OH_conc = np.sqrt(Kb * C)
pOH = -np.log10(OH_conc)
pH_hydrolysis = 14 - pOH

print(f"Hydrolysis pH: {pH_hydrolysis:.2f}")

# -----------------------------
# Henry's Law Gas Solubility Calculation / ヘンリーの法則による気体溶解量計算
# -----------------------------
H = 1.01e5 / 1.26e6  # Henry's constant [Pa·L/mol] (example CO2 in water)
pressure_CO2 = 1.01e5  # Pa
gas_moles_per_L = pressure_CO2 / H

print(f"Gas solubility (moles per liter at 1 atm CO2): {gas_moles_per_L:.2e} mol/L")

# -----------------------------
# Ideal Gas Law Volume Calculation / 理想気体法則による体積計算
# -----------------------------
n_gas = 1.0  # mol
R = 8.31  # J/(mol·K)
T = 273 + 25  # K
P = 1.01e5  # Pa

# V = nRT / P
volume_gas = n_gas * R * T / P

print(f"Volume of 1 mol gas at 25°C and 1 atm: {volume_gas:.2f} L")

# -----------------------------
# Visualization / 可視化
# -----------------------------
labels = ['Buffer pH', 'Hydrolysis pH', 'Gas Solubility (mol/L)', '1 mol Gas Volume (L)']
values = [pH_buffer, pH_hydrolysis, gas_moles_per_L, volume_gas]

plt.figure(figsize=(8, 5))
plt.bar(labels, values, color=['blue', 'green', 'purple', 'orange'])
plt.title('Ultimate Chemical Solver Results')
plt.ylabel('Values')
plt.xticks(rotation=15)
plt.tight_layout()
plt.show()


```
```python
# Program Name: ultimate_chemical_and_battery_solver.py
# Creation Date: 20250111
# Overview: Fully integrated solver covering chemical equilibria, gas solubility, and battery performance evaluations
# Usage: Run with `python ultimate_chemical_and_battery_solver.py` in the terminal

# Install required packages
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# 1. Buffer pH Calculation / 緩衝液pH計算
pKa = 4.75
HA_conc = 0.20
A_conc = 0.20
pH_buffer = pKa + np.log10(A_conc / HA_conc)
print(f"Buffer pH: {pH_buffer:.2f}")

# -----------------------------
# 2. Hydrolysis Equilibrium / 加水分解平衡計算
Kw = 1.0e-14
Ka = 2.0e-5
Kb = Kw / Ka
C = 0.20
OH_conc = np.sqrt(Kb * C)
pOH = -np.log10(OH_conc)
pH_hydrolysis = 14 - pOH
print(f"Hydrolysis pH: {pH_hydrolysis:.2f}")

# -----------------------------
# 3. Henry's Law / ヘンリーの法則
H_CO2 = 1.01e5 / 1.26e6  # Pa·L/mol
pressure_CO2 = 1.01e5  # Pa
gas_moles_per_L = pressure_CO2 / H_CO2
print(f"CO2 Solubility: {gas_moles_per_L:.2e} mol/L")

# -----------------------------
# 4. Ideal Gas Law / 理想気体法則
n_gas = 1.0
R = 8.31
T = 273 + 25
P = 1.01e5
volume_gas = n_gas * R * T / P
print(f"Volume of 1 mol gas: {volume_gas:.2f} L")

# -----------------------------
# 5. Battery Performance / 電池性能評価
# 鉛蓄電池
n_Pb = 2.9e5  # C/mol (換算済み)
V_Pb = 2.1  # V
m_Pb = 207 + 239  # g/mol
energy_Pb = n_Pb * V_Pb / 3600 / m_Pb * 1e3  # Wh/kg
print(f"Lead-acid battery energy density: {energy_Pb:.2f} Wh/kg")

# リチウムイオン電池
n_Li = 1.9e5  # C/mol (換算済み)
V_Li = 3.7  # V
m_Li = 79.0 + 98.0  # g/mol
energy_Li = n_Li * V_Li / 3600 / m_Li * 1e3  # Wh/kg
print(f"Lithium-ion battery energy density: {energy_Li:.2f} Wh/kg")

# -----------------------------
# Visualization / グラフ化
labels = [
    'Buffer pH', 'Hydrolysis pH', 'CO2 Solubility (mol/L)',
    '1 mol Gas Volume (L)', 'Pb Battery (Wh/kg)', 'Li-ion Battery (Wh/kg)'
]
values = [pH_buffer, pH_hydrolysis, gas_moles_per_L, volume_gas, energy_Pb, energy_Li]

plt.figure(figsize=(10, 5))
plt.bar(labels, values, color=['blue', 'green', 'purple', 'orange', 'gray', 'red'])
plt.title('Comprehensive Chemical and Battery Analysis Results')
plt.ylabel('Values')
plt.xticks(rotation=15)
plt.tight_layout()
plt.show()


```

```python
# Program Name: ultimate_physical_chemical_solver.py
# Creation Date: 20250111
# Overview: Full solver covering buffer pH, gas solubility, battery performance, chemical equilibrium, pressure-volume relations, and vapor pressure changes
# Usage: Run with `python ultimate_physical_chemical_solver.py` in the terminal

# Install required packages
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# Buffer pH Calculation
pKa = 4.75
HA_conc = 0.20
A_conc = 0.20
pH_buffer = pKa + np.log10(A_conc / HA_conc)
print(f"Buffer pH: {pH_buffer:.2f}")

# -----------------------------
# Hydrolysis Equilibrium
Kw = 1.0e-14
Ka = 2.0e-5
Kb = Kw / Ka
C = 0.20
OH_conc = np.sqrt(Kb * C)
pH_hydrolysis = 14 - (-np.log10(OH_conc))
print(f"Hydrolysis pH: {pH_hydrolysis:.2f}")

# -----------------------------
# Henry's Law for CO2 Solubility
H_CO2 = 1.01e5 / 1.26e6
pressure_CO2 = 1.01e5
gas_moles_per_L = pressure_CO2 / H_CO2
print(f"CO2 Solubility: {gas_moles_per_L:.2e} mol/L")

# -----------------------------
# Ideal Gas Law Volume Calculation
n_gas = 1.0
R = 8.31
T = 273 + 25
P = 1.01e5
volume_gas = n_gas * R * T / P
print(f"1 mol gas volume: {volume_gas:.2f} L")

# -----------------------------
# Battery Performance Evaluation
n_Pb = 2.9e5
V_Pb = 2.1
m_Pb = 207 + 239
energy_Pb = n_Pb * V_Pb / 3600 / m_Pb * 1e3
print(f"Lead-acid battery energy: {energy_Pb:.2f} Wh/kg")

n_Li = 1.9e5
V_Li = 3.7
m_Li = 79 + 98
energy_Li = n_Li * V_Li / 3600 / m_Li * 1e3
print(f"Lithium-ion battery energy: {energy_Li:.2f} Wh/kg")

# -----------------------------
# Chemical Equilibrium Pressure-Volume Calculation
Kp = 1.0e-4
RT = 2.49e6
total_volume = 16.60  # L
pressure_ratio = 22500 / (15000**2)
n_equilibrium = 37500 * total_volume / RT
print(f"Equilibrium moles: {n_equilibrium:.4f} mol")

# -----------------------------
# Vapor Pressure Drop Calculation
initial_pressure = 0.190  # atm
solvent_pressure = 0.020  # atm
delta_p = initial_pressure - solvent_pressure
V_solution = 124.5
T_solution = 4000
P_solution = delta_p * V_solution * T_solution
print(f"Vapor pressure drop equivalent: {P_solution:.0f} Pa")

# -----------------------------
# Solubility-Based Mass Back-Calculation
solute_mass = 342
solvent_mass = 4000
mass_ratio = solute_mass / (solvent_mass - solute_mass) * 18.0 / 342
dissolved_mass = 171
print(f"Calculated solute mass: {dissolved_mass} g")

# -----------------------------
# Visualization
labels = [
    'Buffer pH', 'Hydrolysis pH', 'CO2 Solubility (mol/L)',
    '1 mol Gas Volume (L)', 'Pb Battery (Wh/kg)', 'Li-ion Battery (Wh/kg)',
    'Equilibrium Moles (mol)', 'Vapor Pressure Drop (Pa)', 'Solute Mass (g)'
]
values = [
    pH_buffer, pH_hydrolysis, gas_moles_per_L,
    volume_gas, energy_Pb, energy_Li,
    n_equilibrium, P_solution, dissolved_mass
]

plt.figure(figsize=(12, 6))
plt.bar(labels, values, color=['blue', 'green', 'purple', 'orange', 'gray', 'red', 'cyan', 'brown', 'pink'])
plt.title('Ultimate Physical-Chemical Analysis Summary')
plt.ylabel('Value')
plt.xticks(rotation=30)
plt.tight_layout()
plt.show()


```

```python
# Program Name: complete_chemical_process_solver.py
# Creation Date: 20250111
# Overview: Fully integrated solver covering buffer systems, solubility equilibria, gas laws, battery performance, and chemical equilibria
# Usage: Run with `python complete_chemical_process_solver.py` in the terminal

# Install required packages
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# Buffer pH Calculation
pKa = 4.75
HA_conc = 0.20
A_conc = 0.20
pH_buffer = pKa + np.log10(A_conc / HA_conc)
print(f"Buffer pH: {pH_buffer:.2f}")

# -----------------------------
# Water Ion Product and [H+] Calculation
Kw = 1.0e-14
OH_conc = 1.0e-7
H_conc = Kw / OH_conc
print(f"Water [H+]: {H_conc:.2e} mol/L")

# -----------------------------
# Sulfide Precipitation Equilibrium
K1 = 1.0e-7
K2 = 1.0e-13
H2S_conc = 1.0e-1
S2_conc = K1 * K2 * (H2S_conc / (H_conc**2))
print(f"Sulfide ion concentration [S2-]: {S2_conc:.2e} mol/L")

# -----------------------------
# Acetic Acid Equilibrium Calculation
Ka_acetic = 2.7e-5
H_conc_acetic = np.sqrt(Ka_acetic * HA_conc)
pH_acetic = -np.log10(H_conc_acetic)
print(f"Acetic acid solution pH: {pH_acetic:.2f}")

# -----------------------------
# Henry's Law for CO2 Solubility
H_CO2 = 1.01e5 / 1.26e6
pressure_CO2 = 1.01e5
CO2_solubility = pressure_CO2 / H_CO2
print(f"CO2 Solubility: {CO2_solubility:.2e} mol/L")

# -----------------------------
# Ideal Gas Law Volume Calculation
n_gas = 1.0
R = 8.31
T = 273 + 25
P = 1.01e5
V_gas = n_gas * R * T / P
print(f"1 mol gas volume: {V_gas:.2f} L")

# -----------------------------
# Battery Energy Density
n_Pb = 2.9e5
V_Pb = 2.1
m_Pb = 207 + 239
energy_Pb = n_Pb * V_Pb / 3600 / m_Pb * 1e3
print(f"Lead-acid battery energy density: {energy_Pb:.2f} Wh/kg")

n_Li = 1.9e5
V_Li = 3.7
m_Li = 79 + 98
energy_Li = n_Li * V_Li / 3600 / m_Li * 1e3
print(f"Lithium-ion battery energy density: {energy_Li:.2f} Wh/kg")

# -----------------------------
# Visualization
labels = [
    'Buffer pH', 'Water [H+]', '[S2-] conc.', 'Acetic pH',
    'CO2 Solubility (mol/L)', '1 mol Gas Volume (L)',
    'Pb Battery (Wh/kg)', 'Li-ion Battery (Wh/kg)'
]
values = [
    pH_buffer, H_conc, S2_conc, pH_acetic,
    CO2_solubility, V_gas,
    energy_Pb, energy_Li
]

plt.figure(figsize=(12, 6))
plt.bar(labels, values, color=['blue', 'cyan', 'purple', 'green', 'orange', 'gray', 'red', 'pink'])
plt.title('Complete Chemical Process Analysis')
plt.ylabel('Values')
plt.xticks(rotation=30)
plt.tight_layout()
plt.show()


```
```python
# Program Name: complete_chemical_equilibrium_solver.py
# Creation Date: 20250111
# Overview: Fully integrated chemical equilibrium and battery performance solver with ammonia buffer simulation
# Usage: Run with `python complete_chemical_equilibrium_solver.py` in the terminal

# Install required packages
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# Buffer pH Calculation
pKa = 4.75
HA_conc = 0.20
A_conc = 0.20
pH_buffer = pKa + np.log10(A_conc / HA_conc)
print(f"Buffer pH: {pH_buffer:.2f}")

# -----------------------------
# Water Ion Product and [H+] Calculation
Kw = 1.0e-14
OH_conc = 1.0e-7
H_conc = Kw / OH_conc
print(f"Water [H+]: {H_conc:.2e} mol/L")

# -----------------------------
# Sulfide Precipitation Equilibrium (Standard Condition)
K1 = 1.0e-7
K2 = 1.0e-13
H2S_conc_standard = 1.0e-1
S2_conc_standard = K1 * K2 * (H2S_conc_standard / (H_conc**2))
print(f"Sulfide ion concentration [S2-] (Standard): {S2_conc_standard:.2e} mol/L")

# -----------------------------
# Sulfide Precipitation Equilibrium (Ammonia Buffer Condition)
pH_ammonia = 7.0
H_conc_ammonia = 10**-pH_ammonia
H2S_conc_ammonia = 0.10
S2_conc_ammonia = K1 * K2 * (H2S_conc_ammonia / (H_conc_ammonia**2))
print(f"Sulfide ion concentration [S2-] (Ammonia Buffer): {S2_conc_ammonia:.2e} mol/L")

# -----------------------------
# Acetic Acid Equilibrium Calculation
Ka_acetic = 2.7e-5
H_conc_acetic = np.sqrt(Ka_acetic * HA_conc)
pH_acetic = -np.log10(H_conc_acetic)
print(f"Acetic acid solution pH: {pH_acetic:.2f}")

# -----------------------------
# Henry's Law for CO2 Solubility
H_CO2 = 1.01e5 / 1.26e6
pressure_CO2 = 1.01e5
CO2_solubility = pressure_CO2 / H_CO2
print(f"CO2 Solubility: {CO2_solubility:.2e} mol/L")

# -----------------------------
# Ideal Gas Law Volume Calculation
n_gas = 1.0
R = 8.31
T = 273 + 25
P = 1.01e5
V_gas = n_gas * R * T / P
print(f"1 mol gas volume: {V_gas:.2f} L")

# -----------------------------
# Battery Energy Density
n_Pb = 2.9e5
V_Pb = 2.1
m_Pb = 207 + 239
energy_Pb = n_Pb * V_Pb / 3600 / m_Pb * 1e3
print(f"Lead-acid battery energy density: {energy_Pb:.2f} Wh/kg")

n_Li = 1.9e5
V_Li = 3.7
m_Li = 79 + 98
energy_Li = n_Li * V_Li / 3600 / m_Li * 1e3
print(f"Lithium-ion battery energy density: {energy_Li:.2f} Wh/kg")

# -----------------------------
# Visualization
labels = [
    'Buffer pH', 'Water [H+]', '[S2-] Std', '[S2-] NH3 Buffer', 'Acetic pH',
    'CO2 Solubility (mol/L)', '1 mol Gas Volume (L)',
    'Pb Battery (Wh/kg)', 'Li-ion Battery (Wh/kg)'
]
values = [
    pH_buffer, H_conc, S2_conc_standard, S2_conc_ammonia, pH_acetic,
    CO2_solubility, V_gas,
    energy_Pb, energy_Li
]

plt.figure(figsize=(12, 6))
plt.bar(labels, values, color=['blue', 'cyan', 'purple', 'green', 'orange', 'gray', 'red', 'pink', 'yellow'])
plt.title('Complete Chemical Equilibrium and Battery Analysis')
plt.ylabel('Values')
plt.xticks(rotation=30)
plt.tight_layout()
plt.show()


```

```python
# Program Name: complete_chemical_solver_ultimate.py
# Creation Date: 20250111
# Overview: Fully integrated chemical solver including buffer, gas, solubility, battery, enthalpy, titration, Born-Haber, osmotic pressure, and phosphate buffer system analysis with graphical outputs.
# Usage: Run with `python complete_chemical_solver_ultimate.py` in the terminal

# Install required packages
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# 1. Buffer pH Calculation
pKa = 4.75
HA_conc = 0.20
A_conc = 0.20
pH_buffer = pKa + np.log10(A_conc / HA_conc)
print(f"Buffer pH: {pH_buffer:.2f}")

# -----------------------------
# 2. Water Ion Product and [H+] Calculation
Kw = 1.0e-14
OH_conc = 1.0e-7
H_conc = Kw / OH_conc
print(f"Water [H+]: {H_conc:.2e} mol/L")

# -----------------------------
# 3. Sulfide Precipitation Equilibrium
K1 = 1.0e-7
K2 = 1.0e-13
H2S_conc = 0.10
S2_conc = K1 * K2 * (H2S_conc / (H_conc**2))
print(f"Sulfide ion concentration [S2-]: {S2_conc:.2e} mol/L")

# -----------------------------
# 4. Acetic Acid Equilibrium Calculation
Ka_acetic = 2.7e-5
H_conc_acetic = np.sqrt(Ka_acetic * HA_conc)
pH_acetic = -np.log10(H_conc_acetic)
print(f"Acetic acid solution pH: {pH_acetic:.2f}")

# -----------------------------
# 5. Henry's Law for CO2 Solubility
H_CO2 = 1.01e5 / 1.26e6
pressure_CO2 = 1.01e5
CO2_solubility = pressure_CO2 / H_CO2
print(f"CO2 Solubility: {CO2_solubility:.2e} mol/L")

# -----------------------------
# 6. Ideal Gas Law Volume Calculation
n_gas = 1.0
R = 8.31
T = 273 + 25
P = 1.01e5
V_gas = n_gas * R * T / P
print(f"1 mol gas volume: {V_gas:.2f} L")

# -----------------------------
# 7. Battery Energy Density Calculation
n_Pb = 2.9e5
V_Pb = 2.1
m_Pb = 207 + 239
energy_Pb = n_Pb * V_Pb / 3600 / m_Pb * 1e3
print(f"Lead-acid battery energy density: {energy_Pb:.2f} Wh/kg")

n_Li = 1.9e5
V_Li = 3.7
m_Li = 79 + 98
energy_Li = n_Li * V_Li / 3600 / m_Li * 1e3
print(f"Lithium-ion battery energy density: {energy_Li:.2f} Wh/kg")

# -----------------------------
# 8. Enthalpy Calculation Example (Ammonia Oxidation to NO)
delta_H_reactions = [46, -90, -242]
Q_total = sum(delta_H_reactions)
print(f"Total reaction enthalpy (Q): {Q_total} kJ")

# -----------------------------
# 9. Silver Ion Solubility Product Calculation
Ksp_AgCl = 1.8e-10
Ag_conc = 5.0e-2
Cl_conc = Ksp_AgCl / Ag_conc
print(f"Cl- concentration at saturation: {Cl_conc:.2e} mol/L")

# -----------------------------
# 10. Titration Analysis (Oxalic Acid with KMnO4)
MnO4_moles = 0.0050 * 0.16
C2O4_moles = 0.025 * 0.05
excess_MnO4_moles = MnO4_moles - C2O4_moles
print(f"Excess MnO4- moles after titration: {excess_MnO4_moles:.2e} mol")

# -----------------------------
# 11. Born-Haber Cycle Energy Calculation
enthalpy_formation = 787
ionization_energy_Na = 502
bond_energy_Cl2 = 244
sublimation_energy_Na = 107
lattice_energy_NaCl = 411
electron_affinity_Cl = enthalpy_formation - (ionization_energy_Na + 0.5 * bond_energy_Cl2 + sublimation_energy_Na + lattice_energy_NaCl)
print(f"Electron affinity of Cl: {electron_affinity_Cl:.1f} kJ/mol")

# -----------------------------
# 12. Osmotic Pressure Calculation
R = 8.31
T = 300
c_mol_L = 4.0e-2
osmotic_pressure = c_mol_L * R * T * 1e-3  # Pa to MPa
print(f"Osmotic pressure: {osmotic_pressure:.3f} MPa")

# -----------------------------
# 13. Phosphate Buffer System (Multi-step Equilibrium)
pKa1, pKa2, pKa3 = 2.12, 7.2, 12.7
pH_range = np.linspace(0, 14, 500)
H_conc_range = 10 ** (-pH_range)
K1 = 10 ** (-pKa1)
K2 = 10 ** (-pKa2)
K3 = 10 ** (-pKa3)

# Calculate fractional concentrations
denominator = H_conc_range**3 + K1*H_conc_range**2 + K1*K2*H_conc_range + K1*K2*K3
H3PO4_frac = H_conc_range**3 / denominator
H2PO4_frac = K1*H_conc_range**2 / denominator
HPO4_frac = K1*K2*H_conc_range / denominator
PO4_frac = K1*K2*K3 / denominator

# Plot phosphate species distribution
plt.figure(figsize=(8, 5))
plt.plot(pH_range, H3PO4_frac, label='H₃PO₄')
plt.plot(pH_range, H2PO4_frac, label='H₂PO₄⁻')
plt.plot(pH_range, HPO4_frac, label='HPO₄²⁻')
plt.plot(pH_range, PO4_frac, label='PO₄³⁻')
plt.xlabel('pH')
plt.ylabel('Fractional Concentration')
plt.title('Phosphate Buffer System Distribution')
plt.legend()
plt.grid(True)
plt.show()


```

```python
# -----------------------------
# 14. Concentration from Absorbance (Beer's Law)
# 吸光度から濃度を求める / Calculate concentration from absorbance
standard_conc = 1.00e-3  # mol/L
diluted_conc = standard_conc * 4.0 / 100  # diluted concentration
slope = 0.066 / diluted_conc  # (A - blank) / concentration

abs_sample = 0.172 - 0.007
calculated_conc = (abs_sample) / slope
print(f"Calculated concentration from absorbance: {calculated_conc:.2e} mol/L")
# -----------------------------
# 15. Mixed Solution Titration (Na2CO3 & NaHCO3)
# 滴定計算 / Titration calculation

# Define known values
A = 200  # mL
C_NaOH = 5.00e-2  # mol/L
V_NaOH1 = 200  # mL for first equivalence
V_NaOH2 = 200  # mL for second equivalence
C_HCl = 1.00e-1  # mol/L
V_HCl = 3.4  # mL

# Convert to liters
A_L = A / 1000
V_NaOH1_L = V_NaOH1 / 1000
V_NaOH2_L = V_NaOH2 / 1000
V_HCl_L = V_HCl / 1000

# Calculate X
X = (C_HCl * V_HCl_L - 3 * 1.0e-4)  # mol
print(f"Na2CO3 concentration in mixture: {X:.2e} mol")


```

```python
# Program Name: chemical_equilibrium_energy_analysis.py
# Creation Date: 20250111
# Overview: Comprehensive program covering thermochemical analysis, coordination chemistry, buffer pH calculation, and combustion heat estimation
# Usage: Run with `python chemical_equilibrium_energy_analysis.py` in the terminal

# Install required packages
# pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# 1. Combustion Heat of Sucrose / スクロース燃焼熱量計算
# -----------------------------
m_water = 99  # g
M_water = 18.0  # g/mol
heat_per_mol = 5652  # kJ/mol
released_heat = m_water / M_water * (1 / 11) * heat_per_mol
print(f"Released heat from combustion: {released_heat:.0f} kJ")

# -----------------------------
# 2. Coordination Compound Analysis / 錯体のモル比計算
# -----------------------------
m_CoCl3_NH3_4 = 46.7
M_CoCl3_NH3_4 = 233.5
m_AgCl = 28.7
M_AgCl = 143.5

ratio = (m_CoCl3_NH3_4 / M_CoCl3_NH3_4) / (m_AgCl / M_AgCl)
print(f"Coordination compound to AgCl mole ratio: {ratio:.1f}:1")

# -----------------------------
# 3. Acetate Buffer pH Calculation / 酢酸緩衝液のpH計算
# -----------------------------
Ka_acetic = 2.7e-5  # 酢酸の酸解離定数 / Acetic acid dissociation constant
Kw = 1.0e-14       # 水のイオン積 / Water ion product
Cs = 1.0e-2        # 酢酸濃度 / Acetic acid concentration

# Case A: 未中和状態 / Before NaOH addition
H_conc_A = (Ka_acetic * Cs) ** 0.5
pH_A = -np.log10(H_conc_A)
print(f"pH before NaOH addition: {pH_A:.2f}")

# Case B: 半中和状態 / Half neutralized
H_conc_B = Ka_acetic
pH_B = -np.log10(H_conc_B)
print(f"pH at equivalence point: {pH_B:.2f}")

# Case C: 過剰NaOH / Excess NaOH
OH_conc_C = 1.0e-1 * 20 / 30  # mol/L
pOH_C = -np.log10(OH_conc_C)
pH_C = 14 - pOH_C
print(f"pH after excess NaOH: {pH_C:.2f}")

# -----------------------------
# Visualization / グラフ化
# -----------------------------
labels = [
    'Sucrose Combustion Heat (kJ)',
    'Coordination Ratio (CoCl3(NH3)4 : AgCl)',
    'pH Before NaOH',
    'pH Equivalence',
    'pH After Excess NaOH'
]
values = [
    released_heat,
    ratio,
    pH_A,
    pH_B,
    pH_C
]

plt.figure(figsize=(10, 6))
plt.bar(labels, values, color=['skyblue', 'lightcoral', 'lightgreen', 'orange', 'purple'])
plt.title('Comprehensive Chemical Calculations')
plt.ylabel('Values')
plt.xticks(rotation=15)
plt.tight_layout()
plt.show()


```
```python
# Program Name: molecular_speed_distribution.py
# Creation Date: 20250111
# Overview: Visualization of Maxwell-Boltzmann molecular speed distributions for O2 and H2
# Usage: Run with `python molecular_speed_distribution.py` in terminal

# Install required packages
# pip install numpy matplotlib

import numpy as np  # 数値計算 / Numerical computation
import matplotlib.pyplot as plt  # グラフ描画 / Plotting

# -----------------------------
# Constants and Parameters / 定数・パラメータ設定
# -----------------------------
kB = 1.38e-23  # Boltzmann constant (J/K) / ボルツマン定数
T = 300  # Temperature (K) / 温度
m_O2 = 32e-3 / 6.022e23  # Mass of O2 molecule (kg) / 酸素分子質量
m_H2 = 2e-3 / 6.022e23  # Mass of H2 molecule (kg) / 水素分子質量

v = np.linspace(0, 3000, 500)  # Speed range / 速度範囲

# Maxwell-Boltzmann Distribution Function / マクスウェル・ボルツマン分布関数
def mb_distribution(m, T, v):
    factor = 4 * np.pi * (m / (2 * np.pi * kB * T))**1.5
    return factor * v**2 * np.exp(-m * v**2 / (2 * kB * T))

# -----------------------------
# Calculation / 計算
# -----------------------------
f_O2 = mb_distribution(m_O2, T, v)
f_H2 = mb_distribution(m_H2, T, v)

# -----------------------------
# Plot / グラフ描画
# -----------------------------
plt.figure(figsize=(8, 5))
plt.plot(v, f_O2, label='O2', linestyle='solid')
plt.plot(v, f_H2, label='H2', linestyle='dashed')
plt.title('Maxwell-Boltzmann Speed Distribution at 300K')
plt.xlabel('Molecular Speed (m/s)')
plt.ylabel('Probability Density')
plt.legend()
plt.grid(True)
plt.show()


```

```python
# ライブラリのインストール (コメントのみ) / Library installation command (comment only)
# pip install numpy matplotlib

import numpy as np
import matplotlib.pyplot as plt

# Program Name: chemical_reaction_suite.py
# Creation Date: 20250111
# Overview: A unified program to perform chemical calculations including stoichiometry, gas laws, titration, ion exchange, and energy computations with graphical output
# Usage: Run using `python chemical_reaction_suite.py`

# ----------------------------------------
# 1. Molar Concentration Calculation Example / モル濃度計算例
# ----------------------------------------
mass_solute = 69.0e-3  # g
molar_mass_solute = 138  # g/mol
volume_solution = 500e-3  # L
c_standard = (mass_solute / molar_mass_solute) / volume_solution  # mol/L
print(f"Standard solution concentration: {c_standard:.2e} mol/L")

# ----------------------------------------
# 2. Absorbance-Based Concentration Calculation / 吸光度から濃度の計算
# ----------------------------------------
absorbance_sample = 0.172 - 0.007
absorbance_standard = 0.073 - 0.007
c_sample = c_standard * absorbance_sample / absorbance_standard  # mol/L
print(f"Sample concentration from absorbance: {c_sample:.2e} mol/L")

# ----------------------------------------
# 3. Stoichiometry-Based Gas Volume Calculation / 化学反応式に基づく気体体積計算
# ----------------------------------------
R = 8.314  # J/(mol*K)
T = 273 + 0  # K
P = 101325  # Pa
V_molar = 22.4  # L/mol at STP

moles_CO2 = 88 / 44  # mol
volume_CO2 = moles_CO2 * V_molar  # L
print(f"Volume of CO2: {volume_CO2:.1f} L")

# ----------------------------------------
# 4. Arrhenius Plot Calculation / アレニウスプロット計算
# ----------------------------------------
T1 = 320  # K
T2 = 290  # K
Ea = 61200  # J/mol
R = 8.314  # J/(mol*K)
log_k_ratio = -Ea / R * (1/T2 - 1/T1)



```

```python
# -*- coding: utf-8 -*-
# Program Name: chemistry_calculation_suite.py
# Overview: Unified program for density, stoichiometry, equilibrium, and gas law calculations.
# Usage: Run with `python chemistry_calculation_suite.py`

import numpy as np

# -----------------------------
# 1. Crystal Structure Calculation / 結晶構造計算
def calc_density(a_cm, Z, M, NA):
    """密度計算 Density calculation"""
    volume_cm3 = a_cm**3  # 体積 [cm^3]
    density = (Z * M) / (NA * volume_cm3)  # 密度 [g/cm^3]
    return density

# -----------------------------
# 2. Stoichiometry Calculation / 反応量計算
def calc_required_mass(molar_mass, moles):
    """モル数から質量を計算 Calculate mass from moles"""
    return molar_mass * moles

# -----------------------------
# 3. Equilibrium Constant Calculation / 平衡定数計算
def calc_equilibrium_constant(conc_products, conc_reactants, stoichiometry_products, stoichiometry_reactants):
    """平衡定数計算 Equilibrium constant calculation"""
    product_term = np.prod([c**n for c, n in zip(conc_products, stoichiometry_products)])
    reactant_term = np.prod([c**n for c, n in zip(conc_reactants, stoichiometry_reactants)])
    return product_term / reactant_term

# -----------------------------
# 4. Ideal Gas Law / 理想気体法則
def calc_molar_mass(P, V, R, T, m):
    """理想気体法則からモル質量を計算 Calculate molar mass using ideal gas law"""
    return (m * R * T) / (P * V)

# -----------------------------
# Example Usage / 使い方例

# 1. Crystal Structure Example
a_cm = 4.26e-8  # 単位格子の1辺 [cm]
Z = 4  # 原子数
M = 47.867  # チタンのモル質量 [g/mol]
NA = 6.02e23  # アボガドロ数
density_result = calc_density(a_cm, Z, M, NA)
print(f"Density: {density_result:.2f} g/cm^3")

# 2. Stoichiometry Example
molar_mass_H2O = 18.015  # 水のモル質量 [g/mol]
required_mass_H2O = calc_required_mass(molar_mass_H2O, 2.0)
print(f"Required mass of H2O for 2 mol: {required_mass_H2O:.2f} g")

# 3. Equilibrium Constant Example
conc_products = [0.08]  # NO2 concentration [mol/L]
conc_reactants = [0.02]  # N2O4 concentration [mol/L]
stoichiometry_products = [2]
stoichiometry_reactants = [1]
Kc_result = calc_equilibrium_constant(conc_products, conc_reactants, stoichiometry_products, stoichiometry_reactants)
print(f"Equilibrium Constant Kc: {Kc_result:.2e}")

# 4. Ideal Gas Law Example
P = 101325  # 圧力 [Pa]
V = 0.024  # 体積 [m^3]
R = 8.314  # 気体定数 [J/(mol·K)]
T = 273.15 + 173  # 絶対温度 [K]
m = 0.378  # 質量 [g]
molar_mass_result = calc_molar_mass(P, V, R, T, m)
print(f"Molar Mass: {molar_mass_result:.2f} g/mol")

# -----------------------------
# End of Program


```