Brine freezing front¶
The frames are the 20-pair loading of
d-SEAMS/brine-front-230K
at revision 4828e33ecf419c70643b2d466bfa4f283b4138dc. The tutorial
fetches T230_m20_r0_t0.xyz and T230_m20_r0_tend.xyz, checks
their SHA-256, and caches them under docs/.cache. A later run uses
the cache. If the fetch fails and the cache is empty, the tutorial
prints
brine tutorial skipped: cannot fetch d-SEAMS/brine-front-230K at 4828e33ecf419c70643b2d466bfa4f283b4138dc
and returns success. It does not treat a missing download as a passed measurement.
Each file stores a CHILL+ name on every oxygen. The engine is run again on the oxygen coordinates. All 1496 oxygens match the stored names at both times. Ice is hexagonal or cubic. Sodium is the ion, water is type 1, the axis is z, and the bin count is 20. The rejection coefficient is the bulk-ice molality divided by the bulk-liquid molality.
brine t0 hexagonal 733 water 619 interfacial 91 cubic 1 agree 1496
brine t0 thickness 25.5618 k 0.0
brine tend hexagonal 741 water 621 interfacial 89 cubic 0 agree 1496
brine tend thickness 25.3740 k 0.0
box, rows = read_xyz(path)
type_of = {"O": 1, "H": 2, "Na": 3, "Cl": 4}
xyz = []
types = []
for species, x, y, z, _chill in rows:
xyz.extend((x, y, z))
types.append(type_of[species])
count = len(rows)
points = (ctypes.c_double * len(xyz))(*xyz)
box9 = (ctypes.c_double * 9)(box[0], box[1], box[2], box[3], box[4], box[5], 0, 0, 0)
kinds = (ctypes.c_int * count)(*types)
system = lib.seams_system_create()
if lib.seams_system_set_frame(system, points, count, box9, kinds, None) != 0:
raise SystemExit(lib.seams_last_error())
labels = (ctypes.c_int * count)()
counts = (ctypes.c_int * 9)()
if lib.seams_chill_plus(system, 3.5, 1, 0, 0, labels, counts) != 0:
raise SystemExit(lib.seams_last_error())
oxygen = [i for i, row in enumerate(rows) if row[0] == "O"]
agree = sum(labels[i] == NAMES.index(rows[i][4]) for i in oxygen)
histogram = {name: 0 for name in NAMES}
for index in oxygen:
histogram[NAMES[labels[index]]] += 1
ice = (ctypes.c_int * count)(
*[1 if rows[i][0] == "O" and labels[i] in (0, 1) else 0 for i in range(count)]
)
front = ctypes.c_void_p()
# water type 1, sodium type 3, 20 bins, axis z.
if lib.seams_brine_analyse(system, ice, count, 1, 3, 20, 2, ctypes.byref(front)) != 0:
raise SystemExit(lib.seams_last_error())
enter = ctypes.c_double()
leave = ctypes.c_double()
thick = ctypes.c_double()
found = ctypes.c_int()
if lib.seams_brine_fronts(
front, ctypes.byref(enter), ctypes.byref(leave), ctypes.byref(thick), ctypes.byref(found)
) != 0:
raise SystemExit("fronts")
c_ice = ctypes.c_double()
c_liquid = ctypes.c_double()
coeff = ctypes.c_double()
defined = ctypes.c_int()
if lib.seams_brine_rejection(
front, ctypes.byref(c_ice), ctypes.byref(c_liquid), ctypes.byref(coeff), ctypes.byref(defined)
) != 0:
raise SystemExit("rejection")
lib.seams_brine_destroy(front)
lib.seams_system_destroy(system)
return {
"agree": agree,
"oxygen": len(oxygen),
"histogram": histogram,
"found": int(found.value),
"thickness": float(thick.value),
"c_ice": float(c_ice.value),
"k": float(coeff.value),
"defined": int(defined.value),
}
double *xyz = NULL;
int *types = NULL;
int n = 0;
double box9[9];
char(*chill)[16] = NULL;
/* 4608 is the largest frame in this tutorial. Grow if the header says more. */
FILE *probe = fopen(path, "r");
char first[64];
if (probe == NULL || fgets(first, sizeof first, probe) == NULL) {
die(path);
}
fclose(probe);
int declared = atoi(first);
chill = calloc((size_t)declared, 16);
if (read_xyz(path, &xyz, &types, chill, &n, box9) != 0) {
die(path);
}
seams_system *sys = seams_system_create();
if (seams_system_set_frame(sys, xyz, n, box9, types, NULL) != SEAMS_OK) {
die("set_frame");
}
int *labels = calloc((size_t)n, sizeof(int));
int counts[9] = {0};
if (seams_chill_plus(sys, 3.5, 1, 0, 0, labels, counts) != SEAMS_OK) {
die("chill+");
}
int agree = 0;
int oxygen = 0;
int histogram[9] = {0};
for (int i = 0; i < n; i++) {
if (types[i] != 1) {
continue;
}
oxygen += 1;
histogram[labels[i]] += 1;
if (strcmp(chill[i], LABELS[labels[i]]) == 0) {
agree += 1;
}
}
int *ice = calloc((size_t)n, sizeof(int));
for (int i = 0; i < n; i++) {
ice[i] = types[i] == 1 && (labels[i] == 0 || labels[i] == 1);
}
seams_brine *front = NULL;
if (seams_brine_analyse(sys, ice, (size_t)n, 1, 3, 20, 2, &front) != SEAMS_OK) {
die("brine");
}
double thickness = 0;
int found = 0;
double c_ice = 0;
double coeff = 0;
int defined = 0;
if (seams_brine_fronts(front, NULL, NULL, &thickness, &found) != SEAMS_OK) {
die("fronts");
}
if (seams_brine_rejection(front, &c_ice, NULL, &coeff, &defined) != SEAMS_OK) {
die("rejection");
}
printf("brine %s hexagonal %d water %d interfacial %d cubic %d agree %d\n", tag,
histogram[1], histogram[2], histogram[3], histogram[0], agree);
printf("brine %s thickness %.4f k %.1f found %d defined %d\n", tag, thickness, coeff, found,
defined);
seams_brine_destroy(front);
seams_system_destroy(sys);
free(xyz);
free(types);
free(labels);
free(ice);
free(chill);
(void)oxygen;
}
The 5 ns frame. Hydrogens are omitted. The cell origin is the lowest hexagonal oxygen, and the coordinates are then wrapped, so the slab is one piece and the periodic image of the brine is not left under the ice. The frame keeps one sphere radius outside the outline, including above the top edge. Liquid oxygens are small and faint. Sodium and chloride use the oxygen scale: Na is 1.0 Å and Cl is 1.8 Å where oxygen is 1.4 Å, drawn at 0.90 for the ice oxygen. The legend writes Na⁺ and Cl⁻ on two balanced rows. Brackets with end ticks mark the brine and the ice Ih slab, with a gap at the front. A dashed line across the cell is the growth front. The axis reads depth from lower ice surface (nm). The 1 nm bar sits below the legend. CHILL+ on the whole cell is 741 hexagonal, 621 liquid, 89 interfacial, 41 interfacial clathrate, 4 clathrate and no cubic. The picture keeps those non-hexagonal colors only within 1.5 nm of the growth front: 42 interfacial, 37 interfacial clathrate and all 4 clathrate. Farther from the front they are drawn as liquid. Sodium and chloride are not recolored. The engine and the frame column agree. Sodium is violet and interfacial clathrate is pink. Those two are 31 CIEDE2000 apart. Chloride is black. feat/brine-science at 80201fa2 imports scripts/chill_palette.py. The paper’s render_front.py in the private d-SEAMS 2.0 paper repository does too.¶
Paper Fig 18 and SI Figs 25-26 call the same renderer:
python docs/examples/render_brine.py --xyz T230_m20_r0_tend.xyz --out brine.png --width-mm 85
--width-mm is the atom panel at 300 ppi. --out is the png, which
also includes the depth axis and the legend. The legend is at least 7 pt
when that png is printed at the width passed to --width-mm.
What this tells you¶
Over 5 ns at 230 K the hexagonal count moves from 733 to 741 and the ice run stays near 25.5 angstrom. The bulk ice holds no sodium, so the rejection coefficient is 0: the salt stays in the liquid. The stored labels and a fresh CHILL+ call name every oxygen the same way, which is the check that the front is the paper’s front and not a second classifier.