def METHOD_NAME(refine_xyz=True, refine_adp=False):
  # get xray_structure from PDB file
  inp = get_inputs(pdb_str = pdb_str)
  if(1):
    inp.pdb_hierarchy.adopt_xray_structure(inp.xray_structure)
    inp.pdb_hierarchy.write_pdb_file(file_name="start.pdb")
  # simulate poor starting model: shake coordinates and B-factors
  xrs_poor = inp.xray_structure.deep_copy_scatterers()
  if(refine_xyz):
    xrs_poor.shake_sites_in_place(mean_distance = 0.3)
  if(refine_adp):
    for sc in xrs_poor.scatterers():
      sc.u_iso = adptbx.b_as_u(random.choice([7,8,9,11,12,13]))
  if(1):
    inp.pdb_hierarchy.adopt_xray_structure(xrs_poor)
    inp.pdb_hierarchy.write_pdb_file(file_name="poor.pdb")
  # simulate Fobs
  f_obs = abs(inp.xray_structure.structure_factors(
    d_min = 1.0,
    algorithm="direct").f_calc())
  r_free_flags = f_obs.generate_r_free_flags()
  # get fmodel
  params = mmtbx.f_model.sf_and_grads_accuracy_master_params.extract()
  params.algorithm = "direct"
  fmodel = mmtbx.f_model.manager(
    f_obs                        = f_obs,
    r_free_flags                 = r_free_flags,
    xray_structure               = xrs_poor,
    sf_and_grads_accuracy_params = params,
    target_name                  = "ls_wunit_kunit")
  # refinement loop
  print("start r_factor: %6.4f" % fmodel.r_work())
  for macro_cycle in range(100):
    # refine coordinates
    if(refine_xyz):
      minimized = minimizer(fmodel = fmodel, sites = True)
      print("  macro_cycle %3d (sites) r_factor: %6.4f"%(macro_cycle,
        fmodel.r_work()))
    # refine ADPs
    if(refine_adp):
      minimized = minimizer(fmodel = fmodel, u_iso = True)
      print("  macro_cycle %3d (adp)   r_factor: %6.4f"%(macro_cycle, fmodel.r_work()))
  if(1):
    inp.pdb_hierarchy.adopt_xray_structure(fmodel.xray_structure)
    inp.pdb_hierarchy.write_pdb_file(file_name="refined.pdb")