'''
VapoRock: Equilibrium Outgassing
=================================

Demonstrates how to run an equilibrium vaporization routine using VapoRock.

If you want to run this locally, install Vaporock by running the following command in a terminal:

`pip install vaporock@git+https://gitlab.com/ENKI-portal/vaporock@thermoenginelite-port#subdirectory=src`

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%2Fplot_vaporock_outgassing.ipynb
'''

# %% 
# Initialization
# --------------
#
# Import necessary packages:

import vaporock
import numpy as np


# %% 
# Set Melt Composition, Temp., redox
# ----------------------------------
#
# a simplified BSE composition (Schaefer & Fegley, 2009)
melt_comp_wts = {
    'SiO2':45.97, 
    'MgO':36.66, 
    'Al2O3':4.77, 
    'FeO':8.24, 
    'CaO':3.78, 
    'Na2O':0.35, 
    'K2O':0.04}

T = np.linspace(1500,3000,101)
buffer = 'IW'
dlogfO2 = +1.5
logfO2 = vaporock.redox_buffer(T, buffer=buffer, dlogfO2=dlogfO2)


# %% 
# Initialize system & predict gas abundances
# ------------------------------------------
system = vaporock.System()
system.set_melt_comp(melt_comp_wts)
system.print_melt_comp()
logP, lnK, lna =  system.eval_gas_abundances(T, logfO2, full_output=True)


# %% 
# Plot vapor species in different ways
# ------------------------------------
vaporock.plot.partial_pressure(T, logP)

# %%
vaporock.plot.species_mol_frac(T, logP)

# %%
mol_elem_frac, Ptotal = system.calc_gas_props(T, logP)
vaporock.plot.element_mol_frac(T, mol_elem_frac)

# %%
