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

PME for Magnetostatics #54

Open
PicoCentauri opened this issue Sep 19, 2024 · 11 comments
Open

PME for Magnetostatics #54

PicoCentauri opened this issue Sep 19, 2024 · 11 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@PicoCentauri
Copy link
Contributor

Besides, computing the potential for point charges another very important interaction is the one between point dipoles according to

$$ U^{Dip}(\vec{r}) = D \cdot \left( \frac{(\vec{\mu}_i \cdot \vec{\mu}_j)}{r^3} - \frac{3 (\vec{\mu}_i \cdot \vec{r}) (\vec{\mu}_j \cdot \vec{r}) }{r^5} \right) $$

where $`r=|\vec{r}|$ and the prefactor $D$ is given by $D =μ_0/(4π)$. Here, $μ_0$ is the vacuum permittivity.

Analogous to a PME algorithm for point charges there also exist fast solvers for dipolar interaction usually called dipolar PME algorithms as described for example in Cérda 2008 .

@sirmarcel and I saw systems where it seemed crucial to also add point dipoles on top of point charges to model the energy and forces of such structures accurately. Therefore, such calculators could be a very powerful and logical extension of torch-pme.

@PicoCentauri PicoCentauri added enhancement New feature or request help wanted Extra attention is needed labels Sep 19, 2024
@sirmarcel
Copy link
Contributor

This would be very nice, agreed. But maybe this can wait until we released some kind of 1.0?

@PicoCentauri
Copy link
Contributor Author

Yes, I think it has a low priority and probably high difficulty. But, whoever wants, is encouraged to jump on it. :-)

@ceriottm
Copy link
Contributor

As for other things, if you see "design constraints" that would prevent this, and which we can address now (without going on with a full implementation) it'd be worth to consider doing that.

@PicoCentauri
Copy link
Contributor Author

The only thing we don't support is an exponent of 5.

Otherwise, I think everything else should be there.

@chiang-yuan
Copy link

Thanks for developing and open-sourcing this. I would be interested in helping to make this happen earlier and have many immediate needs for different systems. Is anyone actively working on this? Happy to jump into it to lower the barrier to be included as soon as possible. :)

@ceriottm
Copy link
Contributor

hello! great to see involvement already this early after we release the first beta.
I would say that you could start helping merge #128 so you can also ask questions about the code structure and philosophy. There will be a few more adjustments over the next weeks as we have already a TODO list before the accompanying paper gets published, but I'd say that if in the meantime you want to fork, create a magnetostatics branch and open a draft PR, we'll be responsive to questions ^_^.

@PicoCentauri
Copy link
Contributor Author

You can try starting, which is also a good test how well described the code is. If you need some kickstart, we can also have an independent chat. Email me in case.

@chiang-yuan
Copy link

chiang-yuan commented Dec 19, 2024

@ceriottm @PicoCentauri Yes I have used your code calculate the electrostatics and found it is very reliable and smooth! Multipole expansion is the natural extension and much needed.

The code base design is a bit intricate but I found document is great and code is self-explanatory. Maybe a high level question --- Is appending multipoles into a single pass or separating them into multiple class more preferred?

@PicoCentauri
Copy link
Contributor Author

Yes the code still has some not super clear parts. See also #57.

I would go for a different class called DipolarP3M, which should maybe look like

import torch
from torchpme.potentials import Potential


class DipolarP3M:
    def __init__(
        self,
        potential: Potential,
        mesh_spacing: float,
        interpolation_nodes: int = 4,
        full_neighbor_list: bool = False,
        prefactor: float = 1.0,
    ): ...

    def forward(
        self,
        dipoles: torch.Tensor,
        cell: torch.Tensor,
        positions: torch.Tensor,
        neighbor_indices: torch.Tensor,
        neighbor_distances: torch.Tensor,
    ): ...

If we want to implement more then just P3M for dipoles it may makes sense to write another base class and put everything in a subfolder magnetostatics. But we will see how this evolves.

@E-Rum
Copy link
Contributor

E-Rum commented Dec 20, 2024

I want to start implementing the core classes for dipole-dipole interactions, beginning with a direct “potential” since it is the easiest to implement.

The question is: what do you think is the optimal way to store the building blocks? For charge interactions, we can introduce the notion of a scalar potential and calculate the energy as the product of this potential with a scalar charge. For dipoles, the final energy is obtained via a dot product.

Thus, we can either compute the energy directly or, if we aim to preserve the concept of "generalized potential" * "generalized charge" (with the dipole moment acting as the generalized charge in this case), the potential would need to be represented as a vector. However, I am unsure whether this approach is reasonable.

What do you think?

@sirmarcel
Copy link
Contributor

I think for ML purposes it is preferable to have access to the per-atom vector potential, in the same way that we offer access to the per-atom scalar potential.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants