Exemplo n.º 1
0
def test_dihedral_backbone_result(file_name):
    import mdtraj

    mmtf_file = mmtf.MMTFFile()
    mmtf_file.read(file_name)
    array = mmtf.get_structure(mmtf_file, model=1)
    array = array[struc.filter_amino_acids(array)]
    for chain in struc.chain_iter(array):
        print("Chain: ", chain.chain_id[0])
        if len(struc.check_id_continuity(chain)) != 0:
            # Do not test discontinuous chains
            return
        test_phi, test_psi, test_ome = struc.dihedral_backbone(chain)

        temp_file_name = biotite.temp_file("pdb")
        strucio.save_structure(temp_file_name, chain)
        traj = mdtraj.load(temp_file_name)
        _, ref_phi = mdtraj.compute_phi(traj)
        _, ref_psi = mdtraj.compute_psi(traj)
        _, ref_ome = mdtraj.compute_omega(traj)
        ref_phi, ref_psi, ref_ome = ref_phi[0], ref_psi[0], ref_ome[0]

        assert test_phi[1:] == pytest.approx(ref_phi, abs=1e-5, rel=5e-3)
        assert test_psi[:-1] == pytest.approx(ref_psi, abs=1e-5, rel=5e-3)
        assert test_ome[:-1] == pytest.approx(ref_ome, abs=1e-5, rel=5e-3)
Exemplo n.º 2
0
def test_dihedral_backbone_result(file_name):
    import mdtraj

    mmtf_file = mmtf.MMTFFile.read(file_name)
    array = mmtf.get_structure(mmtf_file, model=1)
    array = array[struc.filter_amino_acids(array)]
    if array.array_length() == 0:
        # Structure contains no protein
        # -> determination of backbone angles makes no sense
        return

    for chain in struc.chain_iter(array):
        print("Chain: ", chain.chain_id[0])
        if len(struc.check_res_id_continuity(chain)) != 0:
            # Do not test discontinuous chains
            return
        test_phi, test_psi, test_ome = struc.dihedral_backbone(chain)

        temp = NamedTemporaryFile("w+", suffix=".pdb")
        strucio.save_structure(temp.name, chain)
        traj = mdtraj.load(temp.name)
        temp.close()
        _, ref_phi = mdtraj.compute_phi(traj)
        _, ref_psi = mdtraj.compute_psi(traj)
        _, ref_ome = mdtraj.compute_omega(traj)
        ref_phi, ref_psi, ref_ome = ref_phi[0], ref_psi[0], ref_ome[0]

        assert test_phi[1:] == pytest.approx(ref_phi, abs=1e-5, rel=5e-3)
        assert test_psi[:-1] == pytest.approx(ref_psi, abs=1e-5, rel=5e-3)
        assert test_ome[:-1] == pytest.approx(ref_ome, abs=1e-5, rel=5e-3)
Exemplo n.º 3
0
def run_dihedral_extraction(CP, outdir):
    MEGA_PHI = []
    MEGA_PSI = []
    MEGA_OMEGA = []
    for residue_index in range(1, CP.n_residues - 3):
        print(residue_index)
        PHI = np.degrees(
            np.transpose(md.compute_phi(CP.traj)[1])[residue_index])
        PSI = np.degrees(
            np.transpose(md.compute_psi(CP.traj)[1])[residue_index])
        OMEGA = np.degrees(
            np.transpose(md.compute_omega(CP.traj)[1])[residue_index])

        MEGA_PHI.append(PHI)
        MEGA_PSI.append(PSI)
        MEGA_OMEGA.append(OMEGA)

    np.savetxt('%s/PSI_matrix.csv' % (outdir),
               np.array(MEGA_PSI),
               delimiter=', ')
    np.savetxt('%s/PHI_matrix.csv' % (outdir),
               np.array(MEGA_PHI),
               delimiter=', ')
    np.savetxt('%s/OMEGA_matrix.csv' % (outdir),
               np.array(MEGA_OMEGA),
               delimiter=', ')
