Пример #1
0
    def build(self,
              dump_input=True,
              parse_arg=True,
              a=None,
              gs=None,
              ke_cutoff=None,
              precision=None,
              nimgs=None,
              ew_eta=None,
              ew_cut=None,
              pseudo=None,
              basis=None,
              h=None,
              dimension=None,
              rcut=None,
              ecp=None,
              *args,
              **kwargs):
        '''Setup Mole molecule and Cell and initialize some control parameters.
        Whenever you change the value of the attributes of :class:`Cell`,
        you need call this function to refresh the internal data of Cell.

        Kwargs:
            a : (3,3) ndarray
                The real-space unit cell lattice vectors. Each row represents
                a lattice vector.
            gs : (3,) ndarray of ints
                The number of *positive* G-vectors along each direction.
            pseudo : dict or str
                To define pseudopotential.  If given, overwrite :attr:`Cell.pseudo`
        '''
        if h is not None: self.h = h
        if a is not None: self.a = a
        if gs is not None: self.gs = gs
        if nimgs is not None: self.nimgs = nimgs
        if ew_eta is not None: self.ew_eta = ew_eta
        if ew_cut is not None: self.ew_cut = ew_cut
        if pseudo is not None: self.pseudo = pseudo
        if basis is not None: self.basis = basis
        if dimension is not None: self.dimension = dimension
        if precision is not None: self.precision = precision
        if rcut is not None: self.rcut = rcut
        if ecp is not None: self.ecp = ecp

        assert (self.a is not None)
        assert (self.gs is not None or self.ke_cutoff is not None)

        if 'unit' in kwargs:
            self.unit = kwargs['unit']

        if 'atom' in kwargs:
            self.atom = kwargs['atom']

        # Set-up pseudopotential if it exists
        # This must happen before build() because it affects
        # tot_electrons() via atom_charge()

        self.ecp, self.pseudo = classify_ecp_pseudo(self, self.ecp,
                                                    self.pseudo)
        if self.pseudo is not None:
            if isinstance(self.pseudo, str):
                # specify global pseudo for whole molecule
                _atom = self.format_atom(self.atom, unit=self.unit)
                uniq_atoms = set([a[0] for a in _atom])
                self._pseudo = self.format_pseudo(
                    dict([(a, self.pseudo) for a in uniq_atoms]))
            else:
                self._pseudo = self.format_pseudo(self.pseudo)

        # Do regular Mole.build with usual kwargs
        _built = self._built
        mole.Mole.build(self, False, parse_arg, *args, **kwargs)

        if self.rcut is None:
            self.rcut = max(
                [self.bas_rcut(ib, self.precision) for ib in range(self.nbas)])

        _a = self.lattice_vectors()
        if np.linalg.det(_a) < 0 and self.dimension == 3:
            sys.stderr.write('''WARNING!
  Lattice are not in right-handed coordinate system. This can cause wrong value for some integrals.
  It's recommended to resort the lattice vectors to\na = %s\n\n''' %
                             _a[[0, 2, 1]])
        if self.gs is None:
            assert (self.ke_cutoff is not None)
            self.gs = pbctools.cutoff_to_gs(_a, self.ke_cutoff)

        if self.ew_eta is None or self.ew_cut is None:
            self.ew_eta, self.ew_cut = self.get_ewald_params(
                self.precision, self.gs)

        if dump_input and not _built and self.verbose > logger.NOTE:
            self.dump_input()
            logger.info(self, 'lattice vectors  a1 [%.9f, %.9f, %.9f]', *_a[0])
            logger.info(self, '                 a2 [%.9f, %.9f, %.9f]', *_a[1])
            logger.info(self, '                 a3 [%.9f, %.9f, %.9f]', *_a[2])
            logger.info(self, 'dimension = %s', self.dimension)
            logger.info(self, 'Cell volume = %g', self.vol)
            logger.info(self, 'rcut = %s (nimgs = %s)', self.rcut, self.nimgs)
            logger.info(self, 'lattice sum = %d cells',
                        len(self.get_lattice_Ls()))
            logger.info(self, 'precision = %g', self.precision)
            logger.info(self, 'gs (FFT-mesh) = %s', self.gs)
            logger.info(self, 'pseudo = %s', self.pseudo)
            logger.info(self, 'ke_cutoff = %s', self.ke_cutoff)
            logger.info(self, 'ew_eta = %g', self.ew_eta)
            logger.info(self, 'ew_cut = %s (nimgs = %s)', self.ew_cut,
                        self.get_bounding_sphere(self.ew_cut))
        return self
