CRSManager

This submodule facilitate the creation, execution, and output processes for mutiple crsJob and is intended to be used in conjunction with the pyCRS.database module.

class pyCRS.CRSManager.CRSSystem(iteration=False)

This class manages multiple CRSMixture instances, handling their creation, execution, and result collection. Use add_Mixture() to append CRSMixture objects to the mixture list; results are stored in outputs with the same order. Requires pyCRS.database for COSKF access.

iteration

Enable iteration mode; mixtures will manage CRSIteration instead of a single CRSJob.

Type:

bool

num_mix

Number of mixtures managed by this CRSSystem.

Type:

int

mixture

Ordered list of mixtures in this system.

Type:

list[CRSMixture]

outputs

Results aligned to mixture order.

Type:

list[CRSResults]

Architecture

CRSSystem ├─ mixture: list[CRSMixture] │ ├─ (iteration=False) ──> crs_job [CRSJob] │ └─ (iteration=True) ──> crs_iteration [CRSIteration] ──> crs_job [CRSJob] └─ outputs: list[CRSResults]

Notes

Use runCRSJob() when iteration is False; use runCRSIteration() when iteration is True.

Example

db = COSKFDatabase("my_coskf_db.db")
crs = CRSSystem()
crs.add_Mixture(mixture={"ethanol": 0.0, "water":1.0}, database=db)
crs.runCRSJob()
res = crs.outputs[0].get_results()
print(f"{res['temperature']} : {res['gamma']}")
db = COSKFDatabase("my_coskf_db.db")
crs = CRSSystem(iteration=True)
crs.add_Mixture(mixture={"ethanol": 0.0, "water":1.0}, database=db)
crs.runCRSIteration()
act = cal.get_activity_coefficients()
print(f"activity coefficient of mixture0: comp0: point0={act[0][0][0]:.4f}")

parameter_sett = Settings()
parameter_sett.input.CRSParameters.aeff = 6.5
cal.runCRSIteration(parameter_sett=parameter_sett)
act = cal.get_activity_coefficients()
print(f"activity coefficient of mixture0: comp0: point0={act[0][0][0]:.4f}")
add_Mixture(mixture: dict, temperature: float | str = 298.15, problem_type: str = 'activitycoef', database: str | COSKFDatabase = 'my_coskf_db.db', method: str = 'COSMORS', pressure: float | str = 1.01325, jobname: str | None = None, conformer: bool = False, massfraction: bool = False, density_corr: bool = False, vp_corr: bool = False, solute: str = 'solid', iso: str = 'isotherm', additional_sett: Settings | None = None, multi_species: dict | None = None)

Adds a new CRSMixture to the mixture attribute of the CRSSystem.

Parameters:

mixture (dict) – Composition as {Identifier : mole/mass fraction}

Keyword Arguments:
  • temperature (float or str) – Temp in Kelvin (default 298.15). If str, format can be “T1” or “T1 T2 ntemp”. Where T1 is the starting temperature, T2 is the ending temperature, and ntemp is the number of intervals between T1 and T2.

  • problem_type (str) – Calculation type (default “activitycoef”).

  • database (str or COSKFDatabase) – Path or instance of COSKFDatabase (default “my_coskf_db.db”).

  • method (str) – Version of COSMORS or COSMOSAC (default “COSMORS”).

  • pressure (float or str) – Pressure in bar (default 1.01325). If str, format can be “P1” or “P1 P2 npress”. Where P1 is the starting pressure, P2 is the ending pressure, and npress is the number of intervals between P1 and P2.

  • jobname (str) – Job name in plam_workdir (defaults “crsJob_n”).

  • conformer (bool) – Use multiple conformers in COSMO-RS (default False).

  • massfraction (bool) – Input fraction as mass (default False).

  • density_corr (bool) – Use pure compound density for volume. Default to False (uses COSMO volume).

  • vp_corr (bool) – Correct gas phase chemical potential with vapor pressure (default False).

  • solute (str) – Solute state (“solid”, “gas”, “liquid”) in SOLUBILITY and PURESOLUBILITY. Default is “solid”.

  • iso (str) – Condition (“isotherm”, “isobar”, “flashpoint”) for BINMIXCOEF, TERNARYMIX, and COMPOSITIONLINE. Default is “isotherm”.

  • additional_sett (Settings) – Optional custom settings (default None).

  • multi_species (dict) – Multi-species settings as {Identifier: Settings} (default None).

Note

