Exemple #1
0
def _main(args, out=sys.stdout):
    """
  Main entry point to this script.

  Parameters
  ----------
  args : list of str
      List of arguments, should not include the first argument with the
      executable name.
  out : file, optional
  """
    usage_string = """\
phenix.python -m mmtbx.ions.svm.dump_sites model.pdb data.mtz [options ...]

Utility to dump information about the properties of water and ion sites in a
model. This properties include local environment, electron density maps, and
atomic properties.
"""
    cmdline = load_model_and_data(
        args=args,
        master_phil=master_phil(),
        out=out,
        process_pdb_file=True,
        create_fmodel=True,
        prefer_anomalous=True,
        set_wavelength_from_model_header=True,
        set_inelastic_form_factors="sasaki",
        usage_string=usage_string,
    )

    params = cmdline.params
    params.use_svm = True

    make_header("Inspecting sites", out=out)

    manager = ions.identify.create_manager(
        pdb_hierarchy=cmdline.pdb_hierarchy,
        fmodel=cmdline.fmodel,
        geometry_restraints_manager=cmdline.geometry,
        wavelength=params.input.wavelength,
        params=params,
        verbose=params.debug,
        nproc=params.nproc,
        log=out,
    )

    manager.show_current_scattering_statistics(out=out)

    sites = dump_sites(manager)

    out_name = os.path.splitext(
        params.input.pdb.file_name[0])[0] + "_sites.pkl"
    print("Dumping to", out_name, file=out)
    easy_pickle.dump(out_name, sites)
Exemple #2
0
def exercise():
    wavelength = 1.025
    mtz_file, pdb_file = generate_zinc_inputs(anonymize=False)
    null_out = libtbx.utils.null_out()

    cmdline = mmtbx.command_line.load_model_and_data(args=[
        pdb_file, mtz_file, "wavelength={}".format(wavelength),
        "use_phaser=False", "use_svm=True"
    ],
                                                     master_phil=master_phil(),
                                                     out=null_out,
                                                     process_pdb_file=True,
                                                     create_fmodel=True,
                                                     prefer_anomalous=True)

    os.remove(pdb_file)
    os.remove(mtz_file)
    os.remove(os.path.splitext(pdb_file)[0] + "_fmodel.eff")

    cmdline.xray_structure.set_inelastic_form_factors(
        photon=cmdline.params.input.wavelength, table="sasaki")

    cmdline.fmodel.update_xray_structure(cmdline.xray_structure,
                                         update_f_calc=True)

    manager = ions.identify.create_manager(
        pdb_hierarchy=cmdline.pdb_hierarchy,
        fmodel=cmdline.fmodel,
        geometry_restraints_manager=cmdline.geometry,
        wavelength=cmdline.params.input.wavelength,
        params=cmdline.params,
        nproc=cmdline.params.nproc,
        log=null_out)

    manager.validate_ions(out=null_out)

    for atom_props in manager.atoms_to_props.values():
        i_seq = atom_props.i_seq
        chem_env = ChemicalEnvironment(
            i_seq, manager.find_nearby_atoms(i_seq, far_distance_cutoff=3.5),
            manager)
        scatter_env = ScatteringEnvironment(
            i_seq,
            manager,
            fo_density=manager.get_map_gaussian_fit("mFo", i_seq),
            fofc_density=manager.get_map_gaussian_fit("mFo-DFc", i_seq),
            anom_density=manager.get_map_gaussian_fit("anom", i_seq),
        )
        vector = ion_vector(chem_env, scatter_env)
        resname = ion_class(chem_env)
        assert vector is not None
        assert resname != ""

    print "OK"
