BioSTEAMDevelopmentGroup / thermosteam

BioSTEAM's Premier Thermodynamic Engine
Other
58 stars 12 forks source link

Retrieving list of all components #36

Closed dhkblaszyk closed 3 years ago

dhkblaszyk commented 3 years ago

I have searched but was unable to find a method that retrieved a full list of components in the database at runtime. I would also like to iterate through the available physical property models for each of the components, including the validity ranges (T & P). The reason for asking is that I am working on a graphical front end and would like to show this information to the user.

yoelcortes commented 3 years ago

It's not elegant, but here is one way to do it:

from thermosteam import Chemical # Load thermosteam first to implement pubchem_db.search method
from chemicals.identifiers import pubchem_db  # Chemical metadata manager
try: pubchem_db.search('badname') # Autoloads all metadata files
except: pass
all_chemicals = [Chemical(i.CASs) for i in pubchem_db.CAS_index.values()] 
# Note that len(all_chemicals) == 74191, so your ram is going to suffer with list comprehension
# You might want to use a generator instead

Only about 20,000 chemicals have any information other than the chemical metadata (names and molecular weight). Although most T and P domains are by the book, some are a little arbitrary... suggestions are welcome :)

Hope this helps!