Esempio n. 1
0
def mutate_two_res(pose, ires1in, aa1, chis1, ires2in, aa2, chis2, symnum=1):
    pose2 = pose.clone()
    assert len(pose2.residues) % symnum == 0
    nres = len(pose2.residues) // symnum
    for isym in range(symnum):
        ires1 = (ires1in - 1) % nres + 1 + isym * nres
        ires2 = (ires2in - 1) % nres + 1 + isym * nres
        mut = rosetta.protocols.simple_moves.MutateResidue()
        mut.set_preserve_atom_coords(False)
        mut.set_res_name(aa1)
        mut.set_target(ires1)
        mut.apply(pose2)
        for ichi, chi in enumerate(chis1):
            pose2.set_chi(ichi + 1, ires1, chi)
        mut.set_res_name(aa2)
        mut.set_target(ires2)
        mut.apply(pose2)
        for ichi, chi in enumerate(chis2):
            pose2.set_chi(ichi + 1, ires2, chi)
        # pose2.dump_pdb('before.pdb')
        for ir in range(1, len(pose2.residues) + 1):
            pose2.set_xyz(AtomID(pose2.residue(ir).atom_index('O'), ir),
                          pose.residue(ir).xyz('O'))
            if pose2.residue(ir).name3() != 'PRO':
                fix_bb_h(pose2, ir)
        # pose2.dump_pdb('after.pdb')
    return pose2
Esempio n. 2
0
def hokey_position_atoms(pose, ires1, ires2, metal_pos, metalaxispos):
   znres1, znres2 = None, None
   #   if pose.residue(ires1).name() == 'HZD':
   #      znres1 = ires1
   #      znatom1 = 'VZN'
   #      axisatom1 = 'HZ'
   #   elif pose.residue(ires1).name3() == 'CYS':
   #      znres1 = ires1
   #      znatom1 = 'HG'
   #      axisatom1 = '2HB'
   #   elif pose.residue(ires1).name3() == 'ASP':
   #      znres1 = ires1
   #      znatom1 = '1HB'
   #      axisatom1 = '2HB'
   #   elif pose.residue(ires1).name3() == 'GLU':
   #      znres1 = ires1
   #      znatom1 = '1HG'
   #      axisatom1 = '2HG'
   #
   #   if pose.residue(ires2).name3() == 'HZD':
   #      znres2 = ires2
   #      znatom2 = 'VZN'
   #      axisatom2 = 'HZ'
   #   elif pose.residue(ires2).name3() == 'CYS':
   #      znres2 = ires2
   #      znatom2 = 'HG'
   #      axisatom2 = '2HB'
   #   elif pose.residue(ires2).name3() == 'ASP':
   #      znres2 = ires2
   #      znatom2 = '1HB'
   #      axisatom2 = '2HB'
   #   elif pose.residue(ires2).name3() == 'GLU':
   #      znres2 = ires2
   #      znatom2 = '1HG'
   #      axisatom2 = '2HG'
   znres1 = ires1
   znres2 = ires2
   znatom1 = '1HB'
   znatom2 = '1HB'
   axisatom1 = '2HB'
   axisatom2 = '2HB'
   for znres, znatom, axisatom in [(znres1, znatom1, axisatom1), (znres2, znatom2, axisatom2)]:
      pose.set_xyz(AtomID(pose.residue(znres).atom_index(znatom), znres),
                   rVec(metal_pos[0], metal_pos[1], metal_pos[2]))
      pose.set_xyz(AtomID(pose.residue(znres).atom_index(axisatom), znres),
                   rVec(metalaxispos[0], metalaxispos[1], metalaxispos[2]))
