コード例 #1
0
def exercise(pdb_str, use_ideal_bonds_angles):
    # --------------------------------------------------------------
    #          code to switch off CDL
    # --------------------------------------------------------------
    #params_line = grand_master_phil_str
    #params = iotbx.phil.parse(
    #    input_string=params_line, process_includes=True).extract()
    #params.pdb_interpretation.restraints_library.cdl=False
    # ---------------------------------------------------------------

    pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None)
    model = mmtbx.model.manager(model_input=pdb_inp,
                                log=null_out(),
                                build_grm=True)

    pdb_hierarchy = model.get_hierarchy()
    geometry_restraints = model.get_restraints_manager().geometry
    xray_structure = model.get_xray_structure()

    sites_cart = model.get_sites_cart()

    grf = cctbx.geometry_restraints.flags.flags(default=True)
    minimized = mmtbx.refinement.geometry_minimization.lbfgs(
        sites_cart=sites_cart,
        correct_special_position_tolerance=1.0,
        geometry_restraints_manager=geometry_restraints,
        geometry_restraints_flags=grf,
        lbfgs_termination_params=scitbx.lbfgs.termination_parameters(
            max_iterations=500))
    xray_structure.set_sites_cart(sites_cart)
    pdb_hierarchy.adopt_xray_structure(xray_structure)
    atoms = pdb_hierarchy.atoms()
    sites_cart = xray_structure.sites_cart()

    riding_h_manager = riding.manager(
        pdb_hierarchy=pdb_hierarchy,
        geometry_restraints=geometry_restraints,
        use_ideal_bonds_angles=use_ideal_bonds_angles)

    h_parameterization = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)
    h_distances = diagnostics.h_distances

    number_h = model.get_hd_selection().count(True)
    number_h_para = len(h_parameterization) - h_parameterization.count(None)

    assert (number_h_para == number_h), 'Not all H atoms are parameterized'

    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        if use_ideal_bonds_angles:
            assert (h_distances[ih] < 0.03), \
              'distance too large: %s  atom: %s (%s) residue: %s ' \
              % (h_parameterization[ih].htype, atoms[ih].name, ih, labels.resseq.strip())
        else:
            assert (h_distances[ih] < 1e-7), \
              'distance too large: %s  atom: %s (%s) residue: %s  distance %s' \
              % (h_parameterization[ih].htype, atoms[ih].name, ih, labels.resseq.strip(), h_distances[ih])
コード例 #2
0
def exercise(pdb_str, eps):
    mon_lib_srv = monomer_library.server.server()
    ener_lib = monomer_library.server.ener_lib()
    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        raw_records=pdb_str,
        force_symmetry=True)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    xray_structure = processed_pdb_file.xray_structure()

    geometry = processed_pdb_file.geometry_restraints_manager(
        show_energies=False, plain_pairs_radius=5.0)
    #
    riding_h_manager = riding.manager(pdb_hierarchy=pdb_hierarchy,
                                      geometry_restraints=geometry)

    riding_h_manager.idealize(xray_structure=xray_structure)

    sites_cart = xray_structure.sites_cart()

    g_analytical = geometry.energies_sites(sites_cart=sites_cart,
                                           compute_gradients=True).gradients

    hd_selection = xray_structure.hd_selection()
    g_analytical_reduced = riding_h_manager.gradients_reduced_cpp(
        gradients=g_analytical,
        sites_cart=sites_cart,
        hd_selection=hd_selection)

    #
    ex = [eps, 0, 0]
    ey = [0, eps, 0]
    ez = [0, 0, eps]
    g_fd = flex.vec3_double()
    for i_site in xrange(sites_cart.size()):
        g_fd_i = []
        for e in [ex, ey, ez]:
            ts = []
            for sign in [-1, 1]:
                sites_cart_ = sites_cart.deep_copy()
                xray_structure_ = xray_structure.deep_copy_scatterers()
                sites_cart_[i_site] = [
                    sites_cart_[i_site][j] + e[j] * sign for j in xrange(3)
                ]
                xray_structure_.set_sites_cart(sites_cart_)
                # after shift, recalculate H position
                riding_h_manager.idealize(xray_structure=xray_structure_)
                sites_cart_ = xray_structure_.sites_cart()
                ts.append(
                    geometry.energies_sites(sites_cart=sites_cart_,
                                            compute_gradients=False).target)
            g_fd_i.append((ts[1] - ts[0]) / (2 * eps))
        g_fd.append(g_fd_i)

    g_fd_reduced = g_fd.select(~hd_selection)

    for g1, g2 in zip(g_analytical_reduced, g_fd_reduced):
        assert approx_equal(g1, g2, 1.e-4)
