Esempio n. 1
0
    def __init__(self,
                 calculator=None,
                 nspins=None,
                 eps=0.001,
                 istart=0,
                 jend=None,
                 energy_range=None,
                 xc=None,
                 derivative_level=1,
                 numscale=0.00001,
                 txt=None,
                 filename=None,
                 finegrid=2,
                 force_ApmB=False, # for tests
                 eh_comm=None # parallelization over eh-pairs
                 ):

        self.nspins = None
        self.istart = None
        self.jend = None

        if isinstance(calculator, str):
            ExcitationList.__init__(self, None, txt)
            return self.read(calculator)
        else:
            ExcitationList.__init__(self, calculator, txt)

        if filename is not None:
            return self.read(filename)

        self.filename = None
        self.calculator = None
        self.eps = None
        self.xc = None
        self.derivative_level = None
        self.numscale = numscale
        self.finegrid = finegrid
        self.force_ApmB = force_ApmB

        if eh_comm is None:
            eh_comm = mpi.serial_comm
        elif isinstance(eh_comm, (mpi.world.__class__,
                                mpi.serial_comm.__class__)):
            # Correct type already.
            pass
        else:
            # world should be a list of ranks:
            eh_comm = mpi.world.new_communicator(np.asarray(eh_comm))

        self.eh_comm = eh_comm
 
        if calculator is not None:
            calculator.converge_wave_functions()
            if calculator.density.nct_G is None:
                calculator.set_positions()
                
            self.update(calculator, nspins, eps, 
                        istart, jend, energy_range,
                        xc, derivative_level, numscale)
Esempio n. 2
0
    def __init__(
            self,
            calculator=None,
            nspins=None,
            eps=0.001,
            istart=0,
            jend=None,
            energy_range=None,
            xc=None,
            derivative_level=1,
            numscale=0.00001,
            txt=None,
            filename=None,
            finegrid=2,
            force_ApmB=False,  # for tests
            eh_comm=None  # parallelization over eh-pairs
    ):

        self.nspins = None
        self.istart = None
        self.jend = None

        if isinstance(calculator, str):
            ExcitationList.__init__(self, None, txt)
            return self.read(calculator)
        else:
            ExcitationList.__init__(self, calculator, txt)

        if filename is not None:
            return self.read(filename)

        self.filename = None
        self.calculator = None
        self.eps = None
        self.xc = None
        self.derivative_level = None
        self.numscale = numscale
        self.finegrid = finegrid
        self.force_ApmB = force_ApmB

        if eh_comm is None:
            eh_comm = mpi.serial_comm
        elif isinstance(eh_comm,
                        (mpi.world.__class__, mpi.serial_comm.__class__)):
            # Correct type already.
            pass
        else:
            # world should be a list of ranks:
            eh_comm = mpi.world.new_communicator(np.asarray(eh_comm))

        self.eh_comm = eh_comm

        if calculator is not None:
            calculator.converge_wave_functions()
            if calculator.density.nct_G is None:
                calculator.set_positions()

            self.update(calculator, nspins, eps, istart, jend, energy_range,
                        xc, derivative_level, numscale)
Esempio n. 3
0
    def __init__(self,
                 calculator=None,
                 nspins=None,
                 eps=0.001,
                 istart=0,
                 jend=sys.maxsize,
                 energy_range=None,
                 filehandle=None,
                 txt=None):

        self.eps = None
        self.world = mpi.world

        self.calculator = None
        if isinstance(calculator, basestring):
            self.read(calculator)
            return self.select(eps=eps, istart=istart, jend=jend,
                               energy_range=energy_range)
        if filehandle is not None:
            self.read(fh=filehandle)
            return self.select(eps, istart=istart, jend=jend,
                               energy_range=energy_range)

        # LCAO calculation requires special actions
        if calculator is not None:
            self.lcao = calculator.parameters.mode == 'lcao'

        ExcitationList.__init__(self, calculator, txt=txt)

        if calculator is None:
            return  # leave the list empty

        # deny hybrids as their empty states are wrong
