Пример #1
0
def exercise_2(eps = 1.e-6):
###> Get started from PDB
  mon_lib_srv = monomer_library.server.server()
  ener_lib = monomer_library.server.ener_lib()
  pdb_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/phe_abc_tlsanl_out_geometry_minimized.pdb",
    test=os.path.isfile)
  model = mmtbx.model.manager(
      model_input=iotbx.pdb.input(file_name=pdb_file),
      build_grm=True)
  model.setup_scattering_dictionaries(scattering_table="wk1995")
  model.get_xray_structure().convert_to_isotropic()
  u_iso_start = model.get_xray_structure().extract_u_iso_or_u_equiv()
  model.get_xray_structure().convert_to_anisotropic()

  selections = []
  selection_strings = ["chain A", "chain B", "chain C"]
  for string in selection_strings:
      selections.append(model.selection(string = string))
################
  selection = flex.bool(model.get_number_of_atoms(), True)
  class refinement_flags: pass
  refinement_flags.adp_tls = selections
  model.set_refinement_flags(refinement_flags)
  model.determine_tls_groups(selection_strings=selections, generate_tlsos=selections)
  model.set_refinement_flags(refinement_flags)
  xray_structure = model.get_xray_structure()
################
###> Get TLS <-> Ucart
  T_initial = []
  L_initial = []
  S_initial = []
  T_initial.append([0.11,0.22,0.33,0.12,0.13,0.23])
  L_initial.append([1.11,1.22,1.33,1.12,1.13,1.23])
  S_initial.append([0.11,0.12,0.13,0.21,0.22,0.23,0.31,0.32,-0.33])

  T_initial.append([0.22,0.44,0.66,0.24,0.26,0.46])
  L_initial.append([2.22,2.44,2.66,2.24,2.26,2.46])
  S_initial.append([0.22,0.24,0.26,0.42,0.44,0.46,0.62,0.64,-0.66])

  T_initial.append([0.33,0.66,0.99,0.36,0.39,0.69])
  L_initial.append([2.33,2.66,2.99,2.36,2.39,2.69])
  S_initial.append([0.22,0.24,0.26,0.42,0.44,0.46,0.62,0.64,-0.66])

  tlsosA = tools.generate_tlsos(selections     = selections,
                                xray_structure = xray_structure,
                                T              = T_initial,
                                L              = L_initial,
                                S              = S_initial)

  tlsos = tools.generate_tlsos(selections     = selections,
                               xray_structure = xray_structure,
                               T              = T_initial,
                               L              = L_initial,
                               S              = S_initial)
  tlsos = tools.make_tlso_compatible_with_u_positive_definite(
                  tlsos                                       = tlsos,
                  xray_structure                              = xray_structure.deep_copy_scatterers(),
                  selections                                  = selections,
                  max_iterations                              = 50,
                  number_of_u_nonpositive_definite            = 0,
                  eps                                         = eps,
                  number_of_macro_cycles_for_tls_from_uanisos = 30)

  u_cart_answer = tools.u_cart_from_tls(sites_cart = xray_structure.sites_cart(),
                                         selections = selections,
                                         tlsos      = tlsos)
  xray_structure.scatterers().set_u_cart(xray_structure.unit_cell(),
                                                                 u_cart_answer)

  assert approx_equal(u_cart_answer,
        xray_structure.scatterers().extract_u_cart(xray_structure.unit_cell()))


  tools.show_tls(tlsos = tlsos, text = "ANSWER")

###> Set up fmodel
  sfg_params = mmtbx.f_model.sf_and_grads_accuracy_master_params.extract()
  sfg_params.algorithm = "direct"
  sfg_params.cos_sin_table = False
  dummy = xray_structure.structure_factors(algorithm = sfg_params.algorithm,
                                           d_min     = 2.0).f_calc()
  f_obs = abs(dummy.structure_factors_from_scatterers(
                           xray_structure = xray_structure,
                           algorithm      = sfg_params.algorithm,
                           cos_sin_table  = sfg_params.cos_sin_table).f_calc())
  flags = f_obs.generate_r_free_flags(fraction=0.01, max_free=2000)

  fmodel = mmtbx.f_model.manager(xray_structure    = xray_structure,
                                 f_obs             = f_obs,
                                 r_free_flags      = flags,
                                 target_name       = "ls_wunit_k1",
                                 sf_and_grads_accuracy_params = sfg_params)
  fmodel.info(free_reflections_per_bin=250, max_number_of_bins=30).show_all()
  xray_structure.convert_to_isotropic()
  xray_structure.set_b_iso(value = 25.0)
  fmodel.update_xray_structure(xray_structure = xray_structure,
                               update_f_calc  = True)
  fmodel.info(free_reflections_per_bin=250, max_number_of_bins=30).show_all()
  print("*"*80)
