def test_ssmotif(): dist = bb.ds_motif(fname, fname1, l1=8, l2=7, bulges=0, threshold=0.65, out='%s/ds_motif' % outdir) stri = "" for el in dist: stri += " %8.5f " % el[1] for jj in el[2]: stri += "%s-" % jj stri += "\n" fh = open("%s/dsmotif_01.test.dat" % outdir, 'w') fh.write(stri) fh.close() comp("%s/dsmotif_01.test.dat" % refdir) # compare all pdbs of = glob.glob('%s/ds_motif*.pdb' % refdir) for f in of: comp(f)
def test_dump(): fh = open("%s/dump_01.test.dat" % outdir,'w') rvecs,resi = bb.dump_rvec(fname,cutoff=1.7) stri = "" for i1 in range(len(resi)): for i2 in range(len(resi)): if(sum((rvecs[0,i1,i2])**2) > 1.0e-5): stri += "%10s %10s %14e %14e %14e \n" % (resi[i1],resi[i2],rvecs[0,i1,i2,0],rvecs[0,i1,i2,1],rvecs[0,i1,i2,2]) fh.write(stri) fh.close() gvecs,resi = bb.dump_gvec(fname) fh = open("%s/dump_02.test.dat" % outdir,'w') stri = "" for i1 in range(len(resi)): for i2 in range(len(resi)): if(sum((gvecs[0,i1,i2])**2) > 1.0e-5): stri += "%10s %10s %14e %14e %14e %14e \n" % (resi[i1],resi[i2],gvecs[0,i1,i2,0],gvecs[0,i1,i2,1],gvecs[0,i1,i2,2],gvecs[0,i1,i2,3]) fh.write(stri) fh.close() comp("%s/dump_01.test.dat" % refdir) comp("%s/dump_02.test.dat" % refdir)
def test_cluster(): # first, calculate all g-vectors print("# Calculating G-vectors") gvec,seq = bb.dump_gvec(traj,top) lent = gvec.shape[0] gvec = gvec.reshape(lent,-1)[::5] print("# Calculating PCA. gvec shape: ", gvec.shape) # calculate PCA v,w = cc.pca(gvec,nevecs=3) print("# Cumulative explained variance of component: 1=%5.1f 2:=%5.1f 3=%5.1f" % (v[0]*100,v[1]*100,v[2]*100)) print("# DBSCAN clustering...") # do DBSCAN clustering. eps and min_samples need to be adjusted. new_labels, center_idx = cc.dbscan(gvec,range(gvec.shape[0]),eps=0.6/np.sqrt(8.),min_samples=10) print("DONE!") # create color palette. gray, small points for unassigned clusters. #cp = sns.color_palette("hls",len(center_idx)+1) #colors = [cp[j-1] if(j!=0) else (0.77,0.77,0.77) for j in new_labels] size = [5 if(j!=0) else 0.25 for j in new_labels] # do scatterplot #plt.scatter(w[:,0],w[:,1],s=size,c=colors) # now dump centroids and print labels on plot print("# Dump PDB centroids") t = md.load(traj, top=top) idxs = [ii for ii,kk in enumerate(new_labels) if(kk==0)] for i,k in enumerate(center_idx): t[k].save_pdb("%s/cluster_%03d.test.pdb" % (outdir,i)) comp("%s/cluster_%03d.test.pdb" % (refdir,i)) #plt.text(w[k,0],w[k,1],str(i),ha='center',va='center') idxs = [ii for ii,kk in enumerate(new_labels) if(kk==i+1)]
def test_dump(): fh = open("%s/dump_01.test.dat" % outdir, 'w') rvecs, resi = bb.dump_rvec(fname, cutoff=1.7) stri = "" for i1 in range(len(resi)): for i2 in range(len(resi)): if (sum((rvecs[0, i1, i2])**2) > 1.0e-5): stri += "%10s %10s %14e %14e %14e \n" % ( resi[i1], resi[i2], rvecs[0, i1, i2, 0], rvecs[0, i1, i2, 1], rvecs[0, i1, i2, 2]) fh.write(stri) fh.close() gvecs, resi = bb.dump_gvec(fname) fh = open("%s/dump_02.test.dat" % outdir, 'w') stri = "" for i1 in range(len(resi)): for i2 in range(len(resi)): if (sum((gvecs[0, i1, i2])**2) > 1.0e-5): stri += "%10s %10s %14e %14e %14e %14e \n" % ( resi[i1], resi[i2], gvecs[0, i1, i2, 0], gvecs[0, i1, i2, 1], gvecs[0, i1, i2, 2], gvecs[0, i1, i2, 3]) fh.write(stri) fh.close() comp("%s/dump_01.test.dat" % refdir) comp("%s/dump_02.test.dat" % refdir)
def test_score(): # set "force-field" ee = escore.Escore([ffname]) ss = ee.score(traj,topology=fname) fh = open("%s/score_01.test.dat" % outdir,'w') stri = " ".join(["%10.4e \n" % (ss[e]) for e in range(len(ss))]) fh.write(stri) fh.close() comp("%s/score_01.test.dat" % refdir)
def test_score(): # set "force-field" ee = escore.Escore([ffname]) ss = ee.score(traj, topology=fname) fh = open("%s/score_01.test.dat" % outdir, 'w') stri = " ".join(["%10.4e \n" % (ss[e]) for e in range(len(ss))]) fh.write(stri) fh.close() comp("%s/score_01.test.dat" % refdir)
def test_enm_6(): """Tests modes output""" # initialize class. Only PDB are accepted #SBP_enm = enm.Enm(fname,sparse=True) SBP_enm = enm.Enm(fname,sparse=True) import mdtraj as md traj_mode=SBP_enm.get_mode_traj(6) traj_mode.save_pdb("%s/enm_14.test.pdb" % outdir) comp("%s/enm_14.test.pdb" % refdir)
def test_rmsd_2(): # align pdb to pdb with different sequence fname = "%s/test/data/4v7t-pdb-bundle3_G521_00006.align.pdb" % cwd fname1 = "%s/test/data/centroid_10.pdb" % cwd dist = bb.rmsd(fname, fname1, out='%s/aligned_2.pdb' % outdir) stri = "".join(["%14e \n" % (dd) for dd in dist]) fh = open("%s/rmsd_02.test.dat" % outdir, 'w') fh.write(stri) fh.close() comp("%s/rmsd_02.test.dat" % refdir) comp("%s/aligned_2.pdb" % refdir)
def test_rmsd_2(): # align pdb to pdb with different sequence fname = "%s/test/data/4v7t-pdb-bundle3_G521_00006.align.pdb" % cwd fname1 = "%s/test/data/centroid_10.pdb" % cwd dist = bb.rmsd(fname,fname1,out='%s/aligned_2.pdb' % outdir) stri = "".join([ "%14e \n" % (dd) for dd in dist]) fh = open("%s/rmsd_02.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/rmsd_02.test.dat" % refdir) comp("%s/aligned_2.pdb" % refdir)
def test_ermsd_3(): fname = "%s/test/data/4v7t-pdb-bundle3_G521_00006.align.pdb" % cwd fname1 = "%s/test/data/centroid_10.pdb" % cwd dist = bb.ermsd(fname,fname1,cutoff=5.0) stri = "".join([ "%14e \n" % (dd) for dd in dist]) fh = open("%s/ermsd_03.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/ermsd_03.test.dat" % refdir) return 0
def test_rmsd_1(): # align pdb to pdb with the same sequence fname = "%s/test/data/sample1.pdb" % cwd fname1 = "%s/test/data/sample2.pdb" % cwd dist = bb.rmsd(fname,fname1,out='%s/aligned_1.pdb' % outdir,heavy_atom=True) stri = "".join([ "%14e \n" % (dd) for dd in dist]) fh = open("%s/rmsd_01.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/rmsd_01.test.dat" % refdir) comp("%s/aligned_1.pdb" % refdir)
def test_couplings_2(): angles,rr = bb.jcouplings(traj,topology=top,raw=True) fh = open("%s/couplings_02.test.dat" % outdir,'w') for e in range(angles.shape[0]): stri = "" for k in range(angles.shape[1]): for l in range(angles.shape[2]): stri += " %10.4f " % angles[e,k,l] stri += "\n" fh.write(stri) fh.close() comp("%s/couplings_02.test.dat" % refdir)
def test_ermsd_3(): fname = "%s/test/data/4v7t-pdb-bundle3_G521_00006.align.pdb" % cwd fname1 = "%s/test/data/centroid_10.pdb" % cwd dist = bb.ermsd(fname, fname1, cutoff=5.0) stri = "".join(["%14e \n" % (dd) for dd in dist]) fh = open("%s/ermsd_03.test.dat" % outdir, 'w') fh.write(stri) fh.close() comp("%s/ermsd_03.test.dat" % refdir) return 0
def test_rmsd_1(): # align pdb to pdb with the same sequence fname = "%s/test/data/sample1.pdb" % cwd fname1 = "%s/test/data/sample2.pdb" % cwd dist = bb.rmsd(fname, fname1, out='%s/aligned_1.pdb' % outdir) stri = "".join(["%14e \n" % (dd) for dd in dist]) fh = open("%s/rmsd_01.test.dat" % outdir, 'w') fh.write(stri) fh.close() comp("%s/rmsd_01.test.dat" % refdir) comp("%s/aligned_1.pdb" % refdir)
def test_enm_1(): '''Tests C2-C2 calculation''' # initialize class. Only PDB are accepted SBP_enm = enm.Enm(fname,sele_atoms=["C2","C1\'","P"]) # print eigenvectors evecs = SBP_enm.print_evec(3) fh = open("%s/enm_01.test.dat" % outdir,'w') fh.write(evecs) fh.close() # print eigenvalues evals = SBP_enm.print_eval() fh = open("%s/enm_02.test.dat" % outdir,'w') fh.write(evals) fh.close() # print mean square fluctuations fluc = SBP_enm.get_MSF() np.savetxt("%s/enm_03b.test.dat" % outdir,fluc,fmt='%.6e') # print C2'-C2' fluctuations fluc,res = SBP_enm.c2_fluctuations() fh = open("%s/enm_03.test.dat" % outdir,'w') stri = "# %19s %s \n" % ("Residues","Fluctuations") for i in range(len(fluc)): stri += "%10s/%-10s %.6e \n" % (res[i],res[i+1],fluc[i]) fh.write(stri) fh.close() comp("%s/enm_01.test.dat" % refdir) comp("%s/enm_02.test.dat" % refdir) comp("%s/enm_03.test.dat" % refdir) comp("%s/enm_03b.test.dat" % refdir)
def test_ermsd_4(): # align trajectory to pdb fname = "%s/test/data/sample1.pdb" % cwd fname1 = "%s/test/data/samples.xtc" % cwd dist = bb.ermsd(fname,fname1,topology=fname) stri = "".join([ "%14e \n" % (dd) for dd in dist]) fh = open("%s/ermsd_04.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/ermsd_04.test.dat" % refdir) return 0
def test(): print("# TEST %02d: %s" % (num, spec)) # initialize reweighting class rew = bme.Reweight() # load data rew.load(exp_train1, calc_train1) rew.load(exp_train2, calc_train2) rew.load(exp_train3, calc_train3) # do optimization using theta=2 chib, chia, srel = rew.optimize(theta=50) # compare NOE before and after optimization . # output is written to files with prefix 'example1_noe' chi2_b, chi2_a = rew.weight_exp(exp_train1, calc_train1, '%s/test_%02d_train1' % (outdir, num)) chi2_b, chi2_a = rew.weight_exp(exp_train2, calc_train2, '%s/test_%02d_train2' % (outdir, num)) chi2_b, chi2_a = rew.weight_exp(exp_train3, calc_train3, '%s/test_%02d_train3' % (outdir, num)) ww = rew.get_weights() fh = open("%s/test_%02d_weights.dat" % (outdir, num), "w") fh.write(" ".join(["%8.4f " % x for x in ww])) fh.close() comp("%s/test_%02d_weights.dat" % (refdir, num)) comp("%s/test_%02d_train1.stats.dat" % (refdir, num)) comp("%s/test_%02d_train2.stats.dat" % (refdir, num)) comp("%s/test_%02d_train3.stats.dat" % (refdir, num)) print("# TEST %02d: %s" % (num, spec)) print("# DONE #")
def test_rmsd_3(): # align trajectory to pdb fname = "%s/test/data/sample1.pdb" % cwd fname1 = "%s/test/data/samples.xtc" % cwd dist = bb.rmsd(fname,fname1,topology=fname,out='%s/aligned_3.xtc' % outdir,heavy_atom=True) stri = "".join([ "%14e \n" % (dd) for dd in dist]) fh = open("%s/rmsd_03.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/rmsd_03.test.dat" % refdir)
def test_ermsd_4(): # align trajectory to pdb fname = "%s/test/data/sample1.pdb" % cwd fname1 = "%s/test/data/samples.xtc" % cwd dist = bb.ermsd(fname, fname1, topology=fname) stri = "".join(["%14e \n" % (dd) for dd in dist]) fh = open("%s/ermsd_04.test.dat" % outdir, 'w') fh.write(stri) fh.close() comp("%s/ermsd_04.test.dat" % refdir) return 0
def test_ermsd_1(): # align pdb to pdb with the same sequence fname = "%s/test/data/sample1.pdb" % cwd fname1 = "%s/test/data/sample2.pdb" % cwd dist = bb.ermsd(fname,fname1) stri = "".join([ "%14e \n" % (dd) for dd in dist]) fh = open("%s/ermsd_01.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/ermsd_01.test.dat" % refdir) return 0
def test_angles_4(): resi = ["RG_69_0","RU_37_0"] angles = ["gamma","alpha"] angles_b,rr = bb.backbone_angles(fname1,topology=fname,residues=resi,angles=angles) stri = "" for p in range(angles_b.shape[0]): for k in range(angles_b.shape[2]): stri += " %10.4f %10.4f " % (angles_b[p,0,k],angles_b[p,1,k]) stri += "\n" fh = open("%s/angles_04.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/angles_04.test.dat" % refdir)
def test_rmsd_3(): # align trajectory to pdb fname = "%s/test/data/sample1.pdb" % cwd fname1 = "%s/test/data/samples.xtc" % cwd dist = bb.rmsd(fname, fname1, topology=fname, out='%s/aligned_3.xtc' % outdir) stri = "".join(["%14e \n" % (dd) for dd in dist]) fh = open("%s/rmsd_03.test.dat" % outdir, 'w') fh.write(stri) fh.close() comp("%s/rmsd_03.test.dat" % refdir)
def test_angles_1(): angles_b,rr = bb.backbone_angles(fname) fh = open("%s/angles_01.test.dat" % outdir,'w') stri = "%20s " % "#" for pp in dd.bb_angles: stri += " %10s " % pp stri += "\n" for e in range(angles_b.shape[1]): stri += "%20s " % (rr[e]) for k in range(angles_b.shape[2]): stri += " %10.4f " % angles_b[0,e,k] stri += "\n" fh.write(stri) fh.close() comp("%s/angles_01.test.dat" % refdir)
def test_sugar_1(): sugar_b, rr = bb.sugar_angles(fname) fh = open("%s/sugar_01.test.dat" % outdir, 'w') stri = "%20s " % "#" for pp in dd.sugar_angles: stri += " %10s " % pp stri += "\n" for e in range(sugar_b.shape[1]): stri += "%20s " % (rr[e]) for k in range(sugar_b.shape[2]): stri += " %10.4f " % sugar_b[0, e, k] stri += "\n" fh.write(stri) fh.close() comp("%s/sugar_01.test.dat" % refdir)
def test_sugar_3(): resi = ["RG_69_0", "RU_37_0"] na = ["Phase", "tm"] angles, rr = bb.pucker_angles(fname, residues=resi) stri = "".join([" %10s " % pp for pp in na]) stri += "\n" for e in range(angles.shape[1]): stri += "%20s " % (rr[e]) for k in range(angles.shape[2]): stri += " %10.4f " % angles[0, e, k] stri += "\n" fh = open("%s/sugar_03.test.dat" % outdir, 'w') fh.write(stri) fh.close() comp("%s/sugar_03.test.dat" % refdir)
def test_angles_4(): resi = ["RG_69_0", "RU_37_0"] angles = ["gamma", "alpha"] angles_b, rr = bb.backbone_angles(fname1, topology=fname, residues=resi, angles=angles) stri = "" for p in range(angles_b.shape[0]): for k in range(angles_b.shape[2]): stri += " %10.4f %10.4f " % (angles_b[p, 0, k], angles_b[p, 1, k]) stri += "\n" fh = open("%s/angles_04.test.dat" % outdir, 'w') fh.write(stri) fh.close() comp("%s/angles_04.test.dat" % refdir)
def test_sugar_3(): resi = ["RG_69_0","RU_37_0"] na = ["Phase","tm"] angles,rr = bb.pucker_angles(fname,residues=resi,altona=True) stri = "".join([" %10s " % pp for pp in na]) stri += "\n" for e in range(angles.shape[1]): stri += "%20s " % (rr[e]) for k in range(angles.shape[2]): stri += " %10.4f " % angles[0,e,k] stri += "\n" fh = open("%s/sugar_03.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/sugar_03.test.dat" % refdir)
def test_ssmotif(): dist = bb.ss_motif(fname,fname1,bulges=1,threshold=0.6,out='%s/ss_motif' % outdir) stri = "" for el in dist: stri += " %8.5f " % el[1] for jj in el[2]: stri += "%s-" % jj stri += "\n" fh = open("%s/ssmotif_01.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/ssmotif_01.test.dat" % refdir) # compare all pdbs of = glob.glob('%s/ss_motif*.pdb' % refdir) for f in of: comp(f)
def test_sugar_2(): resi = ["RC5_1_0","RG_69_0"] angles = ["nu1","nu4","nu3"] sugar_b,rr = bb.sugar_angles(fname,residues=resi,angles=angles) stri = "%20s " % "#" for pp in angles: stri += " %10s " % pp stri += "\n" for e in range(sugar_b.shape[1]): stri += "%20s " % (rr[e]) for k in range(sugar_b.shape[2]): stri += " %10.4f " % sugar_b[0,e,k] stri += "\n" fh = open("%s/sugar_02.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/sugar_02.test.dat" % refdir)
def test_sugar_2(): resi = ["RC5_1_0", "RG_69_0"] angles = ["nu1", "nu4", "nu3"] sugar_b, rr = bb.sugar_angles(fname, residues=resi, angles=angles) stri = "%20s " % "#" for pp in angles: stri += " %10s " % pp stri += "\n" for e in range(sugar_b.shape[1]): stri += "%20s " % (rr[e]) for k in range(sugar_b.shape[2]): stri += " %10.4f " % sugar_b[0, e, k] stri += "\n" fh = open("%s/sugar_02.test.dat" % outdir, 'w') fh.write(stri) fh.close() comp("%s/sugar_02.test.dat" % refdir)
def test_enm_5(): '''Tests RNA+protein complex (sparse)''' # initialize class. Only PDB are accepted AA_enm = enm.Enm(fname_prot, sele_atoms="AA", sparse=True, cutoff=0.7) # print eigenvalues evals = AA_enm.print_eval() fh = open("%s/enm_12.test.dat" % outdir, 'w') fh.write(evals) fh.close() # print eigenvectors evecs = AA_enm.print_evec(3) fh = open("%s/enm_13.test.dat" % outdir, 'w') fh.write(evecs) fh.close() comp("%s/enm_12.test.dat" % refdir) comp("%s/enm_13.test.dat" % refdir)
def test(): print("# TEST %02d: %s" % (num,spec)) # initialize reweighting class rew_bme = bme.Reweight() rows = range(0,20000,100) # load data rew_bme.load(exp_train,calc_train,rows=rows) # do optimization using theta=2, method MAXENT (default) chib,chia, srel = rew_bme.optimize(theta=2,method="MAXENT") ww_bme = rew_bme.get_weights() # initialize reweighting class rew_eros = bme.Reweight() # load data rew_eros.load(exp_train,calc_train,rows=rows) # do optimization using theta=2 chib,chia, srel = rew_eros.optimize(theta=2,method="BER") ww_ber = rew_eros.get_weights() diff=np.sqrt(np.sum(((ww_ber-ww_bme)**2))/len(ww_ber)) print(" rms difference between BER and BME: %10.5e" % diff) fh = open("%s/test_%02d_weights_bme.dat" % (outdir,num) ,"w") fh.write(" ".join(["%10.5e \n" % x for x in ww_bme]) ) fh.close() fh = open("%s/test_%02d_weights_ber.dat" % (outdir,num) ,"w") fh.write(" ".join(["%10.5e \n" % x for x in ww_ber]) ) fh.close() comp("%s/test_%02d_weights_ber.dat" % (refdir,num)) comp("%s/test_%02d_weights_bme.dat" % (refdir,num)) print("# TEST %02d: %s" % (num,spec)) print("# DONE #")
def test_enm_5(): '''Tests RNA+protein complex (sparse)''' # initialize class. Only PDB are accepted AA_enm = enm.Enm(fname_prot,sele_atoms="AA",sparse=True,cutoff=0.7) # print eigenvalues evals = AA_enm.print_eval() fh = open("%s/enm_12.test.dat" % outdir,'w') fh.write(evals) fh.close() # print eigenvectors evecs = AA_enm.print_evec(3) fh = open("%s/enm_13.test.dat" % outdir,'w') fh.write(evecs) fh.close() comp("%s/enm_12.test.dat" % refdir) comp("%s/enm_13.test.dat" % refdir)
def test_enm_2(): '''Tests different bead choices''' # initialize class. Only PDB are accepted S_enm = enm.Enm(fname,sele_atoms=["C1\'"],cutoff=1.5) SB_enm = enm.Enm(fname,sele_atoms=["C2","C1\'"],cutoff=1.1) # print eigenvalues S-ENM evals = S_enm.print_eval() fh = open("%s/enm_04.test.dat" % outdir,'w') fh.write(evals) fh.close() # print eigenvalues SB-ENM evals = SB_enm.print_eval() fh = open("%s/enm_05.test.dat" % outdir,'w') fh.write(evals) fh.close() comp("%s/enm_04.test.dat" % refdir) comp("%s/enm_05.test.dat" % refdir)
def test_angles_3(): resi = ["RG_69_0","RU_37_0"] angles = ["gamma","alpha"] angles_b,rr = bb.backbone_angles(fname,residues=resi,angles=angles) stri = "%20s " % "#" for pp in angles: stri += " %10s " % pp stri += "\n" for e in range(angles_b.shape[1]): stri += "%20s " % (rr[e]) for k in range(angles_b.shape[2]): stri += " %10.4f " % angles_b[0,e,k] stri += "\n" fh = open("%s/angles_03.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/angles_03.test.dat" % refdir)
def test_angles_3(): resi = ["RG_69_0", "RU_37_0"] angles = ["gamma", "alpha"] angles_b, rr = bb.backbone_angles(fname, residues=resi, angles=angles) stri = "%20s " % "#" for pp in angles: stri += " %10s " % pp stri += "\n" for e in range(angles_b.shape[1]): stri += "%20s " % (rr[e]) for k in range(angles_b.shape[2]): stri += " %10.4f " % angles_b[0, e, k] stri += "\n" fh = open("%s/angles_03.test.dat" % outdir, 'w') fh.write(stri) fh.close() comp("%s/angles_03.test.dat" % refdir)
def test_sugar_4(): resi = ["RC5_1_0","RG_69_0","RU_37_0"] na = ["Phase","tm"] angles_b,rr = bb.pucker_angles(fname,residues=resi) stri = "%20s " % "#" for pp in na: stri += " %10s " % pp stri += "\n" for e in range(angles_b.shape[1]): stri += "%20s " % (rr[e]) for k in range(angles_b.shape[2]): stri += " %10.4f " % angles_b[0,e,k] stri += "\n" fh = open("%s/sugar_04.test.dat" % outdir,'w') fh.write(stri) fh.close() comp("%s/sugar_04.test.dat" % refdir)
def test_annotate_2(): fname = "%s/test/data/1S72.pdb" % cwd stackings, pairings, res = bb.annotate(fname) dotbr,ss = bb.dot_bracket(pairings,res) fh = open("%s/stackings_02.test.dat" % outdir,'w') stri = "# STACKING \n" for e in range(len(stackings[0][0])): stri += "%15s " % (res[stackings[0][0][e][0]]) stri += "%15s " % (res[stackings[0][0][e][1]]) stri += " %4s \n" % (stackings[0][1][e]) fh.write(stri) fh.close() fh = open("%s/pairings_02.test.dat" % outdir,'w') stri = "# PAIRING \n" for e in range(len(pairings[0][0])): stri += "%15s " % (res[pairings[0][0][e][0]]) stri += "%15s " % (res[pairings[0][0][e][1]]) stri += " %4s \n" % (pairings[0][1][e]) fh.write(stri) fh.close() fh = open("%s/dotbracket_02.test.dat" % outdir,'w') fh.write(str(dotbr[0])) fh.close() comp("%s/stackings_02.test.dat" % refdir) comp("%s/pairings_02.test.dat" % refdir) comp("%s/dotbracket_02.test.dat" % refdir)
def test(): print("# TEST %02d: %s" % (num,spec)) # initialize reweighting class, use non-uniform initial weights bias = [float(line.split()[1]) for line in open(bias_file)] rew = bme.Reweight(w0=bias,kbt=kbt) # load data rew.load(exp_train,calc_train) # do optimization using theta=2 chib,chia, srel = rew.optimize(theta=1) # compare NOE before and after optimization . # output is written to files with prefix 'example1_noe' chi2_b,chi2_a = rew.weight_exp(exp_train,calc_train, '%s/test_%02d_train' % (outdir,num)) chi2_b,chi2_a = rew.weight_exp(exp_test,calc_test, '%s/test_%02d_test' % (outdir,num)) ww = rew.get_weights() fh = open("%s/test_%02d_weights.dat" % (outdir,num) ,"w") fh.write(" ".join(["%8.4f " % x for x in ww]) ) fh.close() comp("%s/test_%02d_weights.dat" % (refdir,num)) comp("%s/test_%02d_train.stats.dat" % (refdir,num)) comp("%s/test_%02d_test.stats.dat" % (refdir,num)) print("# TEST %02d: %s" % (num,spec)) print("# DONE #")
def test_enm_3(): '''Tests sparse diagonalization''' # initialize class. Only PDB are accepted AA_enm = enm.Enm(fname,sele_atoms="AA",sparse=True,cutoff=0.7) # print eigenvalues evals = AA_enm.print_eval() fh = open("%s/enm_06.test.dat" % outdir,'w') fh.write(evals) fh.close() # print eigenvectors evecs = AA_enm.print_evec(3) fh = open("%s/enm_07.test.dat" % outdir,'w') fh.write(evecs) fh.close() # print C2'-C2' fluctuations fluc,res = AA_enm.c2_fluctuations() fh = open("%s/enm_08.test.dat" % outdir,'w') stri = "# %19s %s \n" % ("Residues","Fluctuations") for i in range(len(fluc)): stri += "%10s/%-10s %.6e \n" % (res[i],res[i+1],fluc[i]) fh.write(stri) fh.close() comp("%s/enm_06.test.dat" % refdir) comp("%s/enm_07.test.dat" % refdir) comp("%s/enm_08.test.dat" % refdir)
def test_enm_4(): '''Tests RNA+protein complex''' # initialize class. Only PDB are accepted SBP_enm = enm.Enm(fname_prot,sparse=False) # print eigenvalues evals = SBP_enm.print_eval() fh = open("%s/enm_09.test.dat" % outdir,'w') fh.write(evals) fh.close() # print eigenvectors evecs = SBP_enm.print_evec(3) fh = open("%s/enm_10.test.dat" % outdir,'w') fh.write(evecs) fh.close() # print C2'-C2' fluctuations fluc,res = SBP_enm.c2_fluctuations() fh = open("%s/enm_11.test.dat" % outdir,'w') stri = "# %19s %s \n" % ("Residues","Fluctuations") for i in range(len(fluc)): stri += "%10s/%-10s %.6e \n" % (res[i],res[i+1],fluc[i]) fh.write(stri) fh.close() comp("%s/enm_09.test.dat" % refdir) comp("%s/enm_10.test.dat" % refdir) comp("%s/enm_11.test.dat" % refdir)
def test_enm_0(): """Tests command line interface""" cl.main(['ENM','--pdb',fname,'-o',"%s/enm_00.test" % outdir,'--ntop','4','--shape']) comp("%s/enm_00.test.ENM.eigvecs.out" % refdir) comp("%s/enm_00.test.ENM.eigvals.out" % refdir) comp("%s/enm_00.test.ENM.shape.out" % refdir)
def test_annotate_2(): fname = "%s/test/data/1S72.pdb" % cwd stackings, pairings, res = bb.annotate(fname) dotbr, ss = bb.dot_bracket(pairings, res) fh = open("%s/stackings_02.test.dat" % outdir, 'w') stri = "# STACKING \n" for e in range(len(stackings[0][0])): stri += "%15s " % (res[stackings[0][0][e][0]]) stri += "%15s " % (res[stackings[0][0][e][1]]) stri += " %4s \n" % (stackings[0][1][e]) fh.write(stri) fh.close() fh = open("%s/pairings_02.test.dat" % outdir, 'w') stri = "# PAIRING \n" for e in range(len(pairings[0][0])): stri += "%15s " % (res[pairings[0][0][e][0]]) stri += "%15s " % (res[pairings[0][0][e][1]]) stri += " %4s \n" % (pairings[0][1][e]) fh.write(stri) fh.close() fh = open("%s/dotbracket_02.test.dat" % outdir, 'w') fh.write(str(dotbr[0])) fh.close() comp("%s/stackings_02.test.dat" % refdir) comp("%s/pairings_02.test.dat" % refdir) comp("%s/dotbracket_02.test.dat" % refdir)
def test_cluster(): # first, calculate all g-vectors print("# Calculating G-vectors") gvec, seq = bb.dump_gvec(traj, top) lent = gvec.shape[0] gvec = gvec.reshape(lent, -1)[::5] print("# Calculating PCA. gvec shape: ", gvec.shape) # calculate PCA v, w = cc.pca(gvec, nevecs=3) print( "# Cumulative explained variance of component: 1=%5.1f 2:=%5.1f 3=%5.1f" % (v[0] * 100, v[1] * 100, v[2] * 100)) print("# DBSCAN clustering...") # do DBSCAN clustering. eps and min_samples need to be adjusted. new_labels, center_idx = cc.dbscan(gvec, range(gvec.shape[0]), eps=0.6 / np.sqrt(8.), min_samples=10) print("DONE!") # create color palette. gray, small points for unassigned clusters. #cp = sns.color_palette("hls",len(center_idx)+1) #colors = [cp[j-1] if(j!=0) else (0.77,0.77,0.77) for j in new_labels] size = [5 if (j != 0) else 0.25 for j in new_labels] # do scatterplot #plt.scatter(w[:,0],w[:,1],s=size,c=colors) # now dump centroids and print labels on plot print("# Dump PDB centroids") t = md.load(traj, top=top) idxs = [ii for ii, kk in enumerate(new_labels) if (kk == 0)] for i, k in enumerate(center_idx): t[k].save_pdb("%s/cluster_%03d.test.pdb" % (outdir, i)) comp("%s/cluster_%03d.test.pdb" % (refdir, i)) #plt.text(w[k,0],w[k,1],str(i),ha='center',va='center') idxs = [ii for ii, kk in enumerate(new_labels) if (kk == i + 1)]
def test_enm_0(): """Tests command line interface""" cl.main([ 'ENM', '--pdb', fname, '-o', "%s/enm_00.test" % outdir, '--ntop', '4', '--shape' ]) comp("%s/enm_00.test.ENM.eigvecs.out" % refdir) comp("%s/enm_00.test.ENM.eigvals.out" % refdir) comp("%s/enm_00.test.ENM.shape.out" % refdir)
def test_annotate_1(): stackings, pairings, res = bb.annotate(fname1,topology=fname) dotbr,ss = bb.dot_bracket(pairings,res) fh = open("%s/stackings_01.test.dat" % outdir,'w') stri = "# STACKING \n" for k in range(len(stackings)): stri += "# frame %d \n" % k for e in range(len(stackings[k][0])): stri += "%15s " % (res[stackings[k][0][e][0]]) stri += "%15s " % (res[stackings[k][0][e][1]]) stri += " %4s \n" % (stackings[k][1][e]) stri += "\n" fh.write(stri) fh.close() fh = open("%s/pairings_01.test.dat" % outdir,'w') stri = "# PAIRING \n" for k in range(len(pairings)): stri += "# frame %d \n" % k for e in range(len(pairings[k][0])): stri += "%15s " % (res[pairings[k][0][e][0]]) stri += "%15s " % (res[pairings[k][0][e][1]]) stri += " %4s \n" % (pairings[k][1][e]) fh.write(stri) fh.close() fh = open("%s/dotbracket_01.test.dat" % outdir,'w') stri = "" for k in range(len(pairings)): stri += " %06d " % k stri += "%s \n" % dotbr[k] fh.write(stri) fh.close() comp("%s/stackings_01.test.dat" % refdir) comp("%s/pairings_01.test.dat" % refdir) comp("%s/dotbracket_01.test.dat" % refdir)
def test_annotate_1(): stackings, pairings, res = bb.annotate(fname1, topology=fname) dotbr, ss = bb.dot_bracket(pairings, res) fh = open("%s/stackings_01.test.dat" % outdir, 'w') stri = "# STACKING \n" for k in range(len(stackings)): stri += "# frame %d \n" % k for e in range(len(stackings[k][0])): stri += "%15s " % (res[stackings[k][0][e][0]]) stri += "%15s " % (res[stackings[k][0][e][1]]) stri += " %4s \n" % (stackings[k][1][e]) stri += "\n" fh.write(stri) fh.close() fh = open("%s/pairings_01.test.dat" % outdir, 'w') stri = "# PAIRING \n" for k in range(len(pairings)): stri += "# frame %d \n" % k for e in range(len(pairings[k][0])): stri += "%15s " % (res[pairings[k][0][e][0]]) stri += "%15s " % (res[pairings[k][0][e][1]]) stri += " %4s \n" % (pairings[k][1][e]) fh.write(stri) fh.close() fh = open("%s/dotbracket_01.test.dat" % outdir, 'w') stri = "" for k in range(len(pairings)): stri += " %06d " % k stri += "%s \n" % dotbr[k] fh.write(stri) fh.close() comp("%s/stackings_01.test.dat" % refdir) comp("%s/pairings_01.test.dat" % refdir) comp("%s/dotbracket_01.test.dat" % refdir)
def test_snippet(): bb.snippet(fname,"AAANU",outdir="%s" % outdir) for f in glob.glob("%s/1S72*.pdb" %outdir): comp(f)
def test_snippet(): bb.snippet(fname, "AAANU", outdir="%s" % outdir) for f in glob.glob("%s/1S72*.pdb" % outdir): comp(f)