1# Note: The last time I tested something was missing so I couldn't work
2import pathlib
3import transpyle
4
5path = pathlib.Path('my_script.py')
6code_reader = transpyle.CodeReader()
7code = code_reader.read_file(path)
8
9from_language = transpyle.Language.find('Python 3.6')
10to_language = transpyle.Language.find('Fortran 95')
11translator = transpyle.AutoTranslator(from_language, to_language)
12fortran_code = translator.translate(code, path)
13print(fortran_code)
14
1
2import multiprocessing as mp
3import multiprocessing.sharedctypes
4
5import numpy as np
6import scipy as sp
7
8# Try to use the FFT implementation in PyFFTW if available, or fall back on
9# numpy's.
10
11
12try:
13 import pyfftw.interfaces.numpy_fft as npf
14except ImportError:
15 from BoltzTraP2.misc import warning
16 warning("you can install pyfftw to get better FFT performance")
17 import numpy.fft as npf
18
19from BoltzTraP2.units import * # import all functions from units
20
21
22
23def fitde3D(data, equivalences):
24 """Obtain the interpolation coefficients from DFT data.
25
26 Args:
27 data: DFTdata object containing all relevant input
28 equivalences: list of k-point equivalence classes in direct coordinates
29
30 Returns:
31 A set of interpolation coefficients as an array whose first dimension
32 runs over bands.
33 """
34 kp = data.kpoints
35 ene = data.ebands
36 mommat = data.mommat
37 lattvec = data.get_lattvec()
38
39 tpii = 2j * np.pi
40 C1 = .75
41 C2 = .75
42 Rvec = np.array([equiv[0] for equiv in equivalences]) #assigning first element of equiv to the Rvec
43 Rvec = np.array([equiv[0] for equiv in equivalences])
44 nstar = np.array([len(equiv) for equiv in equivalences])
45 R = np.linalg.norm(Rvec @ lattvec.T, axis=1) #used to calculate vector norm
46 De = ene.T[:-1] - ene.T[-1]
47 if mommat is not None:
48 for i in range(3):
49 De = np.vstack((De, mommat[:, :, i])) #vstack
50 X2 = (R / R[1])**2
51 rhoi = 1. / ((1. - C1 * X2)**2 + C2 * X2**3)
52 rhoi[0] = 0.
53