.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/_4_unorganized/plot_rockychem_basics.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_rockychem_basics.py: Rockychem Basics: Converting Rocky Compositions =============================================== Demonstrates how to easily perform typical compositional conversions using Rockychem. 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%2Frockychem_basics.ipynb .. GENERATED FROM PYTHON SOURCE LINES 14-18 Initialization -------------- Import necessary packages: .. GENERATED FROM PYTHON SOURCE LINES 18-26 .. code-block:: Python import numpy as np import pandas as pd import thermoengine from thermoengine import rockychem, model OXIDE_WTS = rockychem.OXIDE_WTS .. GENERATED FROM PYTHON SOURCE LINES 27-29 A simple test for converting bulk compositions ---------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 29-41 .. code-block:: Python wt_oxides = { 'MgO' : 2*OXIDE_WTS['MgO'], 'SiO2': 1*OXIDE_WTS['SiO2']} mol_elems = rockychem.convert_bulk_comp(wt_oxides=wt_oxides, to='mol_elems') mol_oxides = rockychem.convert_bulk_comp(wt_oxides=wt_oxides, to='mol_oxides') wt_oxides_rev = rockychem.convert_bulk_comp(mol_oxides=mol_oxides, to='wt_oxides') .. GENERATED FROM PYTHON SOURCE LINES 42-57 .. code-block:: Python print(wt_oxides) print('---') print(mol_elems) print('---') print(mol_oxides) print('---') print('... and converting in the reverse direction ...') print(wt_oxides_rev) print('---') .. rst-class:: sphx-glr-script-out .. code-block:: none {'MgO': 80.6088, 'SiO2': 60.0848} --- Si 1.0 Mg 2.0 O 4.0 dtype: float64 --- SiO2 1.0 MgO 2.0 dtype: float64 --- ... and converting in the reverse direction ... SiO2 60.0848 MgO 80.6088 dtype: float64 --- .. GENERATED FROM PYTHON SOURCE LINES 58-60 Converting entire tables ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 62-74 .. code-block:: Python wt_oxides_tbl = pd.DataFrame({ 'SiO2': {'SiO2' : OXIDE_WTS['SiO2']}, 'MgSiO3': {'MgO' : OXIDE_WTS['MgO'], 'SiO2':OXIDE_WTS['SiO2']}, 'Mg2SiO4': {'MgO' : 2*OXIDE_WTS['MgO'], 'SiO2':OXIDE_WTS['SiO2']}, 'MgO': {'MgO' : OXIDE_WTS['MgO']}}, index=['SiO2','MgO']).fillna(0).T mol_elems_tbl = rockychem.convert_bulk_comp_table(wt_oxides=wt_oxides_tbl, to='mol_elems') mol_oxides_tbl = rockychem.convert_bulk_comp_table(wt_oxides=wt_oxides_tbl, to='mol_oxides') wt_oxides_rev_tbl = rockychem.convert_bulk_comp_table(mol_elems=mol_elems_tbl, to='wt_oxides') .. GENERATED FROM PYTHON SOURCE LINES 75-88 .. code-block:: Python print(wt_oxides_tbl) print('---') print(mol_elems_tbl) print('---') print(mol_oxides_tbl) print('---') print('') print('... and converting in the reverse direction ...') print(wt_oxides_rev_tbl) print('---') .. rst-class:: sphx-glr-script-out .. code-block:: none SiO2 MgO SiO2 60.0848 0.0000 MgSiO3 60.0848 40.3044 Mg2SiO4 60.0848 80.6088 MgO 0.0000 40.3044 --- Si Mg O SiO2 1.0 0.0 2.0 MgSiO3 1.0 1.0 3.0 Mg2SiO4 1.0 2.0 4.0 MgO 0.0 1.0 1.0 --- SiO2 MgO SiO2 1.0 0.0 MgSiO3 1.0 1.0 Mg2SiO4 1.0 2.0 MgO 0.0 1.0 --- ... and converting in the reverse direction ... SiO2 MgO SiO2 60.0848 0.0000 MgSiO3 60.0848 40.3044 Mg2SiO4 60.0848 80.6088 MgO 0.0000 40.3044 --- .. GENERATED FROM PYTHON SOURCE LINES 89-91 Examples converting phase compositions ---------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 93-94 - **You must provide a phase abbreviation. Here is the list of available abbreviations** .. GENERATED FROM PYTHON SOURCE LINES 96-100 .. code-block:: Python database = model.Database(database_name='MELTS_v1_2') database.phase_list .. rst-class:: sphx-glr-script-out .. code-block:: none ['Ol', 'Fsp', 'Cpx', 'Opx', 'SplS', 'Qz', 'Trd', 'Ky', 'And', 'Sil', 'Fl', 'Grt', 'Liq'] .. GENERATED FROM PYTHON SOURCE LINES 101-109 .. code-block:: Python wt_oxides = { 'MgO' : 1.5*OXIDE_WTS['MgO'], 'FeO' : 0.5*OXIDE_WTS['FeO'], 'SiO2': 1*OXIDE_WTS['SiO2']} mol_endmems = rockychem.convert_phase_comp('Ol', wt_oxides=wt_oxides, to='mol_endmems') mol_endmems .. rst-class:: sphx-glr-script-out .. code-block:: none Tephroite 0.00 Fayalite 0.25 Coolivine 0.00 Niolivine 0.00 Monticellite 0.00 Forsterite 0.75 dtype: float64 .. GENERATED FROM PYTHON SOURCE LINES 110-113 Converting a table of phase compositions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Note these must all be the same phase .. GENERATED FROM PYTHON SOURCE LINES 113-123 .. code-block:: Python wt_oxides_tbl = pd.DataFrame({ 'Mg2SiO4': {'MgO' : 2*OXIDE_WTS['MgO'], 'SiO2':OXIDE_WTS['SiO2']}, 'Mg1Fe1SiO4': {'MgO' : 1*OXIDE_WTS['MgO'], 'FeO':1*OXIDE_WTS['FeO'], 'SiO2':OXIDE_WTS['SiO2']}, 'Fe2SiO4': {'FeO' : 2*OXIDE_WTS['FeO'], 'SiO2':OXIDE_WTS['SiO2']} }, index=['MgO','FeO','SiO2']).fillna(0).T print('input') wt_oxides_tbl .. rst-class:: sphx-glr-script-out .. code-block:: none input .. raw:: html
MgO FeO SiO2
Mg2SiO4 80.6088 0.0000 60.0848
Mg1Fe1SiO4 40.3044 71.8464 60.0848
Fe2SiO4 0.0000 143.6928 60.0848


