def get_surrounding_unit_cells_2d(unit_cell_sym_mates, uc_dimensions):
    all_surrounding_unit_cells = []

    asu_bb_atom_template = unit_cell_sym_mates[0].get_backbone_atoms()
    unit_cell_sym_mates_len = len(unit_cell_sym_mates)

    central_uc_bb_cart_coords = []
    for unit_cell_sym_mate_pdb in unit_cell_sym_mates:
        central_uc_bb_cart_coords.extend(
            unit_cell_sym_mate_pdb.extract_backbone_coords())
    central_uc_bb_frac_coords = cart_to_frac(central_uc_bb_cart_coords,
                                             uc_dimensions)

    all_surrounding_uc_bb_frac_coords = []
    for x_shift in [-1, 0, 1]:
        for y_shift in [-1, 0, 1]:
            if [x_shift, y_shift] != [0, 0]:
                shifted_uc_bb_frac_coords = central_uc_bb_frac_coords + [
                    x_shift, y_shift, 0
                ]
                all_surrounding_uc_bb_frac_coords.extend(
                    shifted_uc_bb_frac_coords)

    all_surrounding_uc_bb_cart_coords = frac_to_cart(
        all_surrounding_uc_bb_frac_coords, uc_dimensions)
    all_surrounding_uc_bb_cart_coords = np.split(
        all_surrounding_uc_bb_cart_coords, 8)

    for surrounding_uc_bb_cart_coords in all_surrounding_uc_bb_cart_coords:
        all_uc_sym_mates_bb_cart_coords = np.split(
            surrounding_uc_bb_cart_coords, unit_cell_sym_mates_len)
        one_surrounding_unit_cell = []
        for uc_sym_mate_bb_cart_coords in all_uc_sym_mates_bb_cart_coords:
            uc_sym_mate_bb_pdb = PDB()
            uc_sym_mate_bb_atoms = []
            atom_count = 0
            for atom in asu_bb_atom_template:
                x_transformed = uc_sym_mate_bb_cart_coords[atom_count][0]
                y_transformed = uc_sym_mate_bb_cart_coords[atom_count][1]
                z_transformed = uc_sym_mate_bb_cart_coords[atom_count][2]
                atom_transformed = Atom(atom.get_number(), atom.get_type(),
                                        atom.get_alt_location(),
                                        atom.get_residue_type(),
                                        atom.get_chain(),
                                        atom.get_residue_number(),
                                        atom.get_code_for_insertion(),
                                        x_transformed, y_transformed,
                                        z_transformed, atom.get_occ(),
                                        atom.get_temp_fact(),
                                        atom.get_element_symbol(),
                                        atom.get_atom_charge())
                uc_sym_mate_bb_atoms.append(atom_transformed)
                atom_count += 1

            uc_sym_mate_bb_pdb.set_all_atoms(uc_sym_mate_bb_atoms)
            one_surrounding_unit_cell.append(uc_sym_mate_bb_pdb)

        all_surrounding_unit_cells.append(one_surrounding_unit_cell)

    return all_surrounding_unit_cells
