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)
示例#2
0
    def runTest(self):
        num_aa = torch.zeros(self.batch_size,
                             dtype=torch.int,
                             device=self.device).random_(
                                 int(self.length / 2), self.length)
        sequences = [
            ''.join(['G' for i in range(num_aa[j].item())])
            for j in range(self.batch_size)
        ]
        fa_angles = torch.randn(self.batch_size,
                                8,
                                self.length,
                                dtype=torch.double,
                                device='cpu')
        coords_fa, res_names, atom_names, num_atoms = self.a2c(
            fa_angles, sequences)

        R = getRandomRotation(self.batch_size)
        T = torch.randn(self.batch_size, 3, dtype=torch.double, device='cpu')
        rot_coords_fa = self.rotate(coords_fa, R, num_atoms)
        tra_rot_coords_fa = self.translate(rot_coords_fa, T, num_atoms)

        tra_rot_coords_fa = tra_rot_coords_fa.to(device=self.device,
                                                 dtype=self.dtype)
        coords_fa = coords_fa.to(device=self.device, dtype=self.dtype)
        num_atoms = num_atoms.to(device=self.device, dtype=torch.int)
        min_rmsd = self.rmsd(tra_rot_coords_fa, coords_fa, num_atoms)
        for i in range(self.batch_size):
            self.assertAlmostEqual(min_rmsd[i].item(), 0.0, places=self.places)
示例#3
0
	def runTest(self):
		R = getRandomRotation(self.batch_size)
		#Matrixes should be det = 1
		for i in range(R.size(0)):
			U = R[i].numpy()
			D = np.linalg.det(U)
			self.assertAlmostEqual(D, 1.0, places=self.places)
示例#4
0
	def runTest(self):
		coords = torch.zeros_like(self.coords).copy_(self.coords).requires_grad_()
		
		#Random rotation matrixes
		R = getRandomRotation(self.batch_size).to(dtype=self.dtype, device=self.device)
		result = torch.autograd.gradcheck(self.rotate, (coords, R, self.num_atoms))
		self.assertTrue(result)
示例#5
0
def test_random_rotation(num_rotations):
	batch_size = num_rotations
	R = getRandomRotation(batch_size)
		
	num_atoms = torch.ones(R.size(0), dtype=torch.int)
	coords = torch.zeros(R.size(0),3, dtype=torch.double)
	coords[:,0]=1.0
	coords[:,1]=0.0
	coords[:,2]=0.0

	rotate = CoordsRotate()
	rotated = rotate(coords, R, num_atoms)
	
	return rotated
示例#6
0
	
	box_size = 80
	resolution = 1.25

	sequence = ['GGAGRRRGGWG']
	angles = torch.zeros(len(sequence), 7, len(sequence[0]), dtype=torch.double)
	angles[0,0,:] = -1.047
	angles[0,1,:] = -0.698
	angles[0,2:,:] = 110.4*np.pi/180.0
	a2c = Angles2Coords()
	c2cc = Coords2CenteredCoords(rotate=False, translate=False, box_size=box_size, resolution=resolution)
	c2tc = Coords2TypedCoords()
	tc2v = TypedCoords2Volume(box_size=box_size, resolution=resolution)
	rotate = CoordsRotate()
	translate = CoordsTranslate()
	R = getRandomRotation( len(sequence) )
	volume_rotate = VolumeRotation(mode='bilinear')

	
	#Generating protein and initial volume
	protein, res_names, atom_names, num_atoms = a2c(angles, sequence)
	protein = c2cc(protein, num_atoms)
	coords, num_atoms_of_type, offsets = c2tc(protein, res_names, atom_names, num_atoms)
	volume = tc2v(coords.cuda(), num_atoms_of_type.cuda(), offsets.cuda())

	#Rotating protein
	center = torch.zeros(len(sequence), 3, dtype=torch.double, device='cpu').fill_((box_size - 0.5)*resolution/2.0)
	centered_coords = translate(coords, -center, num_atoms)
	rotated_centered_coords = rotate(centered_coords, R, num_atoms)
	rotated_coords = translate(rotated_centered_coords, center, num_atoms)
	#Reprojecting protein