def _rmsd(res):
	#mol is an md universe
	#res,name_file_dcd,mol=args
	mol = MD.Universe(pdb_file, dcd_file)
	print "["+str(res)+"] Aligning Trajectory"
	ref_sel = ref.selectAtoms('backbone and resid ' + str(res),'backbone and around ' + cutoff + ' (backbone and resid ' + str(res) + ')')
	print ref_sel.atoms
	ref_sel_str = ''
	for i in list(ref_sel):
		useful =str(i).split(":")[1]
		ref_sel_str += '(' + useful.replace('>',' ').replace("'",'').replace(',',' and').replace('of','and') + ') or '
		#ref_sel_str += "(" + useful.replace('>',' ').replace("'",'') + ') or '
	ref_sel_str = ref_sel_str[:-4] 
	#print ref_sel_str
	filenamedcd = "LA" + cutoff + "rmsd.noh.R" + str(res) + '.dcd'
	MDA.rms_fit_trj(mol, ref, select=ref_sel_str, filename = filenamedcd ) #'name N and type N and resname MET resid 1 and segid P1')
	output = ''

	print "["+str(res)+"] Calculating RMSD for residue " + str(res) + "..." + str( 1 + range(res_beg,res_end).index(res) ) + " of " + str(res_num)
	mol = MD.Universe(pdb_file, filenamedcd)
	cf_timer = time.time()
	atoms_mol = mol.selectAtoms("resid " + str(res) + " and not name H")
	mol.trajectory[ref_frame]
	atoms_ref = copy.deepcopy(mol.selectAtoms("resid " + str(res) + " and not name H").coordinates())
	rmsd = []
	for ts1 in mol.trajectory[0:-1:skip]:
		rmsd.append(MDA.rmsd(atoms_mol.coordinates(), atoms_ref))
	
	rmsd = numpy.array(rmsd)
	numpy.savetxt(name_file_dcd + "rmsd.noh.LA" + cutoff +".%04d.txt" % res , rmsd)
	os.remove(filenamedcd)
Пример #2
0
def calc_rmsd(args):
    """
    input : args -> from read_traj_vmd
    calculates g2(t) rmsd, and plots to file using save_plot_rmsd
    """

    psffile = os.path.splitext(args.psffile)[0]
    u = Universe(psffile + '.psf', args.traj)
    ref_atoms = u.selectAtoms("all")
    traj_atoms = u.selectAtoms("all")
    frame = []
    rmsd_array = []

    # reference centre of mass system
    ref_com = ref_atoms.centerOfMass()
    ref_coordinates = ref_atoms.coordinates() - ref_com
    # diff_coordinates = ref_atoms.coordinates().copy

    # allocate the array for selection atom coords
    traj_coordinates = traj_atoms.coordinates().copy()

    for ts in u.trajectory[args.startframe:args.endframe:args.trajskip]:
        # selection is updated with the time frame
        x_com = traj_atoms.centerOfMass()
        traj_coordinates[:] = traj_atoms.coordinates() - x_com
        rmsd_value = MDrmsd.rmsd(traj_coordinates, ref_coordinates)

        print "frame ", ts.frame, " rmsd ", rmsd_value
        frame.append(ts.frame)
        rmsd_array.append(rmsd_value)
    frame = np.array(frame)
    rmsd_array = np.array(rmsd_array)
    save_plot_rmsd(frame, rmsd_array, psffile)
    return None
def _rmsd(res):
    #mol is an md universe
    #res,name_file_dcd,mol=args
    mol = MD.Universe(pdb_file, dcd_file)
    print "[" + str(res) + "] Aligning Trajectory"
    ref_sel = ref.selectAtoms(
        'backbone and resid ' + str(res), 'backbone and around ' + cutoff +
        ' (backbone and resid ' + str(res) + ')')
    print ref_sel.atoms
    ref_sel_str = ''
    for i in list(ref_sel):
        useful = str(i).split(":")[1]
        ref_sel_str += '(' + useful.replace('>', ' ').replace("'", '').replace(
            ',', ' and').replace('of', 'and') + ') or '
        #ref_sel_str += "(" + useful.replace('>',' ').replace("'",'') + ') or '
    ref_sel_str = ref_sel_str[:-4]
    #print ref_sel_str
    filenamedcd = "LA" + cutoff + "rmsd.noh.R" + str(res) + '.dcd'
    MDA.rms_fit_trj(
        mol, ref, select=ref_sel_str, filename=filenamedcd
    )  #'name N and type N and resname MET resid 1 and segid P1')
    output = ''

    print "[" + str(res) + "] Calculating RMSD for residue " + str(
        res) + "..." + str(
            1 + range(res_beg, res_end).index(res)) + " of " + str(res_num)
    mol = MD.Universe(pdb_file, filenamedcd)
    cf_timer = time.time()
    atoms_mol = mol.selectAtoms("resid " + str(res) + " and not name H")
    mol.trajectory[ref_frame]
    atoms_ref = copy.deepcopy(
        mol.selectAtoms("resid " + str(res) + " and not name H").coordinates())
    rmsd = []
    for ts1 in mol.trajectory[0:-1:skip]:
        rmsd.append(MDA.rmsd(atoms_mol.coordinates(), atoms_ref))

    rmsd = numpy.array(rmsd)
    numpy.savetxt(name_file_dcd + "rmsd.noh.LA" + cutoff + ".%04d.txt" % res,
                  rmsd)
    os.remove(filenamedcd)
