flory.common.phases

Module providing common utilities to deal with phases and their composition.

Classes

Phases

Contains information about compositions and relative sizes of many phases.

PhasesResult

Contains compositions and relative sizes of many phases along with extra information.

class Phases(volumes, fractions)[source]

Bases: object

Contains information about compositions and relative sizes of many phases.

Parameters:
  • volumes (ndarray) – 1D array with shape \(N_\mathrm{P}\), containing the volume \(J_p\) of each phase.

  • fractions (ndarray) – 2D array with shape \(N_\mathrm{P} \times N_\mathrm{C}\), containing the volume fractions of the components in each phase \(\phi_{p,i}\). The first dimension must be the same as volumes.

Public Data Attributes:

num_phases

Number of phases \(N_\mathrm{P}\).

num_components

Number of components \(N_\mathrm{C}\).

total_volume

Total volume of entire system

mean_fractions

Mean fraction averaged over phases \(\bar{\phi}_i\)

Public Methods:

normalize()

normalize the phases so that their volumes adds to one

sort()

Sort the phases according to the index of most concentrated components.

get_clusters([dist])

Find clusters of compositions.

Private Methods:

_copy(volumes, fractions)

create copy with changed volume and fraction


_copy(volumes, fractions)[source]

create copy with changed volume and fraction

This method helps with subclassing methods that should keep other information intact.

Return type:

Phases

property num_phases: int

Number of phases \(N_\mathrm{P}\).

property num_components: int

Number of components \(N_\mathrm{C}\).

property total_volume: float

Total volume of entire system

property mean_fractions: ndarray

Mean fraction averaged over phases \(\bar{\phi}_i\)

normalize()[source]

normalize the phases so that their volumes adds to one

Return type:

Phases

sort()[source]

Sort the phases according to the index of most concentrated components.

Returns:

The sorted phases.

Return type:

Phases

get_clusters(dist=0.01)[source]

Find clusters of compositions.

Find unique phases from compartments by clustering. The returning results are sorted according to the index of most concentrated components.

Parameters:

dist (float, default: 0.01) – Cut-off distance for cluster analysis.

Returns:

The clustered and sorted phases.

Return type:

Phases

class PhasesResult(volumes, fractions, *, info=None)[source]

Bases: Phases

Contains compositions and relative sizes of many phases along with extra information.

Parameters:
  • volumes (ndarray) – 1D array with shape \(N_\mathrm{P}\), containing the volume \(J_p\) of each phase.

  • fractions (ndarray) – 2D array with shape \(N_\mathrm{P} \times N_\mathrm{C}\), containing the volume fractions of the components in each phase \(\phi_{p,i}\). The first dimension must be the same as volumes.

  • info (dict | None, default: None) – Additional information about how the phases were obtained.

Public Data Attributes:

info

Information for the current collection of phases.

Inherited from Phases:

Public Methods:

from_phases(phases, *[, info])

create phase result from Phases

Inherited from Phases:

Private Methods:

_copy(volumes, fractions)

create copy with changed volume and fraction

Inherited from Phases:


classmethod from_phases(phases, *, info=None)[source]

create phase result from Phases

Parameters:
  • phases (Phases) – The Phases containing volumes and fractions.

  • info (dict | None, default: None) – Additional information about how the phases were obtained

Return type:

PhasesResult

property info: dict

Information for the current collection of phases.

_copy(volumes, fractions)[source]

create copy with changed volume and fraction

This method helps with subclassing methods that should keep other information intact.

Return type:

PhasesResult

get_clusters(dist=0.01)

Find clusters of compositions.

Find unique phases from compartments by clustering. The returning results are sorted according to the index of most concentrated components.

Parameters:

dist (float, default: 0.01) – Cut-off distance for cluster analysis.

Returns:

The clustered and sorted phases.

Return type:

Phases

property mean_fractions: ndarray

Mean fraction averaged over phases \(\bar{\phi}_i\)

normalize()

normalize the phases so that their volumes adds to one

Return type:

Phases

property num_components: int

Number of components \(N_\mathrm{C}\).

property num_phases: int

Number of phases \(N_\mathrm{P}\).

sort()

Sort the phases according to the index of most concentrated components.

Returns:

The sorted phases.

Return type:

Phases

property total_volume: float

Total volume of entire system

Functions

get_uniform_random_composition

pick concentrations uniformly from allowed simplex (sum of fractions < 1)

get_uniform_random_composition(num_comps, rng=None)[source]

pick concentrations uniformly from allowed simplex (sum of fractions < 1)

Parameters:
  • num_comps (int) – the number of components to use

  • rng (default: None) – The random number generator

Returns:

An array with `num_comps` random fractions

Return type:

ndarray