nglviewer / nglview

Jupyter widget to interactively view molecular structures and trajectories
http://nglviewer.org/nglview/latest/
Other
821 stars 134 forks source link

show_psi4 not working #980

Closed duerrsimon closed 3 years ago

duerrsimon commented 3 years ago

Seems like show_psi4 is broken. show_pdb or other commands work without problem.

view = nglview.show_psi4(psi4.geometry("""H 0 0 0""")) 
view
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-13-7ee333b82b11> in <module>
----> 1 view = nglview.show_psi4(psi4.geometry("""H 0 0 0"""))
      2 view

~/miniconda3/envs/iesm/lib//python3.7/site-packages/nglview/show.py in show_psi4(obj, **kwargs)
    125     ... view
    126     """
--> 127     return NGLWidget(QCElementalStructure(obj), **kwargs)
    128 
    129 

~/miniconda3/envs/iesm/lib//python3.7/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:

~/miniconda3/envs/iesm/lib//python3.7/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:

~/miniconda3/envs/iesm/lib//python3.7/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

~/miniconda3/envs/iesm/lib//python3.7/site-packages/nglview/adaptor.py in get_structure_string(self)
    159 
    160     def get_structure_string(self):
--> 161         return self._obj.to_string('nglview-sdf')
    162 
    163 

~/miniconda3/envs/iesm/lib/python3.7/site-packages/psi4/driver/qcdb/molecule.py in to_string(self, dtype, units, atom_format, ghost_format, width, prec)
   1244             ghost_format=ghost_format,
   1245             width=width,
-> 1246             prec=prec)
   1247         return smol
   1248 

~/miniconda3/envs/iesm/lib/python3.7/site-packages/qcelemental/molparse/to_string.py in to_string(molrec, dtype, units, atom_format, ghost_format, width, prec, return_data)
     78     }
     79     if dtype not in default_units:
---> 80         raise KeyError(f"dtype '{dtype}' not understood.")
     81 
     82     # Handle units

KeyError: "dtype 'nglview-sdf' not understood."
hainm commented 3 years ago

I bet your qcelemnetal is outdated: https://github.com/MolSSI/QCElemental/blob/85b890919ad5ef0d796ee68557b49497004878ea/qcelemental/molparse/to_string.py#L359

https://github.com/MolSSI/QCElemental/blob/85b890919ad5ef0d796ee68557b49497004878ea/qcelemental/molparse/to_string.py#L74-L91

duerrsimon commented 3 years ago

Indeed. I was on 0.4.1. pip install -U qcelemental fixed it. With latest 'v0.20.0' it is running.