@@ -523,6 +523,33 @@ def __init__(self,classid='0',components=None,comments=None):
523523 self .components = components
524524 self .comments = comments
525525
526+ @staticmethod
527+ def from_grid (grid , type = None , typequote = '"' , ** kwargs ):
528+ comments = [
529+ "OpenDX density file written by gridDataFormats.Grid.export()" ,
530+ "File format: http://opendx.sdsc.edu/docs/html/pages/usrgu068.htm#HDREDF" ,
531+ "Data are embedded in the header and tied to the grid positions." ,
532+ "Data is written in C array order: In grid[x,y,z] the axis z is fastest" ,
533+ "varying, then y, then finally x, i.e. z is the innermost loop." ,
534+ ]
535+ if grid .metadata :
536+ comments .append ("Meta data stored with the python Grid object:" )
537+ for k in grid .metadata :
538+ comments .append (" " + str (k ) + " = " + str (grid .metadata [k ]))
539+ comments .append ("(Note: the VMD dx-reader chokes on comments below this line)" )
540+
541+ components = dict (
542+ positions = gridpositions (1 , grid .grid .shape , grid .origin , grid .delta ),
543+ connections = gridconnections (2 , grid .grid .shape ),
544+ data = array (3 , grid .grid , type = type , typequote = typequote ),
545+ )
546+ dx_field = field ('density' , components = components , comments = comments )
547+ return dx_field
548+
549+ @property
550+ def native (self ):
551+ return self
552+
526553 def _openfile_writing (self , filename ):
527554 """Returns a regular or gz file stream for writing"""
528555 if filename .endswith ('.gz' ):
0 commit comments