This page was generated from docs/Installation/MAGEMin_PythonCall.ipynb. Interactive online version: Binder badge.

Python Notebook Download

Please download this notebook (use the links above to find the source file) and run the following installation script as a notebook.

Running MAGEMin calculations through Julia

PetThermoTools provides the ability to run calculations/models that utilize the recent Weller et al. (2024) and Green et al. (2025) thermodynamic models. Once everything is set up you should be able to run these calculations from the same functions used to run models with alphaMELTS, but simply setting the Model kwarg to Green2025 or Weller2024.

I’ve worked hard to try and ensure a set up routine that works on every operating system, regardless of prior installations etc. There is, however, a good chance you’ll come across a bug/issue I haven’t seen before. If there is an issue in the following script/functions please email me (gleesonm@berkeley.edu) and I will try to find a fix as quickly as possible!

The following notebook and functions will establish a new julia environment on your machine. From PetThermoTools v0.2.51 and later this environment will be activated whenever a MAGEMin calculation is initialized from Python. This should ensure that any prior julia installations/packages on your machine are not influenced by the following installation routine.

Step 1 - install juliacall

Uncomment the line below and install juliacall in your Python environment

[1]:
%pip install juliacall

Step 2 - Install MAGEMin

Import PetThermoTools (install it if you haven’t done so yet) and then use the inbuilt functions to install MAGEMin_C and MAGEMinCalc using the function below. You will need top uncomment the function to run it. If you’ve previously run this section successfully import PetThermoTools and then go to Step 2b to update the MAGEMinCalc and MAGEMin_C installations.

[ ]:
# %pip install petthermotools #### If running on Victor uncomment this line to install petthermotools
[2]:
import petthermotools as ptt
ptt.__version__  # should ve v0.3.2 or later
[2]:
'0.2.50'

This code installs MAGEMinCalc and underlying dependencies in julia and links them to the PetThermoTools installation. In a couple of cases the code below has caused the Python kernel to crash AFTER it completed. Therefore if a kernel crash message appears don’t worry, just restart the kernel and procede to the test_MAGEMinCalc() function below (step 3).

[1]:
# ptt.install_MAGEMinCalc()
Detected IPython. Loading juliacall extension. See https://juliapy.github.io/PythonCall.jl/stable/compat/#IPython

Step 2b - Update MAGEMin

If you’ve previously run the cell above but need to update the MAGEMinCalc and MAGEMin_C versions following a PetThermoTools update, uncomment and run the cell below.

[ ]:
# ptt.update_MAGEMinCalc()

Step 3 - test the installation

Test the installation by running the following cell. This is calling the MAGEMinCalc functions directly with Julia code using juliacall. This is different to how the code is usually initiated in PetThermoTools but it provides an initial test of the installation. If successful it should print a Pandas DataFrame containing the predicted melt compositions in this crystallization example:

[3]:
import petthermotools as ptt
ptt.test_MAGEMinCalc()
Detected IPython. Loading juliacall extension. See https://juliapy.github.io/PythonCall.jl/stable/compat/#IPython
  Activating project at `~/.petthermotools_julia_env`
Using libMAGEMin.dylib from MAGEMin_jll
ig
        SiO2     Al2O3       CaO       MgO       FeO       K2O      Na2O  \
