def test_mbar_single_sample(): dataset = pd.read_csv(data[0], sep=" ") sample = mics.sample(dataset, "beta*E1", "beta*(E2 - E1)", beta=beta) mixture = mics.mixture([sample], mics.MBAR()) assert mixture.Overlap[0][0] == pytest.approx(1.0)
files = [f'{solute}-in-{solvent}_energy-{i:02d}.csv' for i in states.index] renamer = lambda x: x.replace('Energy[', 'E').replace('] (kJ/mole)', '') kT = (kB * T).value_in_unit(unit.kilojoules_per_mole) mx.verbose = True samples = mx.pooledsample() for i, file in zip(states.index, files): print(f"Reading file {file}") df = pd.read_csv(file) df.drop(index=range(15000), inplace=True) df.rename(renamer, axis='columns', inplace=True) prev = max(i - 1, 0) next = min(i + 1, nstates - 1) samples += mx.sample(df, f'beta*(E{i}-E0)', acfun=f'E{next}-E{prev}', beta=1 / kT, lambda_vdw=states.lambda_vdw[i], lambda_coul=states.lambda_coul[i]) samples.histograms().plot(x='potential') plt.show() mixture = mx.mixture(samples, engine=mx.MICS(tol=1.0E-11)) # mixture = mx.mixture(samples.subsampling(), engine=mx.MBAR()) f = mixture.free_energies() kT = (kB * T).value_in_unit(unit.kilocalories_per_mole) #f['lambda[vdw+coul]'] = f['lambda_vdw'] + f['lambda_coul'] f['delta_g'] = kT * f['f'] f['error(delta_g)'] = kT * f['df'] print(f) f.plot(x='lambda_vdw', y='delta_g', yerr='error(delta_g)') mixture.histograms('potential', bins=200).plot(x='potential')
def test_main(): assert mics # use your library here mics.verbose = True m = 4 beta = 1.6773985789 data = ["tests/data/log_%d.dat" % (i + 1) for i in range(m)] samples = mics.pooledsample() for i in range(m): dataset = pd.read_csv(data[i], sep=" ") potential = "beta*E%d" % (i + 1) autocorr = "beta*(E%d - E%d)" % (min(i + 2, m), max(i, 1)) samples += mics.sample(dataset, potential, autocorr, beta=beta) def test_read_samples(): for sample in samples: assert sample.dataset.columns[5] == 'Press' def test_pooledsample(): neff = [ 100.829779921697, 76.82824014457174, 69.63811023389404, 55.179192164637165 ] for i in range(m): assert samples[i].neff == pytest.approx(neff[i])