#        gsxc = calculator.hamiltonian.xc
#        hybrid = hasattr(gsxc, 'hybrid') and gsxc.hybrid > 0.0
#        assert(not hybrid)

        # ensure correctly initialized wave functions
        calculator.converge_wave_functions()
        self.world = calculator.wfs.world

        # parallelization over bands not yet supported
        assert(calculator.wfs.bd.comm.size == 1)

        self.select(nspins, eps, istart, jend, energy_range)

        trkm = self.get_trk()
        print(file=self.txt)
        print('KSS %d transitions' % len(self), file=self.txt)
        print('KSS TRK sum %g (%g,%g,%g)' %
              (np.sum(trkm) / 3., trkm[0], trkm[1], trkm[2]), file=self.txt)
        pol = self.get_polarizabilities(lmax=3)
        print('KSS polarisabilities(l=0-3) %g, %g, %g, %g' %
              tuple(pol.tolist()), file=self.txt)
Esempio n. 4
0
    def __init__(self, calculator=None, **kwargs):

        self.timer = Timer()
        self.diagonalized = False

        changed = self.set(**kwargs)

        if isinstance(calculator, basestring):
            ExcitationList.__init__(self, None, self.txt)
            self.filename = calculator
        else:
            ExcitationList.__init__(self, calculator, self.txt)

        if self.filename is not None:
            self.read(self.filename)
            if set(['istart', 'jend', 'energy_range']) & set(changed):
                # the user has explicitely demanded these
                self.diagonalize()
            return

        if self.eh_comm is None:
            self.eh_comm = mpi.serial_comm
        elif isinstance(self.eh_comm,
                        (mpi.world.__class__, mpi.serial_comm.__class__)):
            # Correct type already.
            pass
        else:
            # world should be a list of ranks:
            self.eh_comm = mpi.world.new_communicator(np.asarray(self.eh_comm))

        if calculator is not None and calculator.initialized:
            # XXXX not ready for k-points
            assert (len(calculator.wfs.kd.ibzk_kc) == 1)
            if not isinstance(calculator.wfs, FDWaveFunctions):
                raise RuntimeError(
                    'Linear response TDDFT supported only in real space mode')
            if calculator.wfs.kd.comm.size > 1:
                err_txt = 'Spin parallelization with Linear response '
                err_txt += "TDDFT. Use parallel={'domain': world.size} "
                err_txt += 'calculator parameter.'
                raise NotImplementedError(err_txt)
            if self.xc == 'GS':
                self.xc = calculator.hamiltonian.xc
            if calculator.parameters.mode != 'lcao':
                calculator.converge_wave_functions()
            if calculator.density.nct_G is None:
                spos_ac = calculator.initialize_positions()
                calculator.wfs.initialize(calculator.density,
                                          calculator.hamiltonian, spos_ac)

            self.update(calculator)
Esempio n. 5
0
    def __init__(self,
                 calculator=None,
                 nonselfconsistent_xc=None,
                 nspins=None,
                 eps=0.001,
                 istart=0,
                 jend=None,
                 energy_range=None,
                 filehandle=None,
                 txt=None):

        if filehandle is not None:
            self.read(fh=filehandle)
            return None

        ExcitationList.__init__(self, calculator, txt=txt)
        
        if calculator is None:
            return # leave the list empty

        # deny hybrids as their empty states are wrong
        gsxc = calculator.hamiltonian.xc
        hybrid = hasattr(gsxc, 'hybrid') and gsxc.hybrid > 0.0
#        assert(not hybrid)

        if nonselfconsistent_xc is None:
            self.de_skn = None
        else:
            pass
#            self.de_skn = (vxc(calculator, nonselfconsistent_xc.name) - 
#                           vxc(calculator, calculator.hamiltonian.xc))

        error = calculator.wfs.eigensolver.error
        criterion = (calculator.input_parameters['convergence']['eigenstates']
                     * calculator.wfs.nvalence)
        if error > criterion:
            raise RuntimeError('The wfs error is larger than ' +
                               'the convergence criterion (' +
                               str(error) + ' > ' + str(criterion) + ')')

        self.select(nspins, eps, istart, jend, energy_range)

        trkm = self.get_trk()
        print >> self.txt, 'KSS TRK sum %g (%g,%g,%g)' % \
              (np.sum(trkm)/3., trkm[0], trkm[1], trkm[2])
        pol = self.get_polarizabilities(lmax=3)
        print >> self.txt, \
              'KSS polarisabilities(l=0-3) %g, %g, %g, %g' % \
              tuple(pol.tolist())
    def __init__(self,
                 calculator=None,
                 nspins=None,
                 eps=0.001,
                 istart=0,
                 jend=sys.maxsize,
                 energy_range=None,
                 filehandle=None,
                 txt=None):

        self.eps = None

        if isinstance(calculator, str):
            filehandle = open(calculator)
        if filehandle is not None:
            self.world = mpi.world
            self.read(fh=filehandle, istart=istart, jend=jend)
            return None

        # LCAO calculation requires special actions
        if calculator is not None:
            self.lcao = calculator.input_parameters.mode == 'lcao'

        ExcitationList.__init__(self, calculator, txt=txt)

        if calculator is None:
            return  # leave the list empty

        # deny hybrids as their empty states are wrong
