CalebBell / chemicals

chemicals: Chemical database of Chemical Engineering Design Library (ChEDL)
MIT License
186 stars 36 forks source link

Get chemical name from chemical notation #31

Closed Python3-8 closed 3 years ago

Python3-8 commented 3 years ago
>>> from chemicals import *
>>> h2co3_from_name = CAS_from_any('Carbonic Acid')
>>> h2co3_from_notation = CAS_from_any('h2co3')
>>> h2co3_from_name == h2co3_from_notation # True
>>> get_name(h2co3_from_notation) # is there something I can use to do something like this and get "Carbonic Acid"?

Also, may I know the difference between CAS_from_any('h2co3') and CAS_from_any('H2CO3')? They seem to return different results: '463-79-6', and '107-32-4'.

longemen3000 commented 3 years ago

107-32-4: https://en.wikipedia.org/wiki/Performic_acid , formula = CH2O3 63-79-6: https://en.wikipedia.org/wiki/Carbonic_acid , formula = CH2O3 the main problem is that a search by formula is not unique. it also seems that h2co3 is stored as a synonym of Carbonic acid

CalebBell commented 3 years ago

Hi Pranav, Andrés is exactly correct! The synonyms are from pubchem and unexpected things happen sometimes, like h2co3 resolving to something different than CH2O3. I strongly recommend avoiding searching by formula. You can retrieve more information about a chemical with the method search_chemical; i.e. the name can be found with a query like:

>>> search_chemical('carbonic acid').common_name
"carbonic acid"

Sincerely, Caleb

CalebBell commented 3 years ago

Your question has inspired me to begin working on documentation for the project again. https://chemicals.readthedocs.io/tutorial.html may provide assistance as well. Thank you, Andrés, for your help with this!