コード例 #1
0
def run():
  pdb_str="""
CRYST1    5.000    5.000    5.000  90.00  90.00  90.00 P 1
HETATM    1  C    C      1       0.000   0.000   0.000  1.00  5.00           C
END
"""
  xrs = iotbx.pdb.input(source_info=None, lines=pdb_str).xray_structure_simple()
  ###
  fc = xrs.structure_factors(d_min = 0.26, algorithm = "direct").f_calc()
  fft_map_ref = fc.fft_map(resolution_factor = 0.1)
  fft_map_ref.apply_sigma_scaling()
  map_data_ref = fft_map_ref.real_map_unpadded()
  r_r, rho_r = map_1d(xrs=xrs,
    map_data=map_data_ref.deep_copy()/flex.max(map_data_ref))
  F_0 = xrs.structure_factors(d_min=1.4999999, algorithm="direct").f_calc()
  #
  fft_map_0 = miller.fft_map(
    crystal_gridding     = fft_map_ref,
    fourier_coefficients = F_0)
  fft_map_0.apply_sigma_scaling()
  map_data_0 = fft_map_0.real_map_unpadded()
  r_s, rho_s = map_1d(xrs=xrs, map_data=map_data_0)
  sc = scale(rho_r, rho_s)
  rho_s = rho_s*sc
  #
  R = r_factor(x=r_s, r1=rho_r, r2=rho_s)
  cc = flex.linear_correlation(x = rho_r, y = rho_s).coefficient()
  print("Initial dist: %6.3f"%R, cc)
  ### Exercise fixed lam
  lam = 0.74
  for start_map in ["flat", "lde", "min_shifted"]:
    m = mem.run(f=F_0, f_000=xrs.f_000(), lam=lam, resolution_factor=0.1,
      verbose=False, start_map=start_map, max_iterations=1300,
      detect_convergence=False)
    r_m, rho_m = map_1d(xrs=xrs, map_data=m.rho)
    sc = scale(rho_r, rho_m)
    rho_m = rho_m*sc
    R = r_factor(x=r_s, r1=rho_r, r2=rho_m)
    cc = flex.linear_correlation(x = rho_r, y = rho_m).coefficient()
    print(m.show(verbose=False), "*", "dist: %6.3f"%R, cc)
    assert R < 0.0004, R
    assert cc > 0.999, R
  ### Exercise auto-incremented lam, 1
  m = mem.run(f=F_0, f_000=xrs.f_000(), lam=0.01, resolution_factor=0.1,
    lambda_increment_factor = 1.01, beta=0.5, verbose=True,
    start_map="min_shifted", max_iterations=800, detect_convergence=True)
  r_m, rho_m = map_1d(xrs=xrs, map_data=m.rho)
  sc = scale(rho_r, rho_m)
  rho_m = rho_m*sc
  R = r_factor(x=r_s, r1=rho_r, r2=rho_m)
  cc = flex.linear_correlation(x = rho_r, y = rho_m).coefficient()
  print(m.show(verbose=False), "*", "dist: %6.3f"%R, cc)
  assert R < 0.004, R
  assert cc > 0.999, R
  ### Exercise auto-incremented lam, 2
  m = mem.run(f=F_0, f_000=xrs.f_000(), lam=0.01, resolution_factor=0.1,
    lambda_increment_factor = 1.01, beta=0.5, xray_structure=xrs, verbose=True,
    start_map="min_shifted", max_iterations=800, detect_convergence=True)
  r_m, rho_m = map_1d(xrs=xrs, map_data=m.rho)
  sc = scale(rho_r, rho_m)
  rho_m = rho_m*sc
  R = r_factor(x=r_s, r1=rho_r, r2=rho_m)
  cc = flex.linear_correlation(x = rho_r, y = rho_m).coefficient()
  print(m.show(verbose=False), "*", "dist: %6.3f"%R, cc)
  assert R < 0.05, R
  assert cc > 0.998, R
  #
  of = open("gp","w")
  assert rho_r.size() == rho_s.size() == rho_m.size()
  for r, r1, r2, r3 in zip(r_r, rho_r, rho_s, rho_m):
    print("%15.12f %15.12f %15.12f %15.12f"%(r, r1, r2, r3), file=of)
  of.close()
  #
  m.write_mtz_file()
  #
  print("gnuplot command to show results:")
  print("""
plot [-3:3] [-0.1:1.1] "gp" using 1:2 with lines title "exact" lw 3, "gp" using 1:3 with lines title "synthesis" lw 3 lc rgb "black", "gp" using 1:4 with lines title "MEM" lw 3
""")
コード例 #2
0
def run(args, log):
    timer = user_plus_sys_time()
    format_usage_message(log=log)
    if (len(args) == 0): return
    parsed = master_params()
    inputs = mmtbx.utils.process_command_line_args(args=args,
                                                   master_params=parsed,
                                                   log=log)
    params = inputs.params.extract()
    broadcast(m="Input parameters", log=log)
    inputs.params.show(prefix="  ")
    ###
    xray_structure = None
    if (len(inputs.pdb_file_names) > 0):
        broadcast(m="Input model", log=log)
        assert len(inputs.pdb_file_names) == 1
        print >> log, "  file name:", inputs.pdb_file_names[0]
        xray_structure = iotbx.pdb.input(
            file_name=inputs.pdb_file_names[0]).xray_structure_simple()
        assert xray_structure is not None
        xray_structure.show_summary(prefix="  ", f=log)
        mmtbx.utils.setup_scattering_dictionaries(
            scattering_table=params.scattering_table,
            xray_structure=xray_structure,
            d_min=0.25)
        xray_structure.scattering_type_registry().show(prefix="  ", out=log)
    ###
    broadcast(m="Input reflection data", log=log)
    reff = inputs.reflection_file_names
    if (len(reff) > 1):
        raise Sorry("One reflection file should be provided.")
    elif (len(reff) == 0):
        if (params.hkl_file_name is None):
            raise Sorry("No reflection file provided.")
        else:
            reff = [params.hkl_file_name]
    map_coeffs = reflection_file_utils.extract_miller_array_from_file(
        file_name=reff[0], label=params.label, type="complex", log=log)
    assert map_coeffs is not None
    map_coeffs.show_comprehensive_summary(prefix="  ", f=log)
    ###
    broadcast(m="MEM calculations begin", log=log)
    f_000 = params.f_000
    solvent_fraction = params.solvent_fraction
    if (f_000 is None):
        f_000_obj = mmtbx.utils.f_000(
            xray_structure=xray_structure,
            unit_cell_volume=map_coeffs.unit_cell().volume(),
            solvent_fraction=params.solvent_fraction,
            mean_solvent_density=params.mean_solvent_density)
        f_000 = f_000_obj.f_000
        solvent_fraction = f_000_obj.solvent_fraction
    print >> log, "F(0,0,0): %12.6f" % f_000
    if (solvent_fraction is not None):
        print >> log, "solvent_fraction: %6.4f" % solvent_fraction
    result = mem.run(f=map_coeffs,
                     f_000=f_000,
                     lam=params.lam,
                     lambda_increment_factor=params.lambda_increment_factor,
                     resolution_factor=params.resolution_factor,
                     verbose=True,
                     start_map="min_shifted",
                     max_iterations=params.max_iterations,
                     use_modification=True,
                     beta=params.beta,
                     convergence_at_r_factor=params.convergence_at_r_factor,
                     xray_structure=xray_structure,
                     convergence_r_threshold=params.convergence_r_threshold,
                     log=log)
    ###
    broadcast(m="Output MEM map coefficients", log=log)
    ind = max(0, reff[0].rfind("."))
    ofn = params.output_file_name
    if (ofn is None):
        ofn = reff[0] + "_mem.mtz" if ind == 0 else reff[0][:ind] + "_mem.mtz"
    print >> log, "  Output file name:", ofn
    result.write_mtz_file(file_name=ofn,
                          column_root_label=params.column_root_label,
                          d_min=params.output_high_resolution)
    broadcast(m="All done", log=log)
    return os.path.abspath(ofn)
