def generate_map_coefficients(
        model=None,  # Required model
        output_map_coeffs_file_name=None,
        d_min=3,
        scattering_table='electron',
        log=sys.stdout):
    '''
    Convenience function to create map coefficients from a model.

    This function typically accessed and tested through map_model_manager

    Summary:  Supply model.manager object or parameters for generate_model,
    high_resolution limit of d_min and optional scattering_table ("electron"
    for cryo-EM, "n_gaussian" for x-ray) and optional
    output_map_coeffs_file_name.

    Writes map coefficients and returns miller_array object
    containing the map coefficients

    Parameters:
    -----------

      model (model.manager object, None):    model to use
      output_map_coeffs_file_name (string, None): output model file name
      d_min (float, 3):   High-resolution limit for map coeffs (A)
      scattering_table (choice, 'electron'): choice of scattering table
           All choices: wk1995 it1992 n_gaussian neutron electron

  '''

    assert model is not None

    # get map coefficients
    from mmtbx.utils import fmodel_from_xray_structure
    import iotbx.phil
    from mmtbx.command_line.fmodel import master_phil
    fmodel_params = master_phil.extract()

    assert model.crystal_symmetry(
    ) is not None  # Need crystal_symmetry in model

    xrs = model.get_xray_structure()

    fmodel_params.high_resolution = float(d_min)
    fmodel_params.scattering_table = scattering_table

    fmodel = fmodel_from_xray_structure(xray_structure=xrs,
                                        params=fmodel_params,
                                        out=log)
    f_model = fmodel.f_model
    if output_map_coeffs_file_name:
        f_model.as_mtz_dataset(column_root_label='FWT').mtz_object().write(
            file_name=output_map_coeffs_file_name)
        print("Writing map coefficients to resolution of %s A to %s" %
              (d_min, output_map_coeffs_file_name),
              file=log)
    else:
        print("Generated map coefficients to resolution of %s A " % (d_min),
              file=log)
    return f_model
Example #2
0
def generate_map_coefficients(model=None,
                              output_map_coeffs_file_name=None,
                              high_resolution=3,
                              scattering_table='electron',
                              log=sys.stdout,
                              **pass_through_kw):
    '''
    generate_map_coefficients  Convenience function to create
    map coefficients from a model.  Supply model.manager object,
    high_resolution limit and optional scattering_table ("electron"
    for cryo-EM, "n_gaussian" for x-ray) and optional
    output_map_coeffs_file_name.

    Writes map coefficients and returns miller_array object
    containing the map
  '''

    if not model:
        model = generate_model(log=log, **pass_through_kw)

    # get map coefficients
    from mmtbx.utils import fmodel_from_xray_structure
    import iotbx.phil
    from mmtbx.command_line.fmodel import master_phil
    fmodel_params = master_phil.extract()

    xrs = model.get_xray_structure()

    fmodel_params.high_resolution = float(high_resolution)
    fmodel_params.scattering_table = scattering_table

    fmodel = fmodel_from_xray_structure(xray_structure=xrs,
                                        params=fmodel_params,
                                        out=log)
    f_model = fmodel.f_model
    if output_map_coeffs_file_name:
        f_model.as_mtz_dataset(column_root_label='FWT').mtz_object().write(
            file_name=output_map_coeffs_file_name)
        print("Writing map coefficients to resolution of %s A to %s" %
              (high_resolution, output_map_coeffs_file_name),
              file=log)
    else:
        print("Generated map coefficients to resolution of %s A " %
              (high_resolution),
              file=log)
    return f_model