###> TLS refinement against xray data
  if (not "--comprehensive" in sys.argv[1:]):
          number_of_macro_cycles   = 1
          max_number_of_iterations = 3
  else:
          number_of_macro_cycles   = 100
          max_number_of_iterations = 50

  for start_tls_value in [None]:#[0.0, tlsosA, None]:
  #for start_tls_value in [None]:
      print(" \n "+str(start_tls_value) + " \n ")
      fmodel_cp = fmodel.deep_copy()
      #for sc in fmodel_cp.xray_structure.scatterers():
      #  sc.flags.set_use_u_aniso(True)
      fmodel_cp.xray_structure.convert_to_anisotropic()

      if(start_tls_value is None):
         run_finite_differences_test = True
      else: run_finite_differences_test = False
      model.set_xray_structure(fmodel_cp.xray_structure)
      tls_refinement_manager = tools.tls_refinement(
                     fmodel                      = fmodel_cp,
                     model                       = model,
                     selections                  = selections,
                     selections_1d               = None,
                     refine_T                    = 1,
                     refine_L                    = 1,
                     refine_S                    = 1,
                     number_of_macro_cycles      = number_of_macro_cycles,
                     max_number_of_iterations    = max_number_of_iterations,
                     start_tls_value             = start_tls_value,
                     run_finite_differences_test = run_finite_differences_test,
                     eps                         = eps)
      u_cart = tls_refinement_manager.fmodel.xray_structure.scatterers().extract_u_cart(
                                                        xray_structure.unit_cell())
      if("--comprehensive" in sys.argv[1:]):
         format   = "%10.6f %10.6f %10.6f %10.6f %10.6f %10.6f"
         counter = 0
         if(start_tls_value == tlsosA): tolerance = 1.e-6
         else: tolerance = 0.02
         for m1,m2 in zip(u_cart_answer, u_cart):
             counter += 1
             if(counter < 10):
                print("1=" + format % (m1[0],m1[1],m1[2],m1[3],m1[4],m1[5]))
                print("2=" + format % (m2[0],m2[1],m2[2],m2[3],m2[4],m2[5]))
             assert approx_equal(m1,m2, tolerance)
