示例#1
0
def get_inputs(args, log, master_params):
    """
  Eventually, this will be centralized.
  """
    cmdline = process_command_line_with_files(args=args,
                                              master_phil=master_params,
                                              pdb_file_def='model_file_name')
    params = cmdline.work.extract()
    # Model
    file_names = params.model_file_name
    pdb_combined = combine_unique_pdb_files(file_names=file_names)
    pdb_inp = iotbx.pdb.input(source_info=None,
                              lines=flex.std_string(pdb_combined.raw_records),
                              raise_sorry_if_format_error=True)
    # Crystal symmetry
    fake_crystal_symmetry = False
    crystal_symmetry = pdb_inp.crystal_symmetry()
    if (crystal_symmetry is None or crystal_symmetry.is_empty()
            or crystal_symmetry.is_nonsence()):
        fake_crystal_symmetry = True
        from cctbx import uctbx
        crystal_symmetry = \
          uctbx.non_crystallographic_unit_cell_with_the_sites_in_its_center(
            sites_cart=pdb_inp.atoms().extract_xyz(),
            buffer_layer=5).crystal_symmetry()
    #
    model = mmtbx.model.manager(model_input=pdb_inp,
                                crystal_symmetry=crystal_symmetry)
    #
    return group_args(params=params,
                      pdb_file_names=file_names,
                      model=model,
                      fake_crystal_symmetry=fake_crystal_symmetry)
def run(args, log = sys.stdout):
  if(len(args)==0):
    print >> log, legend
    defaults(log=log)
    return
  #
  parsed = defaults(log=log)
  processed_args = mmtbx.utils.process_command_line_args(args = args,
    log = sys.stdout, master_params = parsed)
  params = processed_args.params.extract()
  unit_cell = processed_args.crystal_symmetry.unit_cell()
  reflection_files = processed_args.reflection_files
  #
  atoms_with_labels = None
  if(len(processed_args.pdb_file_names)==1):
    pdb_combined = combine_unique_pdb_files(
      file_names=processed_args.pdb_file_names)
    pdb_combined.report_non_unique()
    pdb_inp = iotbx.pdb.input(source_info = None,
      lines = flex.std_string(pdb_combined.raw_records))
    atoms_with_labels = pdb_inp.atoms_with_labels()
  if(len(params.point)==0 and atoms_with_labels is None):
    raise Sorry("No points given to compute map value at.")

  if(len(reflection_files) == 0 and processed_args.ccp4_map is None):
    raise Sorry("No reflection or map files found.")

  if(len(reflection_files) > 1):
    raise Sorry("More than one reflection file found.")
  crystal_symmetry = processed_args.crystal_symmetry
  if(crystal_symmetry is None):
    raise Sorry("No crystal symmetry found.")
  if(len(reflection_files) != 0):
    map_3d = map_from_reflection_file(reflection_files=reflection_files, params=params)
  else:
    map_3d = processed_args.ccp4_map.data.as_double()
  print "Map values at specified points:"
  for point in params.point:
    point_frac = unit_cell.fractionalize(point)
    point_formatted = ",".join([str("%10.3f"%p).strip() for p in point])
    point_frac_formatted = \
      ",".join([str("%10.3f"%p).strip() for p in point_frac])
    map_value = str(
      "%10.3f"%map_3d.eight_point_interpolation(point_frac)).strip()
    print "  Input point: (%s) Fractionalized: (%s) Map value: %s"%(
      point_formatted, point_frac_formatted, map_value)
  #
  if(atoms_with_labels is not None):
    for point in atoms_with_labels:
      point_frac = processed_args.crystal_symmetry.unit_cell().fractionalize(point.xyz)
      point_formatted = ",".join([str("%8.3f"%p) for p in point.xyz])
      map_value = str(
        "%10.3f"%map_3d.eight_point_interpolation(point_frac)).strip()
      print point.quote(), "Point: %s Map value: %s"%(point_formatted,map_value)
  #
  print
  print "All done."
示例#3
0
def run(args, log = sys.stdout):
  if(len(args)==0):
    print(legend, file=log)
    defaults(log=log)
    return
  #
  parsed = defaults(log=log)
  processed_args = mmtbx.utils.process_command_line_args(args = args,
    log = sys.stdout, master_params = parsed)
  params = processed_args.params.extract()
  unit_cell = processed_args.crystal_symmetry.unit_cell()
  reflection_files = processed_args.reflection_files
  #
  atoms_with_labels = None
  if(len(processed_args.pdb_file_names)==1):
    pdb_combined = combine_unique_pdb_files(
      file_names=processed_args.pdb_file_names)
    pdb_combined.report_non_unique()
    pdb_inp = iotbx.pdb.input(source_info = None,
      lines = flex.std_string(pdb_combined.raw_records))
    atoms_with_labels = pdb_inp.atoms_with_labels()
  if(len(params.point)==0 and atoms_with_labels is None):
    raise Sorry("No points given to compute map value at.")

  if(len(reflection_files) == 0 and processed_args.ccp4_map is None):
    raise Sorry("No reflection or map files found.")

  if(len(reflection_files) > 1):
    raise Sorry("More than one reflection file found.")
  crystal_symmetry = processed_args.crystal_symmetry
  if(crystal_symmetry is None):
    raise Sorry("No crystal symmetry found.")
  if(len(reflection_files) != 0):
    map_3d = map_from_reflection_file(reflection_files=reflection_files, params=params)
  else:
    map_3d = processed_args.ccp4_map.map_data()
  print("Map values at specified points:")
  for point in params.point:
    point_frac = unit_cell.fractionalize(point)
    point_formatted = ",".join([str("%10.3f"%p).strip() for p in point])
    point_frac_formatted = \
      ",".join([str("%10.3f"%p).strip() for p in point_frac])
    map_value = str(
      "%10.3f"%map_3d.eight_point_interpolation(point_frac)).strip()
    print("  Input point: (%s) Fractionalized: (%s) Map value: %s"%(
      point_formatted, point_frac_formatted, map_value))
  #
  if(atoms_with_labels is not None):
    for point in atoms_with_labels:
      point_frac = processed_args.crystal_symmetry.unit_cell().fractionalize(point.xyz)
      point_formatted = ",".join([str("%8.3f"%p) for p in point.xyz])
      map_value = str(
        "%10.3f"%map_3d.eight_point_interpolation(point_frac)).strip()
      print(point.quote(), "Point: %s Map value: %s"%(point_formatted,map_value))
  #
  print()
  print("All done.")