Esempio n. 3
0
def fix_bb_h(pose, ires):
    # if pose.residue(ires).name() == 'PRO': return
    # if pose.residue(ires).name() == 'DPRO': return
    c = np.array(pose.residue((ires - 2) % len(pose.residues) + 1).xyz('C'))
    n = np.array(pose.residue(ires).xyz('N'))
    ca = np.array(pose.residue(ires).xyz('CA'))

    hpos = (n - (ca + c) / 2)
    hpos = n + hpos / np.linalg.norm(hpos)

    hpos = xyzVec(*hpos[:3])
    if pose.residue(ires).has('H'):
        pose.set_xyz(AtomID(pose.residue(ires).atom_index('H'), ires), hpos)
Esempio n. 4
0
def get_bordering_atom_id(pose, site_chain, site_res, stack_position, atom):
    """
	Determines the residue above or below the target residue in the tau fibril 
	and returns the specified atom of that neighbor. Selection assumes the  
	chain numbering matches 5o3l, wherein alternating chains are in each stack. 
	(Target stack is A-C-E-G-I.)
	"""
    # Verifying correct atom name
    if atom not in ['N', 'CA', 'C']:
        print("Incorrect atom name")
        exit()

    neighbor_chain_number = site_chain + 2 * stack_position
    neighbor_chain = chr(64 + neighbor_chain_number)  # 'A' is chr(65)
    neighbor_res = pose.pdb_info().pdb2pose(neighbor_chain, site_res)
    atom_id = AtomID(pose.residue(neighbor_res).atom_index(atom), neighbor_res)

    return atom_id
Esempio n. 5
0
def make_constraints(pose, chain_no, tug_site, tug_len):
    """
	Creates harmonic constraints for 5o3l (hard-coded) to pull a target site 
	residue away from its neighbors in the chains above and below by a given 
	length in Angstroms. Uses get_bordering_atom_id to determine neighbors.
	"""
    # Catch useless tugs
    if tug_len < 5:
        print("Default distance is roughly 5A, so pick something bigger for d")
        exit()

    # Identifying target residue's CA
    res_info = pose.pdb_info().pose2pdb(tug_site).split()
    res_no_in_chain = int(res_info[0])
    ca_target = AtomID(pose.residue(tug_site).atom_index('CA'), tug_site)

    # Determining residues immediately above and below the target
    ca_ab = get_bordering_atom_id(pose, chain_no, res_no_in_chain, -1, 'CA')
    ca_bl = get_bordering_atom_id(pose, chain_no, res_no_in_chain, 1, 'CA')

    # Creating repulsion constraints to push away from neighbors
    tug_sd = float(tug_len - 4.5) / 10
    hf = HarmonicFunc(tug_len, tug_sd)  # Normally distance is <4.8A
    cst_above = AtomPairConstraint(ca_target, ca_ab, hf)
    cst_below = AtomPairConstraint(ca_target, ca_bl, hf)

    # Determining CA above and below target one res back for dihedrals
    ca_ab_p = get_bordering_atom_id(pose, chain_no, res_no_in_chain - 1, -1,
                                    'CA')
    ca_bl_p = get_bordering_atom_id(pose, chain_no, res_no_in_chain - 1, 1,
                                    'CA')

    # Making constraints--30 degree tolerance from ideal angle
    chf_above = CircularHarmonicFunc(radians(90), .5, .5)
    chf_below = CircularHarmonicFunc(radians(-90), .5, .5)

    dih_above = DihedralConstraint(ca_ab_p, ca_ab, ca_bl, ca_target, chf_above)
    dih_below = DihedralConstraint(ca_bl_p, ca_bl, ca_ab, ca_target, chf_below)

    return [cst_above, cst_below, dih_above, dih_below]
