Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atom color picker options #169

Merged
merged 6 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions GoVizzy/gv_ui/gv_ui/DisplayUI.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import ipywidgets as widgets
from ipywidgets import Dropdown, VBox, HBox, Output, ColorPicker, AppLayout, Layout, Label, Button
from ipywidgets import Dropdown, VBox, HBox, Output, ColorPicker, AppLayout, Layout, Label, Button, Checkbox, link, Accordion
import ipyvolume as ipv
import matplotlib.pyplot as plt
from gv_ui import plotting, meshes, gvWidgets
from gv_ui.gvWidgets import mesh_visibility_toggle, atom_color_picker
from IPython.display import display

# Define globals
selected_option ='Slice Options'
options = ['Slice Options', 'Mesh Options', 'Color Options']
options = ['Slice Options', 'Mesh Options'] #, 'Color Options']
dropdown = Dropdown(options=options, value=options[0], layout=Layout(margin='5px 0 0 5px'));
large_box = Output(layout=Layout(width="70%", height="100%"))
selected_view_options = Output(layout=Layout(width="200px", height="300px"))
selected_view_options = Output(layout=Layout(width="auto", height="300px"))
slice_picker = Output(layout=Layout(flex= '1',border='1px solid black'))
slice_picker_descr = widgets.Label(value="Slice Picker", layout=Layout(margin='5px 0 0 5px'))
exit_button = widgets.Button(description='[X]', button_style='danger',border='1px solid black')
Expand All @@ -18,6 +20,11 @@

newCube_button = Button(description='New Cube', layout=Layout(flex= '1', border='1px solid black'))
save_button = Button(description='Save', layout=Layout(flex= '1', border='1px solid black'))


# atom mesh globals
atom_meshes = []

# Displays logo and hides the app output
def show_menu():
exit_button.layout.visibility = 'visible'
Expand Down Expand Up @@ -49,7 +56,9 @@ def show_ui():
newCube_button.layout.visibility = 'visible'

def display_cube(cube):
global atom_meshes
visualizer = plotting.Visualizer(cube)
global atom_meshes
with large_box: # Capture output within large_box
# Clear previous content
large_box.clear_output()
Expand All @@ -62,10 +71,8 @@ def display_cube(cube):
# Mesh View
elif selected_option == 'Mesh Options':
visualizer.display_cell()
origin = (50, 50, 50)
radius = 10
meshes.plot_sphere_surface(origin, radius)

atom_meshes = meshes.plot_atoms(cube)

# Additional View
elif selected_option == 'Color Options':
visualizer.display_cell()
Expand All @@ -78,7 +85,7 @@ def display_cube(cube):
def display_app():

# Containers for right menu

global atom_meshes

top_container = HBox([dropdown, in_app_exit])

Expand All @@ -96,12 +103,18 @@ def display_app():


elif selected_option == 'Mesh Options':
#display Mesh TO DO
#display Mesh TO DO
atom_controls = []
for mesh in atom_meshes:
controls = [mesh_visibility_toggle(mesh, 'Visible'),
atom_color_picker(mesh, 'Color')]
atom_controls.append(VBox(children=controls))
titles = tuple(f'Atom {idx}' for idx in range(len(atom_controls)))
with selected_view_options:
selected_view_options.clear_output()



accordion = Accordion(children=atom_controls, titles=titles)
mesh_box = VBox([accordion])
display(mesh_box)



Expand Down
12 changes: 11 additions & 1 deletion GoVizzy/gv_ui/gv_ui/gvWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Documentation for widget library: https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#file-upload
'''
from IPython.display import display
from ipywidgets import Layout, Button, Box, Textarea, Label, ColorPicker, FloatSlider, Checkbox
from ipywidgets import Layout, Button, Box, Textarea, Label, ColorPicker, FloatSlider, Checkbox, link
from ipyvolume.widgets import Mesh

# Input form
# Layout for Input form
Expand Down Expand Up @@ -65,8 +66,17 @@
indent=True
)

def mesh_visibility_toggle(mesh: Mesh, description: str="Atom"):
toggle = Checkbox(value=True, description=description)
link((toggle, 'value'), (mesh, 'visible'))
return toggle

color = ColorPicker(concise=True, value='white', description='Color', disabled=False, layout=Layout(flex='1 1 0%', width='auto'))

def atom_color_picker(atom: Mesh, description: str="Color"):
picker = ColorPicker(value=str(atom.color), description=description)
link((picker, 'value'), (atom, 'color'))
return picker

# Input form items
form_items = [
Expand Down
7 changes: 5 additions & 2 deletions GoVizzy/gv_ui/gv_ui/meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def sphere_surface(phi: float, theta: float):
return (x, y, z)

x, y, z = np.array(list(sphere_surface(gridx, gridy)))
ipv.plot_surface(x, z, y, color=color)
return ipv.plot_surface(x, z, y, color=color)

def plot_atoms(cube: Cube, sizes: dict[int, int]=vanderwaals, colors: dict[int, str]=default_colors):
'''
Expand All @@ -80,8 +80,11 @@ def plot_atoms(cube: Cube, sizes: dict[int, int]=vanderwaals, colors: dict[int,
'''
default_color = "red"
default_size = 10
atom_meshes = []
for atom in range(len(cube.atoms)):
position = cube.atoms.get_scaled_positions()[atom]
number = cube.atoms.get_atomic_numbers()[atom]
x, z, y = tuple(p * cube.data3D.shape[idx] / Bohr for idx, p in enumerate(position))
plot_sphere_surface((x, y, z), sizes[number] or default_size, colors[number] or default_color)
mesh = plot_sphere_surface((x, y, z), sizes.get(number, default_size), colors.get(number, default_color))
atom_meshes.append(mesh)
return atom_meshes