Esempio n. 1
0
def exercise_space_group_handling():
    flex.set_random_seed(123456)
    random.seed(123456)
    base = "tst_cc_star_space_group"
    pdb_in = iotbx.pdb.hierarchy.input(pdb_string=model_1yjp)
    xrs = pdb_in.xray_structure_simple()
    xrs.set_inelastic_form_factors(photon=1.54, table="sasaki")
    fc = abs(xrs.structure_factors(d_min=1.5).f_calc()).average_bijvoet_mates()
    fc.set_observation_type_xray_amplitude()
    flags = fc.generate_r_free_flags()
    mtz = fc.as_mtz_dataset(column_root_label="F")
    mtz.add_miller_array(flags, column_root_label="FreeR_flag")
    mtz.mtz_object().write(base + ".mtz")
    xrs_p1 = xrs.expand_to_p1()
    xrs_p1.shake_sites_in_place(rms_difference=0.1)
    fc_p1 = xrs_p1.structure_factors(d_min=1.4).f_calc()
    fc_p1_extra = fc_p1.randomize_amplitude_and_phase(amplitude_error=1.0,
                                                      phase_error_deg=0,
                                                      random_seed=123456)
    fc_p1 = abs(
        fc_p1.concatenate(other=fc_p1_extra)).sort(by_value="packed_indices")
    fc_p1.set_observation_type_xray_amplitude()
    sg_p2 = sgtbx.space_group_info("P2")
    ic = fc_p1.f_as_f_sq().customized_copy(space_group_info=sg_p2,
                                           sigmas=flex.double(
                                               fc_p1.size(), 10.0))
    ic.export_as_scalepack_unmerged(file_name=base + ".sca")
    open(base + ".pdb", "w").write(model_1yjp)
    args = [
        base + ".mtz",
        base + ".pdb",
        "unmerged_data=%s.sca" % base,
    ]
    cc_star.run(args=args, out=null_out())
    # now with .sca in P1 (raises Sorry)
    ic2 = fc_p1.f_as_f_sq().customized_copy(
        sigmas=flex.double(fc_p1.size(), 10.0))
    ic2.export_as_scalepack_unmerged(file_name=base + "_p1.sca")
    args = [
        base + ".mtz",
        base + ".pdb",
        "unmerged_data=%s_p1.sca" % base,
    ]
    try:
        cc_star.run(args=args, out=null_out())
    except Sorry, s:
        assert (
            str(s) ==
            "Incompatible space groups in merged and unmerged data:P 1 21 1 versus P 1"
        ), s
Esempio n. 2
0
def exercise_space_group_handling () :
  flex.set_random_seed(123456)
  random.seed(123456)
  base = "tst_cc_star_space_group"
  pdb_in = iotbx.pdb.hierarchy.input(pdb_string=model_1yjp)
  xrs = pdb_in.xray_structure_simple()
  xrs.set_inelastic_form_factors(
    photon=1.54,
    table="sasaki")
  fc = abs(xrs.structure_factors(d_min=1.5).f_calc()).average_bijvoet_mates()
  fc.set_observation_type_xray_amplitude()
  flags = fc.generate_r_free_flags()
  mtz = fc.as_mtz_dataset(column_root_label="F")
  mtz.add_miller_array(flags, column_root_label="FreeR_flag")
  mtz.mtz_object().write(base + ".mtz")
  xrs_p1 = xrs.expand_to_p1()
  xrs_p1.shake_sites_in_place(rms_difference=0.1)
  fc_p1 = xrs_p1.structure_factors(d_min=1.4).f_calc()
  fc_p1_extra = fc_p1.randomize_amplitude_and_phase(amplitude_error=1.0,
    phase_error_deg=0,
    random_seed=123456)
  fc_p1 = abs(fc_p1.concatenate(other=fc_p1_extra)).sort(
    by_value="packed_indices")
  fc_p1.set_observation_type_xray_amplitude()
  sg_p2 = sgtbx.space_group_info("P2")
  ic = fc_p1.f_as_f_sq().customized_copy(
    space_group_info=sg_p2,
    sigmas=flex.double(fc_p1.size(), 10.0))
  ic.export_as_scalepack_unmerged(file_name=base + ".sca")
  open(base + ".pdb", "w").write(model_1yjp)
  args = [
    base + ".mtz",
    base + ".pdb",
    "unmerged_data=%s.sca" % base,
  ]
  cc_star.run(args=args, out=null_out())
  # now with .sca in P1 (raises Sorry)
  ic2 = fc_p1.f_as_f_sq().customized_copy(
    sigmas=flex.double(fc_p1.size(), 10.0))
  ic2.export_as_scalepack_unmerged(file_name=base + "_p1.sca")
  args = [
    base + ".mtz",
    base + ".pdb",
    "unmerged_data=%s_p1.sca" % base,
  ]
  try :
    cc_star.run(args=args, out=null_out())
  except Sorry, s :
    assert (str(s) == "Incompatible space groups in merged and unmerged data:P 1 21 1 versus P 1"), s
