def assmearing(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" """ if isinstance(obj, cls): return obj # obj is a string obj, tsmear = obj.split(":") obj.strip() if obj == "nosmearing": return cls.nosmearing() else: occopt = cls._mode2occopt[obj] try: tsmear = float(tsmear) except ValueError: tsmear, units = tsmear.split() tsmear = any2Ha(units)(float(tsmear)) return cls(occopt, tsmear)
def asppmodel(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, units = plasmon_freq.split() plasmon_freq = any2Ha(units)(float(plasmon_freq)) return cls(mode=mode, plasmon_freq=plasmon_freq)