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
27 use global_oct_m
28 use grid_oct_m
31 use ions_oct_m
32 use, intrinsic :: iso_fortran_env
33 use mesh_oct_m
39 use parser_oct_m
42 use scf_oct_m
43 use space_oct_m
48 use utils_oct_m
49 use v_ks_oct_m
51
52 implicit none
53
54 private
55 public :: phonons_run
56
57contains
58
59 ! ---------------------------------------------------------
60 subroutine phonons_run(system)
61 class(*), intent(inout) :: system
62
63 push_sub(phonons_run)
64
65 select type (system)
66 class is (multisystem_basic_t)
67 message(1) = "CalculationMode = vib_modes not implemented for multi-system calculations"
68 call messages_fatal(1, namespace=system%namespace)
69 type is (electrons_t)
70 call phonons_run_legacy(system)
71 end select
72
73 pop_sub(phonons_run)
74 end subroutine phonons_run
75
76 ! ---------------------------------------------------------
77 subroutine phonons_run_legacy(sys)
78 type(electrons_t), intent(inout) :: sys
79
80 type(vibrations_t) :: vib
81 integer :: ierr
82 type(restart_t) :: gs_restart
83
84 push_sub(phonons_run_legacy)
85
86 if (sys%hm%pcm%run_pcm) then
87 call messages_not_implemented("PCM for CalculationMode /= gs or td", namespace=sys%namespace)
88 end if
89
90 ! Why not? The symmetries are computed only for the unperturbed geometry,
91 ! and are not valid when the atoms are displaced.
92 ! FIXME: implement instead use of symmetry over dynamical matrix to make things more efficient.
93 if (sys%st%symmetrize_density .or. sys%kpoints%use_symmetries) then
94 message(1) = "Cannot compute vibrational modes by finite differences when symmetry is being used."
95 message(2) = "Set KPointsUseSymmetries = no and SymmetrizeDensity = no, for gs run and this run."
96 call messages_fatal(2, namespace=sys%namespace)
97 end if
98
99 call states_elec_allocate_wfns(sys%st, sys%gr)
100
101 ! load wavefunctions
102 call restart_init(gs_restart, sys%namespace, restart_gs, restart_type_load, sys%mc, ierr, mesh=sys%gr, exact=.true.)
103 if (ierr == 0) then
104 call states_elec_load(gs_restart, sys%namespace, sys%space, sys%st, sys%gr, sys%kpoints, ierr)
105 end if
106 if (ierr /= 0) then
107 message(1) = "Unable to read wavefunctions."
108 call messages_fatal(1, namespace=sys%namespace)
109 end if
110 call restart_end(gs_restart)
111
112 ! setup Hamiltonian
113 message(1) = 'Info: Setting up Hamiltonian.'
114 call messages_info(1, namespace=sys%namespace)
115 call v_ks_h_setup(sys%namespace, sys%space, sys%gr, sys%ions, sys%ext_partners, sys%st, sys%ks, sys%hm)
116
117 call vibrations_init(vib, sys%ions%space, sys%ions%natoms, sys%ions%mass, "fd", sys%namespace)
118
119 !%Variable Displacement
120 !%Type float
121 !%Default 0.01 a.u.
122 !%Section Linear Response::Vibrational Modes
123 !%Description
124 !% When calculating phonon properties by finite differences (<tt>CalculationMode = vib_modes,
125 !% ResponseMethod = finite_differences</tt>),
126 !% <tt>Displacement</tt> controls how much the atoms are to be moved in order to calculate the
127 !% dynamical matrix.
128 !%End
129 call parse_variable(sys%namespace, 'Displacement', 0.01_real64, vib%disp, units_inp%length)
130
131 ! calculate dynamical matrix
132 call get_dyn_matrix(sys%gr, sys%namespace, sys%mc, sys%ions, sys%ext_partners, sys%st, sys%ks, &
133 sys%hm, sys%outp, vib, sys%space)
134
135 call vibrations_output(vib)
136
137 call vibrations_end(vib)
138
139 call states_elec_deallocate_wfns(sys%st)
140 pop_sub(phonons_run_legacy)
141
142 end subroutine phonons_run_legacy
143
144 ! ---------------------------------------------------------
146 subroutine get_dyn_matrix(gr, namespace, mc, ions, ext_partners, st, ks, hm, outp, vib, space)
147 type(grid_t), target, intent(inout) :: gr
148 type(namespace_t), intent(in) :: namespace
149 type(multicomm_t), intent(in) :: mc
150 type(ions_t), intent(inout) :: ions
151 type(partner_list_t), intent(in) :: ext_partners
152 type(states_elec_t), intent(inout) :: st
153 type(v_ks_t), intent(inout) :: ks
154 type(hamiltonian_elec_t), intent(inout) :: hm
155 type(output_t), intent(in) :: outp
156 type(vibrations_t), intent(inout) :: vib
157 type(electron_space_t), intent(in) :: space
158
159 type(scf_t) :: scf
160 integer :: iatom, jatom, alpha, beta, imat, jmat
161 real(real64), allocatable :: forces(:,:), forces0(:,:)
162
163 push_sub(get_dyn_matrix)
164
165
166 call scf_init(scf, namespace, gr, ions, st, mc, hm, space)
167 safe_allocate(forces0(1:space%dim, 1:ions%natoms))
168 safe_allocate(forces(1:space%dim, 1:ions%natoms))
169 forces = m_zero
170 forces0 = m_zero
171
172 do iatom = 1, ions%natoms
173 do alpha = 1, space%dim
174 imat = vibrations_get_index(vib, iatom, alpha)
175
176 call messages_new_line()
177 call messages_print_with_emphasis(namespace=namespace)
178 write(message(1), '(a,i3,3a)') 'Info: Moving atom ', iatom, ' in the +', index2axis(alpha), '-direction.'
179 call messages_info(1, namespace=namespace)
180 call messages_print_with_emphasis(namespace=namespace)
181
182 ! move atom iatom in direction alpha by dist
183 ions%pos(alpha, iatom) = ions%pos(alpha, iatom) + vib%disp
184
185 ! first force
186 call run_displacement()
187 forces0 = ions%tot_force
188
189 call messages_new_line()
190 call messages_print_with_emphasis(namespace=namespace)
191 write(message(1), '(a,i3,3a)') 'Info: Moving atom ', iatom, ' in the -', index2axis(alpha), '-direction.'
192 call messages_info(1, namespace=namespace)
193 call messages_print_with_emphasis(namespace=namespace)
194
195 ions%pos(alpha, iatom) = ions%pos(alpha, iatom) - m_two*vib%disp
196
197 ! second force
198 call run_displacement()
199 forces = ions%tot_force
200
201 ions%pos(alpha, iatom) = ions%pos(alpha, iatom) + vib%disp
202
203 do jatom = 1, ions%natoms
204 do beta = 1, space%dim
205 jmat = vibrations_get_index(vib, jatom, beta)
206 vib%dyn_matrix(jmat, imat) = (forces0(beta, jatom) - forces(beta, jatom)) / (m_two*vib%disp) &
207 * vibrations_norm_factor(vib, iatom, jatom)
208 end do
209 end do
210 call vibrations_out_dyn_matrix_row(vib, imat)
211
212 end do
213 end do
214 safe_deallocate_a(forces0)
215 safe_deallocate_a(forces)
216 call scf_end(scf)
217
220
221 pop_sub(get_dyn_matrix)
222 contains
223
225 !TODO: The same code is called in the GO run mode. This should be combined
226 subroutine run_displacement()
228
229 call hamiltonian_elec_epot_generate(hm, namespace, space, gr, ions, ext_partners, st)
230 call density_calc(st, gr, st%rho)
231 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval=.true.)
232 call energy_calc_total(namespace, space, hm, gr, st, ext_partners)
233 call scf_mix_clear(scf)
234 call scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, verbosity = verb_compact)
235
237 end subroutine run_displacement
238
239 end subroutine get_dyn_matrix
240
241end module phonons_fd_oct_m
242
243!! Local Variables:
244!! mode: f90
245!! coding: utf-8
246!! End:
This module implements a calculator for the density and defines related functions.
Definition: density.F90:120
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:608
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:189
real(real64), parameter, public m_zero
Definition: global.F90:187
This module implements the underlying real-space grid.
Definition: grid.F90:117
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:118
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:930
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1125
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
Definition: messages.F90:624
subroutine, public messages_new_line()
Definition: messages.F90:1146
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:420
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:145
This module implements the basic mulsisystem class, a container system for other systems.
this module contains the output system
Definition: output_low.F90:115
subroutine get_dyn_matrix(gr, namespace, mc, ions, ext_partners, st, ks, hm, outp, vib, space)
Computes the second-order force constant from finite differences.
Definition: phonons_fd.F90:240
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:229
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
Definition: restart.F90:514
integer, parameter, public restart_type_load
Definition: restart.F90:225
subroutine, public restart_end(restart)
Definition: restart.F90:720
subroutine, public scf_mix_clear(scf)
Definition: scf.F90:556
subroutine, public scf_run(scf, namespace, space, mc, gr, ions, ext_partners, st, ks, hm, outp, verbosity, iters_done, restart_load, restart_dump)
Definition: scf.F90:574
integer, parameter, public verb_compact
Definition: scf.F90:197
subroutine, public scf_init(scf, namespace, gr, ions, st, mc, hm, space)
Definition: scf.F90:237
subroutine, public scf_end(scf)
Definition: scf.F90:526
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, 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:118
character pure function, public index2axis(idir)
Definition: utils.F90:202
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:732
subroutine, public v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
Definition: v_ks.F90:679
real(real64) pure function, public vibrations_norm_factor(this, iatom, jatom)
Definition: vibrations.F90:291
subroutine, public vibrations_diag_dyn_matrix(this)
Diagonalize the dynamical matrix.
Definition: vibrations.F90:350
subroutine, public vibrations_out_dyn_matrix_row(this, imat)
Outputs one row of the dynamical matrix.
Definition: vibrations.F90:303
subroutine, public vibrations_init(this, space, natoms, mass, suffix, namespace)
Definition: vibrations.F90:168
subroutine, public vibrations_symmetrize_dyn_matrix(this)
Symmetrize the dynamical matric, which is real symmetric matrix.
Definition: vibrations.F90:231
integer pure function, public vibrations_get_index(this, iatom, idim)
Definition: vibrations.F90:384
subroutine, public vibrations_output(this)
Outputs the eigenvectors and eigenenergies of the dynamical matrix.
Definition: vibrations.F90:413
subroutine, public vibrations_end(this)
Definition: vibrations.F90:207
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:214
Container class for lists of system_oct_m::system_t.
output handler class
Definition: output_low.F90:163
some variables used for the SCF cycle
Definition: scf.F90:203
int true(void)