Octopus
species.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!! Copyright (C) 2023-2024 N. Tancogne-Dejean
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19#include "global.h"
20
21module species_oct_m
22 use debug_oct_m
23 use global_oct_m
24 use iso_c_binding
25 use, intrinsic :: iso_fortran_env
29 use string_oct_m
30
31 implicit none
32
33 private
34 public :: &
35 species_t, &
41 operator(==), &
43
44 interface operator(==)
45 module procedure species_is_same_species
46 end interface operator(==)
47
48
49 integer, public, parameter :: LABEL_LEN=15
50
52 type, abstract :: species_t
53 private
54 integer :: index
55
56 character(len=LABEL_LEN) :: label
57 real(real64) :: z
58 real(real64) :: z_val
59 ! !< minus the core charge in the case of the pseudopotentials
60 real(real64) :: mass
61 real(real64) :: vdw_radius
62
63 logical, public :: has_density
64
65 character(len=MAX_PATH_LEN) :: filename
66
67 ! Derived classes need to access these quantities
68 integer, public :: niwfs
69 integer, allocatable, public :: iwf_l(:, :), iwf_m(:, :), iwf_i(:, :), iwf_n(:, :)
70 real(real64), allocatable, public :: iwf_j(:)
71
72 integer :: hubbard_l
73 real(real64) :: hubbard_U
74 real(real64) :: hubbard_j
75 real(real64) :: hubbard_alpha
76
77 contains
78 procedure(species_is_local), deferred :: is_local
79 procedure(species_get_iwf_radius), deferred :: get_iwf_radius
80 procedure(species_iwf_fix_qn), deferred :: iwf_fix_qn
81 procedure(species_init_potential), deferred :: init_potential
82 procedure(species_build), deferred :: build
83! procedure, deferred :: get_average_energy !< G=0 contribution to the energy
84! procedure, deferred :: get_average_stress !< G=0 contribution to the stress tensor
85 procedure(species_debug), deferred :: debug
86 procedure :: get_label => species_label
87 procedure :: get_index => species_index
88 procedure :: get_zval => species_zval
89 procedure :: get_z => species_z
90 procedure :: get_vdw_radius => species_vdw_radius
91 procedure :: get_mass => species_mass
92 procedure :: get_hubbard_l => species_hubbard_l
93 procedure :: get_hubbard_u => species_hubbard_u
94 procedure :: get_hubbard_j => species_hubbard_j
95 procedure :: get_hubbard_alpha => species_hubbard_alpha
96 procedure :: set_hubbard_l => species_set_hubbard_l
97 procedure :: set_hubbard_u => species_set_hubbard_u
98 procedure :: set_hubbard_j => species_set_hubbard_j
99 procedure :: set_hubbard_alpha => species_set_hubbard_alpha
100 procedure :: get_niwfs => species_niwfs
101 procedure :: get_iwf_ilm => species_iwf_ilm
102 procedure :: get_iwf_n => species_iwf_n
103 procedure :: get_iwf_j => species_iwf_j
104 procedure :: set_mass => species_set_mass
105 procedure :: set_vdw_radius => species_set_vdw_radius
106 procedure :: set_z => species_set_z
107 procedure :: set_zval => species_set_zval
108 procedure :: get_filename => species_filename
109 procedure :: set_filename => species_set_filename
110 procedure :: is_full => species_is_full
111 procedure :: is_ps => species_is_ps
112 procedure :: is_ps_with_nlcc => species_is_ps_with_nlcc
113 procedure :: represents_real_atom => species_represents_real_atom
114 procedure :: is_user_defined => species_user_defined
115 end type species_t
120 class(species_t), pointer :: s
121 end type
122
123 abstract interface
124 ! ---------------------------------------------------------
125 logical function species_is_local(spec) result(is_local)
126 import species_t
127 class(species_t), intent(in) :: spec
128 end function species_is_local
129
130 ! ---------------------------------------------------------
131 real(real64) function species_get_iwf_radius(spec, ii, is, threshold) result(radius)
132 import real64
133 import species_t
134 class(species_t), intent(in) :: spec
135 integer, intent(in) :: ii
136 integer, intent(in) :: is
137 real(real64), optional, intent(in) :: threshold
138 end function species_get_iwf_radius
140 ! ---------------------------------------------------------
141 subroutine species_iwf_fix_qn(spec, namespace, nspin, dim)
142 import species_t
143 import namespace_t
144 class(species_t), intent(inout) :: spec
145 type(namespace_t), intent(in) :: namespace
146 integer, intent(in) :: nspin
147 integer, intent(in) :: dim
148 end subroutine species_iwf_fix_qn
150 ! ---------------------------------------------------------
151 subroutine species_init_potential(this, namespace, grid_cutoff, filter)
154 import real64
155 class(species_t), intent(inout) :: this
156 type(namespace_t), intent(in) :: namespace
157 real(real64), intent(in) :: grid_cutoff
158 integer, intent(in) :: filter
159 end subroutine species_init_potential
161 ! ---------------------------------------------------------
162 subroutine species_build(spec, namespace, ispin, dim, print_info)
165 class(species_t), intent(inout) :: spec
166 type(namespace_t), intent(in) :: namespace
167 integer, intent(in) :: ispin
168 integer, intent(in) :: dim
169 logical, optional, intent(in) :: print_info
170 end subroutine species_build
171
172 ! ---------------------------------------------------------
173 subroutine species_debug(spec, dir, namespace, gmax)
176 import real64
177 class(species_t), intent(in) :: spec
178 character(len=*), intent(in) :: dir
179 type(namespace_t), intent(in) :: namespace
180 real(real64), intent(in) :: gmax
181 end subroutine species_debug
183 end interface
186 integer, public, parameter :: species_libxc_c_index = 10000
188contains
190 ! ---------------------------------------------------------
195 ! ---------------------------------------------------------
196 subroutine species_init(this, label, index)
197 class(species_t), intent(inout) :: this
198 character(len=*), intent(in) :: label
199 integer, intent(in) :: index
201 push_sub(species_init)
203 this%label = trim(label)
204 this%index = index
206 this%z = -m_one
207 this%z_val = -m_one
208 this%mass = -m_one
209 this%vdw_radius = -m_one
210 this%has_density = .false.
211 this%niwfs = -1
212 this%hubbard_l = -1
213 this%hubbard_U = m_zero
214 this%hubbard_j = m_zero
215 this%hubbard_alpha = m_zero
216 this%filename = ""
217
218 pop_sub(species_init)
219 end subroutine species_init
221 ! ---------------------------------------------------------
223 integer pure function species_closed_shell_size(min_niwfs) result(size)
224 integer, intent(in) :: min_niwfs
225
226 integer :: nn
227
228 size = 0
229 do nn = 1, min_niwfs
230 if (size >= min_niwfs) exit
231 size = size + nn**2
232 end do
233
234 end function species_closed_shell_size
235
236 ! ---------------------------------------------------------
237 character(len=LABEL_LEN) pure function species_label(species)
238 class(species_t), intent(in) :: species
239 species_label = trim(species%label)
240 end function species_label
241
242 ! ---------------------------------------------------------
243 character(len=2) pure function species_label_short(species)
244 class(species_t), intent(in) :: species
245 species_label_short = species%label(1:2)
247
248 ! ---------------------------------------------------------
249 integer pure function species_index(species)
250 class(species_t), intent(in) :: species
251 species_index = species%index
252 end function species_index
253
254 ! ---------------------------------------------------------
255 real(real64) pure function species_zval(species)
256 class(species_t), intent(in) :: species
257 species_zval = species%z_val
258 end function species_zval
259
260 ! ---------------------------------------------------------
261 pure subroutine species_set_zval(species, zval)
262 class(species_t), intent(inout) :: species
263 real(real64), intent(in) :: zval
264 species%z_val = zval
265 end subroutine species_set_zval
266
267 ! ---------------------------------------------------------
268 real(real64) pure function species_z(species)
269 class(species_t), intent(in) :: species
270 species_z = species%z
271 end function species_z
272
273 ! ---------------------------------------------------------
274 pure subroutine species_set_z(species, z)
275 class(species_t), intent(inout) :: species
276 real(real64), intent(in) :: z
277 species%z = z
278 end subroutine species_set_z
279
280 ! ---------------------------------------------------------
281 real(real64) pure function species_mass(species)
282 class(species_t), intent(in) :: species
283 species_mass = species%mass
284 end function species_mass
285
286 ! ---------------------------------------------------------
287 pure subroutine species_set_mass(species, mass)
288 class(species_t), intent(inout) :: species
289 real(real64), intent(in) :: mass
290 species%mass = mass
291 end subroutine species_set_mass
292
293 ! ---------------------------------------------------------
294 real(real64) pure function species_vdw_radius(species)
295 class(species_t), intent(in) :: species
296 species_vdw_radius = species%vdw_radius
297 end function species_vdw_radius
298
299 ! ---------------------------------------------------------
300 pure subroutine species_set_vdw_radius(species, radius)
301 class(species_t), intent(inout) :: species
302 real(real64), intent(in) :: radius
303 species%vdw_radius = radius
304 end subroutine species_set_vdw_radius
305
306 ! ---------------------------------------------------------
307 integer pure function species_niwfs(species)
308 class(species_t), intent(in) :: species
309 species_niwfs = species%niwfs
310 end function species_niwfs
311
312 ! ---------------------------------------------------------
313 integer pure function species_hubbard_l(species)
314 class(species_t), intent(in) :: species
315 species_hubbard_l = species%hubbard_l
316 end function species_hubbard_l
317
318 ! ---------------------------------------------------------
319 real(real64) pure function species_hubbard_u(species)
320 class(species_t), intent(in) :: species
321 species_hubbard_u = species%hubbard_u
322 end function species_hubbard_u
323
324 ! ---------------------------------------------------------
325 real(real64) pure function species_hubbard_j(species)
326 class(species_t), intent(in) :: species
327 species_hubbard_j = species%hubbard_j
328 end function species_hubbard_j
329
330 ! ---------------------------------------------------------
331 real(real64) pure function species_hubbard_alpha(species)
332 class(species_t), intent(in) :: species
333 species_hubbard_alpha = species%hubbard_alpha
334 end function species_hubbard_alpha
335
336 ! ---------------------------------------------------------
337 pure subroutine species_set_hubbard_l(species, hubbard_l)
338 class(species_t), intent(inout) :: species
339 integer, intent(in) :: hubbard_l
340 species%hubbard_l = hubbard_l
341 end subroutine species_set_hubbard_l
342
343 ! ---------------------------------------------------------
344 pure subroutine species_set_hubbard_u(species, hubbard_u)
345 class(species_t), intent(inout) :: species
346 real(real64), intent(in) :: hubbard_u
347 species%hubbard_u = hubbard_u
348 end subroutine species_set_hubbard_u
349
350 ! ---------------------------------------------------------
351 pure subroutine species_set_hubbard_j(species, hubbard_j)
352 class(species_t), intent(inout) :: species
353 real(real64), intent(in) :: hubbard_j
354 species%hubbard_j = hubbard_j
355 end subroutine species_set_hubbard_j
357 ! ---------------------------------------------------------
358 pure subroutine species_set_hubbard_alpha(species, hubbard_alpha)
359 class(species_t), intent(inout) :: species
360 real(real64), intent(in) :: hubbard_alpha
361 species%hubbard_alpha = hubbard_alpha
362 end subroutine species_set_hubbard_alpha
364 ! ---------------------------------------------------------
365 character(len=200) pure function species_filename(species)
366 class(species_t), intent(in) :: species
367 species_filename = trim(species%filename)
368 end function species_filename
370 ! ---------------------------------------------------------
371 pure subroutine species_set_filename(species, filename)
372 class(species_t), intent(inout) :: species
373 character(len=*), intent(in) :: filename
374 species%filename = trim(filename)
375 end subroutine species_set_filename
377 ! ---------------------------------------------------------
378 pure subroutine species_iwf_ilm(species, j, is, i, l, m)
379 class(species_t), intent(in) :: species
380 integer, intent(in) :: j, is
381 integer, intent(out) :: i, l, m
383 i = species%iwf_i(j, is)
384 l = species%iwf_l(j, is)
385 m = species%iwf_m(j, is)
386 end subroutine species_iwf_ilm
387
388 ! ---------------------------------------------------------
389 pure subroutine species_iwf_n(species, j, is, n)
390 class(species_t), intent(in) :: species
391 integer, intent(in) :: j, is
392 integer, intent(out) :: n
393
394 n = species%iwf_n(j, is)
395 end subroutine species_iwf_n
396
397 ! ---------------------------------------------------------
398 pure subroutine species_iwf_j(species, iorb, j)
399 class(species_t), intent(in) :: species
400 integer, intent(in) :: iorb
401 real(real64), intent(out) :: j
403 j = species%iwf_j(iorb)
404 end subroutine species_iwf_j
405
406 ! ---------------------------------------------------------
407 subroutine species_end(species)
408 class(species_t), intent(inout) :: species
409
410 push_sub(species_end)
411
412 safe_deallocate_a(species%iwf_n)
413 safe_deallocate_a(species%iwf_l)
414 safe_deallocate_a(species%iwf_m)
415 safe_deallocate_a(species%iwf_i)
416 safe_deallocate_a(species%iwf_j)
417
418 pop_sub(species_end)
419 end subroutine species_end
420 ! ---------------------------------------------------------
421
422
423!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
424! Private procedures
425
426 ! ---------------------------------------------------------
427 function get_symbol(label) result(c_symbol)
428 character(len=*), intent(in) :: label
429 character(kind=c_char) :: c_symbol(label_len+1)
430
431 character(len=LABEL_LEN) :: symbol
433 integer :: ilend
434
435 ! use only the first part of the label to determine the element
436 do ilend = 1, len(label)
437 if (iachar(label(ilend:ilend)) >= iachar('a') .and. iachar(label(ilend:ilend)) <= iachar('z')) cycle
438 if (iachar(label(ilend:ilend)) >= iachar('A') .and. iachar(label(ilend:ilend)) <= iachar('Z')) cycle
439 exit
440 end do
441 ilend = ilend - 1
442
443 symbol = label(1:ilend)
444
445 c_symbol = c_null_char
446 c_symbol(1:c_str_len(symbol)) = string_f_to_c(symbol)
447 end function get_symbol
448
449 ! ---------------------------------------------------------
450 logical function species_is_same_species(spec1, spec2) result(same)
451 class(species_t), intent(in) :: spec1, spec2
452
454
455 same = same_type_as(spec1, spec2)
456 if(abs(spec1%z - spec2%z) > m_epsilon) same = .false.
457 if(abs(spec1%z_val - spec2%z_val) > m_epsilon) same = .false.
458 if(abs(spec1%mass - spec2%mass) > m_epsilon) same = .false.
459
461 end function species_is_same_species
462
463 ! ---------------------------------------------------------
465 logical pure function species_is_full(this)
466 class(species_t), intent(in) :: this
467
468 species_is_full = .false.
469 end function species_is_full
470
471 ! ---------------------------------------------------------
473 logical pure function species_is_ps(this)
474 class(species_t), intent(in) :: this
475
476 species_is_ps = .false.
477 end function species_is_ps
478
479 ! ---------------------------------------------------------
481 logical pure function species_is_ps_with_nlcc(this)
482 class(species_t), intent(in) :: this
483
485 end function species_is_ps_with_nlcc
486
487 ! ---------------------------------------------------------
489 logical pure function species_represents_real_atom(spec)
490 class(species_t), intent(in) :: spec
491
494
495 ! ---------------------------------------------------------
497 logical pure function species_user_defined(spec)
498 class(species_t), intent(in) :: spec
499
500 species_user_defined = .false.
501 end function species_user_defined
503
504end module species_oct_m
505
506!! Local Variables:
507!! mode: f90
508!! coding: utf-8
509!! End:
real(real64) pure function species_zval(species)
Definition: species.F90:351
pure subroutine species_set_hubbard_l(species, hubbard_l)
Definition: species.F90:433
pure subroutine species_set_z(species, z)
Definition: species.F90:370
logical pure function species_user_defined(spec)
Is the species user-defined or not.
Definition: species.F90:593
real(real64) pure function species_hubbard_u(species)
Definition: species.F90:415
character(len=2) pure function, public species_label_short(species)
Definition: species.F90:339
pure subroutine species_set_hubbard_j(species, hubbard_j)
Definition: species.F90:447
integer pure function species_niwfs(species)
Definition: species.F90:403
pure subroutine species_set_filename(species, filename)
Definition: species.F90:467
pure subroutine species_set_zval(species, zval)
Definition: species.F90:357
subroutine, public species_end(species)
Definition: species.F90:503
subroutine, public species_init(this, label, index)
Initializes a species object. This should be the first routine to be called (before species_read and ...
Definition: species.F90:292
logical pure function species_represents_real_atom(spec)
Is the species representing an atomic species or not.
Definition: species.F90:585
logical pure function species_is_ps_with_nlcc(this)
Is the species a pseudopotential derived class or not with nlcc.
Definition: species.F90:577
pure subroutine species_set_hubbard_alpha(species, hubbard_alpha)
Definition: species.F90:454
integer, parameter, public species_libxc_c_index
Must be the same as LIBXC_C_INDEX in xc_functional_oct_m.
Definition: species.F90:281
character(len=200) pure function species_filename(species)
Definition: species.F90:461
pure subroutine species_iwf_ilm(species, j, is, i, l, m)
Definition: species.F90:474
logical function species_is_same_species(spec1, spec2)
Definition: species.F90:546
integer pure function species_index(species)
Definition: species.F90:345
integer, parameter, public label_len
Definition: species.F90:144
logical pure function species_is_ps(this)
Is the species a pseudopotential derived class or not.
Definition: species.F90:569
real(real64) pure function species_vdw_radius(species)
Definition: species.F90:390
pure subroutine species_iwf_n(species, j, is, n)
Definition: species.F90:485
pure subroutine species_set_hubbard_u(species, hubbard_u)
Definition: species.F90:440
real(real64) pure function species_hubbard_alpha(species)
Definition: species.F90:427
real(real64) pure function species_z(species)
Definition: species.F90:364
pure subroutine species_iwf_j(species, iorb, j)
Definition: species.F90:494
character(len=label_len) pure function species_label(species)
Definition: species.F90:333
character(kind=c_char) function, dimension(label_len+1), public get_symbol(label)
Definition: species.F90:523
logical pure function species_is_full(this)
Is the species an all-electron derived class or not.
Definition: species.F90:561
pure subroutine species_set_vdw_radius(species, radius)
Definition: species.F90:396
integer pure function species_hubbard_l(species)
Definition: species.F90:409
pure subroutine species_set_mass(species, mass)
Definition: species.F90:383
real(real64) pure function species_hubbard_j(species)
Definition: species.F90:421
integer pure function, public species_closed_shell_size(min_niwfs)
find size of closed shell for hydrogenic atom with size at least min_niwfs
Definition: species.F90:319
real(real64) pure function species_mass(species)
Definition: species.F90:377
An abstract class for species. Derived classes include jellium, all electron, and pseudopotential spe...
Definition: species.F90:147
Needed for having an array of pointers See for instance https:
Definition: species.F90:214