Skip to content

Commit 6865c81

Browse files
committed
add organic-molecule.typ and branch-cuts-2.typ converted from Latex and add 3d shading via radial gradient to assets/sublattice-points/sublattice-points.typ
1 parent d22e74c commit 6865c81

File tree

4 files changed

+348
-7
lines changed

4 files changed

+348
-7
lines changed
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#import "@preview/cetz:0.3.4": canvas, draw
2+
#import draw: line, content, bezier
3+
4+
#set page(width: auto, height: auto, margin: 8pt)
5+
6+
// Functions for the branch cuts - adjusted to better match the original
7+
// Increased vertical scaling to spread the curves further apart
8+
#let f1(x) = 5 / (calc.sqrt(x) + 2)
9+
#let f2(x) = 5 * (1 / (x + 2) + 1 / 3)
10+
#let f3(x) = -5 / (calc.sqrt(x) + 2)
11+
#let f4(x) = -5 * (1 / (x + 2) + 1 / 3)
12+
13+
#canvas({
14+
// Set up the coordinate system
15+
let (width, height) = (10, 8)
16+
17+
// Draw axes
18+
line(
19+
(0, 0),
20+
(width, 0),
21+
mark: (end: "stealth", fill: black),
22+
stroke: 1.2pt,
23+
name: "x-axis",
24+
)
25+
content((rel: (0, -0.2), to: "x-axis.end"), $"Re"(q_0)$, anchor: "north-east")
26+
27+
line(
28+
(0, -height / 2),
29+
(0, height / 2),
30+
mark: (end: "stealth", fill: black),
31+
stroke: 1.2pt,
32+
name: "y-axis",
33+
)
34+
content((rel: (0.2, 0), to: "y-axis.end"), $"Im"(q_0)$, anchor: "north-west")
35+
36+
// Draw the curves
37+
// Helper function to draw a parametric curve
38+
let draw-curve(f, domain: (1, 9), samples: 100, stroke: black) = {
39+
let points = ()
40+
let step = (domain.at(1) - domain.at(0)) / samples
41+
42+
for i in range(samples + 1) {
43+
let x = domain.at(0) + i * step
44+
let y = f(x)
45+
points.push((x, y))
46+
}
47+
48+
for i in range(samples) {
49+
line(
50+
points.at(i),
51+
points.at(i + 1),
52+
stroke: stroke,
53+
)
54+
}
55+
}
56+
57+
// Draw the red curves
58+
draw-curve(f1, stroke: red + 2pt)
59+
draw-curve(f2, stroke: red + 2pt)
60+
61+
// Draw the blue curves
62+
draw-curve(f3, stroke: blue + 2pt)
63+
draw-curve(f4, stroke: blue + 2pt)
64+
65+
// Calculate points on the curves for arrow start positions
66+
let top_red_x = 4
67+
let top_red_y = f2(top_red_x) // Use the second red curve (higher one)
68+
69+
let bottom_blue_x = 4
70+
let bottom_blue_y = f4(bottom_blue_x) // Use the fourth curve (lower blue one)
71+
72+
// Add the dashed arrows pointing to the origin
73+
// First arrow (from top red curve to origin) - flipped curve direction
74+
bezier(
75+
(top_red_x, top_red_y), // start point - on the red curve
76+
(3.5, 0), // end point - at the origin
77+
(3.6, top_red_y * 0.7), // control point - flipped direction
78+
stroke: (dash: "dashed", thickness: 1pt),
79+
mark: (end: "stealth", fill: black, scale: 0.8),
80+
name: "arrow1",
81+
)
82+
content((rel: (0.15, 0), to: "arrow1.80%"), $k arrow.r 0$, anchor: "west")
83+
84+
// Second arrow (from bottom blue curve to origin) - flipped curve direction
85+
bezier(
86+
(bottom_blue_x, bottom_blue_y), // start point - on the lower blue curve
87+
(3.5, 0), // end point - at the origin
88+
(3.6, bottom_blue_y * 0.7), // control point - flipped direction
89+
stroke: (dash: "dashed", thickness: 1pt),
90+
mark: (end: "stealth", fill: black, scale: 0.8),
91+
name: "arrow2",
92+
)
93+
content((rel: (-0.15, 0), to: "arrow2.80%"), $k arrow.r 0$, anchor: "east")
94+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
#import "@preview/cetz:0.3.4": canvas, draw
2+
#import draw: circle, content, line, on-layer
3+
4+
#set page(width: auto, height: auto, margin: 5pt)
5+
6+
// Atom with 3D shading effect
7+
#let atom(pos, color, element, radius: 0.3, name: none) = {
8+
// Base circle with main color
9+
circle(
10+
pos,
11+
radius: radius,
12+
stroke: none,
13+
fill: color,
14+
name: name,
15+
)
16+
17+
// Gradient overlay for 3D effect
18+
circle(
19+
pos,
20+
radius: radius,
21+
stroke: none,
22+
fill: gradient.radial(
23+
color.lighten(85%),
24+
color,
25+
color.darken(25%),
26+
focal-center: (25%, 20%),
27+
focal-radius: 10%,
28+
center: (30%, 25%),
29+
),
30+
)
31+
32+
// Add element label
33+
let text-color = if color == rgb("#333333") { white } else { black }
34+
35+
// Calculate text size based on radius
36+
let text-size = if radius < 0.4 { 10pt } else { 14pt }
37+
38+
content(
39+
pos,
40+
text(fill: text-color, weight: "bold", size: text-size)[#element],
41+
anchor: "center",
42+
)
43+
}
44+
45+
#canvas({
46+
// Define atom colors
47+
let hydrogen-color = rgb("#eee")
48+
let carbon-color = rgb("#333")
49+
let nitrogen-color = rgb("#3333cc")
50+
let oxygen-color = red.darken(10%)
51+
52+
// Define atom sizes - increased to match target image
53+
let h-radius = 0.35
54+
let heavy-radius = 0.5
55+
56+
// Adjust hydrogen positions to be further from connected atoms
57+
// Original positions from LaTeX
58+
let orig-h-positions = (
59+
("H1", (-2.9, 1.39)),
60+
("H2", (-3.5, 1.23)),
61+
("H3", (-3.8, 0.15)),
62+
("H4", (-1.7, -0.6)),
63+
("H5", (-0.3, 1.4)),
64+
("H6", (-1, 1.15)),
65+
("H7", (0, -0.7)),
66+
("H8", (1, -1.82)),
67+
("H9", (0.2, -1.8)),
68+
("H10", (3.5, 0.5)),
69+
)
70+
71+
// Heavy atom positions
72+
let c-positions = (
73+
("C1", (-3.19, 0.68)),
74+
("C2", (-0.78, 0.67)),
75+
("C3", (0.47, -0.18)),
76+
("C4", (1.73, 0.67)),
77+
)
78+
79+
let n-positions = (
80+
("N1", (-2.00, -0.15)),
81+
("N2", (0.51, -1.32)),
82+
)
83+
84+
let o-positions = (
85+
("O1", (1.80, 1.88)),
86+
("O2", (2.86, -0.07)),
87+
)
88+
89+
// Function to move hydrogen atoms further from their connected atoms
90+
let adjust-h-position(h-pos, connected-pos, factor: 1.5) = {
91+
let (hx, hy) = h-pos
92+
let (cx, cy) = connected-pos
93+
let dx = hx - cx
94+
let dy = hy - cy
95+
let dist = calc.sqrt(dx * dx + dy * dy)
96+
let new-dist = dist * factor
97+
let scale = new-dist / dist
98+
(cx + dx * scale, cy + dy * scale)
99+
}
100+
101+
// Connection map: which hydrogen connects to which heavy atom
102+
let h-connections = (
103+
"H1": "C1",
104+
"H2": "C1",
105+
"H3": "C1",
106+
"H4": "N1",
107+
"H5": "C2",
108+
"H6": "C2",
109+
"H7": "C3",
110+
"H8": "N2",
111+
"H9": "N2",
112+
"H10": "O2",
113+
)
114+
115+
// Combine all heavy atom positions for lookup
116+
let heavy-atoms = (:)
117+
for (name, pos) in c-positions { heavy-atoms.insert(name, pos) }
118+
for (name, pos) in n-positions { heavy-atoms.insert(name, pos) }
119+
for (name, pos) in o-positions { heavy-atoms.insert(name, pos) }
120+
121+
// Adjust hydrogen positions
122+
let h-positions = (:)
123+
for (name, pos) in orig-h-positions {
124+
let connected-atom = h-connections.at(name)
125+
let connected-pos = heavy-atoms.at(connected-atom)
126+
h-positions.insert(name, adjust-h-position(pos, connected-pos))
127+
}
128+
129+
// Further adjust overlapping hydrogens
130+
// Adjust H1 and H2 which overlap in the top left
131+
let h1-pos = h-positions.at("H1")
132+
let h2-pos = h-positions.at("H2")
133+
h-positions.insert("H1", (h1-pos.at(0) - 0.2, h1-pos.at(1) + 0.2))
134+
h-positions.insert("H2", (h2-pos.at(0) - 0.2, h2-pos.at(1) - 0.2))
135+
136+
// Adjust H8 and H9 which overlap near the right N atom
137+
let h8-pos = h-positions.at("H8")
138+
let h9-pos = h-positions.at("H9")
139+
h-positions.insert("H8", (h8-pos.at(0) + 0.3, h8-pos.at(1) - 0.2))
140+
h-positions.insert("H9", (h9-pos.at(0) - 0.3, h9-pos.at(1) - 0.2))
141+
142+
// Draw all atoms
143+
// Draw carbon atoms
144+
for (name, pos) in c-positions {
145+
atom(pos, carbon-color, "C", radius: heavy-radius, name: name)
146+
}
147+
148+
// Draw nitrogen atoms
149+
for (name, pos) in n-positions {
150+
atom(pos, nitrogen-color, "N", radius: heavy-radius, name: name)
151+
}
152+
153+
// Draw oxygen atoms
154+
for (name, pos) in o-positions {
155+
atom(pos, oxygen-color, "O", radius: heavy-radius, name: name)
156+
}
157+
158+
// Draw hydrogen atoms
159+
for (name, pos) in h-positions {
160+
atom(pos, hydrogen-color, "H", radius: h-radius, name: name)
161+
}
162+
163+
// Draw bonds on a background layer (behind atoms)
164+
on-layer(
165+
-1,
166+
{
167+
// Main chain
168+
let bond-chain = ("H1", "C1", "N1", "C2", "C3", "C4", "O1")
169+
for i in range(bond-chain.len() - 1) {
170+
let from = bond-chain.at(i)
171+
let to = bond-chain.at(i + 1)
172+
173+
let from-pos = if from.starts-with("H") {
174+
h-positions.at(from)
175+
} else {
176+
heavy-atoms.at(from)
177+
}
178+
179+
let to-pos = if to.starts-with("H") {
180+
h-positions.at(to)
181+
} else {
182+
heavy-atoms.at(to)
183+
}
184+
185+
line(
186+
from-pos,
187+
to-pos,
188+
stroke: (paint: gray, thickness: 3.5pt),
189+
)
190+
}
191+
192+
// Additional bonds
193+
let additional-bonds = (
194+
("H2", "C1"),
195+
("H3", "C1"),
196+
("N1", "H4"),
197+
("C2", "H5"),
198+
("C2", "H6"),
199+
("C3", "H7"),
200+
("C3", "N2"),
201+
("N2", "H8"),
202+
("N2", "H9"),
203+
("C4", "O2"),
204+
("O2", "H10"),
205+
)
206+
207+
for (from, to) in additional-bonds {
208+
let from-pos = if from.starts-with("H") {
209+
h-positions.at(from)
210+
} else {
211+
heavy-atoms.at(from)
212+
}
213+
214+
let to-pos = if to.starts-with("H") {
215+
h-positions.at(to)
216+
} else {
217+
heavy-atoms.at(to)
218+
}
219+
220+
line(
221+
from-pos,
222+
to-pos,
223+
stroke: (paint: gray, thickness: 3.5pt),
224+
)
225+
}
226+
},
227+
)
228+
})

