program for calculation of absolute scattering from amorphous materials, like air, water, and protein

This short program calculates the absolute-scale scattered intensity from non-crystalline materials given: The definition of a structure factor (Hartree 1925) is the ratio of the amplitude of the wave scattered from the object of interest (one "molecule" in this case) to the amplitude scattered by a single electron at the origin. For a monoatomic gas, such as helium, this is simply the atomic structure factor you will find in the International Tables of Crystallography where it is tabulated with the same units used by nonBragg. A few example input files are: The nonBragg program can also accept a diffraction image in SMV format (the native format of ADSC and Rigaku detectors), and generate a structure factor "stol file", averaged over the image. Other X-ray detector image formats can be converted to SMV using adxv with the command:
adxv -sa whatever_0_00001.cbf whatever_0_001.img
Feeding the stol-file written out by nonBragg back into nonBragg will generate a perfectly centro-symmetric diffraction pattern (after correcting for polarization and detector geometry), which can be useful for background subtraction or other background simulation tasks.
Note that nonBragg does simulate polarization and solid-angle effects from detector orientation and tilt, but the structure factor of the material is presumed to be perfectly centro-symmetric. This is appropriate for gasses, liquids, and genuinely amorphous solids. If you want to simulate anisotropic structure factors that arise from oriented molecules, use the nanoBragg SAXS example as a guide. Don't forget to set the number of unit cells equal to one.
source code: nonBragg.c (85k) or binaries for linux, OSX, Cygwin, Windows
auxillary programs:
noisify is a program that takes the "photons/pixel" noiseless intensity values output by nonBragg or nanoBragg, or nearBragg as "floagimage.bin" and adds different kinds of noise to it to generate an SMV file. This is usually faster than re-running nonBragg just to change things like beam intensity. In addition to photon shot noise, noisify has a few kinds of noise that nonBragg doesn't implement, such as pixel read-out noise, beam flicker, and calibration error.
float_add may be used to add or scale the raw "float" binary files output by nonBragg, nanoBragg, or even nearBragg so that renderings may be divided up on separate CPUs and then combined together. The resulting raw files may then be converted to SMV images with noisify.
float_func can perform a large number of operations on these "floagimage.bin" files.

example usage:

get nonBragg:

compile it
gcc -O -O -o nonBragg nonBragg.c -lm -static
get some structure factor data:
run the simulation for a 100 micron thick slab of water and some typical beamline parameters
./nonBragg -stol water.stol -lambda 1  -MW 18 -density 1.0 -thickness 0.1 -flux 1e12 -exposure 1
view the result
adxv noiseimage.img
convert and re-scale as regular graphics file
convert -depth 16 -type Grayscale -colorspace GRAY -endian LSB -size 1024x1024+512 \
  -negate -normalize \
  GRAY:noiseimage.img noiseimage.png

You can confirm that the number of photons on each pixel is very similar to what you would get in reality. In fact, using water scattering like this is one way to calibrate the flux of a given beamline.

Now assume that noiseimage.img is a real diffraction pattern, you can create a "stol" file for water like this:

./nonBragg -img noiseimage_water.img -stolout recycled_water.stol -stol He.stol -lambda 1 -MW 18 -density 1.0 -thickness 0.1 -flux 1e12 -exposure 1 -nonoise
It is very important to have the right x-ray beam parameters for this to work, especially on an absolute scale!
Note that you still need to provide a "dummy" stol file to give nonBragg an idea fo the spacing you want. The He.stol file is much coarser than water.stol, which you can see if you compare the new water stol file to the original in gnuplot:
plot 'water.stol' with l, 'recycled_water.stol' lt 3

Note that the recycled_water.stol file has a much coarser sampling in this case, but if fed back into nonBragg it will apply a cubic spline interpolation between all the points.

A fast way to compute the centro-symmetric scattering that results from averaging over millions of protein molecules in a SAXS experiment is to compute structure factors for a single molecule, isolated in a unit cell at least 3-4x bigger than the molecule in all directions using phenix.fmodel, or You can then pre-average the structure factors in the resulting MTZ file into a "stol" file ready for input into nonBragg with this script: bigcell.pdb.mtz
which will create a file called mtz.stol that you can feed to nonBragg:
./nonBragg -stol mtz.stol -lambda 1 -dispersion 0 \
  -distance 1000 -detsize 100 -pixel 0.1 \
  -hdiv 0 -vdiv 0 \
  -flux 1e13 -thick 1.2 -MW 14000 -density 0.01
adxv noiseimage.img

Which starts to look more like a SAXS pattern from a conventional SAXS beamline. Note that the "density" of the sample in this case is 0.01 g/cm^3 or 10 mg/mL.

Command-line options:
-stol filename.stol
the structure factor text list.
distance from sample to detector center (mm)
detector size in x and y (mm)
detector size in x direction (mm)
detector size in y direction (mm)
detector pixel size (mm)
detector size in x and y (pixels)
detector size in x direction (pixels)
detector size in y direction (pixels)
direct beam position in x direction (mm) Default: center
direct beam position in y direction (mm) Default: center
all detector pixels same distance from sample (origin)
number of sub-pixels per pixel. Default: 1
-roi xmin xmax ymin ymax
only render pixels within a set range. Default: all detector
incident x-ray wavelength (Angstrom). Default: 1
horizontal angular spread of source points (mrad). Default: 0
vertical angular spread of source points (mrad). Default: 0
number of source points in the horizontal. Default: 1
number of source points in the vertical. Default: 1
spectral dispersion: delta-lambda/lambda (percent). Default: 0
number of wavelengths in above range. Default: 1
name of binary pixel intensity output file (4-byte floats)
name of smv-formatted output file.
scale factor for intfile. Default: fill dynamic range
print pixel values out to the screen
turn off the progress meter