Exemple #3
0
def _main(args, out=sys.stdout):
  """
  Main entry point to this script.

  Parameters
  ----------
  args : list of str
      List of arguments, should not include the first argument with the
      executable name.
  out : file, optional
  """
  usage_string = """\
phenix.python -m mmtbx.ions.svm.dump_sites model.pdb data.mtz [options ...]

Utility to dump information about the properties of water and ion sites in a
model. This properties include local environment, electron density maps, and
atomic properties.
"""
  cmdline = load_model_and_data(
    args=args,
    master_phil=master_phil(),
    out=out,
    process_pdb_file=True,
    create_fmodel=True,
    prefer_anomalous=True,
    set_wavelength_from_model_header=True,
    set_inelastic_form_factors="sasaki",
    usage_string=usage_string,
    )

  params = cmdline.params
  params.use_svm = True

  make_header("Inspecting sites", out=out)

  manager = ions.identify.create_manager(
    pdb_hierarchy=cmdline.pdb_hierarchy,
    fmodel=cmdline.fmodel,
    geometry_restraints_manager=cmdline.geometry,
    wavelength=params.input.wavelength,
    params=params,
    verbose=params.debug,
    nproc=params.nproc,
    log=out,
    )

  manager.show_current_scattering_statistics(out=out)

  sites = dump_sites(manager)

  out_name = os.path.splitext(params.input.pdb.file_name[0])[0] + "_sites.pkl"
  print >> out, "Dumping to", out_name
  easy_pickle.dump(out_name, sites)
def exercise():
    fns = [generate_calcium_inputs, generate_zinc_inputs]
    wavelengths = [1.025, 1.54]

    for fn, wavelength in zip(fns, wavelengths):
        mtz_file, pdb_file = fn(anonymize=True)
        null_out = libtbx.utils.null_out()

        cmdline = mmtbx.command_line.load_model_and_data(
            args=[
                pdb_file, mtz_file, "wavelength={}".format(wavelength),
                "use_phaser=True", "use_svm=True"
            ],
            master_phil=master_phil(),
            out=null_out,
            process_pdb_file=True,
            create_fmodel=True,
            prefer_anomalous=True,
            set_inelastic_form_factors="sasaki",
        )

        os.remove(pdb_file)
        os.remove(mtz_file)
        os.remove(os.path.splitext(mtz_file)[0] + "_fmodel.eff")
        os.remove(os.path.splitext(mtz_file)[0] + ".pdb")

        manager = ions.identify.create_manager(
            pdb_hierarchy=cmdline.pdb_hierarchy,
            fmodel=cmdline.fmodel,
            geometry_restraints_manager=cmdline.geometry,
            wavelength=cmdline.params.input.wavelength,
            params=cmdline.params,
            nproc=cmdline.params.nproc,
            log=null_out,
            manager_class=ions.svm.manager,
        )

        # Build a list of properties of each water / ion site
        waters = []
        for chain in manager.pdb_hierarchy.only_model().chains():
            for residue_group in chain.residue_groups():
                atom_groups = residue_group.atom_groups()
                if (len(atom_groups) > 1):  # alt conf, skip
                    continue
                for atom_group in atom_groups:
                    # Check for non standard atoms in the residue
                    # Or a label indicating the residue is a water
                    resname = atom_group.resname.strip().upper()

                    if (resname in WATER_RES_NAMES):
                        atoms = atom_group.atoms()
                        if (len(atoms) == 1
                            ):  # otherwise it probably has hydrogens, skip
                            waters.append(atoms[0].i_seq)

        assert len(waters) > 0

        atom_props = [AtomProperties(i_seq, manager) for i_seq in waters]

        for atom_prop in atom_props:
            i_seq = atom_prop.i_seq
            chem_env = ChemicalEnvironment(
                i_seq,
                manager.find_nearby_atoms(i_seq, far_distance_cutoff=3.5),
                manager,
            )
            scatter_env = ScatteringEnvironment(
                i_seq,
                manager,
                fo_density=manager.get_map_gaussian_fit("mFo", i_seq),
                fofc_density=manager.get_map_gaussian_fit("mFo-DFc", i_seq),
                anom_density=manager.get_map_gaussian_fit("anom", i_seq),
            )
            resname = ion_class(chem_env)
            assert resname != ""

            predictions = predict_ion(chem_env,
                                      scatter_env,
                                      elements=["HOH", "ZN", "CA"])
            if predictions is None:
                print "Could not load SVM classifier"
                print "Skipping {}".format(os.path.split(__file__)[1])
                return

            if resname != predictions[0][0]:
                print "Prediction ({}) did not match expected: {}" \
                  .format(predictions[0][0], resname)
                for element, prob in predictions:
                    print "  {}: {:.2f}".format(element, prob)
                sys.exit()

    print "OK"
