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(): 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 main(): args = parse() bmea = bme.Reweight(verbose=(not args.quiet)) assert len(args.exp_files) == len(args.calc_files) for j in range(len(args.exp_files)): bmea.load(args.exp_files[j], args.calc_files[j]) bmea.optimize(theta=args.theta)
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 #")
import sys bme_path = os.getcwd()[:-8] # here append the path to the bme script sys.path.append(bme_path) import bme_reweight as bme # define name of experimental datafiles exp_couplings = '../data/couplings_exp.dat' exp_noe='../data/NOE_exp.dat' # define name of experimental quantities # calculated from the trajectory calc_couplings = '../data/couplings_calc.dat' calc_noe='../data/NOE_calc.dat' # initialize reweighting class rew = bme.Reweight() # load data rew.load(exp_couplings,calc_couplings) # do optimization using theta=2 chib,chia, srel = rew.optimize(theta=2) # compare NOE before and after optimization . # output is written to files with prefix 'example1_noe' chi2_b,chi2_a = rew.weight_exp(exp_noe,calc_noe, 'example1_noe') # print chisquared print srel print chib, chia print chi2_a, chi2_b
beta = model.intercept_ #Offset ab.append(np.array([c, alpha, beta])) #Applying scale factor and offset obtained in this cycle to the Pepsi-SAXS ensemble and write to file to feed BME calc = alpha * calc + beta new_calc = open(dir_ + '/tmp_t' + str(t), 'w') new_calc.write('#\n') for i in range(0, np.shape(calc)[0]): new_calc.write('frame' + str(i) + ' ' + ' '.join(str(n) for n in calc[i]) + '\n') new_calc.close() #Running BME with the scaled/shifted ensemble if len(sys.argv) == 6: rew = bme.Reweight(w0=w_in) rew.load(exp_file, dir_ + '/tmp_t' + str(t)) chi2_before, chi2_after, srel = rew.optimize(theta=t) data.append(np.array([c, t, chi2_before, chi2_after, np.exp(srel)])) print(data[-1]) weights.append(rew.get_weights()) else: rew = bme.Reweight() rew.load(exp_file, dir_ + '/tmp_t' + str(t)) chi2_before, chi2_after, srel = rew.optimize(theta=t) data.append(np.array([c, t, chi2_before, chi2_after, np.exp(srel)])) print(data[-1]) weights.append(rew.get_weights()) #Weighted average of the Pepsi-SAXS profiles with BME weights Iav = np.average(calc, axis=0, weights=weights[-1])