Skip to content

Commit

Permalink
More pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
charnley committed Jan 2, 2025
1 parent c5297f8 commit f37d166
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 18 deletions.
44 changes: 35 additions & 9 deletions notebooks/explain_reorder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -217,22 +217,21 @@
" \n",
" fig, ax = plot_funcs.get_plot()\n",
" plot_funcs.set_axis_default(ax)\n",
" plot_funcs.plot_molecule(ax, atoms, coord)\n",
" plot_funcs.plot_molecule(ax, [\"\"]*3, coord)\n",
" plot_funcs.plot_representation(ax, atoms, coord)\n",
"\n",
" filename = \"fig_reorder_problem\"\n",
" fig.savefig(filename, bbox_inches=\"tight\")\n",
"\n",
"qml_illustration()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "37612822-a13a-4c97-a512-40073a161690",
"cell_type": "markdown",
"id": "faa92f45-9f5f-4f4e-9021-dd3e1c9d271a",
"metadata": {},
"outputs": [],
"source": [
"\n",
"import matplotlib\n",
"matplotlib.pyplot.close()"
"# Reorder problem"
]
},
{
Expand All @@ -241,7 +240,34 @@
"id": "9d6ce450-e2f3-42ca-9904-bcfe6873d92d",
"metadata": {},
"outputs": [],
"source": []
"source": [
"def reorder():\n",
"\n",
" coord1 = [\n",
" [0,0,0],\n",
" [1,1,0],\n",
" [2,0,0],\n",
" ]\n",
" coord1 = np.array(coord1, dtype=float) / 1.2\n",
" coord1 -= rmsdlib.centroid(coord1)\n",
" coord2 = np.array(coord1, copy=True)\n",
" atoms1 = [6, 6, 6]\n",
"\n",
" coord2 /= 1.5\n",
" coord2 -= rmsdlib.centroid(coord1)\n",
" coord2[:,1] -= 0.5\n",
" coord1[:,1] += 0.2\n",
" \n",
" fig, ax = plot_funcs.get_plot()\n",
" plot_funcs.set_axis_default(ax)\n",
" 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",
"\n",
"reorder()"
]
},
{
"cell_type": "code",
Expand Down
Binary file added notebooks/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 notebooks/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.
Binary file modified notebooks/fig_rmsd_nothing.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 modified notebooks/fig_rmsd_recentered.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 modified notebooks/fig_rmsd_rotated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 28 additions & 9 deletions notebooks/plot_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

import rmsd as rmsdlib

outline = patheffects.withStroke(linewidth=6, foreground="w")
outline = patheffects.withStroke(linewidth=5, foreground="w")

FIGURE_SIZE = 4
MARKER_SIZE = 400
REP_SIZE = 0.1
REP_HEIGHT = 0.15


def plot_molecule(ax, atoms, coords, hatch="/////"):
Expand All @@ -19,7 +24,7 @@ def plot_molecule(ax, atoms, coords, hatch="/////"):
ax.scatter(
X,
Y,
s=500.0,
s=MARKER_SIZE,
hatch=hatch,
facecolor="#fff",
edgecolor="#000",
Expand Down Expand Up @@ -71,7 +76,7 @@ def plot_representation(ax, atoms, coord):
x, y = ax.transLimits.transform(c)

ins3 = ax.inset_axes(
[x, y, 0.02, 0.1],
[x, y, REP_SIZE, REP_HEIGHT],
)
ins3.imshow(np.expand_dims(vecs[idx], axis=1), cmap="gray")
ins3.xaxis.set_ticks([])
Expand Down Expand Up @@ -100,15 +105,31 @@ def plot_representation(ax, atoms, coord):
# ax.add_artist(arrow)


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

ax.set_box_aspect(1)
ax.set_xlim(-lim, lim)
ax.set_ylim(-lim, lim)
ax.grid(True)
ax.grid(use_grid)

ax.tick_params(width=0, length=0)
ax.tick_params(axis="both", which="major", labelsize=0)

for tick in ax.xaxis.get_major_ticks():

tick.tick1line.set_visible(False)
tick.tick2line.set_visible(False)

tick.label1.set_visible(False)
tick.label2.set_visible(False)

for tick in ax.yaxis.get_major_ticks():

tick.tick1line.set_visible(False)
tick.tick2line.set_visible(False)

tick.label1.set_visible(False)
tick.label2.set_visible(False)


def set_global_style():
font = {"weight": "bold", "size": 18, "family": "serif"}
Expand All @@ -122,7 +143,7 @@ def set_global_style():
# matplotlib.rcParams["ytick.major.width"] = 2


def get_plot(n_ax=1, size=5):
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))

Expand Down Expand Up @@ -157,8 +178,6 @@ def fix_borders(ax, visibles=[False, False, True, True], fix_bounds=True):
min_y = np.min(yticks)
max_y = np.max(yticks)

# TODO Better ax.set_xlim()

for direction, visible in zip(directions, visibles):

spine = spines[direction]
Expand Down

0 comments on commit f37d166

Please sign in to comment.