def calc_lipid_contacts(universe, cut_off):

    # reset the centre of mass list for each residue
    com_array = []

    # Cycle through every residue and get it's centre of mass based on it's side chain atoms (from dict)
    for resid in resid_list:
        sel = universe.select_atoms("resid " + str(resid))

        com_array.append(
            sel.select_atoms(
                "name " +
                str(term_atom_dict[sel.resnames[0]])).atoms.center_of_mass())

    # convert centre of mass array (a list) for next step, define the head group of the POPC groups.
    com_array = np.array(com_array, dtype="float32")

    popc_head = universe.select_atoms("resname POPC and name P")

    if cut_off:
        # Calc distances of CoMs of residues and POPC heads within a cut off, returns a boolean array
        d = dist(com_array, popc_head.atoms.positions) <= cut_off

    else:
        # Calc distances of CoMs of residues and POPC heads
        d = dist(com_array, popc_head.atoms.positions)

    return d
Example #2
0
 def time_dist_offsets(self, num_atoms):
     """Benchmark calculation of distances between
     atoms in two atomgroups with offsets
     to resids.
     """
     distances.dist(A=self.ag1,
                    B=self.ag2,
                    offset=20)
Example #3
0
def main():
    arg_parser = argparse.ArgumentParser(description='通过给定残基名称,残基内原子数目,两个原子在残基内的索引(从0开始),计算所有残基内这两个原子之间的直线距离。')
    arg_parser.add_argument('resname', action='store', help='残基名称')
    arg_parser.add_argument('atoms_num', type=int, action='store', help='残基内原子数目')
    arg_parser.add_argument('index1', type=int, action='store', help='第一个原子的索引,索引从0开始')
    arg_parser.add_argument('index2', type=int, action='store', help='第二个原子的索引,索引从0开始')
    arg_parser.add_argument('topology_file', action='store', help='拓扑文件,例如gro, pdb')
    args = arg_parser.parse_args()

    resname, atoms_num, index1, index2 = args.resname, args.atoms_num, args.index1, args.index2

    universe = Universe(args.topology_file)
    atom_groups = universe.selectAtoms("resname " + resname)
    if len(atom_groups) % atoms_num != 0:
        print("拓扑文件内对应残基原子总数不是所给原子数目的整数倍,请给予正确的原子数目。")
        exit(1)

    atoms1 = []
    atoms2 = []
    for i in range(0, len(atom_groups), atoms_num):
        atoms1.append(atom_groups[i:i + atoms_num][index1])
        atoms2.append(atom_groups[i:i + atoms_num][index2])

    dists = dist(AtomGroup(atoms1), AtomGroup(atoms2))
    print("The distance between atoms %s and %s is:" % (index1, index2))
    for i in dists[2]:
        print(i)
    print("The average distance between atoms %s and %s is:" % (index1, index2))
    print(np.average(dists[2]))
Example #4
0
def cbcb(res):
	#mol is an md universe
#	res,name_file_dcd,mol=args
	mol = MD.Universe(pdb_file, dcd_file)
	output = ''
	print "["+str(res)+"] Calculating CB-CB for residue " + str(res) + ". " + str(res - res_beg) + " of " + str(res_num)
	cf_timer = time.time()
	try:
		CB_A = mol.selectAtoms("resid " + str(res) + " and name CB and segid A")
		CB_B = mol.selectAtoms("resid " + str(res) + " and name CB and segid B")
	except:
		CB_A = mol.selectAtoms("resid " + str(res) + " and name CA and segid A")
	        CB_B = mol.selectAtoms("resid " + str(res) + " and name CA and segid B")
		
	if 1 == 1:
		d_list = []
		frame = 0
		output = ''
		for ts1 in mol.trajectory[0:-1:skip]:
			d = MDdist.dist(CB_A, CB_B)
			d_list.append(d[2])
			output += str(res) + "\t" + str(frame) + "\t%.5f" % d[2] + "\n"
			
			#print str(frame) + '\t' + str(d[2])
			frame += 1
		dlist = numpy.array(d_list)
		print "["+str(res)+"]" + '\t' + str(numpy.average(d_list)) + '\t' + str(numpy.std(d_list)) + '\tin ' + str(time.time()-cf_timer) + " seconds.\n"
		filename = name_file_dcd + "cbcb_numpy.%03d.txt" % res
		outfile = open(filename, 'w')
		outfile.write(output)
		outfile.close()
Example #5
0
def cbcb(res):
    #mol is an md universe
    #	res,name_file_dcd,mol=args
    mol = MD.Universe(pdb_file, dcd_file)
    output = ''
    print "[" + str(res) + "] Calculating CB-CB for residue " + str(
        res) + ". " + str(res - res_beg) + " of " + str(res_num)
    cf_timer = time.time()
    try:
        CB_A = mol.selectAtoms("resid " + str(res) +
                               " and name CB and segid A")
        CB_B = mol.selectAtoms("resid " + str(res) +
                               " and name CB and segid B")
    except:
        CB_A = mol.selectAtoms("resid " + str(res) +
                               " and name CA and segid A")
        CB_B = mol.selectAtoms("resid " + str(res) +
                               " and name CA and segid B")

    if 1 == 1:
        d_list = []
        frame = 0
        output = ''
        for ts1 in mol.trajectory[0:-1:skip]:
            d = MDdist.dist(CB_A, CB_B)
            d_list.append(d[2])
            output += str(res) + "\t" + str(frame) + "\t%.5f" % d[2] + "\n"

            #print str(frame) + '\t' + str(d[2])
            frame += 1
        dlist = numpy.array(d_list)
        print "[" + str(res) + "]" + '\t' + str(
            numpy.average(d_list)) + '\t' + str(
                numpy.std(d_list)) + '\tin ' + str(time.time() -
                                                   cf_timer) + " seconds.\n"
        filename = name_file_dcd + "cbcb_numpy.%03d.txt" % res
        outfile = open(filename, 'w')
        outfile.write(output)
        outfile.close()
