Skip to content

Instantly share code, notes, and snippets.

@PlethoraChutney
Created October 10, 2022 22:14
Show Gist options
  • Save PlethoraChutney/dc8decc11746bfd807507d5420c2b255 to your computer and use it in GitHub Desktop.
Save PlethoraChutney/dc8decc11746bfd807507d5420c2b255 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
if len(sys.argv) == 1:
diam = input('Particle diameter (A): ')
defocus = input('Mean defocus (um): ')
res = input('Target resolution (A): ')
ps = input('Pixel size (a/pix): ')
elif len(sys.argv) != 5:
print('Usage: box-sizer.py {diameter in A} {defocus in um} {resolution in A} {apix in A/pix}')
sys.exit(1)
else:
diam, defocus, res, ps = sys.argv[1:5]
try:
diam = float(diam)
defocus = abs(float(defocus) * 10**4)
res = float(res)
except ValueError:
print('All values must be numbers!')
sys.exit(2)
print('Box size suggested by Rosenthal and Henderson JMB 2003:')
# 0.02 is the approximate wavelength of an electron at 300 kV, in A
bs = diam + 2 * (0.02 * (defocus / res))
print(f'{bs} angstroms. Note: not pixels!')
print(f'{bs/float(ps)} in pixels.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment