Example #1
0
def exercise_xray_structure(use_u_aniso, verbose=0):
    structure = random_structure.xray_structure(
        space_group_info=sgtbx.space_group_info("P 31"),
        elements=["N", "C", "C", "O", "Si"] * 2,
        volume_per_atom=500,
        min_distance=2.0,
        general_positions_only=False,
        random_u_iso=True,
        use_u_aniso=use_u_aniso,
    )
    f_abs = abs(structure.structure_factors(anomalous_flag=False, d_min=2, algorithm="direct").f_calc())
    for resname in (None, "res"):
        for fractional_coordinates in (False, True):
            pdb_file = structure.as_pdb_file(
                remark="Title", remarks=["Any", "Thing"], fractional_coordinates=fractional_coordinates, resname=resname
            )
            if 0 or verbose:
                sys.stdout.write(pdb_file)
            structure_read = iotbx.pdb.input(
                source_info=None, lines=flex.std_string(pdb_file.splitlines())
            ).xray_structure_simple(fractional_coordinates=fractional_coordinates, use_scale_matrix_if_available=False)
            f_read = abs(
                f_abs.structure_factors_from_scatterers(xray_structure=structure_read, algorithm="direct").f_calc()
            )
            regression = flex.linear_regression(f_abs.data(), f_read.data())
            assert regression.is_well_defined()
            if 0 or verbose:
                regression.show_summary()
            assert approx_equal(regression.slope(), 1, eps=1.0e-2)
            assert approx_equal(regression.y_intercept(), 0, eps=flex.max(f_abs.data()) * 0.01)
Example #2
0
 def _write_map(self, file_name):
     iotbx.mrcfile.write_ccp4_map(
         file_name=file_name,
         unit_cell=self.unit_cell,
         space_group=self.model.crystal_symmetry().space_group(),
         map_data=self.map_data.as_double(),
         labels=flex.std_string([""]))
 def _nonbonded_pair_objects(
     max_bonded_cutoff=3.,
     i_seqs=None,
 ):
     if i_seqs is None:
         atoms = self.pdb_hierarchy.atoms()
         i_seqs = flex.size_t()
         for atom in atoms:
             i_seqs.append(atom.i_seq)
     if (self.model_indices is not None):
         model_indices = self.model_indices.select(i_seqs)
     conformer_indices = self.conformer_indices.select(i_seqs)
     sym_excl_indices = self.sym_excl_indices.select(i_seqs)
     donor_acceptor_excl_groups = self.donor_acceptor_excl_groups.select(
         i_seqs)
     asu_mappings = self.special_position_settings.asu_mappings(
         buffer_thickness=max_bonded_cutoff)
     sites_cart = self.sites_cart.select(i_seqs)
     asu_mappings.process_sites_cart(
         original_sites=sites_cart,
         site_symmetry_table=self.site_symmetry_table().select(i_seqs))
     pair_asu_table = crystal.pair_asu_table(asu_mappings=asu_mappings)
     nonbonded_proxies = geometry_restraints.nonbonded_sorted_asu_proxies(
         model_indices=model_indices,
         conformer_indices=conformer_indices,
         sym_excl_indices=sym_excl_indices,
         donor_acceptor_excl_groups=donor_acceptor_excl_groups,
         nonbonded_params=geometry_restraints.nonbonded_params(
             default_distance=1),
         nonbonded_types=flex.std_string(conformer_indices.size()),
         nonbonded_charges=flex.int(conformer_indices.size(), 0),
         nonbonded_distance_cutoff_plus_buffer=max_bonded_cutoff,
         min_cubicle_edge=5,
         shell_asu_tables=[pair_asu_table])
     return nonbonded_proxies, sites_cart, pair_asu_table, asu_mappings, i_seqs
Example #4
0
 def _wrap_loop_if_needed(self, cif_block, name):
     data = cif_block.get(name)
     if data is None:
         return data
     if isinstance(data, string_types):
         data = flex.std_string([data])
     return data
Example #5
0
 def write_map_box(self, box, filename):
     mrcfile.write_ccp4_map(
       file_name   = filename,
       unit_cell   = box.xray_structure_box.unit_cell(),
       space_group = box.xray_structure_box.space_group(),
       map_data    = box.map_box,
       labels      = flex.std_string([""]))