Пример #2
0
    def build(self, dump_input=True, parse_arg=True,
              h=None, gs=None, ke_cutoff=None, precision=None, nimgs=None,
              ew_eta=None, ew_cut=None, pseudo=None, basis=None,
              dimension=None,
              *args, **kwargs):
        '''Setup Mole molecule and Cell and initialize some control parameters.
        Whenever you change the value of the attributes of :class:`Cell`,
        you need call this function to refresh the internal data of Cell.

        Kwargs:
            h : (3,3) ndarray
                The real-space unit cell lattice vectors, a "three-column" array [a1|a2|a3]
            gs : (3,) ndarray of ints
                The number of *positive* G-vectors along each direction.
            pseudo : dict or str
                To define pseudopotential.  If given, overwrite :attr:`Cell.pseudo`
        '''
        if h is not None: self.h = h
        if gs is not None: self.gs = gs
        if nimgs is not None: self.nimgs = nimgs
        if ew_eta is not None: self.ew_eta = ew_eta
        if ew_cut is not None: self.ew_cut = ew_cut
        if pseudo is not None: self.pseudo = pseudo
        if basis is not None: self.basis = basis
        if dimension is not None: self.dimension = dimension

        assert(self.h is not None)
        assert(self.gs is not None or self.ke_cutoff is not None)

        if 'unit' in kwargs:
            self.unit = kwargs['unit']

        if 'atom' in kwargs:
            self.atom = kwargs['atom']

        # Set-up pseudopotential if it exists
        # This must happen before build() because it affects
        # tot_electrons() via atom_charge()
        if self.pseudo is not None:
            if isinstance(self.pseudo, str):
                # specify global pseudo for whole molecule
                _atom = self.format_atom(self.atom, unit=self.unit)
                uniq_atoms = set([a[0] for a in _atom])
                self._pseudo = self.format_pseudo(dict([(a, self.pseudo)
                                                      for a in uniq_atoms]))
            else:
                self._pseudo = self.format_pseudo(self.pseudo)

        # Do regular Mole.build with usual kwargs
        _built = self._built
        mole.Mole.build(self, False, parse_arg, *args, **kwargs)

        self._h = self.lattice_vectors()
        self.vol = float(scipy.linalg.det(self._h))

        if self.nimgs is None:
            self.nimgs = self.get_nimgs(self.precision)

        if self.gs is None:
            assert(self.ke_cutoff is not None)
            self.gs = pbctools.cutoff_to_gs(self._h, self.ke_cutoff)

        if self.ew_eta is None or self.ew_cut is None:
            self.ew_eta, self.ew_cut = self.get_ewald_params(self.precision, self.gs)

        if dump_input and not _built and self.verbose > logger.NOTE:
            self.dump_input()
            logger.info(self, 'lattice vector [a1          | a2          | a3         ]')
            logger.info(self, '               [%.9f | %.9f | %.9f]', *self._h[0])
            logger.info(self, '               [%.9f | %.9f | %.9f]', *self._h[1])
            logger.info(self, '               [%.9f | %.9f | %.9f]', *self._h[2])
            logger.info(self, 'Cell volume = %g', self.vol)
            logger.info(self, 'nimgs = %s  lattice sum = %d cells',
                        self.nimgs, len(self.get_lattice_Ls(self.nimgs)))
            logger.info(self, 'precision = %g', self.precision)
            logger.info(self, 'gs (grid size) = %s', self.gs)
            logger.info(self, 'pseudo = %s', self.pseudo)
            logger.info(self, 'ke_cutoff = %s', self.ke_cutoff)
            logger.info(self, 'ew_eta = %g', self.ew_eta)
            logger.info(self, 'ew_cut = %s', self.ew_cut)
        return self
