Пример #1
0
	def setUp(self):
		self.sequence = ['GGGGGG', 'GGGGGG']
		angles = torch.zeros(len(self.sequence), 7,len(self.sequence[0]), dtype=torch.double, device='cpu')
		angles[0,0,:] = -1.047
		angles[0,1,:] = -0.698
		angles[0,2:,:] = np.pi
		angles[0,3:,:] = 110.4*np.pi/180.0
		a2c = Angles2Coords()
		self.coords, self.res_names, self.atom_names, self.num_atoms = a2c(angles, self.sequence)
		self.c2tc = Coords2TypedCoords()
Пример #2
0
def measure_trace(length=700, device='cuda'):
    x0 = torch.randn(1, 3, length, dtype=torch.float, device=device)
    x0.data[:, 2, :].fill_(-3.1318)
    length = torch.zeros(1, dtype=torch.int, device=device).fill_(length)
    a2c = Angles2Backbone()
    proteins = a2c(x0, length)
    proteins = proteins.data.cpu().resize_(1, 3 * length, 3).numpy()

    a2cfa = Angles2Coords()
    x0 = x0.cpu()
    sequence = ''.join(['A' for i in range(length)])

    x1 = torch.zeros(1, 7, length, dtype=torch.double)
    x1.data[:, 0:2, :].copy_(x0.data[:, 0:2, :])

    proteins_fa, res_names, atom_names, num_atoms = a2cfa(x1, [sequence])
    proteins_fa = proteins_fa.data.cpu().resize_(1, num_atoms.data[0],
                                                 3).numpy()

    error = []
    index = []
    k = 0
    for i in range(num_atoms.data[0]):
        if atom_names.data[0, i, 0] == 67 and atom_names.data[0, i,
                                                              1] == 0:  #C
            error.append(
                np.linalg.norm(proteins[0, k, :] - proteins_fa[0, i, :]))
            index.append(k)
            k += 1
        if atom_names.data[0, i, 0] == 67 and atom_names.data[
                0, i, 1] == 65 and atom_names.data[0, i, 2] == 0:  #CA
            error.append(
                np.linalg.norm(proteins[0, k, :] - proteins_fa[0, i, :]))
            index.append(k)
            k += 1
        if atom_names.data[0, i, 0] == 78 and atom_names.data[0, i,
                                                              1] == 0:  #N
            error.append(
                np.linalg.norm(proteins[0, k, :] - proteins_fa[0, i, :]))
            index.append(k)
            k += 1

    return error, index
    print(center)

    centered_coords = translate(coords, -center, num_atoms)
    a, b = getBBox(centered_coords, num_atoms)
    center = (a + b) * 0.5

    print(center)


def test_rotation(coords, num_atoms):
    batch_size = num_atoms.size(0)
    R = getRandomRotation(batch_size)
    rotate = CoordsRotate()
    rotated = rotate(coords, R, num_atoms)

    print(rotated)


if __name__ == '__main__':

    sequences = ['GGGGGG', 'GGAARRRRRRRRR']
    angles = torch.zeros(2, 7, len(sequences[1]), dtype=torch.double)
    angles[:, 0, :] = -1.047
    angles[:, 1, :] = -0.698
    angles[:, 2:, :] = 110.4 * np.pi / 180.0
    a2c = Angles2Coords()
    protein, res_names, atom_names, num_atoms = a2c(angles, sequences)

    test_translation(protein, num_atoms)
    test_rotation(protein, num_atoms)
Пример #4
0
import mpl_toolkits.mplot3d.axes3d as p3
import seaborn as sea
import torch.optim as optim

from TorchProteinLibrary.FullAtomModel import Angles2Coords
from TorchProteinLibrary.ReducedModel import Angles2Backbone

if __name__ == '__main__':
    L = 700
    x0 = torch.randn(1, 2, L, dtype=torch.float, device='cuda')
    length = torch.zeros(1, dtype=torch.int, device='cuda').fill_(L)
    a2c = Angles2Backbone()
    proteins = a2c(x0, length)
    proteins = proteins.data.cpu().resize_(1, 3 * L, 3).numpy()

    a2cfa = Angles2Coords()
    x0 = x0.cpu()
    sequence = ''
    for i in range(L):
        sequence += 'A'

    x1 = torch.zeros(1, 7, L, dtype=torch.double)
    x1.data[:, 0:2, :].copy_(x0.data)

    proteins_fa, res_names, atom_names, num_atoms = a2cfa(x1, [sequence])
    proteins_fa = proteins_fa.data.cpu().resize_(1, num_atoms.data[0],
                                                 3).numpy()

    error = []
    k = 0
    for i in range(num_atoms.data[0]):