Пример #2
0
def uaniso_from_tls_and_back():
  mon_lib_srv = monomer_library.server.server()
  ener_lib = monomer_library.server.ener_lib()
  pdb_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/1OC2_tst.pdb",
    test=os.path.isfile)
  processed_pdb_file = monomer_library.pdb_interpretation.process(
                                       mon_lib_srv               = mon_lib_srv,
                                       ener_lib                  = ener_lib,
                                       file_name                 = pdb_file,
                                       raw_records               = None,
                                       force_symmetry            = True)
  xray_structure = processed_pdb_file.xray_structure()
  selections = []
  for string in ["chain A", "chain B"]:
      selections.append(processed_pdb_file.all_chain_proxies.selection(
                                                              string = string))
  input_tls_data = iotbx.pdb.remark_3_interpretation.extract_tls_parameters(
    remark_3_records=processed_pdb_file.all_chain_proxies.pdb_inp
      .extract_remark_iii_records(iii=3),
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy,
    chain_ids=[]).tls_params
  tls_params = []
  for item in input_tls_data:
      tls_params.append(tools.tlso(t      = item.t,
                                   l      = item.l,
                                   s      = item.s,
                                   origin = item.origin))
  tools.show_tls(tlsos = tls_params)
  u_cart_from_tls = tools.u_cart_from_tls(
                        sites_cart = xray_structure.sites_cart(),
                        selections = selections,
                        tlsos      = tls_params)

  i = 0
  for utls,atom in zip(u_cart_from_tls,
                       processed_pdb_file.all_chain_proxies.pdb_atoms):
    updb = atom.uij
    #i += 1
    #print "      ", i
    #print "%6.4f %6.4f %6.4f %6.4f %6.4f %6.4f "% \
    #                         (utls[0],utls[1],utls[2],utls[3],utls[4],utls[5])
    #print "%6.4f %6.4f %6.4f %6.4f %6.4f %6.4f "% \
    #                         (updb[0],updb[1],updb[2],updb[3],updb[4],updb[5])
    assert approx_equal(utls,updb, 1.e-4)

  tlsos_initial = []
  for input_tls_data_ in input_tls_data:
      tlsos_initial.append(tools.tlso(
                                   t = ([0.0,0.0,0.0,0.0,0.0,0.0]),
                                   l = ([0.0,0.0,0.0,0.0,0.0,0.0]),
                                   s = ([0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]),
                                   origin = input_tls_data_.origin))
  tls_from_uanisos = tools.tls_from_uanisos(
    number_of_macro_cycles       = 300,
    max_iterations               = 1000,
    xray_structure = xray_structure,
    selections     = selections,
    tlsos_initial  = tlsos_initial)
  print "\nTLS from Uaniso:\n"
  tools.show_tls(tlsos = tls_from_uanisos)

  for input_tls_data_,tls_from_uanisos_ in zip(tls_params,tls_from_uanisos):
    assert approx_equal(input_tls_data_.t,      tls_from_uanisos_.t, 1.e-4)
    assert approx_equal(input_tls_data_.l,      tls_from_uanisos_.l, 1.e-4)
    assert approx_equal(input_tls_data_.s,      tls_from_uanisos_.s, 1.e-4)
    assert approx_equal(input_tls_data_.origin, tls_from_uanisos_.origin, 1.e-3)
  #
  print format_cpu_times()
Пример #3
0
def uaniso_from_tls_and_back():
  mon_lib_srv = monomer_library.server.server()
  ener_lib = monomer_library.server.ener_lib()
  pdb_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/1OC2_tst.pdb",
    test=os.path.isfile)
  processed_pdb_file = monomer_library.pdb_interpretation.process(
                                       mon_lib_srv               = mon_lib_srv,
                                       ener_lib                  = ener_lib,
                                       file_name                 = pdb_file,
                                       raw_records               = None,
                                       force_symmetry            = True)
  xray_structure = processed_pdb_file.xray_structure()
  selections = []
  for string in ["chain A", "chain B"]:
      selections.append(processed_pdb_file.all_chain_proxies.selection(
                                                              string = string))
  input_tls_data = iotbx.pdb.remark_3_interpretation.extract_tls_parameters(
    remark_3_records=processed_pdb_file.all_chain_proxies.pdb_inp
      .extract_remark_iii_records(iii=3),
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy,
    chain_ids=[]).tls_params
  tls_params = []
  for item in input_tls_data:
      tls_params.append(tools.tlso(t      = item.t,
                                   l      = item.l,
                                   s      = item.s,
                                   origin = item.origin))
  tools.show_tls(tlsos = tls_params)
  u_cart_from_tls = tools.u_cart_from_tls(
                        sites_cart = xray_structure.sites_cart(),
                        selections = selections,
                        tlsos      = tls_params)

  i = 0
  for utls,atom in zip(u_cart_from_tls,
                       processed_pdb_file.all_chain_proxies.pdb_atoms):
    updb = atom.uij
    #i += 1
    #print "      ", i
    #print "%6.4f %6.4f %6.4f %6.4f %6.4f %6.4f "% \
    #                         (utls[0],utls[1],utls[2],utls[3],utls[4],utls[5])
    #print "%6.4f %6.4f %6.4f %6.4f %6.4f %6.4f "% \
    #                         (updb[0],updb[1],updb[2],updb[3],updb[4],updb[5])
    assert approx_equal(utls,updb, 1.e-4)

  tlsos_initial = []
  for input_tls_data_ in input_tls_data:
      tlsos_initial.append(tools.tlso(
                                   t = ([0.0,0.0,0.0,0.0,0.0,0.0]),
                                   l = ([0.0,0.0,0.0,0.0,0.0,0.0]),
                                   s = ([0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]),
                                   origin = input_tls_data_.origin))
  tls_from_uanisos = tools.tls_from_uanisos(
    number_of_macro_cycles       = 300,
    max_iterations               = 1000,
    xray_structure = xray_structure,
    selections     = selections,
    tlsos_initial  = tlsos_initial)
  print("\nTLS from Uaniso:\n")
  tools.show_tls(tlsos = tls_from_uanisos)

  for input_tls_data_,tls_from_uanisos_ in zip(tls_params,tls_from_uanisos):
    assert approx_equal(input_tls_data_.t,      tls_from_uanisos_.t, 1.e-4)
    assert approx_equal(input_tls_data_.l,      tls_from_uanisos_.l, 1.e-4)
    assert approx_equal(input_tls_data_.s,      tls_from_uanisos_.s, 1.e-4)
    assert approx_equal(input_tls_data_.origin, tls_from_uanisos_.origin, 1.e-3)
  #
  print(format_cpu_times())
def exercise_2(eps = 1.e-6):
###> Get started from PDB
  mon_lib_srv = monomer_library.server.server()
  ener_lib = monomer_library.server.ener_lib()
  pdb_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/phe_abc_tlsanl_out_geometry_minimized.pdb",
    test=os.path.isfile)
  processed_pdb_file = monomer_library.pdb_interpretation.process(
                                       mon_lib_srv               = mon_lib_srv,
                                       ener_lib                  = ener_lib,
                                       file_name                 = pdb_file,
                                       raw_records               = None,
                                       force_symmetry            = True)
  xray_structure = processed_pdb_file.xray_structure()
  xray_structure.scattering_type_registry(table = "wk1995")
  xray_structure.convert_to_isotropic()
  u_iso_start = xray_structure.extract_u_iso_or_u_equiv()
  xray_structure.convert_to_anisotropic()
  selections = []
  selection_strings = ["chain A", "chain B", "chain C"]
  for string in selection_strings:
      selections.append(processed_pdb_file.all_chain_proxies.selection(
                                                              string = string))
################
  geometry = processed_pdb_file.geometry_restraints_manager(
                                                    show_energies      = False,
                                                    plain_pairs_radius = 5.0)
  restraints_manager = mmtbx.restraints.manager(geometry      = geometry,
                                                normalization = False)
  selection = flex.bool(xray_structure.scatterers().size(), True)
  class refinement_flags: pass
  refinement_flags.adp_tls = selections
  tls_groups = tools.tls_groups(selection_strings = selection_strings)
  tlsos = tools.generate_tlsos(
          selections     = refinement_flags.adp_tls,
          xray_structure = xray_structure,
          value          = 0.0)
  tls_groups.tlsos = tlsos
  model = mmtbx.model.manager(
    refinement_flags = refinement_flags,
    restraints_manager = restraints_manager,
    xray_structure = xray_structure,
    tls_groups = tls_groups,
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy)
################
###> Get TLS <-> Ucart
  T_initial = []
  L_initial = []
  S_initial = []
  T_initial.append([0.11,0.22,0.33,0.12,0.13,0.23])
  L_initial.append([1.11,1.22,1.33,1.12,1.13,1.23])
  S_initial.append([0.11,0.12,0.13,0.21,0.22,0.23,0.31,0.32,-0.33])

  T_initial.append([0.22,0.44,0.66,0.24,0.26,0.46])
  L_initial.append([2.22,2.44,2.66,2.24,2.26,2.46])
  S_initial.append([0.22,0.24,0.26,0.42,0.44,0.46,0.62,0.64,-0.66])

  T_initial.append([0.33,0.66,0.99,0.36,0.39,0.69])
  L_initial.append([2.33,2.66,2.99,2.36,2.39,2.69])
  S_initial.append([0.22,0.24,0.26,0.42,0.44,0.46,0.62,0.64,-0.66])

  tlsosA = tools.generate_tlsos(selections     = selections,
                                xray_structure = xray_structure,
                                T              = T_initial,
                                L              = L_initial,
                                S              = S_initial)

  tlsos = tools.generate_tlsos(selections     = selections,
                               xray_structure = xray_structure,
                               T              = T_initial,
                               L              = L_initial,
                               S              = S_initial)
  tlsos = tools.make_tlso_compatible_with_u_positive_definite(
                  tlsos                                       = tlsos,
                  xray_structure                              = xray_structure.deep_copy_scatterers(),
                  selections                                  = selections,
                  max_iterations                              = 50,
                  number_of_u_nonpositive_definite            = 0,
                  eps                                         = eps,
                  number_of_macro_cycles_for_tls_from_uanisos = 30)

  u_cart_answer = tools.u_cart_from_tls(sites_cart = xray_structure.sites_cart(),
                                         selections = selections,
                                         tlsos      = tlsos)
  xray_structure.scatterers().set_u_cart(xray_structure.unit_cell(),
                                                                 u_cart_answer)

  assert approx_equal(u_cart_answer,
        xray_structure.scatterers().extract_u_cart(xray_structure.unit_cell()))


  tools.show_tls(tlsos = tlsos, text = "ANSWER")

