Exemplo n.º 1
0
def test_addition_scatterers():
  '''
  Test overlaps when adding and moving scatterers
  Test water scatterers with and without labels
  '''
  clashes = get_clashes_result(raw_records=raw_records_3)
  results = clashes.get_results()
  assert(results.n_clashes == 3)
  assert approx_equal(results.clashscore, 1000, eps=0.1)

  # Add water scatterers
  model = clashes.model
  xrs = model.get_xray_structure()
  new_scatterers = flex.xray_scatterer(
    xrs.scatterers().size(),
    xray.scatterer(occupancy = 1, b = 10, scattering_type = "O"))
  new_sites_frac = xrs.unit_cell().fractionalize(xrs.sites_cart()+[0.5,0,0])
  new_scatterers.set_sites(new_sites_frac)
  new_xrs = xray.structure(
    special_position_settings = xrs,
    scatterers                = new_scatterers)
  model.add_solvent(
    solvent_xray_structure = new_xrs,
    refine_occupancies     = False,
    refine_adp             = "isotropic")

  pnps = pnp.manager(model = model)
  clashes = pnps.get_clashes()
  results = clashes.get_results()

  assert(results.n_clashes == 15)
  assert approx_equal(results.clashscore, 2500, eps=5)
Exemplo n.º 2
0
    def run(self):
        pdb_fn = self.data_manager.get_default_model_name()
        print('Using model file:', pdb_fn, file=self.logger)
        restraint_objects = list()
        if self.data_manager.has_restraints():
            print('Using restraints files',
                  self.data_manager.get_restraint_names(),
                  file=self.logger)
            for filename in self.data_manager.get_restraint_names():
                restraint_objects.append(
                    (filename, self.data_manager.get_restraint(filename)))

        model = self.data_manager.get_model()

        pi_params = model.get_default_pdb_interpretation_params()
        pi_params.pdb_interpretation.clash_guard.nonbonded_distance_threshold = None

        # TODO: below are some non-defaults for pdb_interpretation,
        # but they cannot be changed
        # Do we need the non-defaults?
        # assume_hydrogens_all_missing --> default is False, but becomes True if H are present
        # hard_minimum_nonbonded_distance --> default is 0.001 but is 0 in NBO
        # substitute_non_crystallographic_unit_cell_if_necessary --> not necessary

        # add H atoms with readyset
        params = [
            "add_h_to_water=False",
            "optimise_final_geometry_of_hydrogens=False"
        ]
        assert (libtbx.env.has_module(name="reduce"))
        assert (libtbx.env.has_module(name="elbow"))
        readyset_model = ready_set_model_interface(
            model=model, params=params, keep_temp=self.params.keep_temp)

        readyset_model.set_pdb_interpretation_params(pi_params)
        readyset_model.set_restraint_objects(restraint_objects)
        readyset_model.get_restraints_manager()

        # TODO: do we need macro_mol_sel, do we care?
        # If we use model.select(), we don't need it.
        proxies = readyset_model.all_chain_proxies
        cache = proxies.pdb_hierarchy.atom_selection_cache()
        macro_mol_sel = proxies.selection(cache=cache,
                                          string='protein or dna or rna')

        #t0 = time.time()
        nb_overlaps = nbo.info(model=readyset_model,
                               macro_molecule_selection=macro_mol_sel)
        #t1 = time.time()

        nb_overlaps.show(log=self.logger, nbo_type='all', normalized_nbo=True)

        #t2 = time.time()
        processed_nbps = pnp.manager(model=readyset_model)
        clashes = processed_nbps.get_clashes()
        #t3 = time.time()
        clashes.show(log=self.logger)

        hbonds = processed_nbps.get_hbonds()
        hbonds.show(log=self.logger)
Exemplo n.º 3
0
def get_clashes_result(raw_records, sel=None):
    '''
  Helper function to get clashes results from raw records
  '''
    params = mmtbx.model.manager.get_default_pdb_interpretation_params()
    params.pdb_interpretation.allow_polymer_cross_special_position = True
    params.pdb_interpretation.clash_guard.nonbonded_distance_threshold = None
    pdb_inp = iotbx.pdb.input(lines=raw_records.split("\n"), source_info=None)
    model = mmtbx.model.manager(model_input=pdb_inp, log=null_out())
    model.process(pdb_interpretation_params=params, make_restraints=True)
    if sel is not None:
        model = model.select(sel)

    pnps = pnp.manager(model=model)
    clashes = pnps.get_clashes()
    return clashes
Exemplo n.º 4
0
  def get_overlaps(self):
    '''
    Obtain overlaps involving ligands
    '''
    # A model with H atoms is necessary to process overlaps
    if not self.readyset_model.has_hd():
      return None
    elif self._overlaps is None:
      # sel_within could be done in __init__?
      within_radius = 3.0
      # TODO clashes with other ligands?
      sel_within_str = '%s or (residues_within (%s, %s)) and (protein or water)' \
        % (self.sel_str, within_radius, self.sel_str)
      sel_within = self.readyset_model.selection(sel_within_str)
      isel_ligand_within = self.readyset_model.select(sel_within).iselection(self.sel_str)
      #sel = flex.bool([True]*len(sel_within))
      model_within = self.readyset_model.select(sel_within)

      processed_nbps = pnp.manager(model = model_within)
      clashes = processed_nbps.get_clashes()
      clashes_dict   = clashes._clashes_dict

      ligand_clashes_dict = dict()
      for iseq_tuple, record in clashes_dict.iteritems():
        if (iseq_tuple[0] in isel_ligand_within or
            iseq_tuple[1] in isel_ligand_within):
          ligand_clashes_dict[iseq_tuple] = record

      ligand_clashes = pnp.clashes(
                      clashes_dict = ligand_clashes_dict,
                      model        = model_within)

      string_io = StringIO()
      ligand_clashes.show(log=string_io, show_clashscore=False)
      results = ligand_clashes.get_results()

      self._overlaps = group_args(
        n_clashes      = results.n_clashes,
        clashscore     = results.clashscore,
        n_clashes_sym  = results.n_clashes_sym,
        clashscore_sym = results.clashscore_sym,
        clashes_str    = string_io.getvalue(),
        clashes_dict   = clashes._clashes_dict)

    return self._overlaps
def test_manager_and_clashes_functions():
    '''
  Test some functions of the manager and the clashes class
  '''
    model = obtain_model(raw_records=raw_records_7)
    pnps = pnp.manager(model=model)
    assert (pnps.has_clashes())
    clashes = pnps.get_clashes()
    # sorted by overlap (default)
    assert (clashes._clashes_dict.items()[11][0] == ((38, 39)))
    # sorted by symmetry
    clashes.sort_clashes(sort_symmetry=True)
    assert (clashes._clashes_dict.items()[11][0] == (27, 27))

    assert (clashes.is_clashing(iseq=27))
    assert (clashes.is_clashing(iseq=44))
    assert (clashes.is_clashing(iseq=13))
    assert (clashes.is_clashing(iseq=38))
    assert (clashes.is_clashing(iseq=3))