Пример #1
0
def exercise_expand():
  sg = sgtbx.space_group("P 41 (1,-1,0)")
  h = flex.miller_index(((3,1,-2), (1,-2,0)))
  assert tuple(sg.is_centric(h)) == (0, 1)
  p1 = miller.expand_to_p1_iselection(
    space_group=sg, anomalous_flag=False, indices=h, build_iselection=False)
  p1_i0 = ((-3,-1,2), (-1, 3,2),(3,1,2),(1,-3,2),(1,-2, 0),(2,1,0))
  assert tuple(p1.indices) == p1_i0
  assert p1.iselection.size() == 0
  p1 = miller.expand_to_p1_iselection(
    space_group=sg, anomalous_flag=True, indices=h, build_iselection=False)
  assert tuple(p1.indices) \
      == ((3,1,-2), (1,-3,-2), (-3,-1,-2), (-1,3,-2),
          (1,-2,0), (-2,-1,0), (-1,2,0), (2,1,0))
  p1 = miller.expand_to_p1_iselection(
    space_group=sg, anomalous_flag=False, indices=h, build_iselection=True)
  assert tuple(p1.indices) == p1_i0
  assert tuple(p1.iselection) == (0,0,0,0,1,1)
  a = flex.double((1,2))
  p = flex.double((10,90))
  p1 = miller.expand_to_p1_phases(
    space_group=sg, anomalous_flag=False, indices=h, data=p, deg=True)
  assert approx_equal(tuple(p1.data), (-10,110,110,-10, 90,30))
  p1 = miller.expand_to_p1_phases(
    space_group=sg, anomalous_flag=True, indices=h, data=p, deg=True)
  assert approx_equal(tuple(p1.data), (10,-110,-110,10, 90,-30,-90,30))
  p = flex.double([x * math.pi/180 for x in p])
  v = [x * math.pi/180 for x in p1.data]
  p1 = miller.expand_to_p1_phases(
    space_group=sg, anomalous_flag=True, indices=h, data=p, deg=False)
  assert approx_equal(tuple(p1.data), v)
  f = flex.polar(a, p)
  p1 = miller.expand_to_p1_complex(
    space_group=sg, anomalous_flag=True, indices=h, data=f)
  assert approx_equal(tuple(flex.abs(p1.data)), (1,1,1,1,2,2,2,2))
  assert approx_equal(tuple(flex.arg(p1.data)), v)
  hl = flex.hendrickson_lattman([(1,2,3,4), (5,6,7,8)])
  p1 = miller.expand_to_p1_hendrickson_lattman(
    space_group=sg, anomalous_flag=True, indices=h, data=hl)
  assert approx_equal(p1.data, [
    [1,2,3,4],
    [1.232051,-1.866025,-4.964102,0.5980762],
    [1.232051,-1.866025,-4.964102,0.5980762],
    [1,2,3,4],
    [5,6,7,8],
    [2.696152,-7.330127,-10.4282,2.062178],
    [-5,-6,7,8],
    [7.696152,-1.330127,3.428203,-10.06218]])
  b = flex.bool([True,False])
  p1 = miller.expand_to_p1_iselection(
    space_group=sg, anomalous_flag=True, indices=h, build_iselection=True)
  assert b.select(p1.iselection).all_eq(
    flex.bool([True, True, True, True, False, False, False, False]))
  i = flex.int([13,17])
  p1 = miller.expand_to_p1_iselection(
    space_group=sg, anomalous_flag=True, indices=h, build_iselection=True)
  assert i.select(p1.iselection).all_eq(flex.int([13,13,13,13,17,17,17,17]))
  #
  assert approx_equal(miller.statistical_mean(sg, False, h, a), 4/3.)
  assert approx_equal(miller.statistical_mean(sg, True, h, a), 3/2.)
Пример #2
0
    def assign_operators(self, reidx_ops=None):
        arrays = self.arrays
        self.best_operators = None

        if reidx_ops is None: reidx_ops = self.find_reindex_ops()

        print >>self.log_out, "Reindex operators:", map(lambda x: str(x.as_hkl()), reidx_ops)
        print >>self.log_out, ""

        reidx_ops.sort(key=lambda x: not x.is_identity_op()) # identity op to first

        data = None
        latt_id = flex.int([])

        for i, a in enumerate(arrays):
            if data is None: data = a
            else: data = data.concatenate(a, assert_is_similar_symmetry=False)

            latt_id.extend(flex.int(a.size(), i))

        latt_id = data.customized_copy(data=latt_id.as_double())
        result = brehm_diederichs.run(L=[data, latt_id], nproc=self.nproc, plot=True, verbose=True)

        self.best_operators = map(lambda x: None, xrange(len(arrays)))
        for op in result:
            idxes = map(int, result[op])
            print >>self.log_out, " %s num=%3d idxes= %s" %(op, len(result[op]), idxes)
            for idx in idxes:
                self.best_operators[idx] = sgtbx.change_of_basis_op(op)
Пример #3
0
def exercise_flood_fill():
  uc = uctbx.unit_cell('10 10 10 90 90 90')
  for uc in (uctbx.unit_cell('10 10 10 90 90 90'),
             uctbx.unit_cell('9 10 11 87 91 95')):
    gridding = maptbx.crystal_gridding(
      unit_cell=uc,
      pre_determined_n_real=(5,5,5))
    corner_cube = (0,4,20,24,100,104,120,124) # cube across all 8 corners
    channel = (12,37,38,39,42,43,62,63,67,68,87,112)
    data = flex.int(flex.grid(gridding.n_real()))
    for i in (corner_cube + channel): data[i] = 1
    flood_fill = masks.flood_fill(data, uc)
    assert data.count(0) == 105
    for i in corner_cube: assert data[i] == 2
    for i in channel: assert data[i] == 3
    assert approx_equal(flood_fill.centres_of_mass(),
                        ((-0.5, -0.5, -0.5), (-2.5, 7/3, 2.5)))
    assert approx_equal(flood_fill.centres_of_mass_frac(),
                        ((-0.1, -0.1, -0.1), (-0.5, 7/15, 0.5)))
    assert approx_equal(flood_fill.centres_of_mass_cart(),
                        uc.orthogonalize(flood_fill.centres_of_mass_frac()))
    assert flood_fill.n_voids() == 2
    assert approx_equal(flood_fill.grid_points_per_void(), (8, 12))
    if 0:
      from crys3d import wx_map_viewer
      wx_map_viewer.display(raw_map=data.as_double(), unit_cell=uc, wires=False)
    #
    gridding = maptbx.crystal_gridding(
      unit_cell=uc,
      pre_determined_n_real=(10,10,10))
    data = flex.int(flex.grid(gridding.n_real()))
    # parallelogram
    points = [(2,4,5),(3,4,5),(4,4,5),(5,4,5),(6,4,5),
              (3,5,5),(4,5,5),(5,5,5),(6,5,5),(7,5,5),
              (4,6,5),(5,6,5),(6,6,5),(7,6,5),(8,6,5)]
    points_frac = flex.vec3_double()
    for p in points:
      data[p] = 1
      points_frac.append([p[i]/gridding.n_real()[i] for i in range(3)])
    points_cart = uc.orthogonalize(points_frac)
    flood_fill = masks.flood_fill(data, uc)
    assert data.count(2) == 15
    assert approx_equal(flood_fill.centres_of_mass_frac(), ((0.5,0.5,0.5),))
    pai_cart = math.principal_axes_of_inertia(
      points=points_cart, weights=flex.double(points_cart.size(),1.0))
    F = matrix.sqr(uc.fractionalization_matrix())
    O = matrix.sqr(uc.orthogonalization_matrix())
    assert approx_equal(
      pai_cart.center_of_mass(), flood_fill.centres_of_mass_cart()[0])
    assert approx_equal(
      flood_fill.covariance_matrices_cart()[0],
      (F.transpose() * matrix.sym(
        sym_mat3=flood_fill.covariance_matrices_frac()[0]) * F).as_sym_mat3())
    assert approx_equal(
      pai_cart.inertia_tensor(), flood_fill.inertia_tensors_cart()[0])
    assert approx_equal(pai_cart.eigensystem().vectors(),
                        flood_fill.eigensystems_cart()[0].vectors())
    assert approx_equal(pai_cart.eigensystem().values(),
                        flood_fill.eigensystems_cart()[0].values())
  return
Пример #4
0
  def cluster_analysis_dbscan(self, vectors):
    import numpy as np

    from sklearn.cluster import DBSCAN
    from sklearn.preprocessing import StandardScaler

    vectors = flex.vec3_double(vectors)

    X = np.array(vectors)
    # scale the data - is this necessary/does it help or hinder?
    X = StandardScaler().fit_transform(X)

    # Compute DBSCAN
    params = self.params.multiple_lattice_search.cluster_analysis.dbscan
    db = DBSCAN(eps=params.eps, min_samples=params.min_samples).fit(X)
    core_samples = db.core_sample_indices_
    # core_samples is a list of numpy.int64 objects
    core_samples = flex.int([int(i) for i in core_samples])
    labels = flex.int(db.labels_.astype(np.int32))

    # Number of clusters in labels, ignoring noise if present.
    n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)

    logger.info('Estimated number of clusters: %d' % n_clusters_)

    return labels
Пример #5
0
def exercise_miller_array_data_types():
    miller_set = crystal.symmetry(unit_cell=(10, 10, 10, 90, 90, 90), space_group_symbol="P1").miller_set(
        indices=flex.miller_index([(1, 2, 3), (4, 5, 6)]), anomalous_flag=False
    )
    for data in [
        flex.bool([False, True]),
        flex.int([0, 1]),
        flex.size_t([0, 1]),
        flex.double([0, 1]),
        flex.complex_double([0, 1]),
    ]:
        miller_array = miller_set.array(data=data)
        if op.isfile("tmp_iotbx_mtz.mtz"):
            os.remove("tmp_iotbx_mtz.mtz")
        assert not op.isfile("tmp_iotbx_mtz.mtz")
        miller_array.as_mtz_dataset(column_root_label="DATA").mtz_object().write(file_name="tmp_iotbx_mtz.mtz")
        assert op.isfile("tmp_iotbx_mtz.mtz")
        mtz_obj = mtz.object(file_name="tmp_iotbx_mtz.mtz")
        miller_arrays_read_back = mtz_obj.as_miller_arrays()
        assert len(miller_arrays_read_back) == 1
        miller_array_read_back = miller_arrays_read_back[0]
        assert miller_array_read_back.indices().all_eq(miller_array.indices())
        if miller_array.is_integer_array() or miller_array.is_bool_array():
            assert miller_array_read_back.data().all_eq(flex.int([0, 1]))
        elif miller_array.is_real_array():
            assert miller_array_read_back.data().all_eq(flex.double([0, 1]))
        elif miller_array.is_complex_array():
            assert miller_array_read_back.data().all_eq(flex.complex_double([0, 1]))
        else:
            raise RuntimeError("Programming error.")
 def join(self,data_dict):
   """The join() function closes the database.
   """
   # Terminate the consumer process by feeding it a None command and
   # wait for it to finish.
   self._db_commands_queue.put(None)
   self._db_commands_queue.join()
   self._db_results_queue.join()
   self._semaphore.acquire()
   nrows = data_dict["rows"].get_obj()[0]
   print "writing observation pickle with %d rows"%nrows
   kwargs = dict(
     miller_lookup =      flex.size_t(data_dict["miller_proxy"].get_obj()[:nrows]),
     observed_intensity = flex.double(data_dict["intensity_proxy"].get_obj()[:nrows]),
     observed_sigI =      flex.double(data_dict["sigma_proxy"].get_obj()[:nrows]),
     frame_lookup =       flex.size_t(data_dict["frame_proxy"].get_obj()[:nrows]),
     original_H =         flex.int   (data_dict["H_proxy"].get_obj()[:nrows]),
     original_K =         flex.int   (data_dict["K_proxy"].get_obj()[:nrows]),
     original_L =         flex.int   (data_dict["L_proxy"].get_obj()[:nrows]),
   )
   import cPickle as pickle
   pickle.dump(kwargs, open(self.params.output.prefix+"_observation.pickle","wb"),
               pickle.HIGHEST_PROTOCOL)
   pickle.dump(self.miller, open(self.params.output.prefix+"_miller.pickle","wb"),
               pickle.HIGHEST_PROTOCOL)
   pickle.dump(data_dict["xtal_proxy"].get_obj().raw.replace('\0','').strip(),
                       open(self.params.output.prefix+"_frame.pickle","wb"),pickle.HIGHEST_PROTOCOL)
   return kwargs
def compute(miller_array, step_scale=0.0005):
  miller_array.show_comprehensive_summary(prefix="  ")
  step = miller_array.d_min()*step_scale
  #
  ma_p1 = miller_array.expand_to_p1()
  #
  n_h = {}
  n_k = {}
  n_l = {}
  indices = ma_p1.indices()
  for ind in indices:
    h,k,l = ind
    n_h.setdefault(h, flex.int()).append(1)
    n_k.setdefault(k, flex.int()).append(1)
    n_l.setdefault(l, flex.int()).append(1)
  def count(d):
    for k in d.keys():
      d[k] = d[k].size()
    return d
  n_h = count(n_h)
  n_k = count(n_k)
  n_l = count(n_l)
  # resolutions along axes
  a,b,c = miller_array.unit_cell().parameters()[:3]
  x, rho_x = one_d_image_along_axis(n=n_h, step=step, uc_length=a)
  y, rho_y = one_d_image_along_axis(n=n_k, step=step, uc_length=b)
  z, rho_z = one_d_image_along_axis(n=n_l, step=step, uc_length=c)
  # 2nd derivatives
  r2x = second_derivatives(rho=rho_x, delta=step)
  r2y = second_derivatives(rho=rho_y, delta=step)
  r2z = second_derivatives(rho=rho_z, delta=step)
  # effective resolution along axes
  d_eff_a = compute_d_eff(r=x, rho_2nd=r2x)
  d_eff_b = compute_d_eff(r=y, rho_2nd=r2y)
  d_eff_c = compute_d_eff(r=z, rho_2nd=r2z)
  print "  Effective resolution along axes a,b,c: %6.3f %6.3f %6.3f"%(
    d_eff_a, d_eff_b, d_eff_c)
  # all directions
  l = 0.8 * min(d_eff_a/2.5, d_eff_b/2.5, d_eff_c/2.5)
  r = 1.2 * max(d_eff_a/2.5, d_eff_b/2.5, d_eff_c/2.5)
  us = regular_grid_on_unit_sphere.rosca(m=9, hemisphere=True)
  d_effs = flex.double()
  o = maptbx.ft_analytical_1d_point_scatterer_at_origin(N=100000)
  for i, u in enumerate(us):
    o.compute(
      miller_indices=indices,
      step=step,
      left=l,
      right=r,
      u_frac=miller_array.unit_cell().fractionalize(u))
    dist, rho_ = o.distances(), o.rho()
    rho2 = second_derivatives(rho=rho_, delta=step)
    d_eff = compute_d_eff(r=dist, rho_2nd=rho2)
    d_effs.append(d_eff)
  print "  Effective resolution (min,max): %8.3f%8.3f"%(
    flex.min(d_effs), flex.max(d_effs))
 def exclude_pairs(self):
     # exclude all pairs with dist >= 4 * tolerance
     # dist_allowed is invariant under refine_adjusted_shift:
     #   exclude all pairs with dist_allowed >= tolerance
     # if 0 continuous shifts: dist_allowed == dist:
     #   exclude all pairs with dist >= tolerance
     timer = user_plus_sys_time()
     self.add_pair_ext.next_pivot(
         self.match_symmetry.continuous_shift_flags, self.eucl_symop,
         self.adjusted_shift, flex.int(self.singles1),
         flex.int(self.singles2))
     self.times.exclude_pairs += timer.delta()
Пример #9
0
    def __init__(self, filein, log_out=None, read_data=True, i_only=False):
        self._log = null_out() if log_out is None else log_out
        self._filein = filein
        self.indices = flex.miller_index()
        self.i_only = i_only
        self.iobs, self.sigma_iobs, self.xd, self.yd, self.zd, self.rlp, self.peak, self.corr = [flex.double() for i in xrange(8)]
        self.iframe = flex.int()
        self.iset = flex.int() # only for XSCALE
        self.input_files = {} # only for XSCALE [iset:(filename, wavelength), ...]

        self.read_header()
        if read_data:
            self.read_data()
  def read_observations(self):
    cursor = self._db.cursor()
    cursor.execute("SELECT hkl_id_0_base,i,sigi,frame_id_0_base,original_h,original_k,original_l FROM _observation")
    ALL = cursor.fetchall()

    return dict(hkl_id = flex.int([a[0] for a in ALL]), #as MySQL indices are 1-based
               i = flex.double([a[1] for a in ALL]),
               sigi = flex.double([a[2] for a in ALL]),
               frame_id = flex.int([a[3] for a in ALL]),
               original_h = flex.int([a[4] for a in ALL]),
               original_k = flex.int([a[5] for a in ALL]),
               original_l = flex.int([a[6] for a in ALL]),
               )
  def read_observations(self):
    cursor = self._db.cursor()
    cursor.execute("SELECT hkl_id_0_base,i,sigi,frame_id_0_base,original_h,original_k,original_l FROM _observation")
    ALL = cursor.fetchall()

    return dict(hkl_id = flex.int([a[0] for a in ALL]), #as MySQL indices are 1-based
               i = flex.double([a[1] for a in ALL]),
               sigi = flex.double([a[2] for a in ALL]),
               frame_id = flex.int([a[3] for a in ALL]),
               original_h = flex.int([a[4] for a in ALL]),
               original_k = flex.int([a[5] for a in ALL]),
               original_l = flex.int([a[6] for a in ALL]),
               )
Пример #12
0
  def read_observations(self):
    db = self.connection()
    cursor = db.cursor()
    cursor.execute("SELECT hkl_id_0_base,i,sigi,frame_id_0_base,original_h,original_k,original_l FROM `%s_observation`"%self.params.mysql.runtag)
    ALL = cursor.fetchall()

    return dict(hkl_id = flex.int([a[0] for a in ALL]), #as MySQL indices are 1-based
               i = flex.double([a[1] for a in ALL]),
               sigi = flex.double([a[2] for a in ALL]),
               frame_id = flex.int([a[3] for a in ALL]),
               original_h = flex.int([a[4] for a in ALL]),
               original_k = flex.int([a[5] for a in ALL]),
               original_l = flex.int([a[6] for a in ALL]),
               )
Пример #13
0
  def build_shadow(self):
    # XXX WE NEED TO DO SOMETHING ABOUT 'INSIDE/OUTSIDE' DEFINITIONS XXX #
    # first add polygons please
    for polyg in self.hutch.shadow_polygons:
      tmp = sastbx.data_reduction.image_mask(self.hutch.nx, self.hutch.ny)
      tmp.add_polygon( flex.int(polyg.corners_x), flex.int(polyg.corners_y), 0,0 ) # we need a solution for this please
      self.shadow_object.add( tmp.mask() )

    # now add circle
    tmp = sastbx.data_reduction.image_mask(self.hutch.nx, self.hutch.ny)
    tmp_circle = self.hutch.shadow_circle
    if tmp_circle is not None:
      tmp.add_circle(tmp_circle.x, tmp_circle.y, tmp_circle.radius)
      self.shadow_object.add( tmp.mask() )
Пример #14
0
  def read_observations(self):
    db = self.connection()
    cursor = db.cursor()
    cursor.execute("SELECT hkl_id_0_base,i,sigi,frame_id_0_base,original_h,original_k,original_l FROM `%s_observation`"%self.params.mysql.runtag)
    ALL = cursor.fetchall()

    return dict(hkl_id = flex.int([a[0] for a in ALL]), #as MySQL indices are 1-based
               i = flex.double([a[1] for a in ALL]),
               sigi = flex.double([a[2] for a in ALL]),
               frame_id = flex.int([a[3] for a in ALL]),
               original_h = flex.int([a[4] for a in ALL]),
               original_k = flex.int([a[5] for a in ALL]),
               original_l = flex.int([a[6] for a in ALL]),
               )
 def exclude_pairs(self):
   # exclude all pairs with dist >= 4 * tolerance
   # dist_allowed is invariant under refine_adjusted_shift:
   #   exclude all pairs with dist_allowed >= tolerance
   # if 0 continuous shifts: dist_allowed == dist:
   #   exclude all pairs with dist >= tolerance
   timer = user_plus_sys_time()
   self.add_pair_ext.next_pivot(
     self.match_symmetry.continuous_shift_flags,
     self.eucl_symop,
     self.adjusted_shift,
     flex.int(self.singles1),
     flex.int(self.singles2))
   self.times.exclude_pairs += timer.delta()
