Add Spin/Charge embeddings#183
Conversation
Keep both our system-level input tests and upstream's test_mixed_pbc. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Thanks @JonathanSchmidt1! I would also ping @Luthaf who has a better idea of the design we want for these input quantities. One potential concern is that a model might be called with a charge/spin state that it doesn't support and we don't have a mechanism to prevent that. Models that don't support charges and spins will just ignore these charges and spins... which might be correct thing to do, but just checking
| system as the model's floating-point dtype (float32 or float64); the model | ||
| converts them back to integers internally for the embedding lookup. |
There was a problem hiding this comment.
I wouldn't necessarily say this in the documentation, simply because the implementation will potentially change (I think we're soon going to support integer TensorMaps, right @Luthaf?). I wouldn't say how the model is going to handle them either: the point of metatomic is to be totally generic, each model can handle these inputs how it wants (including ignoring them).
There was a problem hiding this comment.
Yes, integer TensorMap are already mostly supported at runtime and will soon be able to be serialized as well.
| * - Input name | ||
| - Default | ||
| - How to set | ||
| * - ``"mtt::charge"`` |
There was a problem hiding this comment.
Charges and spins shouldn't be mtt:: anymore, they should be made standard inputs (so they don't need a prefix anymore)
There was a problem hiding this comment.
Yes, per-atom charge already are, we need to add total charge, per atom spin and total spin
|
This one is not for me to decide, I'll let Filippo and Guillaume review :) |
There is a check for models that support charge and spin to make sure they support the requested values (in the metatrain pr) outside of that I don't think we can solve this issue as we would have to output warnings for every key in atom.info in case they might be an input that the user expects the model to use. |
Summary
This PR adds support for system-level charge and spin multiplicity conditioning
inputs (
mtt::charge,mtt::spin) in the ASE calculator, allowing models thatdeclare these in
requested_inputs()to receive them automatically.Note: I did not take care yet of making this work with torch-sim, though torch-sim already supports system-wide charge and spin (though they have a default spin of 0)
ase_calculator.py:SYSTEM_QUANTITIESdict mappingmtt::charge/mtt::spinto theiratoms.infokeys ("charge"/"spin"), defaults (0 / 1), and TensorMapconstruction logic.
_get_ase_inputto handle system-level scalar inputs fromSYSTEM_QUANTITIES, storing values in the system's floating-point dtype(float32/float64) as required by
system.add_data().check_state()override toMetatomicCalculatorthat detects changesto
atoms.info["charge"]/atoms.info["spin"]and forces a freshcalculation, preventing stale cached results when only the charge or
spin changes. The relevant keys are cached at construction time
(
_system_info_watch) to avoid per-step TorchScript dispatch overhead.docs/src/engines/ase.rst:them via
atoms.info.Tests (
tests/ase_calculator.py): three new tests:test_system_level_input— verifies correct dtype and value forwarding forcharge and spin.
test_system_level_input_defaults— verifies defaults (charge=0, spin=1)when keys are absent from
atoms.info.test_system_level_input_changes_energy— regression test confirming thatdifferent charge values, different spin values, and
atoms.infochangeswithout an explicit
reset()all produce different energies.ChargeSpinAnisoModel— test confirming that a charge/spin model is symmetrized correctlytest_symmetrized_calculator_passes_charge_spin— test confirming that charges and spins are passed through the SymmetrizedCalculatorContributor (creator of pull-request) checklist
Reviewer checklist