0   0.476276  0.164428  0.116295  0.094047  0.091816  0.003300  0.022550
1   0.476311  0.164655  0.116482  0.093537  0.091797  0.003303  0.022572
2   0.476372  0.164888  0.116645  0.093026  0.091774  0.003308  0.022591
3   0.476457  0.165156  0.116821  0.092516  0.091697  0.003310  0.022631
4   0.476543  0.165356  0.116959  0.092003  0.091674  0.003320  0.022656
5   0.476600  0.165608  0.117127  0.091486  0.091618  0.003329  0.022694
6   0.476679  0.165815  0.117307  0.090978  0.091546  0.003333  0.022732
7   0.476789  0.166014  0.117475  0.090462  0.091522  0.003335  0.022770
8   0.476880  0.166223  0.117647  0.089953  0.091484  0.003334  0.022805
9   0.476950  0.166455  0.117817  0.089452  0.091448  0.003335  0.022832
10  0.477000  0.166718  0.117983  0.088940  0.091416  0.003341  0.022873
11  0.477076  0.166931  0.118146  0.088434  0.091400  0.003346  0.022902
12  0.477175  0.167173  0.118310  0.087938  0.091324  0.003351  0.022929
13  0.477512  0.166383  0.118264  0.087365  0.091864  0.003391  0.023051
14  0.477879  0.165479  0.118174  0.086766  0.092514  0.003433  0.023204
15  0.478265  0.164558  0.118119  0.086183  0.093117  0.003471  0.023343
16  0.478611  0.163675  0.118050  0.085598  0.093742  0.003508  0.023492
17  0.478997  0.162752  0.118011  0.085013  0.094356  0.003543  0.023624
18  0.479347  0.161876  0.117955  0.084430  0.094978  0.003584  0.023763
19  0.479771  0.161012  0.117863  0.083845  0.095535  0.003623  0.023925
20  0.480103  0.160162  0.117809  0.083265  0.096122  0.003669  0.024066
21  0.480534  0.159303  0.117741  0.082700  0.096644  0.003703  0.024214
22  0.480895  0.158471  0.117714  0.082138  0.097164  0.003750  0.024355
23  0.481259  0.157630  0.117662  0.081582  0.097704  0.003789  0.024484
24  0.481612  0.156804  0.117614  0.081026  0.098244  0.003825  0.024617
25  0.481952  0.155991  0.117584  0.080473  0.098763  0.003862  0.024749
26  0.482334  0.155181  0.117545  0.079926  0.099240  0.003904  0.024882
27  0.482719  0.154380  0.117509  0.079371  0.099720  0.003947  0.025018
28  0.483126  0.153597  0.117465  0.078832  0.100174  0.003983  0.025159
29  0.483514  0.152812  0.117411  0.078288  0.100661  0.004017  0.025291
30  0.483862  0.152069  0.117362  0.077749  0.101109  0.004057  0.025432
31  0.484211  0.151313  0.117314  0.077214  0.101582  0.004092  0.025564
32  0.484575  0.150554  0.117281  0.076686  0.102022  0.004128  0.025697
33  0.484889  0.149806  0.117269  0.076159  0.102501  0.004163  0.025813
34  0.485042  0.149335  0.116734  0.075553  0.103250  0.004211  0.026014
35  0.485015  0.149040  0.115916  0.074903  0.104195  0.004276  0.026244
36  0.484982  0.148746  0.115101  0.074247  0.105152  0.004341  0.026478
37  0.485004  0.148464  0.114279  0.073590  0.106026  0.004408  0.026728
38  0.485038  0.148184  0.113454  0.072940  0.106889  0.004477  0.026976
39  0.485008  0.147910  0.112657  0.072295  0.107785  0.004542  0.027209
40  0.484987  0.147646  0.111858  0.071646  0.108649  0.004603  0.027460
41  0.484978  0.147392  0.111066  0.070993  0.109497  0.004671  0.027712
42  0.484962  0.147126  0.110273  0.070343  0.110348  0.004733  0.027960
43  0.484908  0.146875  0.109500  0.069696  0.111193  0.004805  0.028195
44  0.484893  0.146627  0.108723  0.069059  0.111993  0.004873  0.028432
45  0.484844  0.146382  0.107957  0.068416  0.112815  0.004937  0.028674
46  0.484855  0.146123  0.107177  0.067779  0.113597  0.005016  0.028898
47  0.484798  0.145888  0.106427  0.067160  0.114373  0.005075  0.029125

        TiO2         O  Cr2O3       H2O
0   0.022949  0.001523    0.0  0.006816
1   0.022999  0.001524    0.0  0.006820
2   0.023036  0.001527    0.0  0.006833
3   0.023041  0.001530    0.0  0.006842
4   0.023102  0.001532    0.0  0.006855
5   0.023143  0.001535    0.0  0.006859
6   0.023204  0.001537    0.0  0.006869
7   0.023219  0.001539    0.0  0.006876
8   0.023247  0.001540    0.0  0.006887
9   0.023271  0.001543    0.0  0.006897
10  0.023279  0.001545    0.0  0.006906
11  0.023301  0.001547    0.0  0.006916
12  0.023329  0.001548    0.0  0.006923
13  0.023601  0.001566    0.0  0.007003
14  0.023880  0.001584    0.0  0.007088
15  0.024170  0.001602    0.0  0.007173
16  0.024446  0.001622    0.0  0.007259
17  0.024727  0.001639    0.0  0.007337
18  0.024990  0.001658    0.0  0.007420
19  0.025249  0.001675    0.0  0.007502
20  0.025529  0.001692    0.0  0.007581
21  0.025786  0.001709    0.0  0.007665
22  0.026039  0.001728    0.0  0.007747
23  0.026318  0.001747    0.0  0.007826
24  0.026587  0.001766    0.0  0.007905
25  0.026857  0.001783    0.0  0.007985
26  0.027125  0.001800    0.0  0.008064
27  0.027380  0.001815    0.0  0.008141
28  0.027608  0.001832    0.0  0.008225
29  0.027855  0.001848    0.0  0.008303
30  0.028111  0.001864    0.0  0.008385
31  0.028366  0.001882    0.0  0.008463
32  0.028620  0.001901    0.0  0.008535
33  0.028872  0.001919    0.0  0.008610
34  0.029197  0.001941    0.0  0.008722
35  0.029589  0.001966    0.0  0.008856
36  0.029977  0.001991    0.0  0.008987
37  0.030368  0.002011    0.0  0.009121
38  0.030751  0.002035    0.0  0.009256
39  0.031142  0.002059    0.0  0.009393
40  0.031538  0.002082    0.0  0.009529
41  0.031921  0.002104    0.0  0.009667
42  0.032327  0.002127    0.0  0.009801
43  0.032743  0.002149    0.0  0.009937
44  0.033147  0.002172    0.0  0.010079
45  0.033565  0.002195    0.0  0.010217
46  0.033984  0.002217    0.0  0.010354
47  0.034410  0.002242    0.0  0.010502

Step 4 - Restart the kernel and test running calculations through PetThermoTools

Assuming the crystallization model above ran without any issues we can now progress to testing the integration of MAGEMin with PetThermoTools. First make sure you have the up to date version of PetThermoTools installed (v0.2.51 or later). Restart the kernel and then run the 3 cells below.

[4]:
import petthermotools as ptt
ptt.__version__
[4]:
'0.2.50'
[5]:
comp = {"SiO2_Liq": 47.5,
        "Al2O3_Liq": 16.4,
        "CaO_Liq": 11.6,
        "MgO_Liq": 9.38,
        "FeOt_Liq": 9.16,
        "K2O_Liq": 0.329,
        "Na2O_Liq": 2.25,
        "TiO2_Liq": 2.29,
        "Fe3Fet_Liq": 0.15,
        "Cr2O3_Liq": 0.0,
        "H2O_Liq": 0.68}

Results = ptt.isobaric_crystallisation(bulk=comp,
                             Model = "Green2025",
                             dt_C = 2.0,
                             T_end_C=1100.0,
                             P_bar=1000.0,
                             find_liquidus=True,
                             Frac_solid=True)
Running Green2025 calculation... Complete (time taken = 37.55 seconds)
  Activating project at `~/.petthermotools_julia_env`
Detected IPython. Loading juliacall extension. See https://juliapy.github.io/PythonCall.jl/stable/compat/#IPython
Using libMAGEMin.dylib from MAGEMin_jll
ig
[6]:
import matplotlib.pyplot as plt
plt.plot(Results["All"]["MgO_Liq"], Results["All"]["FeOt_Liq"], '-r')
plt.xlabel('MgO')
plt.ylabel('FeO$_t$')
[6]:
Text(0, 0.5, 'FeO$_t$')
../_images/Installation_MAGEMin_PythonCall_15_1.png

Step 5 - use PetThermoTools alongside MAGEMin in your research!