Skip to content

Commit d22e74c

Browse files
dgfl-ghjanosh
andauthored
Improve ferroelectric-response.typ (#43)
* refine ferroelectric-response.typ * also apply radial gradient to atoms in basis-plus-lattice.typ and materials-informatics.typ for 3D shading effect * add high-entropy-alloy.typ converted from Latex --------- Co-authored-by: Janosh Riebesell <[email protected]>
1 parent 3177dd9 commit d22e74c

File tree

4 files changed

+253
-99
lines changed

4 files changed

+253
-99
lines changed

assets/basis-plus-lattice/basis-plus-lattice.typ

+21-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,27 @@
44
#set page(width: auto, height: auto, margin: 8pt)
55

66
#let atom(pos, color) = {
7-
circle(pos, radius: 0.25, fill: color.lighten(20%), stroke: 0.3pt)
7+
// First draw the base circle with the main color
8+
circle(
9+
pos,
10+
radius: 0.25,
11+
stroke: none,
12+
fill: color,
13+
)
14+
// Then draw the gradient overlay for 3D shading effect
15+
circle(
16+
(),
17+
radius: 0.25,
18+
stroke: none,
19+
fill: gradient.radial(
20+
color.lighten(75%),
21+
color,
22+
color.darken(15%),
23+
focal-center: (30%, 25%),
24+
focal-radius: 5%,
25+
center: (35%, 30%),
26+
),
27+
)
828
}
929

1030
#canvas({
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#import "@preview/cetz:0.3.4": canvas, draw
2-
#import draw: rect, line, circle, content, hobby, scale
2+
#import draw: rect, line, circle, content, hobby, scale, set-origin
33

44
#set page(width: auto, height: auto, margin: 8pt)
55

66
#canvas({
77
let arrow-style = (mark: (end: "stealth", fill: black, scale: .75))
88
let plot-height = 4
99
let plot-width = 10
10-
let y-offset = 4.65 // Reduced from 6 to bring plots closer together
10+
let y-offset = 4.5
1111

