How to use the quantities.eV function in quantities

To help you get started, we’ve selected a few quantities examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pylada / pylada-light / src / pylada / vasp / extract / base.py View on Github external
def sigma(self):
        """ Greps smearing function from OUTCAR. """
        from numpy import array
        from quantities import eV
        result = self._find_first_OUTCAR(r"""\s*ISMEAR\s*=\s*(?:\d+)\s*;\s*SIGMA\s*=\s+(.*)\s+br""")
        if result is None:
            return None
        result = result.group(1).rstrip().lstrip().split()
        if len(result) == 1:
            return float(result[0]) * eV
        return array(result, dtype="float64") * eV
github pylada / pylada-light / src / pylada / crystal / defects / __init__.py View on Github external
defect.multiplicity[newaxis,:, newaxis])
        dummy = multiply(dummy, 1e0 - defect.occupations)
    elif defect.eigenvalues.ndim == 2:
        dummy = multiply(vbm - defect.eigenvalues, defect.multiplicity[:, newaxis])
        dummy = multiply(dummy, 2e0 - defect.occupations)
    result_p = -sum(dummy[defect.eigenvalues < vbm]) / sum(defect.multiplicity)

    result = result_n + result_p
    if ntype == True:
        return result_n.rescale(eV)
    elif ntype == False:
        return result_p.rescale(eV)
    else:
        if float(result_n) * float(result_p) > 1E-12:
            print("### WARNING: set ntype=True or False explitly for band filling correction.")
            print("    band filling for ntype: {0}".format(result_n.rescale(eV)))
            print("    band filling for ptype: {0}".format(result_p.rescale(eV)))
        return result.rescale(eV)
github pylada / pylada-defects / pylada_defects.py View on Github external
# make neighbors (upto=tol=0.2) to defects unacceptable 
    if ngh_shell:
        for keys in defects:
            for atom in defects[keys]:
                for n in ffirst_shell(d_str, atom.pos, 0.1):
                    acceptable[n[0].index] = False
                    
    # copy of acceptable before trusting user inputs
    raw_acceptable = deepcopy(acceptable)
    
    # dictionary with average defect elec. pot
    dict_defecte = avg_electropot(defect)

    # list to store abs. differnce in the electrostatic potential of defect and host
    diff_dh = [ (0.0*eV if not ok else abs(e - dict_defecte[a.type]).rescale(eV))
           for e, a, ok in zip(defect.electropot, d_str, acceptable)]
    
    # find max value of difference in electrostatic potential of defect and host
    maxdiff = max(diff_dh).magnitude

    # make atoms with diff_dh larger than user energy tolerance(e_tol) unacceptable
    for ii in range(len(acceptable)):
        if acceptable[ii] == False: pass
        elif float(diff_dh[ii].magnitude)>= maxdiff or float(diff_dh[ii].magnitude)>=e_tol:
            acceptable[ii] = False
    
    # Avoid excluding all atoms
    if not any(acceptable):
        # if user give e_tol < 0.0001
        print("WARNING; e_tol is too small excluding all atoms !! Switching to defaults")
        # return to default, which accepts all atomic sites expect defect sites (and ngh sites)
github pylada / pylada-light / src / pylada / vasp / specie.py View on Github external
def enmax(self):
        """ Maximum recommended cutoff """
        from quantities import eV
        import re
        self.potcar_exists()
        with self.read_potcar() as potcar:
            r = re.compile(r"ENMAX\s+=\s+(\S+);\s+ENMIN")
            p = r.search(potcar.read())
            if p is None:
                raise AssertionError("Could not retrieve ENMAX from " + self.directory)
            return float(p.group(1)) * eV
github pylada / pylada-light / vasp / specie.py View on Github external
    @property
    def enmax(self):
        """ Maximum recommended cutoff """
        from quantities import eV
        import re
        self.potcar_exists()
        with self.read_potcar() as potcar:
            r = re.compile("ENMAX\s+=\s+(\S+);\s+ENMIN")
            p = r.search(potcar.read())
            if p is None:
                raise AssertionError, "Could not retrieve ENMAX from " + self.directory
            return float(p.group(1)) * eV
github pylada / pylada-light / vasp / nlep / mpopt.py View on Github external
gw_band_idx = sys_input.gw_band_idx

    target_eigs = [sys_input.gw_in.qp_eigenvalues[k_idx[j]][gw_band_idx[i]]
                   for j in range(0, len(k_idx)) for i in range(0, len(gw_band_idx))]
    target_eigs = np.array([v.rescale(eV) for v in target_eigs])
    eigs = np.array([raweigs[k_idx[j]][nlep_band_idx[i]]
                     for j in range(0, len(k_idx)) for i in range(0, len(nlep_band_idx))])
    pc = np.array([rawpc[sys_input.atom_idx[i]][run_input.pc_orbital_idx[k]] for i in range(
        0, len(sys_input.vasp.species)) for k in range(0, len(run_input.pc_orbital_idx))])
    target_pc = np.array([sys_input_pc[i][run_input.pc_orbital_idx[k]] for i in range(
        0, len(sys_input.vasp.species)) for k in range(0, len(run_input.pc_orbital_idx))])

    if (not run_input.floating_vbm):
        band_shift = raweigs[run_input.gamma_point_idx][sys_input.nlep_valence_band_idx] - \
            sys_input.gw_in.qp_eigenvalues[run_input.gamma_point_idx][sys_input.gw_valence_band_idx]
        band_shift = float(band_shift.rescale(eV))
    else:
        eigdelta = (eigs - target_eigs)
        if (ignore_weights):
            band_shift = sum(eigdelta) / float(len(eigdelta))
        else:
            eigdelta = eigdelta * sys_input.eigenvalue_weights.flat
            normalizer = float(sum(sys_input.eigenvalue_weights.flat))
            band_shift = sum(eigdelta) / normalizer
