pycalphad.core package

Submodules

pycalphad.core.calculate module

The calculate module contains a routine for calculating the property surface of a system.

pycalphad.core.calculate.calculate(dbf, comps, phases, mode=None, output='GM', fake_points=False, **kwargs)[source]

Sample the property surface of ‘output’ containing the specified components and phases. Model parameters are taken from ‘dbf’ and any state variables (T, P, etc.) can be specified as keyword arguments.

Parameters:
  • dbf (Database) – Thermodynamic database containing the relevant parameters.
  • comps (str or sequence) – Names of components to consider in the calculation.
  • phases (str or sequence) – Names of phases to consider in the calculation.
  • mode (string, optional) – See ‘make_callable’ docstring for details.
  • output (string, optional) – Model attribute to sample.
  • fake_points (bool, optional (Default: False)) – If True, the first few points of the output surface will be fictitious points used to define an equilibrium hyperplane guaranteed to be above all the other points. This is used for convex hull computations.
  • points (ndarray or a dict of phase names to ndarray, optional) – Columns of ndarrays must be internal degrees of freedom, sorted. If this is not specified, points will be generated automatically.
  • pdens (int, a dict of phase names to int, or a seq of both, optional) – Number of points to sample per degree of freedom.
  • model (Model, a dict of phase names to Model, or a seq of both, optional) – Model class to use for each phase.
Returns:

Return type:

xray.Dataset of the sampled attribute as a function of state variables

Examples

None yet.

pycalphad.core.cartesian module

The cartesian module contains a routine for computing the Cartesian product of N arrays.

pycalphad.core.cartesian.cartesian(arrays, out=None)[source]

Generate a cartesian product of input arrays. Source: http://stackoverflow.com/questions/1208118/using-numpy-to-build-an-array-of-all-combinations-of-two-arrays

Parameters:
  • arrays (list of array-like) – 1-D arrays to form the cartesian product of.
  • out (ndarray) – Array to place the cartesian product in.
Returns:

out – 2-D array of shape (M, len(arrays)) containing cartesian products formed of input arrays.

Return type:

ndarray

Examples

>>> cartesian(([1, 2, 3], [4, 5], [6, 7]))
array([[1, 4, 6],
       [1, 4, 7],
       [1, 5, 6],
       [1, 5, 7],
       [2, 4, 6],
       [2, 4, 7],
       [2, 5, 6],
       [2, 5, 7],
       [3, 4, 6],
       [3, 4, 7],
       [3, 5, 6],
       [3, 5, 7]])

pycalphad.core.energy_surf module

The energy_surf module contains a routine for calculating the energy surface of a system.

pycalphad.core.energy_surf.energy_surf(dbf, comps, phases, mode=None, output='GM', **kwargs)[source]

Sample the property surface of ‘output’ containing the specified components and phases. Model parameters are taken from ‘dbf’ and any state variables (T, P, etc.) can be specified as keyword arguments.

Parameters:
  • dbf (Database) – Thermodynamic database containing the relevant parameters.
  • comps (list) – Names of components to consider in the calculation.
  • phases (list) – Names of phases to consider in the calculation.
  • mode (string, optional) – See ‘make_callable’ docstring for details.
  • output (string, optional) – Model attribute to sample.
  • pdens (int, a dict of phase names to int, or a list of both, optional) – Number of points to sample per degree of freedom.
  • model (Model, a dict of phase names to Model, or a list of both, optional) – Model class to use for each phase.
Returns:

Return type:

DataFrame of the output as a function of composition, temperature, etc.

Examples

None yet.

pycalphad.core.eqresult module

This module deals with managing the result of an equilibrium calculation.

class pycalphad.core.eqresult.EquilibriumResult(phases, components, potentials, energy, variables)[source]

Bases: object

mole_fractions
class pycalphad.core.eqresult.PhaseResult[source]

Bases: object

mole_fractions
class pycalphad.core.eqresult.SublatticeResult[source]

Bases: object

pycalphad.core.equilibrium module