Пример #16
0
def exercise_extract_delta_anomalous():
    miller_array_start = miller.set(
        crystal_symmetry=crystal.symmetry(unit_cell=(10, 10, 10, 90, 90, 90),
                                          space_group_symbol="P1"),
        indices=flex.miller_index([(1, 2, 3), (-1, -2, -3)]),
        anomalous_flag=True).array(data=flex.double([3, 5]),
                                   sigmas=flex.double([0.3, 0.5]))
    mtz_dataset = miller_array_start.as_mtz_dataset(column_root_label="F")
    mtz_object = mtz_dataset.mtz_object()
    fp = mtz_object.get_column(label="F(+)").extract_values()[0]
    fm = mtz_object.get_column(label="F(-)").extract_values()[0]
    sp = mtz_object.get_column(label="SIGF(+)").extract_values()[0]
    sm = mtz_object.get_column(label="SIGF(-)").extract_values()[0]
    # http://www.ccp4.ac.uk/dist/html/mtzMADmod.html
    # F = 0.5*( F(+) + F(-) )
    # D = F(+) - F(-)
    # SIGD = sqrt( SIGF(+)**2 + SIGF(-)**2 )
    # SIGF = 0.5*SIGD
    f = 0.5 * (fp + fm)
    d = fp - fm
    sigd = math.sqrt(sp**2 + sm**2)
    sigf = 0.5 * sigd
    mtz_dataset.add_column(label="F", type="F").set_reals(
        mtz_reflection_indices=flex.int([0]), data=flex.double([f]))
    mtz_dataset.add_column(label="SIGF", type="Q").set_reals(
        mtz_reflection_indices=flex.int([0]), data=flex.double([sigf]))
    mtz_dataset.add_column(label="D", type="D").set_reals(
        mtz_reflection_indices=flex.int([0]), data=flex.double([d]))
    mtz_dataset.add_column(label="SIGD", type="Q").set_reals(
        mtz_reflection_indices=flex.int([0]), data=flex.double([sigd]))
    miller_arrays = mtz_object.as_miller_arrays()
    assert len(miller_arrays) == 2
    miller_array = miller_arrays[0]
    assert list(miller_array.indices()) == [(1, 2, 3), (-1, -2, -3)]
    assert approx_equal(miller_array.data(), [3, 5])
    assert approx_equal(miller_array.sigmas(), [0.3, 0.5])
    miller_array = miller_arrays[1]
    assert list(miller_array.indices()) == [(1, 2, 3), (-1, -2, -3)]
    # F(+) = F + 0.5*D
    # F(-) = F - 0.5*D
    # SIGF(+) = sqrt( SIGF**2 + 0.25*SIGD**2 )
    # SIGF(-) = SIGF(+)
    fp = f + 0.5 * d
    fm = f - 0.5 * d
    assert approx_equal([fp, fm], miller_array.data())
    sp = math.sqrt(sigf**2 + 0.25 * sigd**2)
    sm = sp
    assert approx_equal([sp, sm], miller_array.sigmas())
Пример #17
0
def exercise_deepcopy_show_select():
    sel_all = flex.int([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]).as_bool()
    sel_none = flex.int([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).as_bool()
    sel_all_true = flex.int([0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0]).as_bool()
    sel_all_false = flex.int([1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1]).as_bool()
    sel_mix = flex.int([1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1]).as_bool()
    #
    compare(rm=all_defined(), expected_result=expected_result_all)
    compare(rm=all_defined(), expected_result=expected_result_all, deep_copy=True)
    compare(rm=all_defined(), expected_result=expected_result_all, selection=sel_all)
    compare(rm=all_defined(), expected_result=expected_result_none_true, selection=sel_none)
    compare(rm=all_defined(), expected_result=expected_result_all, selection=sel_all_true)
    compare(rm=all_defined(), expected_result=expected_result_none_true, selection=sel_all_false)
    compare(rm=all_defined(), expected_result=expected_result_mix, selection=sel_mix)
    #
    compare(rm=refinement_flags.manager(), expected_result=expected_result_none_false)
    compare(rm=refinement_flags.manager(), expected_result=expected_result_none_false, deep_copy=True)
    compare(rm=refinement_flags.manager(), expected_result=expected_result_none_false, selection=sel_all)
    compare(rm=refinement_flags.manager(), expected_result=expected_result_none_false, selection=sel_none)
    compare(rm=refinement_flags.manager(), expected_result=expected_result_none_false, selection=sel_all_true)
    compare(rm=refinement_flags.manager(), expected_result=expected_result_none_false, selection=sel_all_false)
    compare(rm=refinement_flags.manager(), expected_result=expected_result_none_false, selection=sel_mix)
    #
    rm = all_defined()
    rm_dc = rm.deep_copy()
    rm_dc.individual_sites = False
    rm_dc.torsion_angles = False
    rm_dc.rigid_body = False
    rm_dc.individual_adp = False
    rm_dc.group_adp = False
    rm_dc.tls = False
    rm_dc.occupancies = False
    rm_dc.group_anomalous = False
    rm_dc.sites_individual = None
    rm_dc.sites_torsion_angles = None
    rm_dc.sites_rigid_body = None
    rm_dc.adp_individual_iso = None
    rm_dc.adp_individual_aniso = None
    rm_dc.adp_group = None
    rm_dc.group_h = None
    rm_dc.adp_tls = None
    rm_dc.s_occupancies = None
    out = StringIO()
    rm.show(log=out)
    assert out.getvalue() == expected_result_all
    out = StringIO()
    rm_dc.show(log=out)
    assert out.getvalue() == expected_result_none_false
Пример #18
0
    def literals(self):
        frame_dict = self.database.get_frame_dictionary()

        if self.params.run_numbers is None:
            path = self.params.outdir_template
            stream = open(path, "r")
            print(path)
            for line in stream:
                if line.find("XFEL processing:") == 0:
                    tokens = line.strip().split("/")
                    picklefile = line.strip().split()[2]
                    frame_id = frame_dict.get(picklefile, None)
                    if frame_id is not None:
                        print("FETCHED", frame_id)
                if line.find("CV OBSCENTER") == 0 and line.find(
                        "Traceback") == -1:
                    potential_tokens = line.strip().split()
                    if len(potential_tokens)==22 and \
                           potential_tokens[17].isdigit() and \
                           int(potential_tokens[17])==self.params.bravais_setting_id:
                        yield frame_id, potential_tokens
                if len(self.tiles) == 0 and line.find("EFFEC") == 0:
                    self.tiles = flex.int(
                        [int(a) for a in line.strip().split()[2:]])
                    assert len(self.tiles) == 256
                    print(list(self.tiles))
                    self.initialize_per_tile_sums()
            return
        for run in self.params.run_numbers:
            templ = self.params.outdir_template % run
            items = os.listdir(templ)
            for item in items:
                path = os.path.join(templ, item)
                stream = open(path, "r")
                print(path)
                for line in stream:
                    if line.find("CV OBSCENTER") == 0:
                        potential_tokens = line.strip().split()
                        if len(potential_tokens)==22 and \
                           potential_tokens[17].isdigit() and \
                           int(potential_tokens[17])==self.params.bravais_setting_id:
                            yield None, potential_tokens
                    if len(self.tiles) == 0 and line.find("EFFEC") == 0:
                        self.tiles = flex.int(
                            [int(a) for a in line.strip().split()[2:]])
                        assert len(self.tiles) == 256
                        print(list(self.tiles))
                        self.initialize_per_tile_sums()
Пример #19
0
    def read_data(self):
        colindex = self._colindex
        is_xscale = "RLP" not in colindex
        flag_data_start = False

        col_H, col_K, col_L = colindex["H"], colindex["K"], colindex["L"]
        col_i, col_sig, col_xd, col_yd, col_zd = colindex["IOBS"], colindex["SIGMA(IOBS)"], colindex["XD"], colindex["YD"], colindex["ZD"]
        col_rlp, col_peak, col_corr, col_iset = colindex.get("RLP", None), colindex.get("PEAK", None), colindex.get("CORR", None), colindex.get("ISET", None)
        self.indices = []
        self.xd, self.yd, self.zd = [], [], []
        self.iframe, self.rlp, self.peak, self.corr, self.iset = [], [], [], [], []
        for line in open(self._filein):
            if flag_data_start:
                if line.startswith("!END_OF_DATA"):
                    break

                sp = line.split()
                h, k, l = int(sp[col_H]), int(sp[col_K]), int(sp[col_L])
                self.indices.append([h,k,l])

                self.iobs.append(float(sp[col_i]))
                self.sigma_iobs.append(float(sp[col_sig]))
                if not self.i_only:
                    self.xd.append(float(sp[col_xd]))
                    self.yd.append(float(sp[col_yd]))
                    self.zd.append(float(sp[col_zd]))
                    self.iframe.append(int(self.zd[-1])+1)
                    if not is_xscale:
                        self.rlp.append(float(sp[col_rlp]))
                        self.peak.append(float(sp[col_peak]))
                        self.corr.append(float(sp[col_corr]))
                    else:
                        self.iset.append(int(sp[col_iset]))
                    #res = symm.unit_cell().d((h,k,l))

                    if self.iframe[-1] < 0:
                        self.iframe[-1] = 0
                        print >>self._log, 'reflection with surprisingly low z-value:', self.zd[-1]

            if line.startswith('!END_OF_HEADER'):
                flag_data_start = True

        self.indices = flex.miller_index(self.indices)
        self.iobs, self.sigma_iobs, self.xd, self.yd, self.zd, self.rlp, self.peak, self.corr = [flex.double(x) for x in (self.iobs, self.sigma_iobs, self.xd, self.yd, self.zd, self.rlp, self.peak, self.corr)]
        self.iframe = flex.int(self.iframe)
        self.iset = flex.int(self.iset) # only for XSCALE

        print >>self._log, "Reading data done.\n"
Пример #20
0
 def get_frames_from_mysql(self,params):
   T = Timer("frames")
   CART = manager(params)
   db = CART.connection()
   cursor = db.cursor()
   cursor.execute("SELECT * FROM %s_frame;"%params.mysql.runtag)
   ALL = cursor.fetchall()
   from cctbx.crystal_orientation import crystal_orientation
   orientations = [crystal_orientation(
     (a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15],a[16]),False) for a in ALL]
   return dict( frame_id = flex.int( [a[0] for a in ALL] ),
               wavelength = flex.double( [a[1] for a in ALL] ),
                   beam_x = flex.double( [a[2] for a in ALL] ),
                   beam_y = flex.double( [a[3] for a in ALL] ),
                 distance = flex.double( [a[4] for a in ALL] ),
              orientation = orientations,
          rotation100_rad = flex.double([a[17] for a in ALL] ),
          rotation010_rad = flex.double([a[18] for a in ALL] ),
          rotation001_rad = flex.double([a[19] for a in ALL] ),
       half_mosaicity_deg = flex.double([a[20] for a in ALL] ),
              wave_HE_ang = flex.double([a[21] for a in ALL] ),
              wave_LE_ang = flex.double([a[22] for a in ALL] ),
          domain_size_ang = flex.double([a[23] for a in ALL] ),
         unique_file_name = [a[24] for a in ALL],
  )
Пример #21
0
    def cluster_completeness(self, clno, anomalous_flag, calc_redundancy=True):
        if clno not in self.clusters:
            print "Cluster No. %d not found" % clno
            return

        cls = self.clusters[clno][3]
        msets = map(lambda x: self.miller_sets[self.files[x-1]], cls)
        num_idx = sum(map(lambda x: x.size(), msets))
        all_idx = flex.miller_index()
        all_idx.reserve(num_idx)
        for mset in msets: all_idx.extend(mset.indices())

        # Calc median cell
        cells = numpy.array(map(lambda x: x.unit_cell().parameters(), msets))
        median_cell = map(lambda i: numpy.median(cells[:,i]), xrange(6))
        symm = msets[0].customized_copy(unit_cell=median_cell)

        assert anomalous_flag is not None
        # XXX all must belong to the same Laue group and appropriately reindexed..
        all_set = miller.set(indices=all_idx,
                             crystal_symmetry=symm, anomalous_flag=anomalous_flag)
        all_set = all_set.resolution_filter(d_min=self.d_min)

        # dummy for redundancy calculation. dirty way..
        if calc_redundancy:
            dummy_array = miller.array(miller_set=all_set, data=flex.int(all_set.size()))
            merge = dummy_array.merge_equivalents()
            cmpl = merge.array().completeness()
            redun = merge.redundancies().as_double().mean()
            return cmpl, redun
        else:
            cmpl = all_set.unique_under_symmetry().completeness()
            return cmpl
Пример #22
0
    def __init__(self, filein, log_out=None, read_data=True, i_only=False):
        self._log = null_out() if log_out is None else log_out
        self._filein = filein
        self.indices = flex.miller_index()
        self.i_only = i_only
        self.iobs, self.sigma_iobs, self.xd, self.yd, self.zd, self.rlp, self.peak, self.corr = [
            flex.double() for i in xrange(8)
        ]
        self.iframe = flex.int()
        self.iset = flex.int()  # only for XSCALE
        self.input_files = {
        }  # only for XSCALE [iset:(filename, wavelength), ...]

        self.read_header()
        if read_data:
            self.read_data()
Пример #23
0
def ExtendAnyData(data, nsize):
  if isinstance(data, flex.bool):
    # flex.bool cannot be extended with NaN so cast the data to ints and extend with inanval instead
    data = data.as_int().extend( flex.int(nsize, inanval) )
  if isinstance(data, flex.hendrickson_lattman):
    data.extend( flex.hendrickson_lattman(nsize, (nanval, nanval, nanval, nanval)) )
  if isinstance(data, flex.int) or isinstance(data, flex.long) \
        or isinstance(data, flex.size_t):
    data.extend( flex.int(nsize, inanval) )
  if isinstance(data, flex.float) or isinstance(data, flex.double):
    data.extend( flex.double(nsize, nanval) )
  if isinstance(data, flex.complex_double):
    data.extend( flex.complex_double(nsize, nanval) )
  if isinstance(data, flex.vec3_double):
    data.extend( flex.vec3_double(nsize, (1.,1.,1.)) )
  return data
Пример #24
0
def exercise_add_1c():
    rm = all_defined()
    # [ [1], [2], [4,5], [7,8], [10], [11,13] ] - original
    # [ [1], [2], [4], [5,6,7], [9,10,11], [13], [14,16] ] - after insertion for tuples
    #
    # [0,1,1,0,1,1,0,1,1,0, 1, 1, 0, 1, 0, 0] - original
    # [0,1,1,0,1,1,1,1,0,1,1,1,0, 1, 1, 0, 1, 0, 0] - after insertion for tuples
    #
    # [ [[1],[2]], [[4,5],[7,8]],  [[10]], [[11,13]] ] - original
    #
    # [ [[1],[2]], [[5,7],[9,10]], [[13]], [[14,16]], [[4]], [[6]], [[11]] ] - after insertion for tuples
    rm = rm.add(next_to_i_seqs=flex.size_t([4, 8, 3]),
                sites_individual=True,
                sites_torsion_angles=True,
                sites_rigid_body=True,
                adp_individual_iso=True,
                adp_individual_aniso=True,
                adp_group=True,
                group_h=True,
                adp_tls=True,
                s_occupancies=True)
    out = StringIO()
    rm.show(log=out)
    assert not show_diff(
        out.getvalue(), """\
Refinement flags and selection counts:
  individual_sites       = %s (12 atoms)
  torsion_angles         = %s (12 atoms)
  rigid_body             = %s (12 atoms in 7 groups)
  individual_adp         = %s (iso = 12 aniso = 12)
  group_adp              = %s (12 atoms in 7 groups)
  tls                    = %s (12 atoms in 7 groups)
  occupancies            = %s (12 atoms)
  group_anomalous        = %s
""" % tuple(["%5s" % str(True)] * 8))
    barr_result = flex.int([0,1,1,0,1,1,1,1,0,1,1,1,0, 1, 1, 0, 1, 0, 0]) \
      .as_bool()
    iarr_result = [
        flex.size_t([1]),
        flex.size_t([2]),
        flex.size_t([5, 6, 7]),
        flex.size_t([9, 10, 11]),
        flex.size_t([13]),
        flex.size_t([14, 16]),
        flex.size_t([4])
    ]
    oarr_result = [[flex.size_t([1]), flex.size_t([2])],
                   [flex.size_t([5, 7]),
                    flex.size_t([9, 10])], [flex.size_t([13])],
                   [flex.size_t([14, 16])], [flex.size_t([4])],
                   [flex.size_t([6])], [flex.size_t([11])]]
    assert approx_equal(rm.sites_individual, barr_result)
    assert approx_equal(rm.sites_torsion_angles, barr_result)
    assert approx_equal(rm.sites_rigid_body, iarr_result)
    assert approx_equal(rm.adp_individual_iso, barr_result)
    assert approx_equal(rm.adp_individual_aniso, barr_result)
    assert approx_equal(rm.adp_group, iarr_result)
    assert approx_equal(rm.group_h, iarr_result)
    assert approx_equal(rm.adp_tls, iarr_result)
    compare_selections(rm.s_occupancies, oarr_result)
Пример #25
0
  def vectors(self):
    self.database.initialize_tables_and_insert_command()

    self.tile_rmsd = [0.]*64

    for run,tokens in self.literals():
     try:
      itile = self.register_line( float(tokens[2]),float(tokens[3]),
                       float(tokens[5]),float(tokens[6]),
                       float(tokens[8]),float(tokens[9]),
                       float(tokens[11]),float(tokens[12]) )
      if run is not None:
        self.database.insert(run,itile,tokens)
      yield "OK"
     except ValueError:
       print "Valueerror"

    self.database.send_insert_command()
    for x in xrange(64):
      if self.tilecounts[x]==0: continue
      self.radii[x]/=self.tilecounts[x]
      sum_cv = matrix.col(self.mean_cv[x])
      self.mean_cv[x] = sum_cv/self.tilecounts[x]
      mean_cv = matrix.col(self.mean_cv[x])
      selection = (self.master_tiles == x)
      selected_cv = self.master_cv.select(selection)
      if len(selected_cv)>0:
        self.tile_rmsd[x] = math.sqrt(
      flex.mean(flex.double([ (matrix.col(cv) - mean_cv).length_sq() for cv in selected_cv ]))
      )
      else: self.tile_rmsd[x]=0.
    self.overall_N = flex.sum(flex.int( [int(t) for t in self.tilecounts] ))
    self.overall_cv = matrix.col(self.overall_cv)/self.overall_N
    self.overall_rmsd = math.sqrt( self.sum_sq_cv / self.overall_N )
Пример #26
0
  def __init__(self, f_obs, ncs_pairs, reflections_per_bin):
    adopt_init_args(self, locals())
    # Create bins
    f_obs.setup_binner(reflections_per_bin = reflections_per_bin)
    self.binner = f_obs.binner()
    n_bins = self.binner.n_bins_used()
    self.n_bins = n_bins
    self.SigmaN = None
    self.update_SigmaN()
    #
    self.rbin = flex.int(f_obs.data().size(), -1)
    for i_bin in self.binner.range_used():
      for i_seq in self.binner.array_indices(i_bin):
        self.rbin[i_seq] = i_bin-1 # i_bin starts with 1, not 0 !
    assert flex.min(self.rbin)==0
    assert flex.max(self.rbin)==n_bins-1
    # Extract symmetry matrices
    self.sym_matrices = []
    for m_as_string in f_obs.space_group().smx():
      o = sgtbx.rt_mx(symbol=str(m_as_string), t_den=f_obs.space_group().t_den())
      m_as_double = o.r().as_double()
      self.sym_matrices.append(m_as_double)
    self.gradient_evaluator = None
    self.target_and_grads = ext.tncs_eps_factor_refinery(
        tncs_pairs               = self.ncs_pairs,
        f_obs                    = self.f_obs.data(),
        sigma_f_obs              = self.f_obs.sigmas(),
        rbin                     = self.rbin,
        SigmaN                   = self.SigmaN,
        space_group              = self.f_obs.space_group(),
        miller_indices           = self.f_obs.indices(),
        fractionalization_matrix = self.f_obs.unit_cell().fractionalization_matrix(),
        sym_matrices             = self.sym_matrices)

    self.update()
 def pack_parameters(O):
   O.x = flex.double()
   O.l = flex.double()
   O.u = flex.double()
   O.nbd = flex.int()
   sstab = O.xray_structure.site_symmetry_table()
   for i_sc,sc in enumerate(O.xray_structure.scatterers()):
     assert sc.flags.use_u_iso()
     assert not sc.flags.use_u_aniso()
     #
     site_symmetry = sstab.get(i_sc)
     if (site_symmetry.is_point_group_1()):
       p = sc.site
     else:
       p = site_symmetry.site_constraints().independent_params(
         all_params=sc.site)
     O.x.extend(flex.double(p))
     O.l.resize(O.x.size(), 0)
     O.u.resize(O.x.size(), 0)
     O.nbd.resize(O.x.size(), 0)
     #
     O.x.append(sc.u_iso)
     O.l.append(0)
     O.u.append(0)
     O.nbd.append(1)
   O.x *= O.p_as_x
Пример #28
0
def exercise_multiple_atoms(mon_lib_srv, ener_lib):
    geometry, xrs = make_initial_grm(mon_lib_srv, ener_lib, raw_records1)

    # output for debugging!!!
    # show_sorted_geometry(geometry, xrs, 'before_exersice_multiple_atoms.geo')

    xrs_add = iotbx.pdb.input(source_info=None, lines=raw_records3) \
        .xray_structure_simple()
    proxy1 = geometry_restraints.bond_simple_proxy(i_seqs=(3, 9),
                                                   distance_ideal=2.0,
                                                   weight=3000)
    proxy2 = geometry_restraints.bond_simple_proxy(i_seqs=(4, 10),
                                                   distance_ideal=2.0,
                                                   weight=3000)

    new_xrs = xrs.concatenate(xrs_add)
    all_sites_cart = new_xrs.sites_cart()
    number_of_new_atoms = len(xrs_add.sites_cart())
    new_geometry = geometry.new_included_bonded_atoms(
        proxies=[proxy1, proxy2],
        sites_cart=all_sites_cart,
        site_symmetry_table=xrs_add.site_symmetry_table(),
        nonbonded_types=flex.std_string(["OH2"] * number_of_new_atoms),
        nonbonded_charges=flex.int(number_of_new_atoms, 0),
        skip_max_proxy_distance_calculation=True)
    # output for debugging!!!
    # show_sorted_geometry(new_geometry, new_xrs,
    #     'after_exersice_multiple_atoms.geo')

    assert new_geometry.pair_proxies().bond_proxies.simple.size() == 8
    assert new_geometry.pair_proxies().bond_proxies.asu.size() == 2
    assert new_geometry.pair_proxies().nonbonded_proxies.simple.size() == 11
    assert new_geometry.pair_proxies().nonbonded_proxies.asu.size() == 4
Пример #29
0
 def flex_std_string_as_miller_array(self,
                                     value,
                                     wavelength_id=None,
                                     crystal_id=None,
                                     scale_group_code=None):
     # Create a miller_array object of only the data and indices matching the
     # wavelength_id, crystal_id and scale_group_code submitted or full array if these are None
     selection = self.get_selection(value,
                                    wavelength_id=wavelength_id,
                                    crystal_id=crystal_id,
                                    scale_group_code=scale_group_code)
     data = value.select(selection)
     #if not isinstance(data, flex.double):
     try:
         data = flex.int(data)
         indices = self.indices.select(selection)
     except ValueError:
         try:
             data = flex.double(data)
             indices = self.indices.select(selection)
         except ValueError:
             # if flex.std_string return all values including '.' and '?'
             data = value
             indices = self.indices
     if data.size() == 0: return None
     return miller.array(
         miller.set(self.crystal_symmetry, indices).auto_anomalous(), data)
Пример #30
0
  def read_frames_updated_detail(self):
    from cctbx.crystal_orientation import crystal_orientation
    from xfel.cxi.util import is_odd_numbered

    frames = {'frame_id': flex.int(),
              'wavelength': flex.double(),
              'cc': flex.double(),
              'G': flex.double(),
              'BFACTOR': flex.double(),
              'RS': flex.double(),
              'odd_numbered': flex.bool(),
              'thetax': flex.double(),
              'thetay': flex.double(),
              'orientation': [],
              'unit_cell': [],
              'unique_file_name': []}
    stream = open(self.params.output.prefix + '_frame.db', 'r')
    for row in stream:
      items = row.split()
      CO = crystal_orientation([float(t) for t in items[8:17]], True)
      unique_file_name = eval(items[19])
      frames['frame_id'].append(int(items[0]))
      frames['wavelength'].append(float(items[1]))
      frames['cc'].append(float(items[20]))
      frames['G'].append(float(items[5]))
      frames['BFACTOR'].append(float(items[6]))
      frames['RS'].append(float(items[7]))
      frames['thetax'].append(float(items[17]))
      frames['thetay'].append(float(items[18]))
      frames['odd_numbered'].append(is_odd_numbered(unique_file_name))
      frames['orientation'].append(CO)
      frames['unit_cell'].append(CO.unit_cell())
      frames['unique_file_name'].append(unique_file_name)
    stream.close()
    return frames
Пример #31
0
def lbfgs_run(target_evaluator,
              use_bounds,
              lower_bound,
              upper_bound,
              max_iterations=None):
    minimizer = lbfgsb.minimizer(
        n=target_evaluator.n,
        #factr=1.e+1, XXX Affects speed significantly
        l=lower_bound,  # lower bound
        u=upper_bound,  # upper bound
        nbd=flex.int(target_evaluator.n,
                     use_bounds))  # flag to apply both bounds
    minimizer.error = None
    try:
        icall = 0
        while 1:
            icall += 1
            x, f, g = target_evaluator()
            #print "x,f:", ",".join(["%6.3f"%x_ for x_ in x]), f, icall
            have_request = minimizer.process(x, f, g)
            if (have_request):
                requests_f_and_g = minimizer.requests_f_and_g()
                continue
            assert not minimizer.requests_f_and_g()
            if (minimizer.is_terminated()): break
            # XXX temp fix for python3 failure (run_lbfgs in tncs)
            # Failure is that max_iterations is None
            # temp fix is to break if max_iterations is None or icall>max_iterations
            #if(icall>max_iterations): break
            if ((max_iterations is None) or (icall > max_iterations)): break
    except RuntimeError as e:
        minimizer.error = str(e)
    minimizer.n_calls = icall
    return minimizer
Пример #32
0
def all_defined_1():
    #                 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    barr = flex.int([1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1]).as_bool()
    iarr = [
        flex.size_t([0]),
        flex.size_t([1, 2]),
        flex.size_t([4, 5]),
        flex.size_t([8]),
        flex.size_t([12, 13, 14]),
        flex.size_t([15])
    ]
    oarr = [[flex.size_t([0]), flex.size_t([1, 2])], [flex.size_t([4, 5])],
            [flex.size_t([8])], [flex.size_t([12, 13, 14]),
                                 flex.size_t([15])]]
    return refinement_flags.manager(individual_sites=True,
                                    torsion_angles=True,
                                    rigid_body=True,
                                    individual_adp=True,
                                    group_adp=True,
                                    tls=True,
                                    occupancies=True,
                                    group_anomalous=True,
                                    sites_individual=barr,
                                    sites_torsion_angles=barr,
                                    sites_rigid_body=iarr,
                                    adp_individual_iso=barr,
                                    adp_individual_aniso=barr,
                                    adp_group=iarr,
                                    group_h=iarr,
                                    adp_tls=iarr,
                                    s_occupancies=oarr)
Пример #33
0
 def get_miller_indices_containing_loops(self):
     loops = []
     for loop in self.cif_block.loops.values():
         for key in loop.keys():
             if 'index_h' not in key: continue
             hkl_str = [
                 loop.get(key.replace('index_h', 'index_%s' % i))
                 for i in 'hkl'
             ]
             if hkl_str.count(None) > 0:
                 raise CifBuilderError(
                     "Miller indices missing from current CIF block (%s)" %
                     key.replace('index_h',
                                 'index_%s' % 'hkl'[hkl_str.index(None)]))
             hkl_int = []
             for i, h_str in enumerate(hkl_str):
                 try:
                     h_int = flex.int(h_str)
                 except ValueError, e:
                     raise CifBuilderError(
                         "Invalid item for Miller index %s: %s" %
                         ("HKL"[i], str(e)))
                 hkl_int.append(h_int)
             indices = flex.miller_index(*hkl_int)
             loops.append((indices, loop))
             break
Пример #34
0
 def get_frames_from_mysql(self,params):
   T = Timer("frames")
   CART = manager(params)
   db = CART.connection()
   cursor = db.cursor()
   cursor.execute("SELECT * FROM %s_frame;"%params.mysql.runtag)
   ALL = cursor.fetchall()
   from cctbx.crystal_orientation import crystal_orientation
   orientations = [crystal_orientation(
     (a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15],a[16]),False) for a in ALL]
   return dict( frame_id = flex.int( [a[0] for a in ALL] ),
               wavelength = flex.double( [a[1] for a in ALL] ),
                   beam_x = flex.double( [a[2] for a in ALL] ),
                   beam_y = flex.double( [a[3] for a in ALL] ),
                 distance = flex.double( [a[4] for a in ALL] ),
              orientation = orientations,
          rotation100_rad = flex.double([a[17] for a in ALL] ),
          rotation010_rad = flex.double([a[18] for a in ALL] ),
          rotation001_rad = flex.double([a[19] for a in ALL] ),
       half_mosaicity_deg = flex.double([a[20] for a in ALL] ),
              wave_HE_ang = flex.double([a[21] for a in ALL] ),
              wave_LE_ang = flex.double([a[22] for a in ALL] ),
          domain_size_ang = flex.double([a[23] for a in ALL] ),
         unique_file_name = [a[24] for a in ALL],
  )
Пример #35
0
 def _nonbonded_pair_objects(
     max_bonded_cutoff=3.,
     i_seqs=None,
 ):
     if i_seqs is None:
         atoms = self.pdb_hierarchy.atoms()
         i_seqs = flex.size_t()
         for atom in atoms:
             i_seqs.append(atom.i_seq)
     if (self.model_indices is not None):
         model_indices = self.model_indices.select(i_seqs)
     conformer_indices = self.conformer_indices.select(i_seqs)
     sym_excl_indices = self.sym_excl_indices.select(i_seqs)
     donor_acceptor_excl_groups = self.donor_acceptor_excl_groups.select(
         i_seqs)
     asu_mappings = self.special_position_settings.asu_mappings(
         buffer_thickness=max_bonded_cutoff)
     sites_cart = self.sites_cart.select(i_seqs)
     asu_mappings.process_sites_cart(
         original_sites=sites_cart,
         site_symmetry_table=self.site_symmetry_table().select(i_seqs))
     pair_asu_table = crystal.pair_asu_table(asu_mappings=asu_mappings)
     nonbonded_proxies = geometry_restraints.nonbonded_sorted_asu_proxies(
         model_indices=model_indices,
         conformer_indices=conformer_indices,
         sym_excl_indices=sym_excl_indices,
         donor_acceptor_excl_groups=donor_acceptor_excl_groups,
         nonbonded_params=geometry_restraints.nonbonded_params(
             default_distance=1),
         nonbonded_types=flex.std_string(conformer_indices.size()),
         nonbonded_charges=flex.int(conformer_indices.size(), 0),
         nonbonded_distance_cutoff_plus_buffer=max_bonded_cutoff,
         min_cubicle_edge=5,
         shell_asu_tables=[pair_asu_table])
     return nonbonded_proxies, sites_cart, pair_asu_table, asu_mappings, i_seqs
Пример #36
0
 def pack_parameters(O):
     O.x = flex.double()
     O.l = flex.double()
     O.u = flex.double()
     O.nbd = flex.int()
     sstab = O.xray_structure.site_symmetry_table()
     for i_sc, sc in enumerate(O.xray_structure.scatterers()):
         assert sc.flags.use_u_iso()
         assert not sc.flags.use_u_aniso()
         #
         site_symmetry = sstab.get(i_sc)
         if (site_symmetry.is_point_group_1()):
             p = sc.site
         else:
             p = site_symmetry.site_constraints().independent_params(
                 all_params=sc.site)
         O.x.extend(flex.double(p))
         O.l.resize(O.x.size(), 0)
         O.u.resize(O.x.size(), 0)
         O.nbd.resize(O.x.size(), 0)
         #
         O.x.append(sc.u_iso)
         O.l.append(0)
         O.u.append(0)
         O.nbd.append(1)
     O.x *= O.p_as_x
Пример #37
0
def sort_triple( triple ):
  order = flex.sort_permutation( flex.int(triple),False )
  sorted_triple = ( triple[order[0]],
                    triple[order[1]],
                    triple[order[2]] )

  return sorted_triple
Пример #38
0
    def cluster_completeness(self, clno, anomalous_flag, calc_redundancy=True):
        if clno not in self.clusters:
            print "Cluster No. %d not found" % clno
            return

        cls = self.clusters[clno][3]
        msets = map(lambda x: self.miller_sets[self.files[x-1]], cls)
        num_idx = sum(map(lambda x: x.size(), msets))
        all_idx = flex.miller_index()
        all_idx.reserve(num_idx)
        for mset in msets: all_idx.extend(mset.indices())

        # Calc median cell
        cells = numpy.array(map(lambda x: x.unit_cell().parameters(), msets))
        median_cell = map(lambda i: numpy.median(cells[:,i]), xrange(6))
        symm = msets[0].customized_copy(unit_cell=median_cell)

        assert anomalous_flag is not None
        # XXX all must belong to the same Laue group and appropriately reindexed..
        all_set = miller.set(indices=all_idx,
                             crystal_symmetry=symm, anomalous_flag=anomalous_flag)
        all_set = all_set.resolution_filter(d_min=self.d_min)

        # dummy for redundancy calculation. dirty way..
        if calc_redundancy:
            dummy_array = miller.array(miller_set=all_set, data=flex.int(all_set.size()))
            merge = dummy_array.merge_equivalents()
            cmpl = merge.array().completeness()
            redun = merge.redundancies().as_double().mean()
            return cmpl, redun
        else:
            cmpl = all_set.unique_under_symmetry().completeness()
            return cmpl
Пример #39
0
def lbfgs_run(target_evaluator, use_bounds, lower_bound, upper_bound):
    minimizer = lbfgsb.minimizer(
        n=target_evaluator.n,
        #factr=1.e+1, XXX Affects speed significantly
        l=lower_bound,  # lower bound
        u=upper_bound,  # upper bound
        nbd=flex.int(target_evaluator.n,
                     use_bounds))  # flag to apply both bounds
    minimizer.error = None
    try:
        icall = 0
        while 1:
            icall += 1
            x, f, g = target_evaluator()
            #print "x,f:", ",".join(["%6.3f"%x_ for x_ in x]), f, icall
            have_request = minimizer.process(x, f, g)
            if (have_request):
                requests_f_and_g = minimizer.requests_f_and_g()
                continue
            assert not minimizer.requests_f_and_g()
            if (minimizer.is_terminated()): break
    except RuntimeError as e:
        minimizer.error = str(e)
    minimizer.n_calls = icall
    return minimizer
Пример #40
0
    def __init__(self, data, lattice_id, resort=False, verbose=True):
        self.verbose = verbose
        ######  INPUTS #######
        #       data = miller array: ASU miller index & intensity
        #       lattice_id = flex double: assignment of each miller index to a lattice number
        ######################

        if resort:
            order = flex.sort_permutation(lattice_id.data())
            sorted_lattice_id = flex.select(lattice_id.data(), order)
            sorted_data = data.data().select(order)
            sorted_indices = data.indices().select(order)
            self.lattice_id = sorted_lattice_id
            self.data = data.customized_copy(indices=sorted_indices,
                                             data=sorted_data)
        else:
            self.lattice_id = lattice_id.data()  # type flex int
            self.data = data  # type miller array with flex double data
        assert type(self.data.indices()) == type(flex.miller_index())
        assert type(self.data.data()) == type(flex.double())

        # construct a lookup for the separate lattices
        last_id = -1
        self.lattices = flex.int()
        for n in xrange(len(self.lattice_id)):
            if self.lattice_id[n] != last_id:
                last_id = self.lattice_id[n]
                self.lattices.append(n)
def exercise_multiple_atoms(mon_lib_srv, ener_lib):
  geometry, xrs = make_initial_grm(mon_lib_srv, ener_lib, raw_records1)

  # output for debugging!!!
  # show_sorted_geometry(geometry, xrs, 'before_exersice_multiple_atoms.geo')

  xrs_add = iotbx.pdb.input(source_info=None, lines=raw_records3) \
      .xray_structure_simple()
  proxy1 = geometry_restraints.bond_simple_proxy(
      i_seqs=(3,9),
      distance_ideal=2.0,
      weight=3000)
  proxy2 = geometry_restraints.bond_simple_proxy(
      i_seqs=(4,10),
      distance_ideal=2.0,
      weight=3000)

  new_xrs = xrs.concatenate(xrs_add)
  all_sites_cart = new_xrs.sites_cart()
  number_of_new_atoms = len(xrs_add.sites_cart())
  new_geometry = geometry.new_included_bonded_atoms(
      proxies=[proxy1, proxy2],
      sites_cart=all_sites_cart,
      site_symmetry_table=xrs_add.site_symmetry_table(),
      nonbonded_types=flex.std_string(["OH2"]*number_of_new_atoms),
      nonbonded_charges=flex.int(number_of_new_atoms, 0),
      skip_max_proxy_distance_calculation=True)
  # output for debugging!!!
  # show_sorted_geometry(new_geometry, new_xrs,
  #     'after_exersice_multiple_atoms.geo')

  assert new_geometry.pair_proxies().bond_proxies.simple.size() == 8
  assert new_geometry.pair_proxies().bond_proxies.asu.size() == 2
  assert new_geometry.pair_proxies().nonbonded_proxies.simple.size() == 11
  assert new_geometry.pair_proxies().nonbonded_proxies.asu.size() == 4
Пример #42
0
 def _nonbonded_pair_objects(max_bonded_cutoff=3.,
                             i_seqs=None,
                             ):
   if i_seqs is None:
     atoms = self.pdb_hierarchy.atoms()
     i_seqs = flex.size_t()
     for atom in atoms:
       i_seqs.append(atom.i_seq)
   if (self.model_indices is not None):
     model_indices = self.model_indices.select(i_seqs)
   conformer_indices = self.conformer_indices.select(i_seqs)
   sym_excl_indices = self.sym_excl_indices.select(i_seqs)
   donor_acceptor_excl_groups = self.donor_acceptor_excl_groups.select(i_seqs)
   asu_mappings = self.special_position_settings.asu_mappings(
     buffer_thickness=max_bonded_cutoff)
   sites_cart = self.sites_cart.select(i_seqs)
   asu_mappings.process_sites_cart(
     original_sites=sites_cart,
     site_symmetry_table=self.site_symmetry_table().select(i_seqs))
   pair_asu_table = crystal.pair_asu_table(asu_mappings=asu_mappings)
   nonbonded_proxies = geometry_restraints.nonbonded_sorted_asu_proxies(
     model_indices=model_indices,
     conformer_indices=conformer_indices,
     sym_excl_indices=sym_excl_indices,
     donor_acceptor_excl_groups=donor_acceptor_excl_groups,
     nonbonded_params=geometry_restraints.nonbonded_params(
       default_distance=1),
     nonbonded_types=flex.std_string(conformer_indices.size()),
     nonbonded_charges=flex.int(conformer_indices.size(), 0),
     nonbonded_distance_cutoff_plus_buffer=max_bonded_cutoff,
     min_cubicle_edge=5,
     shell_asu_tables=[pair_asu_table])
   return nonbonded_proxies, sites_cart, pair_asu_table, asu_mappings, i_seqs
Пример #43
0
  def __init__(self, data, lattice_id, resort=False, verbose=True):
    self.verbose = verbose
    ######  INPUTS #######
    #       data = miller array: ASU miller index & intensity
    #       lattice_id = flex double: assignment of each miller index to a lattice number
    ######################

    if resort:
      order = flex.sort_permutation(lattice_id.data())
      sorted_lattice_id = flex.select(lattice_id.data(), order)
      sorted_data = data.data().select( order)
      sorted_indices = data.indices().select( order)
      self.lattice_id = sorted_lattice_id
      self.data = data.customized_copy(indices = sorted_indices, data = sorted_data)
    else:
      self.lattice_id = lattice_id.data() # type flex int
      self.data = data # type miller array with flex double data
    assert type(self.data.indices()) == type(flex.miller_index())
    assert type(self.data.data()) == type(flex.double())

    # construct a lookup for the separate lattices
    last_id = -1; self.lattices = flex.int()
    for n in xrange(len(self.lattice_id)):
      if self.lattice_id[n] != last_id:
        last_id = self.lattice_id[n]
        self.lattices.append(n)
    def read_frames(self):
        from xfel.cxi.util import is_odd_numbered

        cursor = self._db.cursor()
        cursor.execute("""SELECT
    frame_id_1_base,wavelength,c_c,slope,offset,res_ori_1,res_ori_2,res_ori_3,
    res_ori_4,res_ori_5,res_ori_6,res_ori_7,res_ori_8,res_ori_9,
    unique_file_name
    FROM _frame""")
        ALL = cursor.fetchall()
        from cctbx.crystal_orientation import crystal_orientation
        orientations = [
            crystal_orientation(
                (a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13]),
                False) for a in ALL
        ]
        return dict(frame_id=flex.int([a[0] - 1 for a in ALL]),
                    wavelength=flex.double([a[1] for a in ALL]),
                    cc=flex.double([a[2] for a in ALL]),
                    slope=flex.double([a[3] for a in ALL]),
                    offset=flex.double([a[4] for a in ALL]),
                    odd_numbered=flex.bool(
                        [is_odd_numbered(a[14]) for a in ALL]),
                    orientation=orientations,
                    unit_cell=[CO.unit_cell() for CO in orientations],
                    unique_file_name=[a[14] for a in ALL])
Пример #45
0
    def from_predictions_multi(experiments,
                               dmin=None,
                               dmax=None,
                               margin=1,
                               force_static=False,
                               padding=0):
        '''
    Construct a reflection table from predictions.

    :param experiments: The experiment list to predict from
    :param dmin: The maximum resolution
    :param dmax: The minimum resolution
    :param margin: The margin to predict around
    :param force_static: Do static prediction with a scan varying model
    :param padding: Padding in degrees
    :return: The reflection table of predictions

    '''
        from scitbx.array_family import flex
        result = reflection_table()
        for i, e in enumerate(experiments):
            rlist = reflection_table.from_predictions(
                e,
                dmin=dmin,
                dmax=dmax,
                margin=margin,
                force_static=force_static,
                padding=padding)
            rlist['id'] = flex.int(len(rlist), i)
            result.extend(rlist)
        return result
Пример #46
0
  def from_predictions_multi(experiments,
                             dmin=None,
                             dmax=None,
                             margin=1,
                             force_static=False):
    '''
    Construct a reflection table from predictions.

    :param experiments: The experiment list to predict from
    :param dmin: The maximum resolution
    :param dmax: The minimum resolution
    :param margin: The margin to predict around
    :param force_static: Do static prediction with a scan varying model
    :return: The reflection table of predictions

    '''
    from scitbx.array_family import flex
    result = reflection_table()
    for i, e in enumerate(experiments):
      rlist = reflection_table.from_predictions(
        e,
        dmin=dmin,
        dmax=dmax,
        margin=margin,
        force_static=force_static)
      rlist['id'] = flex.int(len(rlist), i)
      result.extend(rlist)
    return result
Пример #47
0
def exercise_extract_delta_anomalous():
    miller_array_start = miller.set(
        crystal_symmetry=crystal.symmetry(unit_cell=(10, 10, 10, 90, 90, 90), space_group_symbol="P1"),
        indices=flex.miller_index([(1, 2, 3), (-1, -2, -3)]),
        anomalous_flag=True,
    ).array(data=flex.double([3, 5]), sigmas=flex.double([0.3, 0.5]))
    mtz_dataset = miller_array_start.as_mtz_dataset(column_root_label="F")
    mtz_object = mtz_dataset.mtz_object()
    fp = mtz_object.get_column(label="F(+)").extract_values()[0]
    fm = mtz_object.get_column(label="F(-)").extract_values()[0]
    sp = mtz_object.get_column(label="SIGF(+)").extract_values()[0]
    sm = mtz_object.get_column(label="SIGF(-)").extract_values()[0]
    # http://www.ccp4.ac.uk/dist/html/mtzMADmod.html
    # F = 0.5*( F(+) + F(-) )
    # D = F(+) - F(-)
    # SIGD = sqrt( SIGF(+)**2 + SIGF(-)**2 )
    # SIGF = 0.5*SIGD
    f = 0.5 * (fp + fm)
    d = fp - fm
    sigd = math.sqrt(sp ** 2 + sm ** 2)
    sigf = 0.5 * sigd
    mtz_dataset.add_column(label="F", type="F").set_reals(mtz_reflection_indices=flex.int([0]), data=flex.double([f]))
    mtz_dataset.add_column(label="SIGF", type="Q").set_reals(
        mtz_reflection_indices=flex.int([0]), data=flex.double([sigf])
    )
    mtz_dataset.add_column(label="D", type="D").set_reals(mtz_reflection_indices=flex.int([0]), data=flex.double([d]))
    mtz_dataset.add_column(label="SIGD", type="Q").set_reals(
        mtz_reflection_indices=flex.int([0]), data=flex.double([sigd])
    )
    miller_arrays = mtz_object.as_miller_arrays()
    assert len(miller_arrays) == 2
    miller_array = miller_arrays[0]
    assert list(miller_array.indices()) == [(1, 2, 3), (-1, -2, -3)]
    assert approx_equal(miller_array.data(), [3, 5])
    assert approx_equal(miller_array.sigmas(), [0.3, 0.5])
    miller_array = miller_arrays[1]
    assert list(miller_array.indices()) == [(1, 2, 3), (-1, -2, -3)]
    # F(+) = F + 0.5*D
    # F(-) = F - 0.5*D
    # SIGF(+) = sqrt( SIGF**2 + 0.25*SIGD**2 )
    # SIGF(-) = SIGF(+)
    fp = f + 0.5 * d
    fm = f - 0.5 * d
    assert approx_equal([fp, fm], miller_array.data())
    sp = math.sqrt(sigf ** 2 + 0.25 * sigd ** 2)
    sm = sp
    assert approx_equal([sp, sm], miller_array.sigmas())
Пример #48
0
def exercise_add_2b():
    rm = all_defined_1()
    # [ [0], [1,2], [4,5], [8], [12,13,14], [15] ] - original
    # [ [0], [2,3], [5,6], [9], [14,15,16], [18] ] - after insertion for tuples
    #
    # [ [[0],[1,2]], [[4,5]], [[8]], [[12,13,14],[15]] ] - original
    # [ [[0],[2,3]], [[5,6]], [[9]], [[14,15,16],[18]] ] - after insertion for tuples
    #
    #  0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    # [1,1,1,0,1,1,0,0,1,0, 0, 0, 1, 1, 1, 1] - original
    # [1,0,1,1,0,1,1,0,0,1,0,0,0,0,1,1,1,0,1,0]  - after insertion for bool single
    rm = rm.add(next_to_i_seqs=flex.size_t([0, 10, 14, 15]),
                sites_individual=False,
                sites_torsion_angles=False,
                sites_rigid_body=False,
                adp_individual_iso=False,
                adp_individual_aniso=False,
                adp_group=False,
                group_h=False,
                adp_tls=False,
                s_occupancies=False)
    out = StringIO()
    rm.show(log=out)
    assert not show_diff(
        out.getvalue(), """\
Refinement flags and selection counts:
  individual_sites       = %s (10 atoms)
  torsion_angles         = %s (10 atoms)
  rigid_body             = %s (10 atoms in 6 groups)
  individual_adp         = %s (iso = 10 aniso = 10)
  group_adp              = %s (10 atoms in 6 groups)
  tls                    = %s (10 atoms in 6 groups)
  occupancies            = %s (10 atoms)
  group_anomalous        = %s
""" % tuple(["%5s" % str(True)] * 8))
    barr_result = flex.int(
        [1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1,
         0]).as_bool()
    iarr_result = [
        flex.size_t([0]),
        flex.size_t([2, 3]),
        flex.size_t([5, 6]),
        flex.size_t([9]),
        flex.size_t([14, 15, 16]),
        flex.size_t([18])
    ]
    oarr_result = [[flex.size_t([0]), flex.size_t([2, 3])],
                   [flex.size_t([5, 6])], [flex.size_t([9])],
                   [flex.size_t([14, 15, 16]),
                    flex.size_t([18])]]
    assert approx_equal(rm.sites_individual, barr_result)
    assert approx_equal(rm.sites_torsion_angles, barr_result)
    assert approx_equal(rm.sites_rigid_body, iarr_result)
    assert approx_equal(rm.adp_individual_iso, barr_result)
    assert approx_equal(rm.adp_individual_aniso, barr_result)
    assert approx_equal(rm.adp_group, iarr_result)
    assert approx_equal(rm.group_h, iarr_result)
    assert approx_equal(rm.adp_tls, iarr_result)
    compare_selections(rm.s_occupancies, oarr_result)
