mlund / faunus

A Framework for Metropolis Monte Carlo Simulation of Molecular Systems
https://faunus.readthedocs.io
MIT License
65 stars 34 forks source link

yason.py converting to string instead of number for variable substitution #306

Closed udayardahal closed 4 years ago

udayardahal commented 4 years ago

While trying to generate .json with latest yason.py, I got error and when I compared the files generated from older version of yason.py and the latest one; I find some difference. See the output from the latest yason.py.

{% set pH = 7 %} atomlist:

the .json output is: "H+": { "implicit": true, "activity": "1e-07" }

where the number are generated as strings (within quotation marks).

The older version of yason.py works fine; which outputs number as expected.

mlund commented 4 years ago

Hmm, I it seems to do with this and possibly related to the version the yaml parser (ruamel) or jinja2. Will need to investigate. No changes has been made to the yason.py script as far as I recall.

mlund commented 4 years ago

The problem is that 1e-07 is passed as a string while 1.0e-7 is a number. You could use an ugly hack such as {{ 10**(-pH + 0.0000001) }} but this is of course not a permanent solution.

mlund commented 4 years ago

Could you try to install the ruamel_yaml package? On my system this works, whereas yaml doesn't. According to above linkyaml has a bug that incorrectly pass the number as a string.

udayardahal commented 4 years ago

Seem like it is not due to the yason.py. I have two versions installed (one in conda environment and one locally). I copied the yason.py from conda (which worked in conda environment) and tried with that in my local folder and it still generate string. That means, it has to do with the yaml package as you mentioned. I will try installing ruamel_yaml and see if it solves the error.

mlund commented 4 years ago

any luck with ruamel_yaml?

udayardahal commented 4 years ago

Sorry for the late reply. Now after installing ruamel_yaml, I don't see the same error.