예제 #1
0
def basic_beam():
    print("Make a beam")
    # make a beam
    ENERGY = 9000
    ENERGY_CONV = 1e10 * constants.c * constants.h / constants.electron_volt
    WAVELEN = ENERGY_CONV / ENERGY
    # dxtbx beam model description
    beam_descr = {
        'direction': (0.0, 0.0, 1.0),
        'divergence': 0.0,
        'flux': 1e11,
        'polarization_fraction': 1.,
        'polarization_normal': (0.0, 1.0, 0.0),
        'sigma_divergence': 0.0,
        'transmission': 1.0,
        'wavelength': WAVELEN
    }
    return BeamFactory.from_dict(beam_descr)
    def nanoBragg_constructor_beam(self):
        """dumb necessity FIXME please"""

        beam = BeamFactory.from_dict(self.xray_beams[0].to_dict())

        # set the nominal beam to have the average wavelength and the total flux
        num = 0
        den = 0
        flux = 0
        for b in self.xray_beams:
            wave = b.get_wavelength()
            wt = b.get_flux()
            num += wave * wt
            den += wt
            flux += b.get_flux()
        ave_wave = num / den

        beam.set_wavelength(ave_wave * 1e10)
        beam.set_flux(flux)
        return beam
예제 #3
0
 def nanoBragg_constructor_beam(self):
     """dumb necessity FIXME please"""
     beam = BeamFactory.from_dict(self.xray_beams[0].to_dict())
     beam.set_wavelength(beam.get_wavelength() * 1e10)
     return beam
예제 #4
0
        'material': '',
        'mu': 0.0,
        'name': 'Panel',
        'origin': (-99.165, 99.05499999999999, -125.0),
        'pedestal': 0.0,
        'pixel_size': (0.11, 0.11),
        'px_mm_strategy': {
            'type': 'SimplePxMmStrategy'
        },
        'raw_image_offset': (0, 0),
        'slow_axis': (0.0, -1.0, 0.0),
        'thickness': 0.0,
        'trusted_range': (-29.0, 65505.0),
        'type': 'SENSOR_CCD'
    }]
}

beamDict = {
    'direction': (0.0, 0.0, 1.0),
    'divergence': 0.0,
    'flux': 0.0,
    'polarization_fraction': 0.999,
    'polarization_normal': (0.0, 1.0, 0.0),
    'sigma_divergence': 0.0,
    'transmission': 1.0,
    'wavelength': 1.37095
}

BEAM = BeamFactory.from_dict(beamDict)
DET = DetectorFactory.from_dict(detDict)
예제 #5
0
def test_beam_self_serialization():
    beam = Beam()
    assert beam == BeamFactory.from_dict(beam.to_dict())
예제 #6
0
def main():
    from cxid9114.sim import sim_utils
    from dxtbx.model.crystal import CrystalFactory
    from dxtbx_model_ext import flex_Beam
    from dxtbx.model.detector import DetectorFactory
    from dxtbx.model.beam import BeamFactory
    from simtbx.nanoBragg.tst_nanoBragg_basic import fcalc_from_pdb

    import numpy as np
    from cxid9114.parameters import ENERGY_CONV

    energies = np.arange(8920, 8930)
    fluxes = np.ones(len(energies)) * 5e11

    patt_args = {"Ncells_abc": (20, 20, 20), "profile": "square", "verbose": 0}

    beam_descr = {
        'direction': (0.0, 0.0, 1.0),
        'divergence': 0.0,
        'flux': 5e11,
        'polarization_fraction': 1.,
        'polarization_normal': (0.0, 1.0, 0.0),
        'sigma_divergence': 0.0,
        'transmission': 1.0,
        'wavelength': ENERGY_CONV / energies[0]
    }

    cryst_descr = {
        '__id__': 'crystal',
        'real_space_a': (79, 0, 0),
        'real_space_b': (0, 79, 0),
        'real_space_c': (0, 0, 38),
        'space_group_hall_symbol': '-P 4 2'
    }

    det_descr = {
        'panels': [{
            'fast_axis': (-1.0, 0.0, 0.0),
            'gain': 1.0,
            'identifier': '',
            'image_size': (196, 196),
            'mask': [],
            'material': '',
            'mu': 0.0,
            'name': 'Panel',
            'origin': (19.6, -19.6, -550),
            'pedestal': 0.0,
            'pixel_size': (0.1, 0.1),
            'px_mm_strategy': {
                'type': 'SimplePxMmStrategy'
            },
            'raw_image_offset': (0, 0),
            'slow_axis': (0.0, 1.0, 0.0),
            'thickness': 0.0,
            'trusted_range': (0.0, 65536.0),
            'type': ''
        }]
    }

    DET = DetectorFactory.from_dict(det_descr)
    BEAM = BeamFactory.from_dict(beam_descr)

    crystal = CrystalFactory.from_dict(cryst_descr)
    Patt = sim_utils.PatternFactory(crystal=crystal,
                                    detector=DET,
                                    beam=BEAM,
                                    **patt_args)

    img = None
    Fens = []
    xrbeams = flex_Beam()
    for fl, en in zip(fluxes, energies):
        wave = ENERGY_CONV / en
        F = fcalc_from_pdb(resolution=4, algorithm="fft", wavelength=wave)
        Patt.primer(crystal, energy=en, flux=fl, F=F)
        if img is None:
            img = Patt.sim_rois(reset=True)  # defaults to full detector
        else:
            img += Patt.sim_rois(reset=True)

        Fens.append(F)

        xrb = BeamFactory.from_dict(beam_descr)
        xrb.set_wavelength(wave *
                           1e-10)  # need to fix the necessity to do this..
        xrb.set_flux(fl)
        xrb.set_direction(BEAM.get_direction())

        xrbeams.append(xrb)

    #import pylab as plt
    #def plot_img(ax,img):
    #    m = img[img >0].mean()
    #    s = img[img > 0].std()
    #    vmax = m+5*s
    #    vmin = 0
    #    ax.imshow(img, vmin=vmin, vmax=vmax, cmap='gnuplot')

    print("\n\n\n")
    print("<><><><><><><><><><>")
    print("NEXT TRIAL")
    print("<><><><><><><><><><>")
    #

    patt2 = sim_utils.PatternFactory(crystal=crystal,
                                     detector=DET,
                                     beam=xrbeams,
                                     **patt_args)

    patt2.prime_multi_Fhkl(multisource_Fhkl=Fens)
    img2 = patt2.sim_rois(reset=True)

    #plt.figure()
    #ax1 = plt.gca()
    #plt.figure()
    #ax2 = plt.gca()
    #plot_img(ax1, img)
    #plot_img(ax2, img2)
    #plt.show()

    assert (np.allclose(img, img2))
