xsf_io.f90 6.86 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

7 8 9 10 11 12 13 14 15 16 17
MODULE m_xsf_io
  USE m_types
  !-----------------------------------------------
  ! DESC:subroutines to write xsf-files for xcrysden
  !                 Daniel Wortmann, (06-01-26)
  !-----------------------------------------------
  ! Bohr radius a0, http://physics.nist.gov/cgi-bin/cuu/Value?eqbohrrada0
  REAL, PRIVATE, PARAMETER :: a0 = 0.52917720859 ! in Angstroem

CONTAINS
  !<-- S:S: xsf_WRITE_atoms(fileno,film,amat,neq(:ntype),zatom(:ntype),pos)
18
  SUBROUTINE xsf_WRITE_atoms(fileno,atoms,film,od,amat,forceAllAtoms)
19 20 21 22 23 24 25 26 27 28 29
    !-----------------------------------------------
    !     Writes the crystal dimensions&atomic positions
    !           (last modified: 2004-00-00) D. Wortmann
    !-----------------------------------------------
    IMPLICIT NONE
    !<--Arguments
    INTEGER,INTENT(IN)     :: fileno
    TYPE(t_atoms),INTENT(IN):: atoms
    LOGICAL,INTENT(IN)      :: film
    LOGICAL,INTENT(IN)     :: od
    REAL,INTENT(IN)        :: amat(3,3)
30
    REAL, OPTIONAL, INTENT(IN) :: forceAllAtoms(3,atoms%nat)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    !>
    !<-- Locals
    INTEGER             :: n,nn,na
    !>
    IF (film) THEN
       IF (od) THEN
          WRITE(fileno,*) "POLYMERE"
       ELSE
          WRITE(fileno,*) "SLAB"
       ENDIF
    ELSE
       WRITE(fileno,*) "CRYSTAL"
    ENDIF

    WRITE(fileno,*) "PRIMVEC"
    ! Write in atomic units
    WRITE(fileno,'(3(f0.7,1x))') amat(:,1)*a0
    WRITE(fileno,'(3(f0.7,1x))') amat(:,2)*a0
    WRITE(fileno,'(3(f0.7,1x))') amat(:,3)*a0

    WRITE(fileno,*) "PRIMCOORD"
    WRITE(fileno,*) SUM(atoms%neq)," 1"
    na = 1
    DO n = 1,SIZE(atoms%neq)
       DO nn = 1,atoms%neq(n)
56 57 58 59 60
          IF (PRESENT(forceAllAtoms)) THEN
             WRITE(fileno,'(i4,2x,6(f0.7,1x))') NINT(atoms%zatom(n)),atoms%pos(:,na)*a0,forceAllAtoms(:,na)/a0
          ELSE
             WRITE(fileno,'(i4,2x,3(f0.7,1x))') NINT(atoms%zatom(n)),atoms%pos(:,na)*a0
          END IF
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
          na=na+1
       ENDDO
    ENDDO
    WRITE(fileno,*)
  END SUBROUTINE xsf_WRITE_atoms
  !> 
  !<-- S: xsf_write_header(fileno,twodim,desc,vec1,vec2,vec3,zero,grid)
  SUBROUTINE xsf_WRITE_header(fileno,twodim,desc,vec1,vec2,vec3,zero&
       &     ,grid)
    !-----------------------------------------------
    !  writes the beginning of a gid-datablock
    !           (last modified: 2004-00-00) D. Wortmann
    !-----------------------------------------------
    IMPLICIT NONE
    !<--Arguments
    INTEGER,INTENT(IN)     :: fileno,grid(:)
    LOGICAL,INTENT(IN)     :: twodim
    REAL   ,INTENT(IN)     :: vec1(:),vec2(:),vec3(:),zero(:)
    CHARACTER(LEN =*),INTENT(IN) :: desc 
    !>

    IF (twodim) THEN
       WRITE(fileno,*) "BEGIN_BLOCK_DATAGRID_2D"
       WRITE(fileno,*) desc
       WRITE(fileno,*) "BEGIN_DATAGRID_2D_A"
       WRITE(fileno,'(3i7)') grid(1:2)
       WRITE(fileno,'(3(f12.7,1x))') zero*a0
       WRITE(fileno,'(3(f12.7,1x))') vec1*a0
       WRITE(fileno,'(3(f12.7,1x))') vec2*a0
    ELSE
       WRITE(fileno,*) "BEGIN_BLOCK_DATAGRID_3D"
       WRITE(fileno,*) desc
       WRITE(fileno,*) "BEGIN_DATAGRID_3D_A"
       WRITE(fileno,'(3i7)') grid(1:3)
       WRITE(fileno,'(3(f12.7,1x))') zero*a0
       WRITE(fileno,'(3(f12.7,1x))') vec1*a0
       WRITE(fileno,'(3(f12.7,1x))') vec2*a0
       WRITE(fileno,'(3(f12.7,1x))') vec3*a0
    ENDIF
  END SUBROUTINE xsf_WRITE_header
  !> 
  !<-- S: xsf_write_newblock(fileno,twodim,vec1,vec2,vec3,zero,grid)
  SUBROUTINE xsf_WRITE_newblock(fileno,twodim,vec1,vec2&
       &     ,vec3,zero,grid)
    !-----------------------------------------------
    !  writes the beginning of a new gid-datablock for second spin
    !           (last modified: 2004-00-00) D. Wortmann
    !-----------------------------------------------
    IMPLICIT NONE
    !<--Arguments
    INTEGER,INTENT(IN)     :: fileno,grid(:)
    LOGICAL,INTENT(IN)     :: twodim
    REAL   ,INTENT(IN)     :: vec1(:),vec2(:),vec3(:),zero(:)
    !>

    IF (twodim) THEN
       WRITE(fileno,*) "END_DATAGRID_2D"
       WRITE(fileno,*) "BEGIN_DATAGRID_2D_B"
       WRITE(fileno,'(3i7)') grid(1:2)
       WRITE(fileno,'(3(f12.7,1x))') zero*a0
       WRITE(fileno,'(3(f12.7,1x))') vec1*a0
       WRITE(fileno,'(3(f12.7,1x))') vec2*a0
    ELSE
       WRITE(fileno,*) "END_DATAGRID_3D"
       WRITE(fileno,*) "BEGIN_DATAGRID_3D_B"
       WRITE(fileno,'(3i7)') grid(1:3)
       WRITE(fileno,'(3(f12.7,1x))') zero*a0
       WRITE(fileno,'(3(f12.7,1x))') vec1*a0
       WRITE(fileno,'(3(f12.7,1x))') vec2*a0
       WRITE(fileno,'(3(f12.7,1x))') vec3*a0
    ENDIF
  END SUBROUTINE xsf_WRITE_newblock
  !> 
  !<-- S: xsf_write_endblock(fileno,twodim)
  SUBROUTINE xsf_write_endblock(fileno,twodim)
    !-----------------------------------------------
    !
    !           (last modified: 2004-00-00) D. Wortmann
    !-----------------------------------------------
    IMPLICIT NONE
    !<--Arguments
    INTEGER,INTENT(IN)     :: fileno
    LOGICAL,INTENT(IN)     :: twodim
    !>

    IF (twodim) THEN
       WRITE(fileno,*) "END_DATAGRID_2D"                      
       WRITE(fileno,*) "END_BLOCK_DATAGRID_2D" 
    ELSE
       WRITE(fileno,*) "END_DATAGRID_3D"                      
       WRITE(fileno,*) "END_BLOCK_DATAGRID_3D" 
    ENDIF
  END SUBROUTINE xsf_write_endblock
  !> 

  SUBROUTINE xsf_WRITE_force(fileno,atoms,film,od,amat,force)
    !-----------------------------------------------
    !     Writes the crystal dimensions&force positions
    !           (last modified: 2004-00-00) D. Wortmann
    !-----------------------------------------------
    IMPLICIT NONE
    !<--Arguments
    INTEGER,INTENT(IN)       :: fileno
    TYPE(t_atoms),INTENT(IN) :: atoms
    LOGICAL,INTENT(IN)       :: film
    LOGICAL,INTENT(IN)       :: od
    REAL,INTENT(IN)          :: amat(3,3)
    INTEGER,INTENT(IN)     :: force ! number of atoms + force vectors
    !>
    !<-- Locals
    INTEGER             :: n,nn,na
    !>
    IF (film) THEN
       IF (od) THEN
          WRITE(fileno,*) "POLYMERE"
       ELSE
          WRITE(fileno,*) "SLAB"
       ENDIF
    ELSE
       WRITE(fileno,*) "CRYSTAL"
    ENDIF

    WRITE(fileno,*) "PRIMVEC"
    WRITE(fileno,'(3(f0.7,1x))') amat(:,1)*a0
    WRITE(fileno,'(3(f0.7,1x))') amat(:,2)*a0
    WRITE(fileno,'(3(f0.7,1x))') amat(:,3)*a0

    WRITE(fileno,*) "PRIMCOORD"
    WRITE(fileno,*) force," 1"
    na = 1
    DO n = 1,SIZE(atoms%neq)
       DO nn = 1,atoms%neq(n)
          WRITE(fileno,'(i4,2x,3(f0.7,1x))') NINT(atoms%zatom(n)),&
               &            atoms%pos(:,na)*a0
          na=na+1
       ENDDO
    ENDDO
    WRITE(fileno,*)
  END SUBROUTINE xsf_WRITE_force
  !> 
  !-----------------------------------------------
END MODULE m_xsf_io