!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! VectorPer
!
!!!!!!!!!!!!!!!!!!!!!!!
!
! This subroutine caclulates the vector defined by atom i and j
! with j being displaced to a periodic image of the system.
!
! Input:
!  i: (INTEGER) index of the first atom, in the central cell
!  j: (INTEGER) index of the second atom, in a periodic image
!  na,nb,nc: (INTEGER) number of displacement of j atom, in lattice vectors.
!  x(Nat), y(nat), z(nat) : (REAL) Cartesian coordinates of the system.
!
! Output:
! vx,vy,vz: (REAL) Vector i->j
! Norm:     (REAL) Norm of the vector.
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Nat and Lattice vectors (lat_a, lat_b, lat_c) are taken from Path_Module
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

      SUBROUTINE VectorPer(n1,n2,na,nb,nc,x,y,z,vx,vy,vz,norm)

        use VarTypes
        use Path_module, only : NAt,Lat_a,Lat_b,Lat_c

        integer(KINT) :: n1,n2
        INTEGER(KINT) :: na,nb,nc
        real(KREAL) ::  x(Nat),y(Nat),z(Nat)
        real(KREAL) ::  vx,vy,vz,norm

        vx=x(n2)-x(n1)+na*Lat_a(1)+nb*Lat_b(1)+nc*Lat_c(1)
        vy=y(n2)-y(n1)+na*Lat_a(2)+nb*Lat_b(2)+nc*Lat_c(2)
        vz=z(n2)-z(n1)+na*Lat_a(3)+nb*Lat_b(3)+nc*Lat_c(3)

        norm=dsqrt( vx*vx + vy*vy + vz*vz )

!       write(6,*) "Dbg VectorPer : n1,n2, na,nb,nc :",n1,n2,na,nb,nc
!       write(6,*) vx,vy,vz,norm
!       write(6,*) 

        RETURN
      END SUBROUTINE VectorPer
