smenjas / chemistry-explorer

A chemistry app built with vanilla JavaScript
https://smenjas.github.io/chemistry-explorer/
ISC License
1 stars 2 forks source link

Detect chemical formulas, regardless of letter case #66

Open smenjas opened 11 months ago

smenjas commented 11 months ago

Goal & Context

I'd like to provide an intuitive search feature. Users should be able to type chemical formulas in all lowercase, or all uppercase, or mixed case, and the software should be able to detect whether the input looks like a molecular formula.

Status Quo

Currently the software can only parse chemical formulas when the element symbols have the first letter capitalized, and the 2nd letter miniscule if it exists. I think this makes sense, so it seems like there should be a separate method to test and convert arbitrary strings, before attempting to parse them. Perhaps I'm wrong about this, and case-insensitive formula parsing would not have performance or accuracy costs, but that needs to be investigated.

Non Goals

This new formula detection code need not take into account whether the formula makes sense chemically. For example, a user might enter a substring of a formula where the charge of the ions does not add up correctly. Don't worry about this for now. Perhaps the search is just a partial formula. See issue #63.

Bonus Features

Once we get the initial substring search working correctly for molecular formulas, we might want to look into more options.

These may not be performant given the current data architecture. We could solve this by caching empirical or even equivalent formulas at the expense of storage capacity, but the app is not presently designed to accommodate those performance optimizations.

Prerequisites

This depends on: #48