Example #6
0
    C_A = mol.selectAtoms("resid " + str(res_C) + " and name CA and segid A")
    C_B = mol.selectAtoms("resid " + str(res_C) + " and name CA and segid B")
    N_A = mol.selectAtoms("resid " + str(res_N) + " and name CA and segid A")
    N_B = mol.selectAtoms("resid " + str(res_N) + " and name CA and segid B")

    CA2NB = []
    CB2NA = []
    CA2CB = []
    CA2NA = []
    CB2NB = []
    NA2NB = []

    f = 0
    for ts1 in mol.trajectory:

        CA2NB.append(MDdist.dist(C_A, N_B)[2])
        CB2NA.append(MDdist.dist(C_B, N_A)[2])
        CA2CB.append(MDdist.dist(C_A, C_B)[2])
        CA2NA.append(MDdist.dist(C_A, N_A)[2])
        CB2NB.append(MDdist.dist(C_B, N_B)[2])
        NA2NB.append(MDdist.dist(N_A, N_B)[2])

        hdisp_R += str(f) + '\t' + str(res_C) + '_' + str(
            res_N) + '\t' + name_file_dcd.split(
                '.')[0] + '\t%.3f' % MDdist.dist(
                    C_A, N_B)[2] + '\t%.3f' % MDdist.dist(
                        C_B, N_A)[2] + '\t%.3f' % MDdist.dist(
                            C_A, C_B)[2] + '\t%.3f' % MDdist.dist(
                                C_A, N_A)[2] + '\t%.3f' % MDdist.dist(
                                    C_B, N_B)[2] + '\t%.3f\n' % MDdist.dist(
                                        N_A, N_B)[2]
Example #7
0
def smallest_distance_to(A, group_B, box):  #计算A原子和group B所有原子最小映像距离的函数
    return dist(MDAnalysis.core.groups.AtomGroup(
        [A for i in range(len(group_B))]),
                group_B,
                box=box)[-1]
Example #8
0
        C_B = mol.selectAtoms("resid " + str(res_C) + " and name CA and segid B")
	N_A = mol.selectAtoms("resid " + str(res_N) + " and name CA and segid A")
        N_B = mol.selectAtoms("resid " + str(res_N) + " and name CA and segid B")

	CA2NB = []
	CB2NA = []
	CA2CB = []
	CA2NA = []
	CB2NB = []
	NA2NB = []
	

	f = 0
	for ts1 in mol.trajectory:

		CA2NB.append(MDdist.dist(C_A, N_B)[2])
		CB2NA.append(MDdist.dist(C_B, N_A)[2])
		CA2CB.append(MDdist.dist(C_A, C_B)[2])
                CA2NA.append(MDdist.dist(C_A, N_A)[2])
		CB2NB.append(MDdist.dist(C_B, N_B)[2])
                NA2NB.append(MDdist.dist(N_A, N_B)[2])


		hdisp_R	+= str(f) + '\t' + str(res_C) + '_' + str(res_N) + '\t' + name_file_dcd.split('.')[0] + '\t%.3f' % MDdist.dist(C_A, N_B)[2] + '\t%.3f' % MDdist.dist(C_B, N_A)[2] + '\t%.3f' % MDdist.dist(C_A, C_B)[2] + '\t%.3f' % MDdist.dist(C_A, N_A)[2] + '\t%.3f' % MDdist.dist(C_B, N_B)[2] + '\t%.3f\n' % MDdist.dist(N_A, N_B)[2]
		f += 1
				

	CA2NB = numpy.array(CA2NB)
	CB2NA = numpy.array(CB2NA)
	CA2CB = numpy.array(CA2CB)
        CA2NA = numpy.array(CA2NA)
