Skip to content

Conversation

@DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Oct 11, 2025

Enhancements:

Fixes

  • Fix handling of ! as comment marker for string tags like PREC = Accurate ! hello:
    print(incar["PREC"])  # >>> Accurate ! hello

@DanielYang59 DanielYang59 changed the title Enhance INCAR parsing: multi-line string, line continuation with backslash... Enhance INCAR parsing: handle multi-line string and line continuation with backslash, fix handling of ! as comment marker Oct 11, 2025
@DanielYang59 DanielYang59 force-pushed the incar-multiline-str branch 13 times, most recently from f511b50 to 8a8eeff Compare October 13, 2025 20:12
def test_from_str_multiline_string(self):
incar_str = r"""
# Multi-line string with embedded comments
WANNIER90_WIN = "begin Projections # should NOT be capitalized
Copy link
Contributor Author

@DanielYang59 DanielYang59 Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An edge case, currently comments in multi-line string would be removed, I guess this agrees with the behaviour described by vaspwiki:

For comments, VASP ignores any text after a hashtag # or exclamation mark !. Use this to add comments anywhere to the INCAR file.

@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Oct 14, 2025

@esoteric-ephemera can you please review this maybe? I understand using RE would hurt readability but I didn't find a better way other than using a quite complex state machine, also added unit test to cover as much edge cases as I could think of.

@DanielYang59 DanielYang59 marked this pull request as ready for review October 14, 2025 17:18
@esoteric-ephemera
Copy link
Contributor

@DanielYang59 sure will try to find some time to!

@DanielYang59 DanielYang59 force-pushed the incar-multiline-str branch 2 times, most recently from bc0885b to 20d30ca Compare October 16, 2025 13:12
@shyuep
Copy link
Member

shyuep commented Oct 17, 2025

I wish VASP would switch to YAML for INCARs.... I think use of regex is fine. We use it all over Vasp.outputs.

…ling

test

enhance incar parsing of backslash and multi-line str, fix ! comment
handle

fix most issues: multi-line str still doesn't work

almost there, one statement in comment should not be parsed

guess it's fine to strip multi-line string

I guess ;! is not a valid use case, ; is meant to connect to statements

oops, looks like comment would be parsed

fix test

first working version
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

Successfully merging this pull request may close these issues.

Support for Multi-Line INCAR Parameters in user_incar_settings

3 participants