예제 #7
0
                 'image_size': im_shape,
                 'mask': [],
                 'material': '',
                 'mu': 0.0,
                 'name': 'Panel',
                 'origin': (-im_shape[0]*pixsize/2., im_shape[1]*pixsize/2., -detdist),
                 'pedestal': 0.0,
                 'pixel_size': (pixsize, pixsize),
                 'px_mm_strategy': {'type': 'SimplePxMmStrategy'},
                 'raw_image_offset': (0, 0),
                 'thickness': 0.0,
                 'trusted_range': (-1e7, 1e7),
                 'type': ''}]}

# make the dxtbx objects
BEAM = BeamFactory.from_dict(beam_descr)
DETECTOR = DetectorFactory.from_dict(det_descr)
CRYSTAL = CrystalFactory.from_dict(cryst_descr)

# make a dummie HKL table with constant HKL intensity
# this is just to make spots
DEFAULT_F = 1e2
symbol = CRYSTAL.get_space_group().info().type().lookup_symbol()  # this is just P43212
sgi = sgtbx.space_group_info(symbol)
symm = symmetry(unit_cell=CRYSTAL.get_unit_cell(), space_group_info=sgi)
miller_set = symm.build_miller_set(anomalous_flag=True, d_min=1.6, d_max=999)
Famp = flex.double(np.ones(len(miller_set.indices())) * DEFAULT_F)
Famp = miller.array(miller_set=miller_set, data=Famp).set_observation_type_xray_amplitude()

Ncells_abc = 20, 20, 20
oversmaple = 2
    fast = col((1.0, 0.0, 0.0))
    slow = col((0.0, -1.0, 0.0))
    det = DetectorFactory.make_detector(
        "", fast, slow, orig,
        (pixsize, pixsize), (s*1536,s*1536)) #, trusted_range=(0, 10000000))
    beam_descr = {
        'direction': (7.010833160725592e-06, -3.710515413340211e-06, 0.9999999999685403),
        'divergence': 0.0,
        'flux': 0.0,
        'polarization_fraction': 0.999,
        'polarization_normal': (0.0, 1.0, 0.0),
        'sigma_divergence': 0.0,
        'transmission': 1.0,
        'wavelength': 1.385}
    #beam = BeamFactory.simple(wavelen)
    beam = BeamFactory.from_dict(beam_descr)

elif lab_geom == "cspad":
    det = DetectorFactory.from_dict(dxtbx_cspad.cspad)

    # beam pointing off z-axis
    beam_descr = {
        'direction': (7.010833160725592e-06, -3.710515413340211e-06, 0.9999999999685403),
        'divergence': 0.0,
        'flux': 0.0,
        'polarization_fraction': 0.999,
        'polarization_normal': (0.0, 1.0, 0.0),
        'sigma_divergence': 0.0,
        'transmission': 1.0,
        'wavelength': 1.385}
    beam = BeamFactory.from_dict(beam_descr)
예제 #9
0
    (7.010833160725592e-06, -3.710515413340211e-06, 0.9999999999685403),
    'divergence':
    0.0,
    'flux':
    0.0,
    'polarization_fraction':
    0.999,
    'polarization_normal': (0.0, 1.0, 0.0),
    'sigma_divergence':
    0.0,
    'transmission':
    1.0,
    'wavelength':
    1.385
}
tilted_beam = BeamFactory.from_dict(beam_descr)

net_error_tilt = 0
print "# --- beam centers comparison for tilted setup -- #"
for pid in range(64):
    print "tilted: ", pid
    SIM = simtbx.nanoBragg.nanoBragg(detector=cspad,
                                     beam=tilted_beam,
                                     verbose=0,
                                     panel_id=pid)

    b1 = SIM.beam_center_mm
    b2 = cspad[pid].get_beam_centre(tilted_beam.get_s0())
    print "beam_XY simtbx:  %f, %f" % b1
    print "beam_XY python:  %f, %f" % b2
    print