write_genformat Subroutine

public subroutine write_genformat(mol, unit)

Arguments

Type IntentOptional Attributes Name
class(structure_type), intent(in) :: mol
integer, intent(in) :: unit

Source Code

subroutine write_genformat(mol, unit)
   class(structure_type), intent(in) :: mol
   integer, intent(in) :: unit
   integer :: iat, izp
   real(wp), parameter :: zero3(3) = 0.0_wp
   real(wp), allocatable :: inv_lat(:, :)
   real(wp), allocatable :: abc(:, :)
   logical :: helical

   helical = .false.
   write(unit, '(i0, 1x)', advance='no') mol%nat
   if (.not.any(mol%periodic)) then
      write(unit, '("C")') ! cluster
   else
      helical = count(mol%periodic) == 1 .and. mol%periodic(3) .and. size(mol%lattice, 2) == 1
      if (helical) then
         write(unit, '("H")') ! helical
      else
         if (mol%info%cartesian) then
            write(unit, '("S")') ! supercell
         else
            write(unit, '("F")') ! fractional
         endif
      end if
   endif

   do izp = 1, mol%nid
      write(unit, '(1x, a)', advance='no') trim(mol%sym(izp))
   enddo
   write(unit, '(a)')

   if (.not.any(mol%periodic) .or. mol%info%cartesian) then
      ! now write the cartesian coordinates
      do iat = 1, mol%nat
         write(unit, '(2i5, 3es24.14)') iat, mol%id(iat), mol%xyz(:, iat)*autoaa
      enddo
   else
      inv_lat = matinv_3x3(mol%lattice)
      abc = matmul(inv_lat, mol%xyz)
      ! now write the fractional coordinates
      do iat = 1, mol%nat
         write(unit, '(2i5, 3es24.15)') iat, mol%id(iat), abc(:, iat)
      enddo
   endif

   if (any(mol%periodic)) then
      write(unit, '(3f20.14)') zero3
      ! write the lattice parameters
      if (helical) then
         write(unit, '(2f20.14,1x,i0)') &
            & mol%lattice(1, 1)*autoaa, mol%lattice(2, 1)*180.0_wp/pi, nint(mol%lattice(3, 1))
      else
         write(unit, '(3f20.14)') mol%lattice(:, :)*autoaa
      end if
   endif

end subroutine write_genformat