from pyrosetta.rosetta.core.id import AtomID
from pyrosetta.rosetta.protocols.minimization_packing import MinMover
init()
tev = pose_from_pdb('loop_swap_protocol/tev.pdb')
tev.pdb_info().pdb2pose('A', 142)
tev.pdb_info().pdb2pose('A', 154)
qris = ResidueIndexSelector('134-135,147-148')
ky9 = pose_from_pdb('../dali_data/pdb/ky/pdb1ky9.ent.gz')
ky9.pdb_info().pdb2pose('B', 201)
ky9.pdb_info().pdb2pose('B', 213)
sris = ResidueIndexSelector('466-467,479-480')
pla.align_protein_sections(tev, qris, ky9, sris)
loop = Pose(ky9, 466, 480)
loop.append_pose_by_jump(pose_from_sequence('G'), 1)
size_l = loop.total_residue()
n_ca = AtomID(loop.residue(2).atom_index('CA'), 2)
c_ca = AtomID(loop.residue(size_l - 2).atom_index('CA'), size_l - 2)
x_ca = AtomID(loop.residue(size_l).atom_index('CA'), size_l)
x_n = AtomID(loop.residue(size_l).atom_index('N'), size_l)
x_c = AtomID(loop.residue(size_l).atom_index('C'), size_l)
r_ca = AtomID(loop.residue(1).atom_index('CA'), 1)
int_ca_dist = pla.get_distance(pla.find_res_ca_coords(loop, 1),
                               pla.find_res_ca_coords(loop, size_l - 1)) / 2