コード例 #3
0
def exercise():
    mon_lib_srv = monomer_library.server.server()
    ener_lib = monomer_library.server.ener_lib()

    cif_object = iotbx.cif.reader(input_string=cif_str).model()
    for srv in [mon_lib_srv, ener_lib]:
        srv.process_cif_object(cif_object=cif_object)

    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        file_name=None,
        raw_records=pdb_str,
        force_symmetry=True)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    xray_structure = processed_pdb_file.xray_structure()

    geometry_restraints = processed_pdb_file.geometry_restraints_manager(
        show_energies=False)

    sites_cart = xray_structure.sites_cart()
    atoms = pdb_hierarchy.atoms()

    riding_h_manager = riding.manager(pdb_hierarchy=pdb_hierarchy,
                                      geometry_restraints=geometry_restraints)
    h_para = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)
    h_distances = diagnostics.h_distances
    unk_list = diagnostics.unk_list
    number_h_para = diagnostics.number_h_para
    type_list = diagnostics.type_list

    # number of H atoms in structure
    number_h = 0
    for h_bool in xray_structure.hd_selection():
        if h_bool: number_h += 1

    assert (number_h_para == number_h), 'Not all H atoms are parameterized'
    assert(len(unk_list) == 0), \
      'Some H atoms are parameterized with an unknown type'

    for ih in h_distances:
        # One atom is expected to be moved
        if (ih == 16):
            continue
        labels = atoms[ih].fetch_labels()
        assert (h_distances[ih] < 0.1), \
          'distance too large: %s  atom: %s (%s) residue: %s ' \
          % (h_para[ih].htype, atoms[ih].name, ih, labels.resseq.strip())

    for type1, type2 in zip(type_list, type_list_known):
        assert (type1 == type2)
コード例 #4
0
def run():
  mon_lib_srv = monomer_library.server.server()
  ener_lib = monomer_library.server.ener_lib()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv    = mon_lib_srv,
    ener_lib       = ener_lib,
    file_name      = None,
    raw_records    = pdb_str,
    force_symmetry = True)
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xray_structure = processed_pdb_file.xray_structure()
  pdb_hierarchy.write_pdb_file(
    file_name        = "distorted.pdb",
    crystal_symmetry = xray_structure.crystal_symmetry())
  geometry_restraints = processed_pdb_file.geometry_restraints_manager(
    show_energies = False)
  #geometry_restraints.write_geo_file(file_name='start.geo')
  states = mmtbx.utils.states(
    xray_structure = xray_structure,
    pdb_hierarchy  = pdb_hierarchy)
  states.add(sites_cart = xray_structure.sites_cart())

  riding_h_manager = riding.manager(
    pdb_hierarchy       = pdb_hierarchy,
    geometry_restraints = geometry_restraints)

  # save shaked model in states
  states.add(sites_cart = xray_structure.sites_cart())
  #
  #xray_structure.scatterers().flags_set_grads(state=False)
  xray_structure.scatterers().flags_set_grad_site(
    iselection = xray_structure.all_selection().iselection())
  #xray_structure.show_scatterer_flags_summary()

  use_riding = True
  minimized = lbfgs(
    xray_structure      = xray_structure,
    states              = states,
    geometry_restraints = geometry_restraints,
    riding_h_manager    = riding_h_manager,
    use_riding          = use_riding,
    verbose             = 0)
  minimized.states.write(
    file_name        = "minimized_all_states.pdb",
    crystal_symmetry = xray_structure.crystal_symmetry())
  pdb_hierarchy.adopt_xray_structure(minimized.xray_structure)
  pdb_hierarchy.write_pdb_file(
    file_name        = "minimized.pdb",
    crystal_symmetry = xray_structure.crystal_symmetry())

  target_final = geometry_restraints.energies_sites(
    sites_cart = xray_structure.sites_cart(),
    compute_gradients = True).target
  assert (target_final < 1.5), 'Target of final riding model is too large'
