-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcombine_orientations_mbar.py
152 lines (126 loc) · 4.69 KB
/
combine_orientations_mbar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import pandas as pd
import numpy as np
import json
import os
import base64
from constants import experimental_deltaG
from constants import experimental_deltaH
from constants import systems
from constants import guest_types
from bootstrap import dG_bootstrap
from bootstrap import dH_bootstrap
def json_numpy_obj_hook(dct):
"""Decodes a previously encoded numpy ndarray with proper shape and dtype.
:param dct: (dict) json encoded ndarray
:return: (ndarray) if input was an encoded ndarray
"""
if isinstance(dct, dict) and "__ndarray__" in dct:
data = base64.b64decode(dct["__ndarray__"])
return np.frombuffer(data, dct["dtype"]).reshape(dct["shape"])
# return dct['__ndarray__']
return dct
experimental_deltaG_list = experimental_deltaG.split("\n")
experimental_deltaH_list = experimental_deltaH.split("\n")
experimental = pd.DataFrame(
[
i.split("\t") + j.split("\t")[1:]
for i, j in zip(experimental_deltaG_list, experimental_deltaH_list)
],
columns=["System", "Delta G", "G_SEM", "Delta H", "H_SEM"],
)
def combine_data(df):
"""
Combine data for individual orientations into a single thermodynamic value.
"""
combined = pd.DataFrame()
df["Short"] = [i[0:-2] for i in df["System"].values]
for hg in df["Short"].unique():
tmp = df[df["Short"] == hg]
for _, row in tmp.iterrows():
if "p" in row["System"].split("-")[2]:
# Reducing generality for speed.
primary_fe = row[f"Delta G"]
primary_fe_sem = row[f"G_SEM"]
primary_enthalpy = row[f"Delta H"]
primary_enthalpy_sem = row[f"H_SEM"]
else:
secondary_fe = row[f"Delta G"]
secondary_fe_sem = row[f"G_SEM"]
secondary_enthalpy = row[f"Delta H"]
secondary_enthalpy_sem = row[f"H_SEM"]
combined_fe = dG_bootstrap(
primary_fe,
primary_fe_sem,
secondary_fe,
secondary_fe_sem,
cycles=100000,
)
combined_enthalpy = dH_bootstrap(
primary_enthalpy,
primary_enthalpy_sem,
secondary_enthalpy,
secondary_enthalpy_sem,
primary_fe,
primary_fe_sem,
secondary_fe,
secondary_fe_sem,
cycles=100000,
)
combined = combined.append(
{
"System": hg,
"Delta G": combined_fe["mean"],
"G_SEM": combined_fe["sem"],
"G_CI": combined_fe["ci"],
"Delta H": combined_enthalpy["mean"],
"H_SEM": combined_enthalpy["sem"],
"H_CI": combined_enthalpy["ci"],
"Type": guest_types[hg],
},
ignore_index=True,
)
return combined
# SMIRNOFF99Frosst
smirnoff = pd.DataFrame()
for system in systems:
print(system)
with open(f"results/{system}-mbar-results.json", "r") as f:
json_data = f.read()
results = json.loads(json_data, object_hook=json_numpy_obj_hook)
with open(f"results/{system[0]}-release.json", "r") as f:
json_data = f.read()
results_release = json.loads(json_data, object_hook=json_numpy_obj_hook)
smirnoff_attach = results["attach"]["mbar-block"]["fe"]
smirnoff_pull = results["pull"]["mbar-block"]["fe"]
smirnoff_release = results_release["release"]["ti-block"]["fe"]
smirnoff_attach_sem = results["attach"]["mbar-block"]["sem"]
smirnoff_pull_sem = results["pull"]["mbar-block"]["sem"]
smirnoff_release_sem = results_release["release"]["ti-block"]["sem"]
smirnoff_analytic = 7.14
delta_g = -1 * (
smirnoff_attach + smirnoff_pull - smirnoff_release - smirnoff_analytic
)
delta_g_sem = np.sqrt(
smirnoff_attach_sem ** 2 + smirnoff_pull_sem ** 2 + smirnoff_release_sem ** 2
)
with open(f"results/{system}-smirnoff-enthalpy-full.json", "r") as f:
json_data = f.read()
loaded = json.loads(json_data)
delta_h = loaded["a000"]["total"][0] - loaded["r014"]["total"][0]
delta_h_sem = np.sqrt(
loaded["a000"]["total"][1] ** 2 + loaded["r014"]["total"][1] ** 2
)
smirnoff = smirnoff.append(
{
"System": system,
"Delta G": delta_g,
"G_SEM": delta_g_sem,
"Delta H": delta_h,
"H_SEM": delta_h_sem,
"Type": guest_types[system[0:-2]],
},
ignore_index=True,
)
smirnoff.to_csv("results/smirnoff_mbar_by_orientation.csv")
smirnoff_combined = combine_data(smirnoff)
smirnoff_combined.to_csv("results/smirnoff_mbar_combined.csv")