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
185 integer, private, parameter :: libxc_c_index = 1000
187contains
189 ! ---------------------------------------------------------
194 ! ---------------------------------------------------------
195 subroutine species_init(this, label, index)
196 class(species_t), intent(inout) :: this
197 character(len=*), intent(in) :: label
198 integer, intent(in) :: index
200 push_sub(species_init)
202 this%label = trim(label)
203 this%index = index
205 this%z = -m_one
206 this%z_val = -m_one
207 this%mass = -m_one
208 this%vdw_radius = -m_one
209 this%has_density = .false.
210 this%niwfs = -1
211 this%hubbard_l = -1
212 this%hubbard_U = m_zero
213 this%hubbard_j = m_zero
214 this%hubbard_alpha = m_zero
215 this%filename = ""
216
217 pop_sub(species_init)
218 end subroutine species_init
219
220 ! ---------------------------------------------------------
222 integer pure function species_closed_shell_size(min_niwfs) result(size)
223 integer, intent(in) :: min_niwfs
224
225 integer :: nn
227 size = 0
228 do nn = 1, min_niwfs
229 if (size >= min_niwfs) exit
230 size = size + nn**2
231 end do
232
233 end function species_closed_shell_size
234
235 ! ---------------------------------------------------------
236 character(len=LABEL_LEN) pure function species_label(species)
237 class(species_t), intent(in) :: species
238 species_label = trim(species%label)
239 end function species_label
240
241 ! ---------------------------------------------------------
242 character(len=2) pure function species_label_short(species)
243 class(species_t), intent(in) :: species
244 species_label_short = species%label(1:2)
245 end function species_label_short
247 ! ---------------------------------------------------------
248 integer pure function species_index(species)
249 class(species_t), intent(in) :: species
250 species_index = species%index
251 end function species_index
252
253 ! ---------------------------------------------------------
254 real(real64) pure function species_zval(species)
255 class(species_t), intent(in) :: species
256 species_zval = species%z_val
257 end function species_zval
258
259 ! ---------------------------------------------------------
260 pure subroutine species_set_zval(species, zval)
261 class(species_t), intent(inout) :: species
262 real(real64), intent(in) :: zval
263 species%z_val = zval
264 end subroutine species_set_zval
265
266 ! ---------------------------------------------------------
267 real(real64) pure function species_z(species)
268 class(species_t), intent(in) :: species
269 species_z = species%z
270 end function species_z
271
272 ! ---------------------------------------------------------
273 pure subroutine species_set_z(species, z)
274 class(species_t), intent(inout) :: species
275 real(real64), intent(in) :: z
276 species%z = z
277 end subroutine species_set_z
278
279 ! ---------------------------------------------------------
280 real(real64) pure function species_mass(species)
281 class(species_t), intent(in) :: species
282 species_mass = species%mass
283 end function species_mass
284
285 ! ---------------------------------------------------------
286 pure subroutine species_set_mass(species, mass)
287 class(species_t), intent(inout) :: species
288 real(real64), intent(in) :: mass
289 species%mass = mass
290 end subroutine species_set_mass
291
292 ! ---------------------------------------------------------
293 real(real64) pure function species_vdw_radius(species)
294 class(species_t), intent(in) :: species
295 species_vdw_radius = species%vdw_radius
296 end function species_vdw_radius
297
298 ! ---------------------------------------------------------
299 pure subroutine species_set_vdw_radius(species, radius)
300 class(species_t), intent(inout) :: species
301 real(real64), intent(in) :: radius
302 species%vdw_radius = radius
303 end subroutine species_set_vdw_radius
304
305 ! ---------------------------------------------------------
306 integer pure function species_niwfs(species)
307 class(species_t), intent(in) :: species
308 species_niwfs = species%niwfs
309 end function species_niwfs
310
311 ! ---------------------------------------------------------
312 integer pure function species_hubbard_l(species)
313 class(species_t), intent(in) :: species
314 species_hubbard_l = species%hubbard_l
315 end function species_hubbard_l
316
317 ! ---------------------------------------------------------
318 real(real64) pure function species_hubbard_u(species)
319 class(species_t), intent(in) :: species
320 species_hubbard_u = species%hubbard_u
321 end function species_hubbard_u
322
323 ! ---------------------------------------------------------
324 real(real64) pure function species_hubbard_j(species)
325 class(species_t), intent(in) :: species
326 species_hubbard_j = species%hubbard_j
327 end function species_hubbard_j
328
329 ! ---------------------------------------------------------
330 real(real64) pure function species_hubbard_alpha(species)
331 class(species_t), intent(in) :: species
332 species_hubbard_alpha = species%hubbard_alpha
333 end function species_hubbard_alpha
334
335 ! ---------------------------------------------------------
336 pure subroutine species_set_hubbard_l(species, hubbard_l)
337 class(species_t), intent(inout) :: species
338 integer, intent(in) :: hubbard_l
339 species%hubbard_l = hubbard_l
340 end subroutine species_set_hubbard_l
341
342 ! ---------------------------------------------------------
343 pure subroutine species_set_hubbard_u(species, hubbard_u)
344 class(species_t), intent(inout) :: species
345 real(real64), intent(in) :: hubbard_u
346 species%hubbard_u = hubbard_u
347 end subroutine species_set_hubbard_u
348
349 ! ---------------------------------------------------------
350 pure subroutine species_set_hubbard_j(species, hubbard_j)
351 class(species_t), intent(inout) :: species
352 real(real64), intent(in) :: hubbard_j
353 species%hubbard_j = hubbard_j
354 end subroutine species_set_hubbard_j
356 ! ---------------------------------------------------------
357 pure subroutine species_set_hubbard_alpha(species, hubbard_alpha)
358 class(species_t), intent(inout) :: species
359 real(real64), intent(in) :: hubbard_alpha
360 species%hubbard_alpha = hubbard_alpha
361 end subroutine species_set_hubbard_alpha
363 ! ---------------------------------------------------------
364 character(len=200) pure function species_filename(species)
365 class(species_t), intent(in) :: species
366 species_filename = trim(species%filename)
367 end function species_filename
369 ! ---------------------------------------------------------
370 pure subroutine species_set_filename(species, filename)
371 class(species_t), intent(inout) :: species
372 character(len=*), intent(in) :: filename
373 species%filename = trim(filename)
374 end subroutine species_set_filename
376 ! ---------------------------------------------------------
377 pure subroutine species_iwf_ilm(species, j, is, i, l, m)
378 class(species_t), intent(in) :: species
379 integer, intent(in) :: j, is
380 integer, intent(out) :: i, l, m
382 i = species%iwf_i(j, is)
383 l = species%iwf_l(j, is)
384 m = species%iwf_m(j, is)
385 end subroutine species_iwf_ilm
386
387 ! ---------------------------------------------------------
388 pure subroutine species_iwf_n(species, j, is, n)
389 class(species_t), intent(in) :: species
390 integer, intent(in) :: j, is
391 integer, intent(out) :: n
392
393 n = species%iwf_n(j, is)
394 end subroutine species_iwf_n
395
396 ! ---------------------------------------------------------
397 pure subroutine species_iwf_j(species, iorb, j)
398 class(species_t), intent(in) :: species
399 integer, intent(in) :: iorb
400 real(real64), intent(out) :: j
402 j = species%iwf_j(iorb)
403 end subroutine species_iwf_j
404
405 ! ---------------------------------------------------------
406 subroutine species_end(species)
407 class(species_t), intent(inout) :: species
408
409 push_sub(species_end)
410
411 safe_deallocate_a(species%iwf_n)
412 safe_deallocate_a(species%iwf_l)
413 safe_deallocate_a(species%iwf_m)
414 safe_deallocate_a(species%iwf_i)
415 safe_deallocate_a(species%iwf_j)
416
417 pop_sub(species_end)
418 end subroutine species_end
419 ! ---------------------------------------------------------
420
421
422!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
423! Private procedures
424
425 ! ---------------------------------------------------------
426 function get_symbol(label) result(c_symbol)
427 character(len=*), intent(in) :: label
428 character(kind=c_char) :: c_symbol(label_len+1)
429
430 character(len=LABEL_LEN) :: symbol
432 integer :: ilend
433
434 ! use only the first part of the label to determine the element
435 do ilend = 1, len(label)
436 if (iachar(label(ilend:ilend)) >= iachar('a') .and. iachar(label(ilend:ilend)) <= iachar('z')) cycle
437 if (iachar(label(ilend:ilend)) >= iachar('A') .and. iachar(label(ilend:ilend)) <= iachar('Z')) cycle
438 exit
439 end do
440 ilend = ilend - 1
441
442 symbol = label(1:ilend)
443
444 c_symbol = c_null_char
445 c_symbol(1:c_str_len(symbol)) = string_f_to_c(symbol)
446 end function get_symbol
447
448 ! ---------------------------------------------------------
449 logical function species_is_same_species(spec1, spec2) result(same)
450 class(species_t), intent(in) :: spec1, spec2
451
453
454 same = same_type_as(spec1, spec2)
455 if(abs(spec1%z - spec2%z) > m_epsilon) same = .false.
456 if(abs(spec1%z_val - spec2%z_val) > m_epsilon) same = .false.
457 if(abs(spec1%mass - spec2%mass) > m_epsilon) same = .false.
458
460 end function species_is_same_species
461
462 ! ---------------------------------------------------------
464 logical pure function species_is_full(this)
465 class(species_t), intent(in) :: this
466
467 species_is_full = .false.
468 end function species_is_full
469
470 ! ---------------------------------------------------------
472 logical pure function species_is_ps(this)
473 class(species_t), intent(in) :: this
474
475 species_is_ps = .false.
476 end function species_is_ps
477
478 ! ---------------------------------------------------------
480 logical pure function species_is_ps_with_nlcc(this)
481 class(species_t), intent(in) :: this
482
484 end function species_is_ps_with_nlcc
485
486 ! ---------------------------------------------------------
488 logical pure function species_represents_real_atom(spec)
489 class(species_t), intent(in) :: spec
490
493
494 ! ---------------------------------------------------------
496 logical pure function species_user_defined(spec)
497 class(species_t), intent(in) :: spec
498
499 species_user_defined = .false.
500 end function species_user_defined
502
503end module species_oct_m
504
505!! Local Variables:
506!! mode: f90
507!! coding: utf-8
508!! End:
real(real64) pure function species_zval(species)
Definition: species.F90:350
integer, parameter, private libxc_c_index
Definition: species.F90:280
pure subroutine species_set_hubbard_l(species, hubbard_l)
Definition: species.F90:432
pure subroutine species_set_z(species, z)
Definition: species.F90:369
logical pure function species_user_defined(spec)
Is the species user-defined or not.
Definition: species.F90:592
real(real64) pure function species_hubbard_u(species)
Definition: species.F90:414
character(len=2) pure function, public species_label_short(species)
Definition: species.F90:338
pure subroutine species_set_hubbard_j(species, hubbard_j)
Definition: species.F90:446
integer pure function species_niwfs(species)
Definition: species.F90:402
pure subroutine species_set_filename(species, filename)
Definition: species.F90:466
pure subroutine species_set_zval(species, zval)
Definition: species.F90:356
subroutine, public species_end(species)
Definition: species.F90:502
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:291
logical pure function species_represents_real_atom(spec)
Is the species representing an atomic species or not.
Definition: species.F90:584
logical pure function species_is_ps_with_nlcc(this)
Is the species a pseudopotential derived class or not with nlcc.
Definition: species.F90:576
pure subroutine species_set_hubbard_alpha(species, hubbard_alpha)
Definition: species.F90:453
character(len=200) pure function species_filename(species)
Definition: species.F90:460
pure subroutine species_iwf_ilm(species, j, is, i, l, m)
Definition: species.F90:473
logical function species_is_same_species(spec1, spec2)
Definition: species.F90:545
integer pure function species_index(species)
Definition: species.F90:344
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:568
real(real64) pure function species_vdw_radius(species)
Definition: species.F90:389
pure subroutine species_iwf_n(species, j, is, n)
Definition: species.F90:484
pure subroutine species_set_hubbard_u(species, hubbard_u)
Definition: species.F90:439
real(real64) pure function species_hubbard_alpha(species)
Definition: species.F90:426
real(real64) pure function species_z(species)
Definition: species.F90:363
pure subroutine species_iwf_j(species, iorb, j)
Definition: species.F90:493
character(len=label_len) pure function species_label(species)
Definition: species.F90:332
character(kind=c_char) function, dimension(label_len+1), public get_symbol(label)
Definition: species.F90:522
logical pure function species_is_full(this)
Is the species an all-electron derived class or not.
Definition: species.F90:560
pure subroutine species_set_vdw_radius(species, radius)
Definition: species.F90:395
integer pure function species_hubbard_l(species)
Definition: species.F90:408
pure subroutine species_set_mass(species, mass)
Definition: species.F90:382
real(real64) pure function species_hubbard_j(species)
Definition: species.F90:420
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:318
real(real64) pure function species_mass(species)
Definition: species.F90:376
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