flory.ensemble.base

Module for a general ensemble of mixture.

Classes

EnsembleBase

Base class for a general ensemble of mixture.

EnsembleBaseCompiled

Abstract base class for a general compiled ensemble.

class EnsembleBase(num_comp)[source]

Bases: object

Base class for a general ensemble of mixture.

Parameters:

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

Public Data Attributes:

num_comp

Component count

Public Methods:

compiled(**kwargs_full)

Make a compiled ensemble instance for CoexistingPhasesFinder.

Private Methods:

_compiled_impl(**kwargs)

Implementation of creating a compiled ensemble instance (Interface).


property num_comp: int

Component count

_compiled_impl(**kwargs)[source]

Implementation of creating a compiled ensemble instance (Interface).

This interface is meant to be overridden in derived classes. See compiled() for more information on the compiled ensemble instance.

Return type:

EnsembleBaseCompiled

compiled(**kwargs_full)[source]

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 EnsembleBaseCompiled[source]

Bases: object

Abstract base class for a general compiled ensemble.

This abstract class defines the necessary members of a compiled constraint instance. This abstract class does not inherit from abc.ABC, since the numba.experimental.jitclass() currently does not support some members of abc.ABC. A compiled class derived from EnsembleBaseCompiled is in general stateless. In other words, the compiled ensemble instance never managers its own data. Note that the methods may change the input arrays inplace to avoid creating them each time.

Public Data Attributes:

num_comp

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

Public Methods:

normalize(phis_comp, Qs, masks)

Normalize the volume fractions of components.


property num_comp: int

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