assets/sublattice-points/sublattice-points.typ

+22-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33

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

6+
// Atom with 3D shading effect
7+
#let shaded-circle(pos, color, radius: 0.1, name: none, stroke: 0.2pt) = {
8+
circle(
9+
pos,
10+
radius: radius,
11+
stroke: stroke,
12+
fill: gradient.radial(
13+
color.lighten(85%),
14+
color,
15+
color.darken(25%),
16+
focal-center: (25%, 20%),
17+
focal-radius: 10%,
18+
center: (30%, 25%),
19+
),
20+
name: name,
21+
)
22+
}
23+
624
#canvas({
725
// Define styles and constants
826
let grid-size = 2 // number of points in each direction
@@ -29,11 +47,12 @@
2947
// Use modulo to cycle through colors
3048
let color-idx = calc.rem(ii - 2 * jj, colors.len())
3149
if color-idx < 0 { color-idx += colors.len() }
32-
circle(
50+
51+
// Use the shaded-circle function instead of regular circle
52+
shaded-circle(
3353
(x, y),
54+
colors.at(color-idx),
3455
radius: dot-radius * 1.2,
35-
fill: colors.at(color-idx),
36-
stroke: .5pt,
3756
name: str(ii) + "," + str(jj),
3857
)
3958
}

0 commit comments

Comments
 (0)