Ejemplo n.º 1
0
 def writeMKL(self, fn, rep=[1, 1, 1]):
     "Write .mkl file with unitcell repeated rep times"
     geom = copy.deepcopy(self)
     for i in range(3):
         geom.repeteGeom(self.pbc[i], rep=rep[i])
         geom.pbc[i] = [rep[i] * x for x in self.pbc[i]]
     SIO.WriteMKLFile(fn, geom.anr, geom.xyz, [], [], 0, 0)
Ejemplo n.º 2
0
    def WriteOutput(self, label, SinglePrec, GammaPoint):
        print('\nPhonons.WriteOutput')
        ### Write MKL- and xyz-files
        natoms = self.geom.natoms
        hw = self.hw
        # Write only real part of eigenvectors
        UU = self.UU.reshape(len(hw), 3 * natoms).real
        UUdisp = self.UUdisp.reshape(len(hw), 3 * natoms).real
        UUcl = self.UUcl.reshape(len(hw), 3 * natoms).real

        SIO.WriteMKLFile('%s.mkl' % label, self.geom.anr, self.geom.xyz, hw,
                         UU, 1, natoms)
        SIO.WriteMKLFile('%s.real-displ.mkl' % label, self.geom.anr,
                         self.geom.xyz, hw, UUdisp, 1, natoms)
        SIO.WriteXYZFile('%s.xyz' % label, self.geom.anr, self.geom.xyz)
        WriteFreqFile('%s.freq' % label, hw)
        WriteVibDOSFile('%s.Gfdos' % label, hw, type='Gaussian')
        WriteVibDOSFile('%s.Lfdos' % label, hw, type='Lorentzian')
        WriteAXSFFiles('%s.mol.axsf' % label, self.geom.xyz, self.geom.anr, hw,
                       UU, 1, natoms)
        WriteAXSFFiles('%s.mol.real-displ.axsf' % label, self.geom.xyz,
                       self.geom.anr, hw, UUdisp, 1, natoms)
        WriteAXSFFiles('%s.mol.charlength-displ.axsf' % label, self.geom.xyz,
                       self.geom.anr, hw, UUcl, 1, natoms)
        WriteAXSFFilesPer('%s.per.axsf' % label, self.geom.pbc, self.geom.xyz,
                          self.geom.anr, hw, UU, 1, natoms)
        WriteAXSFFilesPer('%s.per.real-displ.axsf' % label, self.geom.pbc,
                          self.geom.xyz, self.geom.anr, hw, UUdisp, 1, natoms)
        WriteAXSFFilesPer('%s.per.charlength-displ.axsf' % label,
                          self.geom.pbc, self.geom.xyz, self.geom.anr, hw,
                          UUcl, 1, natoms)
        # Netcdf format
        ncdffn = '%s.nc' % label
        print('Phonons.WriteOutput: Writing ' + ncdffn)
        ncdf = NC4.Dataset(ncdffn, 'w')
        ncdf.createDimension('one', 1)
        ncdf.createDimension('xyz', 3)
        ncdf.createDimension('modes', len(hw))
        ncdf.createDimension('natoms', self.geom.natoms)
        ncdf.createDimension('dyn_atoms', len(self.DynamicAtoms))
        ncdf.createVariable('hw', 'd', ('modes', ))
        ncdf.variables['hw'][:] = hw
        ncdf.variables['hw'].info = 'Phonon frequencies'
        ncdf.variables['hw'].unit = 'eV'
        ncdf.createVariable('U', 'd', ('modes', 'natoms', 'xyz'))
        ncdf.variables['U'][:] = self.UU.real
        ncdf.variables['U'].info = 'Real part of the phonon eigenvectors'
        ncdf.createVariable('Udisp', 'd', ('modes', 'natoms', 'xyz'))
        ncdf.variables['Udisp'][:] = self.UUdisp.real
        ncdf.variables[
            'Udisp'].info = 'Real part of the phonon displacement vectors'
        ncdf.createVariable('Ucl', 'd', ('modes', 'natoms', 'xyz'))
        ncdf.variables['Ucl'][:] = self.UUcl.real
        ncdf.variables[
            'Ucl'].info = 'Real part of displacement vectors scaled for the characteristic length'
        ncdf.createVariable('CellVectors', 'd', ('xyz', 'xyz'))
        ncdf.variables['CellVectors'][:] = self.geom.pbc
        ncdf.variables['CellVectors'].info = 'Unit cell vectors'
        ncdf.variables['CellVectors'].unit = 'Ang'
        ncdf.createVariable('GeometryXYZ', 'd', ('natoms', 'xyz'))
        ncdf.variables['GeometryXYZ'][:] = self.geom.xyz
        ncdf.variables[
            'GeometryXYZ'].info = 'Atomic coordinates of all atoms in cell'
        ncdf.variables['GeometryXYZ'].unit = 'Ang'
        ncdf.createVariable('FC', 'd', ('dyn_atoms', 'xyz', 'natoms', 'xyz'))
        ncdf.variables['FC'][:] = self.mean
        ncdf.variables['FC'].info = 'Force matrix'
        ncdf.variables['FC'].unit = 'eV/Ang^2'
        ncdf.createVariable('AtomNumbers', 'i', ('natoms', ))
        ncdf.variables['AtomNumbers'][:] = self.geom.anr
        ncdf.variables[
            'AtomNumbers'].info = 'Element number for each atom (anr)'
        ncdf.createVariable('SpeciesNumbers', 'i', ('natoms', ))
        ncdf.variables['SpeciesNumbers'][:] = self.geom.snr
        ncdf.variables['SpeciesNumbers'].info = 'Siesta species number (snr)'
        ncdf.createVariable('Masses', 'd', ('dyn_atoms', ))
        ncdf.variables['Masses'][:] = self.Masses
        ncdf.variables['Masses'].info = 'Atomic masses of each dynamic atom'
        ncdf.variables['Masses'].unit = 'Atomic units'
        ncdf.createVariable('DynamicAtoms', 'i', ('dyn_atoms', ))
        ncdf.variables['DynamicAtoms'][:] = self.DynamicAtoms
        ncdf.variables[
            'DynamicAtoms'].info = 'Dynamic atoms (SIESTA numbering)'
        try:
            self.h0
            ncdf.createDimension('dev_atoms', len(self.DeviceAtoms))
            ncdf.createDimension('nspin', len(self.h0))
            ncdf.createDimension('norb', len(self.h0[0]))
            ncdf.createVariable('DeviceAtoms', 'i', ('dev_atoms', ))
            ncdf.variables['DeviceAtoms'][:] = self.DeviceAtoms
            ncdf.variables[
                'DeviceAtoms'].info = 'Device atoms (SIESTA numbering)'
            ncdf.createVariable('kpoint', 'd', ('xyz', ))
            ncdf.variables['kpoint'][:] = self.kpoint
            ncdf.variables[
                'kpoint'].info = 'Vector in orthogonal space (not in reciprocal space)'
            ncdf.createVariable('H0', 'd', ('nspin', 'norb', 'norb'))
            ncdf.variables['H0'][:] = self.h0.real
            ncdf.variables['H0'].info = 'Real part of electronic Hamiltonian'
            ncdf.variables['H0'].unit = 'eV'
            ncdf.createVariable('S0', 'd', ('nspin', 'norb', 'norb'))
            ncdf.variables['S0'][:] = self.s0.real
            ncdf.variables['S0'].info = 'Electronic overlap matrix'
            if not GammaPoint:
                ncdf.createVariable('H0.imag', 'd', ('nspin', 'norb', 'norb'))
                ncdf.variables['H0.imag'][:] = self.h0.imag
                ncdf.variables[
                    'H0.imag'].info = 'Imaginary part of Hamiltonian'
                ncdf.createVariable('S0.imag', 'd', ('nspin', 'norb', 'norb'))
                ncdf.variables['S0.imag'][:] = self.s0.imag
                ncdf.variables['S0.imag'].info = 'Imaginary part of overlap'
            print('Phonons.WriteOutput: Wrote H and S to ' + ncdffn)
        except:
            print('Hamiltonian etc not computed')
        # Precision for He_ph (and gradients)
        if SinglePrec:
            atype = 'f'
        else:
            atype = 'd'
        try:
            self.heph
            ncdf.createVariable('He_ph', atype,
                                ('modes', 'nspin', 'norb', 'norb'))
            ncdf.variables['He_ph'][:] = self.heph.real
            ncdf.variables['He_ph'].info = 'Real part of EPH couplings'
            ncdf.variables['He_ph'].unit = 'eV'
            if not GammaPoint:
                ncdf.createVariable('ImHe_ph', atype,
                                    ('modes', 'nspin', 'norb', 'norb'))
                ncdf.variables['ImHe_ph'][:] = self.heph.imag
                ncdf.variables[
                    'ImHe_ph'].info = 'Imaginary part of EPH couplings'
            print('Phonons.WriteOutput: Wrote He_ph to ' + ncdffn)
        except:
            print('EPH couplings etc not computed')
        try:
            self.gradients
            ncdf.createVariable('grad.re', atype,
                                ('modes', 'nspin', 'norb', 'norb'))
            ncdf.variables['grad.re'][:] = self.gradients.real
            ncdf.variables['grad.re'].info = 'Real part of gradients'
            ncdf.variables['grad.re'].unit = 'eV/Ang'
            if not GammaPoint:
                ncdf.createVariable('grad.im', atype,
                                    ('modes', 'nspin', 'norb', 'norb'))
                ncdf.variables['grad.im'][:] = self.gradients.imag
                ncdf.variables['grad.im'].info = 'Imaginary part of gradients'
            print('Phonons.WriteOutput: Wrote gradients to ' + ncdffn)
        except:
            print('Phonons.WriteOutpot: Gradients not computed')
        ncdf.close()
        print('Phonons.WriteOutput: Finished ' + ncdffn)