Пример #3
0
    def build(self, dump_input=True, parse_arg=True,
              h=None, gs=None, ke_cutoff=None, precision=None, nimgs=None,
              ew_eta=None, ew_cut=None, pseudo=None, basis=None,
              dimension=None,
              *args, **kwargs):
        '''Setup Mole molecule and Cell and initialize some control parameters.
        Whenever you change the value of the attributes of :class:`Cell`,
        you need call this function to refresh the internal data of Cell.

        Kwargs:
            h : (3,3) ndarray
                The real-space unit cell lattice vectors, a "three-column" array [a1|a2|a3]
            gs : (3,) ndarray of ints
                The number of *positive* G-vectors along each direction.
            pseudo : dict or str
                To define pseudopotential.  If given, overwrite :attr:`Cell.pseudo`
        '''
        if h is not None: self.h = h
        if gs is not None: self.gs = gs
        if nimgs is not None: self.nimgs = nimgs
        if ew_eta is not None: self.ew_eta = ew_eta
        if ew_cut is not None: self.ew_cut = ew_cut
        if pseudo is not None: self.pseudo = pseudo
        if basis is not None: self.basis = basis
        if dimension is not None: self.dimension = dimension

        assert(self.h is not None)
        assert(self.gs is not None or self.ke_cutoff is not None)

        if 'unit' in kwargs:
            self.unit = kwargs['unit']

        if 'atom' in kwargs:
            self.atom = kwargs['atom']

        # Set-up pseudopotential if it exists
        # This must happen before build() because it affects
        # tot_electrons() via atom_charge()
        if self.pseudo is not None:
            if isinstance(self.pseudo, str):
                # specify global pseudo for whole molecule
                _atom = self.format_atom(self.atom, unit=self.unit)
                uniq_atoms = set([a[0] for a in _atom])
                self._pseudo = self.format_pseudo(dict([(a, self.pseudo)
                                                      for a in uniq_atoms]))
            else:
                self._pseudo = self.format_pseudo(self.pseudo)

        # Do regular Mole.build with usual kwargs
        _built = self._built
        mole.Mole.build(self, False, parse_arg, *args, **kwargs)

        self._h = self.lattice_vectors()
        self.vol = float(scipy.linalg.det(self._h))

        if self.nimgs is None:
            self.nimgs = self.get_nimgs(self.precision)

        if self.gs is None:
            assert(self.ke_cutoff is not None)
            self.gs = pbctools.cutoff_to_gs(self._h, self.ke_cutoff)

        if self.ew_eta is None or self.ew_cut is None:
            self.ew_eta, self.ew_cut = self.get_ewald_params(self.precision, self.gs)

        if dump_input and not _built and self.verbose > logger.NOTE:
            self.dump_input()
            logger.info(self, 'lattice vector [a1          | a2          | a3         ]')
            logger.info(self, '               [%.9f | %.9f | %.9f]', *self._h[0])
            logger.info(self, '               [%.9f | %.9f | %.9f]', *self._h[1])
            logger.info(self, '               [%.9f | %.9f | %.9f]', *self._h[2])
            logger.info(self, 'Cell volume = %g', self.vol)
            logger.info(self, 'nimgs = %s  lattice sum = %d cells',
                        self.nimgs, len(self.get_lattice_Ls(self.nimgs)))
            logger.info(self, 'precision = %g', self.precision)
            logger.info(self, 'gs (grid size) = %s', self.gs)
            logger.info(self, 'pseudo = %s', self.pseudo)
            logger.info(self, 'ke_cutoff = %s', self.ke_cutoff)
            logger.info(self, 'ew_eta = %g', self.ew_eta)
            logger.info(self, 'ew_cut = %s', self.ew_cut)
        return self