def get_central_asu_pdb_2d(pdb1, pdb2, uc_dimensions):
    pdb_asu = PDB()
    pdb_asu.read_atom_list(pdb1.get_all_atoms() + pdb2.get_all_atoms())

    pdb_asu_coords_cart = pdb_asu.extract_all_coords()

    asu_com_cart = center_of_mass_3d(pdb_asu_coords_cart)
    asu_com_frac = cart_to_frac(asu_com_cart, uc_dimensions)

    asu_com_x_min_cart = sys.maxint
    x_min_shift_vec_frac = None
    for x in range(-10, 11):
        asu_com_x_shifted_coords_frac = asu_com_frac + [x, 0, 0]
        asu_com_x_shifted_coords_cart = frac_to_cart(
            asu_com_x_shifted_coords_frac, uc_dimensions)
        if abs(asu_com_x_shifted_coords_cart[0]) < abs(asu_com_x_min_cart):
            asu_com_x_min_cart = asu_com_x_shifted_coords_cart[0]
            x_min_shift_vec_frac = [x, 0, 0]

    asu_com_y_min_cart = sys.maxint
    y_min_shift_vec_frac = None
    for y in range(-10, 11):
        asu_com_y_shifted_coords_frac = asu_com_frac + [0, y, 0]
        asu_com_y_shifted_coords_cart = frac_to_cart(
            asu_com_y_shifted_coords_frac, uc_dimensions)
        if abs(asu_com_y_shifted_coords_cart[1]) < abs(asu_com_y_min_cart):
            asu_com_y_min_cart = asu_com_y_shifted_coords_cart[1]
            y_min_shift_vec_frac = [0, y, 0]

    if x_min_shift_vec_frac is not None and y_min_shift_vec_frac is not None:
        xyz_min_shift_vec_frac = [
            x_min_shift_vec_frac[0], y_min_shift_vec_frac[1], 0
        ]

        if xyz_min_shift_vec_frac == [0, 0, 0]:
            return pdb_asu

        else:
            pdb_asu_coords_frac = cart_to_frac(pdb_asu_coords_cart,
                                               uc_dimensions)
            xyz_min_shifted_pdb_asu_coords_frac = pdb_asu_coords_frac + xyz_min_shift_vec_frac
            xyz_min_shifted_pdb_asu_coords_cart = frac_to_cart(
                xyz_min_shifted_pdb_asu_coords_frac, uc_dimensions)

            xyz_min_shifted_asu_pdb = copy.deepcopy(pdb_asu)
            xyz_min_shifted_asu_pdb.replace_coords(
                xyz_min_shifted_pdb_asu_coords_cart)

            return xyz_min_shifted_asu_pdb

    else:
        return pdb_asu
def get_unit_cell_sym_mates(pdb_asu, expand_matrices, uc_dimensions):
    unit_cell_sym_mates = [pdb_asu]

    asu_cart_coords = pdb_asu.extract_all_coords()
    asu_frac_coords = cart_to_frac(asu_cart_coords, uc_dimensions)

    for r, t in expand_matrices:
        t_vec = np.array(t)
        r_mat = np.transpose(np.array(r))

        r_asu_frac_coords = np.matmul(asu_frac_coords, r_mat)
        tr_asu_frac_coords = r_asu_frac_coords + t_vec

        tr_asu_cart_coords = frac_to_cart(tr_asu_frac_coords,
                                          uc_dimensions).tolist()

        unit_cell_sym_mate_pdb = PDB()
        unit_cell_sym_mate_pdb_atom_list = []
        atom_count = 0
        for atom in pdb_asu.get_all_atoms():
            x_transformed = tr_asu_cart_coords[atom_count][0]
            y_transformed = tr_asu_cart_coords[atom_count][1]
            z_transformed = tr_asu_cart_coords[atom_count][2]
            atom_transformed = Atom(atom_count, atom.get_type(),
                                    atom.get_alt_location(),
                                    atom.get_residue_type(), atom.get_chain(),
                                    atom.get_residue_number(),
                                    atom.get_code_for_insertion(),
                                    x_transformed, y_transformed,
                                    z_transformed, atom.get_occ(),
                                    atom.get_temp_fact(),
                                    atom.get_element_symbol(),
                                    atom.get_atom_charge())
            atom_count += 1
            unit_cell_sym_mate_pdb_atom_list.append(atom_transformed)

        unit_cell_sym_mate_pdb.set_all_atoms(unit_cell_sym_mate_pdb_atom_list)
        unit_cell_sym_mates.append(unit_cell_sym_mate_pdb)

    return unit_cell_sym_mates