Exemple #5
0
def exercise():
  wavelength = 1.025
  mtz_file, pdb_file = generate_zinc_inputs(anonymize = False)
  null_out = libtbx.utils.null_out()

  cmdline = mmtbx.command_line.load_model_and_data(
    args = [pdb_file, mtz_file, "wavelength={}".format(wavelength),
            "use_phaser=False"],
    master_phil = master_phil(),
    out = null_out,
    process_pdb_file = True,
    create_fmodel = True,
    prefer_anomalous = True
    )

  os.remove(pdb_file)
  os.remove(mtz_file)

  cmdline.xray_structure.set_inelastic_form_factors(
    photon = cmdline.params.input.wavelength,
    table = "sasaki"
    )

  cmdline.fmodel.update_xray_structure(
    cmdline.xray_structure,
    update_f_calc = True
    )

  manager = ions.identify.create_manager(
    pdb_hierarchy = cmdline.pdb_hierarchy,
    fmodel = cmdline.fmodel,
    geometry_restraints_manager = cmdline.geometry,
    wavelength = cmdline.params.input.wavelength,
    params = cmdline.params,
    nproc = cmdline.params.nproc,
    log = null_out
    )

  manager.validate_ions(
    out = null_out
    )

  fo_map = manager.get_map("mFo")
  fofc_map = manager.get_map("mFo-DFc")

  for atom_props in manager.atoms_to_props.values():
    chem_env = environment.ChemicalEnvironment(
      atom_props.i_seq,
      manager.find_nearby_atoms(atom_props.i_seq, far_distance_cutoff = 3.5),
      manager
      )
    new_chem_env = loads(dumps(chem_env))
    for attr in dir(chem_env):
      if attr == "atom":
        # The two won't be directly comparable, but we will trust atom_labels is
        # tested fully in its own module
        assert chem_env.atom.id_str() == new_chem_env.atom.id_str()
      elif not attr.startswith("_") and \
        not isinstance(getattr(chem_env, attr), MethodType):
        assert getattr(chem_env, attr) == getattr(new_chem_env, attr)

    scatter_env = environment.ScatteringEnvironment(
      atom_props.i_seq, manager, fo_map, fofc_map
      )
    new_scatter_env = loads(dumps(scatter_env))
    for attr in dir(scatter_env):
      if not attr.startswith("_") and \
        not isinstance(getattr(scatter_env, attr), MethodType):
        assert getattr(scatter_env, attr) == getattr(new_scatter_env, attr)

  del fo_map
  del fofc_map

  print "OK"