#        gsxc = calculator.hamiltonian.xc
#        hybrid = hasattr(gsxc, 'hybrid') and gsxc.hybrid > 0.0
#        assert(not hybrid)

        # ensure correctly initialized wave functions
        calculator.converge_wave_functions()
        self.world = calculator.wfs.world

        # parallelization over bands not yet supported
        assert(calculator.wfs.band_comm.size == 1)

        self.select(nspins, eps, istart, jend, energy_range)

        trkm = self.get_trk()
        print('KSS TRK sum %g (%g,%g,%g)' %
              (np.sum(trkm) / 3., trkm[0], trkm[1], trkm[2]), file=self.txt)
        pol = self.get_polarizabilities(lmax=3)
        print('KSS polarisabilities(l=0-3) %g, %g, %g, %g' %
              tuple(pol.tolist()), file=self.txt)
Esempio n. 7
0
    def __init__(self, calculator=None, **kwargs):

        self.timer = Timer()

        self.set(**kwargs)

        if isinstance(calculator, str):
            ExcitationList.__init__(self, None, self.txt)
            self.filename = calculator
        else:
            ExcitationList.__init__(self, calculator, self.txt)

        if self.filename is not None:
            return self.read(self.filename)

        if self.eh_comm is None:
            self.eh_comm = mpi.serial_comm
        elif isinstance(self.eh_comm, (mpi.world.__class__,
                                       mpi.serial_comm.__class__)):
            # Correct type already.
            pass
        else:
            # world should be a list of ranks:
            self.eh_comm = mpi.world.new_communicator(np.asarray(eh_comm))

        if calculator is not None and calculator.initialized:
            if not isinstance(calculator.wfs, FDWaveFunctions):
                raise RuntimeError(
                    'Linear response TDDFT supported only in real space mode')
            if calculator.wfs.kd.comm.size > 1:
                err_txt = 'Spin parallelization with Linear response '
                err_txt += "TDDFT. Use parallel = {'domain' : 'domain_only'} "
                err_txt += 'calculator parameter.'
                raise NotImplementedError(err_txt)
            if self.xc == 'GS':
                self.xc = calculator.hamiltonian.xc.name
            if calculator.input_parameters.mode != 'lcao':
                calculator.converge_wave_functions()
            if calculator.density.nct_G is None:
                spos_ac = calculator.initialize_positions()
                calculator.wfs.initialize(calculator.density,
                                          calculator.hamiltonian, spos_ac)

            self.update(calculator)
Esempio n. 8
0
    def __init__(self,
                 calculator=None,
                 nspins=None,
                 eps=0.001,
                 istart=0,
                 jend=None,
                 energy_range=None,
                 filehandle=None,
                 txt=None):

        if filehandle is not None:
            self.read(fh=filehandle)
            return None

        ExcitationList.__init__(self, calculator, txt=txt)

        if calculator is None:
            return  # leave the list empty

        error = calculator.wfs.eigensolver.error
        criterion = (
            calculator.input_parameters['convergence']['eigenstates'] *
            calculator.wfs.nvalence)
        if error > criterion:
            raise RuntimeError('The wfs error is larger than ' +
                               'the convergence criterion (' + str(error) +
                               ' > ' + str(criterion) + ')')

        self.select(nspins, eps, istart, jend, energy_range)

        trkm = self.get_trk()
        print >> self.txt, 'KSS TRK sum %g (%g,%g,%g)' % \
              (np.sum(trkm)/3., trkm[0], trkm[1], trkm[2])
        pol = self.get_polarizabilities(lmax=3)
        print >> self.txt, \
              'KSS polarisabilities(l=0-3) %g, %g, %g, %g' % \
              tuple(pol.tolist())
Esempio n. 9
0
 def __str__(self):
     string = ExcitationList.__str__(self)
     string += '# derived from:\n'
     string += self.kss.__str__()
     return string
Esempio n. 10
0
 def __str__(self):
     string = ExcitationList.__str__(self)
     string += '# derived from:\n'
     string += self.kss.__str__()
     return string