Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PySRIM ioniz file reading incorrect : " could not convert string to float: b'000025,00' " #1

Open
JulienBouixAlainPetrus opened this issue Jun 17, 2021 · 2 comments

Comments

@JulienBouixAlainPetrus
Copy link

Dear all,

I have an issue when tying to use the PySRIM package for my master thesis at Politecnico di Milano. When PySRIM is done with the computation of the ions in matter simulations, it has troubles reading the output file IONIZ.txt. Even if the simulations are over, we are still in the "trim.run(srim_executable_directory)" function.

More precisely, in the python code "output.py", at the line 71, the match.group(1) that needs to be converted from string to float seems to be equal to " b'000025,00' ", it is either the "b" or the "," sign compared to "." that create the error written in the title.

The complete message error is :

"
Traceback (most recent call last):
File "C:\Users\Julien Bouix\Desktop\SRIM-2013\AvecPysrim.py", line 36, in
results = trim.run(srim_executable_directory)
File "c:\users\julien bouix\anaconda3\lib\site-packages\srim\srim.py", line 223, in run
return Results(srim_directory)
File "c:\users\julien bouix\anaconda3\lib\site-packages\srim\output.py", line 111, in init
self.ioniz = Ioniz(directory)
File "c:\users\julien bouix\anaconda3\lib\site-packages\srim\output.py", line 138, in init
num_ions = self._read_num_ions(output)
File "c:\users\julien bouix\anaconda3\lib\site-packages\srim\output.py", line 71, in _read_num_ions
return int(float(match.group(1)))
ValueError: could not convert string to float: b'000025,00'
"

I would like to know your thoughts on what could give rise to this error since we have no control on the type of output files TRIM creates. We can choose what file we want but not what they contain (a comma instead of a point for instance). If it is systematic, I could remove the "b" and replace the comma by a point manually by changing the output.py file, but I would like to keep the source code of PySRIM unaltered.

I would very highly appreciate an answer and a possible solution you can think of. I would gladly give you more details if necessary.

Best regards,

Julien Bouix

@MrRobot2211
Copy link

I think that most of this issues can be solved by using locale and adding a cast to float with atof . They are mainlky problems casting ",". In your case if you work with a french locale then SRIM is writting decimal "," instead of ".". Yo can see this MR https://gitlab.com/costrouc/pysrim/-/merge_requests/5 probalbly your problem will be solved by extending the strategy there.

@jacobopadin
Copy link

Hi! I have the same error, did you find a solution? @JulienBouixAlainPetrus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants