Liquids and mixtures¶
LiquidComponent
dataclass
¶
Represents a single component of a liquid mixture.
This class models a component within a liquid mixture, including its name, the fraction of the total mixture it represents, and an optional integer component value. It provides methods for initialization validation, creating instances from dictionaries, and formatting component information for specific external systems.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the liquid component. |
fraction |
float
|
The fraction of the total mixture this component represents, must be between 0 and 1. |
integer_component |
Optional[int]
|
An optional integer value associated with the component, default is None. |
Methods:
Name | Description |
---|---|
__post_init__ |
Validates the fraction attribute to ensure it is within the expected range (0 to 1). |
from_dict |
dict) -> "LiquidComponent": Class method to create an instance from a dictionary. |
to_insane_format |
Formats the component information for use in an external system, returning a string. |
Source code in martignac/liquid_models/mixtures.py
LiquidMixture
dataclass
¶
Represents a mixture of liquid components.
This class models a mixture of various liquid components, allowing for operations such as normalization checks, setting integer contributions based on a scaling factor, and formatting the mixture information for specific external systems. It supports initialization from a list of dictionaries representing individual components, ensuring that the total fraction of components equals 1.0 for a normalized mixture.
Attributes:
Name | Type | Description |
---|---|---|
components |
list[LiquidComponent]
|
A list of |
scaling_factor |
float
|
A scaling factor used to calculate integer contributions of each component, default is 10.0. |
Methods:
Name | Description |
---|---|
__post_init__ |
Validates the mixture to ensure it is normalized (i.e., the sum of component fractions equals 1.0). |
from_list_of_dicts |
list[dict]) -> "LiquidMixture": Class method to create an instance from a list of dictionaries. |
set_integer_contributions |
Sets the integer contribution for each component based on the scaling factor. |
to_insane_format |
Formats the mixture information for use in an external system, returning a string. |
solvent_names |
Returns a list of names of the components in the mixture. |