Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
lectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Solid state physics
lectures
Commits
8f6fb1c0
Commit
8f6fb1c0
authored
5 years ago
by
Kostas Vilkelis
Browse files
Options
Downloads
Patches
Plain Diff
fixed plot in lecture 10
parent
43d3a2d0
No related branches found
No related tags found
1 merge request
!65
Crystal structure changes
Pipeline
#28115
passed
5 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/10_xray.md
+81
-135
81 additions, 135 deletions
src/10_xray.md
with
81 additions
and
135 deletions
src/10_xray.md
+
81
−
135
View file @
8f6fb1c0
...
@@ -100,162 +100,108 @@ which is clearly 1.
...
@@ -100,162 +100,108 @@ which is clearly 1.
### Example of a two-dimensional reciprocal lattice
### Example of a two-dimensional reciprocal lattice
```
python
```
python
# Define
th
e lattice vectors
# Define
primitiv
e lattice vectors
a1
=
np
.
array
([
1
,
0
])
a1
=
np
.
array
([
1
,
0
])
a2
=
np
.
array
([
0.5
,
sqrt
(
3
)
/
2
])
a2
=
np
.
array
([
0.5
,
sqrt
(
3
)
/
2
])
a1_alt
=
-
a1
-
a2
# Compute reciprocal lattice vectors
a2_alt
=
a1_alt
+
a1
b1
,
b2
=
np
.
linalg
.
inv
(
np
.
array
([
a1
,
a2
]).
T
)
@
np
.
eye
(
2
)
*
2
*
pi
a2_c
=
np
.
array
([
0
,
sqrt
(
3
)])
# Produces the lattice to be fed into plotly
fig
=
make_subplots
(
rows
=
1
,
cols
=
2
,
shared_yaxes
=
True
,
subplot_titles
=
(
'
Real Space
'
,
'
Reciprocal Space
'
))
def
lattice_generation
(
a1
,
a2
,
N
=
6
):
# Generates the lattice given the lattice vectors
def
lattice_generation
(
a1
,
a2
,
N
):
grid
=
np
.
arange
(
-
N
//
2
,
N
//
2
,
1
)
grid
=
np
.
arange
(
-
N
//
2
,
N
//
2
,
1
)
xGrid
,
yGrid
=
np
.
meshgrid
(
grid
,
grid
)
xGrid
,
yGrid
=
np
.
meshgrid
(
grid
,
grid
)
return
np
.
reshape
(
np
.
kron
(
xGrid
.
flatten
(),
a1
),(
-
1
,
2
))
+
np
.
reshape
(
np
.
kron
(
yGrid
.
flatten
(),
a2
),(
-
1
,
2
))
return
np
.
reshape
(
np
.
kron
(
xGrid
.
flatten
(),
a1
),(
-
1
,
2
))
+
np
.
reshape
(
np
.
kron
(
yGrid
.
flatten
(),
a2
),(
-
1
,
2
))
def
subplot
(
a1
,
a2
,
col
):
# Produces the dotted lines of the unit cell
N
=
6
def
dash_contour
(
a1
,
a2
,
vec_zero
=
np
.
array
([
0
,
0
]),
color
=
'
Red
'
):
lat_points
=
lattice_generation
(
a1
,
a2
,
N
)
dotLine_a1
=
np
.
transpose
(
np
.
array
([
a1
,
a1
+
a2
])
+
vec_zero
)
line_a1
=
np
.
transpose
([[
0
,
0
],
a1
])
dotLine_a2
=
np
.
transpose
(
np
.
array
([
a2
,
a1
+
a2
])
+
vec_zero
)
line_a2
=
np
.
transpose
([[
0
,
0
],
a2
])
dotLine_a1
=
np
.
transpose
([
a1
,
a1
+
a2
])
dotLine_a2
=
np
.
transpose
([
a2
,
a1
+
a2
])
def
dash_trace
(
vec
,
color
):
trace
=
go
.
Scatter
(
x
=
vec
[
0
],
y
=
vec
[
1
],
mode
=
'
lines
'
,
line_width
=
2
,
line_color
=
color
,
line_dash
=
'
dot
'
,
visible
=
False
)
return
trace
return
dash_trace
(
dotLine_a1
,
color
),
dash_trace
(
dotLine_a2
,
color
)
fig
.
add_trace
(
go
.
Scatter
(
visible
=
False
,
x
=
line_a1
[
0
],
y
=
line_a1
[
1
],
mode
=
'
lines
'
,
line_color
=
'
red
'
# Makes the lattice vector arrow
),
row
=
1
,
col
=
col
def
make_arrow
(
vec
,
text
,
color
=
'
Red
'
,
vec_zero
=
[
0
,
0
],
text_shift
=
[
-
0.2
,
-
0.1
]):
annot
=
[
dict
(
x
=
vec
[
0
]
+
vec_zero
[
0
],
y
=
vec
[
1
]
+
vec_zero
[
1
],
ax
=
vec_zero
[
0
],
ay
=
vec_zero
[
1
],
xref
=
'
x
'
,
yref
=
'
y
'
,
axref
=
'
x
'
,
ayref
=
'
y
'
,
showarrow
=
True
,
arrowhead
=
2
,
arrowsize
=
1
,
arrowwidth
=
3
,
arrowcolor
=
color
),
dict
(
x
=
(
vec
[
0
]
+
vec_zero
[
0
])
/
2
+
text_shift
[
0
],
y
=
(
vec
[
1
]
+
vec_zero
[
1
])
/
2
+
text_shift
[
1
],
xref
=
'
x
'
,
ayref
=
'
y
'
,
text
=
text
,
font
=
dict
(
color
=
color
,
size
=
20
),
showarrow
=
False
,
)
]
return
annot
# Create the pattern
pattern_points
=
lattice_generation
(
a1
,
a2
)
pattern
=
go
.
Scatter
(
x
=
pattern_points
.
T
[
0
],
y
=
pattern_points
.
T
[
1
],
mode
=
'
markers
'
,
marker
=
dict
(
color
=
'
Black
'
,
size
=
20
,
symbol
=
'
star-open-dot
'
)
)
)
fig
.
add_trace
(
# Lattice Choice A
go
.
Scatter
(
visible
=
False
,
x
=
line_a2
[
0
],
y
=
line_a2
[
1
],
mode
=
'
lines
'
,
line_color
=
'
red
'
latticeA
=
go
.
Scatter
(
visible
=
False
,
x
=
pattern_points
.
T
[
0
],
y
=
pattern_points
.
T
[
1
],
mode
=
'
markers
'
,
marker
=
dict
(
),
row
=
1
,
col
=
col
color
=
'
Red
'
,
size
=
10
,
)
)
)
fig
.
add_trace
(
# Lattice Choice B
go
.
Scatter
(
visible
=
False
,
x
=
dotLine_a1
[
0
],
y
=
dotLine_a1
[
1
],
mode
=
'
lines
'
,
line_color
=
'
red
'
,
line_dash
=
'
dot
'
latB_points
=
lattice_generation
(
a1
,
a2
)
),
row
=
1
,
col
=
col
latticeB
=
go
.
Scatter
(
visible
=
False
,
x
=
latB_points
.
T
[
0
]
+
0.5
,
y
=
latB_points
.
T
[
1
],
mode
=
'
markers
'
,
marker
=
dict
(
color
=
'
Blue
'
,
size
=
10
,
)
)
)
fig
.
add_trace
(
# Annotate the lattice vectors
go
.
Scatter
(
visible
=
False
,
x
=
dotLine_a2
[
0
],
y
=
dotLine_a2
[
1
],
mode
=
'
lines
'
,
line_color
=
'
red
'
,
line_dash
=
'
dot
'
# Button 2
),
row
=
1
,
col
=
col
bt2_annot
=
make_arrow
(
a1
,
'
$a_1$
'
)
+
make_arrow
(
a2
,
'
$a_2$
'
)
+
make_arrow
(
a1_alt
,
'
$a`_1$
'
,
color
=
'
Black
'
,
text_shift
=
[
-
0.55
,
-
0.1
])
+
make_arrow
(
a2_alt
,
'
$a`_2$
'
,
color
=
'
Black
'
)
#Button 3
bt3_annot
=
make_arrow
(
a1
,
'
$a_1$
'
,
vec_zero
=
[
-
0.5
,
0
],
color
=
'
Blue
'
)
+
make_arrow
(
a2
,
'
$a_2$
'
,
vec_zero
=
[
-
0.5
,
0
],
color
=
'
Blue
'
)
#Button 4
bt4_annot
=
make_arrow
(
a2_c
,
'
$a_2$
'
)
+
make_arrow
(
a1
,
'
$a_1$
'
)
# (0) Button 1, (0, 1-5) Button 2, (0, 6-8) Button 3, (0,1,9,10)
data
=
[
pattern
,
latticeA
,
*
dash_contour
(
a1
,
a2
),
*
dash_contour
(
a1_alt
,
a2_alt
,
color
=
'
Black
'
),
latticeB
,
*
dash_contour
(
a1
,
a2
,
vec_zero
=
[
-
0.5
,
0
],
color
=
'
Blue
'
),
*
dash_contour
(
a1
,
a2_c
)]
updatemenus
=
list
([
dict
(
type
=
"
buttons
"
,
direction
=
"
down
"
,
active
=
0
,
buttons
=
list
([
dict
(
label
=
"
Pattern
"
,
method
=
"
update
"
,
args
=
[{
"
visible
"
:
[
True
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
]},
{
"
title
"
:
"
Pattern
"
,
"
annotations
"
:
[]}]),
dict
(
label
=
"
Lattice A
"
,
method
=
"
update
"
,
args
=
[{
"
visible
"
:
[
True
,
True
,
True
,
True
,
True
,
True
,
False
,
False
,
False
,
False
,
False
]},
{
"
title
"
:
"
Lattice A with a Primitive Unit Cell
"
,
"
annotations
"
:
bt2_annot
}]),
dict
(
label
=
"
Lattice B
"
,
method
=
"
update
"
,
args
=
[{
"
visible
"
:
[
True
,
False
,
False
,
False
,
False
,
False
,
True
,
True
,
True
,
False
,
False
]},
{
"
title
"
:
"
Lattice B with a Primitive Unit Cell
"
,
"
annotations
"
:
bt3_annot
}]),
dict
(
label
=
"
C.U.Cell
"
,
method
=
"
update
"
,
args
=
[{
"
visible
"
:
[
True
,
True
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
True
,
True
]},
{
"
title
"
:
"
Conventional Unit Cell
"
,
"
annotations
"
:
bt4_annot
}])
]),
)
)
]
)
fig
.
add_trace
(
go
.
Scatter
(
visible
=
False
,
x
=
lat_points
.
T
[
0
],
y
=
lat_points
.
T
[
1
],
mode
=
'
markers
'
,
marker
=
dict
(
color
=
'
Black
'
,
size
=
20
)
),
row
=
1
,
col
=
col
)
plot_range
=
2
# Generate subplots to be used by the slider
axis
=
dict
(
N_values
=
10
for
i
in
np
.
linspace
(
2.5
,
3.5
,
N_values
):
subplot
(
a1
*
i
,
a2
*
i
,
1
)
subplot
(
b1
/
i
,
b2
/
i
,
2
)
# Define the default subplot
active
=
4
for
i
in
range
(
10
):
fig
.
data
[
active
*
10
+
i
].
visible
=
True
steps
=
[]
for
i
in
range
(
N_values
):
step
=
dict
(
label
=
'
Lattice Constant
'
,
method
=
"
restyle
"
,
args
=
[
"
visible
"
,
[
False
]
*
len
(
fig
.
data
)],
)
for
j
in
range
(
10
):
step
[
"
args
"
][
1
][
i
*
10
+
j
]
=
True
# Toggle i'th trace to "visible"
steps
.
append
(
step
)
sliders
=
[
dict
(
tickcolor
=
'
White
'
,
font_color
=
'
White
'
,
currentvalue_font_color
=
'
Black
'
,
active
=
active
,
name
=
'
Lattice Constant
'
,
steps
=
steps
)]
plot_range
=
5
fig
.
update_layout
(
sliders
=
sliders
,
showlegend
=
False
,
plot_bgcolor
=
'
rgb(254, 254, 254)
'
,
width
=
1000
,
height
=
500
,
xaxis
=
dict
(
range
=
[
-
plot_range
,
plot_range
],
range
=
[
-
plot_range
,
plot_range
],
visible
=
False
,
visible
=
False
,
showgrid
=
False
,
showgrid
=
False
,
fixedrange
=
True
fixedrange
=
True
),
yaxis
=
dict
(
range
=
[
-
plot_range
,
plot_range
],
visible
=
False
,
showgrid
=
False
,
fixedrange
=
True
)
)
layout
=
dict
(
showlegend
=
False
,
updatemenus
=
updatemenus
,
plot_bgcolor
=
'
rgb(254, 254, 254)
'
,
width
=
600
,
height
=
600
,
xaxis
=
axis
,
yaxis
=
axis
)
)
fig
.
update_yaxes
(
range
=
[
-
plot_range
,
plot_range
],
row
=
1
,
col
=
2
)
fig
.
update_xaxes
(
range
=
[
-
plot_range
,
plot_range
],
row
=
1
,
col
=
2
,
visible
=
False
)
fig
.
show
()
fig
=
dict
(
data
=
data
,
layout
=
layout
)
py
.
iplot
(
fig
,
filename
=
'
lattice_basics
'
)
```
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment