pyiron / pyiron_atomistics

pyiron_atomistics - an integrated development environment (IDE) for atomistic simulation in computational materials science.
https://pyiron-atomistics.readthedocs.io
BSD 3-Clause "New" or "Revised" License
44 stars 15 forks source link

nglview notebook tests broken #728

Open pmrv opened 2 years ago

pmrv commented 2 years ago

Currently the notebook tests fails on master. It seems that this is because the current nglview gives an error in import.

Exception encountered at "In [3]":
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [3], in <cell line: 22>()
     18 water = pr.create_atoms(elements=['H', 'H', 'O'], 
     19                         positions=[r_H1, r_H2, r_O], 
     20                         cell=unit_cell, pbc=True)
     21 water.set_repeat([n, n, n])
---> 22 water.plot3d()

File ~/work/pyiron_atomistics/pyiron_atomistics/pyiron_atomistics/atomistics/structure/atoms.py:1224, in Atoms.plot3d(self, mode, show_cell, show_axes, camera, spacefill, particle_size, select_atoms, background, color_scheme, colors, scalar_field, scalar_start, scalar_end, scalar_cmap, vector_field, vector_color, magnetic_moments, view_plane, distance_from_camera, opacity)
   1201 def plot3d(
   1202     self,
   1203     mode="NGLview",
   (...)
   1222     opacity=1.0,
   1223 ):
-> 1224     return self.visualize.plot3d(
   1225         mode=mode,
   1226         show_cell=show_cell,
   1227         show_axes=show_axes,
   1228         camera=camera,
   1229         spacefill=spacefill,
   1230         particle_size=particle_size,
   1231         select_atoms=select_atoms,
   1232         background=background,
   1233         color_scheme=color_scheme,
   1234         colors=colors,
   1235         scalar_field=scalar_field,
   1236         scalar_start=scalar_start,
   1237         scalar_end=scalar_end,
   1238         scalar_cmap=scalar_cmap,
   1239         vector_field=vector_field,
   1240         vector_color=vector_color,
   1241         magnetic_moments=magnetic_moments,
   1242         view_plane=view_plane,
   1243         distance_from_camera=distance_from_camera,
   1244         opacity=opacity,
   1245     )

File ~/work/pyiron_atomistics/pyiron_atomistics/pyiron_atomistics/atomistics/structure/_visualize.py:103, in Visualize.plot3d(self, mode, show_cell, show_axes, camera, spacefill, particle_size, select_atoms, background, color_scheme, colors, scalar_field, scalar_start, scalar_end, scalar_cmap, vector_field, vector_color, magnetic_moments, view_plane, distance_from_camera, opacity)
     49 """
     50 Plot3d relies on NGLView or plotly to visualize atomic structures. Here, we construct a string in the "protein database"
     51 
   (...)
    100     * The colour interpretation of some hex codes is weird, e.g. 'green'.
    101 """
    102 if mode == "NGLview":
--> 103     return self._plot3d(
    104         show_cell=show_cell,
    105         show_axes=show_axes,
    106         camera=camera,
    107         spacefill=spacefill,
    108         particle_size=particle_size,
    109         select_atoms=select_atoms,
    110         background=background,
    111         color_scheme=color_scheme,
    112         colors=colors,
    113         scalar_field=scalar_field,
    114         scalar_start=scalar_start,
    115         scalar_end=scalar_end,
    116         scalar_cmap=scalar_cmap,
    117         vector_field=vector_field,
    118         vector_color=vector_color,
    119         magnetic_moments=magnetic_moments,
    120         view_plane=view_plane,
    121         distance_from_camera=distance_from_camera,
    122     )
    123 elif mode == "plotly":
    124     return self._plot3d_plotly(
    125         camera=camera,
    126         particle_size=particle_size,
   (...)
    131         opacity=opacity,
    132     )

File ~/work/pyiron_atomistics/pyiron_atomistics/pyiron_atomistics/atomistics/structure/_visualize.py:287, in Visualize._plot3d(self, show_cell, show_axes, camera, spacefill, particle_size, select_atoms, background, color_scheme, colors, scalar_field, scalar_start, scalar_end, scalar_cmap, vector_field, vector_color, magnetic_moments, view_plane, distance_from_camera)
    232 """
    233 Plot3d relies on NGLView to visualize atomic structures. Here, we construct a string in the "protein database"
    234 ("pdb") format, then turn it into an NGLView "structure". PDB is a white-space sensitive format, so the
   (...)
    284     * The colour interpretation of some hex codes is weird, e.g. 'green'.
    285 """
    286 try:  # If the graphical packages are not available, the GUI will not work.
--> 287     import nglview
    288 except ImportError:
    289     raise ImportError(
    290         "The package nglview needs to be installed for the plot3d() function!"
    291     )

File /usr/share/miniconda/envs/test/lib/python3.10/site-packages/nglview/__init__.py:4, in <module>
      1 import warnings
      3 # for doc
----> 4 from . import adaptor, datafiles, show, widget
      5 from ._version import get_versions
      6 from .adaptor import *

File /usr/share/miniconda/envs/test/lib/python3.10/site-packages/nglview/show.py:13, in <module>
      3 from . import datafiles
      4 from .adaptor import (ASEStructure, ASETrajectory, BiopythonStructure,
      5                       FileStructure, HTMDTrajectory, IODataStructure,
      6                       IOTBXStructure, MDAnalysisTrajectory, MDTrajTrajectory,
   (...)
     11                       RdkitStructure,
     12                       TextStructure)
---> 13 from .widget import NGLWidget
     15 __all__ = [
     16     'demo',
     17     'show_pdbid',
   (...)
     40     'show_biopython',
     41 ]
     44 def show_pdbid(pdbid, **kwargs):

File /usr/share/miniconda/envs/test/lib/python3.10/site-packages/nglview/widget.py:19, in <module>
     15 from traitlets import (Bool, CaselessStrEnum, Dict, Instance, Int, Integer,
     16                        List, Unicode, observe, validate)
     17 import traitlets
---> 19 from . import color, interpolate
     20 from .adaptor import Structure, Trajectory
     21 from .component import ComponentViewer

File /usr/share/miniconda/envs/test/lib/python3.10/site-packages/nglview/color.py:114, in <module>
    110         else:
    111             raise ValueError(f"{obj} must be either list of list or string")
--> 114 ColormakerRegistry = _ColormakerRegistry()

File /usr/share/miniconda/envs/test/lib/python3.10/site-packages/nglview/base.py:10, in _singleton.<locals>.getinstance()
      8 def getinstance():
      9     if cls not in instances:
---> 10         instances[cls] = cls()
     11     return instances[cls]

File /usr/share/miniconda/envs/test/lib/python3.10/site-packages/nglview/color.py:47, in _ColormakerRegistry.__init__(self, *args, **kwargs)
     45 try:
     46     get_ipython() # only display in notebook
---> 47     self._ipython_display_()
     48 except NameError:
     49     pass

File /usr/share/miniconda/envs/test/lib/python3.10/site-packages/nglview/color.py:54, in _ColormakerRegistry._ipython_display_(self, **kwargs)
     52 if self._ready:
     53     return
---> 54 super()._ipython_display_(**kwargs)

AttributeError: 'super' object has no attribute '_ipython_display_'

I guess we miss this because nglview is only installed in the notebook env and therefore not covered by the dependabot.

pmrv commented 2 years ago

See discussions upstream here and here. It seem the current fix is an upper bound on ipywidgets.

niklassiemer commented 2 years ago

Temporary fix (upper bound on ipywidgets is merged in #729.