.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/_4_unorganized/plot_supplemental_calculator.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples__4_unorganized_plot_supplemental_calculator.py: Calculator: Liquid Properties =========================================== This notebook calculates the activity of endmembers within a liquid. It replaces the functionality previously implemented by the MELTS Supplemental Calculator (https://melts.ofm-research.org/CalcForms/) This calculator is a work in progress -- please let us know if you find any errors! Open this code in an executable MyBinder instance (MyBinder links may be slow to load-- please be patient!): .. image:: https://mybinder.org/badge_logo.svg :target: https://mybinder.org/v2/gl/swmatthews-research%2FThermoEngineLite/main?urlpath=%2Fdoc%2Ftree%2F.%2Fdoc%2Fsource%2Fauto_examples%2F_4_unorganized%2Fsupplemental_calculator.ipynb .. GENERATED FROM PYTHON SOURCE LINES 18-23 User Input ---------- 1. Input liquid composition in wt% oxides, temperature, pressure, and log(fO2) below 2. Once you have input your data in the cell above, click "Run" --> "Run All Cells" at the top of the notebook. This will run the entire notebook and produce the output table at the bottom of the file. .. GENERATED FROM PYTHON SOURCE LINES 23-41 .. code-block:: Python oxide_wt_dict = { 'SiO2': 48.4012, 'TiO2': 0.9208, 'Al2O3': 14.9349, 'FeO': 9.0825, 'MnO': 0.1587, 'MgO': 8.1285, 'CaO': 14.1368, 'Na2O': 1.3124, 'K2O': 0.1462, 'P2O5': 0.001 } TK = 1500 + 273.15 # temperature value in K Pbar = 15000 # pressure value in bar logfO2 = None # can replace this with a value for absolute logfO2 (not relative to a buffer). Otherwise, calculates with given Fe2O3 value. .. GENERATED FROM PYTHON SOURCE LINES 42-46 Calculations ------------ The user does not need to modify this code-- it will run automatically when "Run All Cells" is triggered. .. GENERATED FROM PYTHON SOURCE LINES 46-109 .. code-block:: Python ###----------------------------------------------------------------------------------------- ### 0. Import modules ###----------------------------------------------------------------------------------------- import numpy as np import pandas as pd from thermoengine import model, equilibrate, chemistry from thermoengine.core import chem from thermoengine import redox ###----------------------------------------------------------------------------------------- ### 1. Calculate oxide moles ###----------------------------------------------------------------------------------------- oxide_moles = chem.format_mol_oxide_comp(oxide_wt_dict, convert_grams_to_moles=True) oxide_moles_ser = pd.Series(oxide_moles, index=chemistry.OXIDES) oxide_dict_for_fO2 = {'Liq': oxide_moles} ###----------------------------------------------------------------------------------------- ### 2. Adjust composition to be consistent with log fO2 input ###----------------------------------------------------------------------------------------- if logfO2 is not None: ln_Fe_oxide_ratio = redox.redox_state(TK, Pbar, oxide_comp=oxide_dict_for_fO2, logfO2=logfO2, phase_of_interest='Liq', method='Kress91') Fe2O3_FeO = np.exp(ln_Fe_oxide_ratio) oxide_moles_ser = redox.impose_redox_ratio(Fe2O3_FeO, oxide_moles_ser) ###----------------------------------------------------------------------------------------- ### 3. Create liquid phase instance ###----------------------------------------------------------------------------------------- liquid = model.Database(database_name="MELTS_v1_2").get_phase('Liq') liq_end = liquid.calc_endmember_comp(oxide_moles_ser.values, method='least_squares', output_residual=False, normalize=False, decimals=10) ###----------------------------------------------------------------------------------------- ### 4. Calculate Gibbs Free Energies of Formation ###----------------------------------------------------------------------------------------- end_array = np.identity(liquid.endmember_num) G_array = np.zeros(liquid.endmember_num) for i in range(liquid.endmember_num): G = liquid.gibbs_energy(TK,Pbar,mol=end_array[i,:]) G_array[i] = G ###----------------------------------------------------------------------------------------- ### 5. Calculate Activities ###----------------------------------------------------------------------------------------- activities = liquid.activity(TK, Pbar, mol=liq_end) ###----------------------------------------------------------------------------------------- ### 6. Combine and display data ###----------------------------------------------------------------------------------------- data = {'Endmember': liquid.endmember_names, 'Gibbs Energy (kJ)': G_array/1000, 'Activity': activities} endmember_df = pd.DataFrame(data) pd.set_option('display.max_rows', None) endmember_df .. raw:: html
Endmember Gibbs Energy (kJ) Activity
0 SiO2 -1050.282020 4.198614e-01
1 TiO2 -1112.094551 1.496124e-02
2 Al2O3 -1869.998639 1.819664e-02
3 Fe2O3 -1135.210021 4.429234e-15
4 MgCr2O4 -2121.645896 4.675668e-14
5 Fe2SiO4 -1965.299041 7.973553e-02
6 MnSi1d2O2 -1101.278238 3.264872e-03
7 Mg2SiO4 -2505.085643 6.230201e-02
8 NiSi1d2O2 -903.273135 2.989758e-14
9 CoSi1d2O2 -953.308267 1.272200e-14
10 CaSiO3 -1896.887083 1.720157e-01
11 Na2SiO3 -1939.155257 2.976616e-04
12 KAlSiO4 -2509.371033 3.003395e-03
13 Ca3P2O8 -4858.938309 2.601364e-04
14 H2O -462.507375 5.761648e-28
15 CO2 -600.511436 1.829513e-14


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.021 seconds) .. _sphx_glr_download_auto_examples__4_unorganized_plot_supplemental_calculator.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_supplemental_calculator.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_supplemental_calculator.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_supplemental_calculator.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_