nglviewer / ngl

WebGL protein viewer
http://nglviewer.org/ngl/
MIT License
669 stars 170 forks source link

Import slice images as volume? #691

Open garyo opened 5 years ago

garyo commented 5 years ago

I have a set of registered slice images (density) I'd like to display in ngl as a volume (isosurface). Is that doable or do I need to convert the images to another format first that ngl understands?

arose commented 5 years ago

There is no support for that directly in NGL but you can load them yourself and then create a volume object or directly write a volume parser (see the dx parser as an example https://github.com/arose/ngl/blob/master/src/parser/dx-parser.ts).

NGL support plenty of volume formats (MRC/MAP/CCP4, DX/DXBIN, CUBE, BRIX/DSN6, XPLOR/CNS) so you can also convert your data to one of them

garyo commented 5 years ago

Thanks -- DX looks pretty simple and there's a python/numpy parser/writer for it too. That said, here's a test DX file I created that doesn't import very well in NGL. If you import it into the current web viewer, you'll see a few things:

  1. it isn't view-clipped properly; some parts are clipped off.
  2. To see anything, you have to set the isosurface level to -0.42, which is a bit weird since all the values are positive. (They're the distance to the center of the volume treated as a 10x10x10 ansgstrom cube, i.e. a sphere.)
  3. It's not quite centered in the view; the volume is centered on the origin.

(If you'd like me to resubmit this as a separate ticket, I'd be happy to.)

# OpenDX written by gridData.OpenDX
# from https://github.com/MDAnalysis/GridDataFormats
object 1 class gridpositions counts  5 5 5
origin -5.000000 -5.000000 -5.000000
delta  2.000000 0.000000 0.000000
delta  0.000000 2.000000 0.000000
delta  0.000000 0.000000 2.000000
object 2 class gridconnections counts  5 5 5
object 3 class array type "double" rank 0 items 125 data follows
8.660254037844387       7.500000000000000       7.071067811865476
7.500000000000000       8.660254037844387       7.500000000000000
6.123724356957945       5.590169943749475       6.123724356957945
7.500000000000000       7.071067811865476       5.590169943749475
5.000000000000000       5.590169943749475       7.071067811865476
7.500000000000000       6.123724356957945       5.590169943749475
6.123724356957945       7.500000000000000       8.660254037844387
7.500000000000000       7.071067811865476       7.500000000000000
8.660254037844387       7.500000000000000       6.123724356957945
5.590169943749475       6.123724356957945       7.500000000000000
6.123724356957945       4.330127018922194       3.535533905932738
4.330127018922194       6.123724356957945       5.590169943749475
3.535533905932738       2.500000000000000       3.535533905932738
5.590169943749475       6.123724356957945       4.330127018922194
3.535533905932738       4.330127018922194       6.123724356957945
7.500000000000000       6.123724356957945       5.590169943749475
6.123724356957945       7.500000000000000       7.071067811865476
5.590169943749475       5.000000000000000       5.590169943749475
7.071067811865476       5.590169943749475       3.535533905932738
2.500000000000000       3.535533905932738       5.590169943749475
5.000000000000000       2.500000000000000       0.000000000000000
2.500000000000000       5.000000000000000       5.590169943749475
3.535533905932738       2.500000000000000       3.535533905932738
5.590169943749475       7.071067811865476       5.590169943749475
5.000000000000000       5.590169943749475       7.071067811865476
7.500000000000000       6.123724356957945       5.590169943749475
6.123724356957945       7.500000000000000       6.123724356957945
4.330127018922194       3.535533905932738       4.330127018922194
6.123724356957945       5.590169943749475       3.535533905932738
2.500000000000000       3.535533905932738       5.590169943749475
6.123724356957945       4.330127018922194       3.535533905932738
4.330127018922194       6.123724356957945       7.500000000000000
6.123724356957945       5.590169943749475       6.123724356957945
7.500000000000000       8.660254037844387       7.500000000000000
7.071067811865476       7.500000000000000       8.660254037844387
7.500000000000000       6.123724356957945       5.590169943749475
6.123724356957945       7.500000000000000       7.071067811865476
5.590169943749475       5.000000000000000       5.590169943749475
7.071067811865476       7.500000000000000       6.123724356957945
5.590169943749475       6.123724356957945       7.500000000000000
8.660254037844387       7.500000000000000       7.071067811865476
7.500000000000000       8.660254037844387
attribute "dep" string "positions"
object "density" class field
component "positions" value 1
component "connections" value 2
component "data" value 3