Esempio n. 1
0
def generate_protein_fragments(
    hierarchy,
    geometry,
    backbone_only=False,
    use_capping_hydrogens=False,
    verbose=False,
):
    from mmtbx.conformation_dependent_library.multi_residue_class import \
      ThreeProteinResidues, RestraintsRegistry
    registry = RestraintsRegistry()
    threes = ThreeProteinResidues(geometry, registry=registry)
    for residue in generate_residues_via_conformer(
            hierarchy,
            backbone_only=backbone_only,
            verbose=verbose,
    ):
        list.append(threes, residue)
        if verbose: print 'THREE', threes
        sub_unit = threes.provide_second_sub_unit_if_unlinked()
        if verbose: print 'THREE, SUBUNIT', threes, sub_unit
        if sub_unit:
            threes.start = True
            threes.end = True
            yield threes
            threes = sub_unit
    threes.start = True
    threes.end = True
    yield threes
Esempio n. 2
0
def update_restraints(
    hierarchy,
    geometry,  # restraints_manager,
    current_geometry=None,  # xray_structure!!
    sites_cart=None,
    cdl_proxies=None,
    ideal=True,
    esd=True,
    esd_factor=1.,
    log=None,
    verbose=False,
):
    global registry
    registry = RestraintsRegistry()
    if current_geometry:
        assert not sites_cart
        sites_cart = current_geometry.sites_cart()
    if sites_cart:
        pdb_atoms = hierarchy.atoms()
        # XXX PDB_TRANSITION VERY SLOW
        for j_seq, atom in enumerate(pdb_atoms):
            atom.xyz = sites_cart[j_seq]

    threes = None
    average_updates = 0
    total_updates = 0
    for threes in generate_protein_threes(
            hierarchy,
            geometry,
            cdl_class=True,
            omega_cdl=True,
            #verbose=verbose,
    ):
        threes.apply_updates = apply_updates
        if threes.cis_group(omega_cdl=True):
            if verbose and 0:
                print 'cis ' * 20
                print threes
            continue

        restraint_values = get_restraint_values(threes)
        if restraint_values is None: continue
        if restraint_values[0] == "I":
            average_updates += 1
        else:
            total_updates += 1
        threes.apply_updates(
            threes,
            restraint_values,
            cdl_proxies,
            ideal=ideal,
            esd=esd,
            esd_factor=esd_factor,
        )
    if registry.n:
        threes.apply_average_updates(registry)
        assert 0
    geometry.reset_internals()
    if verbose and threes and threes.errors:
        if log:
            log.write(
                "  Residues not completely updated with CDL restraints\n\n")
        for line in threes.errors:
            if log:
                log.write("%s\n" % line)
            else:
                print line
    return geometry
Esempio n. 3
0
def update_restraints(
    hierarchy,
    geometry,  # restraints_manager,
    current_geometry=None,  # xray_structure!!
    sites_cart=None,
    cdl_proxies=None,
    ideal=True,
    esd=True,
    esd_factor=1.,
    interpolate=False,
    log=None,
    verbose=False,
):
    global registry
    registry = RestraintsRegistry()
    if current_geometry:
        assert not sites_cart
        sites_cart = current_geometry.sites_cart()
    if sites_cart:
        pdb_atoms = hierarchy.atoms()
        #if atom_lookup:
        #  for j_seq, scatterer in enumerate(current_geometry.scatterers()):
        #    pdb_atoms[atom_lookup[scatterer.label]].xyz = sites_cart[j_seq]
        #else:
        # XXX PDB_TRANSITION VERY SLOW
        for j_seq, atom in enumerate(pdb_atoms):
            atom.xyz = sites_cart[j_seq]
            #atom_lookup[atom.id_str()] = j_seq

    threes = None
    average_updates = 0
    total_updates = 0
    for threes in generate_protein_threes(
            hierarchy,
            geometry,  #restraints_manager,
            #verbose=verbose,
    ):
        if threes.cis_group():
            continue

        if 0:
            res_type_group = get_res_type_group(
                threes[1].resname,
                threes[2].resname,
            )
            if res_type_group is None: continue
            key = threes.get_cdl_key()  #verbose=verbose)
            restraint_values = cdl_database[res_type_group][key]
            print restraint_values
            print len(restraint_values)
            assert 0
        else:
            restraint_values = get_restraint_values(threes,
                                                    interpolate=interpolate)

        #if 1:
        #  print threes, threes.are_linked(), res_type_group, key, restraint_values

        if restraint_values is None: continue

        if restraint_values[0] == "I":
            #print threes, threes.are_linked(), res_type_group, key, restraint_values[:4]
            average_updates += 1
        else:
            total_updates += 1
        threes.apply_updates(
            restraint_values,
            cdl_proxies,
            ideal=ideal,
            esd=esd,
            esd_factor=esd_factor,
        )
    if registry.n: threes.apply_average_updates(registry)
    #  restraints_manager.geometry.reset_internals()
    geometry.reset_internals()
    if verbose and threes and threes.errors:
        if log:
            log.write(
                "  Residues not completely updated with CDL restraints\n\n")
        for line in threes.errors:
            if log:
                log.write("%s\n" % line)
            else:
                print line


