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!):

https://mybinder.org/badge_logo.svg

Initialization#

Import necessary packages:

import numpy as np
import pandas as pd
import thermoengine
from thermoengine import rockychem, model

OXIDE_WTS = rockychem.OXIDE_WTS

A simple test for converting bulk compositions#

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')
print(wt_oxides)
print('---')

print(mol_elems)
print('---')

print(mol_oxides)
print('---')

print('... and converting in the reverse direction ...')
print(wt_oxides_rev)
print('---')
{'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
---

Converting entire tables#

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')
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('---')
            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
---

Examples converting phase compositions#

  • You must provide a phase abbreviation. Here is the list of available abbreviations

database = model.Database(database_name='MELTS_v1_2')
database.phase_list
['Ol', 'Fsp', 'Cpx', 'Opx', 'SplS', 'Qz', 'Trd', 'Ky', 'And', 'Sil', 'Fl', 'Grt', 'Liq']
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
Tephroite       0.00
Fayalite        0.25
Coolivine       0.00
Niolivine       0.00
Monticellite    0.00
Forsterite      0.75
dtype: float64

Converting a table of phase compositions#

  • Note these must all be the same phase

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
input
MgO FeO SiO2
Mg2SiO4 80.6088 0.0000 60.0848
Mg1Fe1SiO4 40.3044 71.8464 60.0848
Fe2SiO4 0.0000 143.6928 60.0848


mol_endmems_tbl = rockychem.convert_phase_comp_table('Ol', wt_oxides=wt_oxides_tbl, to='mol_endmems')
mol_endmems_tbl
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


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
... and in the reverse direction ...
SiO2 FeO MgO
Mg2SiO4 60.0848 0.0000 80.6088
Mg1Fe1SiO4 60.0848 71.8464 40.3044
Fe2SiO4 60.0848 143.6928 0.0000


A simplified BSE composition (Schaefer & Fegley, 2009)#

  • Converting a bulk composition to liquid endmembers

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
{'SiO2': 45.97, 'MgO': 36.66, 'Al2O3': 4.77, 'FeO': 8.24, 'CaO': 3.78, 'Na2O': 0.35, 'K2O': 0.04}
mol_endmems = rockychem.convert_phase_comp('Liq', wt_oxides=BSE_wt_oxides, to='mol_endmems')
mol_endmems
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

Total running time of the script: (0 minutes 0.096 seconds)

Gallery generated by Sphinx-Gallery