out_dist1 = sqrt(int_ca_dist**2 + 20**2)
out_dist2 = sqrt(int_ca_dist**2 + 21.5**2)
dist_hf1 = HarmonicFunc(out_dist1, 0.1)
dist_hf2 = HarmonicFunc(out_dist2, 0.1)
dcst1 = AtomPairConstraint(n_ca, x_n, dist_hf1)
dcst2 = AtomPairConstraint(c_ca, x_n, dist_hf1)
dcst3 = AtomPairConstraint(n_ca, x_ca, dist_hf2)
dcst4 = AtomPairConstraint(c_ca, x_ca, dist_hf2)
Esempio n. 7
0
def xtal_search_single_residue(search_spec, pose, **kw):
   raise NotImplemntedError('xtal_search_single_residue needs updating')
   kw = rp.Bunch(kw)

   spec = search_spec
   xspec = spec.xtal_spec

   results = list()

   p_n = pose.pdb_info().name().split('/')[-1]
   # gets rid of the ".pdb" at the end of the pdb name
   pdb_name = p_n[:-4]

   print(f'{pdb_name} searching')

   # check the symmetry type of the pdb
   last_res = rt.core.pose.chain_end_res(pose).pop()
   total_res = int(last_res)
   sym_num = pose.chain(last_res)
   if sym_num < 2:
      print('bad pdb', p_n)
      return list()
   sym = int(sym_num)
   peptide_sym = "C%i" % sym_num

   for ires in range(1, int(total_res / sym) + 1):
      if pose.residue_type(ires) not in (spec.rts.name_map('GLY'), spec.rts.name_map('ALA'),
                                         spec.rts.name_map('DALA')):
         continue
      lig_poses = util.mut_to_ligand(pose, ires, spec.ligands, spec.sym_of_ligand)
      bad_rots = 0
      for ilig, lig_pose in enumerate(lig_poses):
         mut_res_name, lig_sym = lig_poses[lig_pose]

         rotamers = lig_pose.residue(ires).get_rotamers()
         rotamers = util.extra_rotamers(rotamers, lb=-20, ub=21, bs=20)

         pose_num = 1
         for irot, rotamer in enumerate(rotamers):
            #for i in range(1, len(rotamer)+1): # if I want to sample the metal-axis too
            for i in range(len(rotamer)):
               lig_pose.residue(ires).set_chi(i + 1, rotamer[i])
            rot_pose = rt.protocols.grafting.return_region(lig_pose, 1, lig_pose.size())

            if kw.debug:
               rot_pose.set_xyz(AtomID(rot_pose.residue(ires).atom_index('1HB'), ires),
                                rVec(0, 0, -2))
               rot_pose.set_xyz(AtomID(rot_pose.residue(ires).atom_index('CB'), ires),
                                rVec(0, 0, +0.0))
               rot_pose.set_xyz(AtomID(rot_pose.residue(ires).atom_index('2HB'), ires),
                                rVec(0, 0, +2))

            spec.sfxn_rotamer(rot_pose)
            dun_score = rot_pose.energies().residue_total_energy(ires)
            if dun_score >= spec.max_dun_score:
               bad_rots += 1
               continue
            rpxbody = rp.Body(rot_pose)

            ############ fix this

            metal_orig = hm.hpoint(util.coord_find(rot_pose, ires, 'VZN'))
            hz = hm.hpoint(util.coord_find(rot_pose, ires, 'HZ'))
            ne = hm.hpoint(util.coord_find(rot_pose, ires, 'VNE'))
            metal_his_bond = hm.hnormalized(metal_orig - ne)
            metal_sym_axis0 = hm.hnormalized(hz - metal_orig)
            dihedral = xspec.dihedral

            ############# ...

            rots_around_nezn = hm.xform_around_dof_for_vector_target_angle(
               fix=spec.pept_axis, mov=metal_sym_axis0, dof=metal_his_bond,
               target_angle=np.radians(dihedral))

            for idof, rot_around_nezn in enumerate(rots_around_nezn):
               metal_sym_axis = rot_around_nezn @ metal_sym_axis0
               assert np.allclose(hm.line_angle(metal_sym_axis, spec.pept_axis),
                                  np.radians(dihedral))

               newhz = util.coord_find(rot_pose, ires, 'VZN') + 2 * metal_sym_axis[:3]

               aid = rt.core.id.AtomID(rot_pose.residue(ires).atom_index('HZ'), ires)
               xyz = rVec(newhz[0], newhz[1], newhz[2])
               rot_pose.set_xyz(aid, xyz)

               tag = f'{pdb_name}_{ires}_{lig_poses[lig_pose][0]}_{idof}_{pose_num}'
               xtal_poses = mof.xtal_build.xtal_build(
                  pdb_name,
                  xspec,
                  aa1,
                  aa2,
                  rot_pose,
                  peptide_sym,
                  spec.pept_orig,
                  spec.pept_axis,
                  lig_sym,
                  metal_orig,
                  metal_sym_axis,
                  rpxbody,
                  tag,
               )

               if False and xtal_poses:
                  print('hoaktolfhtoia')
                  print(rot_pose)
                  print(pdb_name)
                  print(xspec)
                  rot_pose.dump_pdb('test_xtal_build_p213.pdb')
                  print(ires)
                  print(peptide_sym)
                  print(spec.pept_orig)
                  print(spec.pept_axis)
                  print(lig_sym)
                  print(metal_orig)
                  print(metal_sym_axis)
                  print('rp.Body(pose)')

                  xalign, xpose, bodypdb = xtal_poses[0]
                  print(xalign)
                  xpose.dump_pdb('xtal_pose.pdb')

                  assert 0

               for ixtal, (xalign, xtal_pose, body_pdb) in enumerate(xtal_poses):
                  celldim = xtal_pose.pdb_info().crystinfo().A()
                  fname = f"{xspec.spacegroup.replace(' ','_')}_cell{int(celldim):03}_{tag}"
                  results.append(
                     mof.result.Result(
                        xspec,
                        fname,
                        xalign,
                        rpxbody,
                        xtal_pose,
                        body_pdb,
                     ))

            pose_num += 1
      # print(pdb_name, 'res', ires, 'bad rots:', bad_rots)

   return results
