예제 #1
0
def exercise(space_group_info, anomalous_flag=False, d_min=2., verbose=0):
  sg_fcalc = random_structure.xray_structure(
    space_group_info,
    elements=("N", "C", "C", "O"),
    random_f_double_prime=anomalous_flag,
    random_u_iso=True,
    random_occupancy=True
    ).structure_factors(
      anomalous_flag=anomalous_flag, d_min=d_min, algorithm="direct").f_calc()
  sg_hl = generate_random_hl(sg_fcalc)
  write_cns_input(sg_fcalc, sg_hl.data())
  try: os.unlink("tmp_sg.hkl")
  except OSError: pass
  try: os.unlink("tmp_p1.hkl")
  except OSError: pass
  easy_run.fully_buffered(command="cns < tmp.cns > tmp.out") \
    .raise_if_errors_or_output()
  sg_cns = read_reflection_arrays("tmp_sg.hkl", anomalous_flag, verbose)
  p1_cns = read_reflection_arrays("tmp_p1.hkl", anomalous_flag, verbose)
  verify(sg_fcalc, sg_hl.data(), sg_cns, p1_cns)
  if (anomalous_flag):
    hl_merged = sg_hl.average_bijvoet_mates()
    fc_merged = sg_fcalc.average_bijvoet_mates()
    write_cns_input(sg_fcalc, sg_hl.data(), test_merge=True)
    try: os.unlink("tmp_merged.hkl")
    except OSError: pass
    easy_run.fully_buffered(command="cns < tmp.cns > tmp.out") \
      .raise_if_errors_or_output()
    reflection_file = reflection_reader.cns_reflection_file(
      open("tmp_merged.hkl"))
    if (not sg_fcalc.space_group().is_centric()):
      fc_merged_cns = reflection_file.reciprocal_space_objects["FCALC"]
      fc_merged_cns = fc_merged.customized_copy(
        indices=fc_merged_cns.indices,
        data=fc_merged_cns.data).map_to_asu().common_set(fc_merged)
      assert fc_merged_cns.indices().all_eq(fc_merged.indices())
      fc_merged_a = fc_merged.select_acentric()
      fc_merged_cns_a = fc_merged_cns.select_acentric()
      for part in [flex.real, flex.imag]:
        cc = flex.linear_correlation(
          part(fc_merged_a.data()),
          part(fc_merged_cns_a.data())).coefficient()
        if (cc < 1-1.e-6):
          print "FAILURE acentrics", sg_fcalc.space_group_info()
          if (0): return
          raise AssertionError
    names, miller_indices, hl = reflection_file.join_hl_group()
    assert names == ["PA", "PB", "PC", "PD"]
    hl_merged_cns = hl_merged.customized_copy(indices=miller_indices, data=hl)\
      .map_to_asu().common_set(hl_merged)
    assert hl_merged_cns.indices().all_eq(hl_merged.indices())
    for h,a,b in zip(hl_merged.indices(),
                     hl_merged.data(),
                     hl_merged_cns.data()):
      if (not approx_equal(a, b, eps=5.e-3)):
        print h
        print "cctbx:", a
        print "  cns:", b
        if (0): return
        raise AssertionError
예제 #2
0
 def __init__(self, file_name, anomalous_flag, verbose):
   reflection_file = reflection_reader.cns_reflection_file(open(file_name))
   if (0 or verbose):
     print reflection_file.show_summary()
   assert reflection_file.anomalous == anomalous_flag
   names, self.miller_indices, self.hl = reflection_file.join_hl_group()
   self.fcalc = reflection_file.reciprocal_space_objects["FCALC"]
   self.pi = reflection_file.reciprocal_space_objects["PI"]
   assert not miller.match_indices(
     self.miller_indices, self.fcalc.indices).have_singles()
   assert not miller.match_indices(
     self.miller_indices, self.pi.indices).have_singles()
예제 #3
0
 def __init__(self, file_name, anomalous_flag, verbose):
     reflection_file = reflection_reader.cns_reflection_file(
         open(file_name))
     if (0 or verbose):
         print(reflection_file.show_summary())
     assert reflection_file.anomalous == anomalous_flag
     names, self.miller_indices, self.hl = reflection_file.join_hl_group()
     self.fcalc = reflection_file.reciprocal_space_objects["FCALC"]
     self.pi = reflection_file.reciprocal_space_objects["PI"]
     assert not miller.match_indices(self.miller_indices,
                                     self.fcalc.indices).have_singles()
     assert not miller.match_indices(self.miller_indices,
                                     self.pi.indices).have_singles()
