示例#1
0
 def test_axis_not_origin(self):
     at = []
     for _ in range(100):
         a, b, c, d = random.sample(self.vectors, 4)
         axis = geometry.find_transformations(a, b, c, d)[2]
         at.append(not numpy.allclose(axis, [0, 0, 0]))
     self.assertTrue(all(at))
示例#2
0
    def move_to(self, start, end):
        """Moves the `Polynucleotide` to lie on the `start` and `end` vector.

        Parameters
        ----------
        start : 3D Vector (tuple or list or numpy.array)
            The coordinate of the start of the helix primitive.
        end : 3D Vector (tuple or list or numpy.array)
            The coordinate of the end of the helix primitive.

        Raises
        ------
        ValueError
            Raised if `start` and `end` are very close together.
        """
        start = numpy.array(start)
        end = numpy.array(end)
        if numpy.allclose(start, end):
            raise ValueError('start and end must NOT be identical')
        translation, angle, axis, point = find_transformations(
            self.helix_start, self.helix_end, start, end)
        if not numpy.isclose(angle, 0.0):
            self.rotate(angle=angle, axis=axis, point=point, radians=False)
        self.translate(vector=translation)
        return
示例#3
0
 def test_translation(self):
     # translating s1 should give s2.
     at = []
     for _ in range(100):
         a, b, c, d = random.sample(self.vectors, 4)
         translation = geometry.find_transformations(s1=a, e1=b, s2=c,
                                                     e2=d)[0]
         at.append(numpy.allclose(a + translation, c))
     self.assertTrue(all(at))
示例#4
0
 def test_rotation(self):
     at = []
     for _ in range(100):
         a, b, c, d = random.sample(self.vectors, 4)
         angle, axis, point = geometry.find_transformations(a, b, c, d)[1:]
         q = geometry.Quaternion.angle_and_axis(angle, axis)
         t = q.rotate_vector(b, point=point)
         x = geometry.angle_between_vectors(t - a, d - c)
         at.append(numpy.isclose(x, 0.0, atol=0.0001))
     self.assertTrue(all(at))
示例#5
0
def align_nab(tar, ref):
    """Aligns the N-CA and CA-CB vector of the target monomer.

    Parameters
    ----------
    tar: ampal.Residue
        The residue that will be aligned to the reference.
    ref: ampal.Residue
        The reference residue for the alignment.
    """
    rot_trans_1 = find_transformations(tar['N'].array, tar['CA'].array,
                                       ref['N'].array, ref['CA'].array)
    apply_trans_rot(tar, *rot_trans_1)
    rot_ang_ca_cb = dihedral(tar['CB'], ref['CA'], ref['N'], ref['CB'])
    tar.rotate(rot_ang_ca_cb, ref['N'].array - ref['CA'].array, ref['N'].array)
    return
示例#6
0
 def build(self):
     """Build single DNA strand along z-axis, starting with P on x-axis"""
     ang_per_res = (2 * numpy.pi) / self.nucleotides_per_turn
     atom_offset_coords = _backbone_properties[self.helix_type]['atoms']
     if self.handedness == 'l':
         handedness = -1
     else:
         handedness = 1
     base_atom_labels = _backbone_properties[self.helix_type]['labels']
     monomers = []
     mol_code_format = _backbone_properties[
         self.helix_type]['mol_code_format']
     for i, b in enumerate(self.base_sequence):
         nucleotide = Nucleotide(mol_code=mol_code_format.format(b),
                                 parent=self)
         atoms_dict = OrderedDict()
         if (i == (len(self.base_sequence) - 1)) and not self.phos_3_prime:
             # Do not include phosphate on last nucleotide
             atom_labels = base_atom_labels[3:] + [_bases[b]['labels'][2]]
             atom_offsets = {
                 k: v
                 for k, v in zip(atom_labels, atom_offset_coords[3:])
             }
         else:
             atom_labels = base_atom_labels + [_bases[b]['labels'][2]]
             atom_offsets = {
                 k: v
                 for k, v in zip(atom_labels, atom_offset_coords)
             }
         for atom_label in atom_labels:
             r, zeta, z_shift = atom_offsets[atom_label]
             rot_ang = ((i * ang_per_res) + zeta) * handedness
             z = (self.rise_per_nucleotide * i) + z_shift
             coords = cylindrical_to_cartesian(radius=r,
                                               azimuth=rot_ang,
                                               z=z,
                                               radians=True)
             atom = Atom(coordinates=coords,
                         element=atom_label[0],
                         parent=nucleotide,
                         res_label=atom_label)
             atoms_dict[atom_label] = atom
         base_ref = _bases[b]['ref_atom']
         rot_adj = _bases[b]['rot_adj']
         base_dict = OrderedDict(
             zip(_bases[b]['labels'], _bases[b]['atoms']))
         translation, angle, axis, point = find_transformations(
             base_dict[base_ref], base_dict["C1'"],
             atoms_dict[base_ref]._vector, atoms_dict["C1'"]._vector)
         q1 = Quaternion.angle_and_axis(angle, axis)
         # Align N9 C1'
         for k, v in base_dict.items():
             base_dict[k] = q1.rotate_vector(v, point) + translation
         # Rotate to align O4'
         axis = numpy.array(base_dict["C1'"]) - base_dict[base_ref]
         angle = dihedral(base_dict["O4'"], base_dict[base_ref],
                          base_dict["C1'"], atoms_dict["O4'"]) - rot_adj
         q2 = Quaternion.angle_and_axis(angle, axis)
         for k, v in list(base_dict.items()):
             if k not in atoms_dict:
                 atom = Atom(q2.rotate_vector(v, base_dict[base_ref]),
                             element=k[0],
                             parent=nucleotide,
                             res_label=k)
                 atoms_dict[k] = atom
         nucleotide.atoms = atoms_dict
         monomers.append(nucleotide)
     self._monomers = monomers
     self.relabel_monomers()
     self.relabel_atoms()
     return