【问题标题】:How to display a Protein Data Bank PDB in a Jupyter notebook?如何在 Jupyter 笔记本中显示蛋白质数据库 PDB?
【发布时间】:2018-10-28 11:07:39
【问题描述】:

我正在尝试关注这个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,我相信这不再是问题:python 3.x ImportError: No module named 'cStringIO',现在应该没问题,因为不推荐使用 python2。

【问题讨论】:

  • nglview 0.4 似乎已经过时了,github.com/arose/nglview/releases 上的最新版本是 1.1.4。 (您的问题看起来像是未正确配置为在 Python 2 Python 3 下运行的代码。)
  • @orbeckst 我在 python 3.x 下运行。但这就是方达安装的
  • 在使用 Python 3.6 的 conda 环境中,我做了一个 conda install nglview,它使用 jupyter 4.4 拉出了 1.1.3-py36_0 conda-forge(我使用 conda-forge 通道) .0.来自mdanalysis.org/2016/03/14/nglview 的示例按照宣传的方式工作。
  • 我在 python 3.x 下运行。但这就是 Fonda 所安装的。也许默认的 conda 频道会执行过时的 nglview 包?
  • 你不使用 conda 吗?至少从您的堆栈跟踪中看起来是这样的。您可以尝试使用conda remove nglview 卸载nglview 吗?如果这失败了,那么这个包可能已经被 pip 或 easy_installed。试试pip remove nglview。如果这仍然没有帮助,请手动 rm -r 与 nglview 相关的所有内容。然后conda install -c conda-forge nglview。 (我在 Ubuntu 16.04.4 和 Python 3.6.4 下尝试了 conda 安装,并且没有问题。)

标签: python python-3.x anaconda mdanalysis


【解决方案1】:

我会尝试通过conda(和Anaconda distribution)安装干净的nglview:

尝试使用

卸载 nglview
conda remove nglview

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

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

conda install -c conda-forge nglview

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-27
    • 2016-09-17
    相关资源
    最近更新 更多