def exercise_model_only():
    from mmtbx.building import extend_sidechains
    import iotbx.pdb.hierarchy
    import mmtbx.monomer_library
    pdb_in = iotbx.pdb.hierarchy.input(pdb_string="""
ATOM     65  N   LYS A   7       6.033   4.704   1.582  1.00 17.49           N
ATOM     66  CA  LYS A   7       5.159   5.427   2.499  1.00 18.23           C
ATOM     67  C   LYS A   7       4.673   4.437   3.507  1.00 14.78           C
ATOM     68  O   LYS A   7       4.777   3.208   3.297  1.00 15.83           O
ATOM     69  CB  LYS A   7       3.959   6.057   1.760  1.00 23.56           C
ATOM     70  CG  LYS A   7       4.345   7.215   0.830  1.00 33.58           C
ATOM     71  CD  LYS A   7       3.213   7.570  -0.123  1.00 41.39           C
ATOM     72  CE  LYS A   7       2.976   6.471  -1.165  1.00 48.81           C
""")
    extend_sidechains.extend_protein_model(
        pdb_hierarchy=pdb_in.hierarchy,
        mon_lib_srv=mmtbx.monomer_library.server.server())
    assert (pdb_in.hierarchy.as_pdb_string() == """\
ATOM      1  N   LYS A   7       6.033   4.704   1.582  1.00 17.49           N
ATOM      2  CA  LYS A   7       5.159   5.427   2.499  1.00 18.23           C
ATOM      3  C   LYS A   7       4.673   4.437   3.507  1.00 14.78           C
ATOM      4  O   LYS A   7       4.777   3.208   3.297  1.00 15.83           O
ATOM      5  CB  LYS A   7       3.980   6.048   1.757  1.00 23.56           C
ATOM      6  CG  LYS A   7       4.366   7.205   0.850  1.00 33.58           C
ATOM      7  CD  LYS A   7       3.241   7.559  -0.109  1.00 41.39           C
ATOM      8  CE  LYS A   7       3.011   6.457  -1.129  1.00 48.81           C
ATOM      9  NZ  LYS A   7       1.911   6.790  -2.075  1.00 26.71           N
TER
""")
def exercise_model_only () :
  from mmtbx.building import extend_sidechains
  import iotbx.pdb.hierarchy
  pdb_in = iotbx.pdb.hierarchy.input(pdb_string="""
ATOM     65  N   LYS A   7       6.033   4.704   1.582  1.00 17.49           N
ATOM     66  CA  LYS A   7       5.159   5.427   2.499  1.00 18.23           C
ATOM     67  C   LYS A   7       4.673   4.437   3.507  1.00 14.78           C
ATOM     68  O   LYS A   7       4.777   3.208   3.297  1.00 15.83           O
ATOM     69  CB  LYS A   7       3.959   6.057   1.760  1.00 23.56           C
ATOM     70  CG  LYS A   7       4.345   7.215   0.830  1.00 33.58           C
ATOM     71  CD  LYS A   7       3.213   7.570  -0.123  1.00 41.39           C
ATOM     72  CE  LYS A   7       2.976   6.471  -1.165  1.00 48.81           C
""")
  extend_sidechains.extend_protein_model(
    pdb_hierarchy=pdb_in.hierarchy,
    modify_segids=False,
    log=null_out())
  assert (pdb_in.hierarchy.as_pdb_string() == """\
ATOM      1  N   LYS A   7       6.033   4.704   1.582  1.00 17.49           N
ATOM      2  CA  LYS A   7       5.159   5.427   2.499  1.00 18.23           C
ATOM      3  C   LYS A   7       4.673   4.437   3.507  1.00 14.78           C
ATOM      4  O   LYS A   7       4.777   3.208   3.297  1.00 15.83           O
ATOM      5  CB  LYS A   7       3.959   6.057   1.760  1.00 23.56           C
ATOM      6  CG  LYS A   7       4.368   7.206   0.851  1.00 33.58           C
ATOM      7  CD  LYS A   7       3.242   7.559  -0.108  1.00 41.39           C
ATOM      8  CE  LYS A   7       3.009   6.453  -1.124  1.00 48.81           C
ATOM      9  NZ  LYS A   7       1.909   6.785  -2.070  1.00 48.81           N
TER
""")
def exercise_model_only():
    from mmtbx.building import extend_sidechains
    import iotbx.pdb.hierarchy
    pdb_in = iotbx.pdb.hierarchy.input(pdb_string="""
ATOM     65  N   LYS A   7       6.033   4.704   1.582  1.00 17.49           N
ATOM     66  CA  LYS A   7       5.159   5.427   2.499  1.00 18.23           C
ATOM     67  C   LYS A   7       4.673   4.437   3.507  1.00 14.78           C
ATOM     68  O   LYS A   7       4.777   3.208   3.297  1.00 15.83           O
ATOM     69  CB  LYS A   7       3.959   6.057   1.760  1.00 23.56           C
ATOM     70  CG  LYS A   7       4.345   7.215   0.830  1.00 33.58           C
ATOM     71  CD  LYS A   7       3.213   7.570  -0.123  1.00 41.39           C
ATOM     72  CE  LYS A   7       2.976   6.471  -1.165  1.00 48.81           C
""")
    extend_sidechains.extend_protein_model(pdb_hierarchy=pdb_in.hierarchy,
                                           modify_segids=False,
                                           log=null_out())
    assert (pdb_in.hierarchy.as_pdb_string() == """\
ATOM      1  N   LYS A   7       6.033   4.704   1.582  1.00 17.49           N
ATOM      2  CA  LYS A   7       5.159   5.427   2.499  1.00 18.23           C
ATOM      3  C   LYS A   7       4.673   4.437   3.507  1.00 14.78           C
ATOM      4  O   LYS A   7       4.777   3.208   3.297  1.00 15.83           O
ATOM      5  CB  LYS A   7       3.959   6.057   1.760  1.00 23.56           C
ATOM      6  CG  LYS A   7       4.368   7.206   0.851  1.00 33.58           C
ATOM      7  CD  LYS A   7       3.242   7.559  -0.108  1.00 41.39           C
ATOM      8  CE  LYS A   7       3.009   6.453  -1.124  1.00 48.81           C
ATOM      9  NZ  LYS A   7       1.909   6.785  -2.070  1.00 48.81           N
TER
""")
Esempio n. 4
0
def exercise_do_not_move_if_complete():
    pdb_inp = iotbx.pdb.input(source_info=None,
                              lines=pdb_str_do_no_move_if_complete)
    pdb_h = pdb_inp.construct_hierarchy()
    xyz1 = pdb_h.atoms().extract_xyz()
    pdb_h_completed = pdb_h.deep_copy()
    extend_sidechains.extend_protein_model(pdb_hierarchy=pdb_h_completed,
                                           mon_lib_srv=mon_lib_srv,
                                           add_hydrogens=False)
    xyz2 = pdb_h_completed.atoms().extract_xyz()
    assert approx_equal(flex.max(flex.sqrt((xyz1 - xyz2).dot())), 0.0)
