superstar54 / weas-widget

A widget to visualize and edit atomic structures in Jupyter Notebook
https://weas-widget.readthedocs.io/en/latest/index.html
MIT License
19 stars 3 forks source link

Does not work in colab #50

Open vladislavivanistsev opened 4 months ago

vladislavivanistsev commented 4 months ago

I installed weas-widget in colab as: !pip install weas-widget

Then run: from ase.build import molecule from weas_widget import WeasWidget atoms = molecule("H2O") viewer = WeasWidget() viewer.from_ase(atoms) viewer

Output:

ValueError Traceback (most recent call last)

in <cell line: 5>() 3 atoms = molecule("H2O") 4 viewer = WeasWidget() ----> 5 viewer.from_ase(atoms) 6 viewer

14 frames

/usr/local/lib/python3.10/dist-packages/ipykernel/jsonutil.py in json_clean(obj) 149 150 # we don't understand it, it's probably an unserializable object --> 151 raise ValueError("Can't clean for JSON: %r" % obj)

ValueError: Can't clean for JSON: array([[ 0. , 0. , 0.119262], [ 0. , 0.763239, -0.477047], [ 0. , -0.763239, -0.477047]])

superstar54 commented 4 months ago

Thanks for reporting the issue! It should be fixed in #51 . I just published a new version 0.0.15. Please use this new version.

Screenshot from 2024-04-03 13-56-42

zdcao121 commented 4 months ago

It still has the problem even though the 0.0.15 version is installed. The minimum example is given in the following:

from pymatgen.core import Structure, Lattice
struct = Structure.from_spacegroup("Pm-3m", Lattice.cubic(4.1437), ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]])

from weas_widget import WeasWidget
viewer1 = WeasWidget()
viewer1.from_pymatgen(struct)
viewer1.boundary = [[-0.1, 1.1], [-0.1, 1.1], [-0.1, 1.1]]
viewer1.showBondedAtoms = True
viewer1.colorType = "VESTA"
viewer1

and the output will be

ValueError: Can't clean for JSON: array([0., 0., 0.])
superstar54 commented 4 months ago

Thanks for pointing out the issue. I have fixed this problem in the latest version. The new version also updates its syntax. Please use the following script:

from pymatgen.core import Structure, Lattice
struct = Structure.from_spacegroup("Pm-3m", Lattice.cubic(4.1437), ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]])

from weas_widget import WeasWidget
viewer1 = WeasWidget()
viewer1.from_pymatgen(struct)
# avr is atoms_viewer
viewer1.avr.boundary = [[-0.1, 1.1], [-0.1, 1.1], [-0.1, 1.1]]
viewer1.avr.model_style = 1
viewer1.avr.show_bonded_atoms = True
viewer1.avr.color_type = "VESTA"
viewer1

For more info on the latest version, please visit the docs: https://weas-widget.readthedocs.io/en/latest/quick_start.html

btw, I am not familiar with Pymatgen, so if you find other issues when loading/exporting pymatgen structure, please report an issue. If you could make a PR, that would be great too!