def displace_struct(dcom, groups, d, grofile, ndxfile): ndx_mem = ot.put_ifile_in_memory(ndxfile) grouplist1 = st.indexlist(ndx_mem, groups[0]) grouplist2 = st.indexlist(ndx_mem, groups[1]) del ndx_mem del groups gro_mem = gio.put_grofile_in_memory(grofile) head_mem = gro_mem[0:2] tail_mem = gro_mem[-1] coordsnew_mem = gio.strip_gro(gro_mem) del gro_mem u = unit_vector(dcom) d_add = dcom[3] - float(d) add_to_gr1 = unit_vector_scalar_product(0.5 * d_add, u) add_to_gr2 = unit_vector_scalar_product(-0.5 * d_add, u) for i in grouplist1: line = coordsnew_mem[int(i) - 1] for j in range(len(add_to_gr1)): line[4 + j] = str(float(line[4 + j]) + add_to_gr1[j]) del grouplist1 del add_to_gr1 for i in grouplist2: line = coordsnew_mem[int(i) - 1] for j in range(len(add_to_gr2)): line[4 + j] = str(float(line[4 + j]) + add_to_gr2[j]) del grouplist2 del add_to_gr2 coordsnew_mem[:0] = head_mem coordsnew_mem.append(tail_mem) del head_mem del tail_mem ogrofile = re.sub('.gro', '_d' + d + '.gro', grofile) gio.write_gro(ogrofile, coordsnew_mem) return ogrofile
def find_groupnumber(group, ndxname): ndx_mem = ot.put_ifile_in_memory(ndxname) countgroup = 0 for line in ndx_mem: if ((len(line) > 0) and (re.match('\[', line[0]))): if (re.match(group, line[1])): break countgroup += 1 del ndx_mem return countgroup
def mindist_between_groups(cggrofile, cgndxfile, groups): mindistfile = 'mindist.xvg' ifacelist = ['-f ' + cggrofile, '-n ' + cgndxfile] stdin = [ str(find_groupnumber(groups[0], cgndxfile)), str(find_groupnumber(groups[1], cgndxfile)) ] gmx.g_g_mindist(ifacelist, stdin=stdin, log='mindist.err ') mindist_mem = ot.put_ifile_in_memory(mindistfile) mindist = float(mindist_mem[-1][-1]) del mindist_mem return mindist
def com_dist(cggro_merged, cgndx_merged): ndx_mem = ot.put_ifile_in_memory(cgndx_merged) # make backbone_grouplist bbgrouplist = [] for i in ndx_mem: for j in i: if (re.search('backbone', j)): bbgrouplist.append(j) bbatomlist = [] for group in bbgrouplist: bbatomlist.append(st.indexlist(ndx_mem, group)) del ndx_mem gro_mem = gio.put_grofile_in_memory(cggro_merged) comlist = [] for atlist in bbatomlist: comlist.append(COM(gro_mem, atlist)) return distance(comlist[0], comlist[1])