pwtools.eos.ExternEOS

class pwtools.eos.ExternEOS(app=None, energy=None, volume=None, dir=None, bv_method='ev', verbose=True)[source]

Bases: FlexibleGetters

Base class for calling extern EOS-fitting executables. The class writes an input file, calls the app, loads E(V) fitted data and loads or calcutates P(V), B(V).

The number N of data points for the returned arrays (fitted curves) are handled by derived classes.

We have three “representations” of the data:

  1. input data E(V) : self.volume [Ang^3], self.energy [eV]

  2. fitted or calculated points : self.{ev,pv,bv} – 2d arrays (N,2) where N is the number of returned fitted points from the fitting app. N depends on the fitting app. For instance, in ElkEOSFit, you can use npoints to set N.

  3. Splines thru fitted or calculated (N,2) data ev,pv,bv : self.spl_{ev,pv,bv}.

ev, pv, bv, spl_ev, spl_pv, spl_bv, see fit() doc string.

Examples

>>> from pwtools import eos
>>> efit = eos.ElkEOSFit(app='eos.x', energy=ee, volume=vv)
>>> efit.fit()
>>> plot(vv, ee, 'o-', label='E(V) data')
>>> plot(efit.ev[:,0], efit.ev[:,1], label='E(V) fit')
>>> plot(efit.pv[:,0], efit.pv[:,1], label='P=-dE/dV')
>>> plot(efit.ev[:,0], efit.spl_ev(efit.ev[:,0]), label='spline E(V)')
>>> plot(efit.pv[:,0], efit.spl_pv(efit.pv[:,0]), label='spline P(V)')
>>> print "V0={v0} E0={e0} B0={b0} P0={p0}".format(**efit.get_min())

Notes

For derived classes: Implement _fit(), which sets self.{ev,pv}. bv and spl_bv are always calculated from ev or pv when fit() is called, see also calc_bv() and set_bv_method().

__init__(app=None, energy=None, volume=None, dir=None, bv_method='ev', verbose=True)[source]
Parameters:
  • app (str) – name of the executable ([/path/to/]eos.x), make sure that it is on your PATH or use an absolute path

  • energy (1d array [eV])

  • volume (1d array [Ang^3])

  • dir (str) – dir where in- and outfiles are written, default is the basename of “app” (e.g. “eos.x” for app=’/path/to/eos.x’)

  • bv_method (str, {'pv', 'ev'}) – Based on which quantity should B(V) and minimum properties be calculated. pv: based on P(V) ev: based on E(V)

  • verbose (bool) – print stdout and stderr of fitting tool

Methods

assert_attr(attr)

Raise AssertionError if self.<attr> is not set (is_set_attr() returns False.

assert_attr_lst(attr_lst)

assert_set_attr(attr)

Same as assert_attr(), but run try_set_attr() first.

assert_set_attr_lst(attr_lst)

calc_bv()

check_set_attr(attr)

Run try_set_attr() and return the result of is_set_attr(), i.e. True or False.

check_set_attr_lst(attr_lst)

dump(dump_filename[, mkdir])

Write object to binary file using pickle.

fit(*args, **kwargs)

Fit E-V data (self.energy, self.volume).

get_min([behave])

Calculate properites at energy minimum of E(V).

get_return_attr(attr_name)

Call try_set_attr() are return self.<attr_name> if set.

get_spl_bv()

get_spl_ev()

get_spl_pv()

init_attr_lst([attr_lst])

Set each self.<attr> in attr_lst to None.

is_set_attr(attr)

Check if self has the attribute self.<attr> and if it is _not_ None.

is_set_attr_lst(attr_lst)

load(dump_filename)

Load pickled object.

raw_return(attr_name)

Call try_set_attr(_<attr_name>_raw) and return it if set, else None.

raw_slice_get(attr_name, sl, axis)

Shortcut method:

set_all([attr_lst])

Call getter for each attr name in attr_lst.

set_attr_lst(attr_lst)

Set self.attr_lst and init each attr to None.

set_bv_method(bv_method)

Set self.bv_method, a.k.a.

try_set_attr(attr)

If self.<attr> does not exist or is None, then invoke an appropirately named getter as if this command would be executed.

try_set_attr_lst(attr_lst)