def get_expanded_ptgrp_pdbs(pdb1_asu, pdb2_asu, expand_matrices):
    asu_symm_mates = []

    pdb_asu = PDB()
    pdb_asu.set_all_atoms(pdb1_asu.get_all_atoms() + pdb2_asu.get_all_atoms())

    asu_coords = pdb_asu.extract_all_coords()

    for r in expand_matrices:

        r_mat = np.transpose(np.array(r))
        r_asu_coords = np.matmul(asu_coords, r_mat)

        asu_sym_mate_pdb = PDB()
        asu_sym_mate_pdb_atom_list = []
        atom_count = 0
        for atom in pdb_asu.get_all_atoms():
            x_transformed = r_asu_coords[atom_count][0]
            y_transformed = r_asu_coords[atom_count][1]
            z_transformed = r_asu_coords[atom_count][2]
            atom_transformed = Atom(atom_count, atom.get_type(),
                                    atom.get_alt_location(),
                                    atom.get_residue_type(), atom.get_chain(),
                                    atom.get_residue_number(),
                                    atom.get_code_for_insertion(),
                                    x_transformed, y_transformed,
                                    z_transformed, atom.get_occ(),
                                    atom.get_temp_fact(),
                                    atom.get_element_symbol(),
                                    atom.get_atom_charge())
            atom_count += 1
            asu_sym_mate_pdb_atom_list.append(atom_transformed)

        asu_sym_mate_pdb.set_all_atoms(asu_sym_mate_pdb_atom_list)
        asu_symm_mates.append(asu_sym_mate_pdb)

    return asu_symm_mates
Beispiel #5
0
def biopdb_aligned_chain(pdb_fixed, chain_id_fixed, pdb_moving,
                         chain_id_moving):
    biopdb_atom_fixed = []
    biopdb_atom_moving = []

    for atom in pdb_fixed.get_CA_atoms():
        if atom.chain == chain_id_fixed:
            biopdb_atom_fixed.append(
                BioPDBAtom(atom.type, (atom.x, atom.y, atom.z),
                           atom.temp_fact,
                           atom.occ,
                           atom.alt_location,
                           " %s " % atom.type,
                           atom.number,
                           element=atom.element_symbol))

    pdb_moving_coords = []
    for atom in pdb_moving.get_all_atoms():
        pdb_moving_coords.append([atom.get_x(), atom.get_y(), atom.get_z()])
        if atom.is_CA():
            if atom.chain == chain_id_moving:
                biopdb_atom_moving.append(
                    BioPDBAtom(atom.type, (atom.x, atom.y, atom.z),
                               atom.temp_fact,
                               atom.occ,
                               atom.alt_location,
                               " %s " % atom.type,
                               atom.number,
                               element=atom.element_symbol))

    sup = Bio.PDB.Superimposer()
    sup.set_atoms(biopdb_atom_fixed, biopdb_atom_moving)
    # no need to transpose rotation matrix as Bio.PDB.Superimposer() generates correct matrix to rotate using np.matmul
    rot, tr = sup.rotran[0], sup.rotran[1]

    pdb_moving_coords_rot = np.matmul(pdb_moving_coords, rot)
    pdb_moving_coords_rot_tx = pdb_moving_coords_rot + tr

    pdb_moving_copy = PDB()
    pdb_moving_copy.set_chain_id_list(pdb_moving.get_chain_id_list())
    pdb_moving_copy_atom_list = []
    atom_count = 0
    for atom in pdb_moving.get_all_atoms():
        x_transformed = pdb_moving_coords_rot_tx[atom_count][0]
        y_transformed = pdb_moving_coords_rot_tx[atom_count][1]
        z_transformed = pdb_moving_coords_rot_tx[atom_count][2]
        atom_transformed = Atom(atom.get_number(), atom.get_type(),
                                atom.get_alt_location(),
                                atom.get_residue_type(), atom.get_chain(),
                                atom.get_residue_number(),
                                atom.get_code_for_insertion(),
                                x_transformed, y_transformed, z_transformed,
                                atom.get_occ(), atom.get_temp_fact(),
                                atom.get_element_symbol(),
                                atom.get_atom_charge())
        pdb_moving_copy_atom_list.append(atom_transformed)
        atom_count += 1

    pdb_moving_copy.set_all_atoms(pdb_moving_copy_atom_list)

    return pdb_moving_copy