How to calculate displacement in each coordinate and wrap w.r.t. lattice parameter?

The problem is my box is not orthorhombic (base angles different than 90 degrees). So, I am getting wrong results with the formula,

def distance(a, b):
dx = abs(a - b)
x = min(dx, abs(A - dx))

dy = abs(a - b)
y = min(dy, abs(B - dy))

dz = abs(a - b)
z = min(dz, abs(C - dz))

return sp.sqrt(x**2 + y**2 + z**2)

Any suggestion on how to get the proper distance between any atom and its neighbours, including the periodic images of the neighbours. Basically, it makes the results of RDF and CN unphysical. • Have you tried using the Ovito tool? There are built in functions to evaluate the RDF and CN from the menu. Alternatively, it might be possible to use a tool such as Vesta and convert the unit cell to a rectangular one.
– PBH
Dec 1 '21 at 1:33
• @PBH why not write an answer? Comments are temporary and can be removed permanently without any notification. Dec 1 '21 at 16:48

Sticking with ase you can use the built-in get_distance function. It supports non-orthogonal unit cells.

An example to get the distance between atom number a and atom number b is:

import ase.io