The equilibrium module defines routines for interacting with calculated phase equilibria.

exception pycalphad.core.equilibrium.EquilibriumError[source]

Bases: Exception

Exception related to calculation of equilibrium

class pycalphad.core.equilibrium.PhaseRecord(variables, grad, plane_grad, plane_hess)

Bases: tuple

grad

Alias for field number 1

plane_grad

Alias for field number 2

plane_hess

Alias for field number 3

variables

Alias for field number 0

pycalphad.core.equilibrium.equilibrium(dbf, comps, phases, conditions, **kwargs)[source]

Calculate the equilibrium state of a system containing the specified components and phases, under the specified conditions. Model parameters are taken from ‘dbf’.

Parameters:
  • dbf (Database) – Thermodynamic database containing the relevant parameters.
  • comps (list) – Names of components to consider in the calculation.
  • phases (list or dict) – Names of phases to consider in the calculation.
  • conditions (dict or (list of dict)) – StateVariables and their corresponding value.
  • verbose (bool, optional (Default: True)) – Show progress of calculations.
  • grid_opts (dict, optional) – Keyword arguments to pass to the initial grid routine.
Returns:

Return type:

Structured equilibrium calculation.

Examples

None yet.

pycalphad.core.lower_convex_hull module

The lower_convex_hull module handles geometric calculations associated with equilibrium calculation.

pycalphad.core.lower_convex_hull.lower_convex_hull(global_grid, result_array)[source]

Find the simplices on the lower convex hull satisfying the specified conditions in the result array.

Parameters:
  • global_grid (Dataset) – A sample of the energy surface of the system.
  • result_array (Dataset) – This object will be modified! Coordinates correspond to conditions axes.
Returns:

Return type:

None. Results are written to result_array.

Notes

This routine will not check if any simplex is degenerate. Degenerate simplices will manifest with duplicate or NaN indices.

Examples

None yet.

pycalphad.core.utils module

The minimize module handles helper routines for equilibrium calculation.

class pycalphad.core.utils.NumPyPrinter(settings=None)[source]

Bases: sympy.printing.lambdarepr.LambdaPrinter

Numpy printer which handles vectorized piecewise functions, logical operators, etc.

class pycalphad.core.utils.SpecialNumExprPrinter(settings=None)[source]

Bases: sympy.printing.lambdarepr.NumExprPrinter

numexpr printing for vectorized piecewise functions

pycalphad.core.utils.broadcast_to(arr, shape)[source]

Broadcast an array to a desired shape. Returns a view.

pycalphad.core.utils.check_degenerate_phases(phase_compositions, mindist=0.5)[source]

Because the global minimization procedure returns a simplex as an output, our starting point will always assume the maximum number of phases. In many cases, one or more of these phases will be redundant, i.e., the simplex is narrow. These redundant or degenerate phases can be eliminated from the computation.

Here we perform edge-wise comparisons of all the simplex vertices. Vertices which are from the same phase and “sufficiently” close to each other in composition space are redundant, and one of them is eliminated from the computation.

This function accepts a DataFrame of the estimated phase compositions and returns the indices of the “independent” phases in the DataFrame.

pycalphad.core.utils.endmember_matrix(dof, vacancy_indices=None)[source]

Accept the number of components in each sublattice. Return a matrix corresponding to the compositions of all endmembers.

Parameters:
  • dof (list of int) – Number of components in each sublattice.
  • list of int, optional (vacancy_indices,) – If vacancies are present in every sublattice, specify their indices in each sublattice to ensure the “pure vacancy” endmember is excluded.

Examples

Sublattice configuration like: (AL, NI, VA):(AL, NI, VA):(VA) >>> endmember_matrix([3,3,1], vacancy_indices=[2, 2, 0])

pycalphad.core.utils.fast_aba(a, b)[source]

Vectorized a@b@a matrix product. Source: @dhirschfeld on numpy Gitter chat

pycalphad.core.utils.generate_dof(phase, active_comps)[source]

