Octopus
phonons_fd.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use debug_oct_m
26 use global_oct_m
27 use grid_oct_m
30 use ions_oct_m
31 use, intrinsic :: iso_fortran_env
32 use mesh_oct_m
37 use parser_oct_m
40 use scf_oct_m
41 use space_oct_m
46 use utils_oct_m
47 use v_ks_oct_m
49
50 implicit none
51
52 private
53 public :: phonons_run
54
55contains
56
57 ! ---------------------------------------------------------
58 subroutine phonons_run(system)
59 class(*), intent(inout) :: system
60
61 push_sub(phonons_run)
62
63 select type (system)
64 class is (multisystem_basic_t)
65 message(1) = "CalculationMode = vib_modes not implemented for multi-system calculations"
66 call messages_fatal(1, namespace=system%namespace)
67 type is (electrons_t)
68 call phonons_run_legacy(system)
69 end select
70
71 pop_sub(phonons_run)
72 end subroutine phonons_run
73
74 ! ---------------------------------------------------------
75 subroutine phonons_run_legacy(sys)
76 type(electrons_t), intent(inout) :: sys
77
78 type(vibrations_t) :: vib
79 integer :: ierr
80 type(restart_t) :: gs_restart
81
82 push_sub(phonons_run_legacy)
83
84 if (sys%hm%pcm%run_pcm) then
85 call messages_not_implemented("PCM for CalculationMode /= gs or td", namespace=sys%namespace)
86 end if
87
88 ! Why not? The symmetries are computed only for the unperturbed geometry,
89 ! and are not valid when the atoms are displaced.
90 ! FIXME: implement instead use of symmetry over dynamical matrix to make things more efficient.
91 if (sys%st%symmetrize_density .or. sys%kpoints%use_symmetries) then
92 message(1) = "Cannot compute vibrational modes by finite differences when symmetry is being used."
93 message(2) = "Set KPointsUseSymmetries = no and SymmetrizeDensity = no, for gs run and this run."
94 call messages_fatal(2, namespace=sys%namespace)
95 end if
96
97 call states_elec_allocate_wfns(sys%st, sys%gr)
98
99 ! load wavefunctions
100 call gs_restart%init(sys%namespace, restart_gs, restart_type_load, sys%mc, ierr, mesh=sys%gr, exact=.true.)
101 if (ierr == 0) then
102 call states_elec_load(gs_restart, sys%namespace, sys%space, sys%st, sys%gr, sys%kpoints, &
103 fixed_occ=.false., ierr=ierr)
104 end if
105 if (ierr /= 0) then
106 message(1) = "Unable to read wavefunctions."
107 call messages_fatal(1, namespace=sys%namespace)
108 end if
109 call gs_restart%end()
110
111 ! setup Hamiltonian
112 message(1) = 'Info: Setting up Hamiltonian.'
113 call messages_info(1, namespace=sys%namespace)
114 call v_ks_h_setup(sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st, sys%ks, sys%hm)
115
116 call vibrations_init(vib, sys%ions%space, sys%ions%natoms, sys%ions%mass, "fd", sys%namespace)
117
118 !%Variable Displacement
119 !%Type float
120 !%Default 0.01 a.u.
121 !%Section Linear Response::Vibrational Modes
122 !%Description
123 !% When calculating phonon properties by finite differences (<tt>CalculationMode = vib_modes,
124 !% ResponseMethod = finite_differences</tt>),
125 !% <tt>Displacement</tt> controls how much the atoms are to be moved in order to calculate the
126 !% dynamical matrix.
127 !%End
128 call parse_variable(sys%namespace, 'Displacement', 0.01_real64, vib%disp, units_inp%length)
129
130 ! calculate dynamical matrix
131 call get_dyn_matrix(sys%gr, sys%namespace, sys%mc, sys%ions, sys%ext_partners, sys%st, sys%ks, &
132 sys%hm, vib, sys%space)
133
134 call vibrations_output(vib)
135
136 call vibrations_end(vib)
137
138 call states_elec_deallocate_wfns(sys%st)
139 pop_sub(phonons_run_legacy)
140
141 end subroutine phonons_run_legacy
142
143 ! ---------------------------------------------------------
145 subroutine get_dyn_matrix(gr, namespace, mc, ions, ext_partners, st, ks, hm, vib, space)
146 type(grid_t), target, intent(inout) :: gr
147 type(namespace_t), intent(in) :: namespace
148 type(multicomm_t), intent(in) :: mc
149 type(ions_t), intent(inout) :: ions
150 type(partner_list_t), intent(in) :: ext_partners
151 type(states_elec_t), intent(inout) :: st
152 type(v_ks_t), intent(inout) :: ks
153 type(hamiltonian_elec_t), intent(inout) :: hm
154 type(vibrations_t), intent(inout) :: vib
155 type(electron_space_t), intent(in) :: space
156
157 type(scf_t) :: scf
158 integer :: iatom, jatom, alpha, beta, imat, jmat
159 real(real64), allocatable :: forces(:, :), forces0(:, :)
160
161 push_sub(get_dyn_matrix)
162
163
164 call scf_init(scf, namespace, gr, ions, st, mc, hm, space)
165 safe_allocate(forces0(1:space%dim, 1:ions%natoms))
166 safe_allocate(forces(1:space%dim, 1:ions%natoms))
167 forces = m_zero
168 forces0 = m_zero
169
170 do iatom = 1, ions%natoms
171 do alpha = 1, space%dim
172 imat = vibrations_get_index(vib, iatom, alpha)
173
174 call messages_new_line()
175 call messages_print_with_emphasis(namespace=namespace)
176 write(message(1), '(a,i5,3a)') 'Info: Moving atom ', iatom, ' in the +', index2axis(alpha), '-direction.'
177 call messages_info(1, namespace=namespace)
178 call messages_print_with_emphasis(namespace=namespace)
179
180 ! move atom iatom in direction alpha by dist
181 ions%pos(alpha, iatom) = ions%pos(alpha, iatom) + vib%disp
182
183 ! first force
184 call run_displacement()
185 forces0(:, :) = ions%tot_force(:, :)
186
187 call messages_new_line()
188 call messages_print_with_emphasis(namespace=namespace)
189 write(message(1), '(a,i5,3a)') 'Info: Moving atom ', iatom, ' in the -', index2axis(alpha), '-direction.'
190 call messages_info(1, namespace=namespace)
191 call messages_print_with_emphasis(namespace=namespace)
192
193 ions%pos(alpha, iatom) = ions%pos(alpha, iatom) - m_two*vib%disp
194
195 ! second force
196 call run_displacement()
197 forces(:, :) = ions%tot_force(:, :)
198
199 ions%pos(alpha, iatom) = ions%pos(alpha, iatom) + vib%disp
200
201 do jatom = 1, ions%natoms
202 do beta = 1, space%dim
203 jmat = vibrations_get_index(vib, jatom, beta)
204 vib%dyn_matrix(jmat, imat) = (forces0(beta, jatom) - forces(beta, jatom)) / (m_two*vib%disp) &
205 * vibrations_norm_factor(vib, iatom, jatom)
206 end do
207 end do
208 call vibrations_out_dyn_matrix_row(vib, imat)
209
210 end do
211 end do
212 safe_deallocate_a(forces0)
213 safe_deallocate_a(forces)
214 call scf_end(scf)
215
218
219 pop_sub(get_dyn_matrix)
220 contains
221
223 !TODO: The same code is called in the GO run mode. This should be combined
224 subroutine run_displacement()
226
227 call hamiltonian_elec_epot_generate(hm, namespace, space, gr, ions, ext_partners, st)
228 call density_calc(st, gr, st%rho)
229 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval=.true.)
230 call energy_calc_total(namespace, space, hm, gr, st, ext_partners)
231 call scf_mix_clear(scf)
232 call scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, verbosity = verb_compact)
233
235 end subroutine run_displacement
236
237 end subroutine get_dyn_matrix
238
239end module phonons_fd_oct_m
241!! Local Variables:
242!! mode: f90
243!! coding: utf-8
244!! End:
This module implements a calculator for the density and defines related functions.
Definition: density.F90:122
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:653
subroutine, public energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit, full)
This subroutine calculates the total energy of the system. Basically, it adds up the KS eigenvalues,...
real(real64), parameter, public m_two
Definition: global.F90:202
real(real64), parameter, public m_zero
Definition: global.F90:200
This module implements the underlying real-space grid.
Definition: grid.F90:119
subroutine, public hamiltonian_elec_epot_generate(this, namespace, space, gr, ions, ext_partners, st, time)
This module defines classes and functions for interaction partners.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:898
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
subroutine, public messages_new_line()
Definition: messages.F90:1089
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_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
This module implements the basic mulsisystem class, a container system for other systems.
subroutine get_dyn_matrix(gr, namespace, mc, ions, ext_partners, st, ks, hm, vib, space)
Computes the second-order force constant from finite differences.
Definition: phonons_fd.F90:241
subroutine phonons_run_legacy(sys)
Definition: phonons_fd.F90:171
subroutine, public phonons_run(system)
Definition: phonons_fd.F90:154
integer, parameter, public restart_gs
Definition: restart.F90:156
integer, parameter, public restart_type_load
Definition: restart.F90:184
subroutine, public scf_mix_clear(scf)
Definition: scf.F90:588
integer, parameter, public verb_compact
Definition: scf.F90:207
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
Definition: scf.F90:260
subroutine, public scf_end(scf)
Definition: scf.F90:558
subroutine, public scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, verbosity, iters_done, restart_dump)
Legacy version of the SCF code.
Definition: scf.F90:834
subroutine, public states_elec_deallocate_wfns(st)
Deallocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
Allocates the KS wavefunctions defined within a states_elec_t structure.
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_load(restart, namespace, space, st, mesh, kpoints, fixed_occ, ierr, iter, lr, lowest_missing, label, verbose, skip)
returns in ierr: <0 => Fatal error, or nothing read =0 => read all wavefunctions >0 => could only rea...
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
This module is intended to contain simple general-purpose utility functions and procedures.
Definition: utils.F90:120
character pure function, public index2axis(idir)
Definition: utils.F90:205
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
Definition: v_ks.F90:754
subroutine, public v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
Definition: v_ks.F90:700
real(real64) pure function, public vibrations_norm_factor(this, iatom, jatom)
Definition: vibrations.F90:262
subroutine, public vibrations_diag_dyn_matrix(this)
Diagonalize the dynamical matrix.
Definition: vibrations.F90:321
subroutine, public vibrations_out_dyn_matrix_row(this, imat)
Outputs one row of the dynamical matrix.
Definition: vibrations.F90:274
subroutine, public vibrations_init(this, space, natoms, mass, suffix, namespace)
Definition: vibrations.F90:169
subroutine, public vibrations_symmetrize_dyn_matrix(this)
Symmetrize the dynamical matric, which is real symmetric matrix.
Definition: vibrations.F90:232
integer pure function, public vibrations_get_index(this, iatom, idim)
Definition: vibrations.F90:355
subroutine, public vibrations_output(this)
Outputs the eigenvectors and eigenenergies of the dynamical matrix.
Definition: vibrations.F90:384
subroutine, public vibrations_end(this)
Definition: vibrations.F90:208
subroutine run_displacement()
Runs GS for a given displaced atomic position.
Definition: phonons_fd.F90:320
Extension of space that contains the knowledge of the spin dimension.
Class describing the electron system.
Definition: electrons.F90:221
Container class for lists of system_oct_m::system_t.
some variables used for the SCF cycle
Definition: scf.F90:213
int true(void)