def _calculate_O_coordinates(position_CA, position_C, position_N, residue): """ Calculate coordinates for the O atom. @param position_CA: Coordinates of the CA atom @type position_CA: Vector @param position_C: Coordinates of the C atom @type position_C: Vector @param position_N: Coordinates of the N atom @type position_N: Vector @param residue: Amino acid. @type residue: str @rtype: Vector @return: The calculated O position """ angle_O_C_N = ANGLE_O_C_N[residue] * pi / 180 bond_length_C_N = BOND_LENGTH_C_N[residue] D = Vector( BOND_LENGTH_C_O * cos(angle_O_C_N), BOND_LENGTH_C_O * sin(angle_O_C_N), 0) bc = (position_N - position_C) / bond_length_C_N n = ((position_C - position_CA) ** bc).normalized() nbc = bc ** n basis_change = numpy.array((bc, nbc, n)).transpose() return D.left_multiply(basis_change) + position_C
def test_hbond(self): """Calculates real-life coordinates""" vec1 = Vector([33.48, 142.73, -25.44]) vec2 = Vector([33.24, 142.49, -24.16]) vec3 = Vector([33.00, 141.24, -23.75]) vec4 = build_coord(vec1, vec2, vec3, 1.1, 120.0, 33.0) self.assertEqual(str(vec4), '<Vector 33.49, 140.39, -24.25>')
def __init__(self, donor, hydrogen, acceptor, acc_support): """Takes four sets of coord vectors.""" self.donor = Vector(donor) self.acceptor = Vector(acceptor) self.hydrogen = Vector(hydrogen) self.acc_support = Vector(acc_support) # helper vectors self.dh = self.hydrogen - self.donor self.ha = self.hydrogen - self.acceptor self.acs = self.acc_support - self.acceptor
def test_copy_vectors(self): """Should modify the atom coordinates.""" self.fccd.moving[0] = Vector([1.23, 4.56, 7.89]) self.fccd.copy_vectors_to_atoms() self.assertEqual(self.moving[0].coord[0], 1.23) self.assertEqual(self.moving[0].coord[1], 4.56) self.assertEqual(self.moving[0].coord[2], 7.89)
def get_vector(self): """Return coordinates as Vector. @return: coordinates as 3D vector @rtype: Vector """ x, y, z = self.coord return Vector(x, y, z)
def build_coord(vec1, vec2, vec3, dist, angle, torsion, matrix=None): """" Builds coordinates assuming a reference frame: A (-1/-1/0) B (-1/0/0) C (0/0/0) """ angle = math.radians(180 - angle) torsion = math.radians(torsion) # create initial vector vec_x = dist * math.cos(angle) vec_y = dist * math.cos(torsion) * math.sin(angle) vec_z = dist * math.sin(torsion) * math.sin(angle) # TODO: cache matrices for (dist/angle/torsion) (memoize pattern?) vec_d2 = Vector([vec_x, vec_y, vec_z]) if matrix == None: matrix = get_ref_matrix(vec1, vec2, vec3) result_vec = vec_d2.right_multiply(matrix) + vec3 return result_vec
def build_coord(vec1, vec2, vec3, dist, angle, torsion, matrix=None): """" Builds coordinates assuming a reference frame: A (-1/-1/0) B (-1/0/0) C (0/0/0) """ angle = math.radians(180 - angle) torsion = math.radians(torsion) # create initial vector vec_x = dist * math.cos(angle) vec_y = dist * math.cos(torsion) * math.sin(angle) vec_z = dist * math.sin(torsion) * math.sin(angle) # TODO: cache matrices for (dist/angle/torsion) (memoize pattern?) vec_d2 = Vector([vec_x, vec_y, vec_z]) if matrix == None: matrix = get_ref_matrix(vec1, vec2, vec3) result_vec = vec_d2.right_multiply(matrix) + vec3 return result_vec
def test_calc_dihedrals(residues): """Test the calc_dihedrals function vs BioPython's version.""" backbone = [a for res in residues for a in ram.get_backbone_atoms(res)] for i in range(1, len(residues) - 1): assert residues[i].seq == residues[i - 1].seq + 1 dihedrals = list(ram.calc_dihedrals(atom.coord for atom in backbone)) for i, angle1 in enumerate(dihedrals): vectors = [Vector(atom.coord) for atom in backbone[i:i + 4]] angle2 = biopy_calc_dihedral(*vectors) assert np.isclose(angle1, angle2)
def setUp(self): """Loads the A residue to start with.""" # coordinates for A,B,C in the reference frame self.ref_coord = [ Vector([-1.0, -1.0, 0.0]), Vector([-1.0, 0.0, 0.0]), Vector([0.0, 0.0, 0.0]) ] # some other coordinates for A,B,C self.sample_coord = [ Vector([1.0, 0.0, 0.0]), Vector([0.0, 0.0, 0.0]), Vector([0.0, 1.0, 0.0]) ]
def test_get_fixed_coords(self): """Method for fixed coordinates should pass.""" center = Vector([100.0, 0.0, 0.0]) self.fccd.get_fixed_coords(center) self.assertTrue(True)
def pixelate_atoms_in_box(model, pixels): """ pixelate atoms in residue-centered box by BINWIDTH """ residues = list(model.get_residues()) ori = Vector(0, 0, 0) vec_x = Vector(0, 0, 0) vec_y = Vector(0, 0, 0) vec_z = Vector(0, 0, 0) int_coord_x = [0, 0] int_coord_y = [0, 0] int_coord_z = [0, 0] prob_x = [0, 0] prob_y = [0, 0] prob_z = [0, 0] res_index1 = 0 for residue1 in residues: local_ref = [ori, vec_x, vec_y, vec_z] if not calc_local_reference(residue1, local_ref): pixels = np.delete(pixels, len(pixels) - 1, 0) continue res_index2 = 0 for residue2 in residues: if not is_neighbor_residue(local_ref, residue2): res_index2 += 1 continue res_name = residue2.get_resname()[2] for atom in residue2: atom_name = atom.get_name() if atom_name not in ATOMS_NAME: continue if atom_name == 'P' or atom_name == 'OP1' or atom_name == 'OP2': if is_head_residue(residues, res_index2, residue2): continue local_coordinate = Vector(0, 0, 0) if not is_neighbor_atom(local_ref, atom, local_coordinate): continue lattice_3d_point(local_coordinate, int_coord_x, int_coord_y, int_coord_z, prob_x, prob_y, prob_z) atom_mass = DICT_MASS[atom_name] if atom_name in DICT_CHARGE: atom_charge = DICT_CHARGE[atom_name] elif atom_name == 'O5\'': if is_head_residue(residues, res_index2, residue2): atom_charge = DICT_CHARGE_O5S['head'] else: atom_charge = DICT_CHARGE_O5S['nonhead'] elif atom_name == 'O3\'': if is_tail_residue(residues, res_index2, residue2): atom_charge = DICT_CHARGE_O3S['tail'] else: atom_charge = DICT_CHARGE_O3S['nontail'] elif atom_name == 'C1\'': atom_charge = DICT_CHARGE_C1S[res_name] elif atom_name == 'N9': atom_charge = DICT_CHARGE_N9[res_name] elif atom_name == 'C8': atom_charge = DICT_CHARGE_C8[res_name] elif atom_name == 'N7': atom_charge = DICT_CHARGE_N7[res_name] elif atom_name == 'C5': atom_charge = DICT_CHARGE_C5[res_name] elif atom_name == 'C6': atom_charge = DICT_CHARGE_C6[res_name] elif atom_name == 'N1': atom_charge = DICT_CHARGE_N1[res_name] elif atom_name == 'C2': atom_charge = DICT_CHARGE_C2[res_name] elif atom_name == 'N3': atom_charge = DICT_CHARGE_N3[res_name] elif atom_name == 'C4': atom_charge = DICT_CHARGE_C4[res_name] elif atom_name == 'O2': atom_charge = DICT_CHARGE_O2[res_name] else: continue for i in range(2): if int_coord_x[i] < 0 or int_coord_x[i] >= NBINS: continue for j in range(2): if int_coord_y[j] < 0 or int_coord_y[j] >= NBINS: continue for k in range(2): if int_coord_z[k] < 0 or int_coord_z[k] >= NBINS: continue (pixels[res_index1][0][int_coord_x[i]] [int_coord_y[j]][int_coord_z[k]]) +=\ prob_x[i] * prob_y[j] * prob_z[k] (pixels[res_index1][1][int_coord_x[i]] [int_coord_y[j]][int_coord_z[k]]) +=\ prob_x[i] * prob_y[j] * prob_z[k] * atom_mass (pixels[res_index1][2][int_coord_x[i]] [int_coord_y[j]][int_coord_z[k]]) +=\ prob_x[i] * prob_y[j] * prob_z[k] * atom_charge """ if res_index1 == 0 and int_coord_x[i] == 23 and int_coord_y[j] == 6 and int_coord_z[k] == 3: print atom_name, atom_mass, atom_charge, prob_x[i], prob_y[j], prob_z[k], residue2.get_full_id() """ res_index2 += 1 res_index1 += 1 return pixels
def test_division(self): """Confirm division works.""" from Bio.PDB.Vector import Vector v = Vector(1, 1, 1) / 2 self.assertEqual(repr(v), "<Vector 0.50, 0.50, 0.50>")
def _place_backbone_atoms(coords, angles, cis, aa_seq): """ Place atoms that are in the backbone. @param coords: Array where the coordinates are to be saved. @type coords: numpy.array @param angles: Angles. @type angles: list(float) @param cis: Conformation of the peptide bonds. @type cis: list(int) @param aa_seq: Amino acid sequence. @type aa_seq: list(int) """ for i in xrange(len(aa_seq)): current_res = index_to_three(aa_seq[i]) current_atom = 'N' prev_atom = 'C' prev_prev_atom = 'CA' for j in xrange(backbone_atoms): index = i * atoms_per_residue + j if i == 0 and current_atom == 'N': coords[:,index] = 0 elif i == 0 and current_atom == 'CA': coords[:,index] = 0 coords[X][index] = get_bond_length( current_atom, prev_atom, current_res) else: v1 = _create_vector(coords, index, j, 1) v2 = _create_vector(coords, index, j, 2) if i == 0 and current_atom == 'C': v3 = Vector(0, -1.0, 0) else: v3 = _create_vector(coords, index, j, 3) angle = get_bond_angle( prev_prev_atom, prev_atom, current_atom, current_res) dihedral = _calculate_dihedral(prev_atom, angles, cis, i) bond_length = get_bond_length(prev_atom, current_atom, current_res) bond_length_prev = get_bond_length( prev_prev_atom, prev_atom, current_res) D = Vector( bond_length * cos(pi - angle), bond_length * cos(pi - dihedral) * sin(pi - angle), bond_length * sin(pi - dihedral) * sin(pi - angle), ) bc = (v1 - v2) / bond_length_prev n = ((v1 - v3) ** bc).normalized() nbc = bc ** n basis_change = numpy.array((bc, nbc, n)).transpose() D = D.left_multiply(basis_change) + v1 coords[:,index] = D prev_prev_atom = prev_atom prev_atom = current_atom current_atom = ATOMS[(ATOMS.index(current_atom) + 1) % backbone_atoms]