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, intrinsic :: iso_fortran_env
28
29 implicit none
30
31 private
32 public :: &
33 species_t, &
39 operator(==), &
41
42 interface operator(==)
43 module procedure species_is_same_species
44 end interface operator(==)
45
46
47 integer, public, parameter :: LABEL_LEN=15
48
50 type, abstract :: species_t
51 private
52 integer :: index
53
54 character(len=LABEL_LEN) :: label
55 real(real64) :: z
56 real(real64) :: z_val
57 ! !< minus the core charge in the case of the pseudopotentials
58 real(real64) :: mass
59 real(real64) :: vdw_radius
60
61 logical, public :: has_density
62
63 character(len=MAX_PATH_LEN) :: filename
64
65 ! Derived classes need to access these quantities
66 integer, public :: niwfs
67 integer, allocatable, public :: iwf_l(:, :), iwf_m(:, :), iwf_i(:, :), iwf_n(:, :)
68 real(real64), allocatable, public :: iwf_j(:)
69
70 integer :: hubbard_l
71 real(real64) :: hubbard_U
72 real(real64) :: hubbard_j
73 real(real64) :: hubbard_alpha
74
75 contains
76 procedure(species_is_local), deferred :: is_local
77 procedure(species_get_iwf_radius), deferred :: get_iwf_radius
78 procedure(species_iwf_fix_qn), deferred :: iwf_fix_qn
79 procedure(species_init_potential), deferred :: init_potential
80 procedure(species_build), deferred :: build
81! procedure, deferred :: get_average_energy !< G=0 contribution to the energy
82! procedure, deferred :: get_average_stress !< G=0 contribution to the stress tensor
83 procedure(species_debug), deferred :: debug
84 procedure :: get_label => species_label
85 procedure :: get_index => species_index
86 procedure :: get_zval => species_zval
87 procedure :: get_z => species_z
88 procedure :: get_vdw_radius => species_vdw_radius
89 procedure :: get_mass => species_mass
90 procedure :: get_hubbard_l => species_hubbard_l
91 procedure :: get_hubbard_u => species_hubbard_u
92 procedure :: get_hubbard_j => species_hubbard_j
93 procedure :: get_hubbard_alpha => species_hubbard_alpha
94 procedure :: set_hubbard_l => species_set_hubbard_l
95 procedure :: set_hubbard_u => species_set_hubbard_u
96 procedure :: set_hubbard_j => species_set_hubbard_j
97 procedure :: set_hubbard_alpha => species_set_hubbard_alpha
98 procedure :: get_niwfs => species_niwfs
99 procedure :: get_iwf_ilm => species_iwf_ilm
100 procedure :: get_iwf_n => species_iwf_n
101 procedure :: get_iwf_j => species_iwf_j
102 procedure :: set_mass => species_set_mass
103 procedure :: set_vdw_radius => species_set_vdw_radius
104 procedure :: set_z => species_set_z
105 procedure :: set_zval => species_set_zval
106 procedure :: get_filename => species_filename
107 procedure :: set_filename => species_set_filename
108 procedure :: is_full => species_is_full
109 procedure :: is_ps => species_is_ps
110 procedure :: is_ps_with_nlcc => species_is_ps_with_nlcc
111 procedure :: represents_real_atom => species_represents_real_atom
112 procedure :: is_user_defined => species_user_defined
113 end type species_t
118 class(species_t), pointer :: s
119 end type
120
121 abstract interface
122 ! ---------------------------------------------------------
123 logical function species_is_local(spec) result(is_local)
124 import species_t
125 class(species_t), intent(in) :: spec
126 end function species_is_local
127
128 ! ---------------------------------------------------------
129 real(real64) function species_get_iwf_radius(spec, ii, is, threshold) result(radius)
130 import real64
131 import species_t
132 class(species_t), intent(in) :: spec
133 integer, intent(in) :: ii
134 integer, intent(in) :: is
135 real(real64), optional, intent(in) :: threshold
136 end function species_get_iwf_radius
137
138 ! ---------------------------------------------------------
139 subroutine species_iwf_fix_qn(spec, namespace, nspin, dim)
141 import namespace_t
142 class(species_t), intent(inout) :: spec
143 type(namespace_t), intent(in) :: namespace
144 integer, intent(in) :: nspin
145 integer, intent(in) :: dim
146 end subroutine species_iwf_fix_qn
148 ! ---------------------------------------------------------
149 subroutine species_init_potential(this, namespace, grid_cutoff, filter)
150 import species_t
152 import real64
153 class(species_t), intent(inout) :: this
154 type(namespace_t), intent(in) :: namespace
155 real(real64), intent(in) :: grid_cutoff
156 integer, intent(in) :: filter
157 end subroutine species_init_potential
158
159 ! ---------------------------------------------------------
160 subroutine species_build(spec, namespace, ispin, dim, print_info)
162 import namespace_t
163 class(species_t), intent(inout) :: spec
164 type(namespace_t), intent(in) :: namespace
165 integer, intent(in) :: ispin
166 integer, intent(in) :: dim
167 logical, optional, intent(in) :: print_info
168 end subroutine species_build
170 ! ---------------------------------------------------------
171 subroutine species_debug(spec, dir, namespace, gmax)
174 import real64
175 class(species_t), intent(in) :: spec
176 character(len=*), intent(in) :: dir
177 type(namespace_t), intent(in) :: namespace
178 real(real64), intent(in) :: gmax
179 end subroutine species_debug
181 end interface
183 integer, private, parameter :: libxc_c_index = 1000
185contains
187 ! ---------------------------------------------------------
192 ! ---------------------------------------------------------
193 subroutine species_init(this, label, index)
194 class(species_t), intent(inout) :: this
195 character(len=*), intent(in) :: label
196 integer, intent(in) :: index
198 push_sub(species_init)
200 this%label = trim(label)
201 this%index = index
203 this%z = -m_one
204 this%z_val = -m_one
205 this%mass = -m_one
206 this%vdw_radius = -m_one
207 this%has_density = .false.
208 this%niwfs = -1
209 this%hubbard_l = -1
210 this%hubbard_U = m_zero
211 this%hubbard_j = m_zero
212 this%hubbard_alpha = m_zero
213 this%filename = ""
214
215 pop_sub(species_init)
216 end subroutine species_init
217
218 ! ---------------------------------------------------------
220 integer pure function species_closed_shell_size(min_niwfs) result(size)
221 integer, intent(in) :: min_niwfs
223 integer :: nn
224
225 size = 0
226 do nn = 1, min_niwfs
227 if (size >= min_niwfs) exit
228 size = size + nn**2
229 end do
230
231 end function species_closed_shell_size
233 ! ---------------------------------------------------------
234 character(len=LABEL_LEN) pure function species_label(species)
235 class(species_t), intent(in) :: species
236 species_label = trim(species%label)
237 end function species_label
238
239 ! ---------------------------------------------------------
240 character(len=2) pure function species_label_short(species)
241 class(species_t), intent(in) :: species
242 species_label_short = species%label(1:2)
243 end function species_label_short
244
245 ! ---------------------------------------------------------
246 integer pure function species_index(species)
247 class(species_t), intent(in) :: species
248 species_index = species%index
249 end function species_index
250
251 ! ---------------------------------------------------------
252 real(real64) pure function species_zval(species)
253 class(species_t), intent(in) :: species
254 species_zval = species%z_val
255 end function species_zval
256
257 ! ---------------------------------------------------------
258 pure subroutine species_set_zval(species, zval)
259 class(species_t), intent(inout) :: species
260 real(real64), intent(in) :: zval
261 species%z_val = zval
262 end subroutine species_set_zval
263
264 ! ---------------------------------------------------------
265 real(real64) pure function species_z(species)
266 class(species_t), intent(in) :: species
267 species_z = species%z
268 end function species_z
269
270 ! ---------------------------------------------------------
271 pure subroutine species_set_z(species, z)
272 class(species_t), intent(inout) :: species
273 real(real64), intent(in) :: z
274 species%z = z
275 end subroutine species_set_z
277 ! ---------------------------------------------------------
278 real(real64) pure function species_mass(species)
279 class(species_t), intent(in) :: species
280 species_mass = species%mass
281 end function species_mass
282
283 ! ---------------------------------------------------------
284 pure subroutine species_set_mass(species, mass)
285 class(species_t), intent(inout) :: species
286 real(real64), intent(in) :: mass
287 species%mass = mass
288 end subroutine species_set_mass
289
290 ! ---------------------------------------------------------
291 real(real64) pure function species_vdw_radius(species)
292 class(species_t), intent(in) :: species
293 species_vdw_radius = species%vdw_radius
294 end function species_vdw_radius
295
296 ! ---------------------------------------------------------
297 pure subroutine species_set_vdw_radius(species, radius)
298 class(species_t), intent(inout) :: species
299 real(real64), intent(in) :: radius
300 species%vdw_radius = radius
301 end subroutine species_set_vdw_radius
302
303 ! ---------------------------------------------------------
304 integer pure function species_niwfs(species)
305 class(species_t), intent(in) :: species
306 species_niwfs = species%niwfs
307 end function species_niwfs
308
309 ! ---------------------------------------------------------
310 integer pure function species_hubbard_l(species)
311 class(species_t), intent(in) :: species
312 species_hubbard_l = species%hubbard_l
313 end function species_hubbard_l
314
315 ! ---------------------------------------------------------
316 real(real64) pure function species_hubbard_u(species)
317 class(species_t), intent(in) :: species
318 species_hubbard_u = species%hubbard_u
319 end function species_hubbard_u
320
321 ! ---------------------------------------------------------
322 real(real64) pure function species_hubbard_j(species)
323 class(species_t), intent(in) :: species
324 species_hubbard_j = species%hubbard_j
325 end function species_hubbard_j
326
327 ! ---------------------------------------------------------
328 real(real64) pure function species_hubbard_alpha(species)
329 class(species_t), intent(in) :: species
330 species_hubbard_alpha = species%hubbard_alpha
331 end function species_hubbard_alpha
332
333 ! ---------------------------------------------------------
334 pure subroutine species_set_hubbard_l(species, hubbard_l)
335 class(species_t), intent(inout) :: species
336 integer, intent(in) :: hubbard_l
337 species%hubbard_l = hubbard_l
338 end subroutine species_set_hubbard_l
340 ! ---------------------------------------------------------
341 pure subroutine species_set_hubbard_u(species, hubbard_u)
342 class(species_t), intent(inout) :: species
343 real(real64), intent(in) :: hubbard_u
344 species%hubbard_u = hubbard_u
346
347 ! ---------------------------------------------------------
348 pure subroutine species_set_hubbard_j(species, hubbard_j)
349 class(species_t), intent(inout) :: species
350 real(real64), intent(in) :: hubbard_j
351 species%hubbard_j = hubbard_j
352 end subroutine species_set_hubbard_j
353
354 ! ---------------------------------------------------------
355 pure subroutine species_set_hubbard_alpha(species, hubbard_alpha)
356 class(species_t), intent(inout) :: species
357 real(real64), intent(in) :: hubbard_alpha
358 species%hubbard_alpha = hubbard_alpha
359 end subroutine species_set_hubbard_alpha
360
361 ! ---------------------------------------------------------
362 character(len=200) pure function species_filename(species)
363 class(species_t), intent(in) :: species
364 species_filename = trim(species%filename)
365 end function species_filename
366
367 ! ---------------------------------------------------------
368 pure subroutine species_set_filename(species, filename)
369 class(species_t), intent(inout) :: species
370 character(len=*), intent(in) :: filename
371 species%filename = trim(filename)
372 end subroutine species_set_filename
373
374 ! ---------------------------------------------------------
375 pure subroutine species_iwf_ilm(species, j, is, i, l, m)
376 class(species_t), intent(in) :: species
377 integer, intent(in) :: j, is
378 integer, intent(out) :: i, l, m
379
380 i = species%iwf_i(j, is)
381 l = species%iwf_l(j, is)
382 m = species%iwf_m(j, is)
383 end subroutine species_iwf_ilm
385 ! ---------------------------------------------------------
386 pure subroutine species_iwf_n(species, j, is, n)
387 class(species_t), intent(in) :: species
388 integer, intent(in) :: j, is
389 integer, intent(out) :: n
391 n = species%iwf_n(j, is)
392 end subroutine species_iwf_n
393
394 ! ---------------------------------------------------------
395 pure subroutine species_iwf_j(species, iorb, j)
396 class(species_t), intent(in) :: species
397 integer, intent(in) :: iorb
398 real(real64), intent(out) :: j
399
400 j = species%iwf_j(iorb)
401 end subroutine species_iwf_j
402
403 ! ---------------------------------------------------------
404 subroutine species_end(species)
405 class(species_t), intent(inout) :: species
406
407 push_sub(species_end)
408
409 safe_deallocate_a(species%iwf_n)
410 safe_deallocate_a(species%iwf_l)
411 safe_deallocate_a(species%iwf_m)
412 safe_deallocate_a(species%iwf_i)
413 safe_deallocate_a(species%iwf_j)
414
415 pop_sub(species_end)
416 end subroutine species_end
417 ! ---------------------------------------------------------
418
419
420!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
421! Private procedures
422
423 ! ---------------------------------------------------------
424 character(len=LABEL_LEN) function get_symbol(label) result(symbol)
425 character(len=*), intent(in) :: label
426
427 integer :: ilend
428
429 ! use only the first part of the label to determine the element
430 do ilend = 1, len(label)
431 if (iachar(label(ilend:ilend)) >= iachar('a') .and. iachar(label(ilend:ilend)) <= iachar('z')) cycle
432 if (iachar(label(ilend:ilend)) >= iachar('A') .and. iachar(label(ilend:ilend)) <= iachar('Z')) cycle
433 exit
434 end do
435 ilend = ilend - 1
436
437 symbol = label(1:ilend)
438
439 end function get_symbol
440
441 ! ---------------------------------------------------------
442 logical function species_is_same_species(spec1, spec2) result(same)
443 class(species_t), intent(in) :: spec1, spec2
444
446
447 same = same_type_as(spec1, spec2)
448 if(abs(spec1%z - spec2%z) > m_epsilon) same = .false.
449 if(abs(spec1%z_val - spec2%z_val) > m_epsilon) same = .false.
450 if(abs(spec1%mass - spec2%mass) > m_epsilon) same = .false.
451
453 end function species_is_same_species
454
455 ! ---------------------------------------------------------
457 logical pure function species_is_full(this)
458 class(species_t), intent(in) :: this
459
460 species_is_full = .false.
461 end function species_is_full
462
463 ! ---------------------------------------------------------
465 logical pure function species_is_ps(this)
466 class(species_t), intent(in) :: this
467
469 end function species_is_ps
470
471 ! ---------------------------------------------------------
473 logical pure function species_is_ps_with_nlcc(this)
474 class(species_t), intent(in) :: this
475
477 end function species_is_ps_with_nlcc
478
479 ! ---------------------------------------------------------
481 logical pure function species_represents_real_atom(spec)
482 class(species_t), intent(in) :: spec
483
486
487 ! ---------------------------------------------------------
489 logical pure function species_user_defined(spec)
490 class(species_t), intent(in) :: spec
491
492 species_user_defined = .false.
493 end function species_user_defined
494
495
496end module species_oct_m
498!! Local Variables:
499!! mode: f90
500!! coding: utf-8
501!! End:
real(real64) pure function species_zval(species)
Definition: species.F90:346
integer, parameter, private libxc_c_index
Definition: species.F90:276
pure subroutine species_set_hubbard_l(species, hubbard_l)
Definition: species.F90:428
pure subroutine species_set_z(species, z)
Definition: species.F90:365
logical pure function species_user_defined(spec)
Is the species user-defined or not.
Definition: species.F90:583
real(real64) pure function species_hubbard_u(species)
Definition: species.F90:410
character(len=label_len) function, public get_symbol(label)
Definition: species.F90:518
character(len=2) pure function, public species_label_short(species)
Definition: species.F90:334
pure subroutine species_set_hubbard_j(species, hubbard_j)
Definition: species.F90:442
integer pure function species_niwfs(species)
Definition: species.F90:398
pure subroutine species_set_filename(species, filename)
Definition: species.F90:462
pure subroutine species_set_zval(species, zval)
Definition: species.F90:352
subroutine, public species_end(species)
Definition: species.F90:498
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:287
logical pure function species_represents_real_atom(spec)
Is the species representing an atomic species or not.
Definition: species.F90:575
logical pure function species_is_ps_with_nlcc(this)
Is the species a pseudopotential derived class or not with nlcc.
Definition: species.F90:567
pure subroutine species_set_hubbard_alpha(species, hubbard_alpha)
Definition: species.F90:449
character(len=200) pure function species_filename(species)
Definition: species.F90:456
pure subroutine species_iwf_ilm(species, j, is, i, l, m)
Definition: species.F90:469
logical function species_is_same_species(spec1, spec2)
Definition: species.F90:536
integer pure function species_index(species)
Definition: species.F90:340
logical pure function species_is_ps(this)
Is the species a pseudopotential derived class or not.
Definition: species.F90:559
real(real64) pure function species_vdw_radius(species)
Definition: species.F90:385
pure subroutine species_iwf_n(species, j, is, n)
Definition: species.F90:480
pure subroutine species_set_hubbard_u(species, hubbard_u)
Definition: species.F90:435
real(real64) pure function species_hubbard_alpha(species)
Definition: species.F90:422
real(real64) pure function species_z(species)
Definition: species.F90:359
pure subroutine species_iwf_j(species, iorb, j)
Definition: species.F90:489
character(len=label_len) pure function species_label(species)
Definition: species.F90:328
logical pure function species_is_full(this)
Is the species an all-electron derived class or not.
Definition: species.F90:551
pure subroutine species_set_vdw_radius(species, radius)
Definition: species.F90:391
integer pure function species_hubbard_l(species)
Definition: species.F90:404
pure subroutine species_set_mass(species, mass)
Definition: species.F90:378
real(real64) pure function species_hubbard_j(species)
Definition: species.F90:416
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:314
real(real64) pure function species_mass(species)
Definition: species.F90:372
An abstract class for species. Derived classes include jellium, all electron, and pseudopotential spe...
Definition: species.F90:143
Needed for having an array of pointers See for instance https:
Definition: species.F90:210