예제 #4
0
def exercise(space_group_info, anomalous_flag=False, d_min=2., verbose=0):
  crystal_symmetry = crystal.symmetry(
    space_group_info.any_compatible_unit_cell(1000),
    space_group_info=space_group_info)
  write_cns_input(crystal_symmetry, anomalous_flag, d_min)
  try: os.unlink("tmp_cns_input.hkl")
  except KeyboardInterrupt: raise
  except Exception: pass
  easy_run.fully_buffered(
    command="cns < tmp_cns_input.cns > tmp_cns_input.out") \
      .raise_if_errors_or_output()
  f = open("tmp_cns_input.hkl", "r")
  reflection_file = reflection_reader.cns_reflection_file(f)
  f.close()
  if (0 or verbose):
    print reflection_file.show_summary()
  verify(crystal_symmetry, anomalous_flag, reflection_file)
예제 #5
0
def exercise(space_group_info, anomalous_flag=False, d_min=2., verbose=0):
  crystal_symmetry = crystal.symmetry(
    space_group_info.any_compatible_unit_cell(1000),
    space_group_info=space_group_info)
  write_cns_input(crystal_symmetry, anomalous_flag, d_min)
  try: os.unlink("tmp_cns_input.hkl")
  except KeyboardInterrupt: raise
  except Exception: pass
  easy_run.fully_buffered(
    command="cns < tmp_cns_input.cns > tmp_cns_input.out") \
      .raise_if_errors_or_output()
  f = open("tmp_cns_input.hkl", "r")
  reflection_file = reflection_reader.cns_reflection_file(f)
  f.close()
  if (0 or verbose):
    print(reflection_file.show_summary())
  verify(crystal_symmetry, anomalous_flag, reflection_file)
def try_all_readers(file_name):
  try: content = mtz.object(file_name=file_name)
  except RuntimeError: pass
  else: return ("ccp4_mtz", content)
  if (detect_binary_file.from_initial_block(file_name=file_name)):
    try: content = unpickle_miller_arrays(file_name=file_name)
    except KeyboardInterrupt: raise
    except Exception: pass
    else: return ("cctbx.miller.array", content)
    return (None, None)
  try: content = cns_reflection_reader.cns_reflection_file(
    open(file_name))
  except cns_reflection_reader.CNS_input_Error: pass
  else: return ("cns_reflection_file", content)
  try: content = cns_index_fobs_sigma_reader.reader(
    file_name=file_name)
  except RuntimeError: pass
  else: return ("cns_index_fobs_sigma", content)
  try: content = scalepack_merge.reader(
    open(file_name))
  except scalepack_merge.FormatError: pass
  else: return ("scalepack_merge", content)
  try: content = scalepack_no_merge.reader(file_name)
  except KeyboardInterrupt: raise
  except Exception: pass
  else: return ("scalepack_no_merge_original_index", content)
  try: content = dtrek_reflnlist_reader.reflnlist(
    open(file_name))
  except KeyboardInterrupt: raise
  except Exception: pass
  else: return ("dtrek_reflnlist", content)
  try: content = shelx_hklf.reader(
    file_name=file_name)
  except KeyboardInterrupt: raise
  except Exception: pass
  else: return ("shelx_hklf", content)
  try:
    content = cif_reader(file_path=file_name)
    looks_like_a_reflection_file = False
    for block in content.model().values():
      if '_refln_index_h' in block or '_refln.index_h' in block:
        looks_like_a_reflection_file = True
        break
    if not looks_like_a_reflection_file:
      raise RuntimeError
  except KeyboardInterrupt: raise
  except Exception: pass
  else: return ("cif", content)
  try: content = xds_ascii_reader(
    open(file_name))
  except KeyboardInterrupt: raise
  except Exception: pass
  else: return ("xds_ascii", content)
  try:
    content = xds_integrate_hkl_reader()
    content.read_file(file_name)
  except KeyboardInterrupt: raise
  except Exception: pass
  else: return ("xds_integrate_hkl", content)
  try: content = solve_fpfm_reader(file_name=file_name)
  except KeyboardInterrupt: raise
  except Exception: pass
  else: return ("solve_fpfm", content)
  return (None, None)
