示例#1
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"
示例#2
0
def exercise():
  wavelength = 1.025
  mtz_file, pdb_file = generate_zinc_inputs(anonymize=True)
  args = [
    "input.pdb.file_name=" + pdb_file,
    "input.xray_data.file_name=" + mtz_file,
    "wavelength={}".format(wavelength),
    ]
  fully_buffered(
    "phenix.python -m mmtbx.ions.svm.dump_sites " + " ".join(args),
    ).raise_if_errors()

  os.remove(pdb_file)
  os.remove(os.path.splitext(pdb_file)[0][:-4] + ".pdb")
  os.remove(mtz_file)
  # "zn_frag_hoh.pdb" => "zn_frag_fmodel.eff"
  os.remove(os.path.splitext(pdb_file)[0][:-4] + "_fmodel.eff")

  sites_path = os.path.splitext(pdb_file)[0] + "_sites.pkl"
  sites = load(sites_path)

  os.remove(sites_path)

  assert len(sites) == 7
  for chem_env, scatter_env in sites:
    assert chem_env is not None
    assert scatter_env is not None
    for name in chem_env.__slots__:
      if getattr(chem_env, name) is None:
        print "Error: chem_env.{} is not set".format(name)
        sys.exit()
    for name in scatter_env.__slots__:
      # f' is not set by phaser
      if name in ["fp"]:
        continue
      # Only check f'' for heavy metals
      if name != "fpp" or ion_class(chem_env) != "HOH":
        if getattr(scatter_env, name) is None:
          print "Error: scatter_env.{} is not set".format(name)
          sys.exit()

  print "OK"
示例#3
0
def exercise():
    wavelength = 1.025
    mtz_file, pdb_file = generate_zinc_inputs(anonymize=True)
    args = [
        "input.pdb.file_name=" + pdb_file,
        "input.xray_data.file_name=" + mtz_file,
        "wavelength={}".format(wavelength),
    ]
    fully_buffered(
        "phenix.python -m mmtbx.ions.svm.dump_sites " +
        " ".join(args), ).raise_if_errors()

    os.remove(pdb_file)
    os.remove(os.path.splitext(pdb_file)[0][:-4] + ".pdb")
    os.remove(mtz_file)
    # "zn_frag_hoh.pdb" => "zn_frag_fmodel.eff"
    os.remove(os.path.splitext(pdb_file)[0][:-4] + "_fmodel.eff")

    sites_path = os.path.splitext(pdb_file)[0] + "_sites.pkl"
    sites = load(sites_path)

    os.remove(sites_path)

    assert len(sites) == 7
    for chem_env, scatter_env in sites:
        assert chem_env is not None
        assert scatter_env is not None
        for name in chem_env.__slots__:
            if getattr(chem_env, name) is None:
                print "Error: chem_env.{} is not set".format(name)
                sys.exit()
        for name in scatter_env.__slots__:
            # f' is not set by phaser
            if name in ["fp"]:
                continue
            # Only check f'' for heavy metals
            if name != "fpp" or ion_class(chem_env) != "HOH":
                if getattr(scatter_env, name) is None:
                    print "Error: scatter_env.{} is not set".format(name)
                    sys.exit()

    print "OK"
示例#4
0
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"
示例#5
0
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"
示例#6
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"