コード例 #5
0
def exercise():
    mon_lib_srv = monomer_library.server.server()
    ener_lib = monomer_library.server.ener_lib()
    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        file_name=None,
        raw_records=pdb_str,
        force_symmetry=True)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    xray_structure = processed_pdb_file.xray_structure()

    geometry_restraints = processed_pdb_file.geometry_restraints_manager(
        show_energies=False)

    sites_cart = xray_structure.sites_cart()
    atoms = pdb_hierarchy.atoms()

    riding_h_manager = riding.manager(pdb_hierarchy=pdb_hierarchy,
                                      geometry_restraints=geometry_restraints)

    h_parameterization = riding_h_manager.h_parameterization

    diagnostics = parameterization.diagnostics_parameterization(
        connectivity_obj=riding_h_manager.connectivity_obj,
        h_parameterization=h_parameterization,
        sites_cart=sites_cart,
        threshold=0.05)

    h_distances = diagnostics.h_distances
    unk_list = diagnostics.unk_list

    # There are 90 H atoms in the pdb_string, check if all of them are recognized
    assert (len(
        h_parameterization.keys()) == 90), 'Not all H atoms are parameterized'

    # For each H atom, check if distance between computed H and that in input model is
    # not too large
    type_list = []
    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        hp = h_parameterization[ih]
        type_list.append(hp.htype)
        assert (h_distances[ih] < 0.03), 'distance too large: %s  atom: %s (%s) residue: %s ' \
          % (hp.htype, atoms[ih].name, ih, labels.resseq.strip())

# Check if there are atoms with unknown parameterization
    assert (len(unk_list) == 0), 'Some H atoms are not recognized'

    # Check that parameterization types are correct
    assert (len(h_parameterization) == 90), 'Fewer H atoms than expected'
    for type1, type2 in zip(type_list, type_list_known):
        assert (type1 == type2)
コード例 #6
0
def exercise():
    mon_lib_srv = monomer_library.server.server()
    ener_lib = monomer_library.server.ener_lib()
    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        file_name=None,
        raw_records=pdb_str,
        force_symmetry=True)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    xray_structure = processed_pdb_file.xray_structure()

    geometry_restraints = processed_pdb_file.geometry_restraints_manager(
        show_energies=False)

    sites_cart = xray_structure.sites_cart()
    atoms = pdb_hierarchy.atoms()

    riding_h_manager = riding.manager(pdb_hierarchy=pdb_hierarchy,
                                      geometry_restraints=geometry_restraints)
    h_parameterization = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)
    h_distances = diagnostics.h_distances
    unk_list = diagnostics.unk_list
    number_h_para = diagnostics.number_h_para
    type_list = diagnostics.type_list

    # number of H atoms in structure
    number_h = 0
    for h_bool in xray_structure.hd_selection():
        if h_bool: number_h += 1

# There are 90 H atoms in pdb_string, check if all of them are recognized and
# that none of them has unknown type
    assert (number_h_para == number_h), 'Not all H atoms are parameterized'
    assert(len(unk_list) == 0), \
      'Some H atoms are parameterized with an unknown type'

    # For every H , check if distance between computed H and H in input model is
    # < 0.03 A
    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        assert (h_distances[ih] < 0.03), 'distance too large: %s  atom: %s (%s) residue: %s ' \
          % (h_parameterization[ih].htype, atoms[ih].name, ih, labels.resseq.strip())

# Check if parameterization types are correct
    for type1, type2 in zip(type_list, type_list_known):
        assert (type1 == type2)
コード例 #7
0
def exercise(pdb_str):
    mon_lib_srv = monomer_library.server.server()
    ener_lib = monomer_library.server.ener_lib()
    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        file_name=None,
        raw_records=pdb_str,
        restraints_loading_flags={"use_neutron_distances": True},
        force_symmetry=True)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    xray_structure = processed_pdb_file.xray_structure()

    geometry_restraints = processed_pdb_file.geometry_restraints_manager(
        show_energies=False)

    sites_cart = xray_structure.sites_cart()
    atoms = pdb_hierarchy.atoms()

    riding_h_manager = riding.manager(pdb_hierarchy=pdb_hierarchy,
                                      geometry_restraints=geometry_restraints)

    h_parameterization = riding_h_manager.h_parameterization

    diagnostics = parameterization.diagnostics_parameterization(
        connectivity_obj=riding_h_manager.connectivity_obj,
        h_parameterization=h_parameterization,
        sites_cart=sites_cart,
        threshold=0.05)

    h_distances = diagnostics.h_distances
    unk_list = diagnostics.unk_list
    number_h = diagnostics.number_h

    # For each H atom, check if distance between computed H and that in input model is
    # not too large
    type_list = []
    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        hp = h_parameterization[ih]
        type_list.append(hp.htype)
        assert (h_distances[ih] < 0.1), 'distance too large: %s  atom: %s (%s) residue: %s ' \
          % (hp.htype, atoms[ih].name, ih, labels.resseq.strip())