Esempio n. 5
0
def exercise_extend_sidechains(pdb_str_bad, pdb_str_good, i, Sorry_msg, add_h):
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str_bad)
    pdb_h = pdb_inp.construct_hierarchy()
    pdb_h.write_pdb_file(file_name="m_in_%d.pdb" % i)
    pdb_h_bad = pdb_h.deep_copy()
    e = None
    try:
        extend_sidechains.extend_protein_model(pdb_hierarchy=pdb_h,
                                               mon_lib_srv=mon_lib_srv,
                                               add_hydrogens=add_h)
    except Exception, e:
        pass
Esempio n. 6
0
def complete_model(pdb_hierarchy):
    fraction_of_nonH_incomplete = None
    try:
        number_of_residues = len(list(pdb_hierarchy.residue_groups()))
        n_changed = extend_sidechains.extend_protein_model(pdb_hierarchy,
                                                           mon_lib_server,
                                                           add_hydrogens=False)
        fraction_of_nonH_incomplete = n_changed * 100. / number_of_residues
    except KeyboardInterrupt:
        raise
    except Exception, e:
        fraction_of_nonH_incomplete = None
def exercise_extend_sidechains(pdb_str_bad, pdb_str_good, i, Sorry_msg, add_h):
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str_bad)
    pdb_h = pdb_inp.construct_hierarchy()
    pdb_h.write_pdb_file(file_name="m_in_%d.pdb" % i)
    pdb_h_bad = pdb_h.deep_copy()
    e = None
    try:
        extend_sidechains.extend_protein_model(pdb_hierarchy=pdb_h,
                                               mon_lib_srv=mon_lib_srv,
                                               add_hydrogens=add_h)
    except Exception as e:
        if (Sorry_msg is not None):
            assert str(e).find(Sorry_msg) > -1
            return
    #
    pdb_h.write_pdb_file(file_name="m_completed_%d.pdb" % i)
    pdb_h_result = pdb_h.deep_copy()
    #
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str_good)
    pdb_h_answer = pdb_inp.construct_hierarchy()
    pdb_h_answer.write_pdb_file(file_name="m_good_%d.pdb" % i)
    #
    check(answer=pdb_h_answer, result=pdb_h_result, bad=pdb_h_bad)
Esempio n. 8
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
Esempio n. 9
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,
):
    """Complete PDB hierarchy with hydrogen atoms as needed

       This needs to move to Phenix with better functionality

  Args:
      hierarchy (hierarchy): Starting model
      geometry_restraints_manager (GRM): Starting restraints
      use_capping_hydrogens (bool, optional): Capping or not
      append_to_end_of_model (bool, optional): Added atoms go to end of atom list
      pdb_filename (None, optional): Description
      pdb_inp (None, optional): Description
      original_pdb_filename (None, optional): Description
      verbose (bool, optional): Description
      debug (bool, optional): Description

  Returns:
      TYPE: Description

  Raises:
      Sorry: Description
  """
    for ag in hierarchy.atom_groups():
        if get_class(ag.resname) in ['common_rna_dna']:
            raise Sorry('Nucleotides are not currently supported. e.g. %s' %
                        ag.resname)
    from mmtbx.building import extend_sidechains
    original_hierarchy = None
    params = hierarchy_utils.get_pdb_interpretation_params()
    params.restraints_library.cdl = False
    if use_capping_hydrogens:
        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)
    #
    # moved to mmtbx.ligands
    #
    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