Accept a Phase object and a set() of the active components. Return a tuple of variable names and the sublattice degrees of freedom.

pycalphad.core.utils.halton(dim, nbpts, primes=None)[source]

Generate a multi-dimensional Halton sequence.

Parameters:
  • dim (int) – Number of dimensions in the sequence.
  • nbpts (int) – Number of points along each dimension.
  • primes (sequence, optional) – A sequence of at least ‘dim’ prime numbers. This is for generating shuffled sequences. By default, this is the first 32 primes.
Returns:

Return type:

ndarray of shape (nbpts, dim)

pycalphad.core.utils.make_callable(model, variables, mode=None)[source]

Take a SymPy object and create a callable function.

Parameters:
  • SymPy object (model,) – Abstract representation of function
  • list (variables,) – Input variables, ordered in the way the return function will expect
  • ['numpy', 'numexpr', 'sympy'], optional (mode,) – Method to use when ‘compiling’ the function. SymPy mode is slow and should only be used for debugging. If Numexpr is installed, it can offer speed-ups when calling the energy function many times on multi-core CPUs.
Returns:

  • Function that takes arguments in the same order as ‘variables’
  • and returns the energy according to ‘model’.

Examples

None yet.

pycalphad.core.utils.point_sample(comp_count, pdof=10, roll=0)[source]

Sample ‘pdof * (sum(comp_count) - len(comp_count))’ points in composition space for the sublattice configuration specified by ‘comp_count’. Points are sampled quasi-randomly from a Halton sequence. A Halton sequence is like a uniform random distribution, but the result will always be the same for a given ‘comp_count’ and ‘pdof’. Note: For systems with only one component, only one point will be returned, regardless of ‘pdof’. This is because the degrees of freedom are zero for that case.

Parameters:
  • comp_count (list) – Number of components in each sublattice.
  • pdof (int) – Number of points to sample per degree of freedom.
  • roll (int, optional) – Number of positions by which the prime number array should be shifted.
Returns:

Return type:

ndarray of generated points satisfying the mass balance.

Examples

>>> comps = [8,1] # 8 components in sublattice 1; only 1 in sublattice 2
>>> pts = point_sample(comps, pdof=20) # 7 d.o.f, returns a 140x7 ndarray
pycalphad.core.utils.sizeof_fmt(num, suffix='B')[source]

Human-readable string for a number of bytes. http://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size

pycalphad.core.utils.unpack_condition(tup)[source]

Convert a condition to a list of values. Rules for keys of conditions dicts: (1) If it’s numeric, treat as a point value (2) If it’s a tuple with one element, treat as a point value (3) If it’s a tuple with two elements, treat as lower/upper limits and

guess a step size
  1. If it’s a tuple with three elements, treat as lower/upper/step
  2. If it’s a list, ndarray or other non-tuple ordered iterable, use those values directly
pycalphad.core.utils.unpack_kwarg(kwarg_obj, default_arg=None)[source]

Keyword arguments in pycalphad can be passed as a constant value, a dict of phase names and values, or a list containing both of these. If the latter, then the dict is checked first; if the phase of interest is not there, then the constant value is used.

This function is a way to construct defaultdicts out of keyword arguments.

Parameters:
  • kwarg_obj (dict, iterable, or None) – Argument to unpack into a defaultdict
  • default_arg (object) – Default value to use if iterable isn’t specified
Returns:

Return type:

defaultdict for the keyword argument of interest

Examples

>>> test_func = lambda **kwargs: print(unpack_kwarg('opt'))
>>> test_func(opt=100)
>>> test_func(opt={'FCC_A1': 50, 'BCC_B2': 10})
>>> test_func(opt=[{'FCC_A1': 30}, 200])
>>> test_func()
>>> test_func2 = lambda **kwargs: print(unpack_kwarg('opt', default_arg=1))
>>> test_func2()
pycalphad.core.utils.unpack_phases(phases)[source]

Convert a phases list/dict into a sorted list.

Module contents