XRD CUBIC - Simulation of Unit cell dimension, (h, k, l) - Miller indices d-spacing from X-ray diffraction (XRD) angle, 2-theta (For Cubic crystals)

Designed a basic computer program “XRD CUBIC” (coded in Python)  to simulate possible unit crystal cell length (a), Miller indices - {h, k, l} and interplanar spacing (d) for cubic crystals from observed (experimental) X-ray diffraction (XRD) angle that is 2-theta.


It can simulate all these possible crystal lattice parameters for cubic crystal systems such as Simple Cubic or Face Centered Cubic or Body Centered Cubic systems, between the given 2–theta values within the range of specified cell length (a) limits.



1. Enter wavelength of X-ray (in Angstroms)

2. Enter minimum and maximum diffraction angle as 2-theta (in Degrees)

3. Enter minimum and maximum unit cell length (in Angstroms)

All the possible cubic crystal parameters as well as diffraction angle with reference to d-spacing between the given Miller indices (h k l planes) will be simulated.

Video Tutorial


Designed by:
Dr. M Kanagasabapathy, Asst. Professor
Department of Chemistry, Rajus’ College,
Madurai Kamaraj University
Rajapalayam, (TN) INDIA 626117


Outline of the Python code for this program

import math

twotheta=float(input("Enter 2-theta (Degrees):  "))

sintheta = math.sin(math.radians(twotheta*0.5))

d = 1.5406/(2*sintheta)

amin=float(input ("Enter minimum cell length (Angstroms) :  "))

amax=float(input ("Enter maximum cell length (Angstroms) :  "))








if amin<=amax:

        amin=amin + 0.00001

        for h in range(hmin, hmax):

                h = h+1

                for k in range(kmin, kmax):

                        k = k+1

                        for l in range(lmin, lmax):

                                l = l+1

                                if round((amin**2)/(d**2),2) == round(((h**2)+(k**2)+(l**2)),2):

                                        print("{h, k, l} : ",h,k,l)

                                        print("d-spacing = ", round (d,5))

                                        print("Unit cell length (a) = ", round(amin,5))

                                        print(" ")