Package Volume :: Package IO :: Module gamessOrbitalsReader
[hide private]
[frames] | no frames]

Source Code for Module Volume.IO.gamessOrbitalsReader

 1  import Numeric 
 2  from string import split 
 3   
4 -class ReadGamessOrbitals:
5 """Read a rawiv binary file""" 6
7 - def mapArray(self, values, mini, maxi):
8 9 # allocate numeric array that is **2 10 dim = int(round(len(values)**(1./3))) 11 print dim, dim**3, len(values) 12 if dim**3!=len(values): 13 raise ValueError, "Length of array is not **3" 14 dim2 = 2 15 while dim2<dim: 16 dim2 = dim2*2 17 print 'dim: padding from:', dim, 'to:', dim2 18 intval = Numeric.zeros( (dim2,dim2,dim2), Numeric.UnsignedInt8 ) 19 20 valuesN = Numeric.array(values) 21 22 minim = min(values) 23 maxim = max(values) 24 scale = (maxi - mini)/float(maxim - minim) 25 valuesN.shape = (dim, dim, dim) 26 27 for i in range(dim): 28 face = valuesN[i] 29 for j in range(dim): 30 line = face[j] 31 for k in range(dim): 32 intval[i][j][k] = ((line[k]-minim)*scale) + mini 33 return intval, minim, maxim
34 35
36 - def read(self, filename):
37 38 myfile = open(filename) 39 data = myfile.readlines() 40 myfile.close() 41 self.header = {} 42 43 dataspl = map( split, data ) 44 values = [] 45 for l in dataspl: 46 values.extend( map(float, l) ) 47 48 # Fixme this should be done in separate nodes 49 self.data, mini, maxi = self.mapArray(values, 1, 255) 50 w, h, d = self.data.shape 51 self.header['width'] = w 52 self.header['height'] = h 53 self.header['depth'] = d 54 self.header['minif'] = mini 55 self.header['maxif'] = maxi 56 57 return self.header, self.data
58