Octopus
lda_u_io.F90
Go to the documentation of this file.
1!! Copyright (C) 2016 N. Tancogne-Dejean
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18#include "global.h"
19
20module lda_u_io_oct_m
22 use debug_oct_m
23 use global_oct_m
24 use io_oct_m
26 use ions_oct_m
28 use lda_u_oct_m
29 use mesh_oct_m
32 use mpi_oct_m
36 use parser_oct_m
39 use space_oct_m
43 use unit_oct_m
45
46 implicit none
47
48 private
49
50 public :: &
57 lda_u_load, &
59
60contains
61
63 subroutine lda_u_write_occupation_matrices(dir, this, st, namespace)
64 type(lda_u_t), intent(in) :: this
65 character(len=*), intent(in) :: dir
66 type(states_elec_t), intent(in) :: st
67 type(namespace_t), intent(in) :: namespace
68
69 integer :: iunit, ios, ispin, im, imp, ios2, inn
70 type(orbitalset_t), pointer :: os, os2
71
73
74 if (st%system_grp%is_root()) then ! this the absolute master writes
75 iunit = io_open(trim(dir) // "/occ_matrices", namespace, action='write')
76 write(iunit,'(a)') ' Occupation matrices '
77
78 do ios = 1, this%norbsets
79 os => this%orbsets(ios)
80
81 do ispin = 1,st%d%nspin
82 write(iunit,'(a, i4, a, i4)') ' Orbital set ', ios, ' spin ', ispin
83
84 do im = 1, os%norbs
85 write(iunit,'(1x)',advance='no')
86
87 if (states_are_real(st)) then
88 do imp = 1, os%norbs-1
89 write(iunit,'(f14.8)', advance='no') this%dn(im, imp, ispin, ios)
90 end do
91 write(iunit,'(f14.8)') this%dn(im, os%norbs, ispin, ios)
92 else
93 do imp = 1, os%norbs-1
94 write(iunit,'(f14.8,f14.8)', advance='no') this%zn(im, imp, ispin, ios)
95 end do
96 write(iunit,'(f14.8,f14.8)') this%zn(im, os%norbs, ispin, ios)
97 end if
98 end do
99 end do !ispin
100 end do !iatom
101 call io_close(iunit)
102
103 if (this%level == dft_u_acbn0) then
104 iunit = io_open(trim(dir) // "/renorm_occ_matrices", namespace, action='write')
105 write(iunit,'(a)') ' Renormalized occupation matrices '
106
107 do ios = 1, this%norbsets
108 os => this%orbsets(ios)
109 do ispin = 1, st%d%nspin
110 write(iunit,'(a, i4, a, i4)') ' Orbital set ', ios, ' spin ', ispin
111 do im = 1, os%norbs
112
113 write(iunit,'(1x)',advance='no')
114
115 if (states_are_real(st)) then
116 do imp = 1, os%norbs-1
117 write(iunit,'(f14.8)', advance='no') this%dn_alt(im, imp, ispin, ios)
118 end do
119 write(iunit,'(f14.8)') this%dn_alt(im, os%norbs, ispin, ios)
120 else
121 do imp = 1, os%norbs-1
122 write(iunit,'(f14.8,f14.8)', advance='no') this%zn_alt(im, imp, ispin, ios)
123 end do
124 write(iunit,'(f14.8,f14.8)') this%zn_alt(im, os%norbs, ispin, ios)
125 end if
126 end do
127 end do !ispin
128 end do !iatom
129 call io_close(iunit)
130 end if
131
132 if(this%intersite) then
133 iunit = io_open(trim(dir) // "/intersite_occ_matrices", namespace, action='write')
134 write(iunit,'(a)') ' Intersite occupation matrices '
135 do ios = 1, this%norbsets
136 os => this%orbsets(ios)
137 do ispin = 1, st%d%nspin
138 write(iunit,'(a, i4, a, i4)') ' Orbital set ', ios, ' spin ', ispin
139 do inn = 1, os%nneighbors
140 write(iunit,'(a, i4)') ' Neighbour ', inn
141 ios2 = os%map_os(inn)
142 os2 => this%orbsets(ios2)
143 do im = 1, os%norbs
144
145 write(iunit,'(1x)',advance='no')
146
147 if (states_are_real(st)) then
148 do imp = 1, os2%norbs - 1
149 write(iunit,'(f14.8)', advance='no') this%dn_ij(im, imp, ispin, ios, inn)
150 end do
151 write(iunit,'(f14.8)') this%dn_ij(im, os2%norbs, ispin, ios, inn)
152 else
153 do imp = 1, os2%norbs - 1
154 write(iunit,'(f14.8,f14.8)', advance='no') this%zn_ij(im, imp, ispin, ios, inn)
155 end do
156 write(iunit,'(f14.8,f14.8)') this%zn_ij(im, os2%norbs, ispin, ios, inn)
157 end if
158 end do
159 end do !inn
160 end do !ispin
161 end do ! ios
162 call io_close(iunit)
163 end if
164
165 end if
166
169
170 !---------------------------------------------------------
171 subroutine lda_u_write_effectiveu(dir, this, st, namespace)
172 type(lda_u_t), intent(in) :: this
173 character(len=*), intent(in) :: dir
174 type(states_elec_t), intent(in) :: st
175 type(namespace_t), intent(in) :: namespace
176
177 integer :: iunit, ios
178
179 push_sub(lda_u_write_effectiveu)
180
181 if (st%system_grp%is_root()) then ! this the absolute master writes
182 iunit = io_open(trim(dir) // "/effectiveU", namespace, action='write')
183 call lda_u_write_u(this, iunit)
184
185 write(iunit, '(a,a,a)') 'Hubbard U [', trim(units_abbrev(units_out%energy)),']:'
186 write(iunit,'(a,6x,14x,a)') ' Orbital', 'U'
187 do ios = 1, this%norbsets
188 if (.not. this%basisfromstates) then
189 if (this%orbsets(ios)%ndim == 1 .or. this%basis%combine_j_orbitals) then
190 if (this%orbsets(ios)%nn /= 0) then
191 write(iunit,'(i4,a10, 2x, i1, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
192 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
193 units_from_atomic(units_out%energy, this%orbsets(ios)%Ubar)
194 else
195 write(iunit,'(i4,a10, 3x, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
196 l_notation(this%orbsets(ios)%ll), &
197 units_from_atomic(units_out%energy, this%orbsets(ios)%Ubar)
198 end if
199 else
200 if (this%orbsets(ios)%nn /= 0) then
201 write(iunit,'(i4,a10, 2x, i1, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
202 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
203 int(m_two*(this%orbsets(ios)%jj)), '/2', &
204 units_from_atomic(units_out%energy, this%orbsets(ios)%Ubar)
205 else
206 write(iunit,'(i4,a10, 3x, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
207 l_notation(this%orbsets(ios)%ll), &
208 int(m_two*(this%orbsets(ios)%jj)), '/2', &
209 units_from_atomic(units_out%energy, this%orbsets(ios)%Ubar)
210 end if
211 end if
212 else
213 write(iunit,'(i4,a10, 3x, f15.6)') ios, 'states', units_from_atomic(units_out%energy, this%orbsets(ios)%Ubar)
214 end if
215 end do
216
217
218 write(iunit, '(a,a,a)') 'Hund J [', trim(units_abbrev(units_out%energy)),']:'
219 write(iunit,'(a,6x,14x,a)') ' Orbital', 'J'
220 do ios = 1, this%norbsets
221 if (.not. this%basisfromstates) then
222 if (this%orbsets(ios)%ndim == 1 .or. this%basis%combine_j_orbitals) then
223 if (this%orbsets(ios)%nn /= 0) then
224 write(iunit,'(i4,a10, 2x, i1, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
225 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
226 units_from_atomic(units_out%energy, this%orbsets(ios)%Jbar)
227 else
228 write(iunit,'(i4,a10, 3x, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
229 l_notation(this%orbsets(ios)%ll), &
230 units_from_atomic(units_out%energy, this%orbsets(ios)%Jbar)
231 end if
232 else
233 if (this%orbsets(ios)%nn /= 0) then
234 write(iunit,'(i4,a10, 2x, i1, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
235 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
236 int(m_two*(this%orbsets(ios)%jj)), '/2', &
237 units_from_atomic(units_out%energy, this%orbsets(ios)%Jbar)
238 else
239 write(iunit,'(i4,a10, 3x, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
240 l_notation(this%orbsets(ios)%ll), &
241 int(m_two*(this%orbsets(ios)%jj)), '/2', &
242 units_from_atomic(units_out%energy, this%orbsets(ios)%Jbar)
243 end if
244 end if
245 else
246 write(iunit,'(i4,a10, f15.6)') ios, 'states', units_from_atomic(units_out%energy, this%orbsets(ios)%Jbar)
247 end if
248 end do
249
250 call io_close(iunit)
251 end if
252
254 end subroutine lda_u_write_effectiveu
255
256 !---------------------------------------------------------
257 subroutine lda_u_write_kanamoriu(dir, st, this, namespace)
258 type(lda_u_t), intent(in) :: this
259 type(states_elec_t), intent(in) :: st
260 character(len=*), intent(in) :: dir
261 type(namespace_t), intent(in) :: namespace
262
263 integer :: iunit, ios
264 real(real64), allocatable :: kanamori(:,:)
265
267
268 if (st%system_grp%is_root()) then ! this the absolute master writes
269 safe_allocate(kanamori(1:3,1:this%norbsets))
270
271 call compute_acbno_u_kanamori(this, st, kanamori)
272
273 iunit = io_open(trim(dir) // "/kanamoriU", namespace, action='write')
274
275 write(iunit, '(a,a,a)') 'Intraorbital U [', trim(units_abbrev(units_out%energy)),']:'
276 write(iunit,'(a,6x,14x,a)') ' Orbital', 'U'
277 do ios = 1, this%norbsets
278 if (.not. this%basisfromstates) then
279 if (this%orbsets(ios)%ndim == 1 .or. this%basis%combine_j_orbitals) then
280 if (this%orbsets(ios)%nn /= 0) then
281 write(iunit,'(i4,a10, 2x, i1, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
282 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
283 units_from_atomic(units_out%energy, kanamori(1,ios))
284 else
285 write(iunit,'(i4,a10, 3x, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
286 l_notation(this%orbsets(ios)%ll), &
287 units_from_atomic(units_out%energy, kanamori(1,ios))
288 end if
289 else
290 if (this%orbsets(ios)%nn /= 0) then
291 write(iunit,'(i4,a10, 2x, i1, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
292 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
293 int(m_two*(this%orbsets(ios)%jj)), '/2', &
294 units_from_atomic(units_out%energy, kanamori(1,ios))
295 else
296 write(iunit,'(i4,a10, 3x, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
297 l_notation(this%orbsets(ios)%ll), &
298 int(m_two*(this%orbsets(ios)%jj)), '/2', &
299 units_from_atomic(units_out%energy, kanamori(1,ios))
300 end if
301 end if
302 else
303 write(iunit,'(i4,a10, 3x, f15.6)') ios, 'states', units_from_atomic(units_out%energy, kanamori(1,ios))
304 end if
305 end do
306
307
308 write(iunit, '(a,a,a)') 'Interorbital Up [', trim(units_abbrev(units_out%energy)),']:'
309 write(iunit,'(a,6x,14x,a)') ' Orbital', 'Up'
310 do ios = 1, this%norbsets
311 if (.not. this%basisfromstates) then
312 if (this%orbsets(ios)%ndim == 1 .or. this%basis%combine_j_orbitals) then
313 if (this%orbsets(ios)%nn /= 0) then
314 write(iunit,'(i4,a10, 2x, i1, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
315 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
316 units_from_atomic(units_out%energy, kanamori(2,ios))
317 else
318 write(iunit,'(i4,a10, 3x, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
319 l_notation(this%orbsets(ios)%ll), &
320 units_from_atomic(units_out%energy, kanamori(2,ios))
321 end if
322 else
323 if (this%orbsets(ios)%nn /= 0) then
324 write(iunit,'(i4,a10, 2x, i1, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
325 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
326 int(m_two*(this%orbsets(ios)%jj)), '/2', &
327 units_from_atomic(units_out%energy, kanamori(2,ios))
328 else
329 write(iunit,'(i4,a10, 3x, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
330 l_notation(this%orbsets(ios)%ll), &
331 int(m_two*(this%orbsets(ios)%jj)), '/2', &
332 units_from_atomic(units_out%energy, kanamori(2,ios))
333 end if
334 end if
335 else
336 write(iunit,'(i4,a10, f15.6)') ios, 'states', units_from_atomic(units_out%energy, kanamori(2,ios))
337 end if
338 end do
339
340 write(iunit, '(a,a,a)') 'Hund J [', trim(units_abbrev(units_out%energy)),']:'
341 write(iunit,'(a,6x,14x,a)') ' Orbital', 'J'
342 do ios = 1, this%norbsets
343 if (.not. this%basisfromstates) then
344 if (this%orbsets(ios)%ndim == 1 .or. this%basis%combine_j_orbitals) then
345 if (this%orbsets(ios)%nn /= 0) then
346 write(iunit,'(i4,a10, 2x, i1, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
347 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
348 units_from_atomic(units_out%energy, kanamori(3,ios))
349 else
350 write(iunit,'(i4,a10, 3x, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
351 l_notation(this%orbsets(ios)%ll), &
352 units_from_atomic(units_out%energy, kanamori(3,ios))
353 end if
354 else
355 if (this%orbsets(ios)%nn /= 0) then
356 write(iunit,'(i4,a10, 2x, i1, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
357 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
358 int(m_two*(this%orbsets(ios)%jj)), '/2', &
359 units_from_atomic(units_out%energy, kanamori(3,ios))
360 else
361 write(iunit,'(i4,a10, 3x, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
362 l_notation(this%orbsets(ios)%ll), &
363 int(m_two*(this%orbsets(ios)%jj)), '/2', &
364 units_from_atomic(units_out%energy, kanamori(3,ios))
365 end if
366 end if
367 else
368 write(iunit,'(i4,a10, f15.6)') ios, 'states', units_from_atomic(units_out%energy, kanamori(3,ios))
369 end if
370 end do
371
372
373 call io_close(iunit)
374
375 safe_deallocate_a(kanamori)
376 end if
377
378
379 pop_sub(lda_u_write_kanamoriu)
380 end subroutine lda_u_write_kanamoriu
381
382
383
384 !---------------------------------------------------------
385 subroutine lda_u_write_magnetization(dir, this, ions, mesh, st, namespace)
386 type(lda_u_t), intent(in) :: this
387 character(len=*), intent(in) :: dir
388 type(ions_t), intent(in) :: ions
389 class(mesh_t), intent(in) :: mesh
390 type(states_elec_t), intent(in) :: st
391 type(namespace_t), intent(in) :: namespace
392
393 integer :: iunit, ia, ios, im
394 real(real64), allocatable :: mm(:,:)
395
396 if (.not. st%system_grp%is_root()) return
397
399
400 call io_mkdir(dir, namespace)
401 iunit = io_open(trim(dir)//"/magnetization.xsf", namespace, action='write', position='asis')
402
403 if (this%nspins > 1) then
404 safe_allocate(mm(1:3, 1:ions%natoms))
405 mm = m_zero
406 !We compute the magnetization vector for each orbital set
407 do ios = 1, this%norbsets
408 ia = this%orbsets(ios)%iatom
409 do im = 1, this%orbsets(ios)%norbs
410 if (states_are_real(st)) then
411 mm(3, ia) = mm(3, ia) + this%dn(im,im,1,ios) - this%dn(im,im,2,ios)
412 else
413 mm(3, ia) = mm(3, ia) + real(this%zn(im,im,1,ios) - this%zn(im,im,2,ios), real64)
414 !Spinors
415 if (this%nspins /= this%spin_channels) then
416 mm(1, ia) = mm(1, ia) + 2*real(this%zn(im,im,3,ios), real64)
417 mm(2, ia) = mm(2, ia) - 2*aimag(this%zn(im,im,3,ios))
418 end if
419 end if
420 end do !im
421 end do ! ios
422 call write_xsf_geometry(iunit, ions%space, ions%latt, ions%pos, ions%atom, mesh, forces = mm)
423 safe_deallocate_a(mm)
424 end if
425
426 call io_close(iunit)
427
429 end subroutine lda_u_write_magnetization
430
431 !---------------------------------------------------------
432 subroutine lda_u_write_u(this, iunit, namespace)
433 type(lda_u_t), intent(in) :: this
434 integer, optional, intent(in) :: iunit
435 type(namespace_t), optional, intent(in) :: namespace
436
437 integer :: ios
438
439 push_sub(lda_u_write_u)
440
441 write(message(1), '(a,a,a)') 'Effective Hubbard U [', trim(units_abbrev(units_out%energy)),']:'
442 write(message(2),'(a,6x,14x,a)') ' Orbital', 'U'
443 call messages_info(2, iunit=iunit, namespace=namespace)
444
445 do ios = 1, this%norbsets
446 if (.not. this%basisfromstates) then
447 if (this%orbsets(ios)%ndim == 1 .or. this%basis%combine_j_orbitals) then
448 if (this%orbsets(ios)%nn /= 0) then
449 write(message(1),'(i4,a10, 2x, i1, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
450 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
451 units_from_atomic(units_out%energy, this%orbsets(ios)%Ueff)
452 else
453 write(message(1),'(i4,a10, 3x, a1, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
454 l_notation(this%orbsets(ios)%ll), &
455 units_from_atomic(units_out%energy, this%orbsets(ios)%Ueff)
456 end if
457 else
458 if (this%orbsets(ios)%nn /= 0) then
459 write(message(1),'(i4,a10, 2x, i1, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
460 this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
461 int(m_two*(this%orbsets(ios)%jj)), '/2', &
462 units_from_atomic(units_out%energy, this%orbsets(ios)%Ueff)
463 else
464 write(message(1),'(i4,a10, 3x, a1, i1, a2, f15.6)') ios, trim(this%orbsets(ios)%spec%get_label()), &
465 l_notation(this%orbsets(ios)%ll), &
466 int(m_two*(this%orbsets(ios)%jj)), '/2', &
467 units_from_atomic(units_out%energy, this%orbsets(ios)%Ueff)
468 end if
469 end if
470 else
471 write(message(1),'(i4,a10, f15.6)') ios, 'states', units_from_atomic(units_out%energy, this%orbsets(ios)%Ueff)
472 end if
473 call messages_info(1, iunit=iunit, namespace=namespace)
474 end do
475
476 pop_sub(lda_u_write_u)
477 end subroutine lda_u_write_u
478
479 !---------------------------------------------------------
480 subroutine lda_u_write_v(this, iunit, namespace)
481 type(lda_u_t), intent(in) :: this
482 integer, optional, intent(in) :: iunit
483 type(namespace_t), optional, intent(in) :: namespace
484
485 integer :: ios, icopies, ios2
486
487 if (.not. this%intersite) return
488
489 push_sub(lda_u_write_v)
490
491 write(message(1), '(a,a,a)') 'Effective intersite V [', trim(units_abbrev(units_out%energy)),']:'
492 write(message(2),'(a,14x,a)') ' Orbital', 'V'
493 call messages_info(2, iunit=iunit, namespace=namespace)
494
495 do ios = 1, this%norbsets
496 do icopies = 1, this%orbsets(ios)%nneighbors
497 ios2 = this%orbsets(ios)%map_os(icopies)
498 if (.not.this%basisfromstates) then
499 if (this%orbsets(ios)%ndim == 1 .or. this%basis%combine_j_orbitals) then
500 if (this%orbsets(ios)%nn /= 0) then
501 write(message(1),'(i4,a10, 2x, i1, a1, i4, 1x, i1, a1, f7.3, f15.6)') ios, &
502 trim(this%orbsets(ios)%spec%get_label()), this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), ios2, &
503 this%orbsets(ios2)%nn, l_notation(this%orbsets(ios2)%ll), &
504 units_from_atomic(units_out%length, this%orbsets(ios)%V_ij(icopies,3+1)), &
505 units_from_atomic(units_out%energy, this%orbsets(ios)%V_ij(icopies,0))
506 call messages_info(1, iunit=iunit, namespace=namespace)
507 else
508 write(message(1),'(i4,a10, 3x, a1, i4, 1x, a1, f7.3, f15.6)') ios, &
509 trim(this%orbsets(ios)%spec%get_label()), l_notation(this%orbsets(ios)%ll), ios2, &
510 l_notation(this%orbsets(ios2)%ll), units_from_atomic(units_out%length, this%orbsets(ios)%V_ij(icopies,3+1)), &
511 units_from_atomic(units_out%energy, this%orbsets(ios)%V_ij(icopies,0))
512 call messages_info(1, iunit=iunit, namespace=namespace)
513 end if
514 else
515 if (this%orbsets(ios)%nn /= 0) then
516 write(message(1),'(i4,a10, 2x, i1, a1, i1, a2, i4, f7.3, f15.6)') ios, &
517 trim(this%orbsets(ios)%spec%get_label()), this%orbsets(ios)%nn, l_notation(this%orbsets(ios)%ll), &
518 int(m_two*(this%orbsets(ios)%jj)), '/2', ios2, &
519 units_from_atomic(units_out%length, this%orbsets(ios)%V_ij(icopies,3+1)), &
520 units_from_atomic(units_out%energy, this%orbsets(ios)%V_ij(icopies,0))
521 call messages_info(1, iunit=iunit, namespace=namespace)
522 else
523 write(message(1),'(i4,a10, 3x, a1, i1, a2, i4, f7.3, f15.6)') ios, &
524 trim(this%orbsets(ios)%spec%get_label()), l_notation(this%orbsets(ios)%ll), &
525 int(m_two*(this%orbsets(ios)%jj)), '/2', ios2, &
526 units_from_atomic(units_out%length, this%orbsets(ios)%V_ij(icopies,3+1)), &
527 units_from_atomic(units_out%energy, this%orbsets(ios)%V_ij(icopies,0))
528 call messages_info(1, iunit=iunit, namespace=namespace)
529 end if ! this%orbsets(ios)%nn /= 0
530 end if ! this%orbsets(ios)%ndim == 1
531 else
532 write(message(1),'(i4,a10, i4, f7.3, f15.6)') ios, 'states', ios2, &
533 units_from_atomic(units_out%length, this%orbsets(ios)%V_ij(icopies,3+1)), &
534 units_from_atomic(units_out%energy, this%orbsets(ios)%V_ij(icopies,0))
535 call messages_info(1, iunit=iunit, namespace=namespace)
536 end if
537
538 end do ! icopies
539 end do ! ios
540
541 pop_sub(lda_u_write_v)
542 end subroutine lda_u_write_v
543
544
545 ! ---------------------------------------------------------
546 subroutine lda_u_dump(restart, namespace, this, st, mesh, ierr)
547 type(restart_t), intent(in) :: restart
548 type(namespace_t), intent(in) :: namespace
549 type(lda_u_t), intent(in) :: this
550 type(states_elec_t), intent(in) :: st
551 class(mesh_t), intent(in) :: mesh
552 integer, intent(out) :: ierr
553
554 integer :: err, occsize, ios, ncount
555 real(real64), allocatable :: ueff(:), docc(:), veff(:)
556 complex(real64), allocatable :: zocc(:)
557
558 push_sub(lda_u_dump)
559
560 ierr = 0
561
562 if (restart%skip()) then
563 pop_sub(lda_u_dump)
564 return
565 end if
566
567 message(1) = "Debug: Writing DFT+U restart."
568 call messages_info(1, namespace=namespace, debug_only=.true.)
569
570 occsize = this%maxnorbs*this%maxnorbs*this%nspins*this%norbsets
571 if (this%level == dft_u_acbn0) then
572 occsize = occsize*2
573 if (this%intersite) then
574 occsize = occsize + 2*this%maxnorbs*this%maxnorbs*this%nspins*this%norbsets*this%maxneighbors
575 end if
576 end if
577
578
579 if (states_are_real(st)) then
580 safe_allocate(docc(1:occsize))
581 docc = m_zero
582 call dlda_u_get_occupations(this, docc)
583 call restart%write_binary("lda_u_occ", occsize, docc, err)
584 if (err /= 0) ierr = ierr + 1
585 safe_deallocate_a(docc)
586 else
587 safe_allocate(zocc(1:occsize))
588 zocc = m_zero
589 call zlda_u_get_occupations(this, zocc)
590 call restart%write_binary("lda_u_occ", occsize, zocc, err)
591 if (err /= 0) ierr = ierr + 1
592 safe_deallocate_a(zocc)
593 end if
594
595
596 if (this%level == dft_u_acbn0) then
597 safe_allocate(ueff(1:this%norbsets))
598 ueff = m_zero
599 call lda_u_get_effectiveu(this, ueff(:))
600 call restart%write_binary("lda_u_Ueff", this%norbsets, ueff, err)
601 safe_deallocate_a(ueff)
602 if (err /= 0) ierr = ierr + 1
603
604 if (this%intersite .and. this%maxneighbors > 0) then
605 ncount = 0
606 do ios = 1, this%norbsets
607 ncount = ncount + this%orbsets(ios)%nneighbors
608 end do
609 safe_allocate(veff(1:ncount))
610 call lda_u_get_effectivev(this, veff(:))
611 call restart%write_binary("lda_u_Veff", ncount, veff, err)
612 safe_deallocate_a(veff)
613 if (err /= 0) ierr = ierr + 1
614 end if
615 end if
616
617 call lda_u_dump_coulomb_integrals(this, restart, st, mesh, ierr)
618
619 message(1) = "Debug: Writing DFT+U restart done."
620 call messages_info(1, namespace=namespace, debug_only=.true.)
621
622 pop_sub(lda_u_dump)
623 end subroutine lda_u_dump
624
625
626 ! ---------------------------------------------------------
627 subroutine lda_u_load(restart, this, st, dftu_energy, ierr, occ_only, u_only)
628 type(restart_t), intent(in) :: restart
629 type(lda_u_t), intent(inout) :: this
630 type(states_elec_t), intent(in) :: st
631 real(real64), intent(out) :: dftu_energy
632 integer, intent(out) :: ierr
633 logical, optional, intent(in) :: occ_only
634 logical, optional, intent(in) :: u_only
635
636 integer :: err, occsize, ncount, ios
637 real(real64), allocatable :: ueff(:), docc(:), veff(:)
638 complex(real64), allocatable :: zocc(:)
639
640 push_sub(lda_u_load)
642 ierr = 0
643
644 if (restart%skip()) then
645 pop_sub(lda_u_load)
646 return
647 end if
648
649 message(1) = "Debug: Reading DFT+U restart."
650 call messages_info(1, debug_only=.true.)
651
652 !We have to read the effective U first, as we call lda_u_uptade_potential latter
653 if (this%level == dft_u_acbn0 .and. .not. optional_default(occ_only, .false.)) then
654 safe_allocate(ueff(1:this%norbsets))
655 call restart%read_binary("lda_u_Ueff", this%norbsets, ueff, err)
656 if (err /= 0) then
657 ierr = ierr + 1
658 ueff = m_zero
659 end if
660 call lda_u_set_effectiveu(this, ueff)
661 safe_deallocate_a(ueff)
662
663 if (this%intersite .and. this%maxneighbors > 0) then
664 ncount = 0
665 do ios = 1, this%norbsets
666 ncount = ncount + this%orbsets(ios)%nneighbors
667 end do
668 safe_allocate(veff(1:ncount))
669 call restart%read_binary("lda_u_Veff", ncount, veff, err)
670 if (err /= 0) then
671 ierr = ierr + 1
672 veff = m_zero
673 end if
674 call lda_u_set_effectivev(this, veff)
675 safe_deallocate_a(veff)
676 end if
677 end if
678
679
680 if (.not. optional_default(u_only, .false.)) then
681 occsize = this%maxnorbs*this%maxnorbs*this%nspins*this%norbsets
682 if (this%level == dft_u_acbn0) then
683 occsize = occsize*2
684 if (this%intersite) then
685 occsize = occsize + 2*this%maxnorbs*this%maxnorbs*this%nspins*this%norbsets*this%maxneighbors
686 end if
687 end if
688
689
690 if (states_are_real(st)) then
691 safe_allocate(docc(1:occsize))
692 call restart%read_binary("lda_u_occ", occsize, docc, err)
693 if (err /= 0) then
694 ierr = ierr + 1
695 docc = m_zero
696 end if
697 call dlda_u_set_occupations(this, docc)
698 safe_deallocate_a(docc)
699 else
700 safe_allocate(zocc(1:occsize))
701 call restart%read_binary("lda_u_occ", occsize, zocc, err)
702 if (err /= 0) then
703 ierr = ierr + 1
704 zocc = m_z0
705 end if
706 call zlda_u_set_occupations(this, zocc)
707 safe_deallocate_a(zocc)
708 end if
709 end if
710
711 if (states_are_real(st)) then
712 call dcompute_dftu_energy(this, dftu_energy, st)
713 call dlda_u_update_potential(this, st)
714 else
715 call zcompute_dftu_energy(this, dftu_energy, st)
716 call zlda_u_update_potential(this, st)
717 end if
718
719 message(1) = "Debug: Reading DFT+U restart done."
720 call messages_info(1, debug_only=.true.)
721
722 pop_sub(lda_u_load)
723 end subroutine lda_u_load
724
725 ! ---------------------------------------------------------
726 subroutine lda_u_dump_coulomb_integrals(this, restart, st, mesh, ierr)
727 type(lda_u_t), intent(in) :: this
728 type(restart_t), intent(in) :: restart
729 type(states_elec_t), intent(in) :: st
730 class(mesh_t), intent(in) :: mesh
731 integer, intent(out) :: ierr
732
733 integer :: coulomb_int_file, idim1, idim2, err
734 integer :: ios, im, imp, impp, imppp
735 character(len=256) :: lines(3)
736 logical :: complex_coulomb_integrals
737
739
740 ierr = 0
741
742 if (restart%skip() .or. this%level == dft_u_empirical) then
744 return
745 end if
746
747 message(1) = "Debug: Writing Coulomb integrals restart."
748 call messages_info(1, debug_only=.true.)
749
750 complex_coulomb_integrals = .false.
751 do ios = 1, this%norbsets
752 if (this%orbsets(ios)%ndim > 1) complex_coulomb_integrals = .true.
753 end do
754
755 coulomb_int_file = restart%open('coulomb_integrals')
756 ! sanity checks. Example file 'coulomb_int_file':
757 ! norb= 2
758 ! dim= 1
759 ! checksum= xxxxxxxxxxx
760 write(lines(1), '(a20,i21)') "norb=", this%norbsets
761 write(lines(2), '(a20,i21)') "dim=", st%d%dim
762 write(lines(3), '(a20,i21)') "checksum=", mesh%idx%checksum
763 call restart%write(coulomb_int_file, lines, 3, err)
764 if (err /= 0) ierr = ierr - 2
765
766 ios_cycle: do ios = 1, this%norbsets
767 do im = 1, this%orbsets(ios)%norbs
768 do imp = 1, this%orbsets(ios)%norbs
769 do impp = 1, this%orbsets(ios)%norbs
770 do imppp = 1, this%orbsets(ios)%norbs
771 if(.not. complex_coulomb_integrals) then
772 write(lines(1), '(i4,i4,i4,i4,i4,e20.12)') ios, im, imp, impp, imppp, this%coulomb(im, imp, impp, imppp, ios)
773 else
774 do idim1 = 1, st%d%dim
775 do idim2 = 1, st%d%dim
776 write(lines(1), '(i4,i4,i4,i4,i4,i4,i4,2e20.12)') ios, im, imp, impp, imppp, idim1, idim2, &
777 real(this%zcoulomb(im, imp, impp, imppp, idim1, idim2, ios), real64) , &
778 aimag(this%zcoulomb(im, imp, impp, imppp, idim1, idim2, ios))
779 end do
780 end do
781 end if
782 call restart%write(coulomb_int_file, lines, 1, err)
783 if (err /=0) then
784 ierr = ierr - 2**2
785 exit ios_cycle
786 end if
787 end do
788 end do
789 end do
790 end do
791 end do ios_cycle
792 call restart%close(coulomb_int_file)
793
794 message(1) = "Debug: Writing Coulomb integrals restart done."
795 call messages_info(1, debug_only=.true.)
796
798 end subroutine lda_u_dump_coulomb_integrals
799
800end module lda_u_io_oct_m
character(len=1), dimension(0:3), parameter, public l_notation
real(real64), parameter, public m_two
Definition: global.F90:202
real(real64), parameter, public m_zero
Definition: global.F90:200
complex(real64), parameter, public m_z0
Definition: global.F90:210
subroutine, public write_xsf_geometry(iunit, space, latt, pos, atoms, mesh, forces, index)
for format specification see: http:
Definition: io.F90:116
subroutine, public io_close(iunit, grp)
Definition: io.F90:467
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:361
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:402
subroutine, public lda_u_write_occupation_matrices(dir, this, st, namespace)
Prints the occupation matrices at the end of the scf calculation.
Definition: lda_u_io.F90:159
subroutine, public lda_u_write_kanamoriu(dir, st, this, namespace)
Definition: lda_u_io.F90:353
subroutine, public lda_u_dump(restart, namespace, this, st, mesh, ierr)
Definition: lda_u_io.F90:642
subroutine, public lda_u_write_u(this, iunit, namespace)
Definition: lda_u_io.F90:528
subroutine, public lda_u_load(restart, this, st, dftu_energy, ierr, occ_only, u_only)
Definition: lda_u_io.F90:723
subroutine lda_u_dump_coulomb_integrals(this, restart, st, mesh, ierr)
Definition: lda_u_io.F90:822
subroutine, public lda_u_write_effectiveu(dir, this, st, namespace)
Definition: lda_u_io.F90:267
subroutine, public lda_u_write_magnetization(dir, this, ions, mesh, st, namespace)
Definition: lda_u_io.F90:481
subroutine, public lda_u_write_v(this, iunit, namespace)
Definition: lda_u_io.F90:576
subroutine, public lda_u_get_effectiveu(this, Ueff)
Definition: lda_u.F90:1011
subroutine, public lda_u_set_effectiveu(this, Ueff)
Definition: lda_u.F90:995
subroutine, public dlda_u_get_occupations(this, occ)
Definition: lda_u.F90:3575
subroutine, public zcompute_dftu_energy(this, energy, st)
This routine computes the value of the double counting term in the DFT+U energy.
Definition: lda_u.F90:4281
integer, parameter, public dft_u_empirical
Definition: lda_u.F90:205
subroutine, public compute_acbno_u_kanamori(this, st, kanamori)
Definition: lda_u.F90:958
subroutine, public zlda_u_update_potential(this, st)
This routine computes the potential that, once multiplied by the projector Pmm' and summed over m and...
Definition: lda_u.F90:4355
subroutine, public dlda_u_set_occupations(this, occ)
Definition: lda_u.F90:3518
subroutine, public lda_u_get_effectivev(this, Veff)
Definition: lda_u.F90:1045
subroutine, public lda_u_set_effectivev(this, Veff)
Definition: lda_u.F90:1027
integer, parameter, public dft_u_acbn0
Definition: lda_u.F90:205
subroutine, public zlda_u_get_occupations(this, occ)
Definition: lda_u.F90:5596
subroutine, public dcompute_dftu_energy(this, energy, st)
This routine computes the value of the double counting term in the DFT+U energy.
Definition: lda_u.F90:2311
subroutine, public dlda_u_update_potential(this, st)
This routine computes the potential that, once multiplied by the projector Pmm' and summed over m and...
Definition: lda_u.F90:2385
subroutine, public zlda_u_set_occupations(this, occ)
Definition: lda_u.F90:5539
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
pure logical function, public states_are_real(st)
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
character(len=20) pure function, public units_abbrev(this)
Definition: unit.F90:225
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
Class to describe DFT+U parameters.
Definition: lda_u.F90:218
Describes mesh distribution to nodes.
Definition: mesh.F90:187
The states_elec_t class contains all electronic wave functions.
int true(void)