Esempio n. 8
0
def xtal_search_two_residues(
    search_spec,
    pose,
    rotcloud1base,
    rotcloud2base,
    err_tolerance=1.5,
    min_dist_to_z_axis=6.0,
    sym_axes_angle_tolerance=3.0,
    **arg,
):
    arg = rp.Bunch(arg)

    spec = search_spec
    xspec = spec.xtal_spec

    results = list()

    farep_orig = search_spec.rep_sfxn(pose)

    p_n = pose.pdb_info().name().split('/')[-1]
    # gets rid of the ".pdb" at the end of the pdb name
    pdb_name = p_n[:-4]

    print(f'{pdb_name} searching')

    # check the symmetry type of the pdb
    last_res = rt.core.pose.chain_end_res(pose).pop()
    total_res = int(last_res)

    sym_num = pose.chain(last_res)
    sym = int(sym_num)
    if sym_num < 2:
        print('bad pdb', p_n)
        return list()
    asym_nres = int(total_res / sym)
    peptide_sym = "C%i" % sym_num

    rpxbody = rp.Body(pose)

    for ires1 in range(1, asym_nres + 1):
        # if pose.residue_type(ires1) not in (spec.rts.name_map('ALA'), spec.rts.name_map('DALA')):
        if pose.residue_type(ires1) != spec.rts.name_map('ALA'):
            continue
        stub1 = rpxbody.stub[ires1 - 1]

        rots1ok = min_dist_to_z_axis < np.linalg.norm(
            (stub1 @ rotcloud1base.rotframes)[:, :2, 3], axis=1)
        if 0 == np.sum(rots1ok): continue
        rotcloud1 = rotcloud1base.subset(rots1ok)
        rotframes1 = stub1 @ rotcloud1.rotframes
        # rotcloud1.dump_pdb(f'cloud_a_{ires1:02}.pdb', position=stub1)

        range2 = range(1, int(total_res) + 1)
        if rotcloud1base is rotcloud2base:
            range2 = range(ires1 + 1, int(total_res) + 1)
        for ires2 in range2:
            if ires1 == ires2 % asym_nres: continue
            if pose.residue_type(ires2) != spec.rts.name_map('ALA'):
                continue
            stub2 = rpxbody.stub[ires2 - 1]
            # rotcloud2.dump_pdb(f'cloud_b_{ires2:02}.pdb', position=stub2)

            rots2ok = min_dist_to_z_axis < np.linalg.norm(
                (stub2 @ rotcloud2base.rotframes)[:, :2, 3], axis=1)
            if 0 == np.sum(rots2ok): continue
            rotcloud2 = rotcloud2base.subset(rots2ok)
            rotframes2 = stub2 @ rotcloud2.rotframes

            dist = rotframes1[:, :, 3].reshape(
                -1, 1, 4) - rotframes2[:, :, 3].reshape(1, -1, 4)
            dist = np.linalg.norm(dist, axis=2)
            # if np.min(dist) < 1.0:
            # print(f'{ires1:02} {ires2:02} {np.sort(dist.flat)[:5]}')
            dot = np.sum(rotframes1[:, :, 0].reshape(-1, 1, 4) *
                         rotframes2[:, :, 0].reshape(1, -1, 4),
                         axis=2)
            ang = np.degrees(np.arccos(dot))
            angerr = np.abs(ang - 107)
            err = angerr / 15.0 + dist
            rot1err = np.min(err, axis=1)
            bestrot2 = np.argmin(err, axis=1)
            hits1 = np.argwhere(rot1err < err_tolerance).reshape(-1)

            # hits = (angerr < angle_err_tolerance) * (dist < dist_err_tolerance)
            if len(hits1):
                # print(rotcloud1.amino_acid, rotcloud2.amino_acid, ires1, ires2)
                hits2 = bestrot2[hits1]
                hits = np.stack([hits1, hits2], axis=1)
                # print(
                # f'stats {ires1:2} {ires2:2} {np.sum(angerr < 10):7} {np.sum(dist < 1.0):5} {np.sum(hits):3}'
                # )
                for ihit, hit in enumerate(hits):
                    frame1 = rotframes1[hit[0]]
                    frame2 = rotframes2[hit[1]]

                    parl = (frame1[:, 0] + frame2[:, 0]) / 2.0
                    perp = rp.homog.hcross(frame1[:, 0], frame2[:, 0])
                    metalaxis1 = rp.homog.hrot(parl, +45) @ perp
                    metalaxis2 = rp.homog.hrot(parl, -45) @ perp
                    symang1 = rp.homog.line_angle(metalaxis1, spec.pept_axis)
                    symang2 = rp.homog.line_angle(metalaxis2, spec.pept_axis)
                    match11 = np.abs(np.degrees(symang1) -
                                     35.26) < sym_axes_angle_tolerance
                    match12 = np.abs(np.degrees(symang2) -
                                     35.26) < sym_axes_angle_tolerance
                    match21 = np.abs(np.degrees(symang1) -
                                     54.735) < sym_axes_angle_tolerance
                    match22 = np.abs(np.degrees(symang2) -
                                     54.735) < sym_axes_angle_tolerance
                    if not (match11 or match12 or match12 or match22): continue
                    matchsymang = symang1 if (match11 or match21) else symang2
                    metalaxis = metalaxis1 if (match11
                                               or match21) else metalaxis2

                    metal_pos = (rotframes1[hit[0], :3, 3] +
                                 rotframes2[hit[1], :3, 3]) / 2.0
                    metalaxispos = metal_pos + metalaxis[:3] + metalaxis[:3]
                    # metal_dist_z = np.sqrt(metal_pos[0]**2 + metal_pos[1]**2)
                    # if metal_dist_z < 4.0: continue
                    pose2 = mof.util.mutate_two_res(
                        pose,
                        ires1,
                        rotcloud1.amino_acid,
                        rotcloud1.rotchi[hit[0]],
                        ires2,
                        rotcloud2.amino_acid,
                        rotcloud2.rotchi[hit[1]],
                    )
                    if pose2.residue(ires1).has('VZN'):
                        pose2.set_xyz(
                            AtomID(
                                pose2.residue(ires1).atom_index('VZN'), ires1),
                            rVec(metal_pos[0], metal_pos[1], metal_pos[2]))
                        pose2.set_xyz(
                            AtomID(
                                pose2.residue(ires1).atom_index('HZ'), ires1),
                            rVec(metalaxispos[0], metalaxispos[1],
                                 metalaxispos[2]))

                    elif pose2.residue(ires2).has('VZN'):
                        pose2.set_xyz(
                            AtomID(
                                pose2.residue(ires2).atom_index('VZN'), ires2),
                            rVec(metal_pos[0], metal_pos[1], metal_pos[2]))
                        pose2.set_xyz(
                            AtomID(
                                pose2.residue(ires2).atom_index('HZ'), ires2),
                            rVec(metalaxispos[0], metalaxispos[1],
                                 metalaxispos[2]))
                    farep_delta = search_spec.rep_sfxn(pose2) - farep_orig
                    if farep_delta > 1.0: continue
                    print(
                        "HIT",
                        rotcloud1.amino_acid,
                        rotcloud2.amino_acid,
                        ires1,
                        ires2,
                        np.round(np.degrees(matchsymang), 3),
                        hit,
                        rotcloud1.rotchi[hit[0]],
                        rotcloud2.rotchi[hit[1]],
                        # farep_delta,
                        np.round(dist[tuple(hit)], 3),
                        np.round(angerr[tuple(hit)], 3),
                    )
                    fn = ('hit_%s_%s_%i_%i_%i.pdb' %
                          (rotcloud1.amino_acid, rotcloud2.amino_acid, ires1,
                           ires2, ihit))
                    rotcloud1.dump_pdb(fn + '_a.pdb', stub1, which=hit[0])
                    rotcloud2.dump_pdb(fn + '_b.pdb', stub2, which=hit[1])
                    pose2.dump_pdb(fn)

    return results