.. GENERATED FROM PYTHON SOURCE LINES 124-128 .. code-block:: Python mol_endmems_tbl = rockychem.convert_phase_comp_table('Ol', wt_oxides=wt_oxides_tbl, to='mol_endmems') mol_endmems_tbl .. raw:: html
Tephroite Fayalite Coolivine Niolivine Monticellite Forsterite
Mg2SiO4 0.0 0.0 0.0 0.0 0.0 1.0
Mg1Fe1SiO4 0.0 0.5 0.0 0.0 0.0 0.5
Fe2SiO4 0.0 1.0 0.0 0.0 0.0 0.0


.. GENERATED FROM PYTHON SOURCE LINES 129-134 .. code-block:: Python print('... and in the reverse direction ...') wt_oxides_rev_tbl = rockychem.convert_phase_comp_table('Ol', mol_endmems=mol_endmems_tbl, to='wt_oxides') wt_oxides_rev_tbl .. rst-class:: sphx-glr-script-out .. code-block:: none ... and in the reverse direction ... .. raw:: html
SiO2 FeO MgO
Mg2SiO4 60.0848 0.0000 80.6088
Mg1Fe1SiO4 60.0848 71.8464 40.3044
Fe2SiO4 60.0848 143.6928 0.0000


.. GENERATED FROM PYTHON SOURCE LINES 135-138 A simplified BSE composition (Schaefer & Fegley, 2009) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Converting a bulk composition to liquid endmembers .. GENERATED FROM PYTHON SOURCE LINES 140-151 .. code-block:: Python BSE_wt_oxides = { 'SiO2':45.97, 'MgO':36.66, 'Al2O3':4.77, 'FeO':8.24, 'CaO':3.78, 'Na2O':0.35, 'K2O':0.04} BSE_wt_oxides .. rst-class:: sphx-glr-script-out .. code-block:: none {'SiO2': 45.97, 'MgO': 36.66, 'Al2O3': 4.77, 'FeO': 8.24, 'CaO': 3.78, 'Na2O': 0.35, 'K2O': 0.04} .. GENERATED FROM PYTHON SOURCE LINES 152-160 .. code-block:: Python mol_endmems = rockychem.convert_phase_comp('Liq', wt_oxides=BSE_wt_oxides, to='mol_endmems') mol_endmems .. rst-class:: sphx-glr-script-out .. code-block:: none SiO2 0.179051 TiO2 0.000000 Al2O3 0.046358 Fe2O3 0.000000 MgCr2O4 0.000000 Fe2SiO4 0.057345 MnSi1d2O2 0.000000 Mg2SiO4 0.454789 NiSi1d2O2 0.000000 CoSi1d2O2 0.000000 CaSiO3 0.067404 Na2SiO3 0.005647 KAlSiO4 0.000849 Ca3P2O8 0.000000 H2O 0.000000 CO2 0.000000 dtype: float64 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.096 seconds) .. _sphx_glr_download_auto_examples__4_unorganized_plot_rockychem_basics.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_rockychem_basics.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_rockychem_basics.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_rockychem_basics.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_