Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jung Nguyen
lectures
Commits
56a280bd
Verified
Commit
56a280bd
authored
Feb 11, 2020
by
Anton Akhmerov
Browse files
WIP: make a script for plotting Fermi surfaces
parent
2e8b5e21
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/fermi_surfaces.md
View file @
56a280bd
# Periodic table of Fermi surfaces
Data taken from the
[
Fermi surface database
](
https://www.phys.ufl.edu/fermisurface/
)
, © 2000 Tat-Sang Choy, CC-BY.
```
python
import
json
import
itertools
import
numpy
as
np
from
plotly
import
graph_objects
as
go
with
open
(
'code/fermi_surfaces.json'
)
as
f
:
fermi_surface_data
=
json
.
load
(
f
)
```
```
python
palette
=
[
'#1f77b4'
,
# muted blue
'#ff7f0e'
,
# safety orange
'#2ca02c'
,
# cooked asparagus green
'#d62728'
,
# brick red
'#9467bd'
,
# muted purple
'#8c564b'
,
# chestnut brown
'#e377c2'
,
# raspberry yogurt pink
'#7f7f7f'
,
# middle gray
'#bcbd22'
,
# curry yellow-green
'#17becf'
# blue-teal
]
def
element_to_traces
(
data
):
brillouin_zone
=
data
[
'brillouin_zone'
]
coords
,
indices
=
brillouin_zone
[
'coords'
],
np
.
array
(
brillouin_zone
[
'indices'
])
fermi_surfaces
=
data
[
'fermi_surfaces'
]
coords
=
np
.
array
(
3
*
[
np
.
nan
]
+
coords
).
reshape
(
-
1
,
3
)
x
,
y
,
z
=
coords
[
indices
+
1
].
T
bz_contour
=
go
.
Scatter3d
(
x
=
x
,
y
=
y
,
z
=
z
,
mode
=
'lines'
,
hoverinfo
=
'none'
,
)
surfaces
=
[]
for
zone
,
surface
in
fermi_surfaces
.
items
():
x
,
y
,
z
=
np
.
array
(
surface
[
'coords'
]).
reshape
(
-
1
,
3
).
T
i
,
j
,
k
=
np
.
array
(
surface
[
'indices'
]).
T
surfaces
.
append
(
go
.
Mesh3d
(
x
=
x
,
y
=
y
,
z
=
z
,
i
=
i
,
j
=
j
,
k
=
k
,
color
=
palette
[
int
(
zone
)
%
len
(
palette
)],
opacity
=
.
8
,
hoverinfo
=
'name'
,
name
=
f
'Band
{
zone
}
'
,
))
return
[
bz_contour
]
+
surfaces
```
```
python
elements_data
=
{
name
:
element_to_traces
(
data
)
for
name
,
data
in
fermi_surface_data
.
items
()}
index
=
itertools
.
count
()
trace_indices
=
[
[
i
for
i
,
j
in
zip
(
index
,
traces
)]
for
traces
in
elements_data
.
values
()
]
```
```
python
frames
=
[
go
.
Frame
(
data
=
traces
,
name
=
name
,
)
for
name
,
traces
,
_
in
zip
(
elements_data
,
elements_data
.
values
(),
range
(
5
))
],
```
```
python
fig
=
go
.
Figure
(
layout
=
go
.
Layout
(
scene
=
go
.
layout
.
Scene
(
xaxis
=
go
.
layout
.
scene
.
XAxis
(
color
=
'rgba(0,0,0,0)'
,
backgroundcolor
=
'rgba(0,0,0,0)'
,
),
yaxis
=
go
.
layout
.
scene
.
YAxis
(
color
=
'rgba(0,0,0,0)'
,
backgroundcolor
=
'rgba(0,0,0,0)'
,
),
zaxis
=
go
.
layout
.
scene
.
ZAxis
(
color
=
'rgba(0,0,0,0)'
,
backgroundcolor
=
'rgba(0,0,0,0)'
,
),
)
)
)
for
element
,
traces
in
fig
.
data
[
len
(
trace_indices
[
0
]):]:
trace
.
visible
=
False
fig
.
layout
.
updatemenus
=
[
{
'sliders'
:
[
go
.
layout
.
Slider
(
steps
=
[
dict
(
)
],
),
],
'direction'
:
'left'
,
'pad'
:
{
'r'
:
10
,
't'
:
87
},
'showactive'
:
False
,
'type'
:
'sli'
,
'x'
:
0.55
,
'xanchor'
:
'right'
,
'y'
:
0
,
'yanchor'
:
'top'
}
]
fig
```
```
python
```
```
python
# Imports
import
numpy
as
np
import
plotly.graph_objs
as
go
import
ipywidgets
as
widgets
import
time
init_notebook_mode
()
# Compute surface data
x
=
np
.
linspace
(
-
10
,
10
,
201
)
y
=
np
.
linspace
(
-
10
,
10
,
201
)
X
,
Y
=
np
.
meshgrid
(
x
,
y
)
z_bath
=
X
+
Y
z_tnm
=
np
.
zeros
((
10
,
201
,
201
),
dtype
=
float
)
for
t
in
range
(
10
):
tsunami
=
t
*
np
.
sin
(
X
+
t
/
10
*
np
.
pi
)
z_tnm
[
t
]
=
tsunami
# Create FigureWidget and add surface trace
#fig = go.Figure()
#surface = fig.add_surface(z=z_bath,name='bath')
# ----- change part ------
bath
=
go
.
Surface
(
z
=
z_bath
)
fig
=
go
.
Figure
(
data
=
[
bath
,
bath
])
# Set axis ranges to fixed values to keep them from retting during animation
fig
.
layout
.
scene
.
zaxis
.
range
=
[
-
10
,
10
]
fig
.
layout
.
scene
.
yaxis
.
range
=
[
0
,
150
]
fig
.
layout
.
scene
.
xaxis
.
range
=
[
0
,
150
]
#surface.cmin = -10
#surface.cmax = 10
frames
=
[]
for
i
in
range
(
10
):
frames
.
append
(
go
.
Frame
(
data
=
[{
'type'
:
'surface'
,
'z'
:
z_tnm
[
i
],
'name'
:
'tsunami'
}]))
fig
.
frames
=
frames
fig
.
layout
.
updatemenus
=
[
{
'buttons'
:
[
{
'args'
:
[
None
,
{
'frame'
:
{
'duration'
:
500
,
'redraw'
:
False
},
'fromcurrent'
:
True
,
'transition'
:
{
'duration'
:
300
}}],
'label'
:
'Play'
,
'method'
:
'animate'
},
{
'args'
:
[[
None
],
{
'frame'
:
{
'duration'
:
0
,
'redraw'
:
False
},
'mode'
:
'immediate'
,
'transition'
:
{
'duration'
:
0
}}],
'label'
:
'Pause'
,
'method'
:
'animate'
}
],
'direction'
:
'left'
,
'pad'
:
{
'r'
:
10
,
't'
:
87
},
'showactive'
:
False
,
'type'
:
'buttons'
,
'x'
:
0.55
,
'xanchor'
:
'right'
,
'y'
:
0
,
'yanchor'
:
'top'
}
]
fig
```
```
python
%
```
```
python
```
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment