from scipy import * from pyvtk import * from pyvtk.DataSetAttr import * class Cubefile: def __init__(self,filename): """Represents a Gaussian03 cubefile object. Attributes: data -- a scipy array containing the data numAtoms -- the number of atoms origin -- the origin numPoints -- a list of the number of points in x,y,z spacing -- a list of the spacing in x,y,z """ self.readCubeFile(filename) def readCubeFile(self,filename): """Read in a cube file.""" inputfile = open(filename,"r") header = "".join([inputfile.readline(),inputfile.readline()]) temp = inputfile.readline().strip().split() self.numAtoms = int(temp[0]) self.origin = map(float,temp[1:]) self.numPoints = [0]*3 self.spacing = [0]*3 for i in range(3): line = inputfile.readline().strip().split() self.numPoints[i] = int(line[0]) temp = map(float,line[1:]) self.spacing[i] = temp[i] assert sum(temp[:i]+temp[i+1:])==0 # Read in the lines with atom data for i in range(self.numAtoms): line = inputfile.readline() self.data = zeros( (self.numPoints[1],self.numPoints[0],self.numPoints[2]),"float" ) i = j = k =0 while i