def hbond_calculations(universe, lambda_data, resid, nc_freq, lambda_freq, min_step = -1, max_step = -1, hbond_cutoff = 2.4, salt_bridge_cutoff = 4.0,
                       biglambda = 0.8, smalllambda = 0.2):
    if salt_bridge_cutoff > hbond_cutoff:
        cutoff = salt_bridge_cutoff
    else:
        cutoff = hbond_cutoff
    main_resname = universe.select_atoms('resid {}'.format(resid))[0].resname
    if main_resname == 'AS2' or main_resname == 'GL2':
        titrres = lambda_data.titrreses.index(int(resid))
        lambda_index = lambda_data.ititrs[titrres]
        x_index = lambda_index + 1
    donated_hbonds = 0
    accepted_hbonds = 0
    salt_bridges = 0
    mixed_frames = 0
    step_ratio = nc_freq / lambda_freq
    if min_step > 0:
        min_iter = math.floor(min_step / nc_freq)
    else:
        min_iter = 0
    if max_step > 0:
        max_iter = math.floor(max_step / nc_freq)
    else:
        max_iter = len(universe.trajectory)
    frames = max_iter - min_iter
    for i, ts in enumerate(universe.trajectory[min_iter:max_iter]):
        lambda_step_index = math.floor(i * step_ratio)
        if main_resname == 'AS2' or main_resname == 'GL2':
            if lambda_step_index >= len(lambda_data.lambdavals[lambda_index]):
                print('WTH {} {} {} {} {} {}'.format(step_ratio, max_iter, i, len(lambda_data.lambdavals[lambda_index]), lambda_step_index, len(universe.trajectory)))
            mylambda = lambda_data.lambdavals[lambda_index][lambda_step_index]
            myx = lambda_data.lambdavals[x_index][lambda_step_index]
            mixed = False
            if mylambda > biglambda and myx < smalllambda:
                protonated = False
                taut_state = 1
            elif mylambda > biglambda and myx > biglambda:
                protonated = False
                taut_state = 2
            elif mylambda < smalllambda and myx < smalllambda:
                protonated = True
                taut_state = 1
            elif mylambda < smalllambda and myx > biglambda:
                protonated = True
                taut_state = 2
            else:
                mixed = True
                mixed_frames += 1
        if not mixed:
            nearby_atoms = universe.select_atoms('around {} resid {}'.format(cutoff, resid))
            nearby_residues = []
            nearby_resnames = []
            for nearby_atom in nearby_atoms:
                nearby_resid = nearby_atom.resid
                resname = nearby_atom.resname
                if nearby_resid not in nearby_residues and nearby_resid != resid:
                    nearby_residues.append(nearby_resid)
                    nearby_resnames.append(resname)
            for j, nearby_resid in enumerate(nearby_residues):
                resname = nearby_resnames[j]
                if main_resname == 'AS2' or main_resname == 'GL2':
                    if main_resname == 'AS2':
                        od1_selection = universe.select_atoms('resid {} and name OD1'.format(resid))
                        od2_selection = universe.select_atoms('resid {} and name OD2'.format(resid))
                        hd1_selection = universe.select_atoms('resid {} and name HD1'.format(resid))
                        hd2_selection = universe.select_atoms('resid {} and name HD2'.format(resid))
                    else:
                        od1_selection = universe.select_atoms('resid {} and name OE1'.format(resid))
                        od2_selection = universe.select_atoms('resid {} and name OE2'.format(resid))
                        hd1_selection = universe.select_atoms('resid {} and name HE1'.format(resid))
                        hd2_selection = universe.select_atoms('resid {} and name HE2'.format(resid))
                    if not resname == 'PRO':
                        donor_selection = universe.select_atoms('resid {} and name H'.format(nearby_resid))
                        distances = [dist(od1_selection, donor_selection)[2][0],
                                     dist(od2_selection, donor_selection)[2][0]]
                        if not protonated:
                            if min(distances) < hbond_cutoff:
                                accepted_hbonds += 1
                        else:
                            if distances[0] < hbond_cutoff and taut_state == 2:
                                accepted_hbonds += 1
                            elif distances[1] < hbond_cutoff and taut_state == 1:
                                accepted_hbonds += 1
                    if protonated:
                        acceptor_selection = universe.select_atoms('resid {} and name O'.format(nearby_resid))
                        if taut_state == 1:
                            donor_selection = hd1_selection
                        else:
                            donor_selection = hd2_selection
                        distance = dist(donor_selection, acceptor_selection)[2][0]
                        if distance < hbond_cutoff:
                            donated_hbonds += 1
                    if not protonated and resname == 'ARG':
                        hh11_selection = universe.select_atoms('resid {} and name HH11'.format(nearby_resid))
                        hh12_selection = universe.select_atoms('resid {} and name HH12'.format(nearby_resid))
                        hh21_selection = universe.select_atoms('resid {} and name HH21'.format(nearby_resid))
                        hh22_selection = universe.select_atoms('resid {} and name HH22'.format(nearby_resid))
                        distance = min([dist(hh11_selection, od1_selection)[2][0],
                                        dist(hh12_selection, od1_selection)[2][0],
                                        dist(hh21_selection, od1_selection)[2][0],
                                        dist(hh22_selection, od1_selection)[2][0],
                                        dist(hh12_selection, od2_selection)[2][0],
                                        dist(hh12_selection, od2_selection)[2][0],
                                        dist(hh21_selection, od2_selection)[2][0],
                                        dist(hh22_selection, od2_selection)[2][0]])
                        if distance < salt_bridge_cutoff:
                            salt_bridges += 1
                    if protonated and resname == 'ARG' and taut_state == 1:
                        hh11_selection = universe.select_atoms('resid {} and name HH11'.format(nearby_resid))
                        hh12_selection = universe.select_atoms('resid {} and name HH12'.format(nearby_resid))
                        hh21_selection = universe.select_atoms('resid {} and name HH21'.format(nearby_resid))
                        hh22_selection = universe.select_atoms('resid {} and name HH22'.format(nearby_resid))
                        distance = min([dist(hh12_selection, od2_selection)[2][0],
                                        dist(hh12_selection, od2_selection)[2][0],
                                        dist(hh21_selection, od2_selection)[2][0],
                                        dist(hh22_selection, od2_selection)[2][0]])
                        if distance < hbond_cutoff:
                            accepted_hbonds += 1
                    if protonated and resname == 'ARG' and taut_state == 2:
                        hh11_selection = universe.select_atoms('resid {} and name HH11'.format(nearby_resid))
                        hh12_selection = universe.select_atoms('resid {} and name HH12'.format(nearby_resid))
                        hh21_selection = universe.select_atoms('resid {} and name HH21'.format(nearby_resid))
                        hh22_selection = universe.select_atoms('resid {} and name HH22'.format(nearby_resid))
                        distance = min([dist(hh12_selection, od1_selection)[2][0],
                                        dist(hh12_selection, od1_selection)[2][0],
                                        dist(hh21_selection, od1_selection)[2][0],
                                        dist(hh22_selection, od1_selection)[2][0]])
                        if distance < hbond_cutoff:
                            accepted_hbonds += 1
                    #Add non-titrating HIS?
                    if resname == 'HIP':
                        hip_titrres = lambda_data.titrreses.index(int(nearby_resid))
                        hip_lambda_index = lambda_data.ititrs[hip_titrres]
                        hip_lambda = lambda_data.lambdavals[hip_lambda_index][lambda_step_index]
                        hip_x = lambda_data.lambdavals[hip_lambda_index + 1][lambda_step_index]
                        other_hd1_selection = universe.select_atoms('resid {} and name HD1'.format(nearby_resid))
                        other_he2_selection = universe.select_atoms('resid {} and name HE2'.format(nearby_resid))
                        if hip_lambda > biglambda:
                            if hip_x < smalllambda:
                                if protonated and taut_state == 1:
                                    distance = dist(other_hd1_selection, od2_selection)[2][0]
                                    if distance < hbond_cutoff:
                                        accepted_hbonds += 1
                                    distance = dist(other_he2_selection, od1_selection)[2][0]
                                    if distance < hbond_cutoff:
                                        donated_hbonds += 1
                                elif protonated and taut_state == 2:
                                    distance = dist(other_hd1_selection, od1_selection)[2][0]
                                    if distance < hbond_cutoff:
                                        accepted_hbonds += 1
                                    distance = dist(other_he2_selection, od2_selection)[2][0]
                                    if distance < hbond_cutoff:
                                        donated_hbonds += 1
                                else:
                                    distance = min([dist(other_hd1_selection, od1_selection)[2][0],
                                                    dist(other_hd1_selection, od2_selection)[2][0]])
                                    if distance < hbond_cutoff:
                                        accepted_hbonds += 1
                            # Here I am assuming that if the H is not on ND1 it is on NE2. Change?
                            else:                                
                                if protonated and taut_state == 1:
                                    distance = dist(other_he2_selection, od2_selection)[2][0]
                                    if distance < hbond_cutoff:
                                        accepted_hbonds += 1
                                elif protonated and taut_state == 2:
                                    distance = dist(other_he2_selection, od1_selection)[2][0]
                                    if distance < hbond_cutoff:
                                        accepted_hbonds += 1
                                else:
                                    distance = min([dist(other_he2_selection, od1_selection)[2][0],
                                                    dist(other_he2_selection, od2_selection)[2][0]])
                                    if distance < hbond_cutoff:
                                        accepted_hbonds += 1
                        #Here I am assuming that if hip is not unprotonated, it can form a salt bridge. Change?
                        elif not protonated:
                            distance = min([dist(other_hd1_selection, od1_selection)[2][0],
                                            dist(other_he2_selection, od1_selection)[2][0],
                                            dist(other_hd1_selection, od2_selection)[2][0],
                                            dist(other_he2_selection, od2_selection)[2][0]])
                            if distance < salt_bridge_cutoff:
                                salt_bridges += 1
                        elif taut_state == 1:
                            distance = min([dist(other_hd1_selection, od2_selection)[2][0],
                                            dist(other_he2_selection, od2_selection)[2][0]])
                            if distance < hbond_cutoff:
                                accepted_hbonds += 1
                        else:
                            distance = min([dist(other_hd1_selection, od2_selection)[2][0],
                                            dist(other_he2_selection, od2_selection)[2][0]])
                            if distance < hbond_cutoff:
                                accepted_hbonds += 1
                    if not protonated and resname == 'LYS':
                        hz1_selection = universe.select_atoms('resid {} and name HZ1'.format(nearby_resid))
                        hz2_selection = universe.select_atoms('resid {} and name HZ2'.format(nearby_resid))
                        hz3_selection = universe.select_atoms('resid {} and name HZ3'.format(nearby_resid))
                        distance = min([dist(hz1_selection, od1_selection)[2][0],
                                        dist(hz2_selection, od1_selection)[2][0],
                                        dist(hz3_selection, od1_selection)[2][0],
                                        dist(hz1_selection, od2_selection)[2][0],
                                        dist(hz2_selection, od2_selection)[2][0],
                                        dist(hz3_selection, od2_selection)[2][0]])
                        if distance < salt_bridge_cutoff:
                            salt_bridges += 1
                    if protonated and resname == 'LYS' and taut_state == 1:
                        hz1_selection = universe.select_atoms('resid {} and name HZ1'.format(nearby_resid))
                        hz2_selection = universe.select_atoms('resid {} and name HZ2'.format(nearby_resid))
                        hz3_selection = universe.select_atoms('resid {} and name HZ3'.format(nearby_resid))
                        distance = min([dist(hz1_selection, od2_selection)[2][0],
                                        dist(hz2_selection, od2_selection)[2][0],
                                        dist(hz3_selection, od2_selection)[2][0]])
                        if distance < hbond_cutoff:
                            accepted_hbonds += 1
                    if protonated and resname == 'LYS' and taut_state == 2:
                        hz1_selection = universe.select_atoms('resid {} and name HZ1'.format(nearby_resid))
                        hz2_selection = universe.select_atoms('resid {} and name HZ2'.format(nearby_resid))
                        hz3_selection = universe.select_atoms('resid {} and name HZ3'.format(nearby_resid))
                        distance = min([dist(hz1_selection, od1_selection)[2][0],
                                        dist(hz2_selection, od1_selection)[2][0],
                                        dist(hz3_selection, od1_selection)[2][0]])
                        if distance < hbond_cutoff:
                            accepted_hbonds += 1
                    if resname == 'AS2' or resname == 'GL2':
                        other_titrres = lambda_data.titrreses.index(int(nearby_resid))
                        other_lambda_index = lambda_data.ititrs[other_titrres]
                        other_lambda = lambda_data.lambdavals[other_lambda_index][lambda_step_index]
                        other_x = lambda_data.lambdavals[other_lambda_index + 1][lambda_step_index]
                        if resname == 'AS2':
                            other_od1_selection = universe.select_atoms('resid {} and name OD1'.format(nearby_resid))
                            other_od2_selection = universe.select_atoms('resid {} and name OD2'.format(nearby_resid))
                            other_hd1_selection = universe.select_atoms('resid {} and name HD1'.format(nearby_resid))
                            other_hd2_selection = universe.select_atoms('resid {} and name HD2'.format(nearby_resid))
                        else:
                            other_od1_selection = universe.select_atoms('resid {} and name OE1'.format(nearby_resid))
                            other_od2_selection = universe.select_atoms('resid {} and name OE2'.format(nearby_resid))
                            other_hd1_selection = universe.select_atoms('resid {} and name HE1'.format(nearby_resid))
                            other_hd2_selection = universe.select_atoms('resid {} and name HE2'.format(nearby_resid))
                        if other_lambda > biglambda and protonated:
                            if taut_state == 1:
                                distance = min([dist(hd1_selection, other_od1_selection)[2][0],
                                                dist(hd1_selection, other_od2_selection)[2][0]])
                                if distance < hbond_cutoff:
                                    donated_hbonds += 1
                            else:
                                distance = min([dist(hd2_selection, other_od1_selection)[2][0],
                                                dist(hd2_selection, other_od2_selection)[2][0]])
                                if distance < hbond_cutoff:
                                    donated_hbonds += 1
                        #Again, assuming that if lambda < biglambda, then is protonated.
                        elif other_lambda < biglambda and not protonated:
                            if other_x < smalllambda:
                                distance = min([dist(other_hd1_selection, od1_selection)[2][0],
                                               dist(other_hd1_selection, od2_selection)[2][0]])
                                if distance < hbond_cutoff:
                                    accepted_hbonds += 1
                            else:
                                distance = min([dist(other_hd2_selection, od1_selection)[2][0],
                                               dist(other_hd2_selection, od2_selection)[2][0]])
                                if distance < hbond_cutoff:
                                    accepted_hbonds += 1
                        elif other_lambda < biglambda and protonated:
                            if other_x < smalllambda and taut_state == 1:
                                distance = dist(other_hd1_selection, od2_selection)[2][0]
                                if distance < hbond_cutoff:
                                    accepted_hbonds += 1
                                distance = dist(hd1_selection, other_od2_selection)[2][0]
                                if distance < hbond_cutoff:
                                    donated_hbonds += 1
                            elif other_x < smalllambda and taut_state == 2:
                                distance = dist(other_hd1_selection, od1_selection)[2][0]
                                if distance < hbond_cutoff:
                                    accepted_hbonds += 1
                                distance = dist(hd2_selection, other_od2_selection)[2][0]
                                if distance < hbond_cutoff:
                                    donated_hbonds += 1
                            elif other_x > smalllambda and taut_state == 1:
                                distance = dist(other_hd2_selection, od2_selection)[2][0]
                                if distance < hbond_cutoff:
                                    accepted_hbonds += 1
                                distance = dist(hd1_selection, other_od1_selection)[2][0]
                                if distance < hbond_cutoff:
                                    donated_hbonds += 1
                            elif other_x > smalllambda and taut_state == 2:
                                distance = dist(other_hd2_selection, od1_selection)[2][0]
                                if distance < hbond_cutoff:
                                    accepted_hbonds += 1
                                distance = dist(hd2_selection, other_od1_selection)[2][0]
                                if distance < hbond_cutoff:
                                    donated_hbonds += 1
                    if resname == 'SER':
                        hg_selection = universe.select_atoms('resid {} and name HG'.format(nearby_resid))
                        if not protonated:
                            distance = min([dist(hg_selection, od1_selection)[2][0],
                                           dist(hg_selection, od2_selection)[2][0]])
                        elif taut_state == 1:
                            distance = dist(hg_selection, od2_selection)[2][0]
                        elif taut_state == 2:
                            distance = dist(hg_selection, od1_selection)[2][0]
                        if distance < hbond_cutoff:
                            accepted_hbonds += 1
                    if resname == 'THR':
                        hg_selection = universe.select_atoms('resid {} and name HG1'.format(nearby_resid))
                        if not protonated:
                            distance = min([dist(hg_selection, od1_selection)[2][0],
                                           dist(hg_selection, od2_selection)[2][0]])
                        elif taut_state == 1:
                            distance = dist(hg_selection, od2_selection)[2][0]
                        elif taut_state == 2:
                            distance = dist(hg_selection, od1_selection)[2][0]
                        if distance < hbond_cutoff:
                            accepted_hbonds += 1
                    if resname == 'ASN':
                        other_od1_selection = universe.select_atoms('resid {} and name OD1'.format(nearby_resid))
                        other_hd21_selection = universe.select_atoms('resid {} and name HD21'.format(nearby_resid))
                        other_hd22_selection = universe.select_atoms('resid {} and name HD22'.format(nearby_resid))
                        if not protonated:
                            distance = min([dist(other_hd21_selection, od1_selection)[2][0],
                                           dist(other_hd22_selection, od1_selection)[2][0],
                                           dist(other_hd21_selection, od2_selection)[2][0],
                                           dist(other_hd22_selection, od2_selection)[2][0]])
                            if distance < hbond_cutoff:
                                accepted_hbonds += 1
                        elif taut_state == 1:
                            distance = min([dist(other_hd21_selection, od2_selection)[2][0],
                                           dist(other_hd22_selection, od2_selection)[2][0]])
                            if distance < hbond_cutoff:
                                accepted_hbonds += 1
                            distance = dist(other_od1_selection, hd1_selection)[2][0]
                            if distance < hbond_cutoff:
                                donated_hbonds += 1
                        elif taut_state == 2:
                            distance = min([dist(other_hd21_selection, od1_selection)[2][0],
                                           dist(other_hd22_selection, od1_selection)[2][0]])
                            if distance < hbond_cutoff:
                                accepted_hbonds += 1
                            distance = dist(other_od1_selection, hd2_selection)[2][0]
                            if distance < hbond_cutoff:
                                donated_hbonds += 1
                    if resname == 'GLN':
                        other_od1_selection = universe.select_atoms('resid {} and name OE1'.format(nearby_resid))
                        other_hd21_selection = universe.select_atoms('resid {} and name HE21'.format(nearby_resid))
                        other_hd22_selection = universe.select_atoms('resid {} and name HE22'.format(nearby_resid))
                        if not protonated:
                            distance = min([dist(other_hd21_selection, od1_selection)[2][0],
                                           dist(other_hd22_selection, od1_selection)[2][0],
                                           dist(other_hd21_selection, od2_selection)[2][0],
                                           dist(other_hd22_selection, od2_selection)[2][0]])
                            if distance < hbond_cutoff:
                                accepted_hbonds += 1
                        elif taut_state == 1:
                            distance = min([dist(other_hd21_selection, od2_selection)[2][0],
                                           dist(other_hd22_selection, od2_selection)[2][0]])
                            if distance < hbond_cutoff:
                                accepted_hbonds += 1
                            distance = dist(other_od1_selection, hd1_selection)[2][0]
                            if distance < hbond_cutoff:
                                donated_hbonds += 1
                        elif taut_state == 2:
                            distance = min([dist(other_hd21_selection, od1_selection)[2][0],
                                           dist(other_hd22_selection, od1_selection)[2][0]])
                            if distance < hbond_cutoff:
                                accepted_hbonds += 1
                            distance = dist(other_od1_selection, hd2_selection)[2][0]
                            if distance < hbond_cutoff:
                                donated_hbonds += 1
                    #Here assuming CYS is not titrating. Fix this later.
                    if resname == 'CYS':
                        hg_selection = universe.select_atoms('resid {} and name HG'.format(nearby_resid))
                        if not protonated:
                            distance = min([dist(hg_selection, od1_selection)[2][0],
                                           dist(hg_selection, od2_selection)[2][0]])
                        elif taut_state == 1:
                            distance = dist(hg_selection, od2_selection)[2][0]
                        elif taut_state == 2:
                            distance = dist(hg_selection, od1_selection)[2][0]
                        if distance < hbond_cutoff:
                            accepted_hbonds += 1
                    if resname == 'PRO':
                        n_selection = universe.select_atoms('resid {} and name N'.format(nearby_resid))
                        if protonated:
                            if taut_state == 1:
                                h_selection = hd1_selection
                            else:
                                h_selection = hd2_selection
                            distance = dist(n_selection, h_selection)[2][0]
                            if distance < hbond_cutoff:
                                donated_hbonds += 1
                    #Here ignoring that TYR can also accept
                    if resname == 'TYR':
                        h_selection = universe.select_atoms('resid {} and name HH'.format(nearby_resid))
                        if not protonated:
                            distance = min([dist(h_selection, od1_selection)[2][0],
                                           dist(h_selection, od2_selection)[2][0]])
                        elif taut_state == 1:
                            distance = dist(h_selection, od2_selection)[2][0]
                        else:
                            distance = dist(h_selection, od1_selection)[2][0]
                        if distance < hbond_cutoff:
                            accepted_hbonds += 1
                    if resname == 'TRP':
                        h_selection = universe.select_atoms('resid {} and name HE1'.format(nearby_resid))
                        if not protonated:
                            distance = min([dist(h_selection, od1_selection)[2][0],
                                           dist(h_selection, od2_selection)[2][0]])
                        elif taut_state == 1:
                            distance = dist(h_selection, od2_selection)[2][0]
                        else:
                            distance = dist(h_selection, od1_selection)[2][0]
                        if distance < hbond_cutoff:
                            accepted_hbonds += 1
    return accepted_hbonds, donated_hbonds, salt_bridges, frames, mixed_frames