def exercise_1():
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv              = server.server(),
    ener_lib                 = server.ener_lib(),
    raw_records              = flex.std_string(pdb_str_1.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  grm = processed_pdb_file.geometry_restraints_manager()
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  sites_cart = pdb_hierarchy.atoms().extract_xyz()
  # c-beta restraints are added by default!!!
  assert len(grm.get_c_beta_torsion_proxies()) == 4

  #test global selection and removing c-beta restraints
  tst_boolsel = pdb_hierarchy.atom_selection_cache().selection("resname TYR")
  tst_iselection = tst_boolsel.iselection()
  #test global selection
  grm2 = grm.select(iselection=tst_iselection)
  assert len(grm2.get_c_beta_torsion_proxies()) == 2
  grm2 = grm.select(selection=tst_boolsel)
  assert len(grm2.get_c_beta_torsion_proxies()) == 2
  #remove a selection
  grm.remove_c_beta_torsion_restraints_in_place(selection=tst_iselection)
  assert len(grm.get_c_beta_torsion_proxies()) == 2
  #add a selection
  grm.remove_c_beta_torsion_restraints_in_place()
  assert len(grm.get_c_beta_torsion_proxies()) == 0
  c_beta_torsion_proxies = c_beta.get_c_beta_torsion_proxies(
      pdb_hierarchy,
      selection=tst_iselection,
      sigma=2.5)
  assert len(c_beta_torsion_proxies) == 2
def get_pair_sym_table(xray_structure):
  asu_mappings = xray_structure.asu_mappings(buffer_thickness=3.5)
  pair_asu_table = crystal.pair_asu_table(asu_mappings=asu_mappings)
  scattering_types = xray_structure.scatterers().extract_scattering_types()
  pair_asu_table.add_covalent_pairs(
    scattering_types, exclude_scattering_types=flex.std_string(("H","D")))
  return pair_asu_table.extract_pair_sym_table()
def exercise_1():
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv              = server.server(),
    ener_lib                 = server.ener_lib(),
    raw_records              = flex.std_string(pdb_str_1.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  grm = processed_pdb_file.geometry_restraints_manager()
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  sites_cart = pdb_hierarchy.atoms().extract_xyz()
  # c-beta restraints are added by default!!!
  assert len(grm.get_c_beta_torsion_proxies()) == 4

  #test global selection and removing c-beta restraints
  tst_boolsel = pdb_hierarchy.atom_selection_cache().selection("resname TYR")
  tst_iselection = tst_boolsel.iselection()
  #test global selection
  grm2 = grm.select(iselection=tst_iselection)
  assert len(grm2.get_c_beta_torsion_proxies()) == 2
  grm2 = grm.select(selection=tst_boolsel)
  assert len(grm2.get_c_beta_torsion_proxies()) == 2
  #remove a selection
  grm.remove_c_beta_torsion_restraints_in_place(selection=tst_iselection)
  assert len(grm.get_c_beta_torsion_proxies()) == 2
  #add a selection
  grm.remove_c_beta_torsion_restraints_in_place()
  assert len(grm.get_c_beta_torsion_proxies()) == 0
  c_beta_torsion_proxies = c_beta.get_c_beta_torsion_proxies(
      pdb_hierarchy,
      selection=tst_iselection,
      sigma=2.5)
  assert len(c_beta_torsion_proxies) == 2
Example #9
0
def write_files(results, mask_output, debug, f_obs, prefix, log):
    # write mask files (if specified)
    if (mask_output):
        masks = [
            results.mask_data_all, results.mask_data_omit,
            results.mask_data_polder
        ]
        filenames = ["all", "omit", "polder"]
        for mask_data, filename in zip(masks, filenames):
            ccp4_map.write_ccp4_map(file_name="mask_" + filename + ".ccp4",
                                    unit_cell=f_obs.unit_cell(),
                                    space_group=f_obs.space_group(),
                                    map_data=mask_data,
                                    labels=flex.std_string([""]))
    mtz_dataset = results.mc_polder.as_mtz_dataset(
        column_root_label="mFo-DFc_polder")
    # add map coeffs for biased map if debug=True
    if (debug):
        mtz_dataset.add_miller_array(miller_array=results.mc_biased,
                                     column_root_label="mFo-DFc_bias_omit")
    mtz_dataset.add_miller_array(miller_array=results.mc_omit,
                                 column_root_label="mFo-DFc_omit")
    mtz_object = mtz_dataset.mtz_object()
    polder_file_name = "polder_map_coeffs.mtz"
    if (prefix is not None):
        polder_file_name = prefix + "_" + polder_file_name
    mtz_object.write(file_name=polder_file_name)
    print >> log, 'File %s was written.' % polder_file_name
Example #10
0
 def _nonbonded_pair_objects(max_bonded_cutoff=3.,
                             i_seqs=None,
                             ):
   if i_seqs is None:
     atoms = self.pdb_hierarchy.atoms()
     i_seqs = flex.size_t()
     for atom in atoms:
       i_seqs.append(atom.i_seq)
   if (self.model_indices is not None):
     model_indices = self.model_indices.select(i_seqs)
   conformer_indices = self.conformer_indices.select(i_seqs)
   sym_excl_indices = self.sym_excl_indices.select(i_seqs)
   donor_acceptor_excl_groups = self.donor_acceptor_excl_groups.select(i_seqs)
   asu_mappings = self.special_position_settings.asu_mappings(
     buffer_thickness=max_bonded_cutoff)
   sites_cart = self.sites_cart.select(i_seqs)
   asu_mappings.process_sites_cart(
     original_sites=sites_cart,
     site_symmetry_table=self.site_symmetry_table().select(i_seqs))
   pair_asu_table = crystal.pair_asu_table(asu_mappings=asu_mappings)
   nonbonded_proxies = geometry_restraints.nonbonded_sorted_asu_proxies(
     model_indices=model_indices,
     conformer_indices=conformer_indices,
     sym_excl_indices=sym_excl_indices,
     donor_acceptor_excl_groups=donor_acceptor_excl_groups,
     nonbonded_params=geometry_restraints.nonbonded_params(
       default_distance=1),
     nonbonded_types=flex.std_string(conformer_indices.size()),
     nonbonded_charges=flex.int(conformer_indices.size(), 0),
     nonbonded_distance_cutoff_plus_buffer=max_bonded_cutoff,
     min_cubicle_edge=5,
     shell_asu_tables=[pair_asu_table])
   return nonbonded_proxies, sites_cart, pair_asu_table, asu_mappings, i_seqs
Example #11
0
def output_map(f_obs, r_free_flags, xray_structure, mask_data, filename,
               params, log):
    f_calc = f_obs.structure_factors_from_scatterers(
        xray_structure=xray_structure).f_calc()
    mask = f_obs.structure_factors_from_map(map=mask_data,
                                            use_scale=True,
                                            anomalous_flag=False,
                                            use_sg=False)
    # is it really use_sg = false?
    fmodel = mmtbx.f_model.manager(f_obs=f_obs,
                                   r_free_flags=r_free_flags,
                                   f_calc=f_calc,
                                   f_mask=mask)
    fmodel.update_all_scales()
    print >> log, "r_work=%6.4f r_free=%6.4f" % (fmodel.r_work(),
                                                 fmodel.r_free())
    print >> log, "*" * 79
    mc_diff = map_tools.electron_density_map(fmodel=fmodel).map_coefficients(
        map_type="mFo-DFc", isotropize=True, fill_missing=False)
    if (params.mask_output and filename != 'bias_omit'):
        ccp4_map.write_ccp4_map(file_name="mask_" + filename + ".ccp4",
                                unit_cell=f_obs.unit_cell(),
                                space_group=f_obs.space_group(),
                                map_data=mask_data,
                                labels=flex.std_string([""]))
    return mc_diff
Example #12
0
def write_map_file(map_data, cs, file_name):  # FOR DEBUGGING XXX
    from iotbx import mrcfile
    mrcfile.write_ccp4_map(file_name=file_name,
                           unit_cell=cs.unit_cell(),
                           space_group=cs.space_group(),
                           map_data=map_data,
                           labels=flex.std_string([""]))
Example #13
0
def exercise_00(debug=True):
  mon_lib_srv = monomer_library.server.server()
  ener_lib = monomer_library.server.ener_lib()
  for i, l in enumerate(loop):
    if(debug): print "-"*70, i
    ppf = monomer_library.pdb_interpretation.process(
      mon_lib_srv    = mon_lib_srv,
      ener_lib       = ener_lib,
      raw_records    = flex.std_string(l[0].splitlines()),
      force_symmetry = True)
    geometry = ppf.geometry_restraints_manager(
      show_energies      = False,
      plain_pairs_radius = 5.0)
    restraints_manager = mmtbx.restraints.manager(
      geometry = geometry, normalization = False)
    ph = ppf.all_chain_proxies.pdb_hierarchy
    sel = hydrogens.rotatable(pdb_hierarchy=ph, mon_lib_srv=mon_lib_srv,
      restraints_manager = restraints_manager, log=None)
    if(debug):
      print
      print sel
      print l[2]
      print l[0]
      print "\n".join([a.format_atom_record() for a in ph.atoms()])
    ppf.all_chain_proxies.pdb_inp.write_pdb_file(file_name = "m%s.pdb"%str(i))
    if(debug): print "-"*80
    assert sel == l[2], "%s != %s" % (sel, l[2])
    assert hydrogens.count_rotatable(sel) == l[1]
Example #14
0
def output_map(f_obs, r_free_flags, xray_structure, mask_data, filename, params,
               log):
  f_calc = f_obs.structure_factors_from_scatterers(
    xray_structure = xray_structure).f_calc()
  mask = f_obs.structure_factors_from_map(
    map            = mask_data,
    use_scale      = True,
    anomalous_flag = False,
    use_sg         = False)
  # is it really use_sg = false?
  fmodel = mmtbx.f_model.manager(
    f_obs        = f_obs,
    r_free_flags = r_free_flags,
    f_calc       = f_calc,
    f_mask       = mask)
  fmodel.update_all_scales()
  print >> log, "r_work=%6.4f r_free=%6.4f" % (fmodel.r_work(), fmodel.r_free())
  print >> log, "*"*79
  mc_diff = map_tools.electron_density_map(
    fmodel = fmodel).map_coefficients(
      map_type         = "mFo-DFc",
      isotropize       = True,
      fill_missing     = False)
  if (params.mask_output and filename != 'bias_omit'):
    ccp4_map.write_ccp4_map(
    file_name   = "mask_"+filename+".ccp4",
    unit_cell   = f_obs.unit_cell(),
    space_group = f_obs.space_group(),
    map_data    = mask_data,
    labels      = flex.std_string([""]))
  return mc_diff
Example #15
0
def exercise_1():
    pdb_inp = iotbx.pdb.input(lines=flex.std_string(pdb_str_1.splitlines()),
                              source_info=None)
    model = mmtbx.model.manager(model_input=pdb_inp)
    model.process(make_restraints=True)
    grm = model.get_restraints_manager().geometry
    pdb_hierarchy = model.get_hierarchy()
    sites_cart = model.get_sites_cart()
    # c-beta restraints are added by default!!!
    assert len(grm.get_c_beta_torsion_proxies()) == 4

    #test global selection and removing c-beta restraints
    tst_boolsel = pdb_hierarchy.atom_selection_cache().selection("resname TYR")
    tst_iselection = tst_boolsel.iselection()
    #test global selection
    grm2 = grm.select(iselection=tst_iselection)
    assert len(grm2.get_c_beta_torsion_proxies()) == 2
    grm2 = grm.select(selection=tst_boolsel)
    assert len(grm2.get_c_beta_torsion_proxies()) == 2
    #remove a selection
    grm.remove_c_beta_torsion_restraints_in_place(selection=tst_iselection)
    assert len(grm.get_c_beta_torsion_proxies()) == 2
    #add a selection
    grm.remove_c_beta_torsion_restraints_in_place()
    assert len(grm.get_c_beta_torsion_proxies()) == 0
    c_beta_torsion_proxies = c_beta.get_c_beta_torsion_proxies(
        pdb_hierarchy, selection=tst_iselection, sigma=2.5)
    assert len(c_beta_torsion_proxies) == 2
Example #16
0
 def write_files(self, results, f_obs):
     if (self.params.mask_output):
         masks = [
             results.mask_data_all, results.mask_data_omit,
             results.mask_data_polder
         ]
         filenames = ["all", "omit", "polder"]
         for mask_data, filename in zip(masks, filenames):
             mrcfile.write_ccp4_map(file_name="mask_" + filename + ".ccp4",
                                    unit_cell=f_obs.unit_cell(),
                                    space_group=f_obs.space_group(),
                                    map_data=mask_data,
                                    labels=flex.std_string([""]))
     mtz_dataset = results.mc_polder.as_mtz_dataset(
         column_root_label="mFo-DFc_polder")
     mtz_dataset.add_miller_array(miller_array=results.mc_omit,
                                  column_root_label="mFo-DFc_omit")
     if (self.params.debug):
         mtz_dataset.add_miller_array(miller_array=results.mc_biased,
                                      column_root_label="mFo-DFc_bias_omit")
     mtz_object = mtz_dataset.mtz_object()
     polder_file_name = "polder_map_coeffs.mtz"
     if (self.params.output_file_name_prefix is not None):
         polder_file_name = self.params.output_file_name_prefix + "_" + polder_file_name
     mtz_object.write(file_name=polder_file_name)
     print('File %s was written.' % polder_file_name, file=self.logger)
Example #17
0
def write_map_file(crystal_symmetry, map_data, file_name):
    from iotbx import mrcfile
    mrcfile.write_ccp4_map(file_name=file_name,
                           unit_cell=crystal_symmetry.unit_cell(),
                           space_group=crystal_symmetry.space_group(),
                           map_data=map_data,
                           labels=flex.std_string([""]))
Example #18
0
def exercise_xray_structure(use_u_aniso, verbose=0):
  structure = random_structure.xray_structure(
    space_group_info=sgtbx.space_group_info("P 31"),
    elements=["N","C","C","O","Si"]*2,
    volume_per_atom=500,
    min_distance=2.,
    general_positions_only=False,
    random_u_iso=True,
    use_u_aniso=use_u_aniso)
  f_abs = abs(structure.structure_factors(
    anomalous_flag=False, d_min=2, algorithm="direct").f_calc())
  for resname in (None, "res"):
    for fractional_coordinates in (False, True):
      pdb_file = structure.as_pdb_file(
        remark="Title", remarks=["Any", "Thing"],
        fractional_coordinates=fractional_coordinates,
        resname=resname)
      if (0 or verbose):
        sys.stdout.write(pdb_file)
      structure_read = iotbx.pdb.input(
        source_info=None,
        lines=flex.std_string(pdb_file.splitlines())).xray_structure_simple(
          fractional_coordinates=fractional_coordinates,
          use_scale_matrix_if_available=False)
      f_read = abs(f_abs.structure_factors_from_scatterers(
        xray_structure=structure_read, algorithm="direct").f_calc())
      regression = flex.linear_regression(f_abs.data(), f_read.data())
      assert regression.is_well_defined()
      if (0 or verbose):
        regression.show_summary()
      assert approx_equal(regression.slope(), 1, eps=1.e-2)
      assert approx_equal(
        regression.y_intercept(), 0, eps=flex.max(f_abs.data())*0.01)
def exercise_multiple_atoms(mon_lib_srv, ener_lib):
    geometry, xrs = make_initial_grm(mon_lib_srv, ener_lib, raw_records1)

    # output for debugging!!!
    # show_sorted_geometry(geometry, xrs, 'before_exersice_multiple_atoms.geo')

    xrs_add = iotbx.pdb.input(source_info=None, lines=raw_records3) \
        .xray_structure_simple()
    proxy1 = geometry_restraints.bond_simple_proxy(i_seqs=(3, 9),
                                                   distance_ideal=2.0,
                                                   weight=3000)
    proxy2 = geometry_restraints.bond_simple_proxy(i_seqs=(4, 10),
                                                   distance_ideal=2.0,
                                                   weight=3000)

    new_xrs = xrs.concatenate(xrs_add)
    all_sites_cart = new_xrs.sites_cart()
    number_of_new_atoms = len(xrs_add.sites_cart())
    new_geometry = geometry.new_included_bonded_atoms(
        proxies=[proxy1, proxy2],
        sites_cart=all_sites_cart,
        site_symmetry_table=xrs_add.site_symmetry_table(),
        nonbonded_types=flex.std_string(["OH2"] * number_of_new_atoms),
        nonbonded_charges=flex.int(number_of_new_atoms, 0),
        skip_max_proxy_distance_calculation=True)
    # output for debugging!!!
    # show_sorted_geometry(new_geometry, new_xrs,
    #     'after_exersice_multiple_atoms.geo')

    assert new_geometry.pair_proxies().bond_proxies.simple.size() == 8
    assert new_geometry.pair_proxies().bond_proxies.asu.size() == 2
    assert new_geometry.pair_proxies().nonbonded_proxies.simple.size() == 11
    assert new_geometry.pair_proxies().nonbonded_proxies.asu.size() == 4
Example #20
0
def run(args):
    map_fname = args[0]
    af = any_file(map_fname)
    assert af.file_type == "ccp4_map"
    ccp4_map = af.file_content
    print("origin:", ccp4_map.origin)
    # see how access this info in cctbx_project/iotbx/ccp4_map/__init__.py: def show_summary
    print("summary:", ccp4_map.show_summary())
    xc = yc = zc = 1  # real coordinates
    # fractional coordinates
    xf, yf, zf = ccp4_map.unit_cell().fractionalize([xc, yc, zc])
    print("map value:",
          ccp4_map.map_data().eight_point_interpolation([xf, yf, zf]))
    shifted_map_data = shift_origin_if_needed(ccp4_map.map_data()).map_data
    print("map value on shifted map:",
          shifted_map_data.eight_point_interpolation([xf, yf, zf]))
    print("shifted origin:", shifted_map_data.origin())
    # This does not work for non 0-based (non-shifted) map
    print("map value at closes grid point:",
          shifted_map_data.value_at_closest_grid_point([xf, yf, zf]))

    cs = ccp4_map.crystal_symmetry()
    # writing shifted map
    iotbx.mrcfile.write_ccp4_map(file_name="shifted_map.map",
                                 unit_cell=cs.unit_cell(),
                                 space_group=cs.space_group(),
                                 map_data=shifted_map_data,
                                 labels=flex.std_string([""]))
def exercise_multiple_atoms(mon_lib_srv, ener_lib):
  geometry, xrs = make_initial_grm(mon_lib_srv, ener_lib, raw_records1)

  # output for debugging!!!
  # show_sorted_geometry(geometry, xrs, 'before_exersice_multiple_atoms.geo')

  xrs_add = iotbx.pdb.input(source_info=None, lines=raw_records3) \
      .xray_structure_simple()
  proxy1 = geometry_restraints.bond_simple_proxy(
      i_seqs=(3,9),
      distance_ideal=2.0,
      weight=3000)
  proxy2 = geometry_restraints.bond_simple_proxy(
      i_seqs=(4,10),
      distance_ideal=2.0,
      weight=3000)

  new_xrs = xrs.concatenate(xrs_add)
  all_sites_cart = new_xrs.sites_cart()
  number_of_new_atoms = len(xrs_add.sites_cart())
  new_geometry = geometry.new_included_bonded_atoms(
      proxies=[proxy1, proxy2],
      sites_cart=all_sites_cart,
      site_symmetry_table=xrs_add.site_symmetry_table(),
      nonbonded_types=flex.std_string(["OH2"]*number_of_new_atoms),
      nonbonded_charges=flex.int(number_of_new_atoms, 0),
      skip_max_proxy_distance_calculation=True)
  # output for debugging!!!
  # show_sorted_geometry(new_geometry, new_xrs,
  #     'after_exersice_multiple_atoms.geo')

  assert new_geometry.pair_proxies().bond_proxies.simple.size() == 8
  assert new_geometry.pair_proxies().bond_proxies.asu.size() == 2
  assert new_geometry.pair_proxies().nonbonded_proxies.simple.size() == 11
  assert new_geometry.pair_proxies().nonbonded_proxies.asu.size() == 4
def exercise(pdb_poor_str, d_min = 1.0, resolution_factor = 0.25):
  # Fit one residue in many-residues model
  #
  # answer
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
  pdb_inp.write_pdb_file(file_name = "answer.pdb")
  xrs_answer = pdb_inp.xray_structure_simple()
  f_calc = xrs_answer.structure_factors(d_min = d_min).f_calc()
  fft_map = f_calc.fft_map(resolution_factor=resolution_factor)
  fft_map.apply_sigma_scaling()
  target_map = fft_map.real_map_unpadded()
  mtz_dataset = f_calc.as_mtz_dataset(column_root_label = "FCmap")
  mtz_object = mtz_dataset.mtz_object()
  mtz_object.write(file_name = "answer.mtz")
  # take TYR9
  sites_answer = list(
    pdb_inp.construct_hierarchy().residue_groups())[1].atoms().extract_xyz()
  # poor
  mon_lib_srv = monomer_library.server.server()
  master_params = iotbx.phil.parse(
    input_string=mmtbx.monomer_library.pdb_interpretation.master_params_str,
    process_includes=True).extract()
  master_params.link_distance_cutoff=999
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv              = mon_lib_srv,
    params                   = master_params,
    ener_lib                 = monomer_library.server.ener_lib(),
    raw_records              = flex.std_string(pdb_poor_str.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xrs_poor = processed_pdb_file.xray_structure()
  sites_cart_poor = xrs_poor.sites_cart()
  pdb_hierarchy_poor.write_pdb_file(file_name = "poor.pdb")
  #
  rotamer_manager = RotamerEval()
  get_class = iotbx.pdb.common_residue_names_get_class
  for model in pdb_hierarchy_poor.models():
    for chain in model.chains():
      for residue in chain.only_conformer().residues():
        if(get_class(residue.resname) == "common_amino_acid" and
           int(residue.resseq)==9): # take TYR9
          t0 = time.time()
          ro = mmtbx.refinement.real_space.fit_residue.run_with_minimization(
            target_map      = target_map,
            residue         = residue,
            xray_structure  = xrs_poor,
            mon_lib_srv     = mon_lib_srv,
            rotamer_manager = rotamer_manager,
            real_space_gradients_delta  = d_min*resolution_factor,
            geometry_restraints_manager = processed_pdb_file.geometry_restraints_manager(show_energies=False))
          sites_final = residue.atoms().extract_xyz()
          t1 = time.time()-t0
  pdb_hierarchy_poor.adopt_xray_structure(ro.xray_structure)
  pdb_hierarchy_poor.write_pdb_file(file_name = "refined.pdb")
  dist = flex.mean(flex.sqrt((sites_answer - sites_final).dot()))
  # Highly unstable test
  assert dist < 0.9
def exercise(pdb_poor_str, rotamer_manager, sin_cos_table, i_pdb, d_min = 1.0,
             resolution_factor = 0.1):
  # Fit one residue. There is a huge heavy atom nearby that overlaps with a
  # plausible rotamer.
  # Show importance of map truncaiton.
  #
  # answer
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
  pdb_inp.write_pdb_file(file_name = "answer_%s.pdb"%str(i_pdb))
  xrs_answer = pdb_inp.xray_structure_simple()
  f_calc = xrs_answer.structure_factors(d_min = d_min).f_calc()
  fft_map = f_calc.fft_map(resolution_factor=resolution_factor)
  fft_map.apply_sigma_scaling()
  target_map = fft_map.real_map_unpadded()
  mtz_dataset = f_calc.as_mtz_dataset(column_root_label = "FCmap")
  mtz_object = mtz_dataset.mtz_object()
  mtz_object.write(file_name = "answer_%s.mtz"%str(i_pdb))
  pdb_hierarchy_answer = pdb_inp.construct_hierarchy()
  matching_selection = pdb_hierarchy_answer.atom_selection_cache().selection(
    string = "not element U")
  # Truncate the map
  target_map = target_map.set_selected(target_map > 2, 2)
  # poor
  mon_lib_srv = monomer_library.server.server()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv              = mon_lib_srv,
    ener_lib                 = monomer_library.server.ener_lib(),
    raw_records              = flex.std_string(pdb_poor_str.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xrs_poor = processed_pdb_file.xray_structure()
  sites_cart_poor = xrs_poor.sites_cart()
  pdb_hierarchy_poor.write_pdb_file(file_name = "poor_%s.pdb"%str(i_pdb))
  #
  get_class = iotbx.pdb.common_residue_names_get_class
  residue_poor = None
  for model in pdb_hierarchy_poor.models():
    for chain in model.chains():
      for residue in chain.only_conformer().residues():
        if(get_class(residue.resname) == "common_amino_acid"):
          t0=time.time() # TIMER START
          # refine
          mmtbx.refinement.real_space.fit_residue.run(
            residue         = residue,
            unit_cell       = xrs_poor.unit_cell(),
            target_map      = target_map,
            mon_lib_srv     = mon_lib_srv,
            rotamer_manager = rotamer_manager,
            sin_cos_table   = sin_cos_table)
          sites_cart_poor.set_selected(residue.atoms().extract_i_seq(),
            residue.atoms().extract_xyz())
          print "time (refine): %6.4f" % (time.time()-t0)
  xrs_poor = xrs_poor.replace_sites_cart(sites_cart_poor)
  pdb_hierarchy_poor.adopt_xray_structure(xrs_poor)
  pdb_hierarchy_poor.write_pdb_file(file_name = "refined_%s.pdb"%str(i_pdb))
  dist = xrs_answer.select(matching_selection).max_distance(other = xrs_poor)
  assert dist < 0.25, dist
Example #24
0
def expand_nonbonded_types(
      nonbonded_types,
      x_n_seq,
      related_x_i_seqs):
  result = flex.std_string(x_n_seq)
  for i_seq,s in enumerate(nonbonded_types):
    result.set_selected(related_x_i_seqs[i_seq], s)
  return result
def exercise(i_pdb, pdb_for_map, rotamer_manager, sin_cos_table,
             d_min = 1.5, resolution_factor = 0.1):
  # Best fitting residue is a rotamer outlier (PHE 407), two scenarious:
  #   - outlier fits density perfectly
  #   - outlier fits not so good.
  # No better options to fit other than keep the outlier unchanged.
  #
  # answer PDB
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
  pdb_inp.write_pdb_file(file_name = "answer.pdb")
  xrs_answer = pdb_inp.xray_structure_simple()
  # answer map
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_for_map)
  pdb_inp.write_pdb_file(file_name = "for_map.pdb")
  xrs_map = pdb_inp.xray_structure_simple()
  f_calc = xrs_map.structure_factors(d_min = d_min).f_calc()
  fft_map = f_calc.fft_map(resolution_factor=resolution_factor)
  fft_map.apply_sigma_scaling()
  target_map = fft_map.real_map_unpadded()
  mtz_dataset = f_calc.as_mtz_dataset(column_root_label = "FCmap")
  mtz_object = mtz_dataset.mtz_object()
  mtz_object.write(file_name = "answer_%s.mtz"%str(i_pdb))
  # poor
  mon_lib_srv = monomer_library.server.server()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv              = mon_lib_srv,
    ener_lib                 = monomer_library.server.ener_lib(),
    raw_records              = flex.std_string(pdb_poor.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xrs_poor = processed_pdb_file.xray_structure()
  sites_cart_poor = xrs_poor.sites_cart()
  pdb_hierarchy_poor.write_pdb_file(file_name = "poor.pdb")
  #
  target_map_object = group_args(
    data             = target_map,
    f_map_diff       = None,
    miller_array     = f_calc,
    crystal_gridding = fft_map)
  grm = mmtbx.restraints.manager(
    geometry=processed_pdb_file.geometry_restraints_manager(show_energies=False),
    normalization = True)
  sm = mmtbx.refinement.real_space.structure_monitor(
    pdb_hierarchy               = pdb_hierarchy_poor,
    xray_structure              = xrs_poor,
    target_map_object           = target_map_object,
    geometry_restraints_manager = grm.geometry)
  result = mmtbx.refinement.real_space.fit_residues.manager(
    structure_monitor = sm,
    rotamer_manager   = rotamer_manager,
    sin_cos_table     = sin_cos_table,
    mon_lib_srv       = mon_lib_srv)
  #
  sm.pdb_hierarchy.write_pdb_file(file_name = "refined_%s.pdb"%str(i_pdb))
  dist = xrs_answer.mean_distance(other = sm.xray_structure)
  assert dist < 0.3, dist
Example #26
0
 def get_loop_with_defaults(self, loop_name, default_dict):
     loop_ = self.get_loop(loop_name)
     if loop_ is None:
         loop_ = loop(header=default_dict.keys())
     n_rows = loop_.n_rows()
     for key, value in default_dict.iteritems():
         if key not in loop_:
             loop_.add_column(key, flex.std_string(n_rows, value))
     return loop_
Example #27
0
 def get_loop_with_defaults(self, loop_name, default_dict):
   loop_ = self.get_loop(loop_name)
   if loop_ is None:
     loop_ = loop(header=default_dict.keys())
   n_rows = loop_.n_rows()
   for key, value in default_dict.iteritems():
     if key not in loop_:
       loop_.add_column(key, flex.std_string(n_rows, value))
   return loop_
def exercise(rotamer_manager, sin_cos_table, d_min = 1.0,
             resolution_factor = 0.1):
  # Fit one residue having weak side chain density. There is a blob nearby that
  # overlaps with a plausible rotamer.
  # Making B of HOH smaller will break the test, indicaing potential problem.
  #
  # answer PDB
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
  pdb_inp.write_pdb_file(file_name = "answer.pdb")
  xrs_answer = pdb_inp.xray_structure_simple()
  # answer map
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_poor_for_map)
  xrs_map = pdb_inp.xray_structure_simple()
  f_calc = xrs_map.structure_factors(d_min = d_min).f_calc()
  fft_map = f_calc.fft_map(resolution_factor=resolution_factor)
  fft_map.apply_sigma_scaling()
  target_map = fft_map.real_map_unpadded()
  mtz_dataset = f_calc.as_mtz_dataset(column_root_label = "FCmap")
  mtz_object = mtz_dataset.mtz_object()
  mtz_object.write(file_name = "answer.mtz")
  # poor
  mon_lib_srv = monomer_library.server.server()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv              = mon_lib_srv,
    ener_lib                 = monomer_library.server.ener_lib(),
    raw_records              = flex.std_string(pdb_poor.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xrs_poor = processed_pdb_file.xray_structure()
  sites_cart_poor = xrs_poor.sites_cart()
  pdb_hierarchy_poor.write_pdb_file(file_name = "poor.pdb")
  #
  get_class = iotbx.pdb.common_residue_names_get_class
  residue_poor = None
  for model in pdb_hierarchy_poor.models():
    for chain in model.chains():
      for residue in chain.only_conformer().residues():
        if(get_class(residue.resname) == "common_amino_acid"):
          t0=time.time() # TIMER START
          # refine
          mmtbx.refinement.real_space.fit_residue.run(
            residue         = residue,
            unit_cell       = xrs_poor.unit_cell(),
            target_map      = target_map,
            mon_lib_srv     = mon_lib_srv,
            rotamer_manager = rotamer_manager,
            sin_cos_table   = sin_cos_table)
          sites_cart_poor.set_selected(residue.atoms().extract_i_seq(),
            residue.atoms().extract_xyz())
          print "time (refine): %6.4f" % (time.time()-t0)
  xrs_poor = xrs_poor.replace_sites_cart(sites_cart_poor)
  pdb_hierarchy_poor.adopt_xray_structure(xrs_poor)
  pdb_hierarchy_poor.write_pdb_file(file_name = "refined.pdb")
  dist = xrs_answer.max_distance(other = xrs_poor)
  assert dist < 0.24, dist
Example #29
0
 def show(self, out=None, indent="  ", indent_row=None, fmt_str=None, align_columns=True):
   assert self.n_rows() > 0 and self.n_columns() > 0
   if out is None:
     out = sys.stdout
   if indent_row is None:
     indent_row = indent
   assert indent.strip() == ""
   assert indent_row.strip() == ""
   print >> out, "loop_"
   for k in self.keys():
     print >> out, indent + k
   values = self._columns.values()
   if fmt_str is not None:
     # Pretty printing:
     #   The user is responsible for providing a valid format string.
     #   Values are not quoted - it is the user's responsibility to place
     #   appropriate quotes in the format string if a particular value may
     #   contain spaces.
     values = copy.deepcopy(values)
     for i, v in enumerate(values):
       for flex_numeric_type in (flex.int, flex.double):
         if not isinstance(v, flex_numeric_type):
           try:
             values[i] = flex_numeric_type(v)
           except ValueError:
             continue
           else:
             break
     if fmt_str is None:
       fmt_str = indent_row + ' '.join(["%s"]*len(values))
     for i in range(self.size()):
       print >> out, fmt_str % tuple([values[j][i] for j in range(len(values))])
   elif align_columns:
     fmt_str = []
     for i, (k, v) in enumerate(self.iteritems()):
       for i_v in range(v.size()):
         v[i_v] = format_value(v[i_v])
       # exclude and semicolon text fields from column width calculation
       v_ = flex.std_string(item for item in v if "\n" not in item)
       width = v_.max_element_length()
       # See if column contains only number, '.' or '?'
       # right-align numerical columns, left-align everything else
       v = v.select(~( (v == ".") | (v == "?") ))
       try:
         flex.double(v)
       except ValueError:
         width *= -1
       fmt_str.append("%%%is" %width)
     fmt_str = indent_row + "  ".join(fmt_str)
     for i in range(self.size()):
       print >> out, (fmt_str %
                      tuple([values[j][i]
                             for j in range(len(values))])).rstrip()
   else:
     for i in range(self.size()):
       values_to_print = [format_value(values[j][i]) for j in range(len(values))]
       print >> out, ' '.join([indent] + values_to_print)
Example #30
0
def exercise_planarity():
  p = geometry_restraints.motif_planarity()
  assert p.atom_names.size() == 0
  assert p.weights.size() == 0
  assert p.id == ""
  p = geometry_restraints.motif_planarity(
    atom_names=flex.std_string(["a", "b"]),
    weights=flex.double([1.5, 2.5]),
    id="t")
  assert list(p.atom_names) == ["a", "b"]
  assert list(p.weights) == [1.5, 2.5]
  assert p.id == "t"
  p.atom_names = flex.std_string(["x", "y", "z"])
  assert list(p.atom_names) == ["x", "y", "z"]
  p.weights = flex.double([3.5, 6.5])
  assert list(p.weights) == [3.5, 6.5]
  p.id = "u"
  assert p.id == "u"
Example #31
0
def main(filenames, map_file, npoints=192, max_resolution=6, reverse_phi=False):
    rec_range = 1 / max_resolution

    image = ImageFactory(filenames[0])
    panel = image.get_detector()[0]
    beam = image.get_beam()
    s0 = beam.get_s0()
    pixel_size = panel.get_pixel_size()
    
    xlim, ylim = image.get_raw_data().all()
    
    xy = recviewer.get_target_pixels(panel, s0, xlim, ylim, max_resolution)
    
    s1 = panel.get_lab_coord(xy * pixel_size[0]) # FIXME: assumed square pixel
    s1 = s1 / s1.norms() * (1 / beam.get_wavelength()) # / is not supported...
    S = s1 - s0
    
    grid = flex.double(flex.grid(npoints, npoints, npoints), 0)
    cnts = flex.int(flex.grid(npoints, npoints, npoints), 0)
    
    for filename in filenames:
        print "Processing image", filename
        try:
            fill_voxels(ImageFactory(filename), grid, cnts, S, xy, reverse_phi, rec_range)
        except:
            print " Failed to process. Skipped this."
        
    recviewer.normalize_voxels(grid, cnts)
    
    uc = uctbx.unit_cell((npoints, npoints, npoints, 90, 90, 90))
    ccp4_map.write_ccp4_map(map_file, uc, sgtbx.space_group("P1"), 
                            (0, 0, 0), grid.all(), grid, 
                            flex.std_string(["cctbx.miller.fft_map"]))
    return
    from scitbx import fftpack
    fft = fftpack.complex_to_complex_3d(grid.all())
    grid_complex = flex.complex_double(
                            reals=flex.pow2(grid),
                            imags=flex.double(grid.size(), 0))
    grid_transformed = flex.abs(fft.backward(grid_complex))
    print flex.max(grid_transformed), flex.min(grid_transformed), grid_transformed.all()
    ccp4_map.write_ccp4_map(map_file, uc, sgtbx.space_group("P1"), 
                            (0, 0, 0), grid.all(), grid_transformed,
                            flex.std_string(["cctbx.miller.fft_map"]))
def exercise(rotamer_manager, sin_cos_table,
             d_min = 1.0, resolution_factor = 0.1):
  # Run into a water clash if needed: water is considered as just a map peak.
  #
  # answer PDB
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
  pdb_inp.write_pdb_file(file_name = "answer.pdb")
  xrs_answer = pdb_inp.xray_structure_simple()
  # answer map
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_for_map)
  pdb_inp.write_pdb_file(file_name = "for_map.pdb")
  xrs_map = pdb_inp.xray_structure_simple()
  f_calc = xrs_map.structure_factors(d_min = d_min).f_calc()
  fft_map = f_calc.fft_map(resolution_factor=resolution_factor)
  fft_map.apply_sigma_scaling()
  target_map = fft_map.real_map_unpadded()
  mtz_dataset = f_calc.as_mtz_dataset(column_root_label = "FCmap")
  mtz_object = mtz_dataset.mtz_object()
  mtz_object.write(file_name = "answer.mtz")
  # poor
  mon_lib_srv = monomer_library.server.server()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv              = mon_lib_srv,
    ener_lib                 = monomer_library.server.ener_lib(),
    raw_records              = flex.std_string(pdb_poor.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xrs_poor = processed_pdb_file.xray_structure()
  sites_cart_poor = xrs_poor.sites_cart()
  pdb_hierarchy_poor.write_pdb_file(file_name = "poor.pdb")
  #
  grm = mmtbx.restraints.manager(
    geometry=processed_pdb_file.geometry_restraints_manager(show_energies=False),
    normalization = True)
  for i in [1,2]:
    print "-"*10
    result = mmtbx.refinement.real_space.fit_residues.run(
      pdb_hierarchy     = pdb_hierarchy_poor,
      crystal_symmetry  = xrs_poor.crystal_symmetry(),
      map_data          = target_map,
      do_all            = True,
      massage_map       = False,
      rotamer_manager   = rotamer_manager,
      sin_cos_table     = sin_cos_table,
      mon_lib_srv       = mon_lib_srv)
    pdb_hierarchy_poor = result.pdb_hierarchy
  #
  result.pdb_hierarchy.write_pdb_file(file_name = "refined.pdb",
    crystal_symmetry=xrs_poor.crystal_symmetry())
  dist = flex.max(flex.sqrt((xrs_answer.sites_cart() -
    result.pdb_hierarchy.atoms().extract_xyz()).dot()))
  assert dist < 0.75, dist # to make it work on marbles
Example #33
0
def exercise(d_min = 1.0, resolution_factor=0.2):
  # Fit HOH or DOD into density map
  #
  # answer model and map
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
  pdb_inp.write_pdb_file(file_name = "answer.pdb")
  xrs_answer = pdb_inp.xray_structure_simple()
  xrs_answer.switch_to_neutron_scattering_dictionary()
  f_calc_answer = xrs_answer.structure_factors(d_min = d_min).f_calc()
  fft_map = f_calc_answer.fft_map(resolution_factor=resolution_factor)
  fft_map.apply_volume_scaling()
  target_map = fft_map.real_map_unpadded()
  mtz_dataset = f_calc_answer.as_mtz_dataset(column_root_label = "FCmap")
  mtz_object = mtz_dataset.mtz_object()
  mtz_object.write(file_name = "answer.mtz")
  # poor model (DOD randomly shifted)
  mon_lib_srv = monomer_library.server.server()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv              = mon_lib_srv,
    ener_lib                 = monomer_library.server.ener_lib(),
    raw_records              = flex.std_string(pdb_poor.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xrs_poor = processed_pdb_file.xray_structure()
  xrs_poor.switch_to_neutron_scattering_dictionary()
  pdb_hierarchy_poor.write_pdb_file(file_name = "poor.pdb")
  # real-space refine DOD to fit target_map best
  mmtbx.refinement.real_space.fit_water.run(
    pdb_hierarchy = pdb_hierarchy_poor,
    target_map    = target_map,
    unit_cell     = xrs_poor.unit_cell(),
    real_space_gradients_delta = d_min*resolution_factor,
    log = sys.stdout)
  # best refined model
  pdb_hierarchy_poor.write_pdb_file(file_name = "refined.pdb")
  xrs_refined = pdb_hierarchy_poor.extract_xray_structure(
    crystal_symmetry = xrs_poor.crystal_symmetry())
  xrs_refined.switch_to_neutron_scattering_dictionary()
  # check results
  def r_factor(x,y):
    x = abs(x).data()
    y = abs(y).data()
    n = flex.sum(flex.abs(x-y))
    d = flex.sum(flex.abs(x+y))/2
    return n/d
  fc_poor = f_calc_answer.structure_factors_from_scatterers(
    xray_structure = xrs_poor).f_calc()
  fc_refined = f_calc_answer.structure_factors_from_scatterers(
    xray_structure = xrs_refined).f_calc()
  assert r_factor(f_calc_answer, fc_poor) > 0.45
  assert r_factor(f_calc_answer, fc_refined) < 0.08
def exercise(rotamer_manager, sin_cos_table, d_min=1.5, resolution_factor=0.1):
  # Partial (incomplete) residues. Just run to make sure it does not crash.
  # It will not fix incomplete residues.
  #
  # answer PDB
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
  pdb_inp.write_pdb_file(file_name = "answer.pdb")
  xrs_answer = pdb_inp.xray_structure_simple()
  # answer map
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_for_map)
  pdb_inp.write_pdb_file(file_name = "for_map.pdb")
  xrs_map = pdb_inp.xray_structure_simple()
  f_calc = xrs_map.structure_factors(d_min = d_min).f_calc()
  fft_map = f_calc.fft_map(resolution_factor=resolution_factor)
  fft_map.apply_sigma_scaling()
  target_map = fft_map.real_map_unpadded()
  mtz_dataset = f_calc.as_mtz_dataset(column_root_label = "FCmap")
  mtz_object = mtz_dataset.mtz_object()
  mtz_object.write(file_name = "answer.mtz")
  # poor
  mon_lib_srv = monomer_library.server.server()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv              = mon_lib_srv,
    ener_lib                 = monomer_library.server.ener_lib(),
    raw_records              = flex.std_string(pdb_poor.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xrs_poor = processed_pdb_file.xray_structure()
  sites_cart_poor = xrs_poor.sites_cart()
  pdb_hierarchy_poor.write_pdb_file(file_name = "poor.pdb")
  #
  target_map_object = group_args(
    data             = target_map,
    f_map_diff       = None,
    miller_array     = f_calc,
    crystal_gridding = fft_map)
  grm = mmtbx.restraints.manager(
    geometry=processed_pdb_file.geometry_restraints_manager(show_energies=False),
    normalization = True)
  sm = mmtbx.refinement.real_space.structure_monitor(
    pdb_hierarchy               = pdb_hierarchy_poor,
    xray_structure              = xrs_poor,
    target_map_object           = target_map_object,
    geometry_restraints_manager = grm.geometry)
  result = mmtbx.refinement.real_space.fit_residues.manager(
    structure_monitor = sm,
    rotamer_manager   = rotamer_manager,
    sin_cos_table     = sin_cos_table,
    mon_lib_srv       = mon_lib_srv)
  #
  sm.pdb_hierarchy.write_pdb_file(file_name = "refined.pdb")
Example #35
0
 def __init__(self,
              pdb_hierarchy,
              crystal_symmetry,
              rotamer_manager,
              sin_cos_table,
              mon_lib_srv,
              bselection=None,
              map_data=None,
              vdw_radii=None,
              do_all=False,
              backbone_sample=True,
              diff_map_data=None,
              massage_map=True,
              tune_up_only=False,
              log=None):
     adopt_init_args(self, locals())
     self.number_of_outliers = None
     if (self.log is None): self.log = sys.stdout
     self.sites_cart = self.pdb_hierarchy.atoms().extract_xyz()
     self.atom_names = flex.std_string(
         [i.strip() for i in self.pdb_hierarchy.atoms().extract_name()])
     self.special_position_settings = None
     self.special_position_indices = None
     if (self.crystal_symmetry is not None):
         self.special_position_settings = crystal.special_position_settings(
             crystal_symmetry=self.crystal_symmetry)
         self.special_position_indices = self.get_special_position_indices()
     # Even better would be to pass it here. Ideally just use model
     self.atom_selection_cache = self.pdb_hierarchy.atom_selection_cache()
     self.selection_water_as_set = set(self.atom_selection_cache.\
         selection(string = "water").iselection())
     if (self.massage_map and self.map_data is not None):
         self.target_map = self.prepare_target_map()
     else:
         self.target_map = map_data
     print >> self.log, \
       "outliers start: %d"%self.count_outliers()
     #
     if (not self.tune_up_only):
         self.loop(function=self.one_residue_iteration)
         assert approx_equal(self.sites_cart,
                             self.pdb_hierarchy.atoms().extract_xyz())
         print >> self.log, \
           "outliers after map fit: %d"%self.count_outliers()
     print >> self.log, "tune up"
     assert approx_equal(self.sites_cart,
                         self.pdb_hierarchy.atoms().extract_xyz())
     self.loop(function=self.one_residue_tune_up)
     print >> self.log, \
       "outliers final: %d"%self.count_outliers()
     assert approx_equal(self.sites_cart,
                         self.pdb_hierarchy.atoms().extract_xyz())
def exercise(rotamer_manager, sin_cos_table, d_min = 1.0,
             resolution_factor = 0.1):
  # Make sure it DOES NOT kicks into existing residue (chain Z).
  #
  # answer PDB
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_for_map)
  pdb_inp.write_pdb_file(file_name = "for_map.pdb")
  xrs_answer = pdb_inp.xray_structure_simple()
  # answer map
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
  xrs_map = pdb_inp.xray_structure_simple()
  f_calc = xrs_map.structure_factors(d_min = d_min).f_calc()
  fft_map = f_calc.fft_map(resolution_factor=resolution_factor)
  fft_map.apply_sigma_scaling()
  target_map = fft_map.real_map_unpadded()
  mtz_dataset = f_calc.as_mtz_dataset(column_root_label = "FCmap")
  mtz_object = mtz_dataset.mtz_object()
  mtz_object.write(file_name = "answer.mtz")
  # poor
  mon_lib_srv = monomer_library.server.server()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv              = mon_lib_srv,
    ener_lib                 = monomer_library.server.ener_lib(),
    raw_records              = flex.std_string(pdb_poor.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xrs_poor = processed_pdb_file.xray_structure()
  sites_cart_poor = xrs_poor.sites_cart()
  pdb_hierarchy_poor.write_pdb_file(file_name = "poor.pdb")
  #
  result = mmtbx.refinement.real_space.fit_residues.run(
    pdb_hierarchy     = pdb_hierarchy_poor,
    crystal_symmetry  = xrs_poor.crystal_symmetry(),
    map_data          = target_map,
    do_all            = True,
    rotamer_manager   = rotamer_manager,
    sin_cos_table     = sin_cos_table,
    mon_lib_srv       = mon_lib_srv)
  result.pdb_hierarchy.write_pdb_file(file_name = "refined.pdb")
  ###
  sel = result.pdb_hierarchy.atom_selection_cache().selection("not chain Z")
  result_hierarchy = result.pdb_hierarchy.select(sel)

  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
  pdb_inp.write_pdb_file(file_name = "answer.pdb")
  xrs_answer = pdb_inp.xray_structure_simple()
  dist = flex.max(flex.sqrt((xrs_answer.sites_cart() -
    result_hierarchy.atoms().extract_xyz()).dot()))
  print dist
  assert dist > 3.95, dist
def exercise(rotamer_manager, sin_cos_table, d_min=1.0, resolution_factor=0.1):
    # Make sure it kicks off existing water. Simple case: no alternatives.
    #
    # answer PDB
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_for_map)
    pdb_inp.write_pdb_file(file_name="for_map.pdb")
    xrs_answer = pdb_inp.xray_structure_simple()
    # answer map
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
    xrs_map = pdb_inp.xray_structure_simple()
    f_calc = xrs_map.structure_factors(d_min=d_min).f_calc()
    fft_map = f_calc.fft_map(resolution_factor=resolution_factor)
    fft_map.apply_sigma_scaling()
    target_map = fft_map.real_map_unpadded()
    mtz_dataset = f_calc.as_mtz_dataset(column_root_label="FCmap")
    mtz_object = mtz_dataset.mtz_object()
    mtz_object.write(file_name="answer.mtz")
    # poor
    mon_lib_srv = monomer_library.server.server()
    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=monomer_library.server.ener_lib(),
        raw_records=flex.std_string(pdb_poor.splitlines()),
        strict_conflict_handling=True,
        force_symmetry=True,
        log=None)
    pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    xrs_poor = processed_pdb_file.xray_structure()
    sites_cart_poor = xrs_poor.sites_cart()
    pdb_hierarchy_poor.write_pdb_file(file_name="poor.pdb")
    #
    result = mmtbx.refinement.real_space.fit_residues.run(
        pdb_hierarchy=pdb_hierarchy_poor,
        crystal_symmetry=xrs_poor.crystal_symmetry(),
        map_data=target_map,
        do_all=True,
        rotamer_manager=rotamer_manager,
        sin_cos_table=sin_cos_table,
        mon_lib_srv=mon_lib_srv)
    result.pdb_hierarchy.write_pdb_file(file_name="refined.pdb")
    ###
    sel = result.pdb_hierarchy.atom_selection_cache().selection("not water")
    result_hierarchy = result.pdb_hierarchy.select(sel)

    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
    pdb_inp.write_pdb_file(file_name="answer.pdb")
    xrs_answer = pdb_inp.xray_structure_simple()
    dist = flex.max(
        flex.sqrt((xrs_answer.sites_cart() -
                   result_hierarchy.atoms().extract_xyz()).dot()))
    print dist
    assert dist < 0.4, dist
Example #38
0
 def __init__(self, cif_block, strict=False):
     # The order of priority for determining space group is:
     #   sym_ops, hall symbol, H-M symbol, space group number
     self.cif_block = cif_block
     sym_ops = self.get_cif_item('_space_group_symop_operation_xyz')
     sym_op_ids = self.get_cif_item('_space_group_symop_id')
     space_group = None
     if sym_ops is not None:
         if isinstance(sym_ops, basestring):
             sym_ops = flex.std_string([sym_ops])
         if sym_op_ids is not None:
             if isinstance(sym_op_ids, basestring):
                 sym_op_ids = flex.std_string([sym_op_ids])
             assert len(sym_op_ids) == len(sym_ops)
         self.sym_ops = {}
         space_group = sgtbx.space_group()
         if isinstance(sym_ops, basestring): sym_ops = [sym_ops]
         for i, op in enumerate(sym_ops):
             try:
                 s = sgtbx.rt_mx(op)
             except RuntimeError, e:
                 str_e = str(e)
                 if "Parse error: " in str_e:
                     raise CifBuilderError(
                         "Error interpreting symmetry operator: %s" %
                         (str_e.split("Parse error: ")[-1]))
                 else:
                     raise
             if sym_op_ids is None:
                 sym_op_id = i + 1
             else:
                 try:
                     sym_op_id = int(sym_op_ids[i])
                 except ValueError, e:
                     raise CifBuilderError(
                         "Error interpreting symmetry operator id: %s" %
                         (str(e)))
             self.sym_ops[sym_op_id] = s
             space_group.expand_smx(s)
def ccp4_map(cg, file_name, mc=None, map_data=None):
  assert [mc, map_data].count(None)==1
  if(map_data is None):
    map_data = get_map(mc=mc, cg=cg)
  from iotbx import ccp4_map
  ccp4_map.write_ccp4_map(
      file_name=file_name,
      unit_cell=cg.unit_cell(),
      space_group=cg.space_group(),
      #gridding_first=(0,0,0),# This causes a bug (map gets shifted)
      #gridding_last=n_real,  # This causes a bug (map gets shifted)
      map_data=map_data,
      labels=flex.std_string([""]))
Example #40
0
def ccp4_map(cg, file_name, mc=None, map_data=None):
    assert [mc, map_data].count(None) == 1
    if (map_data is None):
        map_data = get_map(mc=mc, cg=cg)
    from iotbx import mrcfile
    mrcfile.write_ccp4_map(
        file_name=file_name,
        unit_cell=cg.unit_cell(),
        space_group=cg.space_group(),
        #gridding_first=(0,0,0),# This causes a bug (map gets shifted)
        #gridding_last=n_real,  # This causes a bug (map gets shifted)
        map_data=map_data,
        labels=flex.std_string([""]))
 def debug_write_ccp4_map(self, map_data, file_name):
   from iotbx import ccp4_map
   gridding_first = (0,0,0)
   gridding_last = map_data.all()
   labels = ["cctbx.miller.fft_map"]
   ccp4_map.write_ccp4_map(
     file_name=file_name,
     unit_cell=self.fft_cell,
     space_group=sgtbx.space_group("P1"),
     gridding_first=gridding_first,
     gridding_last=gridding_last,
     map_data=map_data,
     labels=flex.std_string(labels))
Example #42
0
def run(args, command_name="phenix.tls"):
    if (len(args) == 0): args = ["--help"]
    usage_fmt = "%s pdb_file [parameters: file or command line string]"
    des_fmt = "Example: %s model.pdb fit_tls_to.selection='%s' fit_tls_to.selection='%s'"
    command_line = (iotbx_option_parser(
        usage=usage_fmt % command_name, description=banner).option(
            "--show_defaults",
            action="store_true",
            help="Do not output to the screen (except errors).").option(
                "--silent",
                action="store_true",
                help="Suppress output to the screen.")).process(args=args)
    #
    log = sys.stdout
    if (not command_line.options.silent):
        utils.print_header("TLS tools", out=log)
    if (command_line.options.show_defaults):
        master_params.show(out=log)
        print >> log
        return
    if (not command_line.options.silent):
        print >> log, banner
    #
    processed_args = utils.process_command_line_args(
        args=command_line.args, master_params=master_params, log=log)
    reflection_files = processed_args.reflection_files
    if (processed_args.crystal_symmetry is None):
        raise Sorry("No crystal symmetry found.")
    if (len(processed_args.pdb_file_names) == 0):
        raise Sorry("No PDB file found.")
    params = processed_args.params
    if (not command_line.options.silent):
        utils.print_header("Input parameters", out=log)
        params.show(out=log)
    params = params.extract()
    #
    if (processed_args.crystal_symmetry.unit_cell() is None
            or processed_args.crystal_symmetry.space_group() is None):
        raise Sorry("No CRYST1 record found.")

    pdb_combined = iotbx.pdb.combine_unique_pdb_files(
        file_names=processed_args.pdb_file_names)
    pdb_combined.report_non_unique(out=log)
    if (len(pdb_combined.unique_file_names) == 0):
        raise Sorry("No coordinate file given.")
    raw_records = pdb_combined.raw_records
    try:
        pdb_inp = iotbx.pdb.input(source_info=None,
                                  lines=flex.std_string(raw_records))
    except ValueError, e:
        raise Sorry("Model format (PDB or mmCIF) error:\n%s" % str(e))
def exercise(pdb_poor_str,
             rotamer_manager,
             sin_cos_table,
             i_pdb,
             d_min=1.0,
             resolution_factor=0.1):
    # Fit one residue. There is a huge heavy atom nearby that overlaps with a
    # plausible rotamer.
    #
    # answer
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
    pdb_inp.write_pdb_file(file_name="answer_%s.pdb" % str(i_pdb))
    xrs_answer = pdb_inp.xray_structure_simple()
    f_calc = xrs_answer.structure_factors(d_min=d_min).f_calc()
    fft_map = f_calc.fft_map(resolution_factor=resolution_factor)
    fft_map.apply_sigma_scaling()
    target_map = fft_map.real_map_unpadded()
    mtz_dataset = f_calc.as_mtz_dataset(column_root_label="FCmap")
    mtz_object = mtz_dataset.mtz_object()
    mtz_object.write(file_name="answer_%s.mtz" % str(i_pdb))
    # poor
    mon_lib_srv = monomer_library.server.server()
    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=monomer_library.server.ener_lib(),
        raw_records=flex.std_string(pdb_poor_str.splitlines()),
        strict_conflict_handling=True,
        force_symmetry=True,
        log=None)
    pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    xrs_poor = processed_pdb_file.xray_structure()
    sites_cart_poor = xrs_poor.sites_cart()
    pdb_hierarchy_poor.write_pdb_file(file_name="poor_%s.pdb" % str(i_pdb))
    #
    result = mmtbx.refinement.real_space.fit_residues.run(
        pdb_hierarchy=pdb_hierarchy_poor,
        crystal_symmetry=xrs_poor.crystal_symmetry(),
        map_data=target_map,
        do_all=True,
        massage_map=True,
        rotamer_manager=rotamer_manager,
        sin_cos_table=sin_cos_table,
        mon_lib_srv=mon_lib_srv)
    result.pdb_hierarchy.write_pdb_file(file_name="refined_%s.pdb" %
                                        str(i_pdb))
    dist = flex.max(
        flex.sqrt((xrs_answer.sites_cart() -
                   result.pdb_hierarchy.atoms().extract_xyz()).dot()))
    print dist
    if (i_pdb == 2): assert dist < 1.e-6, dist
    else: assert dist < 0.61, dist
Example #44
0
def exercise_01():
    pdb_inp = iotbx.pdb.input(source_info=None, lines=m5_str)
    ph = pdb_inp.construct_hierarchy()
    xrs_answer = pdb_inp.xray_structure_simple()
    xrs_answer.switch_to_neutron_scattering_dictionary()
    ph.write_pdb_file(file_name="answer.pdb")
    f_calc = xrs_answer.structure_factors(d_min=1).f_calc()
    fft_map = f_calc.fft_map(resolution_factor=0.1)
    fft_map.apply_sigma_scaling()
    map_data = fft_map.real_map_unpadded()
    #
    mon_lib_srv = monomer_library.server.server()
    ener_lib = monomer_library.server.ener_lib()
    ppf = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        raw_records=flex.std_string(m5_str_HD_rotated.splitlines()),
        force_symmetry=True)
    geometry = ppf.geometry_restraints_manager(show_energies=False,
                                               plain_pairs_radius=5.0)
    restraints_manager = mmtbx.restraints.manager(geometry=geometry,
                                                  normalization=False)
    xrs = ppf.all_chain_proxies.pdb_inp.xray_structure_simple()
    ph = ppf.all_chain_proxies.pdb_hierarchy
    ph.write_pdb_file(file_name="poor.pdb")
    xrs.switch_to_neutron_scattering_dictionary()
    f_calc_poor = f_calc.structure_factors_from_scatterers(
        xray_structure=xrs).f_calc()
    #
    rotatable_h_selection = hydrogens.rotatable(
        pdb_hierarchy=ph,
        mon_lib_srv=mon_lib_srv,
        restraints_manager=restraints_manager,
        log=None)
    hydrogens.fit_rotatable(pdb_hierarchy=ph,
                            xray_structure=xrs,
                            map_data=map_data,
                            rotatable_h_selection=rotatable_h_selection)
    ph.write_pdb_file(file_name="result.pdb")
    #
    f_calc_fixed = f_calc.structure_factors_from_scatterers(
        xray_structure=xrs).f_calc()

    def r_factor(x, y):
        n = flex.sum(flex.abs(abs(x).data() - abs(y).data()))
        d = flex.sum(flex.abs(abs(x).data() + abs(y).data())) / 2
        return n / d

    assert r_factor(f_calc, f_calc_poor) > 0.2
    assert r_factor(f_calc, f_calc_fixed) < 0.015
Example #45
0
 def __init__(self, cif_block, strict=False):
   # The order of priority for determining space group is:
   #   sym_ops, hall symbol, H-M symbol, space group number
   self.cif_block = cif_block
   sym_ops = self.get_cif_item('_space_group_symop_operation_xyz')
   sym_op_ids = self.get_cif_item('_space_group_symop_id')
   space_group = None
   if sym_ops is not None:
     if isinstance(sym_ops, basestring):
       sym_ops = flex.std_string([sym_ops])
     if sym_op_ids is not None:
       if isinstance(sym_op_ids, basestring):
         sym_op_ids = flex.std_string([sym_op_ids])
       assert len(sym_op_ids) == len(sym_ops)
     self.sym_ops = {}
     space_group = sgtbx.space_group()
     if isinstance(sym_ops, basestring): sym_ops = [sym_ops]
     for i, op in enumerate(sym_ops):
       try:
         s = sgtbx.rt_mx(op)
       except RuntimeError, e:
         str_e = str(e)
         if "Parse error: " in str_e:
           raise CifBuilderError("Error interpreting symmetry operator: %s" %(
             str_e.split("Parse error: ")[-1]))
         else:
           raise
       if sym_op_ids is None:
         sym_op_id = i+1
       else:
         try:
           sym_op_id = int(sym_op_ids[i])
         except ValueError, e:
           raise CifBuilderError("Error interpreting symmetry operator id: %s" %(
             str(e)))
       self.sym_ops[sym_op_id] = s
       space_group.expand_smx(s)
def exercise(pdb_poor_str, rotamer_manager, sin_cos_table, i_pdb, d_min = 1.0,
             resolution_factor = 0.1):
  # Fit one residue. There is a huge heavy atom nearby that overlaps with a
  # plausible rotamer.
  # Show importance of map truncaiton.
  #
  # answer
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
  pdb_inp.write_pdb_file(file_name = "answer_%s.pdb"%str(i_pdb))
  xrs_answer = pdb_inp.xray_structure_simple()
  f_calc = xrs_answer.structure_factors(d_min = d_min).f_calc()
  fft_map = f_calc.fft_map(resolution_factor=resolution_factor)
  fft_map.apply_sigma_scaling()
  target_map = fft_map.real_map_unpadded()
  mtz_dataset = f_calc.as_mtz_dataset(column_root_label = "FCmap")
  mtz_object = mtz_dataset.mtz_object()
  mtz_object.write(file_name = "answer_%s.mtz"%str(i_pdb))
  pdb_hierarchy_answer = pdb_inp.construct_hierarchy()
  matching_selection = pdb_hierarchy_answer.atom_selection_cache().selection(
    string = "not element U")
  # Truncate the map
  target_map = target_map.set_selected(target_map > 2, 2)
  # poor
  mon_lib_srv = monomer_library.server.server()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv              = mon_lib_srv,
    ener_lib                 = monomer_library.server.ener_lib(),
    raw_records              = flex.std_string(pdb_poor_str.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xrs_poor = processed_pdb_file.xray_structure()
  sites_cart_poor = xrs_poor.sites_cart()
  pdb_hierarchy_poor.write_pdb_file(file_name = "poor_%s.pdb"%str(i_pdb))
  #
  result = mmtbx.refinement.real_space.fit_residues.run(
    pdb_hierarchy     = pdb_hierarchy_poor,
    crystal_symmetry  = xrs_poor.crystal_symmetry(),
    map_data          = target_map,
    do_all            = True,
    massage_map       = False,
    rotamer_manager   = rotamer_manager,
    sin_cos_table     = sin_cos_table,
    mon_lib_srv       = mon_lib_srv)
  result.pdb_hierarchy.write_pdb_file(file_name = "refined_%s.pdb"%str(i_pdb))
  dist = flex.max(flex.sqrt((xrs_answer.sites_cart().select(matching_selection) -
    result.pdb_hierarchy.atoms().extract_xyz()).dot()))
  assert dist < 0.25, dist
Example #47
0
def exercise_miller_arrays_as_cif_block():
    from iotbx.cif import reader
    cif_model = reader(input_string=cif_miller_array,
                       builder=cif.builders.cif_model_builder()).model()
    ma_builder = cif.builders.miller_array_builder(cif_model['global'])
    ma1 = ma_builder.arrays()['_refln_F_squared_meas']
    mas_as_cif_block = cif.miller_arrays_as_cif_block(ma1,
                                                      array_type='meas',
                                                      format="corecif")
    mas_as_cif_block.add_miller_array(
        ma1.array(data=flex.complex_double([1 - 1j] * ma1.size())),
        array_type='calc')
    mas_as_cif_block.add_miller_array(
        ma1.array(data=flex.complex_double([1 - 2j] * ma1.size())),
        column_names=['_refln_A_calc', '_refln_B_calc'])
    for key in ('_refln_F_squared_meas', '_refln_F_squared_sigma',
                '_refln_F_calc', '_refln_phase_calc', '_refln_A_calc',
                '_refln_A_calc'):
        assert key in mas_as_cif_block.cif_block.keys(), key
    #
    mas_as_cif_block = cif.miller_arrays_as_cif_block(ma1,
                                                      array_type='meas',
                                                      format="mmcif")
    mas_as_cif_block.add_miller_array(
        ma1.array(data=flex.complex_double([1 - 1j] * ma1.size())),
        array_type='calc')
    for key in ('_refln.F_squared_meas', '_refln.F_squared_sigma',
                '_refln.F_calc', '_refln.phase_calc',
                '_space_group_symop.operation_xyz', '_cell.length_a',
                '_refln.index_h'):
        assert key in mas_as_cif_block.cif_block.keys()
    #
    mas_as_cif_block = cif.miller_arrays_as_cif_block(
        ma1,
        column_names=[
            '_diffrn_refln_intensity_net', '_diffrn_refln_intensity_sigma'
        ],
        miller_index_prefix='_diffrn_refln')
    mas_as_cif_block.add_miller_array(
        ma1.array(data=flex.std_string(ma1.size(), 'om')),
        column_name='_diffrn_refln_intensity_u')
    for key in ('_diffrn_refln_intensity_net', '_diffrn_refln_intensity_sigma',
                '_diffrn_refln_intensity_u'):
        assert key in mas_as_cif_block.cif_block.keys()
    #
    try:
        reader(input_string=cif_global)
    except CifParserError, e:
        pass
def get_pdb_inputs(pdb_str):
    processed_pdb_file = pdb_interpretation.process(
        mon_lib_srv=server.server(),
        ener_lib=server.ener_lib(),
        raw_records=flex.std_string(pdb_str.splitlines()),
        strict_conflict_handling=True,
        force_symmetry=True,
        log=None)
    xrs = processed_pdb_file.xray_structure(show_summary=False)
    geometry_restraints_manager = geometry_minimization.\
        get_geometry_restraints_manager(processed_pdb_file, xrs)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    return group_args(ph=pdb_hierarchy,
                      grm=geometry_restraints_manager,
                      xrs=xrs)
def exercise(rotamer_manager, sin_cos_table, d_min = 1.0,
             resolution_factor = 0.1):
  # Fit one residue having weak side chain density. There is a blob nearby that
  # overlaps with a plausible rotamer.
  # Making B of HOH smaller will break the test, indicaing potential problem.
  #
  # answer PDB
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_answer)
  pdb_inp.write_pdb_file(file_name = "answer.pdb")
  xrs_answer = pdb_inp.xray_structure_simple()
  # answer map
  pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_poor_for_map)
  pdb_inp.write_pdb_file(file_name="for_map.pdb")
  xrs_map = pdb_inp.xray_structure_simple()
  f_calc = xrs_map.structure_factors(d_min = d_min).f_calc()
  fft_map = f_calc.fft_map(resolution_factor=resolution_factor)
  fft_map.apply_sigma_scaling()
  target_map = fft_map.real_map_unpadded()
  mtz_dataset = f_calc.as_mtz_dataset(column_root_label = "FCmap")
  mtz_object = mtz_dataset.mtz_object()
  mtz_object.write(file_name = "answer.mtz")
  # poor
  mon_lib_srv = monomer_library.server.server()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv              = mon_lib_srv,
    ener_lib                 = monomer_library.server.ener_lib(),
    raw_records              = flex.std_string(pdb_poor.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  pdb_hierarchy_poor = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xrs_poor = processed_pdb_file.xray_structure()
  sites_cart_poor = xrs_poor.sites_cart()
  pdb_hierarchy_poor.write_pdb_file(file_name = "poor.pdb")
  #
  result = mmtbx.refinement.real_space.fit_residues.run(
    pdb_hierarchy     = pdb_hierarchy_poor,
    crystal_symmetry  = xrs_poor.crystal_symmetry(),
    map_data          = target_map,
    do_all            = True,
    rotamer_manager   = rotamer_manager,
    sin_cos_table     = sin_cos_table,
    mon_lib_srv       = mon_lib_srv)
  result.pdb_hierarchy.write_pdb_file(file_name = "refined.pdb")
  dist = flex.max(flex.sqrt((xrs_answer.sites_cart() -
    result.pdb_hierarchy.atoms().extract_xyz()).dot()))
  #assert dist < 0.24, dist
  print "Test disabled since current protocol cannot do what test asks for."
Example #50
0
 def get_loop_or_row(self, loop_name, default=None):
   loop_ = self.get_loop(loop_name, None)
   if loop_ is None:
     ln = loop_name
     if ln[-1] != '.':
       ln += '.'
       found_keys = {}
     for key, value in self.iteritems():
       if key.startswith(ln):
         found_keys[key] = flex.std_string([value])
     # constructing the loop
     if len(found_keys) > 0:
       loop_ = loop(data=found_keys)
   if loop_ is None:
     return default
   return loop_
def get_pdb_inputs(pdb_str):
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv              = server.server(),
    ener_lib                 = server.ener_lib(),
    raw_records              = flex.std_string(pdb_str.splitlines()),
    strict_conflict_handling = True,
    force_symmetry           = True,
    log                      = None)
  xrs = processed_pdb_file.xray_structure(show_summary = False)
  geometry_restraints_manager = geometry_minimization.\
      get_geometry_restraints_manager(processed_pdb_file, xrs)
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  return group_args(
    ph  = pdb_hierarchy,
    grm = geometry_restraints_manager,
    xrs = xrs)
