sisl icon indicating copy to clipboard operation
sisl copied to clipboard

`within_inf` returns wrong supercell indices?

Open pfebrer opened this issue 7 months ago • 0 comments

Describe the bug

The supercell indices that within_inf returns are for the atoms translated to the unit cell, is this intended?

Code to reproduce problem

import numpy as np

# Create a geometry with an atom outside of the unit cell
geometry = sisl.Geometry([-0.5, 0, 0], lattice=np.diag([2, 10, 10]))

# Search for atoms
search = sisl.Lattice(np.diag([3, 10, 10]))
ia, xyz, isc = geometry.within_inf(search, periodic=[True, True, True])

print("ia", ia)
print("xyz", xyz)
print("isc", isc)
ia [0]
xyz [[1.5 0.  0. ]]
isc [[0 0 0]]

As you can see, it says that the image of atom 0 on sc (0,0,0) is inside the search lattice, which is a lie. The supercell index should be (1, 0, 0), unless the function specifies that it will first translate atoms to the unit cell.

I understand even less the output if I change the search to [2, 10, 10]:

import numpy as np
geometry = sisl.Geometry([-0.5, 0, 0], lattice=np.diag([2, 10, 10]))

search = sisl.Lattice(np.diag([2, 10, 10]))
ia, xyz, isc = geometry.within_inf(search, periodic=[True, True, True])

print("ia", ia)
print("xyz", xyz)
print("isc", isc)
ia []
xyz []
isc []

It says there are no atoms in the search lattice, this is clearly wrong, isn't it? Regardless of whether the first one is intended.

pfebrer avatar Nov 08 '23 17:11 pfebrer