Hidden WordScanner
Private scans · No account required

DuckieDai Bragg's Law

Solve n*lambda = 2*d*sin(theta), including a guided conversion from an XRD 2-theta reading.

chemistry · MIT License

Overview

Solve n*lambda = 2*d*sin(theta), including a guided conversion from an XRD 2-theta reading.

  • Not calculator tested
  • Downloaded 36 times
  • Version 1.0.0
  • 2301 bytes
  • Uses math

Before you run it

  • TI-84 Plus CE Python · No calculator OS or Python App version has been verified.
  • TI Connect CE .py transfer is the intended path; calculator OS, Python App, transfer, and execution have not yet been tested for this release
  • The stated planes, wavelength, and diffraction order describe the same elastic diffraction peak.
  • Order is positive; theta is greater than 0 and at most 90 degrees; 2-theta is greater than 0 and at most 180 degrees; inverse-sine input cannot exceed 1.
  • A calculated value near an integer does not by itself assign a diffraction peak.

Try the DuckieDai calculator screen

Follow the same opening, solve menu, prompts, validation, and result flow as the downloadable program.

JavaScript is required for the optional browser simulation. Source viewing and downloading remain available without it.

Simulation boundary: This preview uses a reviewed browser adapter. It does not execute the downloaded Python and does not prove TI-Python or calculator compatibility.

Learn the math

How Bragg's law works

The idea

X-rays reflecting from neighboring layers of atoms in a crystal reinforce each other only at certain angles. Those angles depend on the spacing between the layers.

Measuring the angles lets you work out the spacing, which is the basis of X-ray diffraction.

The formula

n*lambda = 2*d*sin(theta)

n
order of the reflection: 1, 2, 3, ...
lambda
X-ray wavelength
d
spacing between crystal planes, in the same unit as lambda
theta
angle between the beam and the planes, in degrees

Using the program

Worked example

Copper K-alpha X-rays have a wavelength of 1.5406 angstroms. A first-order peak appears at theta = 22.5 degrees. Choose 1 and enter 1, 1.5406, and 22.5.

d = 1 x 1.5406/(2 x sin(22.5))

The program shows d = 2.01 angstroms (it prints more decimal places) and 2theta = 45.0.

Tips and common mistakes

Where this comes up

It comes up in the solids and crystal structure unit of general chemistry, in materials science, and in physical chemistry labs that use X-ray diffraction to identify a solid.

Exact reviewed bytes

Source code

Download .py

View source below, copy it when JavaScript is available, or download the exact .py bytes.

  1. from math import sin,asin,radians,degrees
  2. def duckiedai_intro(program_name,wait=True):
  3. title=program_name[:16]
  4. empty=16-len(title)
  5. left=empty//2
  6. right=empty-left
  7. print("+----------------------+")
  8. print("| "+" "*left+title+" "*right+" |")
  9. print("| |")
  10. print("| __ |")
  11. print("| ___(o )> quack! |")
  12. print("| \\ <_. ) |")
  13. print("| `---' |")
  14. print("| by DuckieDai |")
  15. print("+----------------------+")
  16. print("Loading...")
  17. if wait:
  18. input("Press enter to start ")
  19. print("\n"*6)
  20. def pos(s):
  21. while 1:
  22. try:
  23. x=float(input(s))
  24. if x>0:return x
  25. except:pass
  26. print("Enter a positive #")
  27. def whole(s):
  28. while 1:
  29. try:
  30. x=int(input(s))
  31. if x>0:return x
  32. except:pass
  33. print("Enter a whole #")
  34. def angle(s,top=90):
  35. while 1:
  36. x=pos(s)
  37. if x<=top:return x
  38. print("Angle is too large")
  39. def menu():
  40. while 1:
  41. try:
  42. x=int(input("Choose 1-5: "))
  43. if x>0 and x<6:return x
  44. except:pass
  45. print("Choose 1 to 5")
  46. duckiedai_intro("BRAGGS LAW")
  47. print("BRAGG'S LAW")
  48. print("n*lambda=2*d*sin(t)")
  49. print("1 Find d")
  50. print("2 Find theta")
  51. print("3 Find lambda")
  52. print("4 Find order n")
  53. print("5 d from 2theta")
  54. c=menu()
  55. if c==1:
  56. n=whole("Order n: ")
  57. w=pos("Lambda: ")
  58. t=angle("Theta deg: ")
  59. d=n*w/(2*sin(radians(t)))
  60. print("d =",d)
  61. print("2theta =",2*t)
  62. elif c==2:
  63. n=whole("Order n: ")
  64. w=pos("Lambda: ")
  65. d=pos("d: ")
  66. r=n*w/(2*d)
  67. if r>1:print("No Bragg angle")
  68. else:
  69. t=degrees(asin(r))
  70. print("theta =",t)
  71. print("2theta =",2*t)
  72. elif c==3:
  73. n=whole("Order n: ")
  74. d=pos("d: ")
  75. t=angle("Theta deg: ")
  76. print("lambda =",2*d*sin(radians(t))/n)
  77. elif c==4:
  78. w=pos("Lambda: ")
  79. d=pos("d: ")
  80. t=angle("Theta deg: ")
  81. n=2*d*sin(radians(t))/w
  82. near=round(n)
  83. print("Calculated n =",n)
  84. print("Nearest order =",near)
  85. if near<1:print("No positive order")
  86. elif abs(n-near)<.001:print("Matches integer order")
  87. else:print("Not an integer order")
  88. else:
  89. n=whole("Order n: ")
  90. w=pos("Lambda: ")
  91. t=angle("2theta deg: ",180)/2
  92. print("theta =",t)
  93. print("d =",n*w/(2*sin(radians(t))))
  94. input("ENTER for guide: ")
  95. print("QUICK GUIDE")
  96. print("n=1,2,3,...")
  97. print("d and lambda: same")
  98. print("Bragg uses theta")
  99. print("XRD often gives 2theta")
  100. print("DuckieDai: done!")
  101. input("ENTER to exit: ")
Filename
bragg.py
Size
2301 bytes
SHA-256
58e4d702646472cfe19bd4f3fb0a8ee814527e1843791f8bf24756ec532ff5b3

Usage

Inputs

  • Positive integer reflection order
  • Wavelength and lattice-plane spacing in the same length unit
  • Bragg theta in degrees, or measured 2-theta in degrees

Outputs

  • Requested spacing, angle, wavelength, or calculated reflection order

Units: Lambda and d must use the same length unit; theta and 2-theta are entered in degrees.

Assumptions and limitations

Assumptions

  • The stated planes, wavelength, and diffraction order describe the same elastic diffraction peak.

Constraints

  • Order is positive; theta is greater than 0 and at most 90 degrees; 2-theta is greater than 0 and at most 180 degrees; inverse-sine input cannot exceed 1.

Known failures

  • A calculated value near an integer does not by itself assign a diffraction peak.
  • Instrument geometry, uncertainty, and sample effects are not modeled.

Compatibility and review

Review status
Not calculator tested
Tested on
The owner reports personally testing the supplied archive programs on a calculator; exact model, OS, and Python App versions were not recorded
What happened
Owner reported interactive testing is disclosed, but the published bytes are not labeled independently calculator tested because the environment is unrecorded and Arrhenius received a narrow intake correction
Dependencies
math
Suggested calculator name
BRAGG — you can give it another valid, unique name when you transfer it
Desktop test cases
Not available for this interactive-only source

This exact source auto-launches an interactive calculator session, so compatibility evidence comes from the recorded physical-device review rather than an importable desktop fixture.

Transfer and launch

Download the .py file, send it to your calculator with TI Connect CE as BRAGG or another name, then open the Python App and try the worked example on this page first. This release has no verified calculator OS or Python App version; treat transfer and execution as unverified until independently tested.

Full installation and troubleshooting guide. Check your teacher's or exam's rules before using any program.

Version history

Did a DuckieDai program help with your homework? Every program here is free. If you would like to say thanks, you can leave a tip on Cash App ($duckiedai214) or read what tips pay for.

Independent compatibility resource: Hidden Word Scanner is independent and is not affiliated with or endorsed by Texas Instruments. TI product names describe compatibility only.

Action-count privacy: Successful downloads, preview starts, and preview completions increment same-origin aggregate counters, and so does a Yes or No answer about whether the program worked. Your browser notes that you answered; that note is never sent to the site. No entered values, source text, IP address, account, cookie, device identifier, or fingerprint is stored with these counts.