#
    assert (len(unk_list) == 0), 'Some H atoms are not recognized'
    if (pdb_str != pdb_str_02):
        assert (number_h == len(h_parameterization.keys())), \
          'Not all H atoms are parameterized'
コード例 #8
0
def exercise():
  mon_lib_srv = monomer_library.server.server()
  ener_lib = monomer_library.server.ener_lib()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv    = mon_lib_srv,
    ener_lib       = ener_lib,
    file_name      = None,
    raw_records    = pdb_str,
    force_symmetry = True)
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xray_structure = processed_pdb_file.xray_structure()

  geometry_restraints = processed_pdb_file.geometry_restraints_manager(
    show_energies = False)

  sites_cart = xray_structure.sites_cart()
  atoms = pdb_hierarchy.atoms()

  riding_h_manager = riding.manager(
    pdb_hierarchy           = pdb_hierarchy,
    geometry_restraints = geometry_restraints)

  h_parameterization = riding_h_manager.h_parameterization
  diagnostics = parameterization.diagnostics_parameterization(
    connectivity_obj   = riding_h_manager.connectivity_obj,
    h_parameterization = h_parameterization,
    sites_cart         = sites_cart,
    threshold          = 0.05)

  h_distances        = diagnostics.h_distances
  unk_list           = diagnostics.unk_list

# There are 53 H atoms in the pdb_string, check if all of them are recognized
# Note: one H atom (VAL 7 HA) is bound to two CA atoms at once
  assert (len(h_parameterization.keys()) == 68), \
    'Not all H atoms are parameterized'

  type_list = []
  for ih in h_distances:
    labels = atoms[ih].fetch_labels()
    hp = h_parameterization[ih]
    type_list.append(hp.htype)
    assert (h_distances[ih] < 0.2), \
      'distance too large: %s  atom: %s (%s) residue: %s ' \
      % (hp.htype, atoms[ih].name, ih, labels.resseq.strip())

  assert(len(unk_list) == 0), 'Some H atoms are not recognized'

  for type1, type2 in zip(type_list, type_list_known):
    assert (type1 == type2)
コード例 #9
0
def exercise(pdb_str):
    mon_lib_srv = monomer_library.server.server()
    ener_lib = monomer_library.server.ener_lib()
    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        file_name=None,
        raw_records=pdb_str,
        restraints_loading_flags={"use_neutron_distances": True},
        force_symmetry=True)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    xray_structure = processed_pdb_file.xray_structure()

    geometry_restraints = processed_pdb_file.geometry_restraints_manager(
        show_energies=False)

    sites_cart = xray_structure.sites_cart()
    atoms = pdb_hierarchy.atoms()

    riding_h_manager = riding.manager(pdb_hierarchy=pdb_hierarchy,
                                      geometry_restraints=geometry_restraints)
    h_parameterization = riding_h_manager.h_parameterization

    diagnostics = riding_h_manager.diagnostics(sites_cart=sites_cart,
                                               threshold=0.05)
    h_distances = diagnostics.h_distances
    unk_list = diagnostics.unk_list
    number_h_para = diagnostics.number_h_para

    # number of H atoms in structure
    number_h = 0
    for h_bool in xray_structure.hd_selection():
        if h_bool: number_h += 1

    if (pdb_str != pdb_str_02):
        assert (number_h_para == number_h), 'Not all H atoms are parameterized'
    assert(len(unk_list) == 0), \
      'Some H atoms are parameterized with an unknown type'

    # For each H atom, check if distance between computed H and that in input model is
    # not too large
    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        assert (h_distances[ih] < 0.1), \
          'distance too large: %s  atom: %s (%s) residue: %s ' \
          % (h_parameterization[ih].htype, atoms[ih].name, ih, labels.resseq.strip())
