-
Notifications
You must be signed in to change notification settings - Fork 11
Enable NanoPET for atomic-basis spherical targets #527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jwa7
wants to merge
30
commits into
main
Choose a base branch
from
pet_atomic_basis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
66b214d
Allow reading of traget type `'atomic_basis_spherical'`
jwa7 580036c
Missing `TargetInfo` attribute
jwa7 e635b48
Allow rotational augmentation of targets on atomic spherical basis (s…
jwa7 826263b
use `{}_to_device` and `{}_to_dtype` functions in validation batching
jwa7 c9d14cb
Modify loss to allow for empty blocks
jwa7 cf17a19
Allow multi-output training for atomic basis targets
jwa7 7a1179b
Stubs for documentation
jwa7 4c2942b
Use DiskDataset.
jwa7 130b110
Linter on docs.
jwa7 014cdf1
Merge branch 'main' into pet_atomic_basis
jwa7 716bde1
Predict whole matrix, part 1
jwa7 3779229
Treat matrices as a single target
jwa7 4c52ce8
Update docs
jwa7 06bf314
Format, lint
jwa7 4f3d879
Remove uncoupled basis targets for now
jwa7 fe6f26d
Modify per_atom.py
jwa7 696a62d
Merge branch 'main' into pet_atomic_basis
jwa7 a1e06d5
Paolo review comments
jwa7 a857b87
Address Guillaume review comments
jwa7 73c0919
Merge branch 'main' into pet_atomic_basis
jwa7 25822a5
Lint
jwa7 3a183d4
Use a str as `TargetInfo.target_type` instead of `is_scalar`, `is_car…
jwa7 9471b85
Use a layout TensorMap, not the incredibly slow `join`
jwa7 aaff647
incomplete fixing of the merge
jwa7 e7dc511
Fix bug
ppegolo 647b1bd
Remove prints
ppegolo f793a21
Remove other prints
ppegolo eb13745
Fix device mismatch
ppegolo ff005fc
Linting
ppegolo e8ac068
Merge branch 'main' into pet_atomic_basis
ppegolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
170 changes: 170 additions & 0 deletions
170
docs/src/advanced-concepts/fitting-atomic-basis-spherical-targets.rst
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
Fitting spherical targets on an atomic basis | ||
============================================ | ||
|
||
.. note:: This tutorial is currently only applicable for model training with NanoPET. | ||
|
||
.. note:: This section is a work in progress. It will be updated in the future to | ||
include more details and examples. | ||
|
||
Targeting electronic structure quantities such as the electron density, Hamiltonian | ||
matrix, and density matrix is also possible with NanoPET in metatrain. These targets are | ||
ususally expressed on an atom-centered quantum chemical basis set, and differ from | ||
normal spherical targets in that they are per-atom or per-pair quantities, and crucially | ||
with a size that is dependent on the atomic type(s) of the atom center(s). | ||
|
||
|
||
Defining spherical targets on an atomic basis | ||
--------------------------------------------- | ||
|
||
We will briefly outline a couple of examples of spherical targets on an atomic basis. | ||
This section intends to describe the metadata structure of such targets, but the details | ||
on how to generate these is outside the scope of this tutorial. | ||
|
||
Electron density on a basis | ||
########################### | ||
|
||
First let's consider the electron density (though applicable also to any scalar field), | ||
decomposed onto an atom-centered basis set. In this case, the model targets a set of | ||
equivariant expansion coefficients. | ||
|
||
These are stored in block-sparse TensorMap format according to the basis set definition. | ||
|
||
For a methane (CH4) molecule, for instance, the keys may look like: | ||
|
||
.. code-block:: | ||
|
||
TensorMap with 8 blocks | ||
keys: o3_lambda o3_sigma center_type | ||
0 1 6 | ||
1 1 6 | ||
2 1 6 | ||
3 1 6 | ||
4 1 6 | ||
0 1 1 | ||
1 1 1 | ||
2 1 1 | ||
|
||
where "o3_lambda" and "o3_sigma" are the angular order and inversion symmetry of the | ||
irreducible components of the density decomposition (which is positive for a scalar | ||
field, a real tensor), and "center_type" tracks the type of atom on which the | ||
corresponding basis functions are centered. | ||
|
||
For example for the block indexed by key: | ||
|
||
.. code-block:: | ||
|
||
LabelsEntry(o3_lambda=2, o3_sigma=-1, center_type=6) | ||
|
||
|
||
.. code-block:: | ||
|
||
TensorBlock | ||
samples (1): ['system', 'atom'] | ||
components (5): ['o3_mu'] | ||
properties (5): ['n'] | ||
gradients: None | ||
|
||
As this is a per-atom (single-center) quantity, the samples contain the "system" and | ||
"atom" dimensions. As this is a Carbon block (type 6), there is one sample. | ||
|
||
A single "o3_mu" dimension in the components tracks the components of the spherical | ||
tensor of order "o3_lambda" (as indexed in the keys), and the radial basis functions are | ||
enumerated in the properties with dimension "n". | ||
|
||
Hamiltonian (or density matrix) on a coupled basis | ||
################################################## | ||
|
||
The elements of the Hamiltonian matrix (or analogously the density matrix) on the atomic | ||
orbital basis can also be targeted. For now, this must be expressed in the coupled | ||
angular momenta basis, and symmetrized with respect to permutations. Details on how to | ||
represent Hamiltonian matrices in such a way are outside the scope of this tutorial but | ||
will be covered elsewhere. | ||
|
||
For methane, the keys of the Hamiltonian (coupled and symmetrized) are as follows: | ||
|
||
.. code-block:: | ||
|
||
TensorMap with 56 blocks | ||
keys: o3_lambda o3_sigma s2_pi first_atom_type second_atom_type | ||
0 1 0 6 6 | ||
0 1 1 6 6 | ||
... | ||
2 1 1 1 1 | ||
2 1 -1 1 1 | ||
|
||
where "o3_lambda" and "o3_sigma" are as before, and "s2_pi" tracks the permutational | ||
symmetry of each block. A value of zero means unsymmetrized - in the case of on-site | ||
terms or off-site terms for atoms of different types. Values of +/- 1 refer to plus- or | ||
minus-permutationally symmetrized blocks, and only exist for off-site atom pairs of the | ||
same atomic type. "first_atom_type" and "second_atom_type" refer to the types of the | ||
pair of atoms the matrix element corresponds to. | ||
|
||
For example for the block indexed by key: | ||
|
||
.. code-block:: | ||
|
||
LabelsEntry(o3_lambda=1, o3_sigma=-1, s2_pi=0, first_atom_type=1, second_atom_type=6) | ||
|
||
|
||
the block metadata is as follows: | ||
|
||
.. code-block:: | ||
|
||
TensorBlock | ||
samples (0): ['system', 'first_atom', 'second_atom', 'cell_shift_a', 'cell_shift_b', 'cell_shift_c'] | ||
components (1): ['o3_mu'] | ||
properties (39): ['l_1', 'l_2', 'n_1', 'n_2'] | ||
gradients: None | ||
|
||
As this is a per-pair (two-center) quantity, the samples dimensions are the standard | ||
dimensions found in a neighbor list, tracking the atomic indices of the atoms in the | ||
pair and the cell translation vector that separates them (which can be non-zero in | ||
periodic systems). | ||
|
||
The components axis is the same as for the density coefficients above, as the | ||
Hamiltonian is expressed on the coupled angular momenta basis. | ||
|
||
Finally the properties tracks the indices of the original orbitals in the uncoupled | ||
basis. | ||
|
||
Preparing atomic basis spherical targets for metatrain | ||
------------------------------------------------------ | ||
|
||
Atomic basis spherical targets must be stored in TensorMap format and written to a | ||
DiskDataset prior to calling metatrain. With targets stored with the metadata structure | ||
as outlined above, one can create a DiskDataset by following the example in | ||
"examples/programmatic/disk_dataset". | ||
|
||
Then, the ``systems`` and ``targets`` section of the input file should be written as | ||
follows: | ||
|
||
Input file | ||
########## | ||
|
||
|
||
.. code-block:: yaml | ||
|
||
systems: disk_dataset.zip | ||
|
||
targets: | ||
|
||
mtt::electron_density_basis: | ||
read_from: disk_dataset.zip | ||
type: spherical_atomic_basis | ||
|
||
mtt::hamiltonian: | ||
read_from: disk_dataset.zip | ||
type: spherical_atomic_basis | ||
unit: Ha | ||
|
||
Unlike normal spherical targets, the ``irreps`` do not need to be specified in the input | ||
file and are instead inferred by reading the targets in the dataset. Whether the targets | ||
are per-atom or per-pair is also inferred from the samples metadata of the targets, so | ||
only the name (i.e. ``mtt::electron_density_basis``) and ``unit`` of the quantity needs to | ||
be specified. | ||
|
||
It is important to note that for per-pair targets suhc as the Hamiltonian and Density | ||
Matrix, the atom-pair samples present for the target of a given system must reflect its | ||
full neighbor list (including self terms). In other words, the targets must not contain | ||
samples for pairs of atoms outside the specified model cutoff, and must contain all | ||
samples within the cutoff. |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.