Visualization of an MDAnalysis Universe resets its translation
daandtu opened this issue · comments
Luis commented
Setup:
- I load a molecule with MDAnalysis from a PDB file.
- Then I translate the molecule to a new position.
- I visualize the molecule via nglview.show_mdanalysis
Problem:
During the visualization, the translation is reset, i.e. after the creation of the NGLView-Widget the coordinates of the molecule are the same again as in the PDB file.
Example:
import MDAnalysis as mda
from MDAnalysis.transformations.translate import translate
import numpy as np
import nglview as nv
pdb_path = 'temp.pdb'
structure1 = mda.Universe(pdb_path)
print('Before translation:')
for atom in structure1.atoms:
print(atom.position)
translate(np.array([10,10,10]))(structure1.atoms)
print('After translation:')
for atom in structure1.atoms:
print(atom.position)
nv_widget_1 = nv.show_mdanalysis(structure1)
print('After visualization:')
for atom in structure1.atoms:
print(atom.position)
nv_widget_1
The output is:
Before translation:
[1. 0. 0.]
[ 0. 0. -1.]
[1. 0. 1.]
After translation:
[11. 10. 10.]
[10. 10. 9.]
[11. 10. 11.]
After visualization:
[1. 0. 0.]
[ 0. 0. -1.]
[1. 0. 1.]
I used this PDB file:
ATOM 1 N1 1MIMX 1 1.000 0.000 0.000 1.00 0.00 1M
ATOM 2 N2 1MIMX 1 0.000 0.000 -1.000 1.00 0.00 1M
ATOM 3 R3 1MIMX 1 1.000 0.000 1.000 1.00 0.00 1M
ENDMDL
CONECT 1 2 3
CONECT 2 1 3
CONECT 3 1 2
END
Version report
nglview version: 3.0.8
ipywidgets version: 8.1.1
Hai Nguyen commented