###> Set up fmodel
  sfg_params = mmtbx.f_model.sf_and_grads_accuracy_master_params.extract()
  sfg_params.algorithm = "direct"
  sfg_params.cos_sin_table = False
  dummy = xray_structure.structure_factors(algorithm = sfg_params.algorithm,
                                           d_min     = 2.0).f_calc()
  f_obs = abs(dummy.structure_factors_from_scatterers(
                           xray_structure = xray_structure,
                           algorithm      = sfg_params.algorithm,
                           cos_sin_table  = sfg_params.cos_sin_table).f_calc())
  flags = f_obs.generate_r_free_flags(fraction=0.01, max_free=2000)

  fmodel = mmtbx.f_model.manager(xray_structure    = xray_structure,
                                 f_obs             = f_obs,
                                 r_free_flags      = flags,
                                 target_name       = "ls_wunit_k1",
                                 sf_and_grads_accuracy_params = sfg_params)
  fmodel.info(free_reflections_per_bin=250, max_number_of_bins=30).show_all()
  xray_structure.convert_to_isotropic()
  xray_structure.set_b_iso(value = 25.0)
  fmodel.update_xray_structure(xray_structure = xray_structure,
                               update_f_calc  = True)
  fmodel.info(free_reflections_per_bin=250, max_number_of_bins=30).show_all()
  print "*"*80
###> TLS refinement against xray data
  if (not "--comprehensive" in sys.argv[1:]):
          number_of_macro_cycles   = 1
          max_number_of_iterations = 3
  else:
          number_of_macro_cycles   = 100
          max_number_of_iterations = 50

  for start_tls_value in [None]:#[0.0, tlsosA, None]:
  #for start_tls_value in [None]:
      print " \n "+str(start_tls_value) + " \n "
      fmodel_cp = fmodel.deep_copy()
      #for sc in fmodel_cp.xray_structure.scatterers():
      #  sc.flags.set_use_u_aniso(True)
      fmodel_cp.xray_structure.convert_to_anisotropic()

      if(start_tls_value is None):
         run_finite_differences_test = True
      else: run_finite_differences_test = False
      model.xray_structure = fmodel_cp.xray_structure
      tls_refinement_manager = tools.tls_refinement(
                     fmodel                      = fmodel_cp,
                     model                       = model,
                     selections                  = selections,
                     selections_1d               = None,
                     refine_T                    = 1,
                     refine_L                    = 1,
                     refine_S                    = 1,
                     number_of_macro_cycles      = number_of_macro_cycles,
                     max_number_of_iterations    = max_number_of_iterations,
                     start_tls_value             = start_tls_value,
                     run_finite_differences_test = run_finite_differences_test,
                     eps                         = eps)
      u_cart = tls_refinement_manager.fmodel.xray_structure.scatterers().extract_u_cart(
                                                        xray_structure.unit_cell())
      if("--comprehensive" in sys.argv[1:]):
         format   = "%10.6f %10.6f %10.6f %10.6f %10.6f %10.6f"
         counter = 0
         if(start_tls_value == tlsosA): tolerance = 1.e-6
         else: tolerance = 0.02
         for m1,m2 in zip(u_cart_answer, u_cart):
             counter += 1
             if(counter < 10):
                print "1=" + format % (m1[0],m1[1],m1[2],m1[3],m1[4],m1[5])
                print "2=" + format % (m2[0],m2[1],m2[2],m2[3],m2[4],m2[5])
             assert approx_equal(m1,m2, tolerance)