34 use,
intrinsic :: iso_fortran_env
59 integer,
parameter :: &
60 OUTPUT_COORDINATES = 1, &
67 real(real64),
allocatable :: coords(:,:), gradients(:,:)
68 real(real64),
allocatable :: acc(:,:)
69 real(real64),
allocatable :: tot_force(:,:)
70 real(real64),
allocatable :: vel(:,:)
71 real(real64),
allocatable :: prev_tot_force(:,:)
72 integer,
allocatable :: species(:)
74 real(real64),
allocatable :: mass(:)
75 real(real64),
allocatable :: atom_charges(:,:)
76 character(len=LABEL_LEN),
allocatable :: labels(:)
77 real(real64),
allocatable :: prev_acc(:,:,:)
78 real(real64) :: scc_tolerance
79 class(ions_t),
pointer :: ions => null()
80 type(c_ptr) :: output_handle(2)
81 type(ion_dynamics_t) :: ions_dyn
82 class(lasers_t),
pointer :: lasers => null()
83 logical :: laser_field
84 real(real64) :: field(3)
85 real(real64) :: energy
87 type(TDftbPlus) :: dftbp
107 procedure dftb_constructor
111 integer,
parameter :: &
123 class(dftb_t),
pointer :: sys
124 type(namespace_t),
intent(in) :: namespace
125 type(mpi_grp_t),
intent(in) :: grp
130 message(1) =
"DFTB+ system not available. This feature requires compiling Octopus with the DFTB+ library"
147 subroutine dftb_init(this, namespace, grp)
148 class(dftb_t),
target,
intent(inout) :: this
149 type(namespace_t),
intent(in) :: namespace
150 type(mpi_grp_t),
intent(in) :: grp
152 integer :: ii, jj, ispec
153 character(len=MAX_PATH_LEN) :: slako_dir
154 character(len=1),
allocatable :: max_ang_mom(:)
155 character(len=LABEL_LEN) :: this_max_ang_mom, this_label
156 integer :: n_maxang_block
158 real(real64) :: initial_temp
162 type(fnode),
pointer :: proot, pgeo, pham, pdftb, pmaxang, pslakos, ptype2files, panalysis
163 type(fnode),
pointer :: pparseropts
164 type(fnode),
pointer :: pelecdyn, pperturb, plaser
169 this%namespace = namespace
172 allocate(this%supported_interactions(0))
173 allocate(this%supported_interactions_as_partner(0))
176 call this%quantities%add(
quantity_t(
"position", updated_on_demand = .false.))
177 call this%quantities%add(
quantity_t(
"velocity", updated_on_demand = .false.))
181 this%ions =>
ions_t(namespace, grp)
182 this%n_atom = this%ions%natoms
183 safe_allocate(this%coords(1:3, 1:this%n_atom))
184 safe_allocate(this%acc(1:3, 1:this%n_atom))
185 safe_allocate(this%vel(1:3, 1:this%n_atom))
186 safe_allocate(this%tot_force(1:3, 1:this%n_atom))
187 safe_allocate(this%prev_tot_force(1:3, 1:this%n_atom))
188 safe_allocate(this%gradients(1:3, 1:this%n_atom))
189 safe_allocate(this%species(1:this%n_atom))
190 safe_allocate(this%mass(1:this%n_atom))
191 safe_allocate(this%atom_charges(1:this%n_atom, 1))
192 safe_allocate(this%labels(1:this%ions%nspecies))
193 safe_allocate(max_ang_mom(1:this%ions%nspecies))
198 this%labels(1) = trim(this%ions%atom(1)%label)
200 this%coords = this%ions%pos
202 this%mass = this%ions%mass
203 do ii = 1, this%n_atom
204 if ((ii > 1) .and. .not. (any(this%labels(1:ispec) == this%ions%atom(ii)%label)))
then
206 this%labels(ispec) = trim(this%ions%atom(ii)%label)
209 if (trim(this%ions%atom(ii)%label) == trim(this%labels(jj)))
then
210 this%species(ii) = jj
232 if (
parse_block(namespace,
'MaxAngularMomentum', blk) == 0)
then
234 if (n_maxang_block /= this%ions%nspecies)
then
238 do ii = 1, n_maxang_block
241 if (.not. any([
"s",
"p",
"d",
"f"] == trim(adjustl(this_max_ang_mom))))
then
242 call messages_input_error(namespace,
"MaxAngularMomentum",
"Wrong maximum angular momentum for element"//trim(this_label))
244 do jj = 1, this%ions%nspecies
245 if (trim(adjustl(this_label)) == trim(adjustl(this%labels(jj))))
then
246 max_ang_mom(jj) = trim(adjustl(this_max_ang_mom))
269 if (this%dynamics ==
bo)
then
287 if (this%lasers%no_lasers > 0)
then
288 this%laser_field = .
true.
290 this%laser_field = .false.
294 call tdftbplus_init(this%dftbp)
296 call this%dftbp%getEmptyInput(
input)
297 call input%getRootNode(proot)
298 call setchild(proot,
"Geometry", pgeo)
299 call setchildvalue(pgeo,
"Periodic", .false.)
300 call setchildvalue(pgeo,
"TypeNames", this%labels(1:this%ions%nspecies))
301 call setchildvalue(pgeo,
"TypesAndCoordinates", reshape(this%species, [1,
size(this%species)]), this%coords)
302 call setchild(proot,
"Hamiltonian", pham)
303 call setchild(pham,
"Dftb", pdftb)
304 call setchildvalue(pdftb,
"Scc", .
true.)
313 call parse_variable(namespace,
'SccTolerance', 1e-9_real64, this%scc_tolerance)
315 call setchildvalue(pdftb,
"SccTolerance", this%scc_tolerance)
318 call setchild(pdftb,
"MaxAngularMomentum", pmaxang)
320 do ii = 1, this%ions%nspecies
321 call setchildvalue(pmaxang, this%labels(ii), max_ang_mom(ii))
327 call setchild(pdftb,
"SlaterKosterFiles", pslakos)
328 call setchild(pslakos,
"Type2FileNames", ptype2files)
329 call setchildvalue(ptype2files,
"Prefix", slako_dir)
330 call setchildvalue(ptype2files,
"Separator",
"-")
331 call setchildvalue(ptype2files,
"Suffix",
".skf")
334 call setchild(proot,
"Analysis", panalysis)
335 call setchildvalue(panalysis,
"CalculateForces", .
true.)
337 call setchild(proot,
"ParserOptions", pparseropts)
338 call setchildvalue(pparseropts,
"ParserVersion", 5)
340 if (this%dynamics == ehrenfest)
then
341 call setchild(proot,
"ElectronDynamics", pelecdyn)
342 call setchildvalue(pelecdyn,
"IonDynamics", this%ions_dyn%is_active())
343 if (this%ions_dyn%is_active())
then
344 call setchildvalue(pelecdyn,
"InitialTemperature", initial_temp)
348 call setchildvalue(pelecdyn,
"Steps", 1)
349 call setchildvalue(pelecdyn,
"TimeStep",
m_one)
350 call setchild(pelecdyn,
"Perturbation", pperturb)
351 if (this%laser_field)
then
352 call setchild(pperturb,
"Laser", plaser)
354 call setchildvalue(plaser,
"LaserEnergy",
m_one)
355 call setchildvalue(pelecdyn,
"FieldStrength",
m_one)
357 call setchild(pperturb,
"None", plaser)
361 message(1) =
'Input tree in HSD format:'
363 call dumphsd(
input%hsdTree, stdout)
366 call this%dftbp%setupCalculator(
input)
367 call this%dftbp%setGeometry(this%coords)
375 class(
dftb_t),
target,
intent(inout) :: this
380 select type (interaction)
382 message(1) =
"Trying to initialize an unsupported interaction by DFTB+."
391 class(
dftb_t),
intent(inout) :: this
396 select type (algo => this%algo)
398 select case (this%dynamics)
400 call this%dftbp%getGradients(this%gradients)
401 this%tot_force = -this%gradients
403 call this%dftbp%getEnergy(this%energy)
404 call this%dftbp%initializeTimeProp(algo%dt, this%laser_field, .false.)
414 class(
dftb_t),
intent(inout) :: this
416 character(len=:),
allocatable,
intent(out) :: updated_quantities(:)
418 integer :: ii, jj, il
419 type(
tdf_t) :: ff, phi
420 complex(real64) :: amp, pol(3)
421 real(real64) :: time, omega
424 call profiling_in(trim(this%namespace%get())//
":"//trim(operation%id))
426 select type (algo => this%algo)
430 select case (this%dynamics)
433 select case (operation%id)
438 safe_allocate(this%prev_acc(1:3, 1:this%n_atom, 1))
439 do jj = 1, this%n_atom
440 this%acc(1:3, jj) = this%tot_force(1:3, jj) / this%mass(jj)
444 safe_deallocate_a(this%prev_acc)
447 do jj = 1, this%n_atom
448 this%coords(1:3, jj) = this%coords(1:3, jj) + algo%dt * this%vel(1:3, jj) &
449 +
m_half * algo%dt**2 * this%acc(1:3, jj)
451 updated_quantities = [
"position"]
454 do ii =
size(this%prev_acc, dim=3) - 1, 1, -1
455 this%prev_acc(1:3, 1:this%n_atom, ii + 1) = this%prev_acc(1:3, 1:this%n_atom, ii)
457 this%prev_acc(1:3, 1:this%n_atom, 1) = this%acc(1:3, 1:this%n_atom)
459 call this%dftbp%setGeometry(this%coords)
460 call this%dftbp%getGradients(this%gradients)
461 this%tot_force = -this%gradients
463 do jj = 1, this%n_atom
464 this%acc(1:3, jj) = this%tot_force(1:3, jj) / this%mass(jj)
468 this%vel(1:3, 1:this%n_atom) = this%vel(1:3, 1:this%n_atom) &
469 +
m_half * algo%dt * (this%prev_acc(1:3, 1:this%n_atom, 1) + &
470 this%acc(1:3, 1:this%n_atom))
471 updated_quantities = [
"velocity"]
479 select case (operation%id)
488 time = this%iteration%value()
489 do il = 1, this%lasers%no_lasers
496 amp =
tdf(ff, time) *
exp(
m_zi * (omega*time +
tdf(phi, time)))
497 this%field(1:3) = this%field(1:3) + real(amp*pol(1:3), real64)
500 call this%dftbp%setTdElectricField(this%field)
501 call this%dftbp%doOneTdStep(this%iteration%counter(), atomnetcharges=this%atom_charges, coord=this%coords,&
502 force=this%tot_force, energy=this%energy)
516 call profiling_out(trim(this%namespace%get())//
":"//trim(operation%id))
522 class(
dftb_t),
intent(in) :: this
523 real(real64),
intent(in) :: tol
536 class(
dftb_t),
intent(inout) :: this
540 select type (algo => this%algo)
543 call io_mkdir(
'td.general', this%namespace)
545 call write_iter_init(this%output_handle(output_coordinates), 0, algo%dt, &
546 trim(
io_workpath(
"td.general/coordinates", this%namespace)))
548 trim(
io_workpath(
"td.general/forces", this%namespace)))
552 call this%output_write()
560 class(
dftb_t),
intent(inout) :: this
564 select type (algo => this%algo)
577 class(
dftb_t),
intent(inout) :: this
579 integer :: idir, iat, iout
580 character(len=50) :: aux
581 character(1) :: out_label(2)
582 real(real64) :: tmp(3)
587 call profiling_in(trim(this%namespace%get())//
":"//
"OUTPUT_WRITE")
589 select type (algo => this%algo)
594 if (this%iteration%counter() == 0)
then
598 call write_iter_string(this%output_handle(iout),
'#####################################################################')
606 do iat = 1, this%n_atom
608 write(aux,
'(a1,a1,i3,a1,i3,a1)') out_label(iout),
'(', iat,
',', idir,
')'
619 do iat = 1, this%n_atom
628 call write_iter_string(this%output_handle(iout),
'#######################################################################')
636 do iat = 1, this%n_atom
650 call profiling_out(trim(this%namespace%get())//
":"//
"OUTPUT_WRITE")
656 class(
dftb_t),
intent(in) :: partner
661 select type (interaction)
663 message(1) =
"Unsupported interaction."
672 class(
dftb_t),
intent(inout) :: partner
677 select type (interaction)
679 message(1) =
"Unsupported interaction."
688 class(
dftb_t),
intent(inout) :: this
693 this%prev_tot_force(1:3, 1:this%n_atom) = this%tot_force(1:3, 1:this%n_atom)
700 class(
dftb_t),
intent(inout) :: this
704 this%kinetic_energy =
m_zero
711 class(
dftb_t),
intent(inout) :: this
715 message(1) =
"DFTB system "//trim(this%namespace%get())//
" cannot write restart data."
724 class(
dftb_t),
intent(inout) :: this
736 type(
dftb_t),
intent(inout) :: this
740 safe_deallocate_a(this%coords)
741 safe_deallocate_a(this%acc)
742 safe_deallocate_a(this%vel)
743 safe_deallocate_a(this%tot_force)
744 safe_deallocate_a(this%prev_tot_force)
745 safe_deallocate_a(this%gradients)
746 safe_deallocate_a(this%species)
747 safe_deallocate_a(this%mass)
750 deallocate(this%ions)
753 if (
associated(this%lasers))
then
754 deallocate(this%lasers)
758 call tdftbplus_destruct(this%dftbp)
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Writes to the corresponding file and adds one to the iteration. Must be called after write_iter_init(...
double exp(double __x) __attribute__((__nothrow__
This module implements the basic elements defining algorithms.
subroutine dftb_output_write(this)
subroutine dftb_update_interactions_start(this)
subroutine dftb_init_interaction_as_partner(partner, interaction)
subroutine dftb_output_finish(this)
subroutine dftb_restart_write_data(this)
subroutine dftb_init_interaction(this, interaction)
logical function dftb_restart_read_data(this)
logical function dftb_do_algorithmic_operation(this, operation, updated_quantities)
subroutine dftb_update_kinetic_energy(this)
subroutine dftb_initialize(this)
integer, parameter output_forces
class(dftb_t) function, pointer dftb_constructor(namespace, grp)
The factory routine (or constructor) allocates a pointer of the corresponding type and then calls the...
subroutine dftb_finalize(this)
logical function dftb_is_tolerance_reached(this, tol)
subroutine dftb_output_start(this)
subroutine, public dftb_init(this, namespace, grp)
The init routine is a module level procedure This has the advantage that different classes can have d...
subroutine dftb_copy_quantities_to_interaction(partner, interaction)
real(real64), parameter, public m_zero
complex(real64), parameter, public m_zi
real(real64), parameter, public m_half
real(real64), parameter, public m_one
This module defines the abstract interaction_t class, and some auxiliary classes for interactions.
character(len=max_path_len) function, public io_workpath(path, namespace)
construct path name from given name and namespace
subroutine, public io_mkdir(fname, namespace, parents)
subroutine, public ion_dynamics_unfreeze(this)
Unfreezes the ionic movement.
subroutine, public ion_dynamics_init(this, namespace, ions, symmetrize, symm)
subroutine, public ion_dynamics_end(this)
complex(real64) function, dimension(3), public laser_polarization(laser)
subroutine, public lasers_parse_external_fields(this)
subroutine, public laser_get_f(laser, ff)
real(real64) function, public laser_carrier_frequency(laser)
subroutine, public laser_get_phi(laser, phi)
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
character(len=512), private msg
subroutine, public messages_warning(no_lines, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
type(mpi_grp_t), public mpi_world
This module implements the multisystem debug functionality.
subroutine, public parse_block_string(blk, l, c, res, convert_to_c)
integer function, public parse_block(namespace, name, blk, check_varinfo_)
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
This module implements the basic propagator framework.
character(len=algo_label_len), parameter, public store_current_status
character(len=30), parameter, public verlet_start
character(len=30), parameter, public verlet_compute_acc
character(len=30), parameter, public verlet_update_pos
character(len=30), parameter, public verlet_finish
character(len=30), parameter, public verlet_compute_vel
This module defines the quantity_t class and the IDs for quantities, which can be exposed by a system...
This module implements the abstract system type.
subroutine, public system_end(this)
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
character(len=20) pure function, public units_abbrev(this)
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_t), public unit_kelvin
For converting energies into temperatures.
Explicit interfaces to C functions, defined in write_iter_low.cc.
subroutine, public write_iter_header(out, string)
subroutine, public write_iter_string(out, string)
subroutine, public write_iter_init(out, iter, factor, file)
Descriptor of one algorithmic operation.
class for a tight binding
abstract interaction class
surrogate interaction class to avoid circular dependencies between modules.
Abstract class implementing propagators.
Systems (system_t) can expose quantities that can be used to calculate interactions with other system...
Abstract class for systems.