Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pymol can't read OpenDX file produced by GridDataFormats #35

Closed
rxu2 opened this issue Jul 27, 2017 · 4 comments

Comments

@rxu2
Copy link

commented Jul 27, 2017

I made a DX file with the following python program:

import numpy as np
import gridData

nx= ny= nz = 5
density = np.empty((nx,ny,nz), dtype=float)
for i in range(nx):
    for j in range(ny):
        for k in range(nz):
            density[i,j,k] = i**2 + j**2 + k**2
density /= density.max()

g =gridData.Grid(density, origin=(0, 0, 0), delta=(1,1,1))
g.export('test.dx', 'dx')

When I load test.dx into pymol (PyMOL 1.8.4.0 Open-Source on Linux) with the bash command ($ pymol test.dx), I get the following error messages from pymol:

 ObjectMapLoadDXFile: Loading from 'test.dx'.
 DXStrToMap: Dimensions: 30 30 30
 DXStrToMap: Origin    0.000    0.000    0.000
 DXStrToMap: Grid    1.000    1.000    1.000
 DXStrToMap: 27000 data points.
ObjectMap-Error: Error reading map
 CmdLoad: "test.dx" loaded as "test".

Here is the test.dx file:

# OpenDX density file written by gridDataFormats.Grid.export()
# File format: http://opendx.sdsc.edu/docs/html/pages/usrgu068.htm#HDREDF
# Data are embedded in the header and tied to the grid positions.
# Data is written in C array order: In grid[x,y,z] the axis z is fastest
# varying, then y, then finally x, i.e. z is the innermost loop.
# (Note: the VMD dx-reader chokes on comments below this line)
object 1 class gridpositions counts  5 5 5
origin 0.000000 0.000000 0.000000
delta  1.000000 0.000000 0.000000
delta  0.000000 1.000000 0.000000
delta  0.000000 0.000000 1.000000
object 2 class gridconnections counts  5 5 5
object 3 class array type float rank 0 items 125 data follows
0.0	0.0208333333333	0.0833333333333	
0.1875	0.333333333333	0.0208333333333	
0.0416666666667	0.104166666667	0.208333333333	
0.354166666667	0.0833333333333	0.104166666667	
0.166666666667	0.270833333333	0.416666666667	
0.1875	0.208333333333	0.270833333333	
0.375	0.520833333333	0.333333333333	
0.354166666667	0.416666666667	0.520833333333	
0.666666666667	0.0208333333333	0.0416666666667	
0.104166666667	0.208333333333	0.354166666667	
0.0416666666667	0.0625	0.125	
0.229166666667	0.375	0.104166666667	
0.125	0.1875	0.291666666667	
0.4375	0.208333333333	0.229166666667	
0.291666666667	0.395833333333	0.541666666667	
0.354166666667	0.375	0.4375	
0.541666666667	0.6875	0.0833333333333	
0.104166666667	0.166666666667	0.270833333333	
0.416666666667	0.104166666667	0.125	
0.1875	0.291666666667	0.4375	
0.166666666667	0.1875	0.25	
0.354166666667	0.5	0.270833333333	
0.291666666667	0.354166666667	0.458333333333	
0.604166666667	0.416666666667	0.4375	
0.5	0.604166666667	0.75	
0.1875	0.208333333333	0.270833333333	
0.375	0.520833333333	0.208333333333	
0.229166666667	0.291666666667	0.395833333333	
0.541666666667	0.270833333333	0.291666666667	
0.354166666667	0.458333333333	0.604166666667	
0.375	0.395833333333	0.458333333333	
0.5625	0.708333333333	0.520833333333	
0.541666666667	0.604166666667	0.708333333333	
0.854166666667	0.333333333333	0.354166666667	
0.416666666667	0.520833333333	0.666666666667	
0.354166666667	0.375	0.4375	
0.541666666667	0.6875	0.416666666667	
0.4375	0.5	0.604166666667	
0.75	0.520833333333	0.541666666667	
0.604166666667	0.708333333333	0.854166666667	
0.666666666667	0.6875	0.75	
0.854166666667	1.0	
attribute "dep" string "positions"
object "density" class field 
component "positions" value 1
component "connections" value 2
component "data" value 3

@rxu2 rxu2 changed the title Pymol can't read the opendx file written Pymol can't read OpenDX file produced by GridDataFormats Jul 27, 2017
@rxu2

This comment has been minimized.

Copy link
Author

commented Jul 27, 2017

Found a simple solution. Both vmd and pymol can read the file if 'float' is changed to 'double'

Source:
https://translate.google.com/translate?hl=en&sl=ja&u=http://lambdalisue.hatenablog.com/entry/2014/12/06/014255&prev=search

@orbeckst

This comment has been minimized.

Copy link
Member

commented Jul 27, 2017

Thanks, I'll have a look.

@orbeckst

This comment has been minimized.

Copy link
Member

commented Dec 8, 2017

@rxu2 sorry, I completely forgot about this issue.

Through your link above (and the patch) it is clear that this is really a bug in pymol (it hard-codes double when looking for the line with grid data).

As discussed in MDAnalysis/mdanalysis#1725 , float is the default for DX files so in principle pymol should be able to deal with it. However, I propose to add a keyword for GridDataFormats that allows people to write out data with double instead of float and a note to the documention.

orbeckst added a commit to MDAnalysis/mdanalysis that referenced this issue Dec 19, 2017
- requires gridDataFormats >= 0.4.0 (to be released)
- documented that PyMOL requires type="double" (see
  MDAnalysis/GridDataFormats#35 for details)
- added tests for Density.export(..., type=<type>) -- note
  that they really only test gridData.Grid.export()
- fixes #1725
orbeckst added a commit to MDAnalysis/mdanalysis that referenced this issue Dec 19, 2017
- requires gridDataFormats >= 0.4.0 (to be released)
- documented that PyMOL requires type="double" (see
  MDAnalysis/GridDataFormats#35 for details)
- added tests for Density.export(..., type=<type>) -- note
  that they really only test gridData.Grid.export()
- updated CHANGELOG
- fixes #1725
@orbeckst orbeckst added this to the 0.4 milestone Dec 19, 2017
@orbeckst

This comment has been minimized.

Copy link
Member

commented Jan 12, 2018

closed by #36

@orbeckst orbeckst closed this Jan 12, 2018
@orbeckst orbeckst referenced this issue Jan 12, 2018
3 of 3 tasks complete
orbeckst added a commit to MDAnalysis/mdanalysis that referenced this issue Jan 21, 2018
- requires gridDataFormats >= 0.4.0
- documented that PyMOL requires type="double" (see
  MDAnalysis/GridDataFormats#35 for details)
- link to GridDataFormats docs for OpenDX type
- use intersphinx to the mdanalysis.org GridDataFormats docs
  instead of RTD (better brand experience by staying inside mdanalysis.org...)
- added tests for Density.export(..., type=<type>) -- note
  that they really only test gridData.Grid.export()
- updated CHANGELOG
- fixes #1725
orbeckst added a commit to MDAnalysis/mdanalysis that referenced this issue Jan 22, 2018
- requires gridDataFormats >= 0.4.0
- documented that PyMOL requires type="double" (see
  MDAnalysis/GridDataFormats#35 for details)
- link to GridDataFormats docs for OpenDX type
- use intersphinx to the mdanalysis.org GridDataFormats docs
  instead of RTD (better brand experience by staying inside mdanalysis.org...)
- added tests for Density.export(..., type=<type>) -- note
  that they really only test gridData.Grid.export()
- updated CHANGELOG
- fixes #1725
giacomofiorin added a commit to giacomofiorin/GridDataFormats that referenced this issue Nov 12, 2018
This change works around another example of poorly hard-coded DX parser
(see also issue MDAnalysis#35).

See the code below from the GridForcesGrid.C file in NAMD:
```
fscanf(poten_fp, "object %*d class array type double rank 0 "
                 "items %*d data follows\n");
```
which will only work if the quote character (introduced in 115b05a to appease
the PyMol parser) is omitted.
giacomofiorin added a commit to giacomofiorin/GridDataFormats that referenced this issue Nov 12, 2018
This change works around another example of poorly hard-coded DX parser
(see also issue MDAnalysis#35).

See the code below from the GridForcesGrid.C file in NAMD:
fscanf(poten_fp, "object %*d class array type double rank 0 "
                 "items %*d data follows\n");
which will only work if the quote character (introduced in 115b05a to appease
the PyMol parser) is omitted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.