# Fortran – Programming Primitive Vectors of Reciprocal Lattice

Suppose $\vec{a_{1}}$, $\vec{a_{2}}$ and $\vec{a_{3}}$ are the 3 primitive vectors of a direct lattice. The primitive vectors of the reciprocal lattice are given by $\vec{b_{1}}=2\pi\frac{\vec{a_{2}}\times \vec{a_{3}}}{\Omega_{a}}$ $\vec{b_{2}}=2\pi\frac{\vec{a_{3}}\times \vec{a_{1}}}{\Omega_{a}}$ $\vec{b_{3}}=2\pi\frac{\vec{a_{1}}\times \vec{a_{2}}}{\Omega_{a}}$

, where $\Omega_{a}$ is the volume of the primitive cell.

Fortran 90 code:

program main
implicit none
real(8), parameter :: PI=4.D0*datan(1.D0)
real(8),dimension(3) :: a1,a2,a3,b1,b2,b3
real(8),dimension(3) :: a,b
real(8) :: Va

print *,"Enter x, y, z coordinates of a1:"
print *,"Enter x, y, z coordinates of a2:"
print *,"Enter x, y, z coordinates of a3:"
Va = dot_product(a1,cross_product(a2,a3))
b1 = cross_product(a2,a3)*2*PI/Va
b2 = cross_product(a3,a1)*2*PI/Va
b3 = cross_product(a1,a2)*2*PI/Va
print *,"b1(1)=",b1(1),"b1(2)=",b1(2),"b1(3)=",b1(3)
print *,"b2(1)=",b2(1),"b2(2)=",b2(2),"b2(3)=",b2(3)
print *,"b3(1)=",b3(1),"b3(2)=",b2(2),"b3(3)=",b2(3)
print *,"Volume of Unit Cell=",Va
contains
function cross_product(x,y)
implicit none
real(8),dimension(3) :: x, y, z, cross_product
z(1)=x(2)*y(3)-x(3)*y(2)
z(2)=x(3)*y(1)-x(1)*y(3)
z(3)=x(1)*y(2)-x(2)*y(1)
cross_product=z
end function cross_product

real(8) function dot_product(x,y)
implicit none
real(8),dimension(3) :: x,y
dot_product = x(1)*y(1)+x(2)*y(2)+x(3)*y(3)
end function dot_product
end program main


The user inputs the 3 direct lattice vectors, and the program will print the 3 reciprocal lattice vectors and the volume of the direct lattice.