flory.ensemble.grandcanonical

Module for grand canonical ensemble of mixture.

Classes

GrandCanonicalEnsemble

Class for an grand canonical ensemble that the chemical potentials are fixed.

GrandCanonicalEnsembleCompiled

Compiled class for grand canonical ensemble.

class GrandCanonicalEnsemble(num_comp, scaled_activity)[source]

Bases: EnsembleBase

Class for an grand canonical ensemble that the chemical potentials are fixed.

Parameters:
  • num_comp (int) – Number of components \(N_\mathrm{C}\).

  • scaled_activity (ndarray) – The scaled activities of the components \(l_i e^{l_i \mu_i}\).

Public Data Attributes:

scaled_activity

The scaled activities of the components \(l_i e^{l_i \mu_i}\).

Public Methods:

from_chemical_potential(num_comp, mus[, sizes])

Create grand canonical ensemble from chemical potentials by volume.

Inherited from EnsembleBase:

compiled(**kwargs_full)

Make a compiled ensemble instance for CoexistingPhasesFinder.

Private Methods:

_compiled_impl()

Implementation of creating a compiled ensemble instance.

Inherited from EnsembleBase:

_compiled_impl(**kwargs)

Implementation of creating a compiled ensemble instance (Interface).


property scaled_activity: ndarray

The scaled activities of the components \(l_i e^{l_i \mu_i}\).

classmethod from_chemical_potential(num_comp, mus, sizes=None)[source]

Create grand canonical ensemble from chemical potentials by volume.

Parameters:
  • num_comp (int) – Number of components \(N_\mathrm{C}\).

  • mus (ndarray) – The chemical potentials by volume \(\mu_i\).

  • sizes (ndarray | None, default: None) – The relative molecule volumes \(l_i = \nu_i/\nu\) with respect to the volume of a reference molecule \(\nu\). It is treated as all-one vector by default.

_compiled_impl()[source]

Implementation of creating a compiled ensemble instance.

This method overwrites the interface _compiled_impl() in EnsembleBase.

Returns:

Instance of GrandCanonicalEnsembleCompiled.

Return type:

GrandCanonicalEnsembleCompiled

compiled(**kwargs_full)

Make a compiled ensemble instance for CoexistingPhasesFinder.

This function requires the implementation of _compiled_impl(). The ensemble instance is a compiled class, which must implement a list of methods or properties. See EnsembleBaseCompiled for the list and the detailed information. Also see CanonicalEnsembleCompiled for an example.

Parameters:

kwargs_full – The keyword arguments for _compiled_impl() but allowing redundant arguments.

Returns:

The compiled ensemble instance.

Return type:

EnsembleBaseCompiled

class GrandCanonicalEnsembleCompiled(scaled_activity)[source]

Bases: EnsembleBaseCompiled

Compiled class for grand canonical ensemble.

In grand canonical ensemble, the original chemical potentials of the components are fixed. Therefore, the volume fractions distribution of the components in compartments can be obtained by scaling the Boltzmann factors according to the scaled activity,

\[\begin{split}\phi_i^{(m)} &= l_i e^{l_i \mu_i} p_i^{(m)} \\\end{split}\]

where \(l_i e^{l_i \mu_i}\) is the scaled activity, \(l_i\) is the relative volumes of molecules and \(\mu_i\) is the chemical potentials of the components by volume. Since (translational) entropy is always defined for each component, this class is only aware of the component-based description of the system.

Parameters:

scaled_activity (ndarray) – 1D array with the size of \(N_\mathrm{C}\), containing the scaled activities of the components, \(l_i e^{l_i \mu_i}\). The number of components \(N_\mathrm{C}\) is inferred from this array.

Public Data Attributes:

num_comp

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

Inherited from EnsembleBaseCompiled:

num_comp

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

Public Methods:

normalize(phis_comp, Qs, masks)

Normalize the volume fractions of components.

Inherited from EnsembleBaseCompiled:

normalize(phis_comp, Qs, masks)

Normalize the volume fractions of components.


property num_comp

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

normalize(phis_comp, Qs, masks)[source]

Normalize the volume fractions of components.

This method normalizes the Boltzmann factor stored in phis_comp into volume fractions of all components \(\phi_i^{(m)}\) and save it back to phis_comp, making use of the single molecule partition function in Qs. The exact form of such normalization depends on the emsemble. This method must report the incompressibility \(\sum_i \phi_i^{(m)} -1\). Note that this function is only aware of the number of components \(N_\mathrm{C}\). Mapping from/to features are handled by entropy.

Parameters:
  • phis_comp (ndarray) – Mutable. The 2D array with the size of \(N_\mathrm{C} \times N_\mathrm{M}\), containing Boltzmann factors of the components, which are proportional to resulting volume fractions.

  • Qs (ndarray) – Constant. The 1D array with the size of \(N_\mathrm{C}\), containing single molecule partition functions of the components.

  • masks (ndarray) – Constant. The 1D array with the size of \(N_\mathrm{M}\), containing the masks to mark whether the compartment is living or not.

Returns:

The incompressibility.

Return type:

ndarray