简体   繁体   English

如何在 Jupyter 笔记本中显示蛋白质数据库 PDB?

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

I am trying to follow this post , but it fails to display a PDB inside a Jupyter notebook:我正在尝试关注这篇文章,但它无法在 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')

When I try to do:当我尝试做:

w = nv.show_mdanalysis(protein)
w

I get:我得到:

---------------------------------------------------------------------------
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'

Edit Feb. 2020: I believe this is not an issue anymore if the libraries you are using updated their code to python3 properly: python 3.x ImportError: No module named 'cStringIO' , and it should be ok by now as python2 is deprecated. 2020 年 2 月编辑:如果您使用的库将其代码正确更新为 python3,我相信这不再是问题: python 3.x ImportError: No module named 'cStringIO' ,现在应该没问题,因为 python2 已弃用.

I would attempt to get a clean nglview installation via conda (and the Anaconda distribution ):我会试图获得通过清洁nglview安装康达(和蟒蛇分布):

Try uninstalling nglview with尝试卸载 nglview

conda remove nglview

just in case there's an old version.以防万一有旧版本。 If this conda-remove fails then this package might have been pip or easy_installed .如果这个 conda-remove 失败,那么这个包可能是pipeasy_installed Try pip remove nglview .尝试pip remove nglview If this still not helping, you have to look for the installed nglview package and manually remove it with rm but I do not want to put copy&paste instructions here as this requires careful looking at files.如果这仍然没有帮助,您必须查找已安装的 nglview 包并使用rm手动删除它,但我不想在此处放置复制和粘贴说明,因为这需要仔细查看文件。

Once all traces of nglview have been removed, install the latest version of nglview from the conda-forge channel with conda :一旦nglview的所有痕迹已被删除,安装最新版本的从康达锻通道nglviewconda

conda install -c conda-forge nglview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM