Пример #1
0
def get_Eoc_corrected_observations(pickle_filename, iparams):
  '''
  Read pickle file name and output Eoc corrected original miller array object.
  '''
  observations_pickle = pickle.load(open(pickle_filename,"rb"))
  observations_original = observations_pickle["observations"][0]
  wavelength = observations_pickle["wavelength"]
  crystal_init_orientation = observations_pickle["current_orientation"][0]
  uc_params = observations_original.unit_cell().parameters()
  detector_distance_mm = observations_pickle['distance']
  mm_predictions = iparams.pixel_size_mm*(observations_pickle['mapped_predictions'][0])
  xbeam = observations_pickle["xbeam"]
  ybeam = observations_pickle["ybeam"]
  alpha_angle = flex.double([math.atan(abs(pred[0]-xbeam)/abs(pred[1]-ybeam)) \
                                   for pred in mm_predictions])
  spot_pred_x_mm = flex.double([pred[0]-xbeam for pred in mm_predictions])
  spot_pred_y_mm = flex.double([pred[1]-ybeam for pred in mm_predictions])

  #filter resolution
  i_sel_res = observations_original.resolution_filter_selection(\
        d_max=iparams.iotacc.d_max, d_min=iparams.iotacc.d_min)
  observations_original = observations_original.customized_copy(\
        indices=observations_original.indices().select(i_sel_res), \
        data=observations_original.data().select(i_sel_res), \
        sigmas=observations_original.sigmas().select(i_sel_res))
  alpha_angle = alpha_angle.select(i_sel_res)
  spot_pred_x_mm = spot_pred_x_mm.select(i_sel_res)
  spot_pred_y_mm = spot_pred_y_mm.select(i_sel_res)


  #Filter weak
  i_sel = (observations_original.data()/observations_original.sigmas()) > iparams.iotacc.sigma_min
  observations_original = observations_original.customized_copy(\
        indices=observations_original.indices().select(i_sel),\
        data=observations_original.data().select(i_sel),\
        sigmas=observations_original.sigmas().select(i_sel))
  alpha_angle = alpha_angle.select(i_sel)
  spot_pred_x_mm = spot_pred_x_mm.select(i_sel)
  spot_pred_y_mm = spot_pred_y_mm.select(i_sel)

  #calculate spot radius
  from prime.postrefine.mod_leastsqr import calc_spot_radius
  spot_radius = calc_spot_radius(sqr(crystal_init_orientation.reciprocal_matrix()),
                                          observations_original.indices(), wavelength)

  G = 1
  B = 0
  from prime.postrefine.mod_leastsqr import calc_partiality_anisotropy_set
  two_theta = observations_original.two_theta(wavelength=wavelength).data()
  sin_theta_over_lambda_sq = observations_original.two_theta(wavelength=wavelength).sin_theta_over_lambda_sq().data()
  ry = 0
  rz = 0
  re = iparams.gamma_e
  rotx = 0
  roty = 0

  #calc partiality
  partiality_init, delta_xy_init, rs_init, rh_init = calc_partiality_anisotropy_set(crystal_init_orientation.unit_cell(), rotx, roty, observations_original.indices(), ry, rz, spot_radius, re, two_theta, alpha_angle, wavelength, crystal_init_orientation, spot_pred_x_mm, spot_pred_y_mm, detector_distance_mm, iparams.partiality_model, iparams.flag_beam_divergence)

  from prime.postrefine.mod_leastsqr import calc_full_refl
  I_full = calc_full_refl(observations_original.data(), sin_theta_over_lambda_sq,
                            G, B, partiality_init, rs_init, iparams.flag_volume_correction)
  sigI_full = calc_full_refl(observations_original.sigmas(), sin_theta_over_lambda_sq,
                            G, B, partiality_init, rs_init, iparams.flag_volume_correction)
  observations_Eoc_corrected = observations_original.customized_copy(data=I_full, sigmas=sigI_full)

  return observations_Eoc_corrected, observations_original
Пример #2
0
def get_Eoc_corrected_observations(pickle_filename, iparams):
    '''
  Read pickle file name and output Eoc corrected original miller array object.
  '''
    observations_pickle = read_frame(pickle_filename)
    observations_original = observations_pickle["observations"][0]
    wavelength = observations_pickle["wavelength"]
    crystal_init_orientation = observations_pickle["current_orientation"][0]
    uc_params = observations_original.unit_cell().parameters()
    detector_distance_mm = observations_pickle['distance']
    mm_predictions = iparams.pixel_size_mm * (
        observations_pickle['mapped_predictions'][0])
    xbeam = observations_pickle["xbeam"]
    ybeam = observations_pickle["ybeam"]
    alpha_angle = flex.double([math.atan(abs(pred[0]-xbeam)/abs(pred[1]-ybeam)) \
                                     for pred in mm_predictions])
    spot_pred_x_mm = flex.double([pred[0] - xbeam for pred in mm_predictions])
    spot_pred_y_mm = flex.double([pred[1] - ybeam for pred in mm_predictions])

    #filter resolution
    i_sel_res = observations_original.resolution_filter_selection(\
          d_max=iparams.iotacc.d_max, d_min=iparams.iotacc.d_min)
    observations_original = observations_original.customized_copy(\
          indices=observations_original.indices().select(i_sel_res), \
          data=observations_original.data().select(i_sel_res), \
          sigmas=observations_original.sigmas().select(i_sel_res))
    alpha_angle = alpha_angle.select(i_sel_res)
    spot_pred_x_mm = spot_pred_x_mm.select(i_sel_res)
    spot_pred_y_mm = spot_pred_y_mm.select(i_sel_res)

    #Filter weak
    i_sel = (observations_original.data() /
             observations_original.sigmas()) > iparams.iotacc.sigma_min
    observations_original = observations_original.customized_copy(\
          indices=observations_original.indices().select(i_sel),\
          data=observations_original.data().select(i_sel),\
          sigmas=observations_original.sigmas().select(i_sel))
    alpha_angle = alpha_angle.select(i_sel)
    spot_pred_x_mm = spot_pred_x_mm.select(i_sel)
    spot_pred_y_mm = spot_pred_y_mm.select(i_sel)

    #calculate spot radius
    from prime.postrefine.mod_leastsqr import calc_spot_radius
    spot_radius = calc_spot_radius(
        sqr(crystal_init_orientation.reciprocal_matrix()),
        observations_original.indices(), wavelength)

    G = 1
    B = 0
    from prime.postrefine.mod_leastsqr import calc_partiality_anisotropy_set
    two_theta = observations_original.two_theta(wavelength=wavelength).data()
    sin_theta_over_lambda_sq = observations_original.two_theta(
        wavelength=wavelength).sin_theta_over_lambda_sq().data()
    ry = 0
    rz = 0
    re = iparams.gamma_e
    rotx = 0
    roty = 0

    #calc partiality
    partiality_init, delta_xy_init, rs_init, rh_init = calc_partiality_anisotropy_set(
        crystal_init_orientation.unit_cell(), rotx, roty,
        observations_original.indices(), ry, rz, spot_radius, re, two_theta,
        alpha_angle, wavelength, crystal_init_orientation, spot_pred_x_mm,
        spot_pred_y_mm, detector_distance_mm, iparams.partiality_model,
        iparams.flag_beam_divergence)

    from prime.postrefine.mod_leastsqr import calc_full_refl
    I_full = calc_full_refl(observations_original.data(),
                            sin_theta_over_lambda_sq, G, B, partiality_init,
                            rs_init, iparams.flag_volume_correction)
    sigI_full = calc_full_refl(observations_original.sigmas(),
                               sin_theta_over_lambda_sq, G, B, partiality_init,
                               rs_init, iparams.flag_volume_correction)
    observations_Eoc_corrected = observations_original.customized_copy(
        data=I_full, sigmas=sigI_full)

    return observations_Eoc_corrected, observations_original
 spot_pred_x_mm = flex.double([pred[0]-xbeam for pred in mm_predictions])
 spot_pred_y_mm = flex.double([pred[1]-ybeam for pred in mm_predictions])
 #resoultion filter
 i_sel_res = observations.resolution_filter_selection(d_min=d_min, d_max=d_max)
 observations = observations.select(i_sel_res)
 alpha_angle = alpha_angle.select(i_sel_res)
 spot_pred_x_mm = spot_pred_x_mm.select(i_sel_res)
 spot_pred_y_mm = spot_pred_y_mm.select(i_sel_res)
 #sort by resolution
 perm = observations.sort_permutation(by_value="resolution", reverse=True)
 observations = observations.select(perm)
 alpha_angle = alpha_angle.select(perm)
 spot_pred_x_mm = spot_pred_x_mm.select(perm)
 spot_pred_y_mm = spot_pred_y_mm.select(perm)
 from prime.postrefine.mod_leastsqr import calc_spot_radius
 r0 = calc_spot_radius(sqr(crystal_init_orientation.reciprocal_matrix()),
                                       observations.indices(), wavelength)
 from prime.postrefine.mod_leastsqr import calc_partiality_anisotropy_set
 two_theta = observations.two_theta(wavelength=wavelength).data()
 sin_theta_over_lambda_sq = observations.two_theta(wavelength=wavelength).sin_theta_over_lambda_sq().data()
 ry, rz, re, rotx, roty = (0, 0, 0.003, 0, 0)
 flag_beam_divergence = False
 partiality_init, delta_xy_init, rs_init, rh_init = calc_partiality_anisotropy_set(crystal_init_orientation.unit_cell(),
                                                       rotx, roty, observations.indices(),
                                                       ry, rz, r0, re, two_theta, alpha_angle, wavelength,
                                                       crystal_init_orientation, spot_pred_x_mm, spot_pred_y_mm,
                                                       detector_distance_mm, "Lorentzian",
                                                       flag_beam_divergence)
 I_full = observations.data()/ partiality_init
 sigI_full = observations.sigmas()/ partiality_init
 observations_full = observations.customized_copy(data=I_full, sigmas=sigI_full)
 #calculate R and cc with reference