diff --git a/docs/figures/fig_reorder_inertia.png b/docs/figures/fig_reorder_inertia.png new file mode 100644 index 0000000..7ad7ae9 Binary files /dev/null and b/docs/figures/fig_reorder_inertia.png differ diff --git a/docs/figures/fig_reorder_problem.png b/docs/figures/fig_reorder_problem.png new file mode 100644 index 0000000..ab1bfe6 Binary files /dev/null and b/docs/figures/fig_reorder_problem.png differ diff --git a/docs/figures/fig_reorder_qml.png b/docs/figures/fig_reorder_qml.png new file mode 100644 index 0000000..f94bce7 Binary files /dev/null and b/docs/figures/fig_reorder_qml.png differ diff --git a/notebooks/fig_rmsd_nothing.png b/docs/figures/fig_rmsd_nothing.png similarity index 100% rename from notebooks/fig_rmsd_nothing.png rename to docs/figures/fig_rmsd_nothing.png diff --git a/notebooks/fig_rmsd_recentered.png b/docs/figures/fig_rmsd_recentered.png similarity index 100% rename from notebooks/fig_rmsd_recentered.png rename to docs/figures/fig_rmsd_recentered.png diff --git a/notebooks/fig_rmsd_rotated.png b/docs/figures/fig_rmsd_rotated.png similarity index 100% rename from notebooks/fig_rmsd_rotated.png rename to docs/figures/fig_rmsd_rotated.png diff --git a/notebooks/fig_reorder_inertia.png b/notebooks/fig_reorder_inertia.png deleted file mode 100644 index 5732bd9..0000000 Binary files a/notebooks/fig_reorder_inertia.png and /dev/null differ diff --git a/notebooks/fig_reorder_problem.png b/notebooks/fig_reorder_problem.png deleted file mode 100644 index 400318d..0000000 Binary files a/notebooks/fig_reorder_problem.png and /dev/null differ diff --git a/notebooks/fig_reorder_qml.png b/notebooks/fig_reorder_qml.png deleted file mode 100644 index ff9c001..0000000 Binary files a/notebooks/fig_reorder_qml.png and /dev/null differ diff --git a/notebooks/explain_reorder.ipynb b/notebooks/figures.ipynb similarity index 86% rename from notebooks/explain_reorder.ipynb rename to notebooks/figures.ipynb index 5d0273f..f28fb6f 100644 --- a/notebooks/explain_reorder.ipynb +++ b/notebooks/figures.ipynb @@ -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", @@ -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", @@ -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", @@ -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()" ] @@ -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()" ] @@ -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()" ] @@ -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": [] diff --git a/notebooks/plot_funcs.py b/notebooks/plot_funcs.py index 08a0dc4..19b3411 100644 --- a/notebooks/plot_funcs.py +++ b/notebooks/plot_funcs.py @@ -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), @@ -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 @@ -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", @@ -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) @@ -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