示例#4
0
    def process_inputs(self, prefix):
        broadcast(m=prefix, log=self.log)
        self.pdb_file_names = list(self.inputs.pdb_file_names)
        if (self.params.file_name is not None):
            self.pdb_file_names.append(self.params.file_name)

        #=================================================
        cs = self.inputs.crystal_symmetry
        is_non_crystallographic_unit_cell = False
        import iotbx.pdb
        pdb_combined = combine_unique_pdb_files(file_names=self.pdb_file_names)
        pdb_inp = iotbx.pdb.input(lines=pdb_combined.raw_records,
                                  source_info=None)
        if (cs is None):
            cs = pdb_inp.crystal_symmetry()
        if (cs is None):
            is_non_crystallographic_unit_cell = True
            box = uctbx.non_crystallographic_unit_cell_with_the_sites_in_its_center(
                sites_cart=pdb_inp.atoms().extract_xyz(), buffer_layer=10)
            cs = box.crystal_symmetry()
        cif_objects = list(self.inputs.cif_objects)
        if (len(self.params.restraints) > 0):
            import iotbx.cif
            for file_name in self.params.restraints:
                cif_object = iotbx.cif.reader(file_path=file_name,
                                              strict=False).model()
                cif_objects.append((file_name, cif_object))
        if (self.params.restraints_directory is not None):
            restraint_files = os.listdir(self.params.restraints_directory)
            for file_name in restraint_files:
                if (file_name.endswith(".cif")):
                    full_path = os.path.join(self.params.restraints_directory,
                                             file_name)
                    cif_object = iotbx.cif.reader(file_path=full_path,
                                                  strict=False).model()
                    cif_objects.append((full_path, cif_object))
        self.model = mmtbx.model.manager(
            model_input=pdb_inp,
            crystal_symmetry=cs,
            restraint_objects=cif_objects,
            stop_for_unknowns=self.params.stop_for_unknowns,
            log=self.log)
        self.model.process(pdb_interpretation_params=self.params,
                           make_restraints=True)
        self.ncs_obj = self.model.get_ncs_obj()
        self.output_crystal_symmetry = not is_non_crystallographic_unit_cell
        self.sites_cart_start = self.model.get_xray_structure().sites_cart(
        ).deep_copy()
        if (self.params.show_states):
            self.states_collector = mmtbx.utils.states(
                xray_structure=self.model.get_xray_structure(),
                pdb_hierarchy=self.model.get_hierarchy())
        self.setup_output_file_names()
def process_input_files(inputs, params, log, mon_lib_srv=None):
  pdb_file_names = []
  pdb_file_names = list(inputs.pdb_file_names)
  if (params.file_name is not None) :
    pdb_file_names.append(params.file_name)
  cs = inputs.crystal_symmetry
  is_non_crystallographic_unit_cell = False
  if(cs is None):
    is_non_crystallographic_unit_cell = True
    import iotbx.pdb
    pdb_combined = combine_unique_pdb_files(file_names = pdb_file_names)
    cs = iotbx.pdb.input(source_info = None, lines = flex.std_string(
      pdb_combined.raw_records)).xray_structure_simple().\
        cubic_unit_cell_around_centered_scatterers(
        buffer_size = 10).crystal_symmetry()
  cif_objects = list(inputs.cif_objects)
  if (len(params.restraints) > 0) :
    import iotbx.cif
    for file_name in params.restraints :
      cif_object = iotbx.cif.reader(file_path=file_name, strict=False).model()
      cif_objects.append((file_name, cif_object))
  if (params.restraints_directory is not None) :
    restraint_files = os.listdir(params.restraints_directory)
    for file_name in restraint_files :
      if (file_name.endswith(".cif")) :
        full_path = os.path.join(params.restraints_directory, file_name)
        cif_object = iotbx.cif.reader(file_path=full_path,
          strict=False).model()
        cif_objects.append((full_path, cif_object))
  processed_pdb_files_srv = mmtbx.utils.process_pdb_file_srv(
    crystal_symmetry          = cs,
    pdb_interpretation_params = params.pdb_interpretation,
    stop_for_unknowns         = params.stop_for_unknowns,
    log                       = log,
    cif_objects               = cif_objects,
    use_neutron_distances     = params.pdb_interpretation.use_neutron_distances,
    mon_lib_srv               = mon_lib_srv)
  processed_pdb_file, junk = processed_pdb_files_srv.\
    process_pdb_files(pdb_file_names = pdb_file_names) # XXX remove junk
  processed_pdb_file.is_non_crystallographic_unit_cell = \
    is_non_crystallographic_unit_cell # XXX bad hack
  return processed_pdb_file