Example #10
0
select_mol1 = u.select_atoms(str(atomtxt1))
select_mol2 = u.select_atoms(str(atomtxt2))
if len(select_mol1) % args.nmol != 0:
    raise ValueError(
        "wrong # molecules, (args.nmol, select_mol) {} {} ".format(
            args.nmol, len(select_mol1)))
if len(select_mol2) % args.nmol != 0:
    raise ValueError(
        "wrong # molecules, (args.nmol, select_mol) {} {} ".format(
            args.nmol, len(select_mol2)))

## read trajectory
i_frame = 0
imod = hjung.time.process_init()
for ts in u.trajectory[skip_frames:]:
    data_ree[i_frame] = distances.dist(select_mol1, select_mol2)[2]
    #vec_tmp = select_mol2.positions - select_mol1.positions
    #print(np.sqrt(np.sum(np.dot(vec_tmp[0],vec_tmp[0]))))
    #print(data_ree[i_frame][0])
    data_ree_vec[i_frame] = select_mol2.positions - select_mol1.positions
    i_frame = i_frame + 1
    imod = hjung.time.process_print(i_frame, n_frames, imod)
print("read total {} frames".format(i_frame))

# save raw rg data file
np.savetxt(args.output,
           data_ree,
           header='Ree (mean = {} +- {} with {} frames'.format(
               np.mean(data_ree), np.std(data_ree), n_frames),
           fmt='%f',
           comments='# ')
