sisl icon indicating copy to clipboard operation
sisl copied to clipboard

sisl.viz Grid plot uses Grid.geometry instead of Grid.lattice

Open zerothi opened this issue 1 year ago • 8 comments

Describe the bug

The problem occurs when the lattice is different from the Geometry.lattice.

Reproducable code

lattice = H.geometry.lattice.untile(3, 0)
grid = sisl.Grid(0.2, geometry=H.geometry, lattice=lattice)
grid.plot()

zerothi avatar Jul 12 '23 19:07 zerothi

I didn't know it was even legal to pass both a geometry and a lattice to Grid :sweat_smile:

pfebrer avatar Jul 12 '23 23:07 pfebrer

I don't know if I should fix this or keep it in mind for the sisl.viz PR. My plan is to work on that during August so that I can finally finish it and merge it to make sisl.viz developeable again.

pfebrer avatar Jul 12 '23 23:07 pfebrer

We can wait, but perhaps it would be nice if we could raise an error if users do this? I.e. if the lattice is different from the geometry.lattice, where could I add this?

zerothi avatar Jul 13 '23 06:07 zerothi

What is the error exactly? Is it that when you use plot_geom=True you get the lattice of the geometry?

pfebrer avatar Jul 13 '23 09:07 pfebrer

If I do grid.plot() it shows the lengths as though it was the geometry.lattice but it should show the grid.lattice, i.e. the values are correct, but it gets stretched and axis are wrong. I wanted to raise an error in the code if they are in-commensurate.

zerothi avatar Jul 13 '23 10:07 zerothi

Ah ok, you can raise the error here:

https://github.com/zerothi/sisl/blob/1ef16ed437174d84c510f6872f01f0613ffcbe9a/src/sisl/viz/plots/grid.py#L539-L545

Using self.grid or grid. But does different lattices make sense for other sisl functionalities?

pfebrer avatar Jul 13 '23 11:07 pfebrer

Ah ok, you can raise the error here:

https://github.com/zerothi/sisl/blob/1ef16ed437174d84c510f6872f01f0613ffcbe9a/src/sisl/viz/plots/grid.py#L539-L545

Using self.grid or grid. But does different lattices make sense for other sisl functionalities?

Yes, when you do grid.sub() or expand densities to grids, then a different lattice is nice (consider graphene -> square grid)

zerothi avatar Jul 13 '23 12:07 zerothi

I see, yes it makes sense :+1:

pfebrer avatar Jul 13 '23 12:07 pfebrer