libtetrabz python package
リビジョン | 6395f024f73d1b52045805c6e066161f7336399b (tree) |
---|---|
日時 | 2022-03-24 20:49:10 |
作者 | ![]() |
コミッター | Mitsuaki Kawamura |
wrapper C-python code
@@ -4,3 +4,8 @@ dist/ | ||
4 | 4 | *.pyc |
5 | 5 | doc/_build |
6 | 6 | src/libtetrabz.egg-info/ |
7 | +*.x | |
8 | +*.o | |
9 | +.idea | |
10 | +build | |
11 | + |
@@ -0,0 +1,247 @@ | ||
1 | +# | |
2 | +# Copyright (c) 2014 Mitsuaki Kawamura | |
3 | +# | |
4 | +# Permission is hereby granted, free of charge, to any person obtaining a | |
5 | +# copy of this software and associated documentation files (the | |
6 | +# "Software"), to deal in the Software without restriction, including | |
7 | +# without limitation the rights to use, copy, modify, merge, publish, | |
8 | +# distribute, sublicense, and/or sell copies of the Software, and to | |
9 | +# permit persons to whom the Software is furnished to do so, subject to | |
10 | +# the following conditions: | |
11 | +# | |
12 | +# The above copyright notice and this permission notice shall be included | |
13 | +# in all copies or substantial portions of the Software. | |
14 | +# | |
15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
16 | +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
18 | +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
19 | +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
20 | +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
21 | +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | +# | |
23 | +from .libtetrabzc import dos_c | |
24 | +from .libtetrabzc import intdos_c | |
25 | +from .libtetrabzc import occ_c | |
26 | +from .libtetrabzc import fermieng_c | |
27 | +from .libtetrabzc import polstat_c | |
28 | +from .libtetrabzc import fermigr_c | |
29 | +from .libtetrabzc import dbldelta_c | |
30 | +from .libtetrabzc import dblstep_c | |
31 | +from .libtetrabzc import polcmplx_c | |
32 | +import numpy | |
33 | + | |
34 | + | |
35 | +def occ(bvec=numpy.array([1.0, 0.0, 0.0]), eig=numpy.array([0.0])): | |
36 | + """ | |
37 | + | |
38 | + :return: | |
39 | + """ | |
40 | + # | |
41 | + ng = numpy.array(eig.shape[0:3]) | |
42 | + nk = ng.prod(0) | |
43 | + nb = eig.shape[3] | |
44 | + eig_c = eig.reshape(nk*nb).tolist() | |
45 | + # | |
46 | + wght_c = libtetrabzc.occ_c(ng[0], ng[1], ng[2], nk, nb, | |
47 | + bvec[0, 0], bvec[0, 1], bvec[0, 2], | |
48 | + bvec[1, 0], bvec[1, 1], bvec[1, 2], | |
49 | + bvec[2, 0], bvec[2, 1], bvec[2, 2], eig_c) | |
50 | + # | |
51 | + wght = numpy.array(wght_c).reshape([ng[0], ng[1], ng[2], nb]) | |
52 | + return wght | |
53 | + | |
54 | + | |
55 | +def fermieng(bvec=numpy.array([1.0, 0.0, 0.0]), eig=numpy.array([0.0]), nelec=0.0): | |
56 | + """ | |
57 | + | |
58 | + :return: | |
59 | + """ | |
60 | + # | |
61 | + ng = numpy.array(eig.shape[0:3]) | |
62 | + nk = ng.prod(0) | |
63 | + nb = eig.shape[3] | |
64 | + eig_c = eig.reshape(nk*nb).tolist() | |
65 | + | |
66 | + wght_c = libtetrabzc.fermieng_c(ng[0], ng[1], ng[2], nk, nb, | |
67 | + bvec[0, 0], bvec[0, 1], bvec[0, 2], | |
68 | + bvec[1, 0], bvec[1, 1], bvec[1, 2], | |
69 | + bvec[2, 0], bvec[2, 1], bvec[2, 2], eig_c, nelec) | |
70 | + # | |
71 | + ef = wght_c[nk * nb] | |
72 | + iteration = wght_c[nk*nb + 1] | |
73 | + wght = numpy.array(wght_c)[0:nk*nb].reshape([ng[0], ng[1], ng[2], nb]) | |
74 | + return ef, wght, iteration | |
75 | + | |
76 | + | |
77 | +def dos(bvec=numpy.array([1.0, 0.0, 0.0]), eig=numpy.array([0.0]), e0=numpy.array([0.0])): | |
78 | + """ | |
79 | + | |
80 | + :return: | |
81 | + """ | |
82 | + ng = numpy.array(eig.shape[0:3]) | |
83 | + nk = ng.prod(0) | |
84 | + nb = eig.shape[3] | |
85 | + ne = e0.shape[0] | |
86 | + eig_c = eig.reshape(nk*nb).tolist() | |
87 | + e0_c = e0.tolist() | |
88 | + # | |
89 | + wght_c = libtetrabzc.dos_c(ng[0], ng[1], ng[2], nk, nb, ne, | |
90 | + bvec[0, 0], bvec[0, 1], bvec[0, 2], | |
91 | + bvec[1, 0], bvec[1, 1], bvec[1, 2], | |
92 | + bvec[2, 0], bvec[2, 1], bvec[2, 2], eig_c, e0_c) | |
93 | + # | |
94 | + wght = numpy.array(wght_c).reshape([ng[0], ng[1], ng[2], nb, ne]) | |
95 | + return wght | |
96 | + | |
97 | + | |
98 | +def intdos(bvec=numpy.array([1.0, 0.0, 0.0]), eig=numpy.array([0.0]), e0=numpy.array([0.0])): | |
99 | + """ | |
100 | + | |
101 | + :return: | |
102 | + """ | |
103 | + ng = numpy.array(eig.shape[0:3]) | |
104 | + nk = ng.prod(0) | |
105 | + nb = eig.shape[3] | |
106 | + ne = e0.shape[0] | |
107 | + eig_c = eig.reshape(nk*nb).tolist() | |
108 | + e0_c = e0.tolist() | |
109 | + # | |
110 | + wght_c = libtetrabzc.intdos_c(ng[0], ng[1], ng[2], nk, nb, ne, | |
111 | + bvec[0, 0], bvec[0, 1], bvec[0, 2], | |
112 | + bvec[1, 0], bvec[1, 1], bvec[1, 2], | |
113 | + bvec[2, 0], bvec[2, 1], bvec[2, 2], eig_c, e0_c) | |
114 | + # | |
115 | + wght = numpy.array(wght_c).reshape([ng[0], ng[1], ng[2], nb, ne]) | |
116 | + return wght | |
117 | + | |
118 | + | |
119 | +def dblstep(bvec=numpy.array([1.0, 0.0, 0.0]), eig1=numpy.array([0.0]), eig2=numpy.array([0.0])): | |
120 | + """ | |
121 | + | |
122 | + :param bvec: | |
123 | + :param eig1: | |
124 | + :param eig2: | |
125 | + :return: | |
126 | + """ | |
127 | + # | |
128 | + ng = numpy.array(eig1.shape[0:3]) | |
129 | + nk = ng.prod(0) | |
130 | + nb = eig1.shape[3] | |
131 | + eig1_c = eig1.reshape(nk*nb).tolist() | |
132 | + eig2_c = eig2.reshape(nk*nb).tolist() | |
133 | + | |
134 | + wght_c = libtetrabzc.dblstep_c(ng[0], ng[1], ng[2], nk, nb, | |
135 | + bvec[0, 0], bvec[0, 1], bvec[0, 2], | |
136 | + bvec[1, 0], bvec[1, 1], bvec[1, 2], | |
137 | + bvec[2, 0], bvec[2, 1], bvec[2, 2], eig1_c, eig2_c) | |
138 | + # | |
139 | + wght = numpy.array(wght_c).reshape([ng[0], ng[1], ng[2], nb, nb]) | |
140 | + return wght | |
141 | + | |
142 | + | |
143 | +def dbldelta(bvec=numpy.array([1.0, 0.0, 0.0]), eig1=numpy.array([0.0]), eig2=numpy.array([0.0])): | |
144 | + """ | |
145 | + | |
146 | + :param bvec: | |
147 | + :param eig1: | |
148 | + :param eig2: | |
149 | + :return: | |
150 | + """ | |
151 | + # | |
152 | + ng = numpy.array(eig1.shape[0:3]) | |
153 | + nk = ng.prod(0) | |
154 | + nb = eig1.shape[3] | |
155 | + eig1_c = eig1.reshape(nk * nb).tolist() | |
156 | + eig2_c = eig2.reshape(nk * nb).tolist() | |
157 | + | |
158 | + wght_c = libtetrabzc.dbldelta_c(ng[0], ng[1], ng[2], nk, nb, | |
159 | + bvec[0, 0], bvec[0, 1], bvec[0, 2], | |
160 | + bvec[1, 0], bvec[1, 1], bvec[1, 2], | |
161 | + bvec[2, 0], bvec[2, 1], bvec[2, 2], eig1_c, eig2_c) | |
162 | + # | |
163 | + wght = numpy.array(wght_c).reshape([ng[0], ng[1], ng[2], nb, nb]) | |
164 | + return wght | |
165 | + | |
166 | + | |
167 | +def polstat(bvec=numpy.array([1.0, 0.0, 0.0]), eig1=numpy.array([0.0]), eig2=numpy.array([0.0])): | |
168 | + """ | |
169 | + | |
170 | + :param bvec: | |
171 | + :param eig1: | |
172 | + :param eig2: | |
173 | + :return: | |
174 | + """ | |
175 | + ng = numpy.array(eig1.shape[0:3]) | |
176 | + nk = ng.prod(0) | |
177 | + nb = eig1.shape[3] | |
178 | + eig1_c = eig1.reshape(nk * nb).tolist() | |
179 | + eig2_c = eig2.reshape(nk * nb).tolist() | |
180 | + | |
181 | + wght_c = libtetrabzc.polstat_c(ng[0], ng[1], ng[2], nk, nb, | |
182 | + bvec[0, 0], bvec[0, 1], bvec[0, 2], | |
183 | + bvec[1, 0], bvec[1, 1], bvec[1, 2], | |
184 | + bvec[2, 0], bvec[2, 1], bvec[2, 2], eig1_c, eig2_c) | |
185 | + # | |
186 | + wght = numpy.array(wght_c).reshape([ng[0], ng[1], ng[2], nb, nb]) | |
187 | + return wght | |
188 | + | |
189 | + | |
190 | +def fermigr(bvec=numpy.array([1.0, 0.0, 0.0]), | |
191 | + eig1=numpy.array([0.0]), eig2=numpy.array([0.0]), e0=numpy.array([0.0])): | |
192 | + """ | |
193 | + | |
194 | + :param bvec: | |
195 | + :param eig1: | |
196 | + :param eig2: | |
197 | + :param e0: | |
198 | + :return: | |
199 | + """ | |
200 | + ng = numpy.array(eig1.shape[0:3]) | |
201 | + nk = ng.prod(0) | |
202 | + nb = eig1.shape[3] | |
203 | + ne = e0.shape[0] | |
204 | + eig1_c = eig1.reshape(nk * nb).tolist() | |
205 | + eig2_c = eig2.reshape(nk * nb).tolist() | |
206 | + e0_c = e0.tolist() | |
207 | + | |
208 | + wght_c = libtetrabzc.fermigr_c(ng[0], ng[1], ng[2], nk, nb, ne, | |
209 | + bvec[0, 0], bvec[0, 1], bvec[0, 2], | |
210 | + bvec[1, 0], bvec[1, 1], bvec[1, 2], | |
211 | + bvec[2, 0], bvec[2, 1], bvec[2, 2], eig1_c, eig2_c, e0_c) | |
212 | + # | |
213 | + wght = numpy.array(wght_c).reshape([ng[0], ng[1], ng[2], nb, nb, ne]) | |
214 | + return wght | |
215 | + | |
216 | + | |
217 | +def polcmplx(bvec=numpy.array([1.0, 0.0, 0.0]), | |
218 | + eig1=numpy.array([0.0]), eig2=numpy.array([0.0]), e0=numpy.array([0.0+0.0j])): | |
219 | + """ | |
220 | + | |
221 | + :param bvec: | |
222 | + :param eig1: | |
223 | + :param eig2: | |
224 | + :param e0: | |
225 | + :return: | |
226 | + """ | |
227 | + ng = numpy.array(eig1.shape[0:3]) | |
228 | + nk = ng.prod(0) | |
229 | + nb = eig1.shape[3] | |
230 | + ne = e0.shape[0] | |
231 | + eig1_c = eig1.reshape(nk * nb).tolist() | |
232 | + eig2_c = eig2.reshape(nk * nb).tolist() | |
233 | + | |
234 | + e0_1 = numpy.empty([ne, 2], dtype=numpy.float_) | |
235 | + e0_1[:, 0] = e0[:].real | |
236 | + e0_1[:, 1] = e0[:].imag | |
237 | + e0_c = e0_1.reshape(ne * 2).tolist() | |
238 | + | |
239 | + wght_c = libtetrabzc.polcmplx_c(ng[0], ng[1], ng[2], nk, nb, ne, | |
240 | + bvec[0, 0], bvec[0, 1], bvec[0, 2], | |
241 | + bvec[1, 0], bvec[1, 1], bvec[1, 2], | |
242 | + bvec[2, 0], bvec[2, 1], bvec[2, 2], eig1_c, eig2_c, e0_c) | |
243 | + # | |
244 | + wght_1 = numpy.array(wght_c).reshape([ng[0], ng[1], ng[2], nb, nb, ne, 2]) | |
245 | + # | |
246 | + wght = wght_1[:, :, :, :, :, :, 0] + 1.0j * wght_1[:, :, :, :, :, :, 1] | |
247 | + return wght |
@@ -613,7 +613,7 @@ static void libtetrabz_dbldelta2( | ||
613 | 613 | /* |
614 | 614 | Main SUBROUTINE for Delta(E1) * Delta(E2) |
615 | 615 | */ |
616 | -static PyObject* dbldelta(PyObject* self, PyObject* args) | |
616 | +static PyObject* dbldelta_c(PyObject* self, PyObject* args) | |
617 | 617 | { |
618 | 618 | int it, ik, ib, i20, i4, j3, jb, ** ikv, indx[4], ierr, ng[3], nk, nb; |
619 | 619 | double wlsm[20][4], ** ei1, ** ej1, ** ej2, e[4], *** w1, **w2, v, tsmall[4][3], thr, |
@@ -923,7 +923,7 @@ static void libtetrabz_dblstep2( | ||
923 | 923 | /* |
924 | 924 | Main SUBROUTINE for Theta(- E1) * Theta(E1 - E2) |
925 | 925 | */ |
926 | -static PyObject* dblstep(PyObject* self, PyObject* args) | |
926 | +static PyObject* dblstep_c(PyObject* self, PyObject* args) | |
927 | 927 | { |
928 | 928 | int it, ik, ib, jb, i20, i4, j4, **ikv, indx[4], ierr, ng[3], nk, nb; |
929 | 929 | double wlsm[20][4], **ei1, **ej1, ei2[4], ** ej2, e[4], *** w1, ** w2, v, tsmall[4][4], thr, |
@@ -1245,7 +1245,7 @@ static PyObject* dblstep(PyObject* self, PyObject* args) | ||
1245 | 1245 | /* |
1246 | 1246 | Compute Dos : Delta(E - E1) |
1247 | 1247 | */ |
1248 | -static PyObject* dos(PyObject* self, PyObject* args) { | |
1248 | +static PyObject* dos_c(PyObject* self, PyObject* args) { | |
1249 | 1249 | int it, ik, ib, ii, jj, ie, ** ikv, indx[4], ierr, ng[3], nk, nb, ne; |
1250 | 1250 | double wlsm[20][4], ** ei1, e[4], *** w1, v, tsmall[4][3], bvec[3][3], ** eig, * e0, *** wght; |
1251 | 1251 | PyObject* eig_po, * e0_po, * wght_po; |
@@ -1404,7 +1404,7 @@ static PyObject* dos(PyObject* self, PyObject* args) { | ||
1404 | 1404 | /* |
1405 | 1405 | Compute integrated Dos : theta(E - E1) |
1406 | 1406 | */ |
1407 | -static PyObject* intdos(PyObject* self, PyObject* args) { | |
1407 | +static PyObject* intdos_c(PyObject* self, PyObject* args) { | |
1408 | 1408 | int it, ik, ib, ii, jj, ie, ** ikv, indx[4], ierr, ng[3], nk, nb, ne; |
1409 | 1409 | double wlsm[20][4], ** ei1, e[4], *** w1, v, tsmall[4][4], bvec[3][3], ** eig, * e0, *** wght; |
1410 | 1410 | PyObject* eig_po, * e0_po, * wght_po; |
@@ -1778,7 +1778,7 @@ static void libtetrabz_fermigr2( | ||
1778 | 1778 | /* |
1779 | 1779 | Main SUBROUTINE for Fermi's Golden rule : Theta(- E1) * Theta(E2) * Delta(E2 - E1 - w) |
1780 | 1780 | */ |
1781 | -static PyObject* fermigr(PyObject* self, PyObject* args) | |
1781 | +static PyObject* fermigr_c(PyObject* self, PyObject* args) | |
1782 | 1782 | { |
1783 | 1783 | int it, ik, ib, i20, i4, j4, jb, ie, **ikv, indx[4], ierr, ng[3], nk, nb, ne; |
1784 | 1784 | double wlsm[20][4], **ei1, **ej1, ei2[4], ** ej2, e[4], **** w1, *** w2, v, tsmall[4][4], thr, |
@@ -2227,7 +2227,7 @@ void occ_main( | ||
2227 | 2227 | /* |
2228 | 2228 | |
2229 | 2229 | */ |
2230 | -static PyObject* occ(PyObject* self, PyObject* args) | |
2230 | +static PyObject* occ_c(PyObject* self, PyObject* args) | |
2231 | 2231 | { |
2232 | 2232 | int ik, ib, ii, nk, nb, ng[3], ierr, ** ikv; |
2233 | 2233 | double** eig, ** wght, bvec[3][3], wlsm[20][4], **ei1, **w1; |
@@ -2305,7 +2305,7 @@ static PyObject* occ(PyObject* self, PyObject* args) | ||
2305 | 2305 | /* |
2306 | 2306 | Calculate Fermi energy |
2307 | 2307 | */ |
2308 | -static PyObject* fermieng(PyObject* self, PyObject* args) | |
2308 | +static PyObject* fermieng_c(PyObject* self, PyObject* args) | |
2309 | 2309 | { |
2310 | 2310 | int maxiter, ik, ib, iteration, nk, nb, ng[3], |
2311 | 2311 | **ikv, ii, ierr; |
@@ -2985,7 +2985,7 @@ static void libtetrabz_polcmplx2( | ||
2985 | 2985 | /* |
2986 | 2986 | Main SUBROUTINE for Polarization (Imaginary axis) : Theta(- E1) * Theta(E2) / (E2 - E1 - iw) |
2987 | 2987 | */ |
2988 | -static PyObject* polcmplx(PyObject* self, PyObject* args) { | |
2988 | +static PyObject* polcmplx_c(PyObject* self, PyObject* args) { | |
2989 | 2989 | int it, ik, ie, ib, i4, j4, ir, jb, **ikv, indx[4], i20, ierr, ng[3], nk, nb, ne; |
2990 | 2990 | double wlsm[20][4], **ei1, **ej1, ei2[4], ** ej2, e[4], ***** w1, **** w2, v, tsmall[4][4], thr, |
2991 | 2991 | bvec[3][3], ** eig1, ** eig2, ** e0, ***** wght; |
@@ -3768,7 +3768,7 @@ static void libtetrabz_polstat2( | ||
3768 | 3768 | /* |
3769 | 3769 | Compute Static polarization function |
3770 | 3770 | */ |
3771 | -static PyObject* polstat(PyObject* self, PyObject* args) | |
3771 | +static PyObject* polstat_c(PyObject* self, PyObject* args) | |
3772 | 3772 | { |
3773 | 3773 | int it, ik, ib, jb, i20, i4, j4, **ikv, indx[4], ierr, ng[3], nk, nb; |
3774 | 3774 | double wlsm[20][4], **ei1, **ej1, ei2[4], ** ej2, e[4], *** w1, ** w2, v, tsmall[4][4], thr, |
@@ -4088,15 +4088,15 @@ static PyObject* polstat(PyObject* self, PyObject* args) | ||
4088 | 4088 | return wght_po; |
4089 | 4089 | } |
4090 | 4090 | static PyMethodDef LibTetraBZCMethods[] = { |
4091 | - {"dos", dos, METH_VARARGS, "Density of States"}, | |
4092 | - {"intdos", intdos, METH_VARARGS, "Integrated density of States"}, | |
4093 | - {"occ", occ, METH_VARARGS, "Occupations"}, | |
4094 | - {"fermieng", fermieng, METH_VARARGS, "Fermi energy"}, | |
4095 | - {"dbldelta", dbldelta, METH_VARARGS, "Double delta"}, | |
4096 | - {"dblstep", dblstep, METH_VARARGS, "Double step function"}, | |
4097 | - {"polstat", polstat, METH_VARARGS, "Static polarization function"}, | |
4098 | - {"fermigr", fermigr, METH_VARARGS, "Fermi's golden rule"}, | |
4099 | - {"polcmplx", polcmplx, METH_VARARGS, "Dynamical polarization function on complex frequency"}, | |
4091 | + {"dos_c", dos_c, METH_VARARGS, "Density of States"}, | |
4092 | + {"intdos_c", intdos_c, METH_VARARGS, "Integrated density of States"}, | |
4093 | + {"occ_c", occ_c, METH_VARARGS, "Occupations"}, | |
4094 | + {"fermieng_c", fermieng_c, METH_VARARGS, "Fermi energy"}, | |
4095 | + {"dbldelta_c", dbldelta_c, METH_VARARGS, "Double delta"}, | |
4096 | + {"dblstep_c", dblstep_c, METH_VARARGS, "Double step function"}, | |
4097 | + {"polstat_c", polstat_c, METH_VARARGS, "Static polarization function"}, | |
4098 | + {"fermigr_c", fermigr_c, METH_VARARGS, "Fermi's golden rule"}, | |
4099 | + {"polcmplx_c", polcmplx_c, METH_VARARGS, "Dynamical polarization function on complex frequency"}, | |
4100 | 4100 | {NULL, NULL, 0, NULL} /* Sentinel */ |
4101 | 4101 | }; |
4102 | 4102 |