-
Notifications
You must be signed in to change notification settings - Fork 876
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
Mistake in regex string of ion_or_solid_comp_object leads to example string formula "Na[+]" failing #4231
Comments
Hi @IsaacGentle thanks for reporting and I could confirm this issue. For a quick guide on making contributions to a project, you could checkout the guide here. I could confirm your fix indeed work, but things looks more complex that this as some other formulas still don't work (for example Also the unit test for this helper method seems missing, so I might take over from here and fix this :) Thanks again for reporting and investigating. A small tip, to share a code block, you could use the permalink instead of copying the code block. Another small tip, to show differences in code, you could add - if re.match(r"\[([^\[\]]+)\]|\(aq\)", formula):
+ if re.match(r".*\[([^\[\]]+)\]|\(aq\)", formula): Update: looks like |
Hi @DanielYang59, thanks a lot for your comprehensive reply and helpful tips! Interesting that ion_or_solid_comp_object is not used across the code base. To add extra information about how I discovered this minor bug, I was use the pymatgen scripts to generate Pourbaix diagrams, but I was manually adding some of the ionic species using ion_or_solid_comp_object. |
No problem at all. Thanks for sharing the context (though it still looks more like a private function to me, but I wouldn't rename it to private for now as I'm not super familiar with Happy coding in the new year! |
Python version
Python 3.12.3
Pymatgen version
2024.11.13
Operating system version
Windows 10
Current behavior
The following code leads to an error (ValueError: + is an invalid formula!)
Even though the definition of ion_or_solid_comp_object states that the argument string should be formatted as 'Na[+]'
In it's current form, the string needs to be '[+]Na' in order for it to work:
Expected Behavior
If 'Na[+]' is the desired string format, the definition of ion_or_solid_comp_object should be modified
L398 of pourbaix_diagram.py is currently:
https://github.com/materialsproject/pymatgen/blob/da607e86f9ce8aec942067c6c1a4fda6e04915dd/src/pymatgen/analysis/pourbaix_diagram.py#L398C18-L398C19
I suggest replacement with
I am not super familiar with git workflows and pull requests so I have sent this as an issue. Please advise if you think this is something that should be fixed and if you wish me to do a pull request :)
Minimal example
Relevant files to reproduce this bug
No response
The text was updated successfully, but these errors were encountered: