예제 #1
0
def run(args):
    def vdw_radii_callback(option, opt_str, value, parser):
        # create a dict from space separated string of element types and radii
        radii = {}
        items = value.split()
        assert len(items) % 2 == 0
        for i in range(int(len(items) / 2)):
            radii.setdefault(items[i * 2], float(items[i * 2 + 1]))
        setattr(parser.values, option.dest, radii)

    command_line = (option_parser(
        usage="smtbx.masks structure reflections [options]"
    ).enable_symmetry_comprehensive().option(
        None, "--solvent_radius", action="store", type="float",
        default=1.3).option(
            None,
            "--shrink_truncation_radius",
            action="store",
            type="float",
            default=1.3).option(None, "--debug", action="store_true").option(
                None, "--verbose", action="store_true").option(
                    None,
                    "--resolution_factor",
                    action="store",
                    type="float",
                    default=1 / 4).option(
                        None, "--grid_step", action="store",
                        type="float").option(
                            None, "--d_min", action="store",
                            type="float").option(
                                None,
                                "--two_theta_max",
                                action="store",
                                type="float").option(
                                    None,
                                    "--cb_op",
                                    action="store",
                                    type="string").option(
                                        None,
                                        "--vdw_radii",
                                        action="callback",
                                        callback=vdw_radii_callback,
                                        type="string",
                                        nargs=1).option(
                                            None,
                                            "--use_space_group_symmetry",
                                            action="store_true")).process(
                                                args=args)
    structure_file = command_line.args[0]
    ext = os.path.splitext(structure_file)[-1].lower()
    if ext in ('.res', '.ins'):
        xs = xray.structure.from_shelx(filename=structure_file)
    elif ext == '.cif':
        xs = xray.structure.from_cif(filename=structure_file)
    else:
        print "%s: unsupported structure file format {shelx|cif}" % ext
        return
    reflections_server = reflection_file_utils.reflection_file_server(
        crystal_symmetry=xs.crystal_symmetry(),
        reflection_files=[
            reflection_file_reader.any_reflection_file(command_line.args[1])
        ])
    fo_sq = reflections_server.get_miller_arrays(None)[0]

    if command_line.options.cb_op is not None:
        cb_op = sgtbx.change_of_basis_op(
            sgtbx.rt_mx(command_line.options.cb_op))
        fo_sq = fo_sq.change_basis(cb_op).customized_copy(crystal_symmetry=xs)

    print "structure file: %s" % command_line.args[0]
    print "reflection file: %s" % command_line.args[1]
    if command_line.options.debug:
        print "debug: %s" % command_line.options.debug
    print

    xs.show_summary()
    print

    d_min = command_line.options.d_min
    two_theta_max = command_line.options.two_theta_max
    assert [d_min, two_theta_max].count(None) > 0
    if two_theta_max is not None:
        d_min = uctbx.two_theta_as_d(two_theta_max,
                                     wavelength=0.71073,
                                     deg=True)
    exercise_masks(
        xs,
        fo_sq,
        solvent_radius=command_line.options.solvent_radius,
        shrink_truncation_radius=command_line.options.shrink_truncation_radius,
        resolution_factor=command_line.options.resolution_factor,
        grid_step=command_line.options.grid_step,
        resolution_cutoff=d_min,
        atom_radii_table=command_line.options.vdw_radii,
        use_space_group_symmetry=command_line.options.use_space_group_symmetry,
        debug=command_line.options.debug,
        verbose=command_line.options.verbose)
    print "OK"
예제 #2
0
def exercise_functions():
  d_star_sq_s = 1.2345
  d_star_sq_a = flex.double((1.2345, 0.1234))
  two_theta_s = 0.61725
  two_theta_a = flex.double((0.61725,0.65432))
  # forward conversions
  assert approx_equal(
    uctbx.d_star_sq_as_stol_sq(d_star_sq_s), d_star_sq_s / 4)
  assert approx_equal(
    uctbx.d_star_sq_as_stol_sq(d_star_sq_a),
    [uctbx.d_star_sq_as_stol_sq(i) for i in d_star_sq_a])
  assert approx_equal(
    uctbx.d_star_sq_as_two_stol(d_star_sq_s)**2, d_star_sq_s)
  assert approx_equal(
    uctbx.d_star_sq_as_two_stol(d_star_sq_a),
    [uctbx.d_star_sq_as_two_stol(i) for i in d_star_sq_a])
  assert approx_equal(
    uctbx.d_star_sq_as_stol(d_star_sq_s)**2, d_star_sq_s / 4)
  assert approx_equal(
    uctbx.d_star_sq_as_stol(d_star_sq_a),
    [uctbx.d_star_sq_as_stol(i) for i in d_star_sq_a])
  assert approx_equal(
    1/(uctbx.d_star_sq_as_d(d_star_sq_s)**2), d_star_sq_s)
  assert approx_equal(
    uctbx.d_star_sq_as_d(d_star_sq_a),
    [uctbx.d_star_sq_as_d(i) for i in d_star_sq_a])
  assert approx_equal(
    uctbx.d_star_sq_as_two_theta(d_star_sq_s, 1.5),
    2 * asin(1.5/2*sqrt(d_star_sq_s)))
  assert approx_equal(
    uctbx.d_star_sq_as_two_theta(d_star_sq_s, 1.5),
    uctbx.d_star_sq_as_two_theta(d_star_sq_s, 1.5, False))
  assert approx_equal(
    uctbx.d_star_sq_as_two_theta(d_star_sq_a, 1.5),
    [uctbx.d_star_sq_as_two_theta(i, 1.5) for i in d_star_sq_a])
  assert approx_equal(
    uctbx.d_star_sq_as_two_theta(d_star_sq_s, 1.5)*180/pi,
    uctbx.d_star_sq_as_two_theta(d_star_sq_s, 1.5, True))
  # reverse conversions
  for d_star_sq, two_theta in zip(
    (d_star_sq_s, d_star_sq_a),(two_theta_s, two_theta_a)):
    assert approx_equal(
      uctbx.stol_sq_as_d_star_sq(
        uctbx.d_star_sq_as_stol_sq(d_star_sq)), d_star_sq)
    assert approx_equal(
      uctbx.two_stol_as_d_star_sq(
        uctbx.d_star_sq_as_two_stol(d_star_sq)), d_star_sq)
    assert approx_equal(
      uctbx.stol_as_d_star_sq(
        uctbx.d_star_sq_as_stol(d_star_sq)), d_star_sq)
    assert approx_equal(
      uctbx.d_as_d_star_sq(
        uctbx.d_star_sq_as_d(d_star_sq)), d_star_sq)
    assert approx_equal(
      uctbx.two_theta_as_d_star_sq(
        uctbx.d_star_sq_as_two_theta(d_star_sq, 1.5), 1.5), d_star_sq)
    assert approx_equal(
      uctbx.two_theta_as_d_star_sq(two_theta, 1.5),
      uctbx.two_theta_as_d_star_sq(two_theta, 1.5, False))
    assert approx_equal(
      uctbx.two_theta_as_d_star_sq(two_theta, 1.5),
      uctbx.two_theta_as_d_star_sq(two_theta*180/pi, 1.5, True))
    assert approx_equal(
      uctbx.two_theta_as_d(two_theta, 1.5),
      uctbx.d_star_sq_as_d(uctbx.two_theta_as_d_star_sq(two_theta, 1.5)))
    assert approx_equal(
      uctbx.two_theta_as_d(two_theta, 1.5, True),
      uctbx.d_star_sq_as_d(uctbx.two_theta_as_d_star_sq(two_theta, 1.5, True)))
  #
  assert uctbx.fractional_unit_shifts(distance_frac=[0,0,0]) == (0,0,0)
  assert uctbx.fractional_unit_shifts([0.6,7.4,-0.4]) == (1,7,0)
  assert uctbx.fractional_unit_shifts([-6,3,-0.6]) == (-6,3,-1)
  site_frac_1 = [0.3,-8.6,2.1]
  for eps,expected_u2 in [(-1.e-5, 1), (1.e-5, 2)]:
    site_frac_2 = [-3,5.6,0.6-eps]
    assert uctbx.fractional_unit_shifts(
      site_frac_1=site_frac_1,
      site_frac_2=site_frac_2) == (3, -14, expected_u2)
예제 #3
0
def run(args):
  def vdw_radii_callback(option, opt_str, value, parser):
    # create a dict from space separated string of element types and radii
    radii = {}
    items = value.split()
    assert len(items) % 2 == 0
    for i in range(int(len(items) / 2)):
      radii.setdefault(items[i*2], float(items[i*2+1]))
    setattr(parser.values, option.dest, radii)
  command_line = (option_parser(
    usage="smtbx.masks structure reflections [options]")
                  .enable_symmetry_comprehensive()
                  .option(None, "--solvent_radius",
                          action="store",
                          type="float",
                          default=1.3)
                  .option(None, "--shrink_truncation_radius",
                          action="store",
                          type="float",
                          default=1.3)
                  .option(None, "--debug",
                          action="store_true")
                  .option(None, "--verbose",
                          action="store_true")
                  .option(None, "--resolution_factor",
                          action="store",
                          type="float",
                          default=1/4)
                  .option(None, "--grid_step",
                          action="store",
                          type="float")
                  .option(None, "--d_min",
                          action="store",
                          type="float")
                  .option(None, "--two_theta_max",
                          action="store",
                          type="float")
                  .option(None, "--cb_op",
                          action="store",
                          type="string")
                  .option(None, "--vdw_radii",
                          action="callback",
                          callback=vdw_radii_callback,
                          type="string",
                          nargs=1)
                  .option(None, "--use_space_group_symmetry",
                          action="store_true")).process(args=args)
  structure_file = command_line.args[0]
  ext = os.path.splitext(structure_file)[-1].lower()
  if ext in ('.res', '.ins'):
    xs = xray.structure.from_shelx(filename=structure_file)
  elif ext == '.cif':
    xs = xray.structure.from_cif(filename=structure_file)
  else:
    print "%s: unsupported structure file format {shelx|cif}" %ext
    return
  reflections_server = reflection_file_utils.reflection_file_server(
    crystal_symmetry = xs.crystal_symmetry(),
    reflection_files = [
      reflection_file_reader.any_reflection_file(command_line.args[1])
    ]
  )
  fo_sq = reflections_server.get_miller_arrays(None)[0]

  if command_line.options.cb_op is not None:
    cb_op = sgtbx.change_of_basis_op(sgtbx.rt_mx(command_line.options.cb_op))
    fo_sq = fo_sq.change_basis(cb_op).customized_copy(
      crystal_symmetry=xs)

  print "structure file: %s" %command_line.args[0]
  print "reflection file: %s" %command_line.args[1]
  if command_line.options.debug:
    print "debug: %s" %command_line.options.debug
  print

  xs.show_summary()
  print

  d_min = command_line.options.d_min
  two_theta_max = command_line.options.two_theta_max
  assert [d_min, two_theta_max].count(None) > 0
  if two_theta_max is not None:
    d_min = uctbx.two_theta_as_d(two_theta_max, wavelength=0.71073, deg=True)
  exercise_masks(
    xs, fo_sq,
    solvent_radius=command_line.options.solvent_radius,
    shrink_truncation_radius=command_line.options.shrink_truncation_radius,
    resolution_factor=command_line.options.resolution_factor,
    grid_step=command_line.options.grid_step,
    resolution_cutoff=d_min,
    atom_radii_table=command_line.options.vdw_radii,
    use_space_group_symmetry=command_line.options.use_space_group_symmetry,
    debug=command_line.options.debug,
    verbose=command_line.options.verbose)
  print "OK"
예제 #4
0
def exercise_functions():
    d_star_sq_s = 1.2345
    d_star_sq_a = flex.double((1.2345, 0.1234))
    two_theta_s = 0.61725
    two_theta_a = flex.double((0.61725, 0.65432))
    # forward conversions
    assert approx_equal(uctbx.d_star_sq_as_stol_sq(d_star_sq_s),
                        d_star_sq_s / 4)
    assert approx_equal(uctbx.d_star_sq_as_stol_sq(d_star_sq_a),
                        [uctbx.d_star_sq_as_stol_sq(i) for i in d_star_sq_a])
    assert approx_equal(
        uctbx.d_star_sq_as_two_stol(d_star_sq_s)**2, d_star_sq_s)
    assert approx_equal(uctbx.d_star_sq_as_two_stol(d_star_sq_a),
                        [uctbx.d_star_sq_as_two_stol(i) for i in d_star_sq_a])
    assert approx_equal(
        uctbx.d_star_sq_as_stol(d_star_sq_s)**2, d_star_sq_s / 4)
    assert approx_equal(uctbx.d_star_sq_as_stol(d_star_sq_a),
                        [uctbx.d_star_sq_as_stol(i) for i in d_star_sq_a])
    assert approx_equal(1 / (uctbx.d_star_sq_as_d(d_star_sq_s)**2),
                        d_star_sq_s)
    assert approx_equal(uctbx.d_star_sq_as_d(d_star_sq_a),
                        [uctbx.d_star_sq_as_d(i) for i in d_star_sq_a])
    assert approx_equal(uctbx.d_star_sq_as_two_theta(d_star_sq_s, 1.5),
                        2 * asin(1.5 / 2 * sqrt(d_star_sq_s)))
    assert approx_equal(uctbx.d_star_sq_as_two_theta(d_star_sq_s, 1.5),
                        uctbx.d_star_sq_as_two_theta(d_star_sq_s, 1.5, False))
    assert approx_equal(
        uctbx.d_star_sq_as_two_theta(d_star_sq_a, 1.5),
        [uctbx.d_star_sq_as_two_theta(i, 1.5) for i in d_star_sq_a])
    assert approx_equal(
        uctbx.d_star_sq_as_two_theta(d_star_sq_s, 1.5) * 180 / pi,
        uctbx.d_star_sq_as_two_theta(d_star_sq_s, 1.5, True))
    # reverse conversions
    for d_star_sq, two_theta in zip((d_star_sq_s, d_star_sq_a),
                                    (two_theta_s, two_theta_a)):
        assert approx_equal(
            uctbx.stol_sq_as_d_star_sq(uctbx.d_star_sq_as_stol_sq(d_star_sq)),
            d_star_sq)
        assert approx_equal(
            uctbx.two_stol_as_d_star_sq(
                uctbx.d_star_sq_as_two_stol(d_star_sq)), d_star_sq)
        assert approx_equal(
            uctbx.stol_as_d_star_sq(uctbx.d_star_sq_as_stol(d_star_sq)),
            d_star_sq)
        assert approx_equal(
            uctbx.d_as_d_star_sq(uctbx.d_star_sq_as_d(d_star_sq)), d_star_sq)
        assert approx_equal(
            uctbx.two_theta_as_d_star_sq(
                uctbx.d_star_sq_as_two_theta(d_star_sq, 1.5), 1.5), d_star_sq)
        assert approx_equal(
            uctbx.two_theta_as_d_star_sq(two_theta, 1.5),
            uctbx.two_theta_as_d_star_sq(two_theta, 1.5, False))
        assert approx_equal(
            uctbx.two_theta_as_d_star_sq(two_theta, 1.5),
            uctbx.two_theta_as_d_star_sq(two_theta * 180 / pi, 1.5, True))
        assert approx_equal(
            uctbx.two_theta_as_d(two_theta, 1.5),
            uctbx.d_star_sq_as_d(uctbx.two_theta_as_d_star_sq(two_theta, 1.5)))
        assert approx_equal(
            uctbx.two_theta_as_d(two_theta, 1.5, True),
            uctbx.d_star_sq_as_d(
                uctbx.two_theta_as_d_star_sq(two_theta, 1.5, True)))
    #
    assert uctbx.fractional_unit_shifts(distance_frac=[0, 0, 0]) == (0, 0, 0)
    assert uctbx.fractional_unit_shifts([0.6, 7.4, -0.4]) == (1, 7, 0)
    assert uctbx.fractional_unit_shifts([-6, 3, -0.6]) == (-6, 3, -1)
    site_frac_1 = [0.3, -8.6, 2.1]
    for eps, expected_u2 in [(-1.e-5, 1), (1.e-5, 2)]:
        site_frac_2 = [-3, 5.6, 0.6 - eps]
        assert uctbx.fractional_unit_shifts(
            site_frac_1=site_frac_1,
            site_frac_2=site_frac_2) == (3, -14, expected_u2)
예제 #5
0
    15.2671, 16.2713, 16.2628, 14.3454, 15.2642, 24.9881, 27.4904, 24.975,
    15.2658, 27.2176, 14.3565, 15.2576, 15.2653, 15.2673, 14.3385, 14.355,
    27.2235, 25.0048, 25.0138, 27.1408, 25.0315, 14.3464, 27.2386, 21.0258,
    25.004, 14.3446, 15.2299, 15.2723, 14.3643, 14.3474, 14.3584, 15.2848,
    21.0256, 21.0246, 15.261, 25.0207, 27.2373, 16.2848, 16.2854, 14.3575,
    14.3636, 29.4477, 27.2583, 14.3619, 21.0374, 21.0399, 16.2755, 14.3487,
    14.3618, 14.3608, 15.2829, 27.2497, 15.2715, 15.2699, 16.2646, 16.2786,
    16.2821, 16.2696, 21.0368, 21.0307, 25.0431, 21.0456, 21.0224, 27.2257,
    27.2486, 25.0266, 25.0252, 29.4661, 25.0415, 25.0266, 25.046, 29.4752,
    27.2545, 29.4521, 37.3152, 29.4306, 29.4684, 37.3646, 28.9946, 28.9884,
    29.4736, 29.4737, 30.0142]

  miller_indices = flex.miller_index()
  two_thetas_obs = flex.double()
  for i, two_theta in enumerate(two_thetas):
    d_spacing = uctbx.two_theta_as_d(two_theta, wavelength, deg=True)
    for j, d in enumerate(ms.d_spacings().data()):
      if abs(d - d_spacing) < 0.1:
        miller_indices.append(ms.indices()[j])
        two_thetas_obs.append(two_theta)

  show_fit(
    two_thetas_obs, miller_indices, wavelength, unit_cell_start)

  refined = refinery(
    two_thetas_obs, miller_indices, wavelength, unit_cell_start,
      space_group=crystal_symmetry.space_group())
  print

  show_fit(
    two_thetas_obs, miller_indices, wavelength, refined.unit_cell())