Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pV and U to reduced potential when they are given #62

Merged
merged 11 commits into from
Nov 26, 2018
31 changes: 21 additions & 10 deletions src/alchemlyb/parsing/gmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def extract_u_nk(xvg, T):

"""

col_match = r"\xD\f{}H \xl\f{}"
h_col_match = r"\xD\f{}H \xl\f{}"
pv_col_match = 'pV'
u_col_match = 'Total Energy'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the files you provided @harlor (https://userpage.fu-berlin.de/dominikwille/nvt300K.tgz), I see "Potential Energy (kJ/mol)" in the ti_0.xvg file. Should we also try and match that?

Copy link
Contributor Author

@harlor harlor Nov 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrshirts explained that in #59 (comment). So I think we need the total energy.

I uploaded a dataset with total energy here: http://dominikwille.userpage.fu-berlin.de/nvt300K_u.tgz

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but I think depending on MDP options given to gromacs it's possible to have a dataset without "Total Energy" but with "Potential Energy". I was thinking that we could handle this in another PR with kwargs, but I don't believe this should be neglected.

Could you add a check for the existence of a "Potential Energy" column as you did for the "Total Energy" column, and if present, use this instead of the "Total Energy" column? That would satisfy me for the purposes of this PR

beta = 1/(k_b * T)

state, lambdas, statevec = _extract_state(xvg)
Expand All @@ -43,22 +45,31 @@ def extract_u_nk(xvg, T):
times = df[df.columns[0]]

# want to grab only dH columns
DHcols = [col for col in df.columns if (col_match in col)]
DHcols = [col for col in df.columns if (h_col_match in col)]
dH = df[DHcols]

# not entirely sure if we need to get potentials relative to
# the state actually sampled, but perhaps needed to stack
# samples from all states?
U = df[df.columns[1]]

# gromacs also gives us pV directly; need this for reduced potential
pV = df[df.columns[-1]]
pv_cols = [col for col in df.columns if (pv_col_match in col)]
pv = None
if pv_cols:
pv = df[pv_cols[0]]

# gromacs also gives us total energy U directly; need this for reduced potential
u_cols = [col for col in df.columns if (u_col_match in col)]
u = None
if u_cols:
u = df[u_cols[0]]

u_k = dict()
cols= list()
cols = list()
for col in dH:
u_col = eval(col.split('to')[1])
u_k[u_col] = beta * (dH[col].values + U.values + pV.values)
# calculate reduced potential u_k = dH + pV + U
u_k[u_col] = beta * dH[col].values
if pv_cols:
u_k[u_col] += beta * pv.values
if u_cols:
u_k[u_col] += beta * u.values
cols.append(u_col)

u_k = pd.DataFrame(u_k, columns=cols,
Expand Down
2 changes: 1 addition & 1 deletion src/alchemlyb/tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def slicer(self, *args, **kwargs):
(True, gmx_benzene_dHdl(), 2001), # 0.00: g = 1.0559445620585415
(True, gmx_benzene_u_nk(), 2001), # 'fep': g = 1.0560203916559594
(False, gmx_benzene_dHdl(), 3789),
(False, gmx_benzene_u_nk(), 3789),
(False, gmx_benzene_u_nk(), 3571),
dotsdl marked this conversation as resolved.
Show resolved Hide resolved
])
def test_conservative(self, data, size, conservative):
sliced = self.slicer(data, series=data.iloc[:, 0], conservative=conservative)
Expand Down