コード例 #10
0
def exercise():
    mon_lib_srv = monomer_library.server.server()
    ener_lib = monomer_library.server.ener_lib()
    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        file_name=None,
        raw_records=pdb_str,
        force_symmetry=True)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    geometry_restraints = processed_pdb_file.geometry_restraints_manager(
        show_energies=False)

    # necessary for comparison
    xray_structure = processed_pdb_file.xray_structure()
    restraints_manager = mmtbx.restraints.manager(geometry=geometry_restraints,
                                                  normalization=False)
    angle_proxies = restraints_manager.geometry.get_all_angle_proxies()

    riding_h_manager = riding.manager(pdb_hierarchy=pdb_hierarchy,
                                      geometry_restraints=geometry_restraints)
    h_connectivity = riding_h_manager.h_connectivity

    # get bonds stored in connectivity
    bond_list = {}
    angle_list = {}
    for neighbors in h_connectivity:
        if (neighbors is None): continue
        ih = neighbors.ih
        a0 = neighbors.a0
        i_a0 = a0['iseq']
        a1 = neighbors.a1
        i_a1 = a1['iseq']
        bond_list[ih] = [i_a0, a0['dist_ideal']]
        selected_atoms = tuple(sorted([ih, i_a0, i_a1]))
        angle_list[selected_atoms] = a1['angle_ideal']
        if neighbors.a2:
            a2 = neighbors.a2
            selected_atoms2 = tuple(sorted([ih, i_a0, a2['iseq']]))
            angle_list[selected_atoms2] = a2['angle_ideal']
        if neighbors.a3:
            a3 = neighbors.a3
            selected_atoms3 = tuple(sorted([ih, i_a0, a3['iseq']]))
            angle_list[selected_atoms3] = a3['angle_ideal']
        if neighbors.h1:
            h1 = neighbors.h1
            selected_atoms4 = tuple(sorted([ih, i_a0, h1['iseq']]))
            angle_list[selected_atoms4] = h1['angle_ideal']
        if neighbors.b1:
            i_b1 = neighbors.b1['iseq']
            third_nb_dict = {ih: i_b1}

# determine bonds from pdb_str
    model = mmtbx.model.manager(restraints_manager=restraints_manager,
                                xray_structure=xray_structure,
                                pdb_hierarchy=pdb_hierarchy)
    bond_ctrl = {}
    for i in model.xh_connectivity_table():
        bond_ctrl[i[1]] = [i[0], i[3]]

# List of angle restraints
    angles = [(4, 1, 12), (0, 1, 12), (2, 1, 12), (13, 4, 14), (5, 4, 14),
              (5, 4, 13), (1, 4, 13), (1, 4, 14), (8, 6, 15), (5, 6, 15),
              (9, 7, 16), (5, 7, 16), (10, 8, 17), (6, 8, 17), (10, 11, 19),
              (7, 9, 18), (10, 9, 18)]

    angle_ctrl = {}
    for ap in angle_proxies:
        if (ap.i_seqs in angles):
            angle_ctrl[tuple(sorted(list(ap.i_seqs)))] = ap.angle_ideal


# HH needs also third neighbors:
    third_nb_ctrl = {19: 8}

    assert (
        bond_list == bond_ctrl), '1-2 neighbors and distance_ideal are wrong'
    assert (
        angle_list == angle_ctrl), '1-3 neighbors and angle_ideal are wrong'
    assert (third_nb_dict == third_nb_ctrl), '1-4 neighbors are wrong'
コード例 #11
0
def exercise():
  mon_lib_srv = monomer_library.server.server()
  ener_lib = monomer_library.server.ener_lib()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv    = mon_lib_srv,
    ener_lib       = ener_lib,
    file_name      = None,
    raw_records    = pdb_str,
    force_symmetry = True)
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xray_structure = processed_pdb_file.xray_structure()

  geometry_restraints = processed_pdb_file.geometry_restraints_manager(
    show_energies = False)

  sites_cart = xray_structure.sites_cart()
  atoms = pdb_hierarchy.atoms()

  riding_h_manager = riding.manager(
    pdb_hierarchy           = pdb_hierarchy,
    geometry_restraints = geometry_restraints)
  h_connectivity = riding_h_manager.h_connectivity
  h_parameterization = riding_h_manager.h_parameterization

  diagnostics = riding_h_manager.diagnostics(
    sites_cart         = sites_cart,
    threshold          = 0.05)

  h_distances        = diagnostics.h_distances
  unk_list           = diagnostics.unk_list
  type_list          = diagnostics.type_list
  number_h_para      = diagnostics.number_h_para
  #unk_ideal_list     = diagnostics.unk_ideal_list
  #long_distance_list = diagnostics.long_distance_list
  #slipped            = diagnostics.slipped

