Thermodynamic stability (stability)#

Calculation of spinodal and binodal

Classes:

RootResultTotal

Modified root result

StabilityBase(collection)

Base class for stability

Spinodals(collection)

Methods for calculation locations of spinodal

Binodals(collection)

Routines to calculate binodal.

Functions:

get_spinodal(collection, build_phases, idx)

Locate spinodal point for a given pair of phases.

class lnpy.stability.RootResultTotal[source]#

Bases: dict

Modified root result

lnpy.stability.get_spinodal(collection, build_phases, idx, idx_nebr=None, efac=1.0, dlnz=0.5, dfac=1.0, vmin=0.0, vmax=100000.0, ntry=20, step=None, nmax=20, ref=None, build_kws=None, close_kws=None, solve_kws=None)[source]#

Locate spinodal point for a given pair of phases.

Parameters:
  • ref (lnPiMasked)

  • collection (lnPiCollection) – initial estimates to work from. Function assumes collection is in lnz sorted order

  • idx, idx_nebr (int) – from/to phase id

  • lnz_in (list) – list with value of static chem pot, and None for variable. e.g., lnz_in=[None,0.0] implies lnz[0] is variable, and lnz[1]=0.0

  • efac (float, optional) – cutoff value for spinodal

  • dlnz (float, optional) – factor to kick back if collection doesn’t already have left and right bounds

  • vmin (float, optional) – Value denoting vmin, i.e., value of free energy difference phase does not exist.

  • vmax (float, optional) – value indicating no transition, but phase idx is present.

  • ntry (int, default 20) – number of times to try kicking forward/backwards to find bracket

  • step (int or None, default None) – if +1, step forward if -1, step backward if None, try to determine step

  • nmax (int, default 20) – max number of steps to refine bracket

  • build_phases (callable(), optional) – Function to create Phases. Default is that from get_default_phasecreator

  • build_kws (dict, optional) – extra arguments to build_phases

  • close_kws (dict, optional) – arguments to numpy.allclose()

  • solve_kws (dict, optional) – extra arguments to scipy.optimize.brentq()

Returns:

class lnpy.stability.StabilityBase(collection)[source]#

Bases: object

Base class for stability

Parameters:

collection (lnPiCollection) – Used to bracket the location limit of stability

Attributes:

parent

Accessor to parent lnPiCollection object

items

Access to the underlying data

access

View (lnpy.lnpiseries.lnPiCollection) of stability

appender

View of access to be appended to parent

Methods:

append_to_parent([sort, copy_stability])

New collection with spinodal data appended to parent.

property parent#

Accessor to parent lnPiCollection object

property items#

Access to the underlying data

access[source]#

View (lnpy.lnpiseries.lnPiCollection) of stability

property appender#

View of access to be appended to parent

append_to_parent(sort=True, copy_stability=True)[source]#

New collection with spinodal data appended to parent.

class lnpy.stability.Spinodals(collection)[source]#

Bases: StabilityBase

Methods for calculation locations of spinodal

Methods:

__call__(phase_ids, build_phases, *[, ...])

Parameters:
  • phase_ids (int, or sequence) -- Phase ids to calculate spinodal for. If int, then find spinodals for phases

__call__(phase_ids, build_phases, *, inplace=True, ref=None, build_kws=None, force=False, as_dict=True, unstack=None, raise_unconverged=True, **kwargs)[source]#
Parameters:
  • phase_ids (int, or sequence) – Phase ids to calculate spinodal for. If int, then find spinodals for phases range(phase_ids).

  • build_phases (callable()) – Factory function to build phases. This should most likely be an instance of lnpy.segment.BuildPhasesBase

  • ref (lnPiMasked, optional)

  • build_kws (dict, optional) – optional arguments to build_phases

  • inplace (bool, default True) – if True, add spinodal inplace, otherwise return spinodal object

  • force (bool, optional) – if True, force recalculation of spinodal if already set inplace. Otherwise return already calculated values

  • as_dict (bool, default True) – if True, return dict of form {phase_id[0] : phases object, …}.

  • unstack (bool, optional) – if passed, create lnPiCollection objects with this unstack value. If not passed, use unstack parameter from parent object

  • raise_unconverged (bool, default True) – If True, raise error if calculation does not converge.

  • **kwargs – Extra argument to get_spinodal() function

Returns:

out (dict or lnPiCollection, optional) – if inplace, return self. if not inplace, and as dict, return dict, else return lnpy.lnpiseries.lnPiCollection with phase_id in index

class lnpy.stability.Binodals(collection)[source]#

Bases: StabilityBase

Routines to calculate binodal.

Methods:

__call__(phase_ids, build_phases, *[, ...])

Parameters:
  • phase_ids (int, or sequence) -- Phase ids to calculate binodal for. If int, then find binodal for phases

__call__(phase_ids, build_phases, *, inplace=True, spinodals=None, ref=None, build_kws=None, force=False, as_dict=True, unstack=None, raise_unconverged=True, **kwargs)[source]#
Parameters:
  • phase_ids (int, or sequence) – Phase ids to calculate binodal for. If int, then find binodal for phases range(phase_ids).

  • build_phases (callable()) – Factory function to build phases

  • inplace (bool, default True) – if True, add binodal inplace, otherwise return spinodal object

  • spinodals (optional) – if not passes, then use parent.spinodal Used for bounding binodal

  • ref (lnPiMasked, optional)

  • build_kws (dict, optional) – optional arguments to build_phases

  • force (bool, optional) – if True, force recalculation of spinodal if already set inplace. Otherwise return already calculated values

  • as_dict (bool, default True) – if True, return dict of form {phase_id[0] : phases object, …}

  • unstack (bool, optional) – if passed, create lnPiCollection objects with this unstack value. If not passed, use unstack parameter from parent object

  • raise_unconverged (bool, default True) – If True, raise error if calculation does not converge.

  • **kwargs – Extra argument to get_spinodal() function

Returns:

out (object) – if inplace, return self if not inplace, and as dict, return dict, else return lnPiCollection with phase_id in index