def old_run(args, out=None):
    import iotbx.phil
    if (out is None):
        out = sys.stdout
    cmdline = iotbx.phil.process_command_line_with_files(
        args=args,
        master_phil=master_phil,
        pdb_file_def="input.pdb_file",
        seq_file_def="input.seq_file")
    params = cmdline.work.extract()
    cmdline.work.show()
    if params.output.cif_file is None:
        params.output.cif_file = os.path.splitext(
            params.input.pdb_file)[0] + ".deposit.cif"
    model_vs_sequence.validate_params(params)
    pdb_input = mmcif.cif_input(file_name=params.input.pdb_file)
    pdb_hierarchy = pdb_input.construct_hierarchy()
    cif_model = pdb_input.cif_model
    cif_block = pdb_input.cif_block
    seq_in = any_file(params.input.seq_file, force_type="seq")
    seq_in.check_file_type("seq")
    sequences = seq_in.file_object

    cif_block = pdb_hierarchy.as_cif_block_with_sequence(
        sequences,
        crystal_symmetry=pdb_input.crystal_symmetry(),
        alignment_params=params)
    block_name = cif_model.keys()[0]

    def float_or_none(string):
        try:
            return float(string)
        except TypeError:
            return None

    d_min_from_cif = float_or_none(cif_block.get('_refine.ls_d_res_high'))
    d_max_from_cif = float_or_none(cif_block.get('_refine.ls_d_res_low'))
    # XXX maybe the values from the CIF (i.e. those actually used in the refinement)
    # should override the input params?
    if params.high_resolution is not None:
        params.high_resolution = d_min_from_cif
    if params.low_resolution is not None:
        params.low_resolution = d_max_from_cif

    if params.input.unmerged_data is not None:
        from mmtbx.command_line import cc_star
        result = cc_star.run(params=params.input, out=out)
        cif_block.update(result.as_cif_block())

    cif_model[block_name].update(cif_block)
    cif_model[block_name].sort(key=category_sort_function)
    print >> out, "Writing updated CIF file:"
    print >> out, "  " + params.output.cif_file
    with open(params.output.cif_file, "wb") as f:
        print >> f, cif_model
    return
def run(args, out=None):
  import iotbx.phil
  if (out is None) :
    out = sys.stdout
  cmdline = iotbx.phil.process_command_line_with_files(
    args=args,
    master_phil=master_phil,
    pdb_file_def="input.pdb_file",
    seq_file_def="input.seq_file"
  )
  params = cmdline.work.extract()
  cmdline.work.show()
  if params.output.cif_file is None:
    params.output.cif_file = os.path.splitext(params.input.pdb_file)[0] + ".deposit.cif"
  model_vs_sequence.validate_params(params)
  pdb_input = mmcif.cif_input(file_name=params.input.pdb_file)
  pdb_hierarchy = pdb_input.construct_hierarchy()
  cif_model = pdb_input.cif_model
  cif_block = pdb_input.cif_block
  seq_in = any_file(params.input.seq_file, force_type="seq")
  seq_in.check_file_type("seq")
  sequences = seq_in.file_object

  cif_block = pdb_hierarchy.as_cif_block_with_sequence(
    sequences, crystal_symmetry=pdb_input.crystal_symmetry(),
    alignment_params=params)
  block_name = cif_model.keys()[0]

  def float_or_none(string):
    try: return float(string)
    except TypeError: return None

  d_min_from_cif = float_or_none(cif_block.get('_refine.ls_d_res_high'))
  d_max_from_cif = float_or_none(cif_block.get('_refine.ls_d_res_low'))
  # XXX maybe the values from the CIF (i.e. those actually used in the refinement)
  # should override the input params?
  if params.high_resolution is not None:
    params.high_resolution = d_min_from_cif
  if params.low_resolution is not None:
    params.low_resolution = d_max_from_cif

  if params.input.unmerged_data is not None:
    from mmtbx.command_line import cc_star
    result = cc_star.run(params=params.input, out=out)
    cif_block.update(result.as_cif_block())

  cif_model[block_name].update(cif_block)
  cif_model[block_name].sort(key=category_sort_function)
  print >> out, "Writing updated CIF file:"
  print >> out, "  " + params.output.cif_file
  with open(params.output.cif_file, "wb") as f:
    print >> f, cif_model
  return
Esempio n. 5
0
     assert (
         str(s) ==
         "Incompatible space groups in merged and unmerged data:P 1 21 1 versus P 1"
     ), s
 else:
     raise Exception_expected
 # now with CIF (complete symmetry)
 f = open(base + ".cif", "w")
 ic.as_cif_simple(array_type="meas", out=f)
 f.close()
 args = [
     base + ".mtz",
     base + ".pdb",
     "unmerged_data=%s.cif" % base,
 ]
 cc_star.run(args=args, out=null_out())
 # bad unit cell
 uc2 = uctbx.unit_cell((23, 6.5, 23.5, 90, 108, 90))
 ic3 = ic.customized_copy(unit_cell=uc2)
 f = open(base + "_new_uc.cif", "w")
 ic3.as_cif_simple(array_type="meas", out=f)
 f.close()
 args = [
     base + ".mtz",
     base + ".pdb",
     "unmerged_data=%s_new_uc.cif" % base,
 ]
 try:
     cc_star.run(args=args, out=null_out())
 except Sorry, s:
     assert ("Incompatible symmetry definitions:" in str(s)), s
Esempio n. 6
0
   cc_star.run(args=args, out=null_out())
 except Sorry, s :
   assert (str(s) == "Incompatible space groups in merged and unmerged data:P 1 21 1 versus P 1"), s
 else :
   raise Exception_expected
 # now with CIF (complete symmetry)
 f = open(base + ".cif", "w")
 ic.as_cif_simple(array_type="meas",
   out=f)
 f.close()
 args = [
   base + ".mtz",
   base + ".pdb",
   "unmerged_data=%s.cif" % base,
 ]
 cc_star.run(args=args, out=null_out())
 # bad unit cell
 uc2 = uctbx.unit_cell((23,6.5,23.5,90,108,90))
 ic3 = ic.customized_copy(unit_cell=uc2)
 f = open(base + "_new_uc.cif", "w")
 ic3.as_cif_simple(array_type="meas",
   out=f)
 f.close()
 args = [
   base + ".mtz",
   base + ".pdb",
   "unmerged_data=%s_new_uc.cif" % base,
 ]
 try :
   cc_star.run(args=args, out=null_out())
 except Sorry, s :