Пример #49
0
def exercise_flex_miller_index():
  from scitbx.array_family.flex import exercise_triple
  exercise_triple(flex_triple=flex.miller_index, flex_order=flex.order)
  a = flex.miller_index([(1,2,3), (2,3,4)])
  assert approx_equal(a.as_vec3_double(), [(1,2,3), (2,3,4)])
  h, k, l = [flex.int((0,1,2,3)),
             flex.int((1,2,3,4)),
             flex.int((2,3,4,5))]
  b = flex.miller_index(h, k, l)
  assert approx_equal(b, ((0,1,2),(1,2,3),(2,3,4),(3,4,5)))
  #
  i = flex.miller_index([(1,-2,3), (-2,3,4)])
  c = flex.complex_double([3-4j, -7+8j])
  x = (0.9284, -1.2845, -0.2293)
  assert approx_equal(
    i.fourier_transform_real_part_at_x(fourier_coeffs=c, x=x),
    15.4357188164)
Пример #50
0
def exercise_flex_miller_index():
  from scitbx.array_family.flex import exercise_triple
  exercise_triple(flex_triple=flex.miller_index, flex_order=flex.order)
  a = flex.miller_index([(1,2,3), (2,3,4)])
  assert approx_equal(a.as_vec3_double(), [(1,2,3), (2,3,4)])
  h, k, l = [flex.int((0,1,2,3)),
             flex.int((1,2,3,4)),
             flex.int((2,3,4,5))]
  b = flex.miller_index(h, k, l)
  assert approx_equal(b, ((0,1,2),(1,2,3),(2,3,4),(3,4,5)))
  #
  i = flex.miller_index([(1,-2,3), (-2,3,4)])
  c = flex.complex_double([3-4j, -7+8j])
  x = (0.9284, -1.2845, -0.2293)
  assert approx_equal(
    i.fourier_transform_real_part_at_x(fourier_coeffs=c, x=x),
    15.4357188164)
def exercise (debug=False) :
  if (not libtbx.env.has_module("phenix_regression")) :
    print "phenix_regression not configured, skipping."
    return
  hkl_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/wizards/p9_se_w2.sca",
    test=os.path.isfile)
  args = [
    hkl_file,
    "space_group=I4",
    "unit_cell=113.949,113.949,32.474,90,90,90",
    "loggraph=True",
  ]
  if (debug) :
    args.append("debug=True")
    print " ".join(args)
  out = StringIO()
  result = merging_statistics.run(args, out=out)
  if (debug) :
    print out.getvalue()
  assert ("R-merge: 0.073" in out.getvalue())
  assert ("R-meas:  0.079" in out.getvalue())
  assert ("""  1.81   1.74  12528   2073    6.04  97.05    1449.2     5.2  0.252  0.275  0.110  0.9""" in out.getvalue()), out.getvalue()
  cif_block = result.as_cif_block()
  assert "_reflns_shell" in cif_block
  assert approx_equal(float(cif_block["_reflns.pdbx_Rpim_I_obs"]), result.overall.r_pim)
  assert approx_equal(float(cif_block["_reflns.phenix_cc_star"]), result.overall.cc_star)
  assert approx_equal(float(cif_block["_reflns.phenix_cc_1/2"]), result.overall.cc_one_half)
  assert approx_equal(
    flex.int(cif_block["_reflns_shell.number_measured_obs"]),
    [15737, 15728, 15668, 15371, 14996, 14771, 13899, 13549, 13206, 12528])
  assert "_reflns_shell.phenix_cc_star" in cif_block
  assert "_reflns_shell.phenix_cc_1/2" in cif_block
  remark_200 = result.as_remark_200(wavelength=0.9792).splitlines()
  assert ("REMARK 200  <I/SIGMA(I)> FOR SHELL         : 5.1536" in remark_200),"\n".join(remark_200)
  assert ("REMARK 200  WAVELENGTH OR RANGE        (A) : 0.9792" in remark_200)
  # test resolution cutoffs
  args2 = list(args[:-1]) + ["high_resolution=2.5", "low_resolution=15"]
  out = StringIO()
  result = merging_statistics.run(args2, out=out)
  if (debug) :
    print out.getvalue()
  assert ("Resolution: 14.96 - 2.50" in out.getvalue())
  # extend binning
  args2 = list(args[:-1]) + ["high_resolution=1.5", "low_resolution=100",
    "--extend_d_max_min"]
  out = StringIO()
  result = merging_statistics.run(args2, out=out)
  if (debug) :
    print out.getvalue()
  assert ("Resolution: 100.00 - 1.50" in out.getvalue())
  assert ("  1.55   1.50      0      0    0.00   0.00       0.0     0.0   None   None   None  0.000  0.000""" in out.getvalue())
  # these should crash
  args2 = list(args[:-1]) + ["high_resolution=15", "low_resolution=2.5"]
  try :
    result = merging_statistics.run(args2, out=out)
  except Sorry, s :
    pass
  def literals(self):
    frame_dict = self.database.get_frame_dictionary()

    if self.params.run_numbers is None:
      path = self.params.outdir_template
      stream = open(path,"r")
      print path
      for line in stream.xreadlines():
        if line.find("XFEL processing:") == 0:
           tokens = line.strip().split("/")
           picklefile = line.strip().split()[2]
           frame_id = frame_dict.get(picklefile, None)
           if frame_id is not None:
             print "FETCHED",frame_id
        if line.find("CV OBSCENTER")==0 and line.find("Traceback")==-1:
          potential_tokens = line.strip().split()
          if len(potential_tokens)==22 and \
                 potential_tokens[17].isdigit() and \
                 int(potential_tokens[17])==self.params.bravais_setting_id:
            yield frame_id,potential_tokens
        if len(self.tiles)==0 and line.find("EFFEC")==0:
          self.tiles = flex.int([int(a) for a in line.strip().split()[2:]])
          assert len(self.tiles)==256
          print list(self.tiles)
          self.initialize_per_tile_sums()
      return
    for run in self.params.run_numbers:
        templ = self.params.outdir_template%run
        items = os.listdir(templ)
        for item in items:
          path = os.path.join(templ,item)
          stream = open(path,"r")
          print path
          for line in stream.xreadlines():
            if line.find("CV OBSCENTER")==0:
              potential_tokens = line.strip().split()
              if len(potential_tokens)==22 and \
                 potential_tokens[17].isdigit() and \
                 int(potential_tokens[17])==self.params.bravais_setting_id:
                yield None,potential_tokens
            if len(self.tiles)==0 and line.find("EFFEC")==0:
              self.tiles = flex.int([int(a) for a in line.strip().split()[2:]])
              assert len(self.tiles)==256
              print list(self.tiles)
              self.initialize_per_tile_sums()
Пример #53
0
 def reduce_by_miller_index(self, miller_indices):
     sequences = range(self.get_size())
     matches = miller.match_multi_indices(
         miller_indices_unique=miller_indices,
         miller_indices=self.miller_indices_merge)
     pair_1 = flex.int([pair[1] for pair in matches.pairs()])
     sequences_bin = flex.size_t(
         [sequences[pair_1[j]] for j in range(len(matches.pairs()))])
     self.reduce_by_selection(sequences_bin)
Пример #54
0
def should_return_atom_types():
    atom_number = flex.int()
    coordinates = flex.vec3_double()
    for i in range(3):
        atom_number.append(i)
        coordinates.append((i, i, i))
    atom_types = multipolar.assign_atom_types(atom_number, coordinates)
    #print atom_types
    for atom_type in atom_types:
        print(atom_type)
 def add_pairs(self):
     # XXX possible optimizations:
     #   if 0 continuous shifts:
     #     tabulate dist
     #     keep all < tolerance
     #     we do not need eliminate_weak_matches
     timer = user_plus_sys_time()
     while (len(self.singles1) and len(self.singles2)):
         if (not self.add_pair_ext.next_pair(self.adjusted_shift,
                                             flex.int(self.singles1),
                                             flex.int(self.singles2))):
             break
         new_pair = (self.add_pair_ext.new_pair_1(),
                     self.add_pair_ext.new_pair_2())
         self.pairs.append(new_pair)
         self.singles1.remove(new_pair[0])
         self.singles2.remove(new_pair[1])
         self.refine_adjusted_shift()
     self.times.add_pairs += timer.delta()
Пример #56
0
def should_return_atom_types():
    atom_number = flex.int()
    coordinates = flex.vec3_double()
    for i in range(3):
        atom_number.append(i)
        coordinates.append((i, i, i))
    atom_types = multipolar.assign_atom_types(atom_number, coordinates)
    # print atom_types
    for atom_type in atom_types:
        print atom_type
Пример #57
0
def image_as_flex_int(image_name,image_type=None,subtract_pedestal=True):
  img_factory = detectors.TrySingleImageType(image_name,image_type)
  img_factory.readHeader(external_keys=[('PEDESTAL','PEDESTAL',int)])
  img_factory.read()
  result = img_factory.linearintdata
  result = flex.int( list(result) )
  if subtract_pedestal:
    if image_type not in non_pedestal_image_types:
      result = result - img_factory.parameters['PEDESTAL']

  return result
 def add_pairs(self):
   # XXX possible optimizations:
   #   if 0 continuous shifts:
   #     tabulate dist
   #     keep all < tolerance
   #     we do not need eliminate_weak_matches
   timer = user_plus_sys_time()
   while (len(self.singles1) and len(self.singles2)):
     if (not self.add_pair_ext.next_pair(
       self.adjusted_shift,
       flex.int(self.singles1),
       flex.int(self.singles2))):
       break
     new_pair = (self.add_pair_ext.new_pair_1(),
                 self.add_pair_ext.new_pair_2())
     self.pairs.append(new_pair)
     self.singles1.remove(new_pair[0])
     self.singles2.remove(new_pair[1])
     self.refine_adjusted_shift()
   self.times.add_pairs += timer.delta()
Пример #59
0
def intersection(cuts):
  assert len(cuts) == 3
  m = flex.int()
  t = flex.int()
  denominator = 1
  for cut in cuts:
    denominator = cut.lcm_of_denominators(start_lcm=denominator)
  for cut in cuts:
    for e in cut.n: m.append(int(e * denominator))
    t.append(-int(cut.c * denominator))
  m.reshape(flex.grid(3,3))
  t.reshape(flex.grid(3,1))
  r = scitbx.math.row_echelon_form_t(m, t)
  assert r in (2,3)
  if (r != 3): return None
  t.reshape(flex.grid(3))
  sol = flex.int(3)
  d = scitbx.math.row_echelon_back_substitution_int(m, t, sol)
  assert d > 0
  return tuple([rational.int(s,d) for s in sol])