Пример #4
0
    def build(self, dump_input=True, parse_arg=True,
              a=None, gs=None, ke_cutoff=None, precision=None, nimgs=None,
              ew_eta=None, ew_cut=None, pseudo=None, basis=None, h=None,
              dimension=None, rcut= None, ecp=None,
              *args, **kwargs):
        '''Setup Mole molecule and Cell and initialize some control parameters.
        Whenever you change the value of the attributes of :class:`Cell`,
        you need call this function to refresh the internal data of Cell.

        Kwargs:
            a : (3,3) ndarray
                The real-space unit cell lattice vectors. Each row represents
                a lattice vector.
            gs : (3,) ndarray of ints
                The number of *positive* G-vectors along each direction.
            pseudo : dict or str
                To define pseudopotential.  If given, overwrite :attr:`Cell.pseudo`
        '''
        if h is not None: self.h = h
        if a is not None: self.a = a
        if gs is not None: self.gs = gs
        if nimgs is not None: self.nimgs = nimgs
        if ew_eta is not None: self.ew_eta = ew_eta
        if ew_cut is not None: self.ew_cut = ew_cut
        if pseudo is not None: self.pseudo = pseudo
        if basis is not None: self.basis = basis
        if dimension is not None: self.dimension = dimension
        if precision is not None: self.precision = precision
        if rcut is not None: self.rcut = rcut
        if ecp is not None: self.ecp = ecp

        assert(self.a is not None)
        assert(self.gs is not None or self.ke_cutoff is not None)

        if 'unit' in kwargs:
            self.unit = kwargs['unit']

        if 'atom' in kwargs:
            self.atom = kwargs['atom']

        # Set-up pseudopotential if it exists
        # This must happen before build() because it affects
        # tot_electrons() via atom_charge()

        self.ecp, self.pseudo = classify_ecp_pseudo(self, self.ecp, self.pseudo)
        if self.pseudo is not None:
            if isinstance(self.pseudo, str):
                # specify global pseudo for whole molecule
                _atom = self.format_atom(self.atom, unit=self.unit)
                uniq_atoms = set([a[0] for a in _atom])
                self._pseudo = self.format_pseudo(dict([(a, self.pseudo)
                                                      for a in uniq_atoms]))
            else:
                self._pseudo = self.format_pseudo(self.pseudo)

        # Do regular Mole.build with usual kwargs
        _built = self._built
        mole.Mole.build(self, False, parse_arg, *args, **kwargs)

        if self.rcut is None:
            self.rcut = max([self.bas_rcut(ib, self.precision)
                             for ib in range(self.nbas)])

        _a = self.lattice_vectors()
        if self.gs is None:
            assert(self.ke_cutoff is not None)
            self.gs = pbctools.cutoff_to_gs(_a, self.ke_cutoff)

        if self.ew_eta is None or self.ew_cut is None:
            self.ew_eta, self.ew_cut = self.get_ewald_params(self.precision, self.gs)

        if dump_input and not _built and self.verbose > logger.NOTE:
            self.dump_input()
            logger.info(self, 'lattice vectors  a1 [%.9f, %.9f, %.9f]', *_a[0])
            logger.info(self, '                 a2 [%.9f, %.9f, %.9f]', *_a[1])
            logger.info(self, '                 a3 [%.9f, %.9f, %.9f]', *_a[2])
            logger.info(self, 'dimension = %s', self.dimension)
            logger.info(self, 'Cell volume = %g', self.vol)
            logger.info(self, 'rcut = %s (nimgs = %s)', self.rcut, self.nimgs)
            logger.info(self, 'lattice sum = %d cells', len(self.get_lattice_Ls()))
            logger.info(self, 'precision = %g', self.precision)
            logger.info(self, 'gs (FFT-mesh) = %s', self.gs)
            logger.info(self, 'pseudo = %s', self.pseudo)
            logger.info(self, 'ke_cutoff = %s', self.ke_cutoff)
            logger.info(self, 'ew_eta = %g', self.ew_eta)
            logger.info(self, 'ew_cut = %s (nimgs = %s)', self.ew_cut,
                        self.get_bounding_sphere(self.ew_cut))
        return self