|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import matplotlib.pyplot as plt |
| 6 | +from torch import scatter |
| 7 | +from ppafm.ocl.oclUtils import init_env |
| 8 | + |
| 9 | +from plot_predictions import get_data as get_data_prediction, MM_TO_INCH |
| 10 | +from plot_predictions import plot_graph as plot_graph_prediction |
| 11 | +from plot_relaxed_structures import get_data as get_data_relaxed |
| 12 | +from plot_relaxed_structures import plot_graph as plot_graph_relaxed |
| 13 | + |
| 14 | +# # Set matplotlib font rendering to use LaTex |
| 15 | +# plt.rcParams.update({"text.usetex": True, "font.family": "serif", "font.serif": ["Computer Modern Roman"]}) |
| 16 | + |
| 17 | + |
| 18 | +def init_fig(width=140, left_margin=4, top_margin=4, row_gap=6, gap=0.5): |
| 19 | + ax_size = (width - left_margin - 5 * gap) / 5 |
| 20 | + |
| 21 | + left_margin *= MM_TO_INCH |
| 22 | + top_margin *= MM_TO_INCH |
| 23 | + row_gap *= MM_TO_INCH |
| 24 | + gap *= MM_TO_INCH |
| 25 | + ax_size *= MM_TO_INCH |
| 26 | + width *= MM_TO_INCH |
| 27 | + height = top_margin + 2 * (ax_size + gap) + row_gap |
| 28 | + fig = plt.figure(figsize=(width, height)) |
| 29 | + |
| 30 | + axes = [] |
| 31 | + |
| 32 | + y = height - top_margin - ax_size |
| 33 | + x = left_margin |
| 34 | + axes_ = [] |
| 35 | + for _ in range(5): |
| 36 | + rect = [x / width, y / height, ax_size / width, ax_size / height] |
| 37 | + ax = fig.add_axes(rect) |
| 38 | + ax.set_xticks([]) |
| 39 | + ax.set_yticks([]) |
| 40 | + for axis in ["top", "bottom", "left", "right"]: |
| 41 | + ax.spines[axis].set_linewidth(0.5) |
| 42 | + axes_.append(ax) |
| 43 | + x += ax_size + gap |
| 44 | + axes.append(axes_) |
| 45 | + |
| 46 | + y = height - top_margin - 2 * ax_size - row_gap |
| 47 | + x = left_margin + 2 * (ax_size + gap) |
| 48 | + axes_ = [] |
| 49 | + for _ in range(3): |
| 50 | + rect = [x / width, y / height, ax_size / width, ax_size / height] |
| 51 | + ax = fig.add_axes(rect) |
| 52 | + ax.set_xticks([]) |
| 53 | + ax.set_yticks([]) |
| 54 | + for axis in ["top", "bottom", "left", "right"]: |
| 55 | + ax.spines[axis].set_linewidth(0.5) |
| 56 | + axes_.append(ax) |
| 57 | + x += ax_size + gap |
| 58 | + axes.append(axes_) |
| 59 | + |
| 60 | + return fig, axes |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + init_env(i_platform=0) |
| 65 | + |
| 66 | + exp_data_dir = Path("./exp_data") |
| 67 | + sim_data_dir = Path("./relaxed_structures/") |
| 68 | + scatter_size = 5 |
| 69 | + zmin = -5.0 |
| 70 | + zmax = 0.5 |
| 71 | + classes = [[1], [8], [29, 79]] |
| 72 | + class_colors = ["w", "r"] |
| 73 | + fontsize = 7 |
| 74 | + |
| 75 | + params = { |
| 76 | + "pred_dir": "predictions_au111-bilayer", |
| 77 | + "sim_name": "hartree_I", |
| 78 | + "exp_name": "Ying_Jiang_4", |
| 79 | + "label": "I", |
| 80 | + "dist": 4.8, |
| 81 | + "rot_angle": -25.000, |
| 82 | + "amp": 2.0, |
| 83 | + "nz": 7, |
| 84 | + "offset": (0.0, 0.0), |
| 85 | + } |
| 86 | + |
| 87 | + exp_data, pred_mol, sim_pred = get_data_prediction(params, exp_data_dir, classes) |
| 88 | + opt_mol, sim_opt, _, sw_opt = get_data_relaxed(params, exp_data_dir, sim_data_dir, classes) |
| 89 | + |
| 90 | + fig, axes = init_fig() |
| 91 | + |
| 92 | + # Plot data |
| 93 | + axes[0][0].imshow(exp_data['data'][:, :, 0].T, origin="lower", cmap="gray") |
| 94 | + axes[0][1].imshow(exp_data['data'][:, :, -1].T, origin="lower", cmap="gray") |
| 95 | + plot_graph_prediction( |
| 96 | + axes[0][2], |
| 97 | + pred_mol, |
| 98 | + box_borders=[[0, 0, zmin], [exp_data["lengthX"], exp_data["lengthY"], zmax]], |
| 99 | + zmin=zmin, |
| 100 | + zmax=zmax, |
| 101 | + scatter_size=scatter_size, |
| 102 | + class_colors=class_colors, |
| 103 | + ) |
| 104 | + axes[0][3].imshow(sim_pred[:, :, 0].T, origin="lower", cmap="gray") |
| 105 | + axes[0][4].imshow(sim_pred[:, :, -1].T, origin="lower", cmap="gray") |
| 106 | + plot_graph_relaxed( |
| 107 | + axes[1][0], |
| 108 | + opt_mol, |
| 109 | + box_borders=[[sw_opt[0][0], sw_opt[0][1], zmin], [sw_opt[1][0], sw_opt[1][1], zmax]], |
| 110 | + zmin=zmin, |
| 111 | + zmax=zmax, |
| 112 | + scatter_size=scatter_size, |
| 113 | + class_colors=class_colors, |
| 114 | + ) |
| 115 | + axes[1][1].imshow(sim_opt[:, :, 0].T, origin="lower", cmap="gray") |
| 116 | + axes[1][2].imshow(sim_opt[:, :, -1].T, origin="lower", cmap="gray") |
| 117 | + |
| 118 | + # Set labels |
| 119 | + y = 1.08 |
| 120 | + axes[0][0].text( |
| 121 | + -0.08, 0.5, params["label"], transform=axes[0][0].transAxes, fontsize=fontsize, va="center", ha="center", rotation="vertical" |
| 122 | + ) |
| 123 | + axes[0][0].text(0.5, y, "Exp.\ AFM (far)", transform=axes[0][0].transAxes, fontsize=fontsize, va="center", ha="center") |
| 124 | + axes[0][1].text(0.5, y, "Exp.\ AFM (close)", transform=axes[0][1].transAxes, fontsize=fontsize, va="center", ha="center") |
| 125 | + axes[0][2].text(0.5, y, "Pred.\ geom.", transform=axes[0][2].transAxes, fontsize=fontsize, va="center", ha="center") |
| 126 | + axes[0][3].text(0.5, y, "Sim.\ AFM (far)", transform=axes[0][3].transAxes, fontsize=fontsize, va="center", ha="center") |
| 127 | + axes[0][4].text(0.5, y, "Sim.\ AFM (close)", transform=axes[0][4].transAxes, fontsize=fontsize, va="center", ha="center") |
| 128 | + axes[1][0].text(0.5, y, "Opt.\ geom.", transform=axes[1][0].transAxes, fontsize=fontsize, va="center", ha="center") |
| 129 | + axes[1][1].text(0.5, y, "Sim.\ AFM (far)", transform=axes[1][1].transAxes, fontsize=fontsize, va="center", ha="center") |
| 130 | + axes[1][2].text(0.5, y, "Sim.\ AFM (close)", transform=axes[1][2].transAxes, fontsize=fontsize, va="center", ha="center") |
| 131 | + |
| 132 | + plt.savefig(f"sims_extra.png", dpi=400) |
0 commit comments