CalebBell / thermo

Thermodynamics and Phase Equilibrium component of Chemical Engineering Design Library (ChEDL)
MIT License
594 stars 114 forks source link

joback estimates fails as calculation values might not be floats #68

Closed gbrault closed 3 years ago

gbrault commented 3 years ago

When calculating Tm, Tb, Tc etc, the code looks for

joback_groups_id_dict[group].Tm
joback_groups_id_dict[group].Tb
joback_groups_id_dict[group].Tc

but some time those values are not floats and the procedure fails.

I did a quick fix which protects the formula by checking the type, but maybe a better solution is needed

Here is a fix exemple for Pc

def Pc(counts, atom_count):
        tot = 0.0
        good = True
        for group, count in counts.items():
            if type(joback_groups_id_dict[group].Pc) == float:
                tot += joback_groups_id_dict[group].Pc*count
            else:
                good = False
        Pc = (0.113 + 0.0032*atom_count - tot)**-2
        if good:
            return Pc*1E5 # bar to Pa
        else:
            return float('nan')    

Same applies for all other Physical Properties

CalebBell commented 3 years ago

Hi Gilbert, Thanks for getting in touch. Yes this could definitely be managed better! In my experience the most Pythonic way to handle this would be to assume nothing is missing, but wrap the whole clause in a try/except. None is also more conventionally returned rather than nan, which tends to propagate and can be hard to track down the source whereas None fails when you try to do math on it.

Well spotted!

Sincerely, Caleb

CalebBell commented 3 years ago

Hi Gilbert, The development of thermo now contains those None return values. Sincerely, Caleb

gbrault commented 3 years ago

Many thanks CalebBell!