Exemplo n.º 1
0
    def read(self, filename):
        reader = Reader(filename)
        tag = reader.get_tag()
        if tag != self.__class__.ulmtag:
            raise RuntimeError('Unknown tag %s' % tag)
        version = reader.version
        if version != self.__class__.version:
            raise RuntimeError('Unknown version %s' % version)

        wfs = self.wfs
        self.S_uMM = read_uMM(wfs, reader, 'S_uMM')
        wfs.read_wave_functions(reader)
        wfs.read_eigenvalues(reader)
        wfs.read_occupations(reader)

        self.C0_unM = []
        self.eig_un = []
        self.occ_un = []
        for kpt in self.wfs.kpt_u:
            C_nM = kpt.C_nM
            self.C0_unM.append(C_nM)
            self.eig_un.append(kpt.eps_n)
            self.occ_un.append(kpt.f_n)

        for arg in self.readwrite_attrs:
            setattr(self, arg, getattr(reader, arg))

        reader.close()
        self.has_initialized = True
Exemplo n.º 2
0
    def read(self, filename, mode='', idiotproof=True):
        if idiotproof and not filename.endswith('.ind'):
            raise IOError('Filename must end with `.ind`.')

        reads = self._parse_readwritemode(mode)

        # Open reader
        from gpaw.io import Reader
        reader = Reader(filename)
        self._read(reader, reads)
        reader.close()
        self.world.barrier()
Exemplo n.º 3
0
    def read(self, filename):
        from ase.io.trajectory import read_atoms
        self.log('Reading from {}'.format(filename))

        self.reader = reader = Reader(filename)

        atoms = read_atoms(reader.atoms)
        self._set_atoms(atoms)

        res = reader.results
        self.results = dict((key, res.get(key)) for key in res.keys())
        if self.results:
            self.log('Read {}'.format(', '.join(sorted(self.results))))

        self.log('Reading input parameters:')
        # XXX param
        self.parameters = self.get_default_parameters()
        dct = {}
        for key, value in reader.parameters.asdict().items():
            if (isinstance(value, dict)
                    and isinstance(self.parameters[key], dict)):
                self.parameters[key].update(value)
            else:
                self.parameters[key] = value
            dct[key] = self.parameters[key]

        self.log.print_dict(dct)
        self.log()

        self.initialize(reading=True)

        self.density.read(reader)
        self.hamiltonian.read(reader)
        self.occupations.read(reader)
        self.scf.read(reader)
        self.wfs.read(reader)

        # We need to do this in a better way:  XXX
        from gpaw.utilities.partition import AtomPartition
        atom_partition = AtomPartition(self.wfs.gd.comm,
                                       np.zeros(len(self.atoms), dtype=int))
        self.wfs.atom_partition = atom_partition
        self.density.atom_partition = atom_partition
        self.hamiltonian.atom_partition = atom_partition
        rank_a = self.density.gd.get_ranks_from_positions(self.spos_ac)
        new_atom_partition = AtomPartition(self.density.gd.comm, rank_a)
        for obj in [self.density, self.hamiltonian]:
            obj.set_positions_without_ruining_everything(
                self.spos_ac, new_atom_partition)

        self.hamiltonian.xc.read(reader)

        if self.hamiltonian.xc.name == 'GLLBSC':
            # XXX GLLB: See test/lcaotddft/gllbsc.py
            self.occupations.calculate(self.wfs)

        return reader
Exemplo n.º 4
0
 def read(self, filename):
     reader = Reader(filename)
     tag = reader.get_tag()
     if tag != self.__class__.ulmtag:
         raise RuntimeError('Unknown tag %s' % tag)
     version = reader.version
     if version != self.__class__.version:
         raise RuntimeError('Unknown version %s' % version)
     self.time = reader.time
     self.foldedfreqs_f = [
         FoldedFrequencies(**ff) for ff in reader.foldedfreqs_f
     ]
     self.__generate_freq_w()
     self.Nw = np.sum([len(ff.frequencies) for ff in self.foldedfreqs_f])
     wfs = self.wfs
     self.rho0_uMM = read_uMM(wfs, reader, 'rho0_uMM')
     self.rho0_dtype = self.rho0_uMM[0].dtype
     wlist = range(self.Nw)
     self.FReDrho_wuMM = read_wuMM(wfs, reader, 'FReDrho_wuMM', wlist)
     self.FImDrho_wuMM = read_wuMM(wfs, reader, 'FImDrho_wuMM', wlist)
     reader.close()
     self.has_initialized = True
Exemplo n.º 5
0
    def read(self, filename, idiotproof=True):
        if idiotproof and not filename.endswith('.ftd'):
            raise IOError('Filename must end with `.ftd`.')

        tar = Reader(filename)

        # Test data type
        dtype = {'Float': float, 'Complex': complex}[tar['DataType']]
        if dtype != self.dtype:
            raise IOError('Data is an incompatible type.')

        # Test time
        time = tar['Time']
        if idiotproof and abs(time - self.time) >= 1e-9:
            raise IOError('Timestamp is incompatible with calculator.')

        # Test timestep (non-critical)
        timestep = tar['TimeStep']
        if abs(timestep - self.timestep) > 1e-12:
            print('Warning: Time-step has been altered. (%lf -> %lf)' \
                % (self.timestep, timestep))
        self.timestep = timestep

        # Test dimensions
        nw = tar.dimension('nw')
        nspins = tar.dimension('nspins')
        ng = (tar.dimension('ngptsx'), tar.dimension('ngptsy'), \
              tar.dimension('ngptsz'),)

        if (nw != self.nw or nspins != self.nspins
                or (ng != self.gd.get_size_of_global_array()).any()):
            raise IOError('Data has incompatible shapes.')

        # Test width (non-critical)
        sigma = tar['Width']
        if ((sigma is None)!=(self.sigma is None) or # float <-> None
            (sigma is not None and self.sigma is not None and \
             abs(sigma - self.sigma) > 1e-12)): # float -> float
            print('Warning: Width has been altered. (%s -> %s)' \
                % (self.sigma, sigma))
        self.sigma = sigma

        # Read frequencies
        self.omega_w[:] = tar.get('Frequency')

        # Read cumulative phase factors
        self.gamma_w[:] = tar.get('PhaseFactor')

        # Read average densities on master and distribute
        for s in range(self.nspins):
            all_Ant_G = tar.get('Average', s)
            self.gd.distribute(all_Ant_G, self.Ant_sG[s])

        # Read fourier transforms on master and distribute
        for w in range(self.nw):
            for s in range(self.nspins):
                all_Fnt_G = tar.get('FourierTransform', w, s)
                self.gd.distribute(all_Fnt_G, self.Fnt_wsG[w, s])

        # Close for good measure
        tar.close()