-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccd82ef
commit d9d6f03
Showing
13 changed files
with
119 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,28 @@ | ||
Metatensor API | ||
============== | ||
|
||
``sphericart`` can be used in conjunction with | ||
`metatensor <https://docs.metatensor.org/latest/index.html>`_ in order to attach | ||
metadata to inputs and outputs, as well as to naturally obtain spherical harmonics, | ||
gradients and Hessians in a single object. | ||
|
||
Here is the API reference for the ``sphericart.metatensor`` and | ||
``sphericart.metatensor.torch`` modules. | ||
|
||
sphericart.metatensor | ||
--------------------- | ||
|
||
.. autoclass:: sphericart.metatensor.SphericalHarmonics | ||
:members: | ||
|
||
.. autoclass:: sphericart.metatensor.SolidHarmonics | ||
:members: | ||
|
||
sphericart.metatensor.torch | ||
--------------------------- | ||
|
||
.. autoclass:: sphericart.metatensor.torch.SphericalHarmonics | ||
:members: | ||
|
||
.. autoclass:: sphericart.metatensor.torch.SolidHarmonics | ||
:members: |
This file contains 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,13 @@ | ||
Using sphericart with metatensor | ||
-------------------------------- | ||
|
||
``sphericart`` can be used in conjunction with | ||
`metatensor <https://docs.metatensor.org/latest/index.html>`_ in order to attach | ||
metadata to inputs and outputs, as well as to naturally obtain spherical harmonics, | ||
gradients and Hessians in a single object. | ||
|
||
This example shows how to use the ``sphericart.metatensor`` module to compute | ||
spherical harmonics, their gradients and their Hessians. | ||
|
||
.. literalinclude:: ../../examples/metatensor/example.py | ||
:language: python |
This file contains 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,54 @@ | ||
import numpy as np | ||
from metatensor import Labels, TensorBlock, TensorMap | ||
|
||
import sphericart | ||
import sphericart.metatensor | ||
|
||
|
||
l_max = 15 | ||
n_samples = 100 | ||
|
||
xyz = TensorMap( | ||
keys=Labels.single(), | ||
blocks=[ | ||
TensorBlock( | ||
values=np.random.rand(n_samples, 3, 1), | ||
samples=Labels( | ||
names=["sample"], | ||
values=np.arange(n_samples).reshape(-1, 1), | ||
), | ||
components=[ | ||
Labels( | ||
names=["xyz"], | ||
values=np.arange(3).reshape(-1, 1), | ||
) | ||
], | ||
properties=Labels.single(), | ||
) | ||
], | ||
) | ||
|
||
calculator = sphericart.metatensor.SphericalHarmonics(l_max) | ||
|
||
spherical_harmonics = calculator.compute(xyz) | ||
|
||
for single_l in range(l_max + 1): | ||
spherical_single_l = spherical_harmonics.block({"o3_lambda": single_l}) | ||
|
||
# check values against pure sphericart | ||
assert np.allclose( | ||
spherical_single_l.values.squeeze(-1), | ||
sphericart.SphericalHarmonics(single_l).compute( | ||
xyz.block().values.squeeze(-1) | ||
)[:, single_l**2 : (single_l + 1) ** 2], | ||
) | ||
|
||
# further example: obtaining gradients of l = 2 spherical harmonics | ||
spherical_harmonics = calculator.compute_with_gradients(xyz) | ||
l_2_gradients = spherical_harmonics.block({"o3_lambda": 2}).gradient("positions") | ||
|
||
# further example: obtaining Hessians of l = 2 spherical harmonics | ||
spherical_harmonics = calculator.compute_with_hessians(xyz) | ||
l_2_hessians = spherical_harmonics.block( | ||
{"o3_lambda": 2} | ||
).gradient("positions").gradient("positions") |
This file contains 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from .spherical_harmonics import SphericalHarmonics, SolidHarmonics # noqa | ||
from . import metatensor # noqa |
This file contains 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
This file contains 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
This file contains 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
This file contains 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