JacksonBurns / mordred-community

Community-Maintained Version of mordred
https://jacksonburns.github.io/mordred-community/
BSD 3-Clause "New" or "Revised" License
49 stars 3 forks source link

Overflow Error #11

Closed dr-aspirinas closed 9 months ago

dr-aspirinas commented 9 months ago

Hi Jackson,

I am also interested in maintaining mordred because they are quite handy. Although you silenced the warning concerning overflow, this avoids some descriptors to be calculated. I found that there is another way to avoid overflowing (not throwing an error at all). Just modify the code like this:

from numpy import product

from numpy import product, array, float128

    with self.rethrow_zerodiv():
        Dvv = array(Dv, dtype=float128)             # this avoids the overflow error
        dx = product(Dvv) ** (1.0 / (2.0 * n))
    return n / (dx ** 2)

I have tested with the largest molecule that I could think of (cyclosporin, MW ~1200 Da) without errors. Only with PEG-2000 (MW 2000 Da) I got the error again (so it is related with size).

Hope it helps!

JacksonBurns commented 9 months ago

@dr-aspirinas thanks for the suggestion! Do you notice any timing differences with this change?

dr-aspirinas commented 9 months ago

@JacksonBurns, no I haven't noticed any slowdown.

JacksonBurns commented 9 months ago

Great! I have implemented this in #12, could you take a look and make sure it looks good? I had to use longdouble instead of float128, since it turned out the latter is only a valid alias on unix-based platforms.