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
Tried it? Did this program work on your calculator?
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.
TI-84 Plus CE Python · screen preview
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
- 1 finds d. 2 finds theta. 3 finds lambda. 4 finds the order n.
- 5 finds d directly from a 2-theta reading, which is what most diffractometers report.
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
- Instruments usually report 2-theta. Halve it for the formula, or use choice 5.
- d comes out in whatever unit you typed for the wavelength.
- The angle is entered in degrees.
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
from math import sin,asin,radians,degreesdef duckiedai_intro(program_name,wait=True):title=program_name[:16]empty=16-len(title)left=empty//2right=empty-leftprint("+----------------------+")print("| "+" "*left+title+" "*right+" |")print("| |")print("| __ |")print("| ___(o )> quack! |")print("| \\ <_. ) |")print("| `---' |")print("| by DuckieDai |")print("+----------------------+")print("Loading...")if wait:input("Press enter to start ")print("\n"*6)def pos(s):while 1:try:x=float(input(s))if x>0:return xexcept:passprint("Enter a positive #")def whole(s):while 1:try:x=int(input(s))if x>0:return xexcept:passprint("Enter a whole #")def angle(s,top=90):while 1:x=pos(s)if x<=top:return xprint("Angle is too large")def menu():while 1:try:x=int(input("Choose 1-5: "))if x>0 and x<6:return xexcept:passprint("Choose 1 to 5")duckiedai_intro("BRAGGS LAW")print("BRAGG'S LAW")print("n*lambda=2*d*sin(t)")print("1 Find d")print("2 Find theta")print("3 Find lambda")print("4 Find order n")print("5 d from 2theta")c=menu()if c==1:n=whole("Order n: ")w=pos("Lambda: ")t=angle("Theta deg: ")d=n*w/(2*sin(radians(t)))print("d =",d)print("2theta =",2*t)elif c==2:n=whole("Order n: ")w=pos("Lambda: ")d=pos("d: ")r=n*w/(2*d)if r>1:print("No Bragg angle")else:t=degrees(asin(r))print("theta =",t)print("2theta =",2*t)elif c==3:n=whole("Order n: ")d=pos("d: ")t=angle("Theta deg: ")print("lambda =",2*d*sin(radians(t))/n)elif c==4:w=pos("Lambda: ")d=pos("d: ")t=angle("Theta deg: ")n=2*d*sin(radians(t))/wnear=round(n)print("Calculated n =",n)print("Nearest order =",near)if near<1:print("No positive order")elif abs(n-near)<.001:print("Matches integer order")else:print("Not an integer order")else:n=whole("Order n: ")w=pos("Lambda: ")t=angle("2theta deg: ",180)/2print("theta =",t)print("d =",n*w/(2*sin(radians(t))))input("ENTER for guide: ")print("QUICK GUIDE")print("n=1,2,3,...")print("d and lambda: same")print("Bragg uses theta")print("XRD often gives 2theta")print("DuckieDai: done!")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
- 1.0.0 — current version, published . Download this reviewed version
Related learning
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.