예제 #7
0
def try_all_readers(file_name):
    try:
        content = mtz.object(file_name=file_name)
    except RuntimeError:
        pass
    else:
        return ("ccp4_mtz", content)
    if (detect_binary_file.from_initial_block(file_name=file_name)):
        try:
            content = unpickle_miller_arrays(file_name=file_name)
        except KeyboardInterrupt:
            raise
        except Exception:
            pass
        else:
            return ("cctbx.miller.array", content)
        return (None, None)
    try:
        content = cns_reflection_reader.cns_reflection_file(open(file_name))
    except cns_reflection_reader.CNS_input_Error:
        pass
    else:
        return ("cns_reflection_file", content)
    try:
        content = cns_index_fobs_sigma_reader.reader(file_name=file_name)
    except RuntimeError:
        pass
    else:
        return ("cns_index_fobs_sigma", content)
    try:
        content = scalepack_merge.reader(open(file_name))
    except scalepack_merge.FormatError:
        pass
    else:
        return ("scalepack_merge", content)
    try:
        content = scalepack_no_merge.reader(file_name)
    except KeyboardInterrupt:
        raise
    except Exception:
        pass
    else:
        return ("scalepack_no_merge_original_index", content)
    try:
        content = dtrek_reflnlist_reader.reflnlist(open(file_name))
    except KeyboardInterrupt:
        raise
    except Exception:
        pass
    else:
        return ("dtrek_reflnlist", content)
    try:
        content = shelx_hklf.reader(file_name=file_name)
    except KeyboardInterrupt:
        raise
    except Exception:
        pass
    else:
        return ("shelx_hklf", content)
    try:
        content = cif_reader(file_path=file_name)
        looks_like_a_reflection_file = False
        for block in content.model().values():
            if '_refln_index_h' in block or '_refln.index_h' in block:
                looks_like_a_reflection_file = True
                break
        if not looks_like_a_reflection_file:
            raise RuntimeError
    except KeyboardInterrupt:
        raise
    except Exception:
        pass
    else:
        return ("cif", content)
    try:
        content = xds_ascii_reader(open(file_name))
    except KeyboardInterrupt:
        raise
    except Exception:
        pass
    else:
        return ("xds_ascii", content)
    try:
        content = xds_integrate_hkl_reader()
        content.read_file(file_name)
    except KeyboardInterrupt:
        raise
    except Exception:
        pass
    else:
        return ("xds_integrate_hkl", content)
    try:
        content = solve_fpfm_reader(file_name=file_name)
    except KeyboardInterrupt:
        raise
    except Exception:
        pass
    else:
        return ("solve_fpfm", content)
    return (None, None)
예제 #8
0
def exercise(space_group_info, anomalous_flag=False, d_min=2., verbose=0):
    sg_fcalc = random_structure.xray_structure(
        space_group_info,
        elements=("N", "C", "C", "O"),
        random_f_double_prime=anomalous_flag,
        random_u_iso=True,
        random_occupancy=True).structure_factors(anomalous_flag=anomalous_flag,
                                                 d_min=d_min,
                                                 algorithm="direct").f_calc()
    sg_hl = generate_random_hl(sg_fcalc)
    write_cns_input(sg_fcalc, sg_hl.data())
    try:
        os.unlink("tmp_sg.hkl")
    except OSError:
        pass
    try:
        os.unlink("tmp_p1.hkl")
    except OSError:
        pass
    easy_run.fully_buffered(command="cns < tmp.cns > tmp.out") \
      .raise_if_errors_or_output()
    sg_cns = read_reflection_arrays("tmp_sg.hkl", anomalous_flag, verbose)
    p1_cns = read_reflection_arrays("tmp_p1.hkl", anomalous_flag, verbose)
    verify(sg_fcalc, sg_hl.data(), sg_cns, p1_cns)
    if (anomalous_flag):
        hl_merged = sg_hl.average_bijvoet_mates()
        fc_merged = sg_fcalc.average_bijvoet_mates()
        write_cns_input(sg_fcalc, sg_hl.data(), test_merge=True)
        try:
            os.unlink("tmp_merged.hkl")
        except OSError:
            pass
        easy_run.fully_buffered(command="cns < tmp.cns > tmp.out") \
          .raise_if_errors_or_output()
        reflection_file = reflection_reader.cns_reflection_file(
            open("tmp_merged.hkl"))
        if (not sg_fcalc.space_group().is_centric()):
            fc_merged_cns = reflection_file.reciprocal_space_objects["FCALC"]
            fc_merged_cns = fc_merged.customized_copy(
                indices=fc_merged_cns.indices,
                data=fc_merged_cns.data).map_to_asu().common_set(fc_merged)
            assert fc_merged_cns.indices().all_eq(fc_merged.indices())
            fc_merged_a = fc_merged.select_acentric()
            fc_merged_cns_a = fc_merged_cns.select_acentric()
            for part in [flex.real, flex.imag]:
                cc = flex.linear_correlation(
                    part(fc_merged_a.data()),
                    part(fc_merged_cns_a.data())).coefficient()
                if (cc < 1 - 1.e-6):
                    print("FAILURE acentrics", sg_fcalc.space_group_info())
                    if (0): return
                    raise AssertionError
        names, miller_indices, hl = reflection_file.join_hl_group()
        assert names == ["PA", "PB", "PC", "PD"]
        hl_merged_cns = hl_merged.customized_copy(indices=miller_indices, data=hl)\
          .map_to_asu().common_set(hl_merged)
        assert hl_merged_cns.indices().all_eq(hl_merged.indices())
        for h, a, b in zip(hl_merged.indices(), hl_merged.data(),
                           hl_merged_cns.data()):
            if (not approx_equal(a, b, eps=5.e-3)):
                print(h)
                print("cctbx:", a)
                print("  cns:", b)
                if (0): return
                raise AssertionError