def process_input_files(inputs, params, log, mon_lib_srv=None):
  pdb_file_names = []
  pdb_file_names = list(inputs.pdb_file_names)
  if (params.file_name is not None) :
    pdb_file_names.append(params.file_name)
  cs = inputs.crystal_symmetry
  is_non_crystallographic_unit_cell = False
  if(cs is None):
    is_non_crystallographic_unit_cell = True
    import iotbx.pdb
    pdb_combined = combine_unique_pdb_files(file_names = pdb_file_names)
    cs = iotbx.pdb.input(source_info = None, lines = flex.std_string(
      pdb_combined.raw_records)).xray_structure_simple().\
        cubic_unit_cell_around_centered_scatterers(
        buffer_size = 10).crystal_symmetry()
  cif_objects = list(inputs.cif_objects)
  if (len(params.restraints) > 0) :
    import iotbx.cif
    for file_name in params.restraints :
      cif_object = iotbx.cif.reader(file_path=file_name, strict=False).model()
      cif_objects.append((file_name, cif_object))
  if (params.restraints_directory is not None) :
    restraint_files = os.listdir(params.restraints_directory)
    for file_name in restraint_files :
      if (file_name.endswith(".cif")) :
        full_path = os.path.join(params.restraints_directory, file_name)
        cif_object = iotbx.cif.reader(file_path=full_path,
          strict=False).model()
        cif_objects.append((full_path, cif_object))
  processed_pdb_files_srv = mmtbx.utils.process_pdb_file_srv(
    crystal_symmetry          = cs,
    pdb_interpretation_params = params.pdb_interpretation,
    stop_for_unknowns         = params.stop_for_unknowns,
    log                       = log,
    cif_objects               = cif_objects,
    use_neutron_distances     = params.pdb_interpretation.use_neutron_distances,
    mon_lib_srv               = mon_lib_srv)
  processed_pdb_file, junk = processed_pdb_files_srv.\
    process_pdb_files(pdb_file_names = pdb_file_names) # XXX remove junk
  processed_pdb_file.is_non_crystallographic_unit_cell = \
    is_non_crystallographic_unit_cell # XXX bad hack
  return processed_pdb_file
