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