Skip to content

Commit

Permalink
Merge pull request #48 from nanotech-empa/release/1.4.2
Browse files Browse the repository at this point in the history
Release/1.4.2
  • Loading branch information
eimrek authored Jan 20, 2022
2 parents cdf8b09 + 1686304 commit 1a7f504
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
40 changes: 32 additions & 8 deletions nanoribbon/viewers/show_computed.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Viewers to display the results of the Nanoribbon work chain."""

# Base imports.
Expand Down Expand Up @@ -387,6 +388,8 @@ def __init__(self, cmap='seismic', center0=True, show_cbar=True, export_label=No
continuous_update=False,
layout=layout)
self.height_slider.observe(self.update_plot, names='value')
self.selected_height = 0.0 # angstrom

self.opacity_slider = ipw.FloatSlider(description="Opacity",
value=0.5,
max=1.0,
Expand Down Expand Up @@ -454,14 +457,16 @@ def update_axis(self, _=None):

geo_center = np.sum(self._current_structure.positions, axis=0) / len(self._current_structure)

z_arr = np.array([d_z * i - geo_center[2] for i in range(0, n_z, 1)])
i_closest_to_1ang = (np.abs(z_arr - 1.0)).argmin()
self.z_arr = np.array([d_z * i - geo_center[2] for i in range(0, n_z, 1)])

for i, z in enumerate(z_arr):
for i, z in enumerate(self.z_arr):
options[u"{:.3f} Å".format(z)] = i

self.height_slider.options = options
self.height_slider.value = list(options.values())[i_closest_to_1ang]

i_start = (np.abs(self.z_arr - 2.5)).argmin()
self.height_slider.value = list(options.values())[i_start]
self.selected_height = self.z_arr[i_start]

def update_plot(self, _=None):
"""Update the 2D plot with the new data."""
Expand All @@ -470,6 +475,7 @@ def update_plot(self, _=None):
fig, axplt = plt.subplots()
fig.dpi = 150.0
data = self._current_data[:, :, self.height_slider.value]
self.selected_height = self.z_arr[self.height_slider.value]
flipped_data = np.flip(data.transpose(), axis=0)

vmax = np.max(flipped_data) * self.colormap_slider.value
Expand Down Expand Up @@ -530,9 +536,11 @@ def make_export_link_txt(self, data):
enc_file = b64encode(tempio.getvalue()).decode()

if self.export_label is not None:
filename = "{}.txt".format(self.export_label)
plot_name = self.export_label
else:
filename = "export.txt"
plot_name = "export"

filename = "{}_h{:.3f}.txt".format(plot_name, self.selected_height)

html = '<a download="{}" href="'.format(filename)
html += 'data:chemical/txt;name={};base64,{}"'.format(filename, enc_file)
Expand All @@ -546,7 +554,8 @@ def make_export_link_igor(self, data):
plot_name = self.export_label
else:
plot_name = "export"
filename = plot_name + ".itx"

filename = "{}_h{:.3f}.itx".format(plot_name, self.selected_height)

igorwave = Wave2d(
data=data,
Expand Down Expand Up @@ -634,7 +643,11 @@ def __init__(self, workcalc, **kwargs):
]
custom_cmap = matplotlib.colors.LinearSegmentedColormap.from_list("half_seismic", custom_cmap_colors)

self.orbital_viewer_2d = CubeArrayData2dViewerWidget(cmap=custom_cmap, center0=False, export_label="pk%d_orbital" % workcalc.pk)
self.orbital_viewer_2d = CubeArrayData2dViewerWidget(
cmap=custom_cmap,
center0=False,
export_label=None
)
self.orbital_viewer_3d = CubeArrayData3dViewerWidget()

self.info_out = ipw.HTML()
Expand Down Expand Up @@ -766,7 +779,14 @@ def on_kpoint_change(self, _=None):
arraydata, fname = arraydata_fn
self.info_out.value = fname

self.orbital_viewer_2d.export_label = "pk{}_b{}_k{:02}_s{}".format(
self._workcalc.pk,
self.bands_viewer.selected_band,
self.bands_viewer.selected_kpoint,
self.bands_viewer.selected_spin,
)
self.orbital_viewer_2d.arraydata = self.clamp_arraydata_to_zero(arraydata)

with self.output:
clear_output()
if self.bands_viewer.selected_3D:
Expand Down Expand Up @@ -835,6 +855,10 @@ def on_sts_btn_click(self, _=None):
]
else:
self.sts_mapping_viewer_wrapper.children = [self.sts_mapping_viewer]

self.sts_mapping_viewer.export_label = "pk{}_ldos_fwhm{}_e{}".format(
self._workcalc.pk, self.sts_fwhm_text.value, self.sts_energy_text.value
)
self.sts_mapping_viewer.arraydata = sts_arraydata
else:
self.sts_mapping_viewer_wrapper.children = [ipw.HTML(value="Could not find data.")]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title = Empa nanotech@surfaces Laboratory - Graphene nanoribbons

[metadata]
name = nanoribbons
version = 1.4.1
version = 1.4.2
author = nanotech@surfaces laboratory, Empa
description = Tools for graphene nanoribbons, developed at the nanotech@surfaces laboratory, Empa
long_description = file: README.md
Expand Down
2 changes: 1 addition & 1 deletion show.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down

0 comments on commit 1a7f504

Please sign in to comment.