Ejemplo n.º 1
0
def run(pdb_filename=None,
        pdb_hierarchy=None,
        crystal_symmetry=None,
        model_completion=True,
        original_pdb_filename=None,
        append_to_end_of_model=True,
        ):
  #
  # function as be used in two main modes
  #   1. completing a model with hydrogens in a protein-like manner
  #   2. completing a cluster with hydrogens in a QM-sensible manner
  #
  if pdb_hierarchy:
    assert crystal_symmetry
    assert pdb_filename is None

  if model_completion:
    use_capping_hydrogens=False
    fname = 'complete'
  else:
    use_capping_hydrogens=True
    fname = 'capping'
    #assert 0 # model has H
  params=None
  if use_capping_hydrogens:
    params = hierarchy_utils.get_pdb_interpretation_params()
    params.link_distance_cutoff=1.8
  if pdb_hierarchy:
    raw_records = hierarchy_utils.get_raw_records(
      pdb_inp=None,
      pdb_hierarchy=pdb_hierarchy,
      crystal_symmetry=crystal_symmetry,
    )
    ppf = hierarchy_utils.get_processed_pdb(raw_records=raw_records)
    sites_cart = pdb_hierarchy.atoms().extract_xyz()
    ppf.all_chain_proxies.pdb_hierarchy.atoms().set_xyz(sites_cart)
  else:
    ppf = hierarchy_utils.get_processed_pdb(pdb_filename=pdb_filename,
                                            params=params,
                                          )
  ppf = complete_pdb_hierarchy(
    ppf.all_chain_proxies.pdb_hierarchy,
    ppf.geometry_restraints_manager(),
    use_capping_hydrogens=use_capping_hydrogens,
    append_to_end_of_model=append_to_end_of_model, # needed for clustering
                                                   # code and Molprobity
    pdb_filename=pdb_filename,   # used just for naming of debug output
    pdb_inp=ppf.all_chain_proxies.pdb_inp, # used in get_raw_records. why?
    original_pdb_filename=original_pdb_filename, # used to define breaks in
                                                 # main chain for capping
    verbose=False,
  )
  if pdb_filename:
    output = hierarchy_utils.write_hierarchy(
      pdb_filename,
      ppf.all_chain_proxies.pdb_inp,
      ppf.all_chain_proxies.pdb_hierarchy,
      fname,
    )
  return ppf.all_chain_proxies.pdb_hierarchy