# number of H atoms in structure
  number_h = 0
  for h_bool in xray_structure.hd_selection():
    if h_bool: number_h += 1

# There are 152 H atoms in pdb_string, check if all of them are parameterized
  assert (number_h_para == number_h), 'Not all H atoms are parameterized'
  assert (number_h_para == len(type_list)), \
    'Some H atoms are parameterized with an unknown type'
  # redundant?
  #assert(len(unk_list) == 0), 'Some H atoms are not recognized'

# For each H atom, check if distance compared to input model is not > 0.05
# 0.0014 = uncertainty for distance if uncertainty of coordinate = 0.001
  for ih in h_distances:
    labels = atoms[ih].fetch_labels()
    assert (h_distances[ih] < 0.05), 'distance too large: %s  atom: %s (%s) residue: %s ' \
      % (h_parameterization[ih].htype, atoms[ih].name, ih, labels.resseq.strip())

# KEEP: useful for debugging
  #for ih in h_parameterization.keys():
  #  hp = h_parameterization[ih]
  #  print "'"+hp.htype+"'"+',',

  for type1, type2 in zip(type_list, type_list_known):
    assert (type1 == type2)
コード例 #12
0
def exercise(pdb_str, eps):
  mon_lib_srv = monomer_library.server.server()
  ener_lib = monomer_library.server.ener_lib()
  processed_pdb_file = monomer_library.pdb_interpretation.process(
    mon_lib_srv    = mon_lib_srv,
    ener_lib       = ener_lib,
    raw_records    = pdb_str,
    force_symmetry = True)
  pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
  xray_structure = processed_pdb_file.xray_structure()
  sites_cart = xray_structure.sites_cart()
  geometry = processed_pdb_file.geometry_restraints_manager(
    show_energies      = False,
    plain_pairs_radius = 5.0)

  es = geometry.energies_sites(
    sites_cart = sites_cart,
    compute_gradients = True)
  g_analytical = es.gradients
#
  riding_h_manager = riding.manager(
    pdb_hierarchy       = pdb_hierarchy,
    geometry_restraints = geometry)

  h_parameterization = riding_h_manager.h_parameterization

  riding_h_manager.idealize_hydrogens_inplace(
      pdb_hierarchy=pdb_hierarchy,
      xray_structure=xray_structure)
  #sites_cart = pdb_hierarchy.atoms().extract_xyz()
  sites_cart = xray_structure.sites_cart()

  #for i in g_analytical:
  #  print i
  #print '----------'
  g_analytical = geometry.energies_sites(
    sites_cart = sites_cart, compute_gradients = True).gradients
  modify_gradients.modify_gradients(
    sites_cart         = sites_cart,
    h_parameterization = h_parameterization,
    grads              = g_analytical)
  #
  ex = [eps,0,0]
  ey = [0,eps,0]
  ez = [0,0,eps]
  g_fd = flex.vec3_double()
  for i_site in xrange(sites_cart.size()):
    g_fd_i = []
    for e in [ex,ey,ez]:
      ts = []
      for sign in [-1,1]:
        sites_cart_ = sites_cart.deep_copy()
        xray_structure_ = xray_structure.deep_copy_scatterers()
        sites_cart_[i_site] = [
          sites_cart_[i_site][j]+e[j]*sign for j in xrange(3)]
        xray_structure_.set_sites_cart(sites_cart_)
        # after shift, recalculate H position
        riding_h_manager.idealize_hydrogens_inplace(
          xray_structure=xray_structure_)
        sites_cart_ = xray_structure_.sites_cart()
        ts.append(geometry.energies_sites(
          sites_cart = sites_cart_,
          compute_gradients = False).target)
      g_fd_i.append((ts[1]-ts[0])/(2*eps))
    g_fd.append(g_fd_i)

  for g1, g2 in zip(g_analytical, g_fd):
    #print g1,g2
    assert approx_equal(g1,g2, 1.e-4)
