w90_readwrite_set_atoms Subroutine

private subroutine w90_readwrite_set_atoms(atom_data, atoms_label_tmp, atoms_pos_cart_tmp, error, comm)

Uses

  • proc~~w90_readwrite_set_atoms~~UsesGraph proc~w90_readwrite_set_atoms w90_readwrite_set_atoms module~w90_error w90_error proc~w90_readwrite_set_atoms->module~w90_error module~w90_utility w90_utility proc~w90_readwrite_set_atoms->module~w90_utility module~w90_comms w90_comms module~w90_error->module~w90_comms module~w90_error_base w90_error_base module~w90_error->module~w90_error_base module~w90_utility->module~w90_comms module~w90_constants w90_constants module~w90_utility->module~w90_constants module~w90_comms->module~w90_constants module~w90_comms->module~w90_error_base

Fills the atom data block during a library call

Arguments

Type IntentOptional Attributes Name
type(atom_data_type), intent(inout) :: atom_data
character(len=*), intent(in) :: atoms_label_tmp(:)

Atom labels

real(kind=dp), intent(in) :: atoms_pos_cart_tmp(3,atom_data%num_atoms)

Atom positions, Cartesian, Angstrom

type(w90_error_type), intent(out), allocatable :: error
type(w90_comm_type), intent(in) :: comm

Calls

proc~~w90_readwrite_set_atoms~~CallsGraph proc~w90_readwrite_set_atoms w90_readwrite_set_atoms proc~set_error_alloc set_error_alloc proc~w90_readwrite_set_atoms->proc~set_error_alloc proc~utility_lowercase utility_lowercase proc~w90_readwrite_set_atoms->proc~utility_lowercase proc~comms_sync_error comms_sync_error proc~set_error_alloc->proc~comms_sync_error proc~set_base_error set_base_error proc~set_error_alloc->proc~set_base_error

Called by

proc~~w90_readwrite_set_atoms~~CalledByGraph proc~w90_readwrite_set_atoms w90_readwrite_set_atoms proc~w90_readwrite_read_atoms w90_readwrite_read_atoms proc~w90_readwrite_read_atoms->proc~w90_readwrite_set_atoms proc~w90_postw90_readwrite_read w90_postw90_readwrite_read proc~w90_postw90_readwrite_read->proc~w90_readwrite_read_atoms proc~w90_wannier90_readwrite_read_special w90_wannier90_readwrite_read_special proc~w90_wannier90_readwrite_read_special->proc~w90_readwrite_read_atoms proc~input_reader_special input_reader_special proc~input_reader_special->proc~w90_wannier90_readwrite_read_special proc~w90_input_setopt w90_input_setopt proc~w90_input_setopt->proc~w90_wannier90_readwrite_read_special program~postw90 postw90 program~postw90->proc~w90_postw90_readwrite_read proc~w90_input_setopt_f w90_input_setopt_f proc~w90_input_setopt_f->proc~w90_input_setopt program~wannier wannier program~wannier->proc~input_reader_special

Source Code

  subroutine w90_readwrite_set_atoms(atom_data, atoms_label_tmp, atoms_pos_cart_tmp, error, comm)
    !================================================!
    !
    !!   Fills the atom data block during a library call
    !
    !================================================!
    use w90_utility, only: utility_cart_to_frac, utility_inverse_mat, utility_lowercase
    use w90_error, only: w90_error_type, set_error_alloc

    implicit none

    type(atom_data_type), intent(inout) :: atom_data
    type(w90_error_type), allocatable, intent(out) :: error
    type(w90_comm_type), intent(in) :: comm
    character(len=*), intent(in) :: atoms_label_tmp(:)
    !! Atom labels
    real(kind=dp), intent(in) :: atoms_pos_cart_tmp(3, atom_data%num_atoms)
    !! Atom positions, Cartesian, Angstrom

    integer :: loop2, max_sites, ierr, ic, loop, counter
    character(len=maxlen) :: ctemp(atom_data%num_atoms)
    character(len=maxlen) :: tmp_string

    ! Now we sort the data into the proper structures
    atom_data%num_species = 1
    ctemp(1) = atoms_label_tmp(1)
    do loop = 2, atom_data%num_atoms
      do loop2 = 1, loop - 1
        if (trim(atoms_label_tmp(loop)) == trim(atoms_label_tmp(loop2))) exit
        if (loop2 == loop - 1) then
          atom_data%num_species = atom_data%num_species + 1
          ctemp(atom_data%num_species) = atoms_label_tmp(loop)
        end if
      end do
    end do

    allocate (atom_data%species_num(atom_data%num_species), stat=ierr)
    if (ierr /= 0) then
      call set_error_alloc(error, 'Error allocating atoms_species_num in w90_readwrite_set_atoms', comm)
      return
    end if
    allocate (atom_data%label(atom_data%num_species), stat=ierr)
    if (ierr /= 0) then
      call set_error_alloc(error, 'Error allocating atoms_label in w90_readwrite__set_atoms', comm)
      return
    end if
    allocate (atom_data%symbol(atom_data%num_species), stat=ierr)
    if (ierr /= 0) then
      call set_error_alloc(error, 'Error allocating atoms_symbol in w90_readwrite_set_atoms', comm)
      return
    end if

    atom_data%species_num(:) = 0

    do loop = 1, atom_data%num_species
      atom_data%label(loop) = ctemp(loop)
      do loop2 = 1, atom_data%num_atoms
        if (trim(atom_data%label(loop)) == trim(atoms_label_tmp(loop2))) then
          atom_data%species_num(loop) = atom_data%species_num(loop) + 1
        end if
      end do
    end do

    max_sites = maxval(atom_data%species_num)
    allocate (atom_data%pos_cart(3, max_sites, atom_data%num_species), stat=ierr)
    if (ierr /= 0) then
      call set_error_alloc(error, 'Error allocating atoms_pos_cart in w90_readwrite_set_atoms', comm)
      return
    end if

    do loop = 1, atom_data%num_species
      counter = 0
      do loop2 = 1, atom_data%num_atoms
        if (trim(atom_data%label(loop)) == trim(atoms_label_tmp(loop2))) then
          counter = counter + 1
          atom_data%pos_cart(:, counter, loop) = atoms_pos_cart_tmp(:, loop2)
        end if
      end do
    end do

    ! Strip any numeric characters from atoms_label to get atoms_symbol
    do loop = 1, atom_data%num_species
      atom_data%symbol(loop) (1:2) = atom_data%label(loop) (1:2)
      ic = ichar(atom_data%symbol(loop) (2:2))
      if ((ic .lt. ichar('a')) .or. (ic .gt. ichar('z'))) &
        atom_data%symbol(loop) (2:2) = ' '
      tmp_string = trim(adjustl(utility_lowercase(atom_data%symbol(loop))))
      atom_data%symbol(loop) (1:2) = tmp_string(1:2)
      tmp_string = trim(adjustl(utility_lowercase(atom_data%label(loop))))
      atom_data%label(loop) (1:2) = tmp_string(1:2)

      ! Upper case the atom labels (eg, si --> Si)
      ic = ichar(atom_data%label(loop) (1:1))
      if ((ic .ge. ichar('a')) .and. (ic .le. ichar('z'))) &
        atom_data%label(loop) (1:1) = char(ic + ichar('Z') - ichar('z'))
    end do
  end subroutine w90_readwrite_set_atoms