Closed Ali-Nazarik closed 5 months ago
@Ali-Nazarik, the aliases are set when compiling chemicals in set_thermo
. Any conflicting aliases are removed to avoid any ambiguity (so that BioSTEAM only does what can be expected). You can modify aliases after set_thermo
as follows:
from biosteam import units, settings, Stream
import thermosteam as tmo
IDs = ['acetic acid', 'formic acid', 'methanol', 'ethanol', 'methanediol',
'hydroxyacetone', 'leucoglucosan', 'glycolaldehyde', 'lactic acid',
'acetone', 'phenol', 'D-Glucose', 'sucrose', 'water']
chemicals = tmo.Chemicals(IDs, cache=False)
settings.set_thermo(chemicals)
chemicals.set_alias('acetic acid', chemicals['acetic acid'].formula) # Set alias after set_thermo
feed = Stream('feed', T=273.15+25, P=100000, units='kg/hr',
C2H4O2=6.59360730593607, CH2O2=2.08219178082192,
CH4O=0.607305936073059, C2H6O=0.17351598173516,
CH4O2=1.04109589041096, C3H6O2=3.81735159817352,
C6H10O5=5.86027397260274, glycolaldehyde=3.96986301369863,
C3H6O3=0.913698630136986, C3H6O=0.504109589041096,
C6H6O=0.148082191780822, C6H12O6=3.05616438356164,
C12H22O11=17.0452054794521, H2O=54.2465753424658)
A = feed.get_flow(units='kg/hr')
But I wouldn't recommend using the formula as an alias for isomers because it can be confusing for bigger projects. Thanks,
Describe the bug
An index error arises when attempting to add two chemicals that are isomers, i.e., they have the same atomic composition. Specifically, this error occurs when adding acetic acid and glycolaldehyde, both of which have the molecular formula C2H4O2, resulting in a KeyError for ‘C2H4O2’. Interestingly, the error does not occur if either of these chemicals is removed from the script provided below.
To Reproduce
The following Python script can be used to reproduce the error:
from biosteam import units, settings, Stream import thermosteam as tmo
ID = ['acetic acid', 'formic acid', 'methanol', 'ethanol', 'methanediol', 'hydroxyacetone', 'leucoglucosan', 'glycolaldehyde', 'lactic acid', 'acetone', 'phenol', 'D-Glucose', 'sucrose', 'water']
chemicals = tmo.Chemicals(ID, cache=False) settings.set_thermo(chemicals)
feed = Stream('feed', T=273.15+25, P=100000, units='kg/hr', C2H4O2=6.59360730593607, CH2O2=2.08219178082192, CH4O=0.607305936073059, C2H6O=0.17351598173516, CH4O2=1.04109589041096, C3H6O2=3.81735159817352, C6H10O5=5.86027397260274, glycolaldehyde=3.96986301369863, C3H6O3=0.913698630136986, C3H6O=0.504109589041096, C6H6O=0.148082191780822, C6H12O6=3.05616438356164, C12H22O11=17.0452054794521, H2O=54.2465753424658)
A = feed.get_flow(units='kg/hr')
Expected behavior It is expected that creation of streams with isomers should be possible.
Actual behavior It is not possible to create streams with isomers using the above method.
Version
Additional context
Encountered error:
Traceback (most recent call last): File "C:\Users\AliNazariKhoorasgani\AppData\Local\Programs\Python\Python312\Lib\site-packages\thermosteam_chemicals.py", line 1073, in _get_index_and_kind return index_cache[key]