コード例 #13
0
def exercise():
    mon_lib_srv = monomer_library.server.server()
    ener_lib = monomer_library.server.ener_lib()
    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        file_name=None,
        raw_records=pdb_str,
        force_symmetry=True)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    geometry_restraints = processed_pdb_file.geometry_restraints_manager(
        show_energies=False)

    # necessary for comparison
    xray_structure = processed_pdb_file.xray_structure()
    restraints_manager = mmtbx.restraints.manager(geometry=geometry_restraints,
                                                  normalization=False)
    angle_proxies = restraints_manager.geometry.get_all_angle_proxies()

    riding_h_manager = riding.manager(pdb_hierarchy=pdb_hierarchy,
                                      geometry_restraints=geometry_restraints)
    h_connectivity = riding_h_manager.h_connectivity

    bond_list = {}
    angle_list = {}
    third_nb_list = {}
    for ih in h_connectivity.keys():
        a0 = (h_connectivity[ih][0])
        bond_list[ih] = [a0.iseq, a0.dist_ideal]
        for atom in h_connectivity[ih][1] + h_connectivity[ih][2]:
            helper = tuple(sorted([ih, a0.iseq, atom.iseq]))
            angle_list[helper] = atom.angle_ideal
        if (len(h_connectivity[ih]) == 4):
            third_nb_list[ih] = []
            for third in h_connectivity[ih][3]:
                third_nb_list[ih].append(third.iseq)

#-----------------------------------------------------------------------------
# This is useful to keep for debugging: human readable output of connectivity
#-----------------------------------------------------------------------------
#  for ih in connectivity.keys():
#    if(len(connectivity[ih])==3):
#      string = (" ".join([names[p.iseq] for p in connectivity[ih][2]]))
#    else:
#      string = 'n/a'
#    print  names[ih],': ', names[(connectivity[ih][0][0]).iseq], \
#      ',', (" ".join([names[p.iseq] for p in connectivity[ih][1]])), \
#      ',', string
#-----------------------------------------------------------------------------

# determine bonds from pdb_str
    model = mmtbx.model.manager(restraints_manager=restraints_manager,
                                xray_structure=xray_structure,
                                pdb_hierarchy=pdb_hierarchy)
    bond_ctrl = {}
    for i in model.xh_connectivity_table():
        bond_ctrl[i[1]] = [i[0], i[3]]

# List of angle restraints
    angles = [(4, 1, 12), (2, 1, 12), (0, 1, 12), (13, 4, 14), (5, 4, 14),
              (5, 4, 13), (1, 4, 13), (1, 4, 14), (8, 6, 15), (5, 6, 15),
              (9, 7, 16), (5, 7, 16), (10, 8, 17), (6, 8, 17), (10, 11, 19),
              (7, 9, 18), (10, 9, 18)]

    angle_ctrl = {}
    for ap in angle_proxies:
        if (ap.i_seqs in angles):
            angle_ctrl[tuple(sorted(list(ap.i_seqs)))] = ap.angle_ideal


# HH needs also third neighbors:
    third_nb_ctrl = {19: [8, 9]}

    assert (
        bond_list == bond_ctrl), '1-2 neighbors and distance_ideal are wrong'
    assert (
        angle_list == angle_ctrl), '1-3 neighbors and angle_ideal are wrong'
    assert (third_nb_list == third_nb_ctrl), '1-4 neighbors are wrong'