def exercise () :
  fns = [generate_calcium_inputs, generate_zinc_inputs]
  wavelengths = [1.025, 1.54]

  for fn, wavelength in zip(fns, wavelengths):
    mtz_file, pdb_file = fn(anonymize = True)
    null_out = libtbx.utils.null_out()

    cmdline = mmtbx.command_line.load_model_and_data(
      args = [pdb_file, mtz_file, "wavelength={}".format(wavelength),
              "use_phaser=True", "use_svm=True"],
      master_phil = master_phil(),
      out = null_out,
      process_pdb_file = True,
      create_fmodel = True,
      prefer_anomalous = True,
      set_inelastic_form_factors = "sasaki",
      )

    os.remove(pdb_file)
    os.remove(mtz_file)
    os.remove(os.path.splitext(mtz_file)[0] + "_fmodel.eff")
    os.remove(os.path.splitext(mtz_file)[0] + ".pdb")

    manager = ions.identify.create_manager(
      pdb_hierarchy = cmdline.pdb_hierarchy,
      fmodel = cmdline.fmodel,
      geometry_restraints_manager = cmdline.geometry,
      wavelength = cmdline.params.input.wavelength,
      params = cmdline.params,
      nproc = cmdline.params.nproc,
      log = null_out,
      manager_class = ions.svm.manager,
      )

    # Build a list of properties of each water / ion site
    waters = []
    for chain in manager.pdb_hierarchy.only_model().chains():
      for residue_group in chain.residue_groups():
        atom_groups = residue_group.atom_groups()
        if (len(atom_groups) > 1) : # alt conf, skip
          continue
        for atom_group in atom_groups :
          # Check for non standard atoms in the residue
          # Or a label indicating the residue is a water
          resname = atom_group.resname.strip().upper()

          if (resname in WATER_RES_NAMES) :
            atoms = atom_group.atoms()
            if (len(atoms) == 1) : # otherwise it probably has hydrogens, skip
              waters.append(atoms[0].i_seq)

    assert len(waters) > 0

    atom_props = [AtomProperties(i_seq, manager) for i_seq in waters]

    for atom_prop in atom_props:
      i_seq = atom_prop.i_seq
      chem_env = ChemicalEnvironment(
        i_seq,
        manager.find_nearby_atoms(i_seq, far_distance_cutoff = 3.5),
        manager,
        )
      scatter_env = ScatteringEnvironment(
        i_seq, manager,
        fo_density = manager.get_map_gaussian_fit("mFo", i_seq),
        fofc_density = manager.get_map_gaussian_fit("mFo-DFc", i_seq),
        anom_density = manager.get_map_gaussian_fit("anom", i_seq),
        )
      resname = ion_class(chem_env)
      assert resname != ""

      predictions = predict_ion(chem_env, scatter_env,
                                elements = ["HOH", "ZN", "CA"])
      if predictions is None:
        print "Could not load SVM classifier"
        print "Skipping {}".format(os.path.split(__file__)[1])
        return

      if resname != predictions[0][0]:
        print "Prediction ({}) did not match expected: {}" \
          .format(predictions[0][0], resname)
        for element, prob in predictions:
          print "  {}: {:.2f}".format(element, prob)
        sys.exit()

  print "OK"
Exemple #7
0
def exercise():
  wavelength = 1.025
  mtz_file, pdb_file = generate_zinc_inputs(anonymize = False)
  null_out = libtbx.utils.null_out()

  cmdline = mmtbx.command_line.load_model_and_data(
    args = [pdb_file, mtz_file, "wavelength={}".format(wavelength),
            "use_phaser=False", "use_svm=True"],
    master_phil = master_phil(),
    out = null_out,
    process_pdb_file = True,
    create_fmodel = True,
    prefer_anomalous = True
    )

  os.remove(pdb_file)
  os.remove(mtz_file)
  os.remove(os.path.splitext(pdb_file)[0] + "_fmodel.eff")

  cmdline.xray_structure.set_inelastic_form_factors(
    photon = cmdline.params.input.wavelength,
    table = "sasaki"
    )

  cmdline.fmodel.update_xray_structure(
    cmdline.xray_structure,
    update_f_calc = True
    )

  manager = ions.identify.create_manager(
    pdb_hierarchy = cmdline.pdb_hierarchy,
    fmodel = cmdline.fmodel,
    geometry_restraints_manager = cmdline.geometry,
    wavelength = cmdline.params.input.wavelength,
    params = cmdline.params,
    nproc = cmdline.params.nproc,
    log = null_out
    )

  manager.validate_ions(
    out = null_out
    )

  for atom_props in manager.atoms_to_props.values():
    i_seq = atom_props.i_seq
    chem_env = ChemicalEnvironment(
      i_seq,
      manager.find_nearby_atoms(i_seq, far_distance_cutoff = 3.5),
      manager
      )
    scatter_env = ScatteringEnvironment(
      i_seq, manager,
      fo_density = manager.get_map_gaussian_fit("mFo", i_seq),
      fofc_density = manager.get_map_gaussian_fit("mFo-DFc", i_seq),
      anom_density = manager.get_map_gaussian_fit("anom", i_seq),
      )
    vector = ion_vector(chem_env, scatter_env)
    resname = ion_class(chem_env)
    assert vector is not None
    assert resname != ""

  print "OK"