如何在 Jupyter notebook 中显示 Protein Data Bank PDB?

How to display a Protein Data Bank PDB in a Jupyter notebook?

我正在尝试遵循此 post,但它无法在 Jupyter 笔记本中显示 PDB:

import MDAnalysis as mda
import nglview as nv
from nglview.datafiles import PDB, XTC

u = mda.Universe(PDB, XTC)

protein = u.select_atoms('protein')

当我尝试这样做时:

w = nv.show_mdanalysis(protein)
w

我得到:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-499e28f0ffd3> in <module>()
----> 1 w = nv.show_mdanalysis(protein)
      2 w

~/anaconda3/lib/python3.6/site-packages/nglview-0.4-py3.5.egg/nglview/__init__.py in show_mdanalysis(atomgroup, **kwargs)
    118     '''
    119     structure_trajectory = MDAnalysisTrajectory(atomgroup)
--> 120     return NGLWidget(structure_trajectory, **kwargs)
    121 
    122 

~/anaconda3/lib/python3.6/site-packages/nglview-0.4-py3.5.egg/nglview/__init__.py in __init__(self, structure, trajectory, representations, parameters, **kwargs)
    347         if parameters:
    348             self.parameters = parameters
--> 349         self.set_structure(structure)
    350         if trajectory:
    351             self.trajectory = trajectory

~/anaconda3/lib/python3.6/site-packages/nglview-0.4-py3.5.egg/nglview/__init__.py in set_structure(self, structure)
    372     def set_structure(self, structure):
    373         self.structure = {
--> 374             "data": structure.get_structure_string(),
    375             "ext": structure.ext,
    376             "params": structure.params

~/anaconda3/lib/python3.6/site-packages/nglview-0.4-py3.5.egg/nglview/__init__.py in get_structure_string(self)
    313                 "'MDAnalysisTrajectory' requires the 'MDAnalysis' package"
    314             )
--> 315         import cStringIO
    316         u = self.atomgroup.universe
    317         u.trajectory[0]

ModuleNotFoundError: No module named 'cStringIO'

2020 年 2 月编辑:我相信如果您使用的库将其代码正确更新为 python3,我相信这不再是问题:,现在应该没问题了,因为 python2 已弃用。

我会尝试通过 conda (and the Anaconda distribution 获得干净的 nglview 安装):

尝试使用

卸载 nglview
conda remove nglview

以防万一有旧版本。如果此 conda-remove 失败,则此程序包可能已 pipeasy_installed。尝试 pip remove nglview。如果这仍然没有帮助,您必须查找已安装的 nglview 包并使用 rm 手动将其删除,但我不想在此处放置复制和粘贴说明,因为这需要仔细查看文件。

删除所有 nglview 痕迹后,安装最新版本的 nglview from the conda-forge channel conda:

conda install -c conda-forge nglview