Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken with ASE 3.23.0b1 #994

Closed
HaoZeke opened this issue Sep 6, 2021 · 2 comments
Closed

Broken with ASE 3.23.0b1 #994

HaoZeke opened this issue Sep 6, 2021 · 2 comments

Comments

@HaoZeke
Copy link

HaoZeke commented Sep 6, 2021

python -c 'import nglview; print(nglview.__version__)' # 3.0.3'
python -c 'import ipywidgets; print(ipywidgets.__version__)' #  '7.6.3'
python -c 'import ase; print(ase.__version__)' #  '3.23.0b1'

Consider the following snippet, which works with ase gui and other visualization methods:

import nglview as nv
from ase import Atoms
from ase.build import fcc111

atoms = fcc111('Au', size=(3,3,1))
atoms.symbols[4:10]='Ag'
nv.show_ase(atoms)

This errors out with:

Error output
---------------------------------------------------------------------------
LinAlgError                               Traceback (most recent call last)
/tmp/ipykernel_335/3578296922.py in <module>
----> 1 nv.show_ase(atoms)

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/nglview/show.py in show_ase(ase_atoms, **kwargs)
     83     """
     84     structure = ASEStructure(ase_atoms)
---> 85     return NGLWidget(structure, **kwargs)
     86 
     87 

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/nglview/widget.py in __init__(self, structure, representations, parameters, **kwargs)
    243         else:
    244             if structure is not None:
--> 245                 self.add_structure(structure, **kwargs)
    246 
    247         if representations:

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/nglview/widget.py in add_structure(self, structure, **kwargs)
   1111         if not isinstance(structure, Structure):
   1112             raise ValueError(f'{structure} is not an instance of Structure')
-> 1113         self._load_data(structure, **kwargs)
   1114         self._ngl_component_ids.append(structure.id)
   1115         if self.n_components > 1:

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/nglview/widget.py in _load_data(self, obj, **kwargs)
   1229         if not is_url:
   1230             if hasattr(obj, 'get_structure_string'):
-> 1231                 blob = obj.get_structure_string()
   1232                 kwargs2['ext'] = obj.ext
   1233                 passing_buffer = True

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/nglview/adaptor.py in get_structure_string(self)
    135 
    136     def get_structure_string(self):
--> 137         return _get_structure_string(self._ase_atoms.write)
    138 
    139 

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/nglview/adaptor.py in _get_structure_string(write_method, suffix)
     57 def _get_structure_string(write_method, suffix='.pdb'):
     58     with mkstemp_wrapper(suffix=suffix) as fname:
---> 59         write_method(fname)
     60         with open(fname) as fh:
     61             return fh.read()

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/ase/atoms.py in write(self, filename, format, **kwargs)
   1962         """
   1963         from ase.io import write
-> 1964         write(filename, self, format, **kwargs)
   1965 
   1966     def iterimages(self):

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/ase/io/formats.py in write(filename, images, format, parallel, append, **kwargs)
    626     io = get_ioformat(format)
    627 
--> 628     return _write(filename, fd, format, io, images,
    629                   parallel=parallel, append=append, **kwargs)
    630 

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/ase/parallel.py in new_func(*args, **kwargs)
    242             not kwargs.pop('parallel', True)):
    243             # Disable:
--> 244             return func(*args, **kwargs)
    245 
    246         ex = None

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/ase/io/formats.py in _write(filename, fd, format, io, images, parallel, append, **kwargs)
    662                 # XXX remember to re-enable compressed open
    663                 # fd = io.open(filename, mode)
--> 664             return io.write(fd, images, **kwargs)
    665         finally:
    666             if open_new and fd is not None:

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/ase/io/formats.py in _write_wrapper(self, *args, **kwargs)
    189         if function is None:
    190             raise ValueError(f'Cannot write to {self.name}-format')
--> 191         return function(*args, **kwargs)
    192 
    193     @property

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/ase/utils/__init__.py in iofunc(file, *args, **kwargs)
    484                 else:
    485                     fd = file
--> 486                 obj = func(fd, *args, **kwargs)
    487                 return obj
    488             finally:

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/ase/io/proteindatabank.py in write_proteindatabank(fileobj, images, write_arrays)
    192         cellpar = cell_to_cellpar(currentcell)
    193         exportedcell = cellpar_to_cell(cellpar)
--> 194         rotation = np.linalg.solve(currentcell, exportedcell)
    195         # ignoring Z-value, using P1 since we have all atoms defined explicitly
    196         format = 'CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P 1\n'

<__array_function__ internals> in solve(*args, **kwargs)

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/numpy/linalg/linalg.py in solve(a, b)
    391     signature = 'DD->D' if isComplexType(t) else 'dd->d'
    392     extobj = get_linalg_error_extobj(_raise_linalgerror_singular)
--> 393     r = gufunc(a, b, signature=signature, extobj=extobj)
    394 
    395     return wrap(r.astype(result_t, copy=False))

~/Git/Github/lesHouches_greens21/tmp/lib/python3.8/site-packages/numpy/linalg/linalg.py in _raise_linalgerror_singular(err, flag)
     86 
     87 def _raise_linalgerror_singular(err, flag):
---> 88     raise LinAlgError("Singular matrix")
     89 
     90 def _raise_linalgerror_nonposdef(err, flag):

LinAlgError: Singular matrix

Although simpler basic snippets work:

import nglview as nv
from ase import Atoms
atoms = Atoms('N2', positions=[[0, 0, -1], [0, 1, 1]])
nv.show_ase(atoms)

Trajectories are also still working, just not the new Symbols approach to Atoms objects.

@hainm
Copy link
Collaborator

hainm commented Sep 7, 2021

hi @HaoZeke

I think it's the problem with ASE, not nglview. Under the hood, nglview was trying to convert the Atoms object to pdb file.

    ...: from ase import Atoms
    ...: from ase.build import fcc111
    ...: 
    ...: atoms = fcc111('Au', size=(3,3,1))
    ...: atoms.symbols[4:10]='Ag'

In [15]: atoms.write("abc.pdb") # THIS CAUSES THE ISSUE

Please ping ASE team for the answer. Cheers.

@HaoZeke
Copy link
Author

HaoZeke commented Sep 7, 2021

Thanks for the prompt response, I've reported it upstream:
https://gitlab.com/ase/ase/-/issues/964

@HaoZeke HaoZeke closed this as completed Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants