Answers.Body: <p>NGLview runs off the JavaScript libray NGL, which is documented as a series of very helpful examples: <a href="http://nglviewer.org/ngl/gallery/" rel="nofollow noreferrer">in the gallery</a>. The commands are not one-to-one (slightly frustratingly), but it is helpful as you can figure it out easily with a few <code>dir</code> and <code>help</code> commands. In this case whatever example of density being loaded it will reveals that it's a different component —this is the same everywhere as density files do not contain atomic coordinates. Unfortunately, there's not a direct way to generate a new <code>ComponentViewer</code> from different sources to an <code>NGLWidget</code> and you cannot merge two of them: the various <code>.show_*</code> functions return an <code>NGLWidget</code> but aren't part of it.</p>
  <p>First, I am not sure why you are going through a convoluted route for loading a PDB code:</p>
  <pre><code>pdb_code = '1fat'
  
  import nglview as nv
  
  view: nv.NGLWidget = nv.show_pdbid(pdb_code) 
  </code></pre>
  <p>Now, on loading the component a representation is added to it.
  These can hide the representation you then add and things will not make sense, until this detail is recalled! I fall in that pit nearly every time.
  But we can change it with update command:</p>
  <pre><code># I don't like wonky sheets
  view.update_cartoon(smoothSheets=True, color='salmon', component=0)
  </code></pre>
  <p>Now let's add the density map the circuitous way (no <code>.show_url</code>).</p>
  <pre><code>import requests, io
  response: requests.Response = requests.get('https://www.ebi.ac.uk/pdbe/coordinates/files/1fat.ccp4')
  response.raise_for_status()
  fh = io.BytesIO(response.content)
  comp: nv.component.ComponentViewer = view.add_component(fh, ext='ccp4') 
  </code></pre>
  <p>Now we can add a surface representation, but first let's clear the default.
  For the arguments I had a gander at the example:</p>
  <pre><code>view.clear_representations(component=1)
  view.add_representation('surface', 
                          color='grey', 
                          wireframe=True, 
                          isolevel=1.5,
                          component=1)
  view.center('100-110:A')
  view
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-13T09:13:40.320Z
Answers.LastActivityDate: 2022-02-13T09:13:40.320Z
Answers.UserDisplayName: Matteo Ferla
Body: <p>Hi everyone (mostly who are interested in structural bioinformatics).
  I face the problem that I cannot plot the electron density of a specific part of my protein. For the whole protein it is not a problem:</p>
  <pre><code>from Bio.PDB import *
  import nglview as nv
  import ipywidgets
  
  
  pdbl = PDBList()
  path = pdbl.retrieve_pdb_file('1FAT')
  parser = MMCIFParser()
  struct = parser.get_structure(&quot;1fat&quot;, path)
  view = nv.show_biopython(struct)
  view
  </code></pre>
  <p>But when I tried to pick up residues from 10 till 109 (<code>res_list = Selection.unfold_entities(struct, &quot;R&quot;)[10:109]</code>) and plot I can't do that, because for <code>nglview</code> I need to have a special Object. As I'm a newbie, I'd like to address this question to specialists.</p>
  <p>At the moment I'm trying to visualise model (structure), not electron density. But the next step is trying to find a package to visualize electron density also. I've just started becoming familiar with some open packages.</p>
  <p>Thank You in Advance!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-02-13T15:12:51.417Z
Comments.Text: Hi @KitsuneBreeze its a good question and looks to be resolved. Please remember to "accept" and "upvote"
Comments.UserDisplayName: M__
Tags: <protein-structure><3d-structure><structural-biology>
Title: How to visualize electron density of a specific part of the protein residue?
ThreadText: # How to visualize electron density of a specific part of the protein residue?
  
  (Asked by: username_0 on 2022-02-11)
  
  Hi everyone (mostly who are interested in structural bioinformatics).
  I face the problem that I cannot plot the electron density of a specific part of my protein. For the whole protein it is not a problem:
  
  ```
  from Bio.PDB import *
  import nglview as nv
  import ipywidgets
  
  pdbl = PDBList()
  path = pdbl.retrieve_pdb_file('1FAT')
  parser = MMCIFParser()
  struct = parser.get_structure("1fat", path)
  view = nv.show_biopython(struct)
  view
  
  ```
  
  But when I tried to pick up residues from 10 till 109 (`res_list = Selection.unfold_entities(struct, "R")[10:109]`) and plot I can't do that, because for `nglview` I need to have a special Object. As I'm a newbie, I'd like to address this question to specialists.
  
  At the moment I'm trying to visualise model (structure), not electron density. But the next step is trying to find a package to visualize electron density also. I've just started becoming familiar with some open packages.
  
  Thank You in Advance!
  
  **Tags:** protein-structure, 3d-structure, structural-biology
  
  > **Comments:**
  > **username_1**: Hi @username_0 its a good question and looks to be resolved. Please remember to "accept" and "upvote"  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-02-13. Score: 2
  
  NGLview runs off the JavaScript libray NGL, which is documented as a series of very helpful examples: [in the gallery](http://nglviewer.org/ngl/gallery/). The commands are not one-to-one (slightly frustratingly), but it is helpful as you can figure it out easily with a few `dir` and `help` commands. In this case whatever example of density being loaded it will reveals that it's a different component —this is the same everywhere as density files do not contain atomic coordinates. Unfortunately, there's not a direct way to generate a new `ComponentViewer` from different sources to an `NGLWidget` and you cannot merge two of them: the various `.show_*` functions return an `NGLWidget` but aren't part of it.
  
  First, I am not sure why you are going through a convoluted route for loading a PDB code:
  
  ```
  pdb_code = '1fat'
  
  import nglview as nv
  
  view: nv.NGLWidget = nv.show_pdbid(pdb_code) 
  
  ```
  
  Now, on loading the component a representation is added to it.
  These can hide the representation you then add and things will not make sense, until this detail is recalled! I fall in that pit nearly every time.
  But we can change it with update command:
  
  ```
  # I don't like wonky sheets
  view.update_cartoon(smoothSheets=True, color='salmon', component=0)
  
  ```
  
  Now let's add the density map the circuitous way (no `.show_url`).
  
  ```
  import requests, io
  response: requests.Response = requests.get('https://www.ebi.ac.uk/pdbe/coordinates/files/1fat.ccp4')
  response.raise_for_status()
  fh = io.BytesIO(response.content)
  comp: nv.component.ComponentViewer = view.add_component(fh, ext='ccp4') 
  
  ```
  
  Now we can add a surface representation, but first let's clear the default.
  For the arguments I had a gander at the example:
  
  ```
  view.clear_representations(component=1)
  view.add_representation('surface', 
                          color='grey', 
                          wireframe=True, 
                          isolevel=1.5,
                          component=1)
  view.center('100-110:A')
  view
  
  ```
  
  
  ---
  
  