Skip to content

Commit 14b7242

Browse files
Merge pull request #82 from wiederm/analysis_warning
Create warning for overlap
2 parents 2ba2435 + c921c67 commit 14b7242

File tree

3 files changed

+50
-30
lines changed

3 files changed

+50
-30
lines changed

transformato/analysis.py

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -736,35 +736,28 @@ def vacuum_free_energy_difference_overlap(self):
736736

737737
def plot_free_energy_overlap(self, env: str):
738738
plt.figure(figsize=[8, 8], dpi=300)
739-
if env == "vacuum":
740-
ax = sns.heatmap(
741-
self.vacuum_free_energy_difference_overlap,
742-
cmap="Blues",
743-
linewidth=0.5,
744-
annot=True,
745-
fmt="0.2f",
746-
annot_kws={"size": "small"},
747-
)
748-
elif env == "waterbox":
749-
ax = sns.heatmap(
750-
self.waterbox_free_energy_difference_overlap,
751-
cmap="Blues",
752-
linewidth=0.5,
753-
annot=True,
754-
fmt="0.2f",
755-
annot_kws={"size": "small"},
756-
)
757-
elif env == "complex":
758-
ax = sns.heatmap(
759-
self.complex_free_energy_difference_overlap,
760-
cmap="Blues",
761-
linewidth=0.5,
762-
annot=True,
763-
fmt="0.2f",
764-
annot_kws={"size": "small"},
765-
)
766-
else:
767-
raise RuntimeError()
739+
740+
overlap_matrix = self.free_energy_overlap(env)
741+
ax = sns.heatmap(
742+
overlap_matrix,
743+
cmap="Reds",
744+
cbar = False,
745+
linewidth=0.5,
746+
annot=True,
747+
fmt="0.2f",
748+
annot_kws={"size": "small"},
749+
)
750+
751+
ax = sns.heatmap(
752+
overlap_matrix,
753+
mask = overlap_matrix < 0.009,
754+
cmap="Blues",
755+
linewidth=0.5,
756+
annot=True,
757+
fmt="0.2f",
758+
annot_kws={"size": "small"},
759+
)
760+
768761
plt.title(f"Overlap of lambda states for ligand in {env}", fontsize=15)
769762
plt.xlabel("lambda state (0 to 1)", fontsize=15)
770763
plt.ylabel("lambda state (0 to 1)", fontsize=15)
@@ -864,15 +857,36 @@ def show_summary(self):
864857
self.plot_waterbox_free_energy_overlap()
865858
self.plot_vacuum_free_energy()
866859
self.plot_waterbox_free_energy()
860+
self.detailed_overlap("waterbox")
861+
self.detailed_overlap("vacuum")
867862
else:
868863
if isnotebook:
869864
# only show this if we are in a notebook
870865
self.plot_complex_free_energy_overlap()
871866
self.plot_waterbox_free_energy_overlap()
872867
self.plot_complex_free_energy()
873868
self.plot_waterbox_free_energy()
869+
self.detailed_overlap("complex")
870+
self.detailed_overlap("waterbox")
874871

875872
energy_estimate, uncertainty = self.end_state_free_energy_difference
876873
print(
877874
f"Free energy to common core: {energy_estimate} [kT] with uncertainty: {uncertainty} [kT]."
878875
)
876+
877+
878+
def detailed_overlap(self, env):
879+
880+
mbar_matrix = self.free_energy_overlap(env=env)
881+
upper = np.diagonal(mbar_matrix, offset = 1)
882+
lower = np.diagonal(mbar_matrix, offset = -1)
883+
av_upper = sum(upper/(len(mbar_matrix)-1))
884+
av_lower = sum(lower/(len(mbar_matrix)-1))
885+
886+
print(f"The average overlap in {env} between the states is {round(av_upper,3)} and {round(av_lower,3)}")
887+
888+
all = np.concatenate((upper,lower))
889+
for state, i in enumerate(all):
890+
if i < 0.01:
891+
print(f" WARNINING: In state {state}, the overlap is {round(i,3)}")
892+

transformato/bin/slurm-preamble.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#!/bin/bash
22
#SBATCH -p lgpu
33
#SBATCH --gres=gpu
4+
5+
source ~/miniconda3/etc/profile.d/conda.sh
6+
conda activate fep
7+

transformato/tests/test_run_production.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from transformato.utils import run_simulation
1313
from transformato.constants import change_platform_to_test_platform
1414

15+
from transformato_testsystems.testsystems import get_testsystems_dir
16+
1517

1618
@pytest.mark.rsfe
1719
@pytest.mark.skipif(
@@ -37,7 +39,7 @@ def test_run_1a0q_1a07_rsfe_with_openMM(caplog):
3739
workdir = get_test_output_dir()
3840
conf = f"{get_testsystems_dir()}/config/test-1a0q-1a07-rsfe.yaml"
3941
configuration = load_config_yaml(
40-
config=conf, input_dir="data/test_systems_mutation", output_dir=workdir
42+
config=conf, input_dir=get_testsystems_dir(), output_dir=workdir
4143
)
4244
s1 = SystemStructure(configuration, "structure1")
4345
s2 = SystemStructure(configuration, "structure2")

0 commit comments

Comments
 (0)