<jupyter_start><jupyter_text>Simple plotting from data filesThe following examples show how to read in data from files and plot it with error bars<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

# The data is created from a clearly unconverged thermodynamical integration for solvating methane in water
# with Gromacs (one exercise on Tuesday). The original version 
# made by <NAME> is available in here: http://www.mdtutorials.com/gmx/free_energy/index.html

data = np.loadtxt("bar.xvg", comments=["@","#"])
print(len(data))
# split the matrix into components with meaningful names
# note, lam below is an integer indicating Nth simulation (corresponding to values between with N-1,N,N+1)
lam=data[:,0]
dlam=data[:,1]
err=data[:,2]
dlam
fig = plt.figure()
plt.plot(lam,dlam)
plt.errorbar(lam,dlam,yerr=err,fmt='-',ecolor='purple',capsize=4)
cumdl=np.cumsum(dlam)
cumerr=np.cumsum(err)
cumerr[-1]
# let's see how the error builds up if we sum it - not mathematically correct
fig = plt.figure()
plt.plot(lam,cumdl,label='cumulative dG/dl')
plt.errorbar(lam,cumdl+cumerr/2,label='cum +error')
plt.errorbar(lam,cumdl-cumerr/2,label='cum -error')
plt.ylabel(r'dG/dl in kT')
plt.xlabel(r'N Lambda')
plt.legend()
# to read in data where there is text in some columns you can specify which ones to use
dg=np.loadtxt('final.txt', usecols=(1,3,5,7))
#dgl=(dg[:,0]+dg[:,2])/2
dgkcalmol=dg[:,2]
errkcalmol=dg[:,3]
dgcumsum=np.cumsum(dgkcalmol)
lambdas=np.loadtxt('lambdas.txt')
# lambda values give the states between which the dG/dl is computed, thus there's one more lambda value, than dG/dl
# we'll go around this to use the end lambda as coordinate in the plot
# lambda separation does not need to be uniform. Based on the profile, would it be more efficient to sample
# some parts with smaller separation?
lambdas=lambdas[1:]
fig = plt.figure()
plt.plot(lambdas,dgkcalmol,label='dG/dl')
plt.errorbar(lambdas,dgkcalmol,yerr=errkcalmol,fmt='',label='error',ecolor='k',capsize=4)
#plt.errorbar(lambdas,cumdl-cumerr,label='cum -error')
plt.ylabel(r'dG/dl in kcal/mol')
plt.xlabel(r'Lambda')
plt.legend()
# print the last element in the cumulative sum which is the integral
dgcumsum[-1]
# look for more features and try them on the plots
#help(plt.errorbar)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12990409764603314, 'fraction_numerical': 0.009154315605928508, 'mean_word_length': 6.127329192546584, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '235477', 'license': 'MIT', 'n_tokens_mistral': 870, 'n_tokens_neox': 810, 'n_words': 244, 'path': 'bar/bar.ipynb', 'repo_name': 'attesillanpaa/sscc-visualization', 'size': '2301'}