コード例 #3
0
ファイル: tst_mem.py プロジェクト: cctbx/cctbx-playground
def run():
  pdb_str="""
CRYST1    5.000    5.000    5.000  90.00  90.00  90.00 P 1
HETATM    1  C    C      1       0.000   0.000   0.000  1.00  5.00           C
END
"""
  xrs = iotbx.pdb.input(source_info=None, lines=pdb_str).xray_structure_simple()
  ###
  fc = xrs.structure_factors(d_min = 0.26, algorithm = "direct").f_calc()
  fft_map_ref = fc.fft_map(resolution_factor = 0.1)
  fft_map_ref.apply_sigma_scaling()
  map_data_ref = fft_map_ref.real_map_unpadded()
  r_r, rho_r = map_1d(xrs=xrs,
    map_data=map_data_ref.deep_copy()/flex.max(map_data_ref))
  F_0 = xrs.structure_factors(d_min=1.4999999, algorithm="direct").f_calc()
  #
  fft_map_0 = miller.fft_map(
    crystal_gridding     = fft_map_ref,
    fourier_coefficients = F_0)
  fft_map_0.apply_sigma_scaling()
  map_data_0 = fft_map_0.real_map_unpadded()
  r_s, rho_s = map_1d(xrs=xrs, map_data=map_data_0)
  sc = scale(rho_r, rho_s)
  rho_s = rho_s*sc
  #
  R = r_factor(x=r_s, r1=rho_r, r2=rho_s)
  cc = flex.linear_correlation(x = rho_r, y = rho_s).coefficient()
  print "Initial dist: %6.3f"%R, cc
  ### Exercise fixed lam
  lam = 0.74
  for start_map in ["flat", "lde", "min_shifted"]:
    m = mem.run(f=F_0, f_000=xrs.f_000(), lam=lam, resolution_factor=0.1,
      verbose=False, start_map=start_map, max_iterations=1300,
      detect_convergence=False)
    r_m, rho_m = map_1d(xrs=xrs, map_data=m.rho)
    sc = scale(rho_r, rho_m)
    rho_m = rho_m*sc
    R = r_factor(x=r_s, r1=rho_r, r2=rho_m)
    cc = flex.linear_correlation(x = rho_r, y = rho_m).coefficient()
    print m.show(verbose=False), "*", "dist: %6.3f"%R, cc
    assert R < 0.0004, R
    assert cc > 0.999, R
  ### Exercise auto-incremented lam, 1
  m = mem.run(f=F_0, f_000=xrs.f_000(), lam=0.01, resolution_factor=0.1,
    lambda_increment_factor = 1.01, beta=0.5, verbose=True,
    start_map="min_shifted", max_iterations=800, detect_convergence=True)
  r_m, rho_m = map_1d(xrs=xrs, map_data=m.rho)
  sc = scale(rho_r, rho_m)
  rho_m = rho_m*sc
  R = r_factor(x=r_s, r1=rho_r, r2=rho_m)
  cc = flex.linear_correlation(x = rho_r, y = rho_m).coefficient()
  print m.show(verbose=False), "*", "dist: %6.3f"%R, cc
  assert R < 0.004, R
  assert cc > 0.999, R
  ### Exercise auto-incremented lam, 2
  m = mem.run(f=F_0, f_000=xrs.f_000(), lam=0.01, resolution_factor=0.1,
    lambda_increment_factor = 1.01, beta=0.5, xray_structure=xrs, verbose=True,
    start_map="min_shifted", max_iterations=800, detect_convergence=True)
  r_m, rho_m = map_1d(xrs=xrs, map_data=m.rho)
  sc = scale(rho_r, rho_m)
  rho_m = rho_m*sc
  R = r_factor(x=r_s, r1=rho_r, r2=rho_m)
  cc = flex.linear_correlation(x = rho_r, y = rho_m).coefficient()
  print m.show(verbose=False), "*", "dist: %6.3f"%R, cc
  assert R < 0.05, R
  assert cc > 0.998, R
  #
  of = open("gp","w")
  assert rho_r.size() == rho_s.size() == rho_m.size()
  for r, r1, r2, r3 in zip(r_r, rho_r, rho_s, rho_m):
    print >> of, "%15.12f %15.12f %15.12f %15.12f"%(r, r1, r2, r3)
  of.close()
  #
  m.write_mtz_file()
  #
  print "gnuplot command to show results:"
  print """
コード例 #4
0
def run(args, log):
  timer = user_plus_sys_time()
  format_usage_message(log = log)
  if(len(args)==0): return
  parsed = master_params()
  inputs = mmtbx.utils.process_command_line_args(
    args=args, master_params=parsed, log=log)
  params = inputs.params.extract()
  broadcast(m="Input parameters", log = log)
  inputs.params.show(prefix="  ")
  ###
  xray_structure = None
  if(len(inputs.pdb_file_names)>0):
    broadcast(m="Input model", log = log)
    assert len(inputs.pdb_file_names) == 1
    print >> log, "  file name:", inputs.pdb_file_names[0]
    xray_structure = iotbx.pdb.input(
      file_name = inputs.pdb_file_names[0]).xray_structure_simple()
    assert xray_structure is not None
    xray_structure.show_summary(prefix="  ", f=log)
    mmtbx.utils.setup_scattering_dictionaries(
      scattering_table = params.scattering_table,
      xray_structure   = xray_structure,
      d_min            = 0.25)
    xray_structure.scattering_type_registry().show(prefix="  ", out = log)
  ###
  broadcast(m="Input reflection data", log = log)
  reff = inputs.reflection_file_names
  if(len(reff) > 1):
    raise Sorry("One reflection file should be provided.")
  elif(len(reff) == 0):
    if(params.hkl_file_name is None):
      raise Sorry("No reflection file provided.")
    else: reff = [params.hkl_file_name]
  map_coeffs = reflection_file_utils.extract_miller_array_from_file(
    file_name = reff[0],
    label     = params.label,
    type      = "complex",
    log       = log)
  assert map_coeffs is not None
  map_coeffs.show_comprehensive_summary(prefix="  ", f=log)
  ###
  broadcast(m="MEM calculations begin", log = log)
  f_000 = params.f_000
  solvent_fraction = params.solvent_fraction
  if(f_000 is None):
    f_000_obj = mmtbx.utils.f_000(
      xray_structure       = xray_structure,
      unit_cell_volume     = map_coeffs.unit_cell().volume(),
      solvent_fraction     = params.solvent_fraction,
      mean_solvent_density = params.mean_solvent_density)
    f_000 = f_000_obj.f_000
    solvent_fraction = f_000_obj.solvent_fraction
  print >> log, "F(0,0,0): %12.6f"%f_000
  if(solvent_fraction is not None):
    print >> log, "solvent_fraction: %6.4f" % solvent_fraction
  result = mem.run(
    f                       = map_coeffs,
    f_000                   = f_000,
    lam                     = params.lam,
    lambda_increment_factor = params.lambda_increment_factor,
    resolution_factor       = params.resolution_factor,
    verbose                 = True,
    start_map               = "min_shifted",
    max_iterations          = params.max_iterations,
    use_modification        = True,
    beta                    = params.beta,
    convergence_at_r_factor = params.convergence_at_r_factor,
    xray_structure          = xray_structure,
    convergence_r_threshold = params.convergence_r_threshold,
    log                     = log)
  ###
  broadcast(m="Output MEM map coefficients", log = log)
  ind = max(0,reff[0].rfind("."))
  ofn = params.output_file_name
  if (ofn is None) :
    ofn = reff[0]+"_mem.mtz" if ind==0 else reff[0][:ind]+"_mem.mtz"
  print >> log, "  Output file name:", ofn
  result.write_mtz_file(file_name = ofn,
    column_root_label=params.column_root_label,
    d_min=params.output_high_resolution)
  broadcast(m="All done", log=log)
  return os.path.abspath(ofn)