Chemicals¶
-
class
thermosteam.
Chemicals
(chemicals)[source]¶ Create a Chemicals object that contains Chemical objects as attributes.
- Parameters
chemicals (Iterable[str or Chemical]) –
- Strings should be one of the following [-]:
Name, in IUPAC form or common form or a synonym registered in PubChem
InChI name, prefixed by ‘InChI=1S/’ or ‘InChI=1/’
InChI key, prefixed by ‘InChIKey=’
PubChem CID, prefixed by ‘PubChem=’
SMILES (prefix with ‘SMILES=’ to ensure smiles parsing)
CAS number
Examples
Create a Chemicals object from chemical identifiers:
>>> from thermosteam import Chemicals >>> chemicals = Chemicals(['Water', 'Ethanol']) >>> chemicals Chemicals([Water, Ethanol])
All chemicals are stored as attributes:
>>> chemicals.Water, chemicals.Ethanol (Chemical('Water'), Chemical('Ethanol'))
-
class
thermosteam.
CompiledChemicals
(chemicals)[source]¶ Create a CompiledChemicals object that contains Chemical objects as attributes.
- Parameters
chemicals (Iterable[str or Chemical]) –
- Strings should be one of the following [-]:
Name, in IUPAC form or common form or a synonym registered in PubChem
InChI name, prefixed by ‘InChI=1S/’ or ‘InChI=1/’
InChI key, prefixed by ‘InChIKey=’
PubChem CID, prefixed by ‘PubChem=’
SMILES (prefix with ‘SMILES=’ to ensure smiles parsing)
CAS number
-
size
¶ Number of chemicals.
- Type
int
-
IDs
¶ IDs of all chemicals.
- Type
tuple[str]
-
CASs
¶ CASs of all chemicals
- Type
tuple[str]
-
MW
¶ MWs of all chemicals.
- Type
1d ndarray
-
Hf
¶ Heats of formation of all chemicals.
- Type
1d ndarray
-
Hc
¶ Heats of combustion of all chemicals.
- Type
1d ndarray
Examples
Create a CompiledChemicals object from chemical identifiers
>>> from thermosteam import CompiledChemicals, Chemical >>> chemicals = CompiledChemicals(['Water', 'Ethanol']) >>> chemicals CompiledChemicals([Water, Ethanol])
All chemicals are stored as attributes:
>>> chemicals.Water, chemicals.Ethanol (Chemical('Water'), Chemical('Ethanol'))
Note that because they are compiled, the append and extend methods do not work:
>>> # Propane = Chemical('Propane') >>> # chemicals.append(Propane) >>> # TypeError: 'CompiledChemicals' object is read-only
-
refresh_constants
()[source]¶ Refresh constant arrays according to their chemical values, including the molecular weight, heats of formation, and heats of combustion.
-
get_combustion_reactions
()[source]¶ Return a ParallelReactions object with all defined combustion reactions.
-
property
formula_array
¶ An array describing the formulas of all chemicals. Each column is a chemical and each row an element. Rows are ordered by atomic number.
-
subgroup
(IDs)[source]¶ Create a new subgroup of chemicals.
- Parameters
IDs (Iterable[str]) – Chemical identifiers.
Examples
>>> chemicals = CompiledChemicals(['Water', 'Ethanol', 'Propane']) >>> chemicals.subgroup(['Propane', 'Water']) CompiledChemicals([Propane, Water])
-
get_synonyms
(ID)[source]¶ Get all synonyms of a chemical.
- Parameters
ID (str) – Chemical identifier.
Examples
Get all synonyms of water:
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water']) >>> chemicals.get_synonyms('Water') ['7732-18-5', 'Water']
-
set_synonym
(ID, synonym)[source]¶ Set a new synonym for a chemical.
- Parameters
ID (str) – Chemical identifier.
synonym (str) – New identifier for chemical.
Examples
Set new synonym for water:
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water']) >>> chemicals.set_synonym('Water', 'H2O') >>> chemicals.H2O is chemicals.Water True
-
kwarray
(ID_data)[source]¶ Return an array with entries that correspond to the orded chemical IDs.
- Parameters
ID_data (dict) – ID-data pairs.
Examples
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Ethanol']) >>> chemicals.kwarray(dict(Water=2)) array([2., 0.])
-
array
(IDs, data)[source]¶ Return an array with entries that correspond to the ordered chemical IDs.
- Parameters
IDs (iterable) – Compound IDs.
data (array_like) – Data corresponding to IDs.
Examples
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Ethanol']) >>> chemicals.array(['Water'], [2]) array([2., 0.])
-
iarray
(IDs, data)[source]¶ Return a chemical indexer.
- Parameters
IDs (iterable) – Chemical IDs.
data (array_like) – Data corresponding to IDs.
Examples
Create a chemical indexer from chemical IDs and data:
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Methanol', 'Ethanol']) >>> chemical_indexer = chemicals.iarray(['Water', 'Ethanol'], [2., 1.]) >>> chemical_indexer.show() ChemicalIndexer: Water 2 Ethanol 1
Note that indexers allow for computationally efficient indexing using identifiers:
>>> chemical_indexer['Ethanol', 'Water'] array([1., 2.]) >>> chemical_indexer['Ethanol'] 1.0
-
ikwarray
(ID_data)[source]¶ Return a chemical indexer.
- Parameters
ID_data (Dict[str: float]) – Chemical ID-value pairs.
Examples
Create a chemical indexer from chemical IDs and data:
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Methanol', 'Ethanol']) >>> chemical_indexer = chemicals.ikwarray(dict(Water=2., Ethanol=1.)) >>> chemical_indexer.show() ChemicalIndexer: Water 2 Ethanol 1
Note that indexers allow for computationally efficient indexing using identifiers:
>>> chemical_indexer['Ethanol', 'Water'] array([1., 2.]) >>> chemical_indexer['Ethanol'] 1.0
-
isplit
(split, order=None)[source]¶ Create a chemical indexer that represents chemical splits.
- Parameters
split (Should be one of the following) –
[float] Split fraction
[array_like] Componentwise split
[dict] ID-split pairs
order=None (Iterable[str], options) – Chemical order of split. Defaults to biosteam.settings.chemicals.IDs
Examples
From a dictionary:
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Methanol', 'Ethanol']) >>> chemical_indexer = chemicals.isplit(dict(Water=0.5, Ethanol=1.)) >>> chemical_indexer.show() ChemicalIndexer: Water 0.5 Ethanol 1
From iterable given the order:
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Methanol', 'Ethanol']) >>> chemical_indexer = chemicals.isplit([0.5, 1], ['Water', 'Ethanol']) >>> chemical_indexer.show() ChemicalIndexer: Water 0.5 Ethanol 1
From a fraction:
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Methanol', 'Ethanol']) >>> chemical_indexer = chemicals.isplit(0.75) >>> chemical_indexer.show() ChemicalIndexer: Water 0.75 Methanol 0.75 Ethanol 0.75
-
index
(ID)[source]¶ Return index of specified chemical.
- Parameters
ID (str) – Chemical identifier.
Examples
Index by ID:
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Ethanol']) >>> chemicals.index('Water') 0
Indices by CAS number:
>>> chemicals.index('7732-18-5') 0
-
indices
(IDs)[source]¶ Return indices of specified chemicals.
- Parameters
IDs (iterable) – Chemical indentifiers.
Examples
Indices by ID:
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Ethanol']) >>> chemicals.indices(['Water', 'Ethanol']) [0, 1]
Indices by CAS number:
>>> chemicals.indices(['7732-18-5', '64-17-5']) [0, 1]
-
get_index
(IDs)[source]¶ Return index/indices of specified chemicals.
- Parameters
IDs (iterable[str] or str) – Chemical identifiers.
Notes
CAS numbers are also supported.
Examples
Get multiple indices:
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Ethanol']) >>> IDs = ('Water', 'Ethanol') >>> chemicals.get_index(IDs) [0, 1]
Get a single index:
>>> chemicals.get_index('Ethanol') 1
-
get_vle_indices
(nonzeros)[source]¶ Return indices of species in vapor-liquid equilibrium given an array dictating whether or not the chemicals are present.
Examples
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Methanol', 'Ethanol']) >>> data = chemicals.kwarray(dict(Water=2., Ethanol=1.)) >>> chemicals.get_vle_indices(data!=0) array([0, 2], dtype=int64)
-
get_lle_indices
(nonzeros)[source]¶ Return indices of species in liquid-liquid equilibrium given an array dictating whether or not the chemicals are present.
Examples
>>> from thermosteam import CompiledChemicals >>> chemicals = CompiledChemicals(['Water', 'Methanol', 'Ethanol']) >>> data = chemicals.kwarray(dict(Water=2., Ethanol=1.)) >>> chemicals.get_lle_indices(data!=0) array([0, 2], dtype=int64)