Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

[Feature Request] Can FNNTW support the periodic boundary for triclinic box? #7

Open
mushroomfire opened this issue Oct 8, 2023 · 4 comments

Comments

@mushroomfire
Copy link

Hi,
FNNTW now supports periodic boundary conditions for a rectangular box, where the angles between the two line vectors are 90 degrees. Is it possible to make it more generalizable for a triclinic box? This feature proves useful in certain simulation domains. Let's consider the box below, where each row represents a box vector:

box = np.array([[a1, a2, a3], [b1, b2, b3], [c1, c2, c3]])

The rectangular box is like below:

box = np.array([[a, 0, 0], [0, b, 0], [0, 0, c]])

A distance vector rij = np.array([x, y, z]) can be wrapped as below:

def pbc(rij, box):
      nz = rij[2] / box[2][2]
      ny = (rij[1] - nz * box[2][1]) / box[1][1]
      nx = (rij[0] - ny * box[1][0] - nz * box[2][0]) / box[0][0]
      n =[nx, ny, nz]
      for i in range(3):
            if n[i] > 0.5:
                n[i] -= 1
            elif n[i] < -0.5:
                n[i] += 1
      return n[0] * box[0] + n[1] * box[1] + n[2] * box[2]

Maybe change the distance equation in codes can achieve this?
Thank you very much!

@cavemanloverboy
Copy link
Owner

just noticed this issue, sorry. i have a new library now bosque that is faster.

triclinic is interesting. best i can come up with off the top of my head is coordinate transformation + weighted squared euclidean

@cavemanloverboy
Copy link
Owner

or, since it's periodic, you should be able to just displace things until it's a box. here's a 2D example. it can be done in 3d as well

image

@mushroomfire
Copy link
Author

Thanks for your reply. I am unsure if this approach can maintain the calculation speed. In molecular dynamics (MD) simulation, there is a code that is capable of handling both triclinic and rectangular boxes with periodic or free boundaries, and it also offers high computational efficiency. I have provided a reference to this code for your convenience: https://gitlab.com/stuko/ovito/-/blob/master/src/ovito/particles/util/NearestNeighborFinder.cpp. Later on, I will also attempt to use Bosque.

@cavemanloverboy
Copy link
Owner

Yes, definitely not ideal. Best of luck. If I can be of any help, make an issue on bosque and we can discuss there

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

No branches or pull requests

2 participants