How to use EquationsOfState
in Python?
It may be attempting for Pythonistas to use this package in Python, without writing too much code. Luckily, Julia provides such a feature.
First, install
PyCall.jl
, following their instructions. Notice on macOS, that if you want to install Python frompyenv
, you may need to runenv PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.6.9
in terminal to install your
python
, or else Julia will throw anImportError: No module named site
See this issue and another issue for details.
Install
PyJulia
in Python. Please see its official tutorial for instructions.Open a (an) Python (IPython) session, start playing!
In [1]: from julia import Unitful In [2]: from julia.EquationsOfState.Collections import * In [3]: from julia.EquationsOfState import * In [4]: Murnaghan(1, 2, 3.0, 4) Out[4]: <PyCall.jlwrap EquationsOfState.Collections.Murnaghan{Float64}(1.0, 2.0, 3.0, 4.0)> In [5]: result = lsqfit( ...: BirchMurnaghan3rd(1, 2, 3.0, 0)(Pressure()), ...: [1, 2, 3, 4, 5], ...: [5, 6, 9, 8, 7], ...: ) In [6]: result.v0, result.b0, result.bp0 Out[6]: (1.1024687826913997, 29.308616965851673, 12.689089874230556) In [7]: from julia import Main In [8]: volumes = Main.eval("data[:, 1] .* UnitfulAtomic.bohr^3") In [9]: energies = Main.eval("data[:, 2] .* UnitfulAtomic.Ry") In [10]: Main.eval("EquationsOfState.NonlinearFitting.lsqfit(EquationsOfState.Collections.Murnaghan(224.445371 * UnitfulAtomic.bohr^3, 9.164446 * Unitful.GPa, 3.752432, -161.708856 * UnitfulAtomic.hartree)(EquationsOfState.Energy()), volumes, energies)") Out[10]: <PyCall.jlwrap EquationsOfState.Collections.Murnaghan{Unitful.Quantity{Float64,D,U} where U where D}(224.5018173532159 a₀^3, 8.896845579229117 GPa, 3.7238388137735674, -161.70884303138902 Eₕ)>
where
data
is copied from Julia:In [1]: data = Main.eval(""" ...: [ ...: 159.9086 -323.4078898 ⋮ ⋮ ...: 319.8173 -323.4105393 ...: ] ...: """ ...: )