Fix structure field shadowing sort_structure in VaspInputGenerator - #1530
Conversation
|
@esoteric-ephemera do you have time to look into this? I don't have much experience with the MD workflow |
|
Thanks @ThomasWarford. I'm not sure the analysis is quite right, since That being said, it is redundant to redeclare the field here so I'm fine with this change Guessing |
|
It looks like redefining structure as a field in from pathlib import Path
from atomate2.vasp.sets.core import MDSetGenerator
defining_class = next(
cls for cls in MDSetGenerator.__mro__ if "structure" in cls.__dict__
)
structure_attr = defining_class.__dict__["structure"]
print(f"`structure` is defined on: {defining_class.__module__}.{defining_class.__qualname__}")
print(f"`structure` is a property: {isinstance(structure_attr, property)}")
print(f"`structure` has a setter: {isinstance(structure_attr, property) and structure_attr.fset is not None}")Before removing (dft) twarford:~/dev/atomate2> python setter_example.py
`structure` is defined on: pymatgen.io.vasp.sets.VaspInputSet
`structure` is a property: True
`structure` has a setter: TrueAfter removing (dft) twarford:~/dev/atomate2> python setter_example.py
`structure` is defined on: atomate2.vasp.sets.base.VaspInputGenerator
`structure` is a property: False
`structure` has a setter: FalseWithout the setter function sorting based on elements, we get the bug in issue #1530. |
|
Gotcha, thanks for the analysis and fix @ThomasWarford! Merging asap |
Summary
VaspInputGeneratorredeclaredstructureas a plain dataclass field, overriding thestructureproperty (with itssort_structure/reduce_structure/validate_magmomsetter) inherited from pymatgen'sVaspInputSet. As a result,sort_structuresilently never ran for any atomate2 VASP input-set generator.MDSetGenerator'snptensemble:LANGEVIN_GAMMAis sized to the number of distinct elements, while VASP counts POSCAR "types" as contiguous same-element runs. With an unsorted structure the two counts diverge and VASP aborts withError reading item LANGEVIN_GAMMA from file INCAR.tests/vasp/test_sets.py) and a standalone repro (example.py).Alternatively, we modify MDSetGenerator something like:
for a more targeted fix.
Additional dependencies introduced (if any)
TODO (if any)
Checklist
Work-in-progress pull requests are encouraged, but please put [WIP] in the pull request
title.
Before a pull request can be merged, the following items must be checked:
The easiest way to handle this is to run the following in the correct sequence on
your local machine. Start with running
ruffandruff formaton your new code. This willautomatically reformat your code to PEP8 conventions and fix many linting issues.
Run ruff on your code.
type check your code.
Note that the CI system will run all the above checks. But it will be much more
efficient if you already fix most errors prior to submitting the PR. It is highly
recommended that you use the pre-commit hook provided in the repository. Simply run
pre-commit installand a check will be run prior to allowing commits.Issue
Closes #1529. See this issue for bug reproduction instructions.