Exemplo n.º 4
0
def get_dihedrals(hdf_file, trajectory, structure,
                  chunk=1000, atoms=None, start=0, stride=1):
    """ Evaluate the dihedral angles and store it as HDF5 dataset """
    trj_iterator = mdtraj.iterload(
        trajectory, top=structure, chunk=chunk, atom_indices=atoms, skip=start,
        stride=stride)
    first_trj_chunk = next(trj_iterator)
    print(f'Calculating dihedrals for trajectory between '
          f'{first_trj_chunk.time[0]} and {first_trj_chunk.time[-1]} ps')
    phi_indices, phi = mdtraj.compute_phi(first_trj_chunk)
    psi_indices, psi = mdtraj.compute_psi(first_trj_chunk)
    omega_indices, omega = mdtraj.compute_omega(first_trj_chunk)

    time = [first_trj_chunk.time]
    phi_array = [phi]
    psi_array = [psi]
    omega_array = [omega]
    for trj_chunk in trj_iterator:
        print(f'Calculating dihedrals for trajectory between '
              f'{trj_chunk.time[0]} and {trj_chunk.time[-1]} ps')
        time.append(trj_chunk.time)
        phi_array.append(mdtraj.compute_phi(trj_chunk)[1])
        psi_array.append(mdtraj.compute_psi(trj_chunk)[1])
        omega_array.append(mdtraj.compute_omega(trj_chunk)[1])

    group = hdf_file.require_group('dihedrals')
    phi_data = numpy.vstack(phi_array)
    phi_dset = group.require_dataset('phi',
                                     data=phi_data,
                                     shape=phi_data.shape,
                                     dtype=phi_data.dtype)
    psi_data = numpy.vstack(psi_array)
    psi_dset = group.require_dataset('psi',
                                     data=psi_data,
                                     shape=psi_data.shape,
                                     dtype=psi_data.dtype)
    omega_data = numpy.vstack(omega_array)
    omega_dset = group.require_dataset('omega',
                                       data=omega_data,
                                       shape=omega_data.shape,
                                       dtype=omega_data.dtype)
    phi_dset.attrs['indices'] = phi_indices.astype(numpy.int32)
    psi_dset.attrs['indices'] = psi_indices.astype(numpy.int32)
    omega_dset.attrs['indices'] = omega_indices.astype(numpy.int32)
    return numpy.hstack(time)
Exemplo n.º 5
0
def test_shape_when_none():
    t = md.load(get_fn('frame0.h5'))
    np.hstack((md.compute_phi(t)[1],
               md.compute_psi(t)[1],
               md.compute_chi1(t)[1],
               md.compute_chi2(t)[1],
               md.compute_chi3(t)[1],
               md.compute_chi1(t)[1],
               md.compute_omega(t)[1]))
Exemplo n.º 6
0
def test_shape_when_none():
    t = md.load(get_fn('frame0.h5'))
    np.hstack((md.compute_phi(t)[1],
               md.compute_psi(t)[1],
               md.compute_chi1(t)[1],
               md.compute_chi2(t)[1],
               md.compute_chi3(t)[1],
               md.compute_chi1(t)[1],
               md.compute_omega(t)[1]))
Exemplo n.º 7
0
def dataset_phi_psi_omega(traj):
    dataset = []
    indices, angles1 = md.compute_phi(traj)
    indices, angles2 = md.compute_psi(traj)
    indices, angles3 = md.compute_omega(traj)
    angles = np.concatenate((angles1, angles2, angles3), axis=1)
    dataset.append(angles)
    print("Done constructing dataset using Phi angles")
    return dataset
Exemplo n.º 8
0
    def calculate_dihedrals(self, save=True):
	""" 
	Calculates dihedral angles using mdtraj functions given omega, psi, or phi

	Parameters:
	    save: Saves to dihedrals_(angle).npy if True (default True)
	
	Returns:
	    indices: The indices that dihedrals are being calculated for
	    dihedrals: The calculated dihedral angles 	
	"""
	print('Calculating dihedrals for angle %s...' % self.angle) 
	if self.angle == 'phi':
	    indices, dihedrals = md.compute_phi(self.traj)
	elif self.angle == 'psi':
	    indices, dihedrals = md.compute_psi(self.traj)
	else:
	    indices, dihedrals = md.compute_omega(self.traj)
	if save:
	    load_and_save(self, dihedrals)
	    print('Dihedrals saved for index [%d][%d][%d]' % (self.run_num, self.clone_num, self.gen_num))
	return indices, dihedrals
Exemplo n.º 9
0
print('define basis functions: heavy-atom contact distances, heavy atom coordinates, all torsions, inverse distances')
print('\n')
sys.stdout.flush()

featurizer = coor.featurizer(topology)
featurizer.add_residue_mindist(residue_pairs='all', scheme='closest-heavy')
featurizer.add_all()
featurizer.add_backbone_torsions(cossin=True)
featurizer.add_chi1_torsions(cossin=True)
indx = md.compute_chi2(traj)[0]
featurizer.add_dihedrals(indx, cossin=True)
indx = md.compute_chi3(traj)[0]
featurizer.add_dihedrals(indx, cossin=True)
indx = md.compute_chi4(traj)[0]
featurizer.add_dihedrals(indx, cossin=True)
indx = md.compute_omega(traj)[0]
featurizer.add_dihedrals(indx, cossin=True)
indx = md.compute_contacts(traj,contacts='all',scheme='closest-heavy')[1]
featurizer.add_custom_func(one_over_d, np.shape(indx)[0])

print(featurizer.describe())
print(featurizer.dimension())
sys.stdout.flush()

# use featurizer to read in trajectories
inp = coor.source([trajfile], featurizer, chunk_size=10000, stride=nskip)

#--------------------------------------------------------------------
# define lag time(s) and run TICA calculation on the trajectory

setup= len(lags)