Git Product home page Git Product logo

Comments (6)

jeremyagray avatar jeremyagray commented on August 11, 2024

from chempy.

spizwhiz avatar spizwhiz commented on August 11, 2024

Thanks, I think I understand the issues.

Would requiring the user to use some kind of special notation for decimal subscripts potentially help with the hydrates issue?

E.g. putting the subscript in square brackets or curly braces?

'Ca{2.832}Fe{0.6285}Mg{2.5395}(CO3)6'

from chempy.

jeremyagray avatar jeremyagray commented on August 11, 2024

from chempy.

spizwhiz avatar spizwhiz commented on August 11, 2024

Awesome, thanks!

I wish I could help more, but I don't think I would be that much help to you at this point.

from chempy.

spizwhiz avatar spizwhiz commented on August 11, 2024

For anyone else needing to work with decimal subscripts, here is a function to quickly calculate the smallest integer subscripts, and the scaling factor.

import decimal

def integer_subs(frac_subs):
    dec = [decimal.Decimal(str(sub)).as_tuple().exponent for sub in frac_subs]
    decmin = min(dec)
    mf = 10**-decmin
    subs = frac_subs*mf
    subs = subs.round()
    subs = subs.astype(int)

    cd = gcd.reduce(subs)

    subsf = (subs/cd).astype(int)
    print('Integer Subscripts: ', subsf)

    sf = mf/cd
    print('Scaling Factor:', sf)
subs1 = np.array([2.832,0.6285,2.5395,6])

integer_subs(subs1)

Integer Subscripts:  [1888  419 1693 4000]
Scaling Factor: 666.6666666666666

from chempy.

bjodah avatar bjodah commented on August 11, 2024

Hi, and thank you both for looking into this.

I'm open to changing the syntax for crystal water to allow parsing non-integer stoichiometric coefficients.

What about "Na2SO4:10H2O", does that look "natural" enough in your eyes? (just a spontaneous suggestion of mine).
I personally won't be able to code up a prototype anytime soon I'm afraid, but if you want to go ahead I'll definitely make time for code review and publishing an updated release etc.

Changing the syntax will be a breaking change, so we'll need to bump the version number, ideally one could have the parser accept both old and new syntax for one intermediate release, issuing a warning instructing the user to migrate to the new syntax. But if that is not possible I'm open to skipping the deprecation cycle.

from chempy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.