How the Rh visit map is made: 8 steps

Where does the Rh atom spend its time on the α-Al₂O₃ surface? This page shows how 240,000 MD frames become one contour map.

All 8 steps at a glance

All 8 steps

1Collect the Rh positions

Step 1
traj = Trajectory(path)
irh = traj[0].get_chemical_symbols().index("Rh")
frames = [int(i) for i in indices.read_text().split()] if indices else range(0, len(traj), stride)
rh += [traj[i].positions[irh] for i in frames]

plot_rh_on_slab_map.py, lines 57–60

2Change to cell fractions

Step 2
frac = np.linalg.solve(cell.T, load_rh_positions(args.traj, stride=args.stride).T).T[:, :2] % 1.0

plot_rh_visit_maps.py, line 185

3Count the frames in each bin

Step 3
hist, _, _ = np.histogram2d(frac[:, 0], frac[:, 1], bins=N_BINS, range=[[0, 1], [0, 1]])

plot_rh_visit_maps.py, line 186

4Blur the counts and turn them into shares

Step 4
p = gaussian_filter(d["hist"], 1.0, mode="wrap")
p /= p.sum()

plot_rh_visit_maps.py, lines 75–76

5Sort the bins and find the three cut values

Step 5
order = np.sort(p.ravel())[::-1]
cum = np.cumsum(order)

def threshold(q):
    return order[np.searchsorted(cum, q / 100)]

thresholds = [threshold(q) for q in levels]

plot_rh_visit_maps.py, lines 77–83

6Colour each bin by its band

Step 6

7Draw smooth contour lines at the cut values

Step 7
periodic_contour(ax, d["cell"], p, True, levels=thresholds + [p.max()], colors=colors, alpha=0.85)
periodic_contour(ax, d["cell"], p, False, levels=thresholds, colors="k", linewidths=0.6)

plot_rh_visit_maps.py, lines 85–86

8Put the square back on the slanted cell, repeated 3 × 3

Step 8
def periodic_contour(ax, cell, values, filled, **kw):
    """contour(f) of a fractional-grid array at bin centres, on one 3x3 periodic tiling of the cell."""
    centres = (np.arange(3 * N_BINS) + 0.5) / N_BINS - 1
    u, v = np.meshgrid(centres, centres, indexing="ij")
    x = u * cell[0, 0] + v * cell[1, 0]
    y = u * cell[0, 1] + v * cell[1, 1]
    draw = ax.contourf if filled else ax.contour
    return draw(x, y, np.tile(values, (3, 3)), zorder=2 if filled else 3, **kw)

plot_rh_visit_maps.py, lines 45–52

One sentence to remember: the 50 % region is the set of busiest bins that hold half of the time, so it can be in several places.

How this page is written: ASD-STE100

The request

“can you visualise each step by step in a easier way along with the code responsible for that? use ASD-STE100. I have ADHD.”

What ASD-STE100 is

How it is used here

The rules, with examples

RuleWritten like thisNot like this
One action per sentenceSort the bins. Add up the time.Sort the bins and then add up the time, which gives the running total that we use for the cuts.
Short sentences (≤ 20 words for steps)It counts the dots in each bin.The histogram routine is then applied over the fractional coordinates to obtain per-bin occupation counts.
Active voiceThe code divides the square into 60 × 60 bins.The square is divided into 60 × 60 bins.
Verb, not nounThe first line blurs the counts.Gaussian smoothing is performed on the counts.
No phrasal verbsThe code adds the cell outline.The code throws in the cell outline.
No semicolonsThe cell is slanted. A square is easier to divide into bins.The cell is slanted; a square is easier to bin.
Lists for 3 or more itemsDark / medium / light / white as a list (Step 6).All four colour rules in one long sentence.
One name for one thingAlways “bin”.“bin”, then “cell”, then “pixel” for the same square.
Keep hedges as they are“about 1 bin”, “zero or few frames”.Turning “about” or “few” into an exact claim the code does not make.

The “not like this” column shows typical alternatives, written for comparison.