Octopus
species_factory.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
23 use debug_oct_m
25 use global_oct_m
26 use iihash_oct_m
27 use io_oct_m
31 use parser_oct_m
36 use string_oct_m
37 use unit_oct_m
39
40 implicit none
41
42 private
43 public :: &
47
48 type :: species_factory_t
49 logical :: initialized = .false.
50 integer :: default_pseudopotential_set_id
51 type(pseudo_set_t) :: default_pseudopotential_set
52 integer :: default_allelectron_type
53 real(real64) :: default_sigma
54 real(real64) :: default_anc_a
55 contains
56 procedure :: init => species_factory_init
57 procedure :: end => species_factory_end
58 procedure :: create_from_input => species_factory_create_from_input
59 procedure :: create_from_block => read_from_block
60 end type species_factory_t
61
62contains
63
64 ! ---------------------------------------------------------
65 subroutine species_factory_init(factory, namespace)
66 class(species_factory_t), intent(inout) :: factory
67 type(namespace_t), intent(in) :: namespace
68
69 integer :: ierr, default_val
70
71 if (factory%initialized) return
72
73 push_sub_with_profile(species_factory_init)
74
75 factory%initialized = .true.
76
77 call share_directory_set(conf%share)
78
79 !%Variable AllElectronType
80 !%Type integer
81 !%Default no
82 !%Section System::Species
83 !%Description
84 !% Selects the type of all-electron species that applies by default to all
85 !% atoms. This is not compatible with <tt>PseudopotentialSet</tt>, but it is
86 !% compatible with the <tt>Species</tt> block.
87 !%
88 !%Option no 0
89 !% Do not specify any default all-electron type of species. All species must be
90 !% specified in the Species block.
91 !%Option full_delta 1
92 !% All atoms are supposed to be by default of type <tt>species_full_delta</tt>.
93 !%Option full_gaussian 2
94 !% All atoms are supposed to be by default of type <tt>species_full_gaussian</tt>.
95 !%Option full_anc 3
96 !% All atoms are supposed to be by default of type <tt>species_full_anc</tt>.
97 !%End
98 call parse_variable(namespace, 'AllElectronType', option__allelectrontype__no, factory%default_allelectron_type)
99 call messages_print_var_option('AllElectronType', factory%default_allelectron_type, namespace=namespace)
100
101 !%Variable AllElectronSigma
102 !%Type integer
103 !%Default 0.6
104 !%Section System::Species
105 !%Description
106 !% Default value for the parameter <tt>gaussian_width</tt>. This is useful
107 !% for specifying multiple atoms without specifying the species block. The
108 !% default value is taken from the recommendation in
109 !% <i>Phys. Rev. B</i> <b>55</b>, 10289 (1997).
110 !%
111 !%End
112 call parse_variable(namespace, 'AllElectronSigma', 0.6_real64, factory%default_sigma)
113
114 !%Variable AllElectronANCParam
115 !%Type integer
116 !%Default 4
117 !%Section System::Species
118 !%Description
119 !% Default values for the parameter <tt>anc_a</tt>. This is usefull
120 !% for specifying multiple atoms without specifying the species block.
121 !%
122 !%End
123 call parse_variable(namespace, 'AllElectronANCParam', 4.0_real64, factory%default_anc_a)
124
125
126 !%Variable PseudopotentialSet
127 !%Type integer
128 !%Default standard
129 !%Section System::Species
130 !%Description
131 !% Selects the set of pseudopotentials used by default for species
132 !% not defined in the <tt>Species</tt> block.
133 !%
134 !% These sets of pseudopotentials come from different
135 !% sources. Octopus developers have not validated them. We include
136 !% them with the code for convenience of the users, but you are
137 !% expected to check the quality and suitability of the
138 !% pseudopotential for your application.
139 !%
140 !% Note that not all these pseudopotentials are compatible with spin-orbit coupling
141 !% Only hgh_lda, hgh_lda_sc and pseudodojo_pbe_fr provide SOC information.
142 !%
143 !%Option none 0
144 !% Do not load any pseudopotential by default. All species must be
145 !% specified in the Species block.
146 !%Option standard 1
147 !% The standard set of Octopus that provides LDA pseudopotentials
148 !% in the PSF format for some elements: H, Li, C, N, O, Na, Si, S, Ti, Se, Cd.
149 !%Option sg15 2
150 !% The set of Optimized Norm-Conserving Vanderbilt
151 !% PBE pseudopotentials. Ref: M. Schlipf and F. Gygi, <i>Comp. Phys. Commun.</i> <b>196</b>, 36 (2015).
152 !% This set provides pseudopotentials for elements up to Z = 83
153 !% (Bi), excluding Lanthanides.
154 !% Current version of the set is 1.2.
155 !%Option hgh_lda 3
156 !% The set of Hartwigsen-Goedecker-Hutter LDA pseudopotentials for elements from H to Rn.
157 !% Ref: C. Hartwigsen, S. Goedecker, and J. Hutter, <i>Phys. Rev. B</i> <b>58</b>, 3641 (1998).
158 !%Option hgh_lda_sc 31
159 !% The semicore set of Hartwigsen-Goedecker-Hutter LDA pseudopotentials.
160 !% Ref: C. Hartwigsen, S. Goedecker, and J. Hutter, <i>Phys. Rev. B</i> <b>58</b>, 3641 (1998).
161 !%Option hscv_lda 4
162 !% The set of Hamann-Schlueter-Chiang-Vanderbilt (HSCV) potentials
163 !% for LDA exchange and correlation downloaded from http://fpmd.ucdavis.edu/potentials/index.htm.
164 !% These pseudopotentials were originally intended for the QBox
165 !% code. They were generated using the method of Hamann, Schluter
166 !% and Chiang. Ref: D. Vanderbilt, <i>Phys. Rev. B</i> <b>32</b>, 8412 (1985).
167 !% Warning from the original site: The potentials provided in this
168 !% site are distributed without warranty. In most cases,
169 !% potentials were not tested. Potentials should be thoroughly
170 !% tested before being used in simulations.
171 !%Option hscv_pbe 5
172 !% PBE version of the HSCV pseudopotentials. Check the
173 !% documentation of the option <tt>hscv_lda</tt> for details and warnings.
174 !%Option pseudodojo_pbe 100
175 !% PBE version of the pseudopotentials of http://pseudo-dojo.org. Version 0.5
176 !%Option pseudodojo_lda 103
177 !% LDA pseudopotentials of http://pseudo-dojo.org. Version 0.4.
178 !%Option pseudodojo_pbesol 105
179 !% PBEsol version of the pseudopotentials of http://pseudo-dojo.org. Version 0.3.
180 !%Option pseudodojo_pbe_fr 106
181 !% Fully-relativistic PBE version of the pseudopotentials of http://pseudo-dojo.org. Version 0.4.
182 !%End
183 default_val = option__pseudopotentialset__standard
184 if(factory%default_allelectron_type /= option__allelectrontype__no) default_val = option__pseudopotentialset__none
185 call parse_variable(namespace, 'PseudopotentialSet', default_val, factory%default_pseudopotential_set_id)
186 call messages_print_var_option('PseudopotentialSet', factory%default_pseudopotential_set_id, namespace=namespace)
187 if (factory%default_pseudopotential_set_id /= option__pseudopotentialset__none) then
188 call pseudo_set_init(factory%default_pseudopotential_set, get_set_directory(factory%default_pseudopotential_set_id), ierr)
189 else
190 call pseudo_set_nullify(factory%default_pseudopotential_set)
191 end if
192
193 if (factory%default_pseudopotential_set_id /= option__pseudopotentialset__none .and. factory%default_allelectron_type /= option__allelectrontype__no) then
194 message(1) = "PseudopotentialSet /= none cannot be used with AllElectronType /= no."
195 call messages_fatal(1, namespace=namespace)
196 end if
197
198 pop_sub_with_profile(species_factory_init)
199 end subroutine species_factory_init
200
201 ! ---------------------------------------------------------
202
203 subroutine species_factory_end(factory)
204 class(species_factory_t), intent(inout) :: factory
205
206 push_sub(species_factory_end)
207
208 if (factory%initialized) then
209 call pseudo_set_end(factory%default_pseudopotential_set)
210 factory%initialized = .false.
211 end if
212
213 pop_sub(species_factory_end)
214 end subroutine species_factory_end
215
216
217 ! ---------------------------------------------------------
222 ! ---------------------------------------------------------
223 function species_factory_create_from_input(factory, namespace, label, index) result(spec)
224 class(species_factory_t), intent(in) :: factory
225 type(namespace_t), intent(in) :: namespace
226 character(len=*), intent(in) :: label
227 integer, intent(in) :: index
228 class(species_t), pointer :: spec
229
230 character(len=LABEL_LEN) :: lab
231 integer :: ib, row, n_spec_block, read_data
232 type(block_t) :: blk
233 type(element_t) :: element
234
236
237 read_data = 0
238
239 !%Variable Species
240 !%Type block
241 !%Section System::Species
242 !%Description
243 !% A species is by definition either an "ion" (nucleus + core electrons) described
244 !% through a pseudopotential, or a model potential.
245 !%
246 !% Note that some sets of pseudopotentials are distributed with
247 !% the code. To use these pseudopotentials, you do not need to define them
248 !% explicitly in the <tt>Species</tt> block, as default parameters
249 !% are provided.
250 !% You can select the set for default pseudopotentials using the
251 !% <tt>PseudopotentialSet</tt> variable.
252 !%
253 !% Supported norm-conserving pseudopotential formats are
254 !% detected by the file extension: UPF (<tt>.upf</tt>), PSF (SIESTA, <tt>.psf</tt>), FHI (ABINIT 6, <tt>.fhi</tt>),
255 !% CPI (Fritz-Haber, <tt>.cpi</tt>), QSO (quantum-simulation.org, for Qbox, <tt>.xml</tt>),
256 !% HGH (Hartwigsen-Goedecker-Hutter, <tt>.hgh</tt>).
257 !% PSPIO format can also be used via <tt>species_pspio</tt> if that library is linked.
258 !% Note: pseudopotentials may only be used in 3D.
259 !%
260 !% The format of this block is the following: The first field is a
261 !% string that defines the name of the species. The second field
262 !% defines the type of species (the valid options are detailed
263 !% below).
264 !%
265 !% Then a list of parameters follows. The parameters are specified
266 !% by a first field with the parameter name and the field that
267 !% follows with the value of the parameter. Some parameters are
268 !% specific to a certain species while others are accepted by all
269 !% species. These are <tt>mass</tt>, <tt>max_spacing</tt>, and <tt>min_radius</tt>.
270 !%
271 !% These are examples of possible species:
272 !%
273 !% <tt>%Species
274 !% <br>&nbsp;&nbsp;'O' | species_pseudo | file | 'O.psf' | lmax | 1 | lloc | 1
275 !% <br>&nbsp;&nbsp;'H' | species_pseudo | file | '../H.hgh'
276 !% <br>&nbsp;&nbsp;'Xe' | species_pseudo | set | pseudojo_pbe_stringent
277 !% <br>&nbsp;&nbsp;'C' | species_pseudo | file | "carbon.xml"
278 !% <br>&nbsp;&nbsp;'jlm' | species_jellium | jellium_radius | 5.0
279 !% <br>&nbsp;&nbsp;'rho' | species_charge_density | density_formula | "exp(-r/a)" | mass | 17.0 | valence | 6
280 !% <br>&nbsp;&nbsp;'udf' | species_user_defined | potential_formula | "1/2*r^2" | valence | 8
281 !% <br>&nbsp;&nbsp;'He_all' | species_full_delta
282 !% <br>&nbsp;&nbsp;'H_all' | species_full_gaussian | gaussian_width | 0.2
283 !% <br>&nbsp;&nbsp;'Li1D' | species_soft_coulomb | softening | 1.5 | valence | 3
284 !% <br>&nbsp;&nbsp;'H_all' | species_full_anc | anc_a | 4
285 !% <br>%</tt>
286 !%Option species_pseudo -7
287 !% The species is a pseudopotential. How to get the
288 !% pseudopotential can be specified by the <tt>file</tt> or
289 !% the <tt>set</tt> parameters. If both are missing, the
290 !% pseudopotential will be taken from the <tt>PseudopotentialSet</tt>
291 !% specified for the run, this is useful if you want to change
292 !% some parameters of the pseudo, like the <tt>mass</tt>.
293 !%
294 !% The optional parameters for this type of species are
295 !% <tt>lmax</tt>, that defines the maximum angular momentum
296 !% component to be used, and <tt>lloc</tt>, that defines the
297 !% angular momentum to be considered as local. When these
298 !% parameters are not set, the value for lmax is the maximum
299 !% angular component from the pseudopotential file. The default
300 !% value for <tt>lloc</tt> is taken from the pseudopotential if
301 !% available, if not, it is set to 0. Note that, depending on the
302 !% type of pseudopotential, it might not be possible to select
303 !% <tt>lmax</tt> and <tt>lloc</tt>, if that is the case the
304 !% parameters will be ignored.
305 !%
306 !%Option species_pspio -110
307 !% (experimental) Alternative method to read pseudopotentials
308 !% using the PSPIO library. This species uses the same parameters
309 !% as <tt>species_pseudo</tt>.
310 !%Option species_user_defined -123
311 !% Species with user-defined potential. The potential for the
312 !% species is defined by the formula given by the <tt>potential_formula</tt>
313 !% parameter.
314 !% The
315 !% <tt>valence</tt> parameter determines the number of electrons
316 !% associated with the species. By default, a valence of 0 is assumed.
317 !%Option species_charge_density -125
318 !% The potential for this species is created from the distribution
319 !% of charge given by the <tt>density_formula</tt> parameter.
320 !% The
321 !% <tt>valence</tt> parameter determines the number of electrons
322 !% associated with the species. By default, a valence of 0 is assumed.
323 !%Option species_point -3
324 !%Option species_jellium -3
325 !% Jellium sphere.
326 !% The charge associated with this species must be given by the <tt>valence</tt> parameter.
327 !%Option species_jellium_slab -4
328 !% A slab of jellium that extends across the simulation box in the
329 !% <i>xy</i>-plane. The dimension along the <i>z</i> direction is
330 !% determined by the required parameter <tt>thickness</tt>.
331 !% The charge associated with this species must be given by the <tt>valence</tt> parameter.
332 !%Option species_full_delta -127
333 !% Full atomic potential represented by a delta charge
334 !% distribution. The atom will be displaced to the nearest grid
335 !% point. The atomic number is determined from the name of the species.
336 !%Option species_full_anc -130
337 !% Analytical norm-conserving regulized Coulomb potential from
338 !% [Gygi J. Chem. Theory Comput. 2023, 19, 1300−1309].
339 !%Option species_full_gaussian -124
340 !% A full-potential atom is defined by a Gaussian accumulation of
341 !% positive charge (distorted if curvilinear coordinates are
342 !% used), in the form:
343 !%
344 !% <math>q(r) = z \beta \exp[ - (\vec{r}-\vec{r_0})^2 / (\sqrt{2} \delta \sigma) ] </math>
345 !%
346 !% <math>\beta</math> is chosen in order to maintain proper
347 !% normalization (the integral of <math>q</math> should sum up to
348 !% <math>z</math>). <math>\delta</math> is the grid spacing (the
349 !% grid spacing in the first dimension, to be precise).
350 !% <math>\vec{r_0}</math> is calculated in such a way that the the
351 !% first moment of <math>q(r)/z</math> is equal to the atomic
352 !% position. For a precise description, see N. A. Modine,
353 !% <i>Phys. Rev. B</i> <b>55</b>, 10289 (1997). The width of the
354 !% Gaussian is set by parameter <tt>gaussian_width</tt>. The
355 !% atomic number is determined from the name of the species.
356 !%Option species_from_file -126
357 !% The potential is read from a file. Accepted file formats, detected by extension: obf, ncdf and csv.
358 !% The
359 !% <tt>valence</tt> parameter determines the number of electrons
360 !% associated with the species. By default, a valence of 0 is assumed.
361 !%Option species_soft_coulomb -128
362 !% The potential is a soft-Coulomb function, <i>i.e.</i> a function in the form:
363 !%
364 !% <math>v(r) = - z_{val} / \sqrt{a^2 + r^2}</math>
365 !%
366 !% The value of <i>a</i> should be given by the mandatory <tt>softening</tt> parameter.
367 !% The charge associated with this species must be given by the <tt>valence</tt> parameter.
368 !%Option species_jellium_charge_density -129
369 !% The parameter is the name of a volume block specifying the shape of the jellium.
370 !%Option lmax -10003
371 !% The maximum angular-momentum channel that will be used for the pseudopotential.
372 !%Option lloc -10004
373 !% The angular-momentum channel of the pseudopotential to be considered local.
374 !%Option mass -10005
375 !% The mass of the species in atomic mass units, <i>i.e.</i> the mass of a proton is
376 !% roughly one. It is set automatically for pseudopotentials from the
377 !% <a href=http://www.nist.gov/pml/data/comp.cfm>NIST values</a>.
378 !% For other species, the default is 1.0.
379 !%Option valence -10006
380 !% The number of electrons of the species. It is set automatically from the name of the species.
381 !% if it correspond to the name in the periodic table. If not specified and if the name
382 !% does not match an atom name, a value of 0 is assumed.
383 !%Option jellium_radius -10007
384 !% The radius of the sphere for <tt>species_jellium</tt>. If this value is not specified,
385 !% the default of 0.5 bohr is used.
386 !%Option set -10017
387 !% For a <tt>species_pseudo</tt>, get the pseudopotential from a
388 !% particular set. This flag must be followed with one of the
389 !% valid values for the variable <tt>PseudopotentialSet</tt>.
390 !%Option gaussian_width -10008
391 !% The width of the Gaussian (in units of spacing) used to represent
392 !% the nuclear charge for <tt>species_full_gaussian</tt>. If not present,
393 !% the default is 0.6.
394 !%Option softening -10009
395 !% The softening parameter <i>a</i> for <tt>species_soft_coulomb</tt> in units of length.
396 !%Option file -10010
397 !% The path for the file that describes the species.
398 !%Option db_file -10011
399 !% Obsolete. Use the <tt>set</tt> option of the <tt>PseudopotentialSet</tt> variable instead.
400 !%Option potential_formula -10012
401 !% Mathematical expression that defines the potential for <tt>species_user_defined</tt>. You can use
402 !% any of the <i>x</i>, <i>y</i>, <i>z</i> or <i>r</i> variables.
403 !%Option density_formula -10013
404 !% Mathematical expression that defines the charge density for <tt>species_charge_density</tt>. You can use
405 !% any of the <i>x</i>, <i>y</i>, <i>z</i> or <i>r</i> variables.
406 !%Option thickness -10014
407 !% The thickness of the slab for species_jellium_slab. Must be positive.
408 !%Option vdw_radius -10015
409 !% The van der Waals radius that will be used for this species.
410 !%Option volume -10016
411 !% Name of a volume block
412 !%Option hubbard_l -10018
413 !% The angular-momentum for which the effective U will be applied.
414 !%Option hubbard_u -10019
415 !% The effective U that will be used for the DFT+U calculations.
416 !%Option hubbard_j -10020
417 !% The value of j (hubbard_l-1/2 or hubbard_l+1/2) on which the effective U is applied.
418 !%Option hubbard_alpha -10021
419 !% The strength of the potential constraining the occupations of the localized subspace
420 !% as defined in PRB 71, 035105 (2005)
421 !%Option anc_a -10022
422 !% The value of the parameter a of the ANC potential, as defined in [Gygi, JCTC 2023, 19, 1300−1309].
423 !% This parameter has the unit of inverse length and determines the range of regularization.
424 !%End
425
426 call messages_obsolete_variable(namespace, 'SpecieAllElectronSigma', 'Species')
427 call messages_obsolete_variable(namespace, 'SpeciesAllElectronSigma', 'Species')
428
429 ! First, find out if there is a Species block.
430 n_spec_block = 0
431 if (parse_block(namespace, 'Species', blk) == 0) then
432 n_spec_block = parse_block_n(blk)
433 end if
434
435 ! Find out if the sought species is in the block
436 row = -1
437 block: do ib = 1, n_spec_block
438 call parse_block_string(blk, ib-1, 0, lab)
439 if (trim(lab) == trim(label)) then
440 row = ib - 1
441 exit block
442 end if
443 end do block
444
445 ! Read whatever may be read from the block
446 if (row >= 0) then
447 spec => factory%create_from_block(namespace, blk, row, label, index, read_data)
448 call parse_block_end(blk)
449
450 assert(read_data > 0)
451
453 return
454 end if
455
456 ! We get here if there is a Species block but it does not contain
457 ! the species we are looking for.
458 if (n_spec_block > 0) call parse_block_end(blk)
459
460 ! Initialize all electron species (except soft-Coulomb) from specified allelectron type
461 if(factory%default_allelectron_type /= 0) then
462 select case(factory%default_allelectron_type)
463 case(option__allelectrontype__full_delta)
464 spec => full_delta_t(label, index, factory%default_sigma)
465 case(option__allelectrontype__full_gaussian)
466 spec => full_gaussian_t(label, index, factory%default_sigma)
467 case(option__allelectrontype__full_anc)
468 spec => full_anc_t(label, index, factory%default_anc_a)
469 case default
470 assert(.false.)
471 end select
472
473 ! get the mass, vdw radius and atomic number for this element
474 call element_init(element, get_symbol(spec%get_label()))
475
476 assert(element_valid(element))
477
478 call spec%set_z(real(element_atomic_number(element), real64))
479 call spec%set_zval(spec%get_z())
480 call spec%set_mass(element_mass(element))
481 call spec%set_vdw_radius(element_vdw_radius(element))
482
483 call element_end(element)
484
485 else ! Pseudopotential from specified set or the default one
486 spec => pseudopotential_t(label, index)
487 select type(spec)
488 type is(pseudopotential_t)
489 call read_from_set(spec, factory%default_pseudopotential_set_id, factory%default_pseudopotential_set, read_data)
490
491 if (read_data == 0) then
492 call messages_write( 'Species '//trim(spec%get_label())//' not found in default pseudopotential set.', new_line=.true. )
493 call messages_write('( '//trim(get_set_directory(factory%default_pseudopotential_set_id))//' )')
494 call messages_fatal(namespace=namespace)
495 end if
496 end select
497 end if
498
501
502!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
503! Private procedures
504
505 ! ---------------------------------------------------------
507 function read_from_block(factory, namespace, blk, row, label, index, read_data) result(spec)
508 class(species_factory_t), intent(in) :: factory
509 type(namespace_t), intent(in) :: namespace
510 type(block_t), intent(in) :: blk
511 integer, intent(in) :: row
512 character(len=*), intent(in) :: label
513 integer, intent(in) :: index
514 integer, intent(out):: read_data
515 class(species_t), pointer :: spec
516
517 integer :: ncols, icol, flag, set_read_data, ierr, type
518 type(element_t) :: element
519 type(iihash_t) :: read_parameters
520 integer :: user_lmax, user_llocal, hubbard_l, pseudopotential_set_id
521 real(real64) :: hubbard_u, hubbard_j, hubbard_alpha, mass, z_val, jradius, jthick, vdw_radius, aa
522 real(real64) :: sigma, softening
523 character(len=MAX_PATH_LEN) :: filename
524
525 integer, parameter :: &
526 species_jellium = 3, & !< jellium sphere.
529 species_pseudo = 7, &
530 species_pspio = 110, &
531 species_usdef = 123, &
532 species_full_gaussian = 124, &
533 species_charge_density = 125, &
534 species_from_file = 126, &
535 species_full_delta = 127, &
536 species_soft_coulomb = 128, &
537 species_full_anc = 130
538
539 push_sub(read_from_block)
540
541 ncols = parse_block_cols(blk, row)
542 read_data = 0
543
544 call parse_block_integer(blk, row, 1, type)
545
546 ! To detect the old species block format, options are represented
547 ! as negative values. If we get a non-negative value we know we
548 ! are reading a mass.
549 if (type >= 0) then
550 call messages_write('Found a species with the old format. Please update', new_line = .true.)
551 call messages_write('the Species block to the new format, where the second', new_line = .true.)
552 call messages_write('column indicates the type of the species.')
553 call messages_fatal(namespace=namespace)
554 end if
555
556 ! now we convert back to positive
557 type = -type
558
559 read_data = 2
560
561
562 select case (type)
563
564 case (species_soft_coulomb)
565 spec => soft_coulomb_t(label, index)
566
567 case (species_usdef) ! user-defined
568 spec => species_user_defined_t(label, index)
569
570 case (species_from_file)
571 spec => species_from_file_t(label, index)
572
573 case (species_jellium)
574 spec => jellium_sphere_t(label, index)
575
577 spec => jellium_slab_t(label, index)
578
579 case (species_full_delta)
580 spec => full_delta_t(label, index, factory%default_sigma)
581
582 case (species_full_gaussian)
583 spec => full_gaussian_t(label, index, factory%default_sigma)
584
585 case (species_full_anc)
586 spec => full_anc_t(label, index, factory%default_anc_a)
587
589 spec => species_charge_density_t(label, index)
590
592 spec => jellium_charge_t(label, index)
593
594 case (species_pseudo)
595 spec => pseudopotential_t(label, index)
596
597 case (species_pspio) ! a pseudopotential file to be handled by the pspio library
598 spec => pseudopotential_t(label, index)
599
600 case default
601 call messages_input_error(namespace, 'Species', "Unknown type for species '"//trim(spec%get_label())//"'", row=row, column=1)
602 end select
603
604 call spec%set_mass(-m_one)
605 call spec%set_vdw_radius(-m_one)
606 call spec%set_zval(-m_one)
607
608 call iihash_init(read_parameters)
609
610 icol = read_data
611 do
612 if (icol >= ncols) exit
613
614 call parse_block_integer(blk, row, icol, flag)
615
616 select case (flag)
617
618 case (option__species__lmax)
619 call check_duplication(option__species__lmax)
620 call parse_block_integer(blk, row, icol + 1, user_lmax)
621
622 select type(spec)
623 class is(pseudopotential_t)
624 call spec%set_user_lmax(user_lmax)
625 class default
626 call messages_input_error(namespace, 'Species', &
627 "The 'lmax' parameter in species "//trim(spec%get_label())//" can only be used with pseudopotential species", &
628 row=row, column=icol+1)
629 end select
630
631 if (user_lmax < 0) then
632 call messages_input_error(namespace, 'Species', &
633 "The 'lmax' parameter in species "//trim(spec%get_label())//" cannot be negative", &
634 row=row, column=icol+1)
635 end if
636
637 case (option__species__lloc)
638 call check_duplication(option__species__lloc)
639 call parse_block_integer(blk, row, icol + 1, user_llocal)
640
641 select type(spec)
642 class is(pseudopotential_t)
643 call spec%set_user_lloc(user_llocal)
644 class default
645 call messages_input_error(namespace, 'Species', &
646 "The 'lloc' parameter in species "//trim(spec%get_label())//" can only be used with pseudopotential species", &
647 row=row, column=icol+1)
648 end select
649
650 if (user_llocal < 0) then
651 call messages_input_error(namespace, 'Species', &
652 "The 'lloc' parameter in species "//trim(spec%get_label())//" cannot be negative", row=row, column=icol+1)
653 end if
654
655 case (option__species__hubbard_l)
656 call check_duplication(option__species__hubbard_l)
657 call parse_block_integer(blk, row, icol + 1, hubbard_l)
658
659 select type(spec)
660 class is(pseudopotential_t)
661 call spec%set_hubbard_l(hubbard_l)
662 class default
663 call messages_input_error(namespace, 'Species', &
664 "The 'hubbard_l' parameter in species "//trim(spec%get_label())//" can only be used with pseudopotential species", &
665 row=row, column=icol+1)
666 end select
667
668 if (hubbard_l < 0) then
669 call messages_input_error(namespace, 'Species', &
670 "The 'hubbard_l' parameter in species "//trim(spec%get_label())//" cannot be negative", row=row, column=icol+1)
671 end if
672
673 case (option__species__hubbard_u)
674 call check_duplication(option__species__hubbard_u)
675 call parse_block_float(blk, row, icol + 1, hubbard_u, unit = units_inp%energy)
676 call spec%set_hubbard_u(hubbard_u)
677
678 case (option__species__hubbard_alpha)
679 call check_duplication(option__species__hubbard_alpha)
680 call parse_block_float(blk, row, icol + 1, hubbard_alpha, unit = units_inp%energy)
681 call spec%set_hubbard_u(hubbard_alpha)
682
683 case (option__species__hubbard_j)
684 call check_duplication(option__species__hubbard_j)
685 call parse_block_float(blk, row, icol + 1, hubbard_j)
686 call spec%set_hubbard_u(hubbard_alpha)
687
688 if (abs(abs(spec%get_hubbard_j()-spec%get_hubbard_l())-m_half) <= m_epsilon) then
689 call messages_input_error(namespace, 'Species', "The 'hubbard_j' parameter in species "// &
690 trim(spec%get_label())//" can only be hubbard_l +/- 1/2", row=row, column=icol+1)
691 end if
692
693 case (option__species__mass)
694 call check_duplication(option__species__mass)
695 call parse_block_float(blk, row, icol + 1, mass, unit = units_inp%mass)
696 call spec%set_mass(mass)
697
698 case (option__species__valence)
699 call check_duplication(option__species__valence)
700 call parse_block_float(blk, row, icol + 1, z_val)
701 call spec%set_zval(z_val)
702 call spec%set_z(z_val)
703
704 case (option__species__jellium_radius)
705 call check_duplication(option__species__jellium_radius)
706 call parse_block_float(blk, row, icol + 1, jradius)
707 if (jradius <= m_zero) call messages_input_error(namespace, 'Species', 'jellium_radius must be positive', &
708 row=row, column=icol+1)
709
710 select type(spec)
711 type is(jellium_sphere_t)
712 call spec%set_radius(jradius)
713 class default
714 call messages_input_error(namespace, 'Species', 'jellium_radius can only be used with species_jellium', &
715 row=row, column=icol+1)
716 end select
717
718 case (option__species__gaussian_width)
719 call check_duplication(option__species__gaussian_width)
720 call parse_block_float(blk, row, icol + 1, sigma)
721 if (sigma <= m_zero) call messages_input_error(namespace, 'Species', 'gaussian_width must be positive', &
722 row=row, column=icol+1)
723 select type(spec)
724 type is(full_gaussian_t)
725 call spec%set_sigma(sigma)
726 class default
727 call messages_input_error(namespace, 'Species', 'gaussian_width can only be used with species_full_gaussian', &
728 row=row, column=icol+1)
729 end select
730
731 case (option__species__anc_a)
732 call check_duplication(option__species__anc_a)
733 call parse_block_float(blk, row, icol + 1, aa)
734 if (aa <= m_zero) call messages_input_error(namespace, 'Species', 'anc_a must be positive', &
735 row=row, column=icol+1)
736
737 select type(spec)
738 type is(full_anc_t)
739 call spec%set_a(aa)
740 class default
741 call messages_input_error(namespace, 'Species', 'anc_a can only be used with species_full_anc', &
742 row=row, column=icol+1)
743 end select
744
745 case (option__species__softening)
746 call check_duplication(option__species__softening)
747 call parse_block_float(blk, row, icol + 1, softening)
748 softening = softening**2
749
750 select type(spec)
751 type is(soft_coulomb_t)
752 call spec%set_softening(softening)
753 class default
754 call messages_input_error(namespace, 'Species', 'softening can only be used with species_soft_coulomb', &
755 row=row, column=icol+1)
756 end select
757
758 case (option__species__file)
759 call check_duplication(option__species__file)
760 call parse_block_string(blk, row, icol + 1, filename)
761 call spec%set_filename(filename)
762
763 case (option__species__db_file)
764 call messages_write("The 'db_file' option for 'Species' block is obsolete. Please use", new_line = .true.)
765 call messages_write("the option 'set' or the variable 'PseudopotentialSet' instead.")
766 call messages_fatal(namespace=namespace)
767
768 case (option__species__set)
769 call check_duplication(option__species__set)
770 call parse_block_integer(blk, row, icol + 1, pseudopotential_set_id)
771
772 select type(spec)
773 type is(pseudopotential_t)
774 spec%pseudopotential_set_initialized = .true.
775 spec%pseudopotential_set_id = pseudopotential_set_id
776 call pseudo_set_init(spec%pseudopotential_set, get_set_directory(spec%pseudopotential_set_id), ierr)
777 class default
778 call messages_input_error(namespace, 'Species', 'set can only be used with species_pseudo', &
779 row=row, column=icol+1)
780 end select
781
782 case (option__species__potential_formula)
783 call check_duplication(option__species__potential_formula)
784 select type(spec)
786 call parse_block_string(blk, row, icol + 1, spec%potential_formula)
787 call conv_to_c_string(spec%potential_formula)
788 class default
789 call messages_input_error(namespace, 'Species', 'potential_formula can only be used with species_user_defined', &
790 row=row, column=icol+1)
791 end select
792
793 case (option__species__volume)
794 call check_duplication(option__species__volume)
795
796 select type(spec)
797 type is(jellium_charge_t)
798 call parse_block_string(blk, row, icol + 1, spec%density_formula)
799 call conv_to_c_string(spec%density_formula)
800
801 class default
802 call messages_input_error(namespace, 'Species', 'volume can only be used with species_jellium_charge_density', &
803 row=row, column=icol+1)
804 end select
805
806 case (option__species__density_formula)
807 call check_duplication(option__species__density_formula)
808
809 select type(spec)
811 call parse_block_string(blk, row, icol + 1, spec%density_formula)
812 call conv_to_c_string(spec%density_formula)
813
814 class default
815 call messages_input_error(namespace, 'Species', 'density_formula can only be used with species_charge_density', &
816 row=row, column=icol+1)
817 end select
818
819 case (option__species__thickness)
820 call check_duplication(option__species__thickness)
821 call parse_block_float(blk, row, icol + 1, jthick) ! thickness of the jellium slab
822
823 if (jthick <= m_zero) then
824 call messages_input_error(namespace, 'Species', 'the value of the thickness parameter in species '&
825 //trim(spec%get_label())//' must be positive.', row=row, column=icol+1)
826 end if
827
828 select type(spec)
829 type is(jellium_slab_t)
830 call spec%set_thickness(jthick)
831 class default
832 call messages_input_error(namespace, 'Species', 'thickness can only be used with species_jellium_slab', &
833 row=row, column=icol+1)
834 end select
835
836 case (option__species__vdw_radius)
837 call check_duplication(option__species__vdw_radius)
838 call parse_block_float(blk, row, icol + 1, vdw_radius, unit = units_inp%length)
839 call spec%set_vdw_radius(vdw_radius)
840
841 case default
842 call messages_input_error(namespace, 'Species', "Unknown parameter in species '"//trim(spec%get_label())//"'", &
843 row=row, column=icol)
844
845 end select
846
847 icol = icol + 2
848 end do
849 ! CHECK THAT WHAT WE PARSED MAKES SENSE
850
851 select type(spec)
852 type is(soft_coulomb_t)
853 if (.not. parameter_defined(option__species__softening)) then
854 call messages_input_error(namespace, 'Species', &
855 "The 'softening' parameter is missing for species "//trim(spec%get_label()))
856 end if
857
859 if (.not. parameter_defined(option__species__potential_formula)) then
860 call messages_input_error(namespace, 'Species', &
861 "The 'potential_formula' parameter is missing for species '"//trim(spec%get_label())//"'")
862 end if
863
865 if (.not. parameter_defined(option__species__density_formula)) then
866 call messages_input_error(namespace, 'Species', &
867 "The 'density_formula' parameter is missing for species '"//trim(spec%get_label())//"'")
868 end if
869
870 type is(species_from_file_t)
871 if( .not. (parameter_defined(option__species__file) .or. parameter_defined(option__species__db_file))) then
872 call messages_input_error(namespace, 'Species', &
873 "The 'file' or 'db_file' parameter is missing for species '"//trim(spec%get_label())//"'")
874 end if
875
876 type is(jellium_slab_t)
877 if (.not. parameter_defined(option__species__thickness)) then
878 call messages_input_error(namespace, 'Species', &
879 "The 'thickness' parameter is missing for species '"//trim(spec%get_label())//"'")
880 end if
881
882 type is(jellium_charge_t)
883 if (.not. parameter_defined(option__species__volume)) then
884 call messages_input_error(namespace, 'Species', &
885 "The 'volume' parameter is missing for species '"//trim(spec%get_label())//"'")
886 end if
887
888 type is(pseudopotential_t)
889 if (parameter_defined(option__species__lmax) .and. parameter_defined(option__species__lloc)) then
890 if (spec%get_user_lloc() > spec%get_user_lmax()) then
891 call messages_input_error(namespace, 'Species', &
892 "the 'lloc' parameter cannot be larger than the 'lmax' parameter in species "//trim(spec%get_label()))
893 end if
894 end if
895
896 if(.not. (parameter_defined(option__species__file) .or. parameter_defined(option__species__db_file))) then
897 ! we need to read the species from the pseudopotential set
898
899 !if the set was not defined, use the default set
900 if (.not. parameter_defined(option__species__set)) then
901 spec%pseudopotential_set_id = factory%default_pseudopotential_set_id
902 spec%pseudopotential_set = factory%default_pseudopotential_set
903 end if
904
905 call read_from_set(spec, spec%pseudopotential_set_id, spec%pseudopotential_set, set_read_data)
906
907 if (set_read_data == 0) then
908 call messages_write('Species '//trim(spec%get_label())//' is not defined in the requested pseudopotential set.', &
909 new_line=.true.)
910 call messages_write('( '//trim(get_set_directory(spec%pseudopotential_set_id))//' )')
911 call messages_fatal(namespace=namespace)
912 end if
913 end if
914
915 end select
916
917 select type (spec)
918 class is(pseudopotential_t)
920
921 class is(full_anc_t)
923
924 ! If z_val was not specified, we set it to be z
925 if (spec%get_zval() < m_zero) then
926 call spec%set_zval(spec%get_z())
927 end if
928
929 class is(full_gaussian_t)
931
932 ! If z_val was not specified, we set it to be z
933 if (spec%get_zval() < m_zero) then
934 call spec%set_zval(spec%get_z())
935 end if
936
937 class is(full_delta_t)
939
940 ! If z_val was not specified, we set it to be z
941 if (spec%get_zval() < m_zero) then
942 call spec%set_zval(spec%get_z())
943 end if
944
945 class default
946 if (.not. parameter_defined(option__species__mass)) then
947 call spec%set_mass(m_one)
948 call messages_write('Info: default mass for species '//trim(spec%get_label())//':')
949 call messages_write(spec%get_mass())
950 call messages_write(' amu.')
951 call messages_info(namespace=namespace)
952 end if
953
954 if (.not. parameter_defined(option__species__vdw_radius)) then
955 call spec%set_vdw_radius(m_zero)
956 call messages_write('Info: default vdW radius for species '//trim(spec%get_label())//':')
957 call messages_write(spec%get_vdw_radius())
958 call messages_write(' [b]')
959 call messages_info(namespace=namespace)
960 end if
961
962 if (.not. parameter_defined(option__species__valence)) then
963 if (spec%is_user_defined()) then
964 call spec%set_zval(m_zero)
965 else
966 call messages_input_error(namespace, 'Species', &
967 "The 'valence' parameter is missing for species '"//trim(spec%get_label())//"'")
968 end if
969 end if
970
971 end select
972
973 call iihash_end(read_parameters)
974
975 pop_sub(read_from_block)
976
977 contains
978
979 logical function parameter_defined(param) result(defined)
980 integer(int64), intent(in) :: param
981
982 integer :: tmp
983
985
986 tmp = iihash_lookup(read_parameters, int(-param), defined)
987
989 end function parameter_defined
990
991 !------------------------------------------------------
992 subroutine check_duplication(param)
993 integer(int64), intent(in) :: param
994
996
997 if (parameter_defined(param)) then
998 call messages_input_error(namespace, 'Species', "Duplicated parameter in species '"//trim(spec%get_label())//"'")
999 end if
1000
1001 call iihash_insert(read_parameters, int(-param), 1)
1002
1004 end subroutine check_duplication
1005
1006
1007 !------------------------------------------------------
1008 subroutine check_real_atom_species()
1009
1010 call element_init(element, get_symbol(spec%get_label()))
1011
1012 if (.not. element_valid(element)) then
1013 call messages_write('Cannot determine the element for species '//trim(spec%get_label())//'.')
1014 call messages_fatal(namespace=namespace)
1015 end if
1016
1017 call spec%set_z(real(element_atomic_number(element), real64))
1018
1019 if (spec%get_mass() < m_zero) then
1020 call spec%set_mass(element_mass(element))
1021 call messages_write('Info: default mass for species '//trim(spec%get_label())//':')
1022 call messages_write(spec%get_mass())
1023 call messages_write(' amu.')
1024 call messages_info(namespace=namespace)
1025 end if
1026
1027 if (spec%get_vdw_radius() < m_zero) then
1028 call spec%set_vdw_radius(element_vdw_radius(element))
1029 if (spec%get_vdw_radius() < m_zero) then
1030 call spec%set_vdw_radius(m_zero)
1031 call messages_write("The default vdW radius for species '"//trim(spec%get_label())//"' is not defined.", &
1032 new_line = .true.)
1033 call messages_write("You can specify the vdW radius in %Species block.")
1034 call messages_warning(namespace=namespace)
1035 end if
1036 call messages_write('Info: default vdW radius for species '//trim(spec%get_label())//':')
1037 call messages_write(spec%get_vdw_radius())
1038 call messages_write(' [b]')
1039 call messages_info(namespace=namespace)
1040 end if
1041
1042 call element_end(element)
1043
1044
1045 end subroutine check_real_atom_species
1046 end function read_from_block
1047
1048end module species_factory_oct_m
1049
1050!! Local Variables:
1051!! mode: f90
1052!! coding: utf-8
1053!! End:
subroutine check_duplication(param)
logical function parameter_defined(param)
Delete the C++ object.
Definition: pseudo_set.F90:152
Nullify the C++ pointer.
Definition: pseudo_set.F90:142
logical function, public element_valid(self)
Definition: element.F90:190
real(real64), parameter, public m_zero
Definition: global.F90:188
real(real64), parameter, public m_epsilon
Definition: global.F90:204
type(conf_t), public conf
Global instance of Octopus configuration.
Definition: global.F90:178
real(real64), parameter, public m_half
Definition: global.F90:194
real(real64), parameter, public m_one
Definition: global.F90:189
This module implements a simple hash table for non-negative integer keys and integer values.
Definition: iihash.F90:125
subroutine, public iihash_end(h)
Free a hash table.
Definition: iihash.F90:184
subroutine, public iihash_insert(h, key, val)
Insert a (key, val) pair into the hash table h.
Definition: iihash.F90:206
integer function, public iihash_lookup(h, key, found)
Look up a value in the hash table h. If found is present, it indicates if key could be found in the t...
Definition: iihash.F90:231
subroutine, public iihash_init(h)
Initialize a hash table h.
Definition: iihash.F90:161
Definition: io.F90:114
integer, parameter, public species_charge_density
user-defined function for charge density
Definition: jellium.F90:139
integer, parameter, public species_jellium_charge_density
jellium volume read from file
Definition: jellium.F90:139
integer, parameter, public species_jellium
jellium sphere.
Definition: jellium.F90:139
integer, parameter, public species_from_file
Definition: jellium.F90:139
integer, parameter, public species_usdef
user-defined function for local potential
Definition: jellium.F90:139
integer, parameter, public species_jellium_slab
jellium slab.
Definition: jellium.F90:139
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:537
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1045
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:414
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:713
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:616
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:618
subroutine, public pseudo_set_init(pseudo_set, dirname, ierr)
Definition: pseudo_set.F90:187
character(len=max_path_len) function, public get_set_directory(set_id)
subroutine, public read_from_set(spec, set_id, set, read_data)
Creates a pseudopotential type from a set.
integer, parameter, public species_pseudo
pseudopotential
integer, parameter, public species_pspio
pseudopotential parsed by pspio library
class(species_t) function, pointer species_factory_create_from_input(factory, namespace, label, index)
Reads the information (from the input file) about a species_t variable, initializing part of it (it h...
subroutine, public species_factory_init(factory, namespace)
class(species_t) function, pointer read_from_block(factory, namespace, blk, row, label, index, read_data)
Parses the species block for a given species.
subroutine, public species_factory_end(factory)
character(len=label_len) function, public get_symbol(label)
Definition: species.F90:518
subroutine, public conv_to_c_string(str)
converts to c string
Definition: string.F90:252
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:132
This module defines the unit system, used for input and output.
type(unit_system_t), public units_inp
the units systems for reading and writing
subroutine check_real_atom_species()
An abstract class for species. Derived classes include jellium, all electron, and pseudopotential spe...
Definition: species.F90:143
int true(void)