#  if (sys_input.cation == "Mg"):
#    print "total Mg hack!"
#    target_pc[1] -= 6.

    target_occs = [sys_input.gw_in.occupations[k_idx[j]][gw_band_idx[i]]
                   for j in range(0, len(k_idx)) for i in range(0, len(gw_band_idx))]
    target_occs = np.array([v.rescale(eV) for v in target_occs])
    occs = np.array([rawoccs[k_idx[j]][nlep_band_idx[i]]
github pylada / pylada-defects / pylada_defects.py View on Github external
# get defect structure from pylada Extract object
    d_str = defect.structure

    # list of indicies in defect structure, that are accpetable in pot_align corr
    acceptable = [True for a in d_str]

    #dictionary with average host electrostatic potential with atom type
    dict_hoste = avg_electropot(host)

    #dictionary with average defect electrostatic potential with atom type
    dict_defecte = avg_electropot(defect)

    # compute the difference between defect electrostatic potential and avg. defect pot for each atom
    # Needed to determine unacceptable atoms based on e_tol
    diff_dh = [abs(e - dict_defecte[a.type]).rescale(eV) for e, a in zip(defect.electropot, d_str)]

    # find max value of difference in electrostatic potential of defect and host
    maxdiff = max(diff_dh).magnitude

    # make atoms unacceptable with diff_dh larger than maxdiff or the user energy tolerance(e_tol)
    for ii in range(len(acceptable)):
        if float(diff_dh[ii].magnitude)>= maxdiff or float(diff_dh[ii].magnitude)>=e_tol:
            acceptable[ii] = False

    # check for impurity
    impurity = [k for k in dict_defecte.keys() if k not in set(dict_hoste.keys())]

    for jj in range(len(acceptable)):
        if d_str[jj].type in impurity:
            acceptable[jj] = False
github pylada / pylada-light / vasp / nlep / mpopt.py View on Github external
import math
    from quantities import eV

    if special_pc != None:
        wprint("using pc overrides")
        sys_input_pc = special_pc
    else:
        sys_input_pc = sys_input.dft_in.partial_charges

    k_idx = run_input.k_idx
    nlep_band_idx = sys_input.nlep_band_idx
    gw_band_idx = sys_input.gw_band_idx

    target_eigs = [sys_input.gw_in.qp_eigenvalues[k_idx[j]][gw_band_idx[i]]
                   for j in range(0, len(k_idx)) for i in range(0, len(gw_band_idx))]
    target_eigs = np.array([v.rescale(eV) for v in target_eigs])
    eigs = np.array([raweigs[k_idx[j]][nlep_band_idx[i]]
                     for j in range(0, len(k_idx)) for i in range(0, len(nlep_band_idx))])
    pc = np.array([rawpc[sys_input.atom_idx[i]][run_input.pc_orbital_idx[k]] for i in range(
        0, len(sys_input.vasp.species)) for k in range(0, len(run_input.pc_orbital_idx))])
    target_pc = np.array([sys_input_pc[i][run_input.pc_orbital_idx[k]] for i in range(
        0, len(sys_input.vasp.species)) for k in range(0, len(run_input.pc_orbital_idx))])

    if (not run_input.floating_vbm):
        band_shift = raweigs[run_input.gamma_point_idx][sys_input.nlep_valence_band_idx] - \
            sys_input.gw_in.qp_eigenvalues[run_input.gamma_point_idx][sys_input.gw_valence_band_idx]
        band_shift = float(band_shift.rescale(eV))
    else:
        eigdelta = (eigs - target_eigs)
        if (ignore_weights):
            band_shift = sum(eigdelta) / float(len(eigdelta))
        else:
github pylada / pylada-light / src / pylada / vasp / incar / _params.py View on Github external
def incar_string(self, **kwargs):
        from ...crystal import specieset
        value = self._value
        if value is None:
            return None
        elif value < 1e-12:
            return None
        elif value >= 1e-12 and value <= 3.0:
            types = specieset(kwargs["structure"])
            encut = max(kwargs["vasp"].species[type].enmax for type in types)
            if hasattr(encut, 'rescale'):
                encut = float(encut.rescale(eV))
            return "{0} = {1} ".format(self.KEY, encut * value)
        return "{0} = {1}".format(self.KEY, value)