コード例 #14
0
def exercise(pdb_str, use_ideal_bonds_angles):
    # --------------------------------------------------------------
    #          code to switch off CDL
    # --------------------------------------------------------------
    #params_line = grand_master_phil_str
    #params = iotbx.phil.parse(
    #    input_string=params_line, process_includes=True).extract()
    #params.pdb_interpretation.restraints_library.cdl=False
    # ---------------------------------------------------------------
    mon_lib_srv = monomer_library.server.server()
    ener_lib = monomer_library.server.ener_lib()
    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        file_name=None,
        raw_records=pdb_str,
        force_symmetry=True)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    xray_structure = processed_pdb_file.xray_structure()
    #
    geometry_restraints = processed_pdb_file.geometry_restraints_manager(
        show_energies=False)
    sites_cart = xray_structure.sites_cart()
    atoms = pdb_hierarchy.atoms()

    #  #mol = mmtbx.model.manager(
    #  #  restraints_manager = restraints_manager,
    #  #  xray_structure     = xray_structure,
    #  #  pdb_hierarchy      = pdb_hierarchy)
    #  #mol.geometry_minimization(nonbonded=True)
    #
    grf = cctbx.geometry_restraints.flags.flags(default=True)
    minimized = mmtbx.refinement.geometry_minimization.lbfgs(
        sites_cart=sites_cart,
        correct_special_position_tolerance=1.0,
        geometry_restraints_manager=geometry_restraints,
        geometry_restraints_flags=grf,
        lbfgs_termination_params=scitbx.lbfgs.termination_parameters(
            max_iterations=500))
    xray_structure.set_sites_cart(sites_cart)
    pdb_hierarchy.adopt_xray_structure(xray_structure)
    sites_cart = xray_structure.sites_cart()

    riding_h_manager = riding.manager(
        pdb_hierarchy=pdb_hierarchy,
        geometry_restraints=geometry_restraints,
        use_ideal_bonds_angles=use_ideal_bonds_angles)

    h_parameterization = riding_h_manager.h_parameterization

    diagnostics = parameterization.diagnostics_parameterization(
        connectivity_obj=riding_h_manager.connectivity_obj,
        h_parameterization=h_parameterization,
        sites_cart=sites_cart,
        threshold=0.05)

    h_distances = diagnostics.h_distances
    unk_list = diagnostics.unk_list
    number_h = diagnostics.number_h

    #type_list = []
    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        hp = h_parameterization[ih]
        #type_list.append(hp.htype)
        if use_ideal_bonds_angles:
            assert (h_distances[ih] < 0.03), \
              'distance too large: %s  atom: %s (%s) residue: %s ' \
              % (hp.htype, atoms[ih].name, ih, labels.resseq.strip())
        else:
            assert (h_distances[ih] < 1e-8), \
              'distance too large: %s  atom: %s (%s) residue: %s ' \
              % (hp.htype, atoms[ih].name, ih, labels.resseq.strip())
        print 'type: %s distance: %s  atom: %s (%s) residue: %s ' % \
          (hp.htype, h_distances[ih], atoms[ih].name, ih, labels.resseq)

    assert (number_h == len(h_parameterization.keys())), \
      'Not all H atoms are parameterized'
    assert (len(unk_list) == 0), 'Some H atoms are not recognized'
コード例 #15
0
def exercise():
    mon_lib_srv = monomer_library.server.server()
    ener_lib = monomer_library.server.ener_lib()
    processed_pdb_file = monomer_library.pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        file_name=None,
        raw_records=pdb_str,
        force_symmetry=True)
    pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy
    xray_structure = processed_pdb_file.xray_structure()

    geometry_restraints = processed_pdb_file.geometry_restraints_manager(
        show_energies=False)

    sites_cart = xray_structure.sites_cart()
    atoms = pdb_hierarchy.atoms()

    riding_h_manager = riding.manager(pdb_hierarchy=pdb_hierarchy,
                                      geometry_restraints=geometry_restraints)

    h_parameterization = riding_h_manager.h_parameterization
    h_connectivity = riding_h_manager.h_connectivity

    diagnostics = parameterization.diagnostics_parameterization(
        connectivity_obj=riding_h_manager.connectivity_obj,
        h_parameterization=h_parameterization,
        sites_cart=sites_cart,
        threshold=0.05)

    #number_h           = diagnostics.number_h
    #double_H           = diagnostics.double_H
    h_distances = diagnostics.h_distances
    unk_list = diagnostics.unk_list
    #unk_ideal_list     = diagnostics.unk_ideal_list
    #long_distance_list = diagnostics.long_distance_list
    #n_connect          = diagnostics.n_connect
    #slipped            = diagnostics.slipped

    # There are 152 H atoms in the pdb_string, check if all of them are recognized
    assert (len(
        h_parameterization.keys()) == 152), 'Not all H atoms are parameterized'

    # For each H atom, check if distance compared to input model is not > 0.05
    # 0.0014 = uncertainty for distance if uncertainty of coordinate = 0.001
    type_list = []
    for ih in h_distances:
        labels = atoms[ih].fetch_labels()
        hp = h_parameterization[ih]
        type_list.append(hp.htype)
        assert (h_distances[ih] < 0.05), 'distance too large: %s  atom: %s (%s) residue: %s ' \
          % (hp.htype, atoms[ih].name, ih, labels.resseq.strip())

# KEEP: useful for debugging
#for ih in h_parameterization.keys():
#  hp = h_parameterization[ih]
#  print "'"+hp.htype+"'"+',',
#
    assert (len(unk_list) == 0), 'Some H atoms are not recognized'

    for type1, type2 in zip(type_list, type_list_known):
        assert (type1 == type2)