Example #52
0
def exercise_line_info_exceptions():
  pdb.pdb_input(source_info=None, lines=flex.std_string(["ATOM"]))
  #
  try:
    pdb.pdb_input(
      source_info="some.pdb",
      lines=flex.split_lines("""\
HETATM    9 2H3  MPR B   5      16.388   0.289   6.613  1.00  0.08
ANISOU    9 2H3  MPR B   5      8+8    848    848      0      0      0
"""))
  except ValueError, e:
    assert not show_diff(str(e), """\
some.pdb, line 2:
  ANISOU    9 2H3  MPR B   5      8+8    848    848      0      0      0
  ---------------------------------^
  unexpected plus sign.""")
Example #53
0
def exercise_01():
  pdb_inp = iotbx.pdb.input(source_info=None, lines=m5_str)
  ph = pdb_inp.construct_hierarchy()
  xrs_answer = pdb_inp.xray_structure_simple()
  xrs_answer.switch_to_neutron_scattering_dictionary()
  ph.write_pdb_file(file_name = "answer.pdb")
  f_calc = xrs_answer.structure_factors(d_min=1).f_calc()
  fft_map = f_calc.fft_map(resolution_factor=0.1)
  fft_map.apply_sigma_scaling()
  map_data = fft_map.real_map_unpadded()
  #
  mon_lib_srv = monomer_library.server.server()
  ener_lib = monomer_library.server.ener_lib()
  ppf = monomer_library.pdb_interpretation.process(
    mon_lib_srv    = mon_lib_srv,
    ener_lib       = ener_lib,
    raw_records    = flex.std_string(m5_str_HD_rotated.splitlines()),
    force_symmetry = True)
  geometry = ppf.geometry_restraints_manager(
    show_energies      = False,
    plain_pairs_radius = 5.0)
  restraints_manager = mmtbx.restraints.manager(
    geometry = geometry, normalization = False)
  xrs = ppf.all_chain_proxies.pdb_inp.xray_structure_simple()
  ph = ppf.all_chain_proxies.pdb_hierarchy
  ph.write_pdb_file(file_name = "poor.pdb")
  xrs.switch_to_neutron_scattering_dictionary()
  f_calc_poor = f_calc.structure_factors_from_scatterers(
    xray_structure = xrs).f_calc()
  #
  rotatable_h_selection = hydrogens.rotatable(
    pdb_hierarchy      = ph,
    mon_lib_srv        = mon_lib_srv,
    restraints_manager = restraints_manager,
    log                = None)
  hydrogens.fit_rotatable(pdb_hierarchy=ph, xray_structure=xrs,
    map_data=map_data,rotatable_h_selection=rotatable_h_selection)
  ph.write_pdb_file(file_name = "result.pdb")
  #
  f_calc_fixed = f_calc.structure_factors_from_scatterers(
    xray_structure = xrs).f_calc()
  def r_factor(x,y):
    n = flex.sum( flex.abs( abs(x).data() - abs(y).data() ) )
    d = flex.sum( flex.abs( abs(x).data() + abs(y).data() ) )/2
    return n/d
  assert r_factor(f_calc, f_calc_poor) > 0.2
  assert r_factor(f_calc, f_calc_fixed) < 0.015
Example #54
0
def exercise_02(debug=False):
  mon_lib_srv = monomer_library.server.server()
  ener_lib = monomer_library.server.ener_lib()
  ppf = monomer_library.pdb_interpretation.process(
    mon_lib_srv    = mon_lib_srv,
    ener_lib       = ener_lib,
    raw_records    = flex.std_string(exercise_02_str.splitlines()),
    force_symmetry = True)
  geometry = ppf.geometry_restraints_manager(
    show_energies      = False,
    plain_pairs_radius = 5.0)
  restraints_manager = mmtbx.restraints.manager(
    geometry = geometry, normalization = False)
  ph = ppf.all_chain_proxies.pdb_hierarchy
  sel = hydrogens.rotatable(pdb_hierarchy=ph, mon_lib_srv=mon_lib_srv,
    restraints_manager = restraints_manager, log = None)
  n_rot_h = hydrogens.count_rotatable(sel)
  assert n_rot_h == 43, n_rot_h