示例#7
0
def exercise_combine_unique_pdb_files():
  for file_name,s in [("tmp1", "1"),
                      ("tmp2", "        2"),
                      ("tmp3", "1\t"),
                      ("tmp4", " \t2"),
                      ("tmp5", "1  ")]:
    open(file_name, "w").write(s)
  for file_names in [[], ["tmp1"], ["tmp1", "tmp2"]]:
    c = pdb.combine_unique_pdb_files(file_names=file_names)
    assert len(c.file_name_registry) == len(file_names)
    assert len(c.md5_registry) == len(file_names)
    assert len(c.unique_file_names) == len(file_names)
    assert len(c.raw_records) == len(file_names)
    s = StringIO()
    c.report_non_unique(out=s)
    assert len(s.getvalue()) == 0
  c = pdb.combine_unique_pdb_files(file_names=["tmp1", "tmp1"])
  assert len(c.file_name_registry) == 1
  assert len(c.md5_registry) == 1
  assert len(c.unique_file_names) == 1
  assert len(c.raw_records) == 1
  s = StringIO()
  c.report_non_unique(out=s)
  assert not show_diff(s.getvalue(), """\
INFO: PDB file name appears 2 times: "tmp1"
  1 repeated file name ignored.

""")
  c = pdb.combine_unique_pdb_files(file_names=["tmp1", "tmp1", "tmp2", "tmp1"])
  assert len(c.file_name_registry) == 2
  assert len(c.md5_registry) == 2
  assert len(c.unique_file_names) == 2
  assert len(c.raw_records) == 2
  s = StringIO()
  c.report_non_unique(out=s, prefix="^")
  assert not show_diff(s.getvalue(), """\
^INFO: PDB file name appears 3 times: "tmp1"
^  2 repeated file names ignored.
^
""")
  c = pdb.combine_unique_pdb_files(file_names=["tmp1", "tmp2", "tmp3"])
  assert len(c.file_name_registry) == 3
  assert len(c.md5_registry) == 2
  assert len(c.unique_file_names) == 2
  assert len(c.raw_records) == 2
  s = StringIO()
  c.report_non_unique(out=s)
  assert not show_diff(s.getvalue(), """\
INFO: PDB files with identical content:
  "tmp1"
  "tmp3"
1 file with repeated content ignored.

""")
  c = pdb.combine_unique_pdb_files(file_names=["tmp1", "tmp2", "tmp3", "tmp5"])
  assert len(c.file_name_registry) == 4
  assert len(c.md5_registry) == 2
  assert len(c.unique_file_names) == 2
  assert len(c.raw_records) == 2
  s = StringIO()
  c.report_non_unique(out=s, prefix=": ")
  assert not show_diff(s.getvalue(), """\
: INFO: PDB files with identical content:
:   "tmp1"
:   "tmp3"
:   "tmp5"
: 2 files with repeated content ignored.
:
""")
  c = pdb.combine_unique_pdb_files(file_names=[
    "tmp1", "tmp2", "tmp3", "tmp4", "tmp5", "tmp4", "tmp5"])
  assert len(c.file_name_registry) == 5
  assert len(c.md5_registry) == 2
  assert len(c.unique_file_names) == 2
  assert len(c.raw_records) == 2
  s = StringIO()
  c.report_non_unique(out=s)
  assert not show_diff(s.getvalue(), """\
INFO: PDB file name appears 2 times: "tmp4"
INFO: PDB file name appears 2 times: "tmp5"
  2 repeated file names ignored.
INFO: PDB files with identical content:
  "tmp2"
  "tmp4"
INFO: PDB files with identical content:
  "tmp1"
  "tmp3"
  "tmp5"
3 files with repeated content ignored.

""")
示例#8
0
def run(args, command_name="phenix.fobs_minus_fobs_map", log=None):
    if (len(args) == 0): args = ["--help"]
    examples = """Examples:

phenix.fobs_minus_fobs_map f_obs_1_file=data1.mtz f_obs_2_file=data2.sca \
f_obs_1_label=FOBS1 f_obs_2_label=FOBS2 model.pdb

phenix.fobs_minus_fobs_map f_obs_1_file=data.mtz f_obs_2_file=data.mtz \
f_obs_1_label=FOBS1 f_obs_2_label=FOBS2 phase_source=model.pdb \
high_res=2.0 sigma_cutoff=2 scattering_table=neutron"""

    command_line = (iotbx_option_parser(
        usage="%s [options]" % command_name,
        description=examples).option("--silent",
                                     action="store_true",
                                     help="Suppress output to the screen.").
                    enable_symmetry_comprehensive()).process(args=args)
    #
    if (log is None):
        log = sys.stdout
    if (not command_line.options.silent):
        utils.print_header("phenix.fobs_minus_fobs_map", out=log)
        print("Command line arguments: ", file=log)
        print(args, file=log)
        print(file=log)
    #
    processed_args = utils.process_command_line_args(
        args=command_line.args,
        cmd_cs=command_line.symmetry,
        master_params=fo_minus_fo_master_params(),
        absolute_angle_tolerance=5,
        absolute_length_tolerance=1,
        log=log,
        suppress_symmetry_related_errors=True)
    working_phil = processed_args.params
    if (not command_line.options.silent):
        print("*** Parameters:", file=log)
        working_phil.show(out=log)
        print(file=log)
    params = working_phil.extract()
    consensus_symmetry = None
    if (params.ignore_non_isomorphous_unit_cells):
        if (None in [
                params.f_obs_1_file_name, params.f_obs_2_file_name,
                params.phase_source
        ]):
            raise Sorry(
                "The file parameters (f_obs_1_file_name, f_obs_2_file_name, " +
                "phase_source) must be specified explicitly when " +
                "ignore_non_isomorphous_unit_cells=True.")
        symm_manager = iotbx.symmetry.manager()
        pdb_in = iotbx.file_reader.any_file(params.phase_source,
                                            force_type="pdb")
        symm_manager.process_pdb_file(pdb_in)
        hkl_in_1 = iotbx.file_reader.any_file(params.f_obs_1_file_name,
                                              force_type="hkl")
        sg_err_1, uc_err_1 = symm_manager.process_reflections_file(hkl_in_1)
        hkl_in_2 = iotbx.file_reader.any_file(params.f_obs_2_file_name,
                                              force_type="hkl")
        sg_err_2, uc_err_2 = symm_manager.process_reflections_file(hkl_in_2)
        out = StringIO()
        symm_manager.show(out=out)
        if (sg_err_1) or (sg_err_2):
            raise Sorry((
                "Incompatible space groups in input files:\n%s\nAll files " +
                "must have the same point group (and ideally the same space group). "
                +
                "Please note that any symmetry information in the PDB file will be "
                + "used first.") % out.getvalue())
        elif (uc_err_1) or (uc_err_2):
            libtbx.call_back(
                message="warn",
                data=
                ("Crystal symmetry mismatch:\n%s\nCalculations will continue "
                 +
                 "using the symmetry in the PDB file (or if not available, the "
                 +
                 "first reflection file), but the maps should be treated with "
                 + "extreme suspicion.") % out.getvalue())
        crystal_symmetry = symm_manager.as_symmetry_object()
    else:
        processed_args = utils.process_command_line_args(
            args=command_line.args,
            cmd_cs=command_line.symmetry,
            master_params=fo_minus_fo_master_params(),
            suppress_symmetry_related_errors=False,
            absolute_angle_tolerance=5,
            absolute_length_tolerance=1,
            log=StringIO())
        crystal_symmetry = processed_args.crystal_symmetry
    #
    pdb_file_names = processed_args.pdb_file_names
    if (len(processed_args.pdb_file_names) == 0):
        if (params.phase_source is not None):
            pdb_file_names = [params.phase_source]
        else:
            raise Sorry("No PDB file found.")
    # Extaract Fobs1, Fobs2
    f_obss = []
    if (len(processed_args.reflection_files) == 2):
        for reflection_file in processed_args.reflection_files:
            reflection_file_server = reflection_file_utils.reflection_file_server(
                crystal_symmetry=crystal_symmetry,
                force_symmetry=True,
                reflection_files=[reflection_file],
                err=null_out())
            # XXX UGLY !!!
            try:
                parameters = utils.data_and_flags_master_params().extract()
                if (params.f_obs_1_label is not None):
                    parameters.labels = [params.f_obs_1_label]
                determine_data_and_flags_result = utils.determine_data_and_flags(
                    reflection_file_server=reflection_file_server,
                    keep_going=True,
                    parameters=parameters,
                    log=null_out())
            except:  # intentional
                parameters = utils.data_and_flags_master_params().extract()
                if (params.f_obs_2_label is not None):
                    parameters.labels = [params.f_obs_2_label]
                determine_data_and_flags_result = utils.determine_data_and_flags(
                    reflection_file_server=reflection_file_server,
                    keep_going=True,
                    parameters=parameters,
                    log=null_out())
            f_obss.append(determine_data_and_flags_result.f_obs)
    else:
        if ([params.f_obs_1_file_name,
             params.f_obs_2_file_name].count(None) == 2):
            raise Sorry("No reflection data file found.")
        for file_name, label in zip(
            [params.f_obs_1_file_name, params.f_obs_2_file_name],
            [params.f_obs_1_label, params.f_obs_2_label]):
            reflection_file = reflection_file_reader.any_reflection_file(
                file_name=file_name, ensure_read_access=False)
            reflection_file_server = reflection_file_utils.reflection_file_server(
                crystal_symmetry=crystal_symmetry,
                force_symmetry=True,
                reflection_files=[reflection_file],
                err=null_out())
            parameters = utils.data_and_flags_master_params().extract()
            if (label is not None):
                parameters.labels = [label]
            determine_data_and_flags_result = utils.determine_data_and_flags(
                reflection_file_server=reflection_file_server,
                parameters=parameters,
                keep_going=True,
                log=null_out())
            f_obss.append(determine_data_and_flags_result.f_obs)
    if (len(f_obss) != 2):
        raise Sorry(" ".join(errors))
    if (not command_line.options.silent):
        for ifobs, fobs in enumerate(f_obss):
            print("*** Summary for data set %d:" % ifobs, file=log)
            fobs.show_comprehensive_summary(f=log)
            print(file=log)
    pdb_combined = combine_unique_pdb_files(file_names=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_recs = flex.std_string()
    for rec in pdb_combined.raw_records:
        if (rec.upper().count("CRYST1") == 0):
            raw_recs.append(rec)
    raw_recs.append(
        iotbx.pdb.format_cryst1_record(crystal_symmetry=crystal_symmetry))
    #
    pdb_in = iotbx.pdb.input(source_info=None, lines=raw_recs)
    model = mmtbx.model.manager(model_input=pdb_in)
    d_min = min(f_obss[0].d_min(), f_obss[1].d_min())
    model.setup_scattering_dictionaries(
        scattering_table=params.scattering_table, d_min=d_min)
    xray_structure = model.get_xray_structure()
    hierarchy = model.get_hierarchy()
    #
    omit_sel = flex.bool(hierarchy.atoms_size(), False)
    if (params.advanced.omit_selection is not None):
        print("Will omit selection from phasing model:", file=log)
        print("  " + params.advanced.omit_selection, file=log)
        omit_sel = hierarchy.atom_selection_cache().selection(
            params.advanced.omit_selection)
        print("%d atoms selected for removal" % omit_sel.count(True), file=log)
    del hierarchy
    xray_structure = xray_structure.select(~omit_sel)
    if (not command_line.options.silent):
        print("*** Model summary:", file=log)
        xray_structure.show_summary(f=log)
        print(file=log)
    info0 = f_obss[0].info()
    info1 = f_obss[1].info()
    f_obss[0] = f_obss[0].resolution_filter(
        d_min=params.high_resolution,
        d_max=params.low_resolution).set_info(info0)
    f_obss[1] = f_obss[1].resolution_filter(
        d_min=params.high_resolution,
        d_max=params.low_resolution).set_info(info1)
    if (params.sigma_cutoff is not None):
        for i in [0, 1]:
            if (f_obss[i].sigmas() is not None):
                sel = f_obss[i].data(
                ) > f_obss[i].sigmas() * params.sigma_cutoff
                f_obss[i] = f_obss[i].select(sel).set_info(info0)
    for k, f_obs in enumerate(f_obss):
        if (f_obs.indices().size() == 0):
            raise Sorry(
                "No data left in array %d (labels=%s) after filtering!" %
                (k + 1, f_obs.info().label_string()))
    output_file_name = params.output_file
    if (output_file_name is None) and (params.file_name_prefix is not None):
        output_file_name = "%s_%s.mtz" % (params.file_name_prefix,
                                          params.job_id)
    output_files = compute_fo_minus_fo_map(
        data_arrays=f_obss,
        xray_structure=xray_structure,
        log=log,
        silent=command_line.options.silent,
        output_file=output_file_name,
        peak_search=params.find_peaks_holes,
        map_cutoff=params.map_cutoff,
        peak_search_params=params.peak_search,
        multiscale=params.advanced.multiscale,
        anomalous=params.advanced.anomalous).file_names
    return output_files
def run(args, command_name = "phenix.fobs_minus_fobs_map", log=None):
  if(len(args) == 0): args = ["--help"]
  examples = """Examples:

phenix.fobs_minus_fobs_map f_obs_1_file=data1.mtz f_obs_2_file=data2.sca \
f_obs_1_label=FOBS1 f_obs_2_label=FOBS2 model.pdb

phenix.fobs_minus_fobs_map f_obs_1_file=data.mtz f_obs_2_file=data.mtz \
f_obs_1_label=FOBS1 f_obs_2_label=FOBS2 phase_source=model.pdb \
high_res=2.0 sigma_cutoff=2 scattering_table=neutron"""

  command_line = (iotbx_option_parser(
    usage="%s [options]" % command_name,
    description=examples)
    .option("--silent",
      action="store_true",
      help="Suppress output to the screen.")
    .enable_symmetry_comprehensive()
    ).process(args=args)
  #
  if (log is None) :
    log = sys.stdout
  if(not command_line.options.silent):
    utils.print_header("phenix.fobs_minus_fobs_map", out = log)
    print >> log, "Command line arguments: "
    print >> log, args
    print >> log
  #
  processed_args = utils.process_command_line_args(
    args=command_line.args,
    cmd_cs=command_line.symmetry,
    master_params=fo_minus_fo_master_params(),
    absolute_angle_tolerance=5,
    absolute_length_tolerance=1,
    log=log,
    suppress_symmetry_related_errors=True)
  working_phil = processed_args.params
  if(not command_line.options.silent):
    print >> log, "*** Parameters:"
    working_phil.show(out = log)
    print >> log
  params = working_phil.extract()
  consensus_symmetry = None
  if (params.ignore_non_isomorphous_unit_cells) :
    if (None in [params.f_obs_1_file_name, params.f_obs_2_file_name,
        params.phase_source]):
      raise Sorry("The file parameters (f_obs_1_file_name, f_obs_2_file_name, "+
        "phase_source) must be specified explicitly when "+
        "ignore_non_isomorphous_unit_cells=True.")
    symm_manager = iotbx.symmetry.manager()
    pdb_in = iotbx.file_reader.any_file(params.phase_source, force_type="pdb")
    symm_manager.process_pdb_file(pdb_in)
    hkl_in_1 = iotbx.file_reader.any_file(params.f_obs_1_file_name,
      force_type="hkl")
    sg_err_1, uc_err_1 = symm_manager.process_reflections_file(hkl_in_1)
    hkl_in_2 = iotbx.file_reader.any_file(params.f_obs_2_file_name,
      force_type="hkl")
    sg_err_2, uc_err_2 = symm_manager.process_reflections_file(hkl_in_2)
    out = StringIO()
    symm_manager.show(out=out)
    if (sg_err_1) or (sg_err_2) :
      raise Sorry(("Incompatible space groups in input files:\n%s\nAll files "+
        "must have the same point group (and ideally the same space group). "+
        "Please note that any symmetry information in the PDB file will be "+
        "used first.") % out.getvalue())
    elif (uc_err_1) or (uc_err_2) :
      libtbx.call_back(message="warn",
        data=("Crystal symmetry mismatch:\n%s\nCalculations will continue "+
          "using the symmetry in the PDB file (or if not available, the "+
          "first reflection file), but the maps should be treated with "+
          "extreme suspicion.") % out.getvalue())
    crystal_symmetry = symm_manager.as_symmetry_object()
  else :
    processed_args = utils.process_command_line_args(
      args=command_line.args,
      cmd_cs=command_line.symmetry,
      master_params=fo_minus_fo_master_params(),
      absolute_angle_tolerance=5,
      absolute_length_tolerance=1,
      log=StringIO())
    crystal_symmetry = processed_args.crystal_symmetry
  #
  pdb_file_names = processed_args.pdb_file_names
  if(len(processed_args.pdb_file_names) == 0):
    if(params.phase_source is not None):
      pdb_file_names = [params.phase_source]
    else:
      raise Sorry("No PDB file found.")
  # Extaract Fobs1, Fobs2
  f_obss = []
  if(len(processed_args.reflection_files)==2):
    for reflection_file in processed_args.reflection_files:
      reflection_file_server = reflection_file_utils.reflection_file_server(
        crystal_symmetry = crystal_symmetry,
        force_symmetry   = True,
        reflection_files = [reflection_file],
        err              = null_out())
      # XXX UGLY !!!
      try:
        parameters = utils.data_and_flags_master_params().extract()
        if(params.f_obs_1_label is not None):
          parameters.labels = [params.f_obs_1_label]
        determine_data_and_flags_result = utils.determine_data_and_flags(
          reflection_file_server  = reflection_file_server,
          keep_going              = True,
          parameters              = parameters,
          log                     = null_out())
      except: # intentional
        parameters = utils.data_and_flags_master_params().extract()
        if(params.f_obs_2_label is not None):
          parameters.labels = [params.f_obs_2_label]
        determine_data_and_flags_result = utils.determine_data_and_flags(
          reflection_file_server  = reflection_file_server,
          keep_going              = True,
          parameters              = parameters,
          log                     = null_out())
      f_obss.append(determine_data_and_flags_result.f_obs)
  else:
    if([params.f_obs_1_file_name,params.f_obs_2_file_name].count(None)==2):
      raise Sorry("No reflection data file found.")
    for file_name, label in zip([params.f_obs_1_file_name,params.f_obs_2_file_name],
                                [params.f_obs_1_label,params.f_obs_2_label]):
      reflection_file = reflection_file_reader.any_reflection_file(
        file_name = file_name, ensure_read_access = False)
      reflection_file_server = reflection_file_utils.reflection_file_server(
        crystal_symmetry = crystal_symmetry,
        force_symmetry   = True,
        reflection_files = [reflection_file],
        err              = null_out())
      parameters = utils.data_and_flags_master_params().extract()
      if(label is not None):
        parameters.labels = [label]
      determine_data_and_flags_result = utils.determine_data_and_flags(
          reflection_file_server  = reflection_file_server,
          parameters              = parameters,
          keep_going              = True,
          log                     = null_out())
      f_obss.append(determine_data_and_flags_result.f_obs)
  if(len(f_obss)!=2):
    raise Sorry(" ".join(errors))
  if(not command_line.options.silent):
    for ifobs, fobs in enumerate(f_obss):
      print >> log, "*** Summary for data set %d:"%ifobs
      fobs.show_comprehensive_summary(f = log)
      print >> log
  pdb_combined = combine_unique_pdb_files(file_names = 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_recs = flex.std_string()
  for rec in pdb_combined.raw_records:
    if(rec.upper().count("CRYST1")==0):
      raw_recs.append(rec)
  raw_recs.append(iotbx.pdb.format_cryst1_record(
    crystal_symmetry = crystal_symmetry))
  #
  pdb_in = iotbx.pdb.input(source_info = None, lines = raw_recs)
  hierarchy = pdb_in.construct_hierarchy()
  omit_sel = flex.bool(hierarchy.atoms_size(), False)
  if (params.advanced.omit_selection is not None) :
    print >> log, "Will omit selection from phasing model:"
    print >> log, "  " + params.advanced.omit_selection
    omit_sel = hierarchy.atom_selection_cache().selection(
      params.advanced.omit_selection)
    print >> log, "%d atoms selected for removal" % omit_sel.count(True)
  xray_structure = pdb_in.xray_structure_simple()
  xray_structure = xray_structure.select(~omit_sel)
  if(not command_line.options.silent):
    print >> log, "*** Model summary:"
    xray_structure.show_summary(f = log)
    print >> log
  info0 = f_obss[0].info()
  info1 = f_obss[1].info()
  f_obss[0] = f_obss[0].resolution_filter(d_min = params.high_resolution,
    d_max = params.low_resolution).set_info(info0)
  f_obss[1] = f_obss[1].resolution_filter(d_min = params.high_resolution,
    d_max = params.low_resolution).set_info(info1)
  if(params.sigma_cutoff is not None):
    for i in [0,1]:
      if(f_obss[i].sigmas() is not None):
        sel = f_obss[i].data() > f_obss[i].sigmas()*params.sigma_cutoff
        f_obss[i] = f_obss[i].select(sel).set_info(info0)
  for k, f_obs in enumerate(f_obss) :
    if (f_obs.indices().size() == 0) :
      raise Sorry("No data left in array %d (labels=%s) after filtering!" % (k+1,
        f_obs.info().label_string()))
  output_file_name = params.output_file
  if (output_file_name is None) and (params.file_name_prefix is not None) :
    output_file_name = "%s_%s.mtz" % (params.file_name_prefix, params.job_id)
  output_files = compute_fo_minus_fo_map(
    data_arrays = f_obss,
    xray_structure = xray_structure,
    log = log,
    silent = command_line.options.silent,
    output_file = output_file_name,
    peak_search=params.find_peaks_holes,
    map_cutoff=params.map_cutoff,
    peak_search_params=params.peak_search,
    multiscale=params.advanced.multiscale,
    anomalous=params.advanced.anomalous).file_names
  return output_files
示例#10
0
def run(args, log=sys.stderr):
    if (len(args) == 0):
        print >> log, msg
        defaults(log=log)
        return
    #
    parsed = defaults(log=log)
    processed_args = mmtbx.utils.process_command_line_args(
        args=args, log=log, master_params=parsed)
    params = processed_args.params.extract()
    reflection_files = processed_args.reflection_files
    #
    atoms_with_labels = None
    if (len(processed_args.pdb_file_names) == 1):
        pdb_combined = combine_unique_pdb_files(
            file_names=processed_args.pdb_file_names)
        pdb_combined.report_non_unique()
        pdb_inp = iotbx.pdb.input(source_info=None,
                                  lines=flex.std_string(
                                      pdb_combined.raw_records))
        atoms_with_labels = pdb_inp.atoms_with_labels()
    #
    if (len(reflection_files) == 0):
        raise Sorry("No reflection file found.")
    if (len(reflection_files) > 1):
        raise Sorry("More than one reflection file found.")
    crystal_symmetry = processed_args.crystal_symmetry
    if (crystal_symmetry is None):
        raise Sorry("No crystal symmetry found.")
    reflection_file_name = reflection_files[0].file_name()
    miller_arrays = reflection_file_reader.any_reflection_file(
        file_name=reflection_file_name).as_miller_arrays()
    #
    if (len(miller_arrays) == 1 and params.label is None):
        ma = miller_arrays[0]
    elif (len(miller_arrays) > 1 and params.label is None):
        raise Sorry(
            "Multiple data columns found in input file. Use label keyword to select the one."
        )
    elif (len(miller_arrays) == 1 and params.label is not None):
        ma = miller_arrays[0]
        if (ma.info().labels[0].lower() != params.label.lower()):
            raise Sorry(
                "Specified label 'label=%s' does not match any label in input file."
                % params.label)
    elif (len(miller_arrays) > 1 and params.label is not None):
        for ma in miller_arrays:
            if (ma.info().labels[0].lower() == params.label.lower()):
                break
    if (not ma.is_complex_array()):
        raise Sorry("Data must be complex type (real provided).")
    print >> log, "Input reflection data (Fourier map coefficients):"
    ma.show_comprehensive_summary(prefix="  ")
    print >> log
    #
    if (len(params.point) == 0 and atoms_with_labels is None):
        raise Sorry("No points given to compute map value at.")
    else:
        fft_map = ma.fft_map(resolution_factor=params.resolution_factor)
        if (params.scale == "sigma"):
            fft_map.apply_sigma_scaling()
            print >> log, "Using sigma scaled map.\n"
        else:
            fft_map.apply_volume_scaling()
            print >> log, "Using volume scale map.\n"
        map_3d = fft_map.real_map_unpadded()
        print >> log, "Map values at specified points:"
        return ma, map_3d
        for point in params.point:
            point_frac = ma.unit_cell().fractionalize(point)
            point_formatted = ",".join(
                [str("%10.3f" % p).strip() for p in point])
            point_frac_formatted = \
              ",".join([str("%10.3f"%p).strip() for p in point_frac])
            map_value = str(
                "%10.3f" %
                map_3d.eight_point_interpolation(point_frac)).strip()
            print >> log, "  Input point: (%s) Fractionalized: (%s) Map value: %s" % (
                point_formatted, point_frac_formatted, map_value)
        #
        if (atoms_with_labels is not None):
            for point in atoms_with_labels:
                point_frac = ma.unit_cell().fractionalize(point.xyz)
                point_formatted = ",".join(
                    [str("%8.3f" % p) for p in point.xyz])
                map_value = str(
                    "%10.3f" %
                    map_3d.eight_point_interpolation(point_frac)).strip()
                print >> log, point.quote(), "Point: %s Map value: %s" % (
                    point_formatted, map_value)
    #
    print >> log
    print >> log, "All done."
def run(args, log = sys.stderr):
  if(len(args)==0):
    print >> log, msg
    defaults(log=log)
    return
  #
  parsed = defaults(log=log)
  processed_args = mmtbx.utils.process_command_line_args(args = args,
    log = log, master_params = parsed)
  params = processed_args.params.extract()
  reflection_files = processed_args.reflection_files
  #
  atoms_with_labels = None
  if(len(processed_args.pdb_file_names)==1):
    pdb_combined = combine_unique_pdb_files(
      file_names=processed_args.pdb_file_names)
    pdb_combined.report_non_unique()
    pdb_inp = iotbx.pdb.input(source_info = None,
      lines = flex.std_string(pdb_combined.raw_records))
    atoms_with_labels = pdb_inp.atoms_with_labels()
  #
  if(len(reflection_files) == 0):
    raise Sorry("No reflection file found.")
  if(len(reflection_files) > 1):
    raise Sorry("More than one reflection file found.")
  crystal_symmetry = processed_args.crystal_symmetry
  if(crystal_symmetry is None):
    raise Sorry("No crystal symmetry found.")
  reflection_file_name = reflection_files[0].file_name()
  miller_arrays = reflection_file_reader.any_reflection_file(file_name =
    reflection_file_name).as_miller_arrays()
  #
  if(len(miller_arrays)==1 and params.label is None):
    ma = miller_arrays[0]
  elif(len(miller_arrays)>1 and params.label is None):
    raise Sorry("Multiple data columns found in input file. Use label keyword to select the one.")
  elif(len(miller_arrays)==1 and params.label is not None):
    ma = miller_arrays[0]
    if(ma.info().labels[0].lower() != params.label.lower()):
      raise Sorry("Specified label 'label=%s' does not match any label in input file."%params.label)
  elif(len(miller_arrays)>1 and params.label is not None):
    for ma in miller_arrays:
      if(ma.info().labels[0].lower() == params.label.lower()):
        break
  if(not ma.is_complex_array()):
    raise Sorry("Data must be complex type (real provided).")
  print >> log, "Input reflection data (Fourier map coefficients):"
  ma.show_comprehensive_summary(prefix="  ")
  print >> log
  #
  if(len(params.point)==0 and atoms_with_labels is None):
    raise Sorry("No points given to compute map value at.")
  else:
    fft_map = ma.fft_map(resolution_factor=params.resolution_factor)
    if(params.scale == "sigma"):
      fft_map.apply_sigma_scaling()
      print >> log, "Using sigma scaled map.\n"
    else:
      fft_map.apply_volume_scaling()
      print >> log, "Using volume scale map.\n"
    map_3d = fft_map.real_map_unpadded()
    print >> log, "Map values at specified points:"
    return ma,map_3d
    for point in params.point:
      point_frac = ma.unit_cell().fractionalize(point)
      point_formatted = ",".join([str("%10.3f"%p).strip() for p in point])
      point_frac_formatted = \
        ",".join([str("%10.3f"%p).strip() for p in point_frac])
      map_value = str(
        "%10.3f"%map_3d.eight_point_interpolation(point_frac)).strip()
      print >> log, "  Input point: (%s) Fractionalized: (%s) Map value: %s"%(
        point_formatted, point_frac_formatted, map_value)
    #
    if(atoms_with_labels is not None):
      for point in atoms_with_labels:
        point_frac = ma.unit_cell().fractionalize(point.xyz)
        point_formatted = ",".join([str("%8.3f"%p) for p in point.xyz])
        map_value = str(
          "%10.3f"%map_3d.eight_point_interpolation(point_frac)).strip()
        print >> log, point.quote(), "Point: %s Map value: %s"%(point_formatted,map_value)
  #
  print >> log
  print >> log, "All done."
示例#12
0
def exercise_combine_unique_pdb_files():
    for file_name, s in [("tmp1", "1"), ("tmp2", "        2"), ("tmp3", "1\t"), ("tmp4", " \t2"), ("tmp5", "1  ")]:
        open(file_name, "w").write(s)
    for file_names in [[], ["tmp1"], ["tmp1", "tmp2"]]:
        c = pdb.combine_unique_pdb_files(file_names=file_names)
        assert len(c.file_name_registry) == len(file_names)
        assert len(c.md5_registry) == len(file_names)
        assert len(c.unique_file_names) == len(file_names)
        assert len(c.raw_records) == len(file_names)
        s = StringIO()
        c.report_non_unique(out=s)
        assert len(s.getvalue()) == 0
    c = pdb.combine_unique_pdb_files(file_names=["tmp1", "tmp1"])
    assert len(c.file_name_registry) == 1
    assert len(c.md5_registry) == 1
    assert len(c.unique_file_names) == 1
    assert len(c.raw_records) == 1
    s = StringIO()
    c.report_non_unique(out=s)
    assert not show_diff(
        s.getvalue(),
        """\
INFO: PDB file name appears 2 times: "tmp1"
  1 repeated file name ignored.

""",
    )
    c = pdb.combine_unique_pdb_files(file_names=["tmp1", "tmp1", "tmp2", "tmp1"])
    assert len(c.file_name_registry) == 2
    assert len(c.md5_registry) == 2
    assert len(c.unique_file_names) == 2
    assert len(c.raw_records) == 2
    s = StringIO()
    c.report_non_unique(out=s, prefix="^")
    assert not show_diff(
        s.getvalue(),
        """\
^INFO: PDB file name appears 3 times: "tmp1"
^  2 repeated file names ignored.
^
""",
    )
    c = pdb.combine_unique_pdb_files(file_names=["tmp1", "tmp2", "tmp3"])
    assert len(c.file_name_registry) == 3
    assert len(c.md5_registry) == 2
    assert len(c.unique_file_names) == 2
    assert len(c.raw_records) == 2
    s = StringIO()
    c.report_non_unique(out=s)
    assert not show_diff(
        s.getvalue(),
        """\
INFO: PDB files with identical content:
  "tmp1"
  "tmp3"
1 file with repeated content ignored.

""",
    )
    c = pdb.combine_unique_pdb_files(file_names=["tmp1", "tmp2", "tmp3", "tmp5"])
    assert len(c.file_name_registry) == 4
    assert len(c.md5_registry) == 2
    assert len(c.unique_file_names) == 2
    assert len(c.raw_records) == 2
    s = StringIO()
    c.report_non_unique(out=s, prefix=": ")
    assert not show_diff(
        s.getvalue(),
        """\
: INFO: PDB files with identical content:
:   "tmp1"
:   "tmp3"
:   "tmp5"
: 2 files with repeated content ignored.
:
""",
    )
    c = pdb.combine_unique_pdb_files(file_names=["tmp1", "tmp2", "tmp3", "tmp4", "tmp5", "tmp4", "tmp5"])
    assert len(c.file_name_registry) == 5
    assert len(c.md5_registry) == 2
    assert len(c.unique_file_names) == 2
    assert len(c.raw_records) == 2
    s = StringIO()
    c.report_non_unique(out=s)
    assert not show_diff(
        s.getvalue(),
        """\
INFO: PDB file name appears 2 times: "tmp4"
INFO: PDB file name appears 2 times: "tmp5"
  2 repeated file names ignored.
INFO: PDB files with identical content:
  "tmp2"
  "tmp4"
INFO: PDB files with identical content:
  "tmp1"
  "tmp3"
  "tmp5"
3 files with repeated content ignored.

""",
    )