The identifiers for a compound can be the name, CAS number, or identifier in the pyCRS.database. When searching in the database, the input string will be converted to lowercase, except when it starts with ‘InChI’.

The available problem types are listed below.

problem_type value

Problem type

ACTIVITYCOEF

Activity Coefficient

BINMIXCOEF

Binary mixture LLE/VLE

TERNARYMIX

Ternary mixture LLE/VLE

COMPOSITIONLINE

Solvent composition line interpolation

SOLUBILITY

Solubility calculation in a mixed solvent

PURESOLUBILITY

Solubility calculation in a pure solvent

LOGP

Partition coefficient calculation

VAPORPRESSURE

Vapor pressure calculation for a mixed solvent

PUREVAPORPRESSURE

Vapor pressure calculation for a pure solvent

BOILINGPOINT

Boiling point calculation for a mixture

PUREBOILINGPOINT

Boiling point calculation for a pure solvent(s)

FLASHPOINT

Flashpoint calculation for a mixture

SIGMAPROFILE

Sigma profile calculation for a mixture

PURESIGMAPROFILE

Sigma profile calculation for a pure component(s)

SIGMAPOTENTIAL

Sigma potential calculation for a mixture

PURESIGMAPOTENTIAL

Sigma potential calculation for a pure component(s)

get_activity_coefficients(idx: int | List[int] | None = None) List[ndarray]

Returns activity coefficients for all CRSMixture or the specified ones.

Keyword Arguments:

idx (int or List[int], optional) – Index or list of indices of CRSMixture to return. If None, returns for all mixtures. Default is None.

Returns:

Activity coefficients as a list of numpy arrays.

Return type:

List[np.ndarray])

runCRSIteration(parameter_sett=None, history=False)

Run CRS iterations for all CRSMixture objects when iteration=True.

Each mixture executes CRSIteration.do_iteration with the base settings plus any overrides in parameter_sett. When history is True, each iteration is kept as a distinct CRSJob; otherwise only the last iteration is retained.

Keyword Arguments:
  • parameter_sett (Settings, optional) – Settings to merge into the base CRS job settings for this iteration.

  • history (bool) – Keep all iterations as children["iteration_N"] when True; keep only children["iteration_last"] when False.

runCRSJob()

Run all CRSJob in each CRSMixture

class pyCRS.CRSManager.CRSMixture(**kwargs)

Build a CRSJob (or CRSIteration when enabled) from mixture input and settings.

This class builds a CRSJob from mixture composition/conditions, thermodynamic settings, and database inputs. When iteration is True, it creates a CRSIteration instead of a single CRSJob.

crs_job

Created when iteration is False.

Type:

CRSJob

crs_iteration

Created when iteration is True.

Type:

CRSIteration

iteration

Enable iterative runs by applying different settings across iterations (default False).

Type:

bool

mixture

Composition as {Identifier : mole/mass fraction}

Type:

dict

temperature

Temp in Kelvin (default 298.15). If str, format can be “T1” or “T1 T2 ntemp”. Where T1 is the starting temperature, T2 is the ending temperature, and ntemp is the number of intervals between T1 and T2.

Type:

float or str

problem_type

Calculation type (default “activitycoef”).

Type:

str

database

Path or instance of COSKFDatabase (default “my_coskf_db.db”).

Type:

str or COSKFDatabase

method

Version of COSMORS or COSMOSAC (default “COSMORS”).

Type:

str

pressure

Pressure in bar (default 1.01325). If str, format can be “P1” or “P1 P2 npress”. Where P1 is the starting pressure, P2 is the ending pressure, and npress is the number of intervals between P1 and P2.

Type:

float or str

jobname

Job name in plam_workdir (defaults “crsJob_n”).

Type:

str

conformer

Use multiple conformers in COSMO-RS (default False).

Type:

bool

massfraction

Input fraction as mass (default False).

Type:

bool

density_corr

Use pure compound density for volume. Default to False (uses COSMO volume).

Type:

bool

vp_corr

Correct gas phase chemical potential with vapor pressure (default False).

Type:

bool

solute

Solute state (“solid”, “gas”, “liquid”) in SOLUBILITY and PURESOLUBILITY. Default is “solid”.

Type:

str

iso

Condition (“isotherm”, “isobar”, “flashpoint”) for BINMIXCOEF, TERNARYMIX, and COMPOSITIONLINE. Default is “isotherm”.

Type:

str

additional_sett

Optional custom settings (default None).

Type:

Settings

multi_species

Multi-species settings as {Identifier: Settings} (default None).

Type:

dict

Reference