Ejemplo n.º 2
0
def complete_pdb_hierarchy(
    hierarchy,
    geometry_restraints_manager,
    use_capping_hydrogens=False,
    append_to_end_of_model=False,
    pdb_filename=None,
    pdb_inp=None,
    original_pdb_filename=None,
    verbose=False,
    debug=False,
):
    for ag in hierarchy.atom_groups():
        if get_class(ag.resname) in ['common_rna_dna']:
            raise Sorry('')
    from mmtbx.building import extend_sidechains
    params = None
    original_hierarchy = None
    if use_capping_hydrogens:
        params = hierarchy_utils.get_pdb_interpretation_params()
        params.link_distance_cutoff = 1.8  # avoid linking across a single missing AA
        if original_pdb_filename:
            original_pdb_inp = iotbx.pdb.input(original_pdb_filename)
            original_hierarchy = original_pdb_inp.construct_hierarchy()
    if debug:
        output = hierarchy_utils.write_hierarchy(
            pdb_filename,
            pdb_inp,
            hierarchy,
            'temp1',
        )
    #
    # assume model is heavy-atom complete
    #
    if not use_capping_hydrogens:
        if debug:
            ppf = hierarchy_utils.get_processed_pdb(pdb_filename=output)
        else:
            raw_records = hierarchy_utils.get_raw_records(pdb_inp, hierarchy)
            ppf = hierarchy_utils.get_processed_pdb(
                raw_records=raw_records,
                params=params,
            )
            sites_cart = hierarchy.atoms().extract_xyz()
            ppf.all_chain_proxies.pdb_hierarchy.atoms().set_xyz(sites_cart)
        n_changed = extend_sidechains.extend_protein_model(
            ppf.all_chain_proxies.pdb_hierarchy,
            mon_lib_server,
            add_hydrogens=False,
        )
        if debug:
            print 'number of side chains changed', n_changed
            output = hierarchy_utils.write_hierarchy(
                pdb_filename,
                pdb_inp,
                ppf.all_chain_proxies.pdb_hierarchy,
                'temp2',
            )
    #
    # need to use Reduce/ReadySet! to add hydrogens
    #
    if not use_capping_hydrogens:
        output = hierarchy_utils.write_hierarchy(
            pdb_filename,
            pdb_inp,
            ppf.all_chain_proxies.pdb_hierarchy,
            'readyset_input',
        )
        hierarchy = hierarchy_utils.add_hydrogens_using_ReadySet(output)
    #
    # remove side chain acid hydrogens - maybe not required since recent changes
    #
    if debug:
        ppf = hierarchy_utils.get_processed_pdb(
            pdb_filename=output,
            params=params,
        )
    else:
        raw_records = hierarchy_utils.get_raw_records(pdb_inp, hierarchy)
        ppf = hierarchy_utils.get_processed_pdb(
            raw_records=raw_records,
            params=params,
        )
        sites_cart = hierarchy.atoms().extract_xyz()
        ppf.all_chain_proxies.pdb_hierarchy.atoms().set_xyz(sites_cart)
    remove_acid_side_chain_hydrogens(ppf.all_chain_proxies.pdb_hierarchy)
    #
    # add hydrogens in special cases
    #  eg ETA
    #  eg N - H, H2
    #
    if debug:
        ppf = hierarchy_utils.get_processed_pdb(
            pdb_filename=output,
            params=params,
        )
    else:
        hierarchy = ppf.all_chain_proxies.pdb_hierarchy
        raw_records = hierarchy_utils.get_raw_records(pdb_inp, hierarchy)
        ppf = hierarchy_utils.get_processed_pdb(
            raw_records=raw_records,
            params=params,
        )
        sites_cart = hierarchy.atoms().extract_xyz()
        ppf.all_chain_proxies.pdb_hierarchy.atoms().set_xyz(sites_cart)
    special_case_hydrogens(
        ppf.all_chain_proxies.pdb_hierarchy,
        ppf.geometry_restraints_manager(),
        #use_capping_hydrogens=use_capping_hydrogens,
        #append_to_end_of_model=append_to_end_of_model,
        #original_hierarchy=original_hierarchy,
        verbose=verbose,
    )
    #
    # add terminals atoms including hydrogens and OXT - more docs here...
    #
    if debug:
        output = hierarchy_utils.write_hierarchy(
            pdb_filename,
            pdb_inp,
            ppf.all_chain_proxies.pdb_hierarchy,
            'temp3',
        )
        ppf = hierarchy_utils.get_processed_pdb(
            pdb_filename=output,
            params=params,
        )
    else:
        hierarchy = ppf.all_chain_proxies.pdb_hierarchy
        raw_records = hierarchy_utils.get_raw_records(pdb_inp, hierarchy)
        ppf = hierarchy_utils.get_processed_pdb(
            raw_records=raw_records,
            params=params,
        )
        sites_cart = hierarchy.atoms().extract_xyz()
        ppf.all_chain_proxies.pdb_hierarchy.atoms().set_xyz(sites_cart)
    add_terminal_hydrogens(
        ppf.all_chain_proxies.pdb_hierarchy,
        ppf.geometry_restraints_manager(),
        use_capping_hydrogens=use_capping_hydrogens,
        append_to_end_of_model=append_to_end_of_model,
        original_hierarchy=original_hierarchy,
        verbose=verbose,
    )  # in place
    ppf.all_chain_proxies.pdb_hierarchy.atoms(
    ).set_chemical_element_simple_if_necessary()
    ppf.all_chain_proxies.pdb_hierarchy.sort_atoms_in_place()
    #display_hierarchy_atoms(ppf.all_chain_proxies.pdb_hierarchy)
    #ppf.all_chain_proxies.pdb_hierarchy.atoms_reset_serial()
    #ppf.all_chain_proxies.pdb_hierarchy.atoms().reset_i_seq()
    return ppf