def read_3D(self, file, filetype=None): """Read the density from a 3D file""" if filetype is None: # estimate file type from name ending filetype = file.split('.')[-1] filetype.lower() if filetype == 'plt': cell, grid = read_plt(file)[:2] pbc_c = [True, True, True] N_c = np.array(grid.shape) for c in range(3): if N_c[c] % 2 == 1: pbc_c[c] = False N_c[c] += 1 self.gd = GridDescriptor(N_c, cell.diagonal() / Bohr, pbc_c) self.offset_c = [int(not a) for a in self.gd.pbc_c] else: raise NotImplementedError('unknown file type "' + filetype + '"') self.file = file self.ldos = np.array(grid * Bohr**3, np.float)
fname = 'H2.gpw' if (not load) or (not os.path.exists(fname)): calc = GPAW(xc='PBE', nbands=2, spinpol=False, txt=txt) H2.set_calculator(calc) H2.get_potential_energy() if load: calc.write(fname, 'all') else: calc = GPAW(fname, txt=txt) calc.initialize_wave_functions() import gpaw.mpi as mpi fname = 'aed.plt' cell = calc.get_atoms().get_cell() #aed = calc.get_all_electron_density(1, pad=False) aed = calc.get_pseudo_density(1, pad=False) #aed = calc.wfs.gd.collect(aed) if mpi.size == 1: data_org = [cell, aed, np.array([0., 0., 0.])] write_plt(fname, calc.get_atoms(), aed) # check if read arrays match the written ones data = read_plt(fname) ##print data[0], data[2] for d, do in zip(data, data_org): dd2 = (d - do)**2 norm = dd2.sum() print norm assert(norm < 1e-10)