Skip to content
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

Version2 #15

Merged
merged 37 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d3f83d3
Add class to handle the bare potentials
Jun 11, 2024
8f1a287
Add base classes for calculators
Jun 11, 2024
002f545
Add calculator for direct aperiodic summation
Jun 11, 2024
67c7c6c
Add calculator for Ewald summation
Jun 11, 2024
2f317e0
Add calculator for PME and rename old mesh-only
Jun 11, 2024
be4b768
Add tests for output accuracy of new calculators
Jun 11, 2024
f492e1c
Add tests to ensure smooth workflow for new calculators
Jun 11, 2024
e3af13a
Update init files to include new calculators
Jun 11, 2024
87f77dd
Add metatensor output to MeshEwald calculator
Jun 11, 2024
6f1c866
Add option to provide external neighborlist
Jun 20, 2024
40b8808
Add tests for potentials class
Jun 20, 2024
809d85e
linting
PicoCentauri Jul 4, 2024
b1556ac
cleanup base classes
PicoCentauri Jul 4, 2024
1cd02a4
simplify base class even further
PicoCentauri Jul 4, 2024
7b43476
unify workflow tests
PicoCentauri Jul 4, 2024
ef714a0
cleanup workflow tests
PicoCentauri Jul 4, 2024
25d3b29
Update docs
PicoCentauri Jul 5, 2024
de910a7
Turn kvector generation into external
Jul 5, 2024
1218270
remove wrong typecheck test
PicoCentauri Jul 5, 2024
fc17493
Add non-binary + random strucs to tests
Jul 5, 2024
bd9f413
Merge branch 'version2' of github.com:ceriottm/MeshLODE into version2
Jul 5, 2024
5d60dc5
use systems neighborlist in metatensor branch
PicoCentauri Jul 5, 2024
e73031e
update notebook
PicoCentauri Jul 5, 2024
db6e065
convert notebook to propper example
PicoCentauri Jul 5, 2024
dee6268
Remove outdated meshpotential calculator
Jul 5, 2024
12eb318
Vectorize + move SR calc to base class
Jul 5, 2024
2ca95ae
Merge branch 'version2' of github.com:ceriottm/MeshLODE into version2
Jul 5, 2024
36e08d9
linting
PicoCentauri Jul 6, 2024
083a43a
Add metatensor API and remove mehspotential
PicoCentauri Jul 8, 2024
0d63a0e
Remove types from input parameters
Jul 9, 2024
d8364a3
change metatensor output shape
PicoCentauri Jul 9, 2024
342188e
Continue types removal
PicoCentauri Jul 10, 2024
ef5be85
add docs
PicoCentauri Jul 10, 2024
22fd41f
finish tests
PicoCentauri Jul 10, 2024
9be73a6
fix linter
PicoCentauri Jul 10, 2024
19134e5
fix tests-min
PicoCentauri Jul 10, 2024
a237de3
more linting
PicoCentauri Jul 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ python:
- method: pip
path: .
extra_requirements:
- examples
- metatensor
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ You can install *MeshLode* using pip with

You can then ``import meshlode`` and use it in your projects!

We also provide bindings to `metatensor
<https://lab-cosmo.github.io/metatensor/latest/>`_ which can optionally be installed
together and used as ``meshlode.metatensor`` via
We also provide bindings to `metatensor <https://docs.metatensor.org/latest/>`_ which
can optionally be installed together and used as ``meshlode.metatensor`` via

.. code-block:: bash

Expand Down
3 changes: 2 additions & 1 deletion docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@
autodoc_typehints_format = "short"