#  print 'average updates',average_updates,total_updates
#  assert average_updates==0
    return geometry  #restraints_manager
Esempio n. 4
0
from __future__ import division
import sys
import copy
from string import letters, digits

import iotbx.pdb

from mmtbx.conformation_dependent_library.cdl_database import cdl_database
import mmtbx.conformation_dependent_library.cdl_utils

from mmtbx.conformation_dependent_library.multi_residue_class import \
  ThreeProteinResidues, RestraintsRegistry

chararcters_36 = letters[:26] + digits

registry = RestraintsRegistry()


def restraints_show(restraints_values):
    from mmtbx.conformation_dependent_library.cdl_setup import headers
    outl = ""
    for i, item in enumerate(restraints_values):
        if i % 2 == 0:
            if i == 0:
                s = "  %s, %s : %s %s\n"
            elif i < 15:
                s = "  %-25s%s: %9.2f %9.2f\n"
            else:
                s = "  %-25s%s:   %9.4f %9.4f\n"
            outl += s % (
                headers[i],
def backrub_move(
    prev_res,
    cur_res,
    next_res,
    angle,
    move_oxygens=False,
    accept_worse_rama=False,
    rotamer_manager=None,
    rama_manager=None):
  import boost.python
  ext = boost.python.import_ext("mmtbx_validation_ramachandran_ext")
  from mmtbx_validation_ramachandran_ext import rama_eval
  from scitbx.matrix import rotate_point_around_axis
  from mmtbx.conformation_dependent_library.multi_residue_class import ThreeProteinResidues, \
      RestraintsRegistry

  if abs(angle) < 1e-4:
    return
  if prev_res is None or next_res is None:
    return
  saved_res = [{},{},{}]
  for i, r in enumerate([prev_res, cur_res, next_res]):
    for a in r.atoms():
      saved_res[i][a.name.strip()] = a.xyz
  if rotamer_manager is None:
    rotamer_manager = RotamerEval()
  prev_ca = prev_res.find_atom_by(name=" CA ")
  cur_ca = cur_res.find_atom_by(name=" CA ")
  next_ca = next_res.find_atom_by(name=" CA ")
  if prev_ca is None or next_ca is None or cur_ca is None:
    return
  atoms_to_move = []
  atoms_to_move.append(prev_res.find_atom_by(name=" C  "))
  atoms_to_move.append(prev_res.find_atom_by(name=" O  "))
  for atom in cur_res.atoms():
    atoms_to_move.append(atom)
  atoms_to_move.append(next_res.find_atom_by(name=" N  "))
  for atom in atoms_to_move:
    assert atom is not None
    new_xyz = rotate_point_around_axis(
        axis_point_1 = prev_ca.xyz,
        axis_point_2 = next_ca.xyz,
        point        = atom.xyz,
        angle        = angle,
        deg          = True)
    atom.xyz = new_xyz
  if move_oxygens:
    registry = RestraintsRegistry()
    if rama_manager is None:
      rama_manager = rama_eval()
    tpr = ThreeProteinResidues(geometry=None, registry=registry)
    tpr.append(prev_res)
    tpr.append(cur_res)
    tpr.append(next_res)
    phi_psi_angles = tpr.get_phi_psi_angles()
    rama_key = tpr.get_ramalyze_key()
    ev_before = rama_manager.evaluate_angles(rama_key, phi_psi_angles[0], phi_psi_angles[1])
    theta1 = _find_theta(
        ap1 = prev_ca.xyz,
        ap2 = cur_ca.xyz,
        cur_xyz = prev_res.find_atom_by(name=" O  ").xyz,
        needed_xyz = saved_res[0]["O"])
    theta2 = _find_theta(
        ap1 = cur_ca.xyz,
        ap2 = next_ca.xyz,
        cur_xyz = cur_res.find_atom_by(name=" O  ").xyz,
        needed_xyz = saved_res[1]["O"])
    for a in [prev_res.find_atom_by(name=" C  "),
        prev_res.find_atom_by(name=" O  "),
        cur_res.find_atom_by(name=" C  ")]:
      new_xyz = rotate_point_around_axis(
              axis_point_1 = prev_ca.xyz,
              axis_point_2 = cur_ca.xyz,
              point        = a.xyz,
              angle        = theta1,
              deg          = True)
      a.xyz = new_xyz
    for a in [cur_res.find_atom_by(name=" C  "),
        cur_res.find_atom_by(name=" O  "),
        next_res.find_atom_by(name=" N  ")]:
      new_xyz = rotate_point_around_axis(
              axis_point_1 = cur_ca.xyz,
              axis_point_2 = next_ca.xyz,
              point        = a.xyz,
              angle        = theta2,
              deg          = True)
      a.xyz = new_xyz
    phi_psi_angles = tpr.get_phi_psi_angles()
    rama_key = tpr.get_ramalyze_key()
    ev_after = rama_manager.evaluate_angles(rama_key, phi_psi_angles[0], phi_psi_angles[1])
    if ev_before > ev_after and not accept_worse_rama:
      for a in [prev_res.find_atom_by(name=" C  "),
          prev_res.find_atom_by(name=" O  "),
          cur_res.find_atom_by(name=" C  ")]:
        new_xyz = rotate_point_around_axis(
                axis_point_1 = prev_ca.xyz,
                axis_point_2 = cur_ca.xyz,
                point        = a.xyz,
                angle        = -theta1,
                deg          = True)
        a.xyz = new_xyz
      for a in [cur_res.find_atom_by(name=" C  "),
          cur_res.find_atom_by(name=" O  "),
          next_res.find_atom_by(name=" N  ")]:
        new_xyz = rotate_point_around_axis(
                axis_point_1 = cur_ca.xyz,
                axis_point_2 = next_ca.xyz,
                point        = a.xyz,
                angle        = -theta2,
                deg          = True)
        a.xyz = new_xyz
Esempio n. 6
0
def update_restraints(hierarchy,
                      geometry,
                      current_geometry=None, # xray_structure!!
                      sites_cart=None,
                      cdl_proxies=None,
                      cis_pro_eh99=False, # use EH99 for cis-PRO
                      cdl_svl=False, # use CDL-SVL
                      ideal=True,
                      esd=True,
                      esd_factor=1.,
                      interpolate=False,
                      log=None,
                      verbose=False,
                      ):
  global registry
  registry = RestraintsRegistry()
  if current_geometry:
    assert not sites_cart
    sites_cart = current_geometry.sites_cart()
  if sites_cart:
    pdb_atoms = hierarchy.atoms()
    # XXX PDB_TRANSITION VERY SLOW
    for j_seq, atom in enumerate(pdb_atoms):
      atom.xyz = sites_cart[j_seq]

  threes = None
  average_updates = 0
  total_updates = 0
  for threes in generate_protein_threes(
    hierarchy,
    geometry,
    cdl_class=True,
    retain_selection="name ca or name c or name n or name o or name cb or name h or name cd or name cg",
    #verbose=verbose,
    ):
    if cdl_svl:
      restraint_values = get_restraint_values(threes,
                                              cdl_svl=cdl_svl,
                                              interpolate=interpolate)
      # print('cdl_svl %s %s' % (threes,restraint_values))
    else:
      if threes.cis_group():
        if cis_pro_eh99:
          # returns cis-PRO EH99 values if asked
          restraint_values = get_restraint_values(threes, interpolate=interpolate)
          # print('cis-PRO EH99  %s %s' % (threes, restraint_values))
        else:
          continue
      else:
        restraint_values = get_restraint_values(threes, interpolate=interpolate)
        # print('CDL %s %s' % (threes, restraint_values))

    if restraint_values is None: continue

    if restraint_values[0]=="I":
      average_updates += 1
    else:
      total_updates += 1
    threes.apply_updates(restraint_values,
                         cdl_proxies,
                         ideal=ideal,
                         esd=esd,
                         esd_factor=esd_factor,
                         )
  if registry.n: threes.apply_average_updates(registry)
  geometry.reset_internals()
  if verbose and threes and threes.errors:
    if log:
      log.write("  Residues not completely updated with CDL restraints\n\n")
    for line in threes.errors:
      if log:
        log.write("%s\n" % line)
      else:
        print(line)
#  print 'average updates',average_updates,total_updates
#  assert average_updates==0
  return geometry #restraints_manager