st-speckmol icon indicating copy to clipboard operation
st-speckmol copied to clipboard

Adding Features / Parameters for the molecules (argument : _PARAMETERS)

Open avrabyt opened this issue 3 years ago • 4 comments

  • [x] a new argument : _PARAMETERS within the spec_plot function allows to add parameters such as outline, bonds, brightness etc . Mainly a helper function add_spec_param(xyz, **kwargs) is called within the spec_plot function
  • [ ] add_spec_param(xyz, **kwargs) ♻️ needs to be rewritten later

avrabyt avatar Jun 28 '22 00:06 avrabyt

FYI: Not sure if you have used streamlit's session state, It would help you to sync widgets and components

import streamlit as st
from ipyspeck import stspeck

example_xyz = '''12
benzene example
C        0.00000        1.40272        0.00000
H        0.00000        2.49029        0.00000
C       -1.21479        0.70136        0.00000
H       -2.15666        1.24515        0.00000
C       -1.21479       -0.70136        0.00000
H       -2.15666       -1.24515        0.00000
C        0.00000       -1.40272        0.00000
H        0.00000       -2.49029        0.00000
C        1.21479       -0.70136        0.00000
H        2.15666       -1.24515        0.00000
C        1.21479        0.70136        0.00000
H        2.15666        1.24515        0.00000
'''

st.set_page_config(
    layout="centered",
    page_title="Specklit",
    page_icon=":sparkles:")
st.sidebar.title("Parameter")

if 'model' not in st.session_state:
    st.session_state['model'] = {
        'bonds': True, 
        'atomScale': 0.24, 
        'relativeAtomScale': 0.64, 
        'bondScale': 0.5,
        'brightness': 0.5, 
        'outline': 0, 
        'spf': 32, 
        'bondShade': 0.5, 
        'atomShade': 0.5, 
        'dofStrength': 0, 
        'dofPosition': 0.5
    }

atomScale = st.sidebar.slider(
    'atomScale', 0.0, 1.0, value=float(st.session_state['model']['atomScale']))
bondScale = st.sidebar.slider(
    'bondScale', 0.0, 1.0, value=float(st.session_state['model']['bondScale']))
atomShade = st.sidebar.slider(
    'atomShade', 0.0, 1.0, value=float(st.session_state['model']['atomShade']))
bonds = st.sidebar.checkbox(
    "bonds", value=st.session_state['model']['bonds'])
outline = st.sidebar.checkbox(
    'outline', value=st.session_state['model']['outline'])
brightness = st.sidebar.slider(
    'brightness', 0.0, 1.0, value=float(st.session_state['model']['brightness']))
relativeAtomScale = st.sidebar.slider(
    'relativeAtomScale', 0.0, 1.0, value=float(st.session_state['model']['relativeAtomScale']))

spec_xyz = stspeck.Speck(
    data=example_xyz,
    atomScale=atomScale,
    bondScale=bondScale,
    outline=outline,
    atomShade=atomShade,
    bonds=bonds,
    brightness=brightness,
    width="800px",
    height="600px", 
    key="model"
)

denphi avatar Jul 08 '22 18:07 denphi

hi @avrabyt,

I found the speck repo has added some new parameters like 'ao' and 'aoRes' for ambient occlusion control, can we add them to support it?

https://github.com/plotly/speck/blob/master/src/view.js#L25

jump2cn avatar May 16 '24 03:05 jump2cn

Hi @jump2cn , yeah I think it is very much possible to add it . Would you mind to make a PR ? It's been while I've made any updates here. Happy to see your interest :)

avrabyt avatar May 16 '24 18:05 avrabyt

@jump2cn, ipyspeck>=0.6.2 exposes ao and aoRes to its streamlite component (stspeck), but NO to its ipywidget, I still need to find time to port it to ipywidgets 8.X

import streamlit as st
from ipyspeck import stspeck

H2O='''3
Water molecule
O          0.00000        0.00000        0.11779
H          0.00000        0.75545       -0.47116
H          0.00000       -0.75545       -0.47116'''

with st.sidebar:
    ao = st.selectbox("Select ao",[0, 0.1, 0.2 ,0.5, 0.8,1])
    bonds = st.selectbox("Select bonds",[True,False])

res = stspeck.Speck(
  data=H2O,
  ao=ao,
  width="800px",
  height="600px"
)

denphi avatar May 16 '24 21:05 denphi