Example #11
0
if len(CAs1) > 0 and len(CAs2) > 0:
    res_set = {CAs1.resnames[0], CAs2.resnames[0]}
    print(res_set)
else:
    res_set = ''

dist_arr = np.zeros([u.trajectory.n_frames, 2])

i = 0

#if there is more than 1 residue in each selection do distances things are weird and this code wont work properly.
if ((CAs1.n_atoms == CAs2.n_atoms ==
     1)) == False and (sel1.n_atoms > 1) and (sel2.n_atoms > 1):
    print("doing normal distance measurements")
    for ts in u.trajectory:
        dist1 = dist(sel1, sel2)
        dist_arr[i][1] = dist1
        dist_arr[i][0] = ts.time * 0.001
        i = i + 1

elif (CAs1.n_atoms == CAs2.n_atoms == 1) and (sel1.n_atoms == sel2.n_atoms ==
                                              1):
    #checking out if we only have CA atoms
    print("Detected CAs selection")
    for ts in u.trajectory:
        dist1 = dist(sel1, sel2)
        dist_arr[i][1] = dist1[-1]
        dist_arr[i][0] = ts.time * 0.001
        i = i + 1

#else its single residue distances and we are going to want to do fancy things.
Example #12
0
    num_models = len(u.trajectory)

    # for each ssbond, loop through pdb models and
    # calculate average CA-CA distance
    for ssbond in range(0, count_ssbonds):
        # select CA in ssbonds
        string = str(
            str("avg and stdev for CA-CA distance in ssbond between resids ") +
            str(resid1[ssbond]) + str(" and ") + str(resid2[ssbond]) + "\n")
        outfile.write(string)
        CA_CA_dist = []
        CA_resid1 = u.select_atoms("resid " + str(resid1[ssbond]) +
                                   " and name CA")
        CA_resid2 = u.select_atoms("resid " + str(resid2[ssbond]) +
                                   " and name CA")
        if (len(distances.dist(CA_resid1, CA_resid2)[2]) > 1):
            print "ss bond excluded due to multiple chains", pdb_file
        else:
            for ts in u.trajectory[0:num_models:1]:
                CA_CA_dist.append(distances.dist(CA_resid1, CA_resid2)[2])
                ssbonds_all.append(distances.dist(CA_resid1, CA_resid2)[2])
            string = str(
                str(np.mean(CA_CA_dist)) + " +/- " + str(np.std(CA_CA_dist)) +
                "\n")
            outfile.write(string)
            if (np.mean(CA_CA_dist) < 4.20):
                print pdb_file
        #print np.mean(CA_CA_dist)
        #print np.std(CA_CA_dist)

