📜  Python 到 C++ 转换器 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:43.586000             🧑  作者: Mango

代码示例1
import multiprocessing as mp
import multiprocessing.sharedctypes

import numpy as np
import scipy as sp

# Try to use the FFT implementation in PyFFTW if available, or fall back on
# numpy's.


try:
    import pyfftw.interfaces.numpy_fft as npf
except ImportError:
    from BoltzTraP2.misc import warning
    warning("you can install pyfftw to get better FFT performance")
    import numpy.fft as npf

from BoltzTraP2.units import *                 # import all functions from units



def fitde3D(data, equivalences):
    """Obtain the interpolation coefficients from DFT data.

    Args:
        data: DFTdata object containing all relevant input
        equivalences: list of k-point equivalence classes in direct coordinates

    Returns:
        A set of interpolation coefficients as an array whose first dimension
        runs over bands.
    """
    kp = data.kpoints
    ene = data.ebands
    mommat = data.mommat
    lattvec = data.get_lattvec()

    tpii = 2j * np.pi
    C1 = .75
    C2 = .75
    Rvec = np.array([equiv[0] for equiv in equivalences])   #assigning first element of equiv to the Rvec
    Rvec = np.array([equiv[0] for equiv in equivalences])
    nstar = np.array([len(equiv) for equiv in equivalences])
    R = np.linalg.norm(Rvec @ lattvec.T, axis=1)            #used to calculate vector norm
    De = ene.T[:-1] - ene.T[-1]
    if mommat is not None:
        for i in range(3):
            De = np.vstack((De, mommat[:, :, i]))   #vstack
    X2 = (R / R[1])**2
    rhoi = 1. / ((1. - C1 * X2)**2 + C2 * X2**3)
    rhoi[0] = 0.