intersphinx_mapping = {
"ase": ("https://wiki.fysik.dtu.dk/ase/", None),
"python": ("https://docs.python.org/3", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"torch": ("https://pytorch.org/docs/stable/", None),
"metatensor": ("https://lab-cosmo.github.io/metatensor/latest/", None),
"metatensor": ("https://docs.metatensor.org/latest/", None),
}

# -- Options for HTML output -------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions docs/src/references/calculators/directpotential.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DirectPotential
###############

.. autoclass:: meshlode.DirectPotential
:members:
:undoc-members:
6 changes: 6 additions & 0 deletions docs/src/references/calculators/ewaldpotential.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
EwaldPotential
##############

.. autoclass:: meshlode.EwaldPotential
:members:
:undoc-members:
5 changes: 2 additions & 3 deletions docs/src/references/calculators/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ Calculators return the representations as a :py:obj:`List` of :py:class:`torch.T
We also provide a return values as a :py:class:`metatensor.TensorMap` in
:ref:`metatensor`.

.. automodule:: meshlode.calculators

.. toctree::
:maxdepth: 1
:glob:

meshpotential
./*
6 changes: 0 additions & 6 deletions docs/src/references/calculators/meshpotential.rst

This file was deleted.

6 changes: 6 additions & 0 deletions docs/src/references/calculators/pmepotential.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PMEPotential
############

.. autoclass:: meshlode.PMEPotential
:members:
:undoc-members:
4 changes: 2 additions & 2 deletions docs/src/references/lib/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ are used for the meshLODE calculators.

.. toctree::
:maxdepth: 1
:glob:

fourier_convolution
mesh_interpolator
./*
6 changes: 6 additions & 0 deletions docs/src/references/lib/kvectors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Kvectors
========

.. automodule:: meshlode.lib.kvectors
:members:
:undoc-members:
6 changes: 6 additions & 0 deletions docs/src/references/metatensor/directpotential.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DirectPotential
###############

.. autoclass:: meshlode.metatensor.DirectPotential
:members:
:undoc-members:
6 changes: 6 additions & 0 deletions docs/src/references/metatensor/ewaldpotential.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
EwaldPotential
##############

.. autoclass:: meshlode.metatensor.EwaldPotential
:members:
:undoc-members:
3 changes: 2 additions & 1 deletion docs/src/references/metatensor/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ For a plain :py:class:`torch.Tensor` refer to :ref:`calculators`.

.. toctree::
:maxdepth: 1
:glob:

meshpotential
./*
6 changes: 0 additions & 6 deletions docs/src/references/metatensor/meshpotential.rst

This file was deleted.

6 changes: 6 additions & 0 deletions docs/src/references/metatensor/pmepotential.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PMEPotential
############

.. autoclass:: meshlode.metatensor.PMEPotential
:members:
:undoc-members:
134 changes: 0 additions & 134 deletions examples/madelung.py

This file was deleted.

123 changes: 123 additions & 0 deletions examples/neighborlist_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""
Computations with explicit Neighbor Lists
=========================================

This example will explain how to use the metatensor branch of Meshlode with an attached
neighborlist to an :py:class:`metatensor.torch.atomistic.System` object.
"""

# %%

import math

import numpy as np
import torch
from ase import Atoms
from ase.neighborlist import neighbor_list
from metatensor.torch import Labels, TensorBlock
from metatensor.torch.atomistic import NeighborListOptions, System

import meshlode


# %%
# Define simple example structure having the CsCl structure and compute the reference
# values. PMEPotential by default outputs the types sorted according to the atomic
# number. Thus, we input the compound "CsCl" and "ClCs" since Cl and Cs have atomic
# numbers 17 and 55, respectively.

types = torch.tensor([17, 55]) # Cl and Cs
positions = torch.tensor([[0, 0, 0], [0.5, 0.5, 0.5]])
charges = torch.tensor([-1.0, 1.0]).reshape(-1, 1)
cell = torch.eye(3)

# %%
# Define the expected values of the energy

n_atoms = len(types)
madelung = 2 * 1.7626 / math.sqrt(3)
energies_ref = -madelung * torch.ones((n_atoms, 1))

# %%
# We first define general parameters for our calculation MeshLODE.

atomic_smearing = 0.1
cell = torch.eye(3)
mesh_spacing = atomic_smearing / 4
interpolation_order = 2


# %%
# Generate neighbor list using ASE's :py:func:`neighbor_list()
# <ase.neighborlist.neighbor_list>` function.

sr_cutoff = np.sqrt(3) * 0.8
struc = Atoms(positions=positions, cell=cell, pbc=True)
nl_i, nl_j, nl_S, nl_D = neighbor_list("ijSD", struc, sr_cutoff)


# %%
# Convert ASE neighbor list into suitable format for a Metatensor system.

neighbors = TensorBlock(
values=torch.from_numpy(nl_D.astype(np.float32).reshape(-1, 3, 1)),
samples=Labels(
names=[
"first_atom",
"second_atom",
"cell_shift_a",
"cell_shift_b",
"cell_shift_c",
],
values=torch.from_numpy(np.vstack([nl_i, nl_j, nl_S.T]).T),
),
components=[Labels.range("xyz", 3)],
properties=Labels.range("distance", 1),
)


# %%
# Define the system.

system = System(types=types, positions=positions, cell=cell)

# %%
# Attach charges to the system.

data = TensorBlock(
values=charges,
samples=Labels.range("atom", charges.shape[0]),
components=[],
properties=Labels.range("charge", charges.shape[1]),
)
system.add_data(name="charges", data=data)

# %%
# Attach ``neighbors`` to ``system`` object.

nl_options = NeighborListOptions(cutoff=sr_cutoff, full_list=True)
system.add_neighbor_list(options=nl_options, neighbors=neighbors)

pme = meshlode.metatensor.PMEPotential(
atomic_smearing=atomic_smearing,
mesh_spacing=mesh_spacing,
interpolation_order=interpolation_order,
subtract_self=True,
sr_cutoff=sr_cutoff,
)
potential = pme.compute(system)

# %%
# The total energy is just the sum of all atomic energies

print(potential)

# total_energy_metatensor = torch.sum(potential[0].values)

# # %%
# # Compare against reference Madelung constant and reference energy:

# print("Using the metatensor version")
# print(f"Computed energies on each atom = {potential[0].values.tolist()}")
# print(f"Reference Madelung constant = {madelung:.3f}")
# print(f"Total energy = {total_energy_metatensor[0].values}")
Loading