Example #1
0
    def as_smearing(cls, obj):
        """
        Constructs an instance of `Smearing` from obj. Accepts obj in the form:

            * Smearing instance
            * "name:tsmear"  e.g. "gaussian:0.004"  (Hartree units)
            * "name:tsmear units" e.g. "gaussian:0.1 eV"
            * None --> no smearing
        """
        if obj is None:
            return Smearing.nosmearing()

        if isinstance(obj, cls):
            return obj

        # obj is a string
        if obj == "nosmearing":
            return cls.nosmearing()
        else:
            obj, tsmear = obj.split(":")
            obj.strip()

            occopt = cls._mode2occopt[obj]
            try:
                tsmear = float(tsmear)
            except ValueError:
                tsmear, unit = tsmear.split()
                tsmear = units.Energy(float(tsmear), unit).to("Ha")

            return cls(occopt, tsmear)
Example #2
0
 def read_energy_terms(self, unit="eV"):
     """
     Return a dictionary with the different contributions to the total electronic energy.
     """
     convert = lambda e: units.Energy(e, unit="Ha").to(unit)
     d = {k: convert(self.read_value(k)) for k in EnergyTerms.ALL_KEYS}
     return EnergyTerms(**d)
Example #3
0
    def read_energy_terms(self, unit="eV"):
        """
        Return a dictionary with the different contributions to the total electronic energy.
        """
        convert = lambda e: units.Energy(e, unit="Ha").to(unit)
        d = OrderedDict()
        for k in EnergyTerms.ALL_KEYS:
            if k == "e_nonlocalpsp" and k not in self.rootgrp.variables:
                # Renamed in 8.9
                d[k] = convert(self.read_value("e_nlpsp_vfock"))
            else:
                d[k] = convert(self.read_value(k))

        return EnergyTerms(**d)
Example #4
0
    def as_ppmodel(cls, obj):
        """
        Constructs an instance of PPModel from obj.

        Accepts obj in the form:
            * PPmodel instance
            * string. e.g "godby:12.3 eV", "linden".
        """
        if isinstance(obj, cls):
            return obj

        # obj is a string
        if ":" not in obj:
            mode, plasmon_freq = obj, None
        else:
            # Extract mode and plasmon_freq
            mode, plasmon_freq = obj.split(":")
            try:
                plasmon_freq = float(plasmon_freq)
            except ValueError:
                plasmon_freq, unit = plasmon_freq.split()
                plasmon_freq = units.Energy(float(plasmon_freq), unit).to("Ha")

        return cls(mode=mode, plasmon_freq=plasmon_freq)
Example #5
0
 def energy(self):
     """Total energy in eV."""
     return units.Energy(self.reader.read_value("etotal"), "Ha").to("eV")
Example #6
0
 def pawecutdg(self):
     """Cutoff energy in Hartree for the PAW double grid (Abinit input variable)"""
     return units.Energy(self.reader.read_value("pawecutdg"), "Ha")
Example #7
0
 def ecut(self):
     """Cutoff energy in Hartree (Abinit input variable)"""
     return units.Energy(self.reader.read_value("ecut"), "Ha")