Refactor: split energy database model#302
Merged
Merged
Conversation
Energy can be written to file in three formats (relaxation, MD, AFQMC). Until now a single flat Energy_DB modeled all of them, leaving most fields unset for any given record. This introduces the first of three format-specific models. EnergyHandler.to_database now infers the format from the labels present in the raw data and, for AFQMC, returns a dedicated EnergyAfqmc_DB. AFQMC energies fluctuate rather than converge, so each term is summarized by its initial, average, and final value instead of a minimum; the sampling step keeps only initial/final. MD and relaxation are unchanged and still return Energy_DB for now.
The energy to-database method now detects molecular-dynamics data from its labels and returns a dedicated EnergyMD_DB instead of the flat, mostly-empty Energy_DB. Because MD energies fluctuate around a value rather than converging to a minimum, each term is summarized by its initial, average, and final value (dropping the min/step_min aggregates that are only meaningful for relaxation). Relaxation energy still falls through to the legacy Energy_DB; its dedicated model and the eventual Energy_DB removal are follow-up cycles.
The energy to-database method now detects ionic-relaxation data from its labels and returns a dedicated EnergyRelaxation_DB. Because a relaxation converges toward a minimum, each term keeps the initial, minimum, step-of-minimum, and final value. Relaxation was the last format still routed through the flat Energy_DB, so the now-unreachable _to_legacy_database helper (including its other_energy_data catch-all) is removed. All three formats now return a format-specific model. The Energy_DB class itself and the docs-introspection update remain a follow-up cleanup.
All three energy formats now return a dedicated model (EnergyRelaxation_DB, EnergyMD_DB, EnergyAfqmc_DB), so the flat union Energy_DB -- whose fields were mostly None for any single record -- is no longer produced anywhere and is removed. The docs/schema introspection in _util/database.py auto-discovers one *_DB class per quantity, which cannot express the energy quantity mapping to three models. It now maps the selections explicitly (energy -> EnergyRelaxation_DB as the representative default, energy:afqmc -> EnergyAfqmc_DB) and injects all three energy models so their fields still appear in the generated documentation. Also adds a test that the label-based format detection raises on unknown labels instead of silently falling through.
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
VASP writes energy data in three formats, distinguished only by which labels the raw data carries (there is no explicit type field): relaxation, MD, and AFQMC. Previously
Calculation._to_database()squeezed all three into a single flatEnergy_DB, so for any given calculation most of its ~60 fields wereNone- obscuring which format a record came from.This PR makes
to_database()detect the format from the labels and return a dedicated, fully-populated model for each. The aggregates each model keeps match the physics of the run:EnergyRelaxation_DBinitial/min/step_min/finalEnergyMD_DBinitial/average/finalEnergyAfqmc_DBinitial/average/final(+stepinitial/final)A minimum is meaningful only for a converging relaxation; MD/AFQMC use the average instead. The old catch-all
other_energy_datafield is dropped - every model is now a fixed, deterministic set of fields.What changed (commit by commit)
EnergyAfqmc_DB, the label-based_detect_energy_formathelper, and route AFQMC data to it.EnergyMD_DBand route MD data to it.EnergyRelaxation_DB, route relaxation data to it, and remove the now-unreachable legacy_to_legacy_databasepath.Energy_DBclass. The docs/schema introspection in_util/database.pyassumed one*_DBclass per quantity, which can't express energy's three models, so it now maps the selections explicitly (energy -> EnergyRelaxation_DBas the representative default,energy:afqmc -> EnergyAfqmc_DB) and injects all three models so their fields still appear in generated docs.Detection
Format detection keys only on labels unique to a format, checking AFQMC's markers before the shared
free energy TOTENlabel is ever consulted - so the one cross-format label overlap (relaxation vs. AFQMC) can't cause misclassification. An unrecognized label set raises rather than silently falling through.