Note
Go to the end to download the full example code.
Tutorial: RockyChem#
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!):
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
mol_endmems_tbl = rockychem.convert_phase_comp_table('Ol', wt_oxides=wt_oxides_tbl, to='mol_endmems')
mol_endmems_tbl
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 ...
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 1.790509e-01
TiO2 0.000000e+00
Al2O3 4.635782e-02
Fe2O3 4.440892e-16
MgCr2O4 0.000000e+00
Fe2SiO4 5.734456e-02
MnSi1d2O2 0.000000e+00
Mg2SiO4 4.547891e-01
NiSi1d2O2 0.000000e+00
CoSi1d2O2 0.000000e+00
CaSiO3 6.740443e-02
Na2SiO3 5.647079e-03
KAlSiO4 8.492984e-04
Ca3P2O8 0.000000e+00
H2O 0.000000e+00
CO2 0.000000e+00
dtype: float64
Total running time of the script: (0 minutes 0.110 seconds)