def pairwise_rmsdnpy(a, b): a = npy3to2(a) b = npy3to2(b) ncoord = np.shape(a[0])[0] RMSD = np.array([[(sum([(a1[i] - b1[i])**2 for i in range(ncoord)]) / (ncoord / 3))**0.5 for b1 in b] for a1 in a]) return RMSD
def rmsdnpy(npy, ref, selatoms): ref = ref.reshape(ref.shape[0] * ref.shape[1]) struc = npy3to2(npy[:, selatoms, :]) nat = len(selatoms) RMSD = [(sum([(s[i] - ref[i])**2 for i in range(nat * 3)]) / nat)**0.5 for s in struc] return RMSD
nfrag = int((len(c) - 3) * 0.5) chains = np.array([[int(i) - 1 for i in l.split()[3:3 + nfrag]] for l in cc]) if args.nfrag is None: nfrag = len(chains[0]) else: nfrag = args.nfrag assert nfrag == len(chains[0]) nat = args.nat[:nfrag + 2] # 7666 for AUUU m = [int(i) - 1 for i in args.motifs[:nfrag]] # motifs: 1 1 2 for AUU+UUU+UUU #assert nfrag == len(nat) - 2 assert len(m) == nfrag, (m, nfrag) struct = [npy3to2(np.load(i)) for i in args.npy] # one np.array per motif outp = args.outp assert outp != args.chains_file, "outp is same as input" c = [3 * n_atoms for n_atoms in nat] for i in range(nfrag): assert struct[m[i]].shape[1] == sum(c[i:i + 3]), (i, struct[m[i]].shape, sum(c[i:i + 3])) rna = np.zeros((len(chains), 3 * sum(nat))) #First nucleotide unchanged rna[:, :c[0]] = struct[m[0]][chains[:, 0], :c[0]] #Merge pairs of overlapping atoms in 1st overlap coor1 = struct[m[0]][chains[:, 0], c[0]:sum(c[:2])]
parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('npy', help="numpy coordinates") parser.add_argument("--ref", help="reference pdb structures", nargs='+') parser.add_argument("--sym", default=None, help="indices of symetrical atoms") parser.add_argument("--atoms", default=None, help="indices of atoms to consider") args = parser.parse_args() ####################################### refs = args.ref # convert references into lists of coordinates if refs[0].split(".")[-1] == "npy": refs = [npy3to2(np.load(r)) for r in refs] else: coors = [] for r in refs: ll = [l for l in open(r).readlines() if l.startswith("ATOM")] coor = [[float(l[30:38]), float(l[38:46]), float(l[46:54])] for l in ll] coors.append(coor) refs = np.array(coors) npy = npy2to3(np.load(args.npy)) nat = np.shape(npy)[1] selatoms = range(nat) if args.atoms: selatoms = [int(i) - 1 for i in args.atoms]
outp = name + '-dr' + str(args.cutoff) + '.npy' else: outp = args.outp if args.fit: print("fitting", file=sys.stderr) from rmsdlib import multifit rotation, translation, RMSD = multifit(npy, npy[0]) rot = np.transpose(rotation, axes=(0, 2, 1)) COM = npy.sum(axis=1) / npy.shape[1] translated = npy - COM[:, None, :] #print(rot.shape, file=sys.stderr) #print(translated.shape, file=sys.stderr) npy = np.einsum('...ij,...jk->...ik', translated, rot) npy = npy[[i for i in range(len(RMSD)) if RMSD[i] > args.cutoff or i == 0]] if not args.center: COM1 = npy[0].sum(axis=0) npy = npy + COM1 from cluster import cluster nn = npy3to2(npy) c = cluster(npy3to2(npy), args.cutoff, args.chunksize) centers = np.array([c[k][0] for k in list(c.keys())]) npclust = npy[centers] clustlist = open('%s-clust%.1f.list' % (name, args.cutoff), "w") print(name + "-clust" + str(args.cutoff)) for k in centers: print("%i " % (k + 1), file=clustlist) np.save(outp, npclust) clustlist.close()