Пример #4
0
pdb_file = sys.argv[1]
dcd_file = sys.argv[2]

print "Loading trajectory"
ref = MDA.Universe(pdb_file)
mol = MDA.Universe(pdb_file, dcd_file)

mol_all = mol.selectAtoms('all')
ref_all = ref.selectAtoms('all')

rmsd_list = []

if "-a" in sys.argv:
	dataout = open(name_file_dcd + 'rmsd.A.txt', 'w')
	for frame in mol.trajectory:
		MDAaa.alignto(mol, ref, select = 'backbone', mass_weighted = True)
		rmsd_list.append(MDAaa.rmsd(mol_all.coordinates(),ref_all.coordinates()))
else:
	dataout = open(name_file_dcd + 'rmsd.txt', 'w')
	for frame in mol.trajectory:
                rmsd_list.append(MDAaa.rmsd(mol_all.coordinates(),ref_all.coordinates()))
	
output = ''

for i in range(len(rmsd_list)):
	output += str(i) + '\t' + '%.5f' % rmsd_list[i] + '\n'

dataout.write(output)
dataout.close()

Пример #5
0
			pick = 2
		else:
			print("fasta file irrelevant for requested operation... ignoring")
			alnlis = ref.residues.resnames()
	else:
		alnlis = ref.residues.resnames()

	for res in alnlis:
		try:
			refcrd = ref.selectAtoms("backbone and resid " + str(res)).coordinates()
		        trgcrd = trg.selectAtoms("backbone and resid " + str(res)).coordinates()
		except IndexError:
			print res
			print alndic[res]
			sys.exit()
		rmsd = MDA.rmsd(refcrd, trgcrd)
		if alnlis == ref.residues.resnames() or pick == 1:
			print(str(res) + ' * ' + str(rmsd))
                        output = str(res) + ' * ' + str(rmsd) + '\n'
		elif pick == 2:
			print(str(alndic[res]) + ' * ' + str(rmsd))
                        output = str(alndic[res]) + ' * ' + str(rmsd) + '\n'
else:
	if '-aln' not in sys.argv:
		print("Structure from different homologs or truncated. Please insert alignment")
		sys.exit()
	else:
		seq_dic, seq_list = bitk.fastareader(sys.argv[sys.argv.index('-aln')+1]) 
		if bitk.threeLetter2oneLetter(ref.residues.resnames()) != seq_dic[seq_list[0]].replace('-',''):
			print("input order is important. Please, make the input order coherent with the alignment file")
			sys.exit()
Пример #6
0
dcd_file = sys.argv[2]

print "Loading trajectory"
ref = MDA.Universe(pdb_file)
mol = MDA.Universe(pdb_file, dcd_file)

mol_all = mol.selectAtoms('all')
ref_all = ref.selectAtoms('all')

rmsd_list = []

if "-a" in sys.argv:
    dataout = open(name_file_dcd + 'rmsd.A.txt', 'w')
    for frame in mol.trajectory:
        MDAaa.alignto(mol, ref, select='backbone', mass_weighted=True)
        rmsd_list.append(
            MDAaa.rmsd(mol_all.coordinates(), ref_all.coordinates()))
else:
    dataout = open(name_file_dcd + 'rmsd.txt', 'w')
    for frame in mol.trajectory:
        rmsd_list.append(
            MDAaa.rmsd(mol_all.coordinates(), ref_all.coordinates()))

output = ''

for i in range(len(rmsd_list)):
    output += str(i) + '\t' + '%.5f' % rmsd_list[i] + '\n'

dataout.write(output)
dataout.close()
selected models and it should represent the entire trajectory.
@author:JamesPino
"""

import os
import numpy as np
from MDAnalysis import *
from MDAnalysis.analysis.align import rmsd


RMSD_Matrix=np.arange(1,4239)

f=open('rmsd.txt','w')
for i in range(1,4239):
    tmp_rmsd=[]
    for k in range(i+1,4239):
        main = Universe(str(i)+"x.pdb" )
        reference=Universe(str(k)+"x.pdb" )       
        bb = main.selectAtoms('backbone') 
        A = bb.coordinates()  # coordinates of main frame
        cc=reference.selectAtoms('backbone')        
        B = cc.coordinates()  # coordinates of reference frame
        x = rmsd(A,B);#print>>f , i , k , x;
        print  i , k , x;
        tmp_rmsd=np.append(tmp_rmsd,x)
    for j in range(i):
        tmp_rmsd=np.insert(tmp_rmsd,0,0)
    RMSD_Matrix=np.column_stack((RMSD_Matrix,tmp_rmsd))
np.savetxt('RMSD_MATRIX.out',RMSD_Matrix)