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':
            data, cell = read_plt(file)

            pbc_c = [True, True, True]
            N_c = np.array(data.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(data * Bohr**3, np.float)
    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':
            data, cell = read_plt(file)

            pbc_c = [True, True, True]
            N_c = np.array(data.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(data * Bohr ** 3, np.float)
Example #3
0
H2.rotate(57, [1, 1, 1])

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()

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 = [aed, cell]
    write_plt(fname, calc.get_atoms(), aed)

    # check if read arrays match the written ones
    data = read_plt(fname)
    for d, do in zip(data, data_org):
        dd2 = (d - do)**2
        norm = dd2.sum()
        print(norm)
        assert(norm < 1e-10)
Example #4
0
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 = [aed, cell]
    write_plt(fname, calc.get_atoms(), aed)
    
    # check if read arrays match the written ones
    data = read_plt(fname)
    for d, do in zip(data, data_org):
        dd2 = (d - do)**2
        norm = dd2.sum() 
        print(norm)
        assert(norm < 1e-10)