subroutine plot_write_xyz(translate_home_cell, num_wann, wannier_centres, real_lattice, &
atom_data, print_output, error, comm, stdout, seedname)
!================================================!
!
! Write xyz file with Wannier centres
!
!================================================!
use w90_io, only: io_date
use w90_constants, only: dp
use w90_utility, only: utility_translate_home
use w90_error, only: w90_error_type, set_error_file
use w90_types, only: atom_data_type, print_output_type
implicit none
type(atom_data_type), intent(in) :: atom_data
type(print_output_type), intent(in) :: print_output
type(w90_error_type), allocatable, intent(out) :: error
type(w90_comm_type), intent(in) :: comm
logical, intent(in) :: translate_home_cell
integer, intent(in) :: num_wann
real(kind=dp), intent(in) :: wannier_centres(:, :)
real(kind=dp), intent(in) :: real_lattice(3, 3)
integer, intent(in) :: stdout
character(len=50), intent(in) :: seedname
integer :: iw, ind, xyz_unit, nsp, nat, ierr
character(len=9) :: cdate, ctime
real(kind=dp) :: wc(3, num_wann)
wc = wannier_centres
if (translate_home_cell) then
do iw = 1, num_wann
call utility_translate_home(wc(:, iw), real_lattice)
end do
end if
if (print_output%iprint > 2) then
write (stdout, '(1x,a)') 'Final centres (translated to home cell for writing xyz file)'
do iw = 1, num_wann
write (stdout, '(2x, "WF centre", i5, 2x, "(", f10.6, ",", f10.6, ",", f10.6, " )")') &
iw, (wc(ind, iw)*print_output%lenconfac, ind=1, 3)
end do
write (stdout, '(1x,a78)') repeat('-', 78)
write (stdout, *)
end if
open (newunit=xyz_unit, file=trim(seedname)//'_centres.xyz', form='formatted', iostat=ierr)
if (ierr /= 0) then
call set_error_file(error, 'Error opening file '//trim(seedname)//'_centres.xyz in wann_write_xyz', comm)
return
end if
write (xyz_unit, '(i6)') num_wann + atom_data%num_atoms
call io_date(cdate, ctime)
write (xyz_unit, *) 'Wannier centres, written by Wannier90 on'//cdate//' at '//ctime
do iw = 1, num_wann
write (xyz_unit, '("X",6x,3(f14.8,3x))') (wc(ind, iw), ind=1, 3)
end do
do nsp = 1, atom_data%num_species
do nat = 1, atom_data%species_num(nsp)
write (xyz_unit, '(a2,5x,3(f14.8,3x))') atom_data%label(nsp), atom_data%pos_cart(:, nat, nsp)
end do
end do
close (xyz_unit)
write (stdout, '(/a)') ' Wannier centres written to file '//trim(seedname)//'_centres.xyz'
return
end subroutine plot_write_xyz