print "collected data for", len(ssbonds_all), "ss-bonds from ", len(
Example #13
0
def smallest_distance_to(A, group_B, box):
    return dist(MDAnalysis.core.groups.AtomGroup([A for i in range(len(group_B))]), group_B, box=box)[-1]
Example #14
0
def atom_dist(cooridnates_a, cooridnates_b):
    distance = dist(cooridnates_a, cooridnates_b)
    return distance
Example #15
0
def compute_simple_protein_features(u, key_res):
    """
    This function takes the PDB code, chain id and certain coordinates of a kinase from
    a command line and returns its structural features.

    Parameters
    ----------
    u : object
        A MDAnalysis.core.universe.Universe object of the input structure (a pdb file or a simulation trajectory).
    key_res : dict of int
        A dictionary (with keys 'group0' ... 'group4') of feature-related residue indices in five feature groups.
    Returns
    -------
    features: list of floats
        A list (single structure) or lists (multiple frames in a trajectory) of 72 features in 5 groups (A-loop, P-loop, aC, DFG, FRET)

    .. todo :: Use kwargs with sensible defaults instead of relying only on positional arguments.


    """
    from MDAnalysis.core.groups import AtomGroup
    from MDAnalysis.analysis.dihedrals import Dihedral
    from MDAnalysis.analysis.distances import dist
    import numpy as np
    import pandas as pd

    # get the array of atom indices for the calculation of:
    #       * seven dihedrals (a 7*4 array where each row contains indices of the four atoms for each dihedral)
    #       * two ditances (a 2*2 array where each row contains indices of the two atoms for each dihedral)
    dih = np.zeros(shape=(7, 4), dtype=int, order="C")
    dis = np.zeros(shape=(2, 2), dtype=int, order="C")

    # name list of the dihedrals and distances
    dih_names = ["xDFG_phi", "xDFG_psi", "dFG_phi", "dFG_psi", "DfG_phi", "DfG_psi", "DfG_chi1"]
    dis_names = ["DFG_conf1", "DFG_conf2", "DFG_conf3", "DFG_conf4"]

    # parse the topology info (0-based atom indices)

    ### dihedrals (feature group 3)
    # dihedral 0 & 1: X-DFG Phi & Psi
    dih[0][0] = int(u.select_atoms(f"resid {key_res['group3'][0]-1} and name C")[0].ix)  # xxDFG C
    dih[0][1] = int(u.select_atoms(f"resid {key_res['group3'][0]} and name N")[0].ix)  # xDFG N
    dih[0][2] = int(u.select_atoms(f"resid {key_res['group3'][0]} and name CA")[0].ix)  # xDFG CA
    dih[0][3] = int(u.select_atoms(f"resid {key_res['group3'][0]} and name C")[0].ix)  # xDFG C
    dih[1][0] = dih[0][1]  # xDFG N
    dih[1][1] = dih[0][2]  # xDFG CA
    dih[1][2] = dih[0][3]  # xDFG C
    dih[1][3] = int(u.select_atoms(f"resid {key_res['group3'][1]} and name N")[0].ix)  # DFG-Asp N

    # dihedral 2 & 3: DFG-Asp Phi & Psi
    dih[2][0] = dih[0][3]  # xDFG C
    dih[2][1] = dih[1][3]  # DFG-Asp N
    dih[2][2] = int(
        u.select_atoms(f"resid {key_res['group3'][1]} and name CA")[0].ix
    )  # DFG-Asp CA
    dih[2][3] = int(u.select_atoms(f"resid {key_res['group3'][1]} and name C")[0].ix)  # DFG-Asp C
    dih[3][0] = dih[2][1]  # DFG-Asp N
    dih[3][1] = dih[2][2]  # DFG-Asp CA
    dih[3][2] = dih[2][3]  # DFG-Asp C
    dih[3][3] = int(u.select_atoms(f"resid {key_res['group3'][2]} and name N")[0].ix)  # DFG-Phe N

    # dihedral 4 & 5: DFG-Phe Phi & Psi
    dih[4][0] = dih[2][3]  # DFG-Asp C
    dih[4][1] = dih[3][3]  # DFG-Phe N
    dih[4][2] = int(
        u.select_atoms(f"resid {key_res['group3'][2]} and name CA")[0].ix
    )  # DFG-Phe CA
    dih[4][3] = int(u.select_atoms(f"resid {key_res['group3'][2]} and name C")[0].ix)  # DFG-Phe C
    dih[5][0] = dih[4][1]  # DFG-Phe N
    dih[5][1] = dih[4][2]  # DFG-Phe CA
    dih[5][2] = dih[4][3]  # DFG-Phe C
    dih[5][3] = int(
        u.select_atoms(f"resid {key_res['group3'][2]+1} and name N")[0].ix
    )  # DFG-Gly N

    # dihedral 6: DFG-Phe Chi1
    dih[6][0] = dih[3][3]  # DFG-Phe N
    dih[6][1] = dih[4][2]  # DFG-Phe CA
    dih[6][2] = int(
        u.select_atoms(f"resid {key_res['group3'][2]} and name CB")[0].ix
    )  # DFG-Phe CB
    dih[6][3] = int(
        u.select_atoms(f"resid {key_res['group3'][2]} and name CG")[0].ix
    )  # DFG-Phe CG

    ### distances
    ## Dunbrack distances D1, D2
    dis[0][0] = int(u.select_atoms(f"resid {key_res['group3'][3]} and name CA")[0].ix)  # ExxxX CA
    dis[0][1] = int(
        u.select_atoms(f"resid {key_res['group3'][2]} and name CZ")[0].ix
    )  # DFG-Phe CZ
    dis[1][0] = int(
        u.select_atoms(f"resid {key_res['group2'][3]} and name CA")[0].ix
    )  # K in beta III CA
    dis[1][1] = dis[0][1]  # DFG-Phe CZ

    # check if there is any missing coordinates; if so, skip dihedral/distance calculation for those residues
    check_flag = 1
    for i in range(len(dih)):
        if 0 in dih[i]:
            dih[i] = [0, 0, 0, 0]
            check_flag = 0

    for i in range(len(dis)):
        if 0 in dis[i]:
            dis[i] = [0, 0]
            check_flag = 0
    if check_flag:
        print("There is no missing coordinates.  All dihedrals and distances will be computed.")

    # compute dihedrals and distances
    distances = list()
    dih_ags = list()
    for i in range(7):  # for each of the dihedrals
        dih_ags.append(AtomGroup(dih[i], u))
    dihedrals = Dihedral(dih_ags).run().angles

    each_frame = list()
    for i in range(2):
        ag0 = AtomGroup([dis[i][0]], u)  # first atom in each atom pair
        ag1 = AtomGroup([dis[i][1]], u)  # second atom in each atom pair
        each_frame.append(dist(ag0, ag1)[-1][0])
    each_frame = np.array(each_frame)
    distances.append(each_frame)

    # clean up
    del u, dih, dis
    return dihedrals, distances
Example #16
0
################################################################################################

Rgyr1 = []
Rgyr2 = []
Rgyr3 =[]
Rgyr4 = []

end_to_end_1_norm = []
end_to_end_2_norm = []
end_to_end_3_norm = []
end_to_end_4_norm = []


for ts in u1.trajectory:
    Rgyr1.append((u1.trajectory.time, at1.radius_of_gyration()))
    xyz = ds.dist(res1_1, res2_1)
    end_to_end_1_norm.append((u1.trajectory.time, xyz[2,0]))

for ts in u2.trajectory:
    Rgyr2.append((u2.trajectory.time, at2.radius_of_gyration()))
    xyz = ds.dist(res1_2, res2_2)
    end_to_end_2_norm.append((u2.trajectory.time, xyz[2,0]))

for ts in u3.trajectory:
    Rgyr3.append((u3.trajectory.time, at3.radius_of_gyration()))
    xyz = ds.dist(res1_3, res2_3)
    end_to_end_3_norm.append((u3.trajectory.time, xyz[2,0]))


for ts in u4.trajectory:
    Rgyr4.append((u4.trajectory.time, at4.radius_of_gyration()))