1212
// Helper to draw axes
1313
let draw-axes(origin, width, height) = {
1414
line(
15-
(origin.at(0) - 0.5, origin.at(1)),
15+
(origin.at(0) - 0.3, origin.at(1)),
1616
(origin.at(0) + width, origin.at(1)),
1717
..arrow-style,
1818
name: "x-axis",
1919
)
2020
line(
21-
(origin.at(0), origin.at(1) - 0.5),
21+
(origin.at(0), origin.at(1) - 0.3),
2222
(origin.at(0), origin.at(1) + height),
2323
..arrow-style,
2424
name: "y-axis",
@@ -31,15 +31,16 @@
3131

3232
// Draw double-well potential curve using hobby spline
3333
hobby(
34-
(top-origin.at(0) + .5, top-origin.at(1) + 3.5), // start high
34+
(top-origin.at(0) + .5, top-origin.at(1) + 4), // start high
3535
(top-origin.at(0) + 1.7, top-origin.at(1) + 0.4), // left minimum
3636
(top-origin.at(0) + 1.8, top-origin.at(1) + 0.3), // left minimum
3737
(top-origin.at(0) + 5, top-origin.at(1) + 1.5), // up to middle peak
3838
(top-origin.at(0) + 8.2, top-origin.at(1) + 0.3), // right minimum
3939
(top-origin.at(0) + 8.3, top-origin.at(1) + 0.4), // right minimum
40-
(top-origin.at(0) + 9.5, top-origin.at(1) + 3.5), // up high again
40+
(top-origin.at(0) + 9.5, top-origin.at(1) + 4), // up high again
4141
omega: 0,
4242
name: "potential-curve",
43+
stroke: 1.5pt,
4344
)
4445

4546
// Add "Free Energy" label
@@ -107,129 +108,135 @@
107108
)
108109

109110
// Helper function to draw BaTiO3 unit cell
110-
// TODO the face-centered oxygen atom positions need fixing and the lines overlap the atoms
111+
let atom(pos, radius: 0.20, fill: luma(50), ..args) = {
112+
circle(
113+
pos,
114+
radius: radius,
115+
stroke: none,
116+
fill: fill,
117+
..args
118+
)
119+
circle(
120+
(),
121+
radius: radius,
122+
stroke: none,
123+
fill: gradient.radial(
124+
fill.lighten(75%), fill, fill.darken(15%),
125+
focal-center: (30%, 25%),
126+
focal-radius: 5%,
127+
center: (35%, 30%),
128+
),
129+
)
130+
}
111131
let draw-unit-cell(center-x, center-y, ti-y, cell-name) = {
112132
let (x, y) = (center-x, center-y)
113-
let z-offset = 0.3 // Consistent offset for back face
133+
let z-offset = -1.0 // Consistent offset for back face
114134
let cube-style = (stroke: 0.7pt)
115135

136+
116137
// Draw unit cell cube with consistent offsets
117138
rect(
118-
(x - 1, y - 1),
119-
(x + 1, y + 1),
139+
(x - 1, y - 1, 0),
140+
(x + 1, y + 1, 0),
120141
..cube-style,
121142
name: cell-name + "-front",
122143
) // Front face
123144
line(
124-
(x - 1, y - 1),
125-
(x - 1 + z-offset, y - 1 + z-offset),
145+
(x - 1, y - 1, 0),
146+
(x - 1, y - 1, z-offset),
126147
..cube-style,
127148
name: cell-name + "-left",
128149
) // Left edge
129150
line(
130-
(x + 1, y - 1),
131-
(x + 1 + z-offset, y - 1 + z-offset),
151+
(x + 1, y - 1, 0),
152+
(x + 1, y - 1, z-offset),
132153
..cube-style,
133154
name: cell-name + "-right",
134155
) // Right edge
135156
line(
136-
(x - 1 + z-offset, y - 1 + z-offset),
137-
(x + 1 + z-offset, y - 1 + z-offset),
157+
(x - 1, y - 1, z-offset),
158+
(x + 1, y - 1, z-offset),
138159
..cube-style,
139160
name: cell-name + "-back",
140161
) // Back edge
141162
line(
142-
(x - 1 + z-offset, y + 1 + z-offset),
143-
(x + 1 + z-offset, y + 1 + z-offset),
163+
(x - 1, y + 1, z-offset),
164+
(x + 1, y + 1, z-offset),
144165
..cube-style,
145166
name: cell-name + "-top-back",
146167
) // Top back edge
147168
line(
148-
(x - 1 + z-offset, y - 1 + z-offset),
149-
(x - 1 + z-offset, y + 1 + z-offset),
169+
(x - 1, y - 1, z-offset),
170+
(x - 1, y + 1, z-offset),
150171
..cube-style,
151172
name: cell-name + "-left-back",
152173
) // Left back edge
153174
line(
154-
(x + 1 + z-offset, y - 1 + z-offset),
155-
(x + 1 + z-offset, y + 1 + z-offset),
175+
(x + 1, y - 1, z-offset),
176+
(x + 1, y + 1, z-offset),
156177
..cube-style,
157178
name: cell-name + "-right-back",
158179
) // Right back edge
159-
160-
// Draw Ba atoms (all 8 corners)
161-
let ba-style = (stroke: none, fill: rgb("#00ffff"))
162-
for (pos, suffix) in (
163-
// Front face corners
164-
((x - 1, y - 1), "front-bl"),
165-
((x + 1, y - 1), "front-br"),
166-
((x - 1, y + 1), "front-tl"),
167-
((x + 1, y + 1), "front-tr"),
168-
// Back face corners
169-
((x - 1 + z-offset, y - 1 + z-offset), "back-bl"),
170-
((x + 1 + z-offset, y - 1 + z-offset), "back-br"),
171-
((x - 1 + z-offset, y + 1 + z-offset), "back-tl"),
172-
((x + 1 + z-offset, y + 1 + z-offset), "back-tr"),
173-
) {
174-
circle(
175-
pos,
176-
radius: 0.15,
177-
..ba-style,
178-
name: cell-name + "-ba-" + suffix,
179-
)
180-
}
181-
182-
// Draw O atoms (all 6 face centers)
183-
let o-style = (stroke: none, fill: red)
184-
for (pos, suffix) in (
185-
// Front and back face centers
186-
((x, y), "front"), // Front face center
187-
((x + z-offset, y + z-offset), "back"), // Back face center
188-
// Face centers with consistent offsets
189-
((x, y + 1), "top"), // Top face center
190-
((x, y - 1), "bottom"), // Bottom face center
191-
((x - 1, y), "left"), // Left face center
192-
((x + 1, y), "right"), // Right face center
193-
) {
194-
circle(
195-
pos,
196-
radius: 0.12,
197-
..o-style,
198-
name: cell-name + "-o-" + suffix,
199-
)
200-
}
201-
202-
// Draw Ti atom (center, displaced)
203-
let ti-style = (stroke: none, fill: gray)
204-
circle(
205-
(x + z-offset / 2, y + ti-y),
206-
radius: 0.1,
207-
..ti-style,
208-
name: cell-name + "-ti",
180+
line(
181+
(x + 1, y - -1),
182+
(x + 1, y - -1, z-offset),
183+
..cube-style,
184+
name: cell-name + "top-right",
185+
) // top right edge
186+
line(
187+
(x + -1, y - -1),
188+
(x + -1, y - -1, z-offset),
189+
..cube-style,
190+
name: cell-name + "top-left",
191+
) // top right edge
192+
193+
// Define helper functions for each atom style
194+
let Ba-atom(pos, name) = atom(pos, fill: rgb("#00ffff"), name: cell-name + "-ba-" + name)
195+
let O-atom(pos, name) = atom( pos, fill: red, name: cell-name + "-o-" + name)
196+
let Ti-atom(pos) = atom( pos, fill: gray, name: cell-name + "-ti")
197+
let Ti-O-bond(end-pos, name) = line(
198+
((x, y + ti-y, z-offset/2), 15%, end-pos),
199+
((x, y + ti-y, z-offset/2), 85%, end-pos),
200+
stroke: 1pt,
201+
name: cell-name + "-bond-" + name,
209202
)
210203

211-
// Draw Ti-O bonds
212-
let bond-style = (stroke: (thickness: 0.5pt))
213-
for (end-pos, suffix) in (
214-
((x, y), "front"), // Front face center
215-
((x + z-offset, y + z-offset), "back"), // Back face center
216-
((x, y + 1), "top"), // Top face center
217-
((x, y - 1), "bottom"), // Bottom face center
218-
((x - 1, y), "left"), // Left face center
219-
((x + 1, y), "right"), // Right face center
220-
) {
221-
line(
222-
(x + z-offset / 2, y + ti-y), // Ti position
223-
end-pos,
224-
..bond-style,
225-
name: cell-name + "-bond-" + suffix,
226-
)
204+
// --- Back Plane (z = z-offset) ---
205+
Ba-atom((x - 1, y - 1, z-offset), "back-bl")
206+
Ba-atom((x + 1, y - 1, z-offset), "back-br")
207+
Ba-atom((x - 1, y + 1, z-offset), "back-tl")
208+
Ba-atom((x + 1, y + 1, z-offset), "back-tr")
209+
O-atom((x, y, z-offset), "back")
210+
Ti-O-bond((x, y, z-offset), "back")
211+
212+
// --- Middle Plane (z = z-offset/2) ---
213+
if ti-y >= 0 {
214+
Ti-O-bond((x, y + 1, z-offset/2), "top")
215+
}
216+
if ti-y <= 0 {
217+
Ti-O-bond((x, y - 1, z-offset/2), "bottom")
227218
}
219+
Ti-O-bond((x - 1, y, z-offset/2), "left")
220+
Ti-O-bond((x + 1, y, z-offset/2), "right")
221+
O-atom((x, y + 1, z-offset/2), "top")
222+
O-atom((x, y - 1, z-offset/2), "bottom")
223+
O-atom((x - 1, y, z-offset/2), "left")
224+
O-atom((x + 1, y, z-offset/2), "right")
225+
Ti-atom((x, y + ti-y, z-offset/2))
226+
227+
// --- Front Plane (z = 0) ---
228+
Ti-O-bond((x, y, 0), "front")
229+
Ba-atom((x - 1, y - 1, 0), "front-bl")
230+
Ba-atom((x + 1, y - 1, 0), "front-br")
231+
Ba-atom((x - 1, y + 1, 0), "front-tl")
232+
Ba-atom((x + 1, y + 1, 0), "front-tr")
233+
O-atom((x, y, 0), "front")
228234
}
229235

230236
// Draw three unit cells with different Ti displacements
231-
scale(0.75)
232-
draw-unit-cell(-4, y-offset + 5, -0.2, "cell1")
233-
draw-unit-cell(0, y-offset + 5, 0, "cell2")
234-
draw-unit-cell(4, y-offset + 5, 0.2, "cell3")
237+
scale(0.64)
238+
set-origin("potential-curve.mid")
239+
draw-unit-cell(-4.5, 2, -0.2, "cell1")
240+
draw-unit-cell(-0.5, 2, 0, "cell2")
241+
draw-unit-cell(3.5, 2, 0.2, "cell3")
235242
})

0 commit comments

Comments
 (0)