Skip to content

Re-attach structure properties and support D3 dispersion in TorchSim - #1544

Open
akwarii wants to merge 2 commits into
materialsproject:mainfrom
akwarii:main
Open

Re-attach structure properties and support D3 dispersion in TorchSim#1544
akwarii wants to merge 2 commits into
materialsproject:mainfrom
akwarii:main

Conversation

@akwarii

@akwarii akwarii commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Preserve Structure.properties and Structure.site_properties across TorchSim runs. TorchSim's SimState conversions (ts.io.structures_to_state() / state.to_structures()) currently drops both, so properties set on the input structures are re-attached onto the output ones once the calculation finishes.

  • Add support for a D3 dispersion correction on any TorchSim model. Passing dispersion=True (plus a1, a2, s8, and a d3_params D3Parameters instance, with s6 optional) to a maker's model_kwargs now builds a D3DispersionModel and sums it with the base model via SumModel. The dispersion correction intentionally does not inherit the base model's cutoff, since D3's long-range tail needs a much larger cutoff than typical short-range ML potentials.

None of these changes are breaking.

Additional dependencies introduced (if any)

None.

Note

The functional-dependent BJ damping parameters (a1, a2, s8) and the element reference data (d3_params) must currently be supplied explicitly by the caller; there is no bundled lookup table for common XC functionals (e.g. from https://github.com/dftd3/simple-dftd3/blob/main/assets/parameters.toml).

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:

  • Code is in the standard Python style.
    The easiest way to handle this is to run the following in the correct sequence on
    your local machine. Start with running ruff and ruff format on your new code. This will
    automatically reformat your code to PEP8 conventions and fix many linting issues.
  • Doc strings have been added in the Numpy docstring format.
    Run ruff on your code.
  • Type annotations are highly encouraged. Run mypy to
    type check your code.
  • Tests have been added for any new functionality or bug fixes.
  • All linting and tests pass.

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 install and a check will be run prior to allowing commits.

@akwarii

akwarii commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

The test that failed seems to be related to the recent bump of phonopy to v4 and not to this PR.

@JaGeo

JaGeo commented Sep 10, 2026

Copy link
Copy Markdown
Member

Could you restrict phonopy for now? Thanks a lot!

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.

2 participants