Skip to content

Commit

Permalink
Fixes for plots, handling some failed calculations.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtarzia committed Oct 16, 2024
1 parent db56830 commit e8066a2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 35 deletions.
57 changes: 36 additions & 21 deletions first_paper_example/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
)


def failed_cage(
name: str,
database: cgexplore.utilities.AtomliteDatabase,
) -> None:
"""Save failed cage."""
res_dict = {"optimised": False}
database.add_properties(key=name, property_dict=res_dict)


def optimise_cage(
molecule: stk.Molecule,
name: str,
Expand Down Expand Up @@ -307,28 +316,34 @@ def build_populations(
),
)

conformer = optimise_cage(
molecule=cage,
name=name,
output_dir=calculation_output,
forcefield=forcefield,
platform=platform,
database=database,
)
if conformer is not None:
conformer.molecule.write(
str(struct_output / f"{name}_optc.mol")
try:
conformer = optimise_cage(
molecule=cage,
name=name,
output_dir=calculation_output,
forcefield=forcefield,
platform=platform,
database=database,
)
count += 1
if conformer is not None:
conformer.molecule.write(
str(struct_output / f"{name}_optc.mol")
)
count += 1

analyse_cage(
conformer=conformer,
name=name,
output_dir=calculation_output,
forcefield=forcefield,
node_element=node_element,
ligand_element=ligand_element,
database=database,
)
analyse_cage(
conformer=conformer,
name=name,
output_dir=calculation_output,
forcefield=forcefield,
node_element=node_element,
ligand_element=ligand_element,
database=database,
)
except openmm.OpenMMException:
failed_cage(
name=name,
database=database,
)

logging.info("%s %s cages built.", count, population)
13 changes: 8 additions & 5 deletions first_paper_example/plot_cages.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,22 +742,22 @@ def si_shape_fig(
plt.close()


def add_energy_to_ax(ax: mpl.Axes, energy: float) -> None:
def add_energy_to_ax(ax: mpl.axes, energy: float) -> None:
"""Add energy to ax."""
colorcode = "#345995" if energy <= isomer_energy() else "#CA1551"

ax.set_title(round(energy, 1), fontsize=16, color=colorcode)


def add_text_to_ax(ax: mpl.Axes, text: str) -> None:
def add_text_to_ax(ax: mpl.axes, text: str) -> None:
"""Add text to ax."""
x = 0.05
y = 0.25
ax.text(x=x, y=y, s=text, fontsize=16, transform=ax.transAxes)


def add_structure_to_ax(
ax: mpl.Axes,
ax: mpl.axes,
struct_name: str,
struct_output: pathlib.Path,
struct_figure_output: pathlib.Path,
Expand Down Expand Up @@ -994,8 +994,11 @@ def check_odd_outcomes(
cdata = ton_data[ton_data["cage_name"] == cage_name]
pair_name = get_paired_cage_name(cage_name)
pdata = tdata[tdata["cage_name"] == pair_name]
ton_energy = float(cdata["energy_per_bb"].iloc[0])
toff_energy = float(pdata["energy_per_bb"].iloc[0])
try:
ton_energy = float(cdata["energy_per_bb"].iloc[0])
toff_energy = float(pdata["energy_per_bb"].iloc[0])
except IndexError:
continue

# Ignore rounding errors in near zero cases.
if ton_energy < 1e-1: # noqa: PLR2004
Expand Down
12 changes: 7 additions & 5 deletions first_paper_example/plot_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,11 +835,13 @@ def plot_topology_pore_flex(data, figure_output: pathlib.Path) -> None:
cdata = ton_data[ton_data["cage_name"] == cage_name]
pair_name = get_paired_cage_name(cage_name)
pdata = tdata[tdata["cage_name"] == pair_name]

ton_energy = float(cdata["energy_per_bb"].iloc[0])
toff_energy = float(pdata["energy_per_bb"].iloc[0])
ton_pore = float(cdata["pore"].iloc[0])
toff_pore = float(pdata["pore"].iloc[0])
try:
ton_energy = float(cdata["energy_per_bb"].iloc[0])
toff_energy = float(pdata["energy_per_bb"].iloc[0])
ton_pore = float(cdata["pore"].iloc[0])
toff_pore = float(pdata["pore"].iloc[0])
except IndexError:
continue
rel_difference = (ton_pore - toff_pore) / toff_pore

differences.append(rel_difference)
Expand Down
4 changes: 2 additions & 2 deletions first_paper_example/plot_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ def pd_3p64p8_figure_bite_angle(
"""Make a plot."""
logging.info("running pd_3p64p8_figure_bite_angle")

color_map = ("3P6", "4P8")
color_map = {"3P6": "tab:orange", "4P8": "tab:green"}

fig, ax = plt.subplots(figsize=(8, 2.5))
trim = all_data[all_data["vdws"] == "von"]
Expand All @@ -832,13 +832,13 @@ def pd_3p64p8_figure_bite_angle(
ey = float(tdata["energy_per_bb"].iloc[0])
tstr_points[tstr].append((ba, ey))

next(ax._get_lines.prop_cycler)["color"] # noqa: SLF001
for tstr in color_map:
ax.plot(
[i[0] for i in tstr_points[tstr]],
[i[1] for i in tstr_points[tstr]],
alpha=1.0,
# edgecolor="k",
markerfacecolor=color_map[tstr],
lw=3,
marker="o",
markeredgecolor="k",
Expand Down
7 changes: 5 additions & 2 deletions first_paper_example/plot_parities.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ def parity_1(all_data: pd.DataFrame, figure_output: pathlib.Path) -> None:
cage_name = str(row["cage_name"])
pair_name = get_paired_cage_name(cage_name)
d2_row = tdata[tdata["cage_name"] == pair_name]
d2_energy = float(d2_row["energy_per_bb"].iloc[0])
try:
d2_energy = float(d2_row["energy_per_bb"].iloc[0])

diffdata.append(d1_energy - d2_energy)
diffdata.append(d1_energy - d2_energy)
except IndexError:
pass

xpos = tcpos[tstr]

Expand Down

0 comments on commit e8066a2

Please sign in to comment.