Skip to content

Commit

Permalink
Figures
Browse files Browse the repository at this point in the history
  • Loading branch information
charnley committed Jan 4, 2025
1 parent ad83eb1 commit 3ff568e
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 91 deletions.
Binary file added docs/figures/fig_reorder_inertia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/fig_reorder_problem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/fig_reorder_qml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file removed notebooks/fig_reorder_inertia.png
Binary file not shown.
Binary file removed notebooks/fig_reorder_problem.png
Binary file not shown.
Binary file removed notebooks/fig_reorder_qml.png
Binary file not shown.
82 changes: 32 additions & 50 deletions notebooks/explain_reorder.ipynb → notebooks/figures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,28 @@
"plot_funcs.set_global_style()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9da6930d-7d90-457a-b69e-783ae35fa3ec",
"metadata": {},
"outputs": [],
"source": [
"folder = Path(\"../docs/figures\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "244df06a-3276-4b72-9ae8-337481ffadb8",
"metadata": {},
"outputs": [],
"source": [
"def save_figure(fig, name):\n",
" filename = folder / name\n",
" fig.savefig(filename, bbox_inches=\"tight\")"
]
},
{
"cell_type": "markdown",
"id": "3cf67d24-ad0a-4130-a3cd-d3f8d79e59cd",
Expand Down Expand Up @@ -150,8 +172,7 @@
"\n",
" print(rmsdlib.rmsd(coord1, coord2))\n",
"\n",
" filename = \"fig_rmsd_nothing\"\n",
" fig.savefig(filename, bbox_inches=\"tight\")\n",
" save_figure(fig, \"fig_rmsd_nothing\")\n",
"\n",
" ##\n",
" \n",
Expand All @@ -166,8 +187,7 @@
"\n",
" print(rmsdlib.rmsd(coord1, coord2))\n",
" \n",
" filename = \"fig_rmsd_recentered\"\n",
" fig.savefig(filename, bbox_inches=\"tight\")\n",
" save_figure(fig, \"fig_rmsd_recentered\")\n",
"\n",
" ##\n",
"\n",
Expand All @@ -182,8 +202,7 @@
"\n",
" print(rmsdlib.rmsd(coord1, coord2))\n",
" \n",
" filename = \"fig_rmsd_rotated\"\n",
" fig.savefig(filename, bbox_inches=\"tight\")\n",
" save_figure(fig, \"fig_rmsd_rotated\")\n",
"\n",
"rmsd1()"
]
Expand Down Expand Up @@ -220,8 +239,7 @@
" plot_funcs.plot_molecule(ax, [\"\"]*3, coord)\n",
" plot_funcs.plot_representation(ax, atoms, coord)\n",
"\n",
" filename = \"fig_reorder_qml\"\n",
" fig.savefig(filename, bbox_inches=\"tight\")\n",
" save_figure(fig, \"fig_reorder_qml\")\n",
"\n",
"qml_illustration()"
]
Expand Down Expand Up @@ -263,8 +281,7 @@
" plot_funcs.plot_molecule(ax, [\"1\", \"2\", \"3\"], coord1)\n",
" plot_funcs.plot_molecule(ax, [\"2\", \"3\", \"1\"], coord2, hatch=\"\\\\\\\\\\\\\")\n",
"\n",
" filename = \"fig_reorder_problem\"\n",
" fig.savefig(filename, bbox_inches=\"tight\")\n",
" save_figure(fig, \"fig_reorder_problem\")\n",
"\n",
"reorder()"
]
Expand Down Expand Up @@ -304,56 +321,21 @@
" plot_funcs.plot_molecule(ax, [\"\"]*3, coord2, hatch=\"\\\\\\\\\\\\\")\n",
"\n",
" pos = np.array([-1.2, 1.0])\n",
" plot_funcs.plot_inertia(ax, pos, atoms1, coord1)\n",
" plot_funcs.plot_inertia(ax, pos, atoms1, coord2)\n",
" plot_funcs.plot_inertia(ax, pos, atoms1, coord1, zorder=300)\n",
" plot_funcs.plot_inertia(ax, pos, atoms1, coord2, zorder=300)\n",
"\n",
" filename = \"fig_reorder_inertia\"\n",
" fig.savefig(filename, bbox_inches=\"tight\")\n",
"\n",
"show_inertia()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f4383e95-c349-44c2-a710-e236646173e3",
"metadata": {},
"outputs": [],
"source": [
"[[ 0.70710678 0.70710678 0. ]\n",
" [ 0.70710678 -0.70710678 0. ]\n",
" [ 0. 0. 1. ]]\n",
"[0 1]\n",
"[0.70710678 1.70710678]\n",
"[0.70710678 0.29289322]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "56beaea8-a833-4ce7-84e1-fbbfc9bfeff0",
"metadata": {},
"outputs": [],
"source": [
"1-1.70710678"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4e01ea91-f201-4c0c-9997-9497668a4e15",
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plot_funcs.get_plot()\n",
" save_figure(fig, \"fig_reorder_inertia\")\n",
"\n",
"ax.plot([0,1,2], [0,0,2], '-')\n"
"show_inertia()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab8c52f9-51bd-4f78-9564-187756cca3d5",
"id": "e19b1501-cf18-4e48-a18c-109ae9bd8e55",
"metadata": {},
"outputs": [],
"source": []
Expand Down
60 changes: 19 additions & 41 deletions notebooks/plot_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ def plot_molecule(ax, atoms, coords, hatch="/////", zorder=0):
return


def plot_representation(ax, atoms, coord):
def plot_representation(ax, atoms, coord, zorder=100):

# qml vectors
parameters = {
"elements": np.unique(atoms),
"pad": len(atoms),
Expand All @@ -75,17 +74,29 @@ def plot_representation(ax, atoms, coord):
c += offset
x, y = ax.transLimits.transform(c)

ins3 = ax.inset_axes(
axins = ax.inset_axes(
[x, y, REP_SIZE, REP_HEIGHT],
zorder=zorder + 1,
)

axins.imshow(np.expand_dims(vecs[idx], axis=1), cmap="gray")
axins.xaxis.set_ticks([])
axins.yaxis.set_ticks([])

# Add white stroke to insert axis
coords = ax.transAxes.inverted().transform(axins.get_tightbbox())
border = 0.009
w, h = coords[1] - coords[0] + 2 * border
ax.add_patch(
plt.Rectangle(
coords[0] - border, w, h, fc="white", transform=ax.transAxes, zorder=zorder
)
)
ins3.imshow(np.expand_dims(vecs[idx], axis=1), cmap="gray")
ins3.xaxis.set_ticks([])
ins3.yaxis.set_ticks([])

return


def plot_inertia(ax, pos, atoms, coord):
def plot_inertia(ax, pos, atoms, coord, zorder=100):

center = rmsdlib.get_cm(atoms, coord)
coord = coord - center
Expand All @@ -97,16 +108,10 @@ def plot_inertia(ax, pos, atoms, coord):

eigvec = eigvec.T
eigvec = eigvec[np.argsort(eigval)]
# eigvec = eigvec.T

eigvec *= -1

print(pos)
print(eigvec)

arrow_options = dict(
zorder=10,
# path_effects=[outline],
zorder=zorder,
head_width=0.1,
head_length=0.1,
fc="k",
Expand Down Expand Up @@ -148,26 +153,6 @@ def plot_inertia(ax, pos, atoms, coord):
)


# def do_dot(ax, coord1, coord2, size=24, **kwargs):
# ax.plot([coord1], [coord2], "o", markersize=size, linewidth=3, color="k", **kwargs)
# return


# def do_arrow(ax, pos_start, pos_end, rad=0.0, color="k"):
# edge_width = 2.0
# arrowstyle = "fancy,head_length={},head_width={},tail_width={}".format(
# 2 * edge_width, 3 * edge_width, edge_width
# )
# arrow = FancyArrowPatch(
# posA=pos_start,
# posB=pos_end,
# arrowstyle=arrowstyle,
# connectionstyle=f"arc3,rad=-{rad:f}",
# color=color,
# )
# ax.add_artist(arrow)


def set_axis_default(ax, lim=2.0, use_grid=True):

ax.set_box_aspect(1)
Expand Down Expand Up @@ -199,17 +184,10 @@ def set_global_style():
matplotlib.rc("font", **font)
matplotlib.rc("axes", labelweight="bold")

# Thicker spines
# matplotlib.rcParams["axes.linewidth"] = 1

# matplotlib.rcParams["xtick.major.width"] = 2
# matplotlib.rcParams["ytick.major.width"] = 2


def get_plot(n_ax=1, size=FIGURE_SIZE):
"""Get a jupyter-sized plot"""
fig, axs = plt.subplots(1, n_ax, sharey=True, sharex=True, figsize=(size * n_ax, size))

fig.tight_layout()
fig.subplots_adjust(hspace=0, wspace=0)
return fig, axs

0 comments on commit 3ff568e

Please sign in to comment.