Closed superstar54 closed 2 months ago
After spent 2 hour debug. :sob: , I found it could be a bug in the nglveiw
.
Here is an example:
from ase import Atoms
import nglview
atoms = Atoms(
["Si", "Si"],
cell = [[0.0, 2.69, 2.69],
[2.69, 0.0, 2.69],
[2.69, 2.69, 0.0],
],
positions = [[2.69, 2.69, 2.69], [4.04, 4.04, 4.04]],
pbc = [True, True, True],
)
view = nglview.NGLWidget()
view.add_component(
nglview.ASEStructure(atoms),
default_representation=True,
name="Structure",
)
view.add_unitcell()
cell = atoms.cell
print("cell: ", cell)
shapes = (
# axis x, y, z
("cylinder",tuple((0, 0, 0)),tuple([5, 0, 0]),tuple((1, 0, 0,)), 0.1),
("cylinder",tuple((0, 0, 0)),tuple([0, 5, 0]),tuple((0, 1, 0,)), 0.1),
("cylinder",tuple((0, 0, 0)),tuple([0, 0, 5]),tuple((0, 0, 1,)), 0.1),
("cylinder",tuple((0, 0, 0)),tuple(cell[0] ),tuple((1, 0, 0,)), 0.2),
("cylinder",tuple((0, 0, 0)),tuple(cell[1] ),tuple((0, 0, 0,)), 0.2),
("cylinder",tuple((0, 0, 0)),tuple(cell[2] ),tuple((0, 0, 0,)), 0.2),
)
view._add_shape(shapes, name = "axis")
view
In nglview, it draw the a-aixs, which align with the x-axis (small, long, red color). However, the a-axis (cell[0]=[0.0, 2.69, 2.69]
) should in the y-z plane, as shown by (big, short, red color) cylinder.
Thus, there is a mismatch between, the default nglview representation and the shapes added by user. Thus, when we draw bonds manually, the position of bonds are wrong in this case.
Should we draw everything (ball, cell, bonds) manually? @yakutovicha @cpignedoli Any idea how to solve this problem?
From @cpignedoli . Steps to reproduce. In QE App, select the “Silicon (diamond)” example structure, and click on “convert to primitive cell”. At every click, it completely changes the bonds, and they are wrong: see two screenshots below.![Screenshot from 2024-03-05 12-32-07](https://github.com/aiidalab/aiidalab-widgets-base/assets/11457659/abab54c4-88ce-4314-9905-838cb6c49ccf)