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
142 class(dftb_t),
target,
intent(inout) :: this
143 type(namespace_t),
intent(in) :: namespace
145 integer :: ii, jj, ispec
146 character(len=MAX_PATH_LEN) :: slako_dir
147 character(len=1),
allocatable :: max_ang_mom(:)
148 character(len=LABEL_LEN) :: this_max_ang_mom, this_label
149 integer :: n_maxang_block
151 real(real64) :: initial_temp
154 type(tdftbplusinput) ::
input
155 type(fnode),
pointer :: proot, pgeo, pham, pdftb, pmaxang, pslakos, ptype2files, panalysis
156 type(fnode),
pointer :: pparseropts
157 type(fnode),
pointer :: pelecdyn, pperturb, plaser
162 this%namespace = namespace
165 allocate(this%supported_interactions(0))
166 allocate(this%supported_interactions_as_partner(0))
171 this%n_atom = this%ions%natoms
172 safe_allocate(this%coords(1:3, 1:this%n_atom))
173 safe_allocate(this%acc(1:3, 1:this%n_atom))
174 safe_allocate(this%vel(1:3, 1:this%n_atom))
175 safe_allocate(this%tot_force(1:3, 1:this%n_atom))
176 safe_allocate(this%prev_tot_force(1:3, 1:this%n_atom))
177 safe_allocate(this%gradients(1:3, 1:this%n_atom))
178 safe_allocate(this%species(1:this%n_atom))
179 safe_allocate(this%mass(1:this%n_atom))
180 safe_allocate(this%atom_charges(1:this%n_atom, 1))
181 safe_allocate(this%labels(1:this%ions%nspecies))
182 safe_allocate(max_ang_mom(1:this%ions%nspecies))
186 this%labels(1) = trim(this%ions%atom(1)%label)
188 this%coords = this%ions%pos
190 this%mass = this%ions%mass
191 do ii = 1, this%n_atom
192 if ((ii > 1) .and. .not. (any(this%labels(1:ispec) == this%ions%atom(ii)%label)))
then
194 this%labels(ispec) = trim(this%ions%atom(ii)%label)
197 if (trim(this%ions%atom(ii)%label) == trim(this%labels(jj)))
then
198 this%species(ii) = jj
220 if (
parse_block(namespace,
'MaxAngularMomentum', blk) == 0)
then
222 if (n_maxang_block /= this%ions%nspecies)
then
226 do ii = 1, n_maxang_block
229 if (any([
"s",
"p",
"d",
"f"] == trim(this_max_ang_mom)))
then
230 call messages_input_error(namespace,
"MaxAngularMomentum",
"Wrong maximum angular momentum for element"//trim(this_label))
232 do jj = 1, this%ions%nspecies
233 if (trim(adjustl(this_label)) == trim(adjustl(this%labels(jj))))
then
234 max_ang_mom(jj) = trim(adjustl(this_max_ang_mom))
257 if (this%dynamics ==
bo)
then
275 if (this%lasers%no_lasers > 0)
then
276 this%laser_field = .
true.
278 this%laser_field = .false.
282 call tdftbplus_init(this%dftbp)
284 call this%dftbp%getEmptyInput(
input)
285 call input%getRootNode(proot)
286 call setchild(proot,
"Geometry", pgeo)
287 call setchildvalue(pgeo,
"Periodic", .false.)
288 call setchildvalue(pgeo,
"TypeNames", this%labels(1:this%ions%nspecies))
289 call setchildvalue(pgeo,
"TypesAndCoordinates", reshape(this%species, [1,
size(this%species)]), this%coords)
290 call setchild(proot,
"Hamiltonian", pham)
291 call setchild(pham,
"Dftb", pdftb)
292 call setchildvalue(pdftb,
"Scc", .
true.)
301 call parse_variable(namespace,
'SccTolerance', 1e-9_real64, this%scc_tolerance)
303 call setchildvalue(pdftb,
"SccTolerance", this%scc_tolerance)
306 call setchild(pdftb,
"MaxAngularMomentum", pmaxang)
308 do ii = 1, this%ions%nspecies
309 call setchildvalue(pmaxang, this%labels(ii), max_ang_mom(ii))
315 call setchild(pdftb,
"SlaterKosterFiles", pslakos)
316 call setchild(pslakos,
"Type2FileNames", ptype2files)
317 call setchildvalue(ptype2files,
"Prefix", slako_dir)
318 call setchildvalue(ptype2files,
"Separator",
"-")
319 call setchildvalue(ptype2files,
"Suffix",
".skf")
322 call setchild(proot,
"Analysis", panalysis)
323 call setchildvalue(panalysis,
"CalculateForces", .
true.)
325 call setchild(proot,
"ParserOptions", pparseropts)
326 call setchildvalue(pparseropts,
"ParserVersion", 5)
328 if (this%dynamics == ehrenfest)
then
329 call setchild(proot,
"ElectronDynamics", pelecdyn)
332 call setchildvalue(pelecdyn,
"InitialTemperature", initial_temp)
336 call setchildvalue(pelecdyn,
"Steps", 1)
337 call setchildvalue(pelecdyn,
"TimeStep",
m_one)
338 call setchild(pelecdyn,
"Perturbation", pperturb)
339 if (this%laser_field)
then
340 call setchild(pperturb,
"Laser", plaser)
342 call setchildvalue(plaser,
"LaserEnergy",
m_one)
343 call setchildvalue(pelecdyn,
"FieldStrength",
m_one)
345 call setchild(pperturb,
"None", plaser)
349 message(1) =
'Input tree in HSD format:'
351 call dumphsd(
input%hsdTree, stdout)
354 call this%dftbp%setupCalculator(
input)
355 call this%dftbp%setGeometry(this%coords)
363 class(
dftb_t),
target,
intent(inout) :: this
368 select type (interaction)
370 message(1) =
"Trying to initialize an unsupported interaction by DFTB+."
379 class(
dftb_t),
intent(inout) :: this
384 select type (algo => this%algo)
386 select case (this%dynamics)
388 call this%dftbp%getGradients(this%gradients)
389 this%tot_force = -this%gradients
391 call this%dftbp%getEnergy(this%energy)
392 call this%dftbp%initializeTimeProp(algo%dt, this%laser_field, .false.)
402 class(
dftb_t),
intent(inout) :: this
404 integer,
allocatable,
intent(out) :: updated_quantities(:)
406 integer :: ii, jj, il
407 type(
tdf_t) :: ff, phi
408 complex(real64) :: amp, pol(3)
409 real(real64) :: time, omega
412 call profiling_in(trim(this%namespace%get())//
":"//trim(operation%id))
414 select type (algo => this%algo)
418 select case (this%dynamics)
421 select case (operation%id)
426 safe_allocate(this%prev_acc(1:3, 1:this%n_atom, 1))
427 do jj = 1, this%n_atom
428 this%acc(1:3, jj) = this%tot_force(1:3, jj) / this%mass(jj)
432 safe_deallocate_a(this%prev_acc)
435 do jj = 1, this%n_atom
436 this%coords(1:3, jj) = this%coords(1:3, jj) + algo%dt * this%vel(1:3, jj) &
437 +
m_half * algo%dt**2 * this%acc(1:3, jj)
442 do ii =
size(this%prev_acc, dim=3) - 1, 1, -1
443 this%prev_acc(1:3, 1:this%n_atom, ii + 1) = this%prev_acc(1:3, 1:this%n_atom, ii)
445 this%prev_acc(1:3, 1:this%n_atom, 1) = this%acc(1:3, 1:this%n_atom)
447 call this%dftbp%setGeometry(this%coords)
448 call this%dftbp%getGradients(this%gradients)
449 this%tot_force = -this%gradients
451 do jj = 1, this%n_atom
452 this%acc(1:3, jj) = this%tot_force(1:3, jj) / this%mass(jj)
456 this%vel(1:3, 1:this%n_atom) = this%vel(1:3, 1:this%n_atom) &
457 +
m_half * algo%dt * (this%prev_acc(1:3, 1:this%n_atom, 1) + &
458 this%acc(1:3, 1:this%n_atom))
467 select case (operation%id)
476 time = this%iteration%value()
477 do il = 1, this%lasers%no_lasers
484 amp =
tdf(ff, time) *
exp(
m_zi * (omega*time +
tdf(phi, time)))
485 this%field(1:3) = this%field(1:3) + real(amp*pol(1:3), real64)
488 call this%dftbp%setTdElectricField(this%field)
489 call this%dftbp%doOneTdStep(this%iteration%counter(), atomnetcharges=this%atom_charges, coord=this%coords,&
490 force=this%tot_force, energy=this%energy)
504 call profiling_out(trim(this%namespace%get())//
":"//trim(operation%id))
510 class(
dftb_t),
intent(in) :: this
511 real(real64),
intent(in) :: tol
524 class(
dftb_t),
intent(inout) :: this
528 select type (algo => this%algo)
531 call io_mkdir(
'td.general', this%namespace)
533 call write_iter_init(this%output_handle(output_coordinates), 0, algo%dt, &
534 trim(
io_workpath(
"td.general/coordinates", this%namespace)))
536 trim(
io_workpath(
"td.general/forces", this%namespace)))
540 call this%output_write()
548 class(
dftb_t),
intent(inout) :: this
552 select type (algo => this%algo)
565 class(
dftb_t),
intent(inout) :: this
567 integer :: idir, iat, iout
568 character(len=50) :: aux
569 character(1) :: out_label(2)
570 real(real64) :: tmp(3)
575 call profiling_in(trim(this%namespace%get())//
":"//
"OUTPUT_WRITE")
577 select type (algo => this%algo)
582 if (this%iteration%counter() == 0)
then
586 call write_iter_string(this%output_handle(iout),
'#####################################################################')
594 do iat = 1, this%n_atom
596 write(aux,
'(a1,a1,i3,a1,i3,a1)') out_label(iout),
'(', iat,
',', idir,
')'
607 do iat = 1, this%n_atom
616 call write_iter_string(this%output_handle(iout),
'#######################################################################')
624 do iat = 1, this%n_atom
638 call profiling_out(trim(this%namespace%get())//
":"//
"OUTPUT_WRITE")
644 class(
dftb_t),
intent(in) :: partner
649 select type (interaction)
651 message(1) =
"Unsupported interaction."
660 class(
dftb_t),
intent(inout) :: partner
665 select type (interaction)
667 message(1) =
"Unsupported interaction."
676 class(
dftb_t),
intent(inout) :: this
681 this%prev_tot_force(1:3, 1:this%n_atom) = this%tot_force(1:3, 1:this%n_atom)
688 class(
dftb_t),
intent(inout) :: this
692 this%kinetic_energy =
m_zero
699 class(
dftb_t),
intent(inout) :: this
703 message(1) =
"DFTB system "//trim(this%namespace%get())//
" cannot write restart data."
712 class(
dftb_t),
intent(inout) :: this
724 type(
dftb_t),
intent(inout) :: this
728 safe_deallocate_a(this%coords)
729 safe_deallocate_a(this%acc)
730 safe_deallocate_a(this%vel)
731 safe_deallocate_a(this%tot_force)
732 safe_deallocate_a(this%prev_tot_force)
733 safe_deallocate_a(this%gradients)
734 safe_deallocate_a(this%species)
735 safe_deallocate_a(this%mass)
738 deallocate(this%ions)
741 if (
associated(this%lasers))
then
742 deallocate(this%lasers)
746 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)
class(dftb_t) function, pointer dftb_constructor(namespace)
The factory routine (or constructor) allocates a pointer of the corresponding type and then calls the...
subroutine, public dftb_init(this, namespace)
The init routine is a module level procedure This has the advantage that different classes can have d...
subroutine dftb_update_kinetic_energy(this)
integer, parameter output_forces
subroutine dftb_finalize(this)
subroutine dftb_initial_conditions(this)
logical function dftb_is_tolerance_reached(this, tol)
subroutine dftb_output_start(this)
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)
subroutine, public io_mkdir(fname, namespace, parents)
logical pure function, public ion_dynamics_ions_move(this)
subroutine, public ion_dynamics_unfreeze(this)
Unfreezes the ionic movement.
subroutine, public ion_dynamics_init(this, namespace, ions)
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)
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, 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)
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
type(mpi_grp_t), public mpi_world
This module implements the multisystem debug functionality.
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...
integer, parameter, public velocity
integer, parameter, public position
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.
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.
Abstract class for systems.