Merge lp:~nickpapior/siesta/4.1-fix-spin into lp:~albertog/siesta/4.1-fix-spin

Proposed by Nick Papior
Status: Merged
Approved by: Alberto Garcia
Approved revision: 832
Merged at revision: 835
Proposed branch: lp:~nickpapior/siesta/4.1-fix-spin
Merge into: lp:~albertog/siesta/4.1-fix-spin
Diff against target: 462 lines (+71/-154)
3 files modified
Src/diag2g.F (+34/-40)
Src/diag2k.F (+36/-113)
version.info (+1/-1)
To merge this branch: bzr merge lp:~nickpapior/siesta/4.1-fix-spin
Reviewer Review Type Date Requested Status
Alberto Garcia Approve
Review via email: mp+335736@code.launchpad.net

Description of the change

Further "fixes" for the non-colinear calculations.
This is just to clarify (in the comments) and in the diag2g routine.

To post a comment you must log in.
Revision history for this message
Alberto Garcia (albertog) wrote :

I need to discuss these things with Ramón in a larger context when we get back to ICMAB.

Revision history for this message
Alberto Garcia (albertog) wrote :

I am ready to accept the changes on simplicity arguments (i.e., having a single, compatible way to build the DM in the Noncol and SOC cases).

I will merge this changes in my 4.1-spin-fix branch (which also contains other clarifications), and we will mark this branch for merging into OSSO when it is ready.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Src/diag2g.F'
2--- Src/diag2g.F 2017-12-21 15:49:49 +0000
3+++ Src/diag2g.F 2018-01-05 08:40:43 +0000
4@@ -32,6 +32,7 @@
5 C This version is for non-collinear spin at gamma point.
6 C Writen by J.Soler, May and August 1998.
7 C Reduced memory requirements, Nick, Aug. 2017
8+C Clarified DM calculation, N.R. Papior, Jan. 2018
9 C **************************** INPUT **********************************
10 C integer nuo : Number of basis orbitals on local node
11 C integer no : Number of basis orbitals
12@@ -107,13 +108,13 @@
13 integer BNode, BTest, ie, ierror, iie, iio
14 integer ind, io, j, jo, nd, iuo, juo
15 real(dp) ee, pipj, qe, t
16- complex(dp) cicj, D11, D22, D12, D21
17+ complex(dp) :: cicj, D11, D22, D12, D21
18 #ifdef MPI
19 integer MPIerror
20 #endif
21 external cdiag
22 #ifdef DEBUG
23- call write_debug( ' PRE diag2k' )
24+ call write_debug( ' PRE diag2g' )
25 #endif
26 !***********************************************************************
27 ! B E G I N
28@@ -136,18 +137,16 @@
29 ! 1. Hermiticity imposes H_{i,j}^{is,js}=H_{j,i}^{js,is}^*
30 ! 2. Since wave functions are real, if there are no single P or L
31 ! operators:
32-! (a) H_{i,j}^{is,js}=H_{j,i}^{is,js}
33-! (b) These imply spin-box hermiticity:
34-! H_{i,j}^{is,js}=H_{i,j}^{js,is}^*
35-!
36-! (c) Hence
37-!
38-! | H(ind,1) H(ind,3) - i
39-! H(ind,4) |
40-! H_{j,i} = H_{i,j} = |
41-! |
42-! | H(ind,3) + i H(ind,4) H(ind,2)
43-! |
44+! (a) H_{i,j}^{is,js}=H_{j,i}^{is,js}
45+! (b) These imply spin-box hermiticity:
46+!
47+! H_{i,j}^{is,js}=H_{i,j}^{js,is}^*
48+!
49+! (c) Hence
50+!
51+! | H(ind,1) H(ind,3) - i H(ind,4) |
52+! H_{j,i} = H_{i,j} = | |
53+! | H(ind,3) + i H(ind,4) H(ind,2) |
54 !
55 !
56 ! The spin-orbit interaction and the orbital part of the Zeeman
57@@ -155,7 +154,6 @@
58 ! break the "spin-box hermiticity" of H. Hence the full format of H is
59 ! needed
60 ! in those cases.
61-!
62
63 Saux = dcmplx(0.0_dp, 0.0_dp)
64 Haux = dcmplx(0.0_dp, 0.0_dp)
65@@ -219,22 +217,21 @@
66 !***********************************************************************
67 !
68 ! | ------- 1,1 ------- ------- 1,2 ------- |
69-! | c_{i,up} c_{j,up}^* c_{i,up} c_{j,down)^* |
70-! D_{i,j} = | |
71+! | c_{j,up}^* c_{i,up} c_{j,up}^* c_{i,dn) |
72+! D_{j,i) = | |
73 ! | ------- 2,1 ------- ------- 2,2 ------- |
74-! | c_{i,down} c_{j,up}^* c_{i,dn} c_{j,dn)^* |
75+! | c_{j,dn}^* c_{i,up} c_{j,dn}^* c_{i,dn) |
76 !
77-! = | D_{i,j}(1) D_{i,j}(3)-i D_{i,j}(4) |
78-! | D_{i,j}(7)+i D_{i,j}(8) D_{i,j}(2) |
79+! = | D_{j,i}(1) D_{j,i}(3)-i D_{j,i}(4) |
80+! | D_{j,i}(7)+i D_{j,i}(8) D_{j,i}(2) |
81
82 ! The Energy is computed as E = Tr [ D_{i,j} H_{j,i} ]
83 !
84 ! The Density Matrix is not "spin box hermitian" even if H does not
85-! contain P or
86-! L operators.
87+! contain P or L operators.
88 !
89 ! Spin-box symmetrization of D inside this present subroutine:
90-! D_{i,j}(1,2) = 0.5 ( D_{i,j}(1,2) + D_{i,j}(2,1)^* )
91+! D_{j,i}(1,2) = 0.5 ( D_{j,i}(1,2) + D_{j,i}(2,1)^* )
92 ! does not affect the results in any case, since H is spin-box
93 ! hermitian.
94
95@@ -243,7 +240,6 @@
96
97 BNode = 0
98 iie = 0
99-
100 do ie = 1,2*nuotot
101 qe = qo(ie)
102 if (Node.eq.BNode) then
103@@ -260,7 +256,7 @@
104 endif
105 #ifdef MPI
106 call MPI_Bcast(caux(1,1),2*nuotot,MPI_double_complex,
107- . BNode,MPI_Comm_World,MPIerror)
108+ & BNode,MPI_Comm_World,MPIerror)
109 #endif
110 ee = qo(ie) * eo(ie)
111 do io = 1,nuo
112@@ -270,30 +266,30 @@
113 jo = listd(ind)
114
115 ! | ------- 1,1 ------- ------- 2,1 ------- |
116-! | c_{j,up} c_{i,up}^* c_{j,dn} c_{i,up)^* |
117+! | c_{j,up}^* c_{i,up} c_{j,dn}^* c_{i,up) |
118 ! D_{j,i} = | |
119 ! | ------- 1,2 ------- ------- 2,2 ------- |
120-! | c_{j,up} c_{i,dn}^* c_{j,dn} c_{i,dn)^* |
121+! | c_{j,up}^* c_{i,dn} c_{j,dn}^* c_{i,dn) |
122 !
123 !------- 1,1 -----------------------------------------------------------
124- D11 = dconjg(caux(1,iio)) * caux(1,jo)
125+ D11 = dconjg(caux(1,jo)) * caux(1,iio)
126 !------- 2,2 -----------------------------------------------------------
127- D22 = dconjg(caux(2,iio)) * caux(2,jo)
128+ D22 = dconjg(caux(2,jo)) * caux(2,iio)
129 !------- 2,1 -----------------------------------------------------------
130- D12 = dconjg(caux(1,iio)) * caux(2,jo)
131+ D12 = dconjg(caux(2,jo)) * caux(1,iio)
132 !------- 1,2 -----------------------------------------------------------
133- D21 = dconjg(caux(2,iio)) * caux(1,jo)
134+ D21 = dconjg(caux(1,jo)) * caux(2,iio)
135
136 !------------ Density matrix has to be spin-box hermitian ----------------------
137 D11 = 0.5_dp * (D11 + dconjg(D11))
138 D22 = 0.5_dp * (D22 + dconjg(D22))
139 D12 = 0.5_dp * (D12 + dconjg(D21))
140- D21 = dconjg(D12)
141+ !D21 = dconjg(D12)
142
143 ! Add contribution to density matrices of unit-cell orbitals
144 ! ----------------------------------------------------------------
145 ! | D11 = D_{j,i}(1) D21 = D_{j,i}(3)-i D_{j,i}(4) |
146-! | D12 = D_{i,j}(3)+i D_{i,j}(4) D22 = D_{j,i}(2) |
147+! | D12 = D_{j,i}(3)+i D_{j,i}(4) D22 = D_{j,i}(2) |
148 ! ----------------------------------------------------------------
149 ! ----------------------------------------------------------------
150 ! | D11 = Dnew(1) D21 = Dnew(3)-i Dnew(4) |
151@@ -302,12 +298,12 @@
152 Dnew(ind,1) = Dnew(ind,1) + dreal(D11) * qe
153 Dnew(ind,2) = Dnew(ind,2) + dreal(D22) * qe
154 Dnew(ind,3) = Dnew(ind,3) + dreal(D12) * qe
155- Dnew(ind,4) = Dnew(ind,4) + dimag(D12) * qe
156+ Dnew(ind,4) = Dnew(ind,4) - dimag(D12) * qe
157
158 Enew(ind,1) = Enew(ind,1) + dreal(D11) * ee
159 Enew(ind,2) = Enew(ind,2) + dreal(D22) * ee
160 Enew(ind,3) = Enew(ind,3) + dreal(D12) * ee
161- Enew(ind,4) = Enew(ind,4) + dimag(D12) * ee
162+ Enew(ind,4) = Enew(ind,4) - dimag(D12) * ee
163
164 enddo
165 enddo
166@@ -322,10 +318,8 @@
167 1001 continue
168
169 #ifdef DEBUG
170- call write_debug( ' POS diag2k' )
171+ call write_debug( ' POS diag2g' )
172 #endif
173-!***********************************************************************
174- return
175- end
176-!**********************************************************************
177+
178+ end subroutine diag2g
179
180
181=== modified file 'Src/diag2k.F'
182--- Src/diag2k.F 2017-08-06 11:17:47 +0000
183+++ Src/diag2k.F 2018-01-05 08:40:43 +0000
184@@ -37,6 +37,7 @@
185 C by J.D. Gale November 2004.
186 C Corrected by V.V. Maslyuk for parallel case, Mai 2007
187 C Reduced memory requirements, Nick, Aug. 2017
188+C Clarified DM calculation, N.R. Papior, Jan. 2018
189 C **************************** INPUT **********************************
190 C integer nuo : Number of basis orbitals in unit cell
191 C integer no : Number of basis orbitals in supercell
192@@ -119,7 +120,7 @@
193 complex(dp), dimension(2,nuotot) :: caux
194 logical getD
195
196-! TEMPOS, INTERNAL VARIABLES etc.
197+! Internal variables .............................................
198
199 integer BNode, BTest, ie, ierror, iie, ik, ind, io, iio
200 integer iuo, j, jo, juo, neigneeded
201@@ -128,14 +129,12 @@
202 ! Haux(js,juo,is,iuo) = <js,juo|H|is,iuo>
203 ! Indices is and js are for spin components
204 ! Indices iuo and juo are for orbital components
205- complex(dp) :: cicj
206- complex(dp) :: D11, D22, D12, D21
207- complex(dp) :: kphs
208- real(dp) :: kxij
209+ complex(dp) :: cicj, D11, D22, D12, D21
210+ complex(dp) :: kphs
211+ real(dp) :: kxij
212 #ifdef MPI
213 integer :: MPIerror
214 #endif
215-
216 external cdiag
217
218 #ifdef DEBUG
219@@ -165,24 +164,11 @@
220 ! H_{jo,iuo} = | |
221 ! | H_{jo,iuo}^{d,u} H_{jo,iuo}^{d,d} |
222 !
223-! | H(ind,1) + i H(ind,5) H(ind,3) - i H(ind,4) |
224-! = | |
225-! | H(ind,7) + i H(ind,8) H(ind,2) + i H(ind,6) |
226+! | H(ind,1) + i H(ind,5) H(ind,3) - i H(ind,4) |
227+! = | |
228+! | H(ind,7) + i H(ind,8) H(ind,2) + i H(ind,6) |
229 !
230 ! 1. Hermiticity imposes H_{i,j}^{is,js}=H_{j,i}^{js,is}^*
231-! 2. Since wave functions are real, if there are no single P or L
232-! operators:
233-! (a) H_{i,j}^{is,js}=H_{j,i}^{is,js}
234-! (b) These imply spin-box hermiticity:
235-! H_{i,j}^{is,js}=H_{i,j}^{js,is}^*
236-!
237-! (c) Hence
238-!
239-! | H(ind,1) H(ind,3) - i H(ind,4) |
240-! H_{j,i} = H_{i,j} = | |
241-! | H(ind,3) + i H(ind,4) H(ind,2) |
242-!
243-!
244
245 ! Find eigenvalues at every k point
246 do ik = 1,nk
247@@ -334,37 +320,34 @@
248 !***********************************************************************
249 !
250 ! | ------- 1,1 ------- ------- 1,2 ------- |
251-! | c_{i,up} c_{j,up}^* c_{i,up} c_{j,down)^* |
252-! D_{i,j} = | |
253+! | c_{j,up}^* c_{i,up} c_{j,up}^* c_{i,dn) |
254+! D_{j,i) = | |
255 ! | ------- 2,1 ------- ------- 2,2 ------- |
256-! | c_{i,down} c_{j,up}^* c_{i,dn} c_{j,dn)^* |
257+! | c_{j,dn}^* c_{i,up} c_{j,dn}^* c_{i,dn) |
258 !
259-! = | D_{i,j}(1) D_{i,j}(3)-i D_{i,j}(4) |
260-! | D_{i,j}(7)+i D_{i,j}(8) D_{i,j}(2) |
261+! = | D_{j,i}(1) D_{j,i}(3)-i D_{j,i}(4) |
262+! | D_{j,i}(7)+i D_{j,i}(8) D_{j,i}(2) |
263
264 ! The Energy is computed as E = Tr [ D_{i,j} H_{j,i} ]
265 !
266 ! The Density Matrix is not "spin box hermitian" even if H does not
267-! contain P or
268-! L operators.
269+! contain P or L operators.
270 !
271 ! Spin-box symmetrization of D inside this present subroutine:
272-! D_{i,j}(1,2) = 0.5 ( D_{i,j}(1,2) + D_{i,j}(2,1)^* )
273+! D_{j,i}(1,2) = 0.5 ( D_{j,i}(1,2) + D_{j,i}(2,1)^* )
274 ! does not affect the results in any case, since H is spin-box
275 ! hermitian.
276 !
277-! The wave function coefficients c_{i,sigma}(ie,k) only satisfy
278+! The wave function coefficients c_{j,sigma}(ie,k) only satisfy
279 ! "TR"-related
280 ! symmetry relations if the state is collinear (nspin = 2). In this case
281-! c_{i,sigma}(ie,k) = c_{i,sigma}(ie, -k)^*
282+! c_{j,sigma}(ie,k) = c_{j,sigma}(ie, -k)^*
283 !
284 ! For a non-collinear state, the above relation does not hold
285-! generically. Hence the
286-! full BZ must be used to compute the DM.
287-
288+! generically. Hence the full BZ must be used to compute the DM.
289
290- Dk = dcmplx(0.0_dp,0.0_dp)
291- Ek = dcmplx(0.0_dp,0.0_dp)
292+ Dk = dcmplx(0.0_dp,0.0_dp)
293+ Ek = dcmplx(0.0_dp,0.0_dp)
294
295 BNode = 0
296 iie = 0
297@@ -384,31 +367,26 @@
298 endif
299 #ifdef MPI
300 call MPI_Bcast(caux(1,1),2*nuotot,MPI_double_complex,BNode,
301- . MPI_Comm_World,MPIerror)
302+ & MPI_Comm_World,MPIerror)
303 #endif
304- ee = qo(ie,ik) * eo(ie,ik)
305+ ee = qe * eo(ie,ik)
306 do iuo = 1,nuo
307 call LocalToGlobalOrb(iuo,Node,Nodes,iio)
308 do juo = 1,nuotot
309-CC RC
310-C In the JF 3.1.1 version the following matrix elements are
311-C calculated by means of dconj(caux(1,juo)) instead of caux(1,juo)
312-C I will leave it as it is. maybe it needs further revision...
313-
314 !------- 1,1 -----------------------------------------------------------
315- cicj = caux(1,iio) * dconjg(caux(1,juo))
316+ cicj = dconjg(caux(1,juo)) * caux(1,iio)
317 Dk(1,juo,1,iuo) = Dk(1,juo,1,iuo) + qe * cicj
318 Ek(1,juo,1,iuo) = Ek(1,juo,1,iuo) + ee * cicj
319 !------- 2,2 -----------------------------------------------------------
320- cicj = caux(2,iio) * dconjg(caux(2,juo))
321+ cicj = dconjg(caux(2,juo)) * caux(2,iio)
322 Dk(2,juo,2,iuo) = Dk(2,juo,2,iuo) + qe * cicj
323 Ek(2,juo,2,iuo) = Ek(2,juo,2,iuo) + ee * cicj
324 !------- 2,1 -----------------------------------------------------------
325- cicj = caux(1,iio) * dconjg(caux(2,juo))
326+ cicj = dconjg(caux(2,juo)) * caux(1,iio)
327 Dk(1,juo,2,iuo) = Dk(1,juo,2,iuo) + qe * cicj
328 Ek(1,juo,2,iuo) = Ek(1,juo,2,iuo) + ee * cicj
329 !------- 1,2 -----------------------------------------------------------
330- cicj = caux(2,iio) * dconjg(caux(1,juo))
331+ cicj = dconjg(caux(1,juo)) * caux(2,iio)
332 Dk(2,juo,1,iuo) = Dk(2,juo,1,iuo) + qe * cicj
333 Ek(2,juo,1,iuo) = Ek(2,juo,1,iuo) + ee * cicj
334 enddo
335@@ -424,7 +402,7 @@
336 ! Add contribution to density matrices of unit-cell orbitals
337 ! ------------------------------------------------------
338 ! | D_{j,i}(1) D_{j,i}(3)-i D_{j,i}(4) |
339-! | D_{i,j}(3)+i D_{i,j}(4) D_{j,i}(2) |
340+! | D_{j,i}(3)+i D_{j,i}(4) D_{j,i}(2) |
341 ! ------------------------------------------------------
342
343 do iuo = 1,nuo
344@@ -433,74 +411,37 @@
345 jo = listd(ind)
346 juo = indxuo(jo)
347 kxij = kpoint(1,ik) * xij(1,ind) +
348- . kpoint(2,ik) * xij(2,ind) +
349- . kpoint(3,ik) * xij(3,ind)
350-! JFR: the sign in the phase of H_ji is reflected in the DM
351+ & kpoint(2,ik) * xij(2,ind) +
352+ & kpoint(3,ik) * xij(3,ind)
353 kphs = cdexp(dcmplx(0.0_dp,-1.0_dp)*kxij)
354
355-CC RC
356-C In the JF's version D11, D22, etc are not time-reversal averaged
357-C I will leave as it is here but maybe it will need major revision
358-
359-! Average k and -k solutions because time-reversal symetry
360-! D11 = 0.5_dp * (Dkc(1,juo,1,iuo) * kphs
361-! . + dconjg(Dkc(1,juo,1,iuo) * kphs))
362-!
363-! D22 = 0.5_dp * (Dkc(2,juo,2,iuo) * kphs
364-! . + dconjg(Dkc(2,juo,2,iuo) * kphs))
365-!
366-! D12 = 0.5_dp * (Dkc(1,juo,2,iuo) * kphs
367-! . + dconjg(Dkc(2,juo,1,iuo) * kphs))
368-!
369-! D21 = 0.5_dp * (Dkc(2,juo,1,iuo) * kphs
370-! . + dconjg(Dkc(1,juo,2,iuo) * kphs))
371-
372 D11 = Dk(1,juo,1,iuo) * kphs
373 D22 = Dk(2,juo,2,iuo) * kphs
374 D12 = Dk(1,juo,2,iuo) * kphs
375 D21 = Dk(2,juo,1,iuo) * kphs
376-
377
378 ! Make DM Spin-box hermitian
379 D12 = 0.5_dp * (D12 + dconjg(D21))
380- D21 = dconjg(D12)
381+ !D21 = dconjg(D12)
382
383 Dnew(ind,1) = Dnew(ind,1) + dreal(D11)
384 Dnew(ind,2) = Dnew(ind,2) + dreal(D22)
385 Dnew(ind,3) = Dnew(ind,3) + dreal(D12)
386- Dnew(ind,4) = Dnew(ind,4) + dimag(D21)
387-
388-CC RC
389-C In the JF's version D11, D22, etc are not time-reversal averaged
390-C I will leave as it is here but maybe it will need major revision
391-
392-! Average k and -k solutions because time-reversal symetry
393-! D11 = 0.5_dp * (Ekc(1,juo,1,iuo) * kphs
394-! . + dconjg(Ekc(1,juo,1,iuo) * kphs))
395-!
396-! D22 = 0.5_dp * (Ekc(2,juo,2,iuo) * kphs
397-! . + dconjg(Ekc(2,juo,2,iuo) * kphs))
398-!
399-! D12 = 0.5_dp * (Ekc(1,juo,2,iuo) * kphs
400-! . + dconjg(Ekc(2,juo,1,iuo) * kphs))
401-!
402-! D21 = 0.5_dp * (Ekc(2,juo,1,iuo) * kphs
403-! . + dconjg(Ekc(1,juo,2,iuo) * kphs))
404+ Dnew(ind,4) = Dnew(ind,4) - dimag(D12)
405
406 D11 = Ek(1,juo,1,iuo) * kphs
407 D22 = Ek(2,juo,2,iuo) * kphs
408 D12 = Ek(1,juo,2,iuo) * kphs
409 D21 = Ek(2,juo,1,iuo) * kphs
410-
411-
412-! Make DM Spin-box hermitian
413+
414+! Make EDM Spin-box hermitian
415 D12 = 0.5_dp * (D12 + dconjg(D21))
416- D21 = dconjg(D12)
417+ !D21 = dconjg(D12)
418
419 Enew(ind,1) = Enew(ind,1) + dreal(D11)
420 Enew(ind,2) = Enew(ind,2) + dreal(D22)
421- Enew(ind,3) = Enew(ind,3) + dreal(D12)
422- Enew(ind,4) = Enew(ind,4) + dimag(D21)
423+ Enew(ind,3) = Enew(ind,3) + dreal(D12)
424+ Enew(ind,4) = Enew(ind,4) - dimag(D12)
425
426 enddo
427 enddo
428@@ -508,27 +449,9 @@
429
430 1001 continue
431
432-! write(160+node,*)'ITERATION'
433-! write(170+node,*)'ITERATION'
434-! do iuo = 1,nuo
435-! do j = 1,numd(iuo)
436-! ind = listdptr(iuo) + j
437-! jo = listd(ind)
438-! juo = indxuo(jo)
439-! write(160+node,'(3i5,4f15.9)')iuo,juo,jo,Dnew(ind,1:4)
440-! write(170+node,'(3i5,4f15.9)')iuo,juo,jo,
441-! . (Dnew(ind,1)+Dnew(ind,2))*0.5,
442-! . (Dnew(ind,1)-Dnew(ind,2))*0.5,Dnew(ind,3:4)
443-! enddo
444-! enddo
445-!
446-! call die('maslyuk')
447-!***********************************************************************
448 #ifdef DEBUG
449 call write_debug( ' POS diag2k' )
450 #endif
451
452- return
453 end subroutine diag2k
454-!***********************************************************************
455
456
457=== modified file 'version.info'
458--- version.info 2017-12-21 15:51:22 +0000
459+++ version.info 2018-01-05 08:40:43 +0000
460@@ -1,3 +1,3 @@
461-siesta-4.1--829--spin-fix-2
462+siesta-4.1--829--spin-fix-2-nicpa-1
463
464

Subscribers

People subscribed via source and target branches