Skip to content

Periodic boundary conditions #92

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

Closed
peastman opened this issue May 16, 2022 · 19 comments
Closed

Periodic boundary conditions #92

peastman opened this issue May 16, 2022 · 19 comments
Assignees

Comments

@peastman
Copy link
Collaborator

I want to try applying a model to a larger system that uses periodic boundary conditions. Currently that isn't supported. It looks to me like the only class that would need to be modified is Distance? But it implements the calculation with torch_cluster.radius_graph(), which doesn't support periodic boundary conditions. So either we would need to add that feature to torch_cluster, or else we would need to rewrite that class to work differently.

Any suggestions on the best way to approach this?

@giadefa
Copy link
Contributor

giadefa commented May 16, 2022 via email

@raimis
Copy link
Collaborator

raimis commented May 17, 2022

The proof-of-concept kernel is here (#61). It was optimized for small molecules, but at the moment neither batching, nor the periodic boundary condition are not supported.

@peastman
Copy link
Collaborator Author

If we can add periodic boundary conditions to it, that would be great. For now I think it's fine to only support rectangular boxes, though we should keep open the possibility of triclinic boxes in the future. Or we could just include that from the start, since it only adds minimal complexity.

@giadefa
Copy link
Contributor

giadefa commented May 17, 2022 via email

@peastman
Copy link
Collaborator Author

Since #61 is still under development, I think it would make more sense to include the changes there. The code is very simple. After computing the delta between two positions, you just add a few extra lines to adjust it. Here's the code from OpenMM for a rectangular box.

delta.x -= floor(delta.x*invPeriodicBoxSize.x+0.5f)*periodicBoxSize.x;
delta.y -= floor(delta.y*invPeriodicBoxSize.y+0.5f)*periodicBoxSize.y;
delta.z -= floor(delta.z*invPeriodicBoxSize.z+0.5f)*periodicBoxSize.z;

For a triclinic box it's just a little bit more complicated.

real scale3 = floor(delta.z*invPeriodicBoxSize.z+0.5f);
delta.x -= scale3*periodicBoxVecZ.x;
delta.y -= scale3*periodicBoxVecZ.y;
delta.z -= scale3*periodicBoxVecZ.z;
real scale2 = floor(delta.y*invPeriodicBoxSize.y+0.5f);
delta.x -= scale2*periodicBoxVecY.x;
delta.y -= scale2*periodicBoxVecY.y;
real scale1 = floor(delta.x*invPeriodicBoxSize.x+0.5f);
delta.x -= scale1*periodicBoxVecX.x;

@giadefa
Copy link
Contributor

giadefa commented May 17, 2022 via email

@raimis
Copy link
Collaborator

raimis commented May 17, 2022

Thanks @peastman! I'll try to move the code to NNPOps and make something working tomorrow.

@raimis raimis self-assigned this May 17, 2022
@peastman
Copy link
Collaborator Author

peastman commented May 4, 2023

What's the status of this? We're working on a project that needs periodic boundary conditions.

@FranklinHu1
Copy link

I have a basic implementation of periodic boundary conditions using square boxes that is working for liquid systems (e.g. water and imidazole), but it could definitely be optimized for better integration with the torchmd-net architecture. It would be great to collaborate with someone on the torchmd-net team about getting this feature optimized and added!

@RaulPPelaez
Copy link
Collaborator

I will add triclinic PBC from NNPops to #169. The new distance module there is a drop in replacement for Distance.

@FranklinHu1
Copy link

Thanks! Roughly what would the timeline be for PBCs to be usable within torchmd-net?

@RaulPPelaez
Copy link
Collaborator

I am actively working on it. In that PR I have an N^2 and a cell list backend. The N^2 I have ready, with the cell list I have cubic boxes working but triclinic is giving me a a bit of a headache.
I will clean up a bit and upload with cubic box support ASAP.

@peastman
Copy link
Collaborator Author

peastman commented May 5, 2023

When you say cubic, I assume you mean rectangular? What's the issue with triclinic?

@RaulPPelaez
Copy link
Collaborator

I meant rectangular, yes. The cell list requires to bin the domain and identify the bin for each particle. In a rectangular cell this is straight forward, say:

int cell_x = floor((pos_x + 0.5*L_x)/cutoff)

I am struggling to achieve this in a triclinic box in a sane way.

@giadefa
Copy link
Contributor

giadefa commented May 5, 2023 via email

@FranklinHu1
Copy link

FranklinHu1 commented May 5, 2023

Is it possible to just release rectangular box PBCs first?

@peastman
Copy link
Collaborator Author

peastman commented May 5, 2023

You can bin it in exactly the same way. A triclinic box is identical to a rectangular box with offsets between copies. The only part you need to handle differently is when identifying which bins in other periodic copies you need to search. See https://doi.org/10.1002/(SICI)1096-987X(19971130)18:15%3C1930::AID-JCC8%3E3.0.CO;2-P for the theory of how it works. And see https://github.com/openmm/openmm/blob/master/platforms/reference/src/SimTKReference/ReferenceNeighborList.cpp for a reference implementation in OpenMM.

We don't care about triclinic

But we do. :)

@RaulPPelaez
Copy link
Collaborator

Thanks for the refs @peastman!. Since rectangular seems more time pressing I will work to finish that ASAP and then I will finish triclinic.

@RaulPPelaez
Copy link
Collaborator

Lets move the discussion to #169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants