diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fadf218 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# production + +dist +# misc +.DS_Store + +*.egg-info +__pycache__ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..51c2665 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Avra + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ + diff --git a/README.md b/README.md index d443d6f..78a893b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,27 @@ # Specklit Speck figures to Streamlit Web App + +## Installation +`pip install st-speckmol==0.0.3` + +## Example + +``` +import streamlit as st +import glob +from st_speckmol import spec_plot + +# Example files path +ex_files = glob.glob("examples/*.xyz") +with st.sidebar: + example_xyz = st.selectbox("Select a molecule",ex_files) + f = open(example_xyz,"r") + example_xyz = f.read() + +res = spec_plot(example_xyz) + +``` [![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://share.streamlit.io/avrabyt/specklit/main/app.py) ![Speclit demo](https://github.com/avrabyt/Specklit/blob/main/SpeckLit_demo.gif) diff --git a/app-main.py b/app-main.py new file mode 100644 index 0000000..d5c5ed1 --- /dev/null +++ b/app-main.py @@ -0,0 +1,12 @@ +import streamlit as st +import glob +from st_speckmol import spec_plot + +# Example files path +ex_files = glob.glob("examples/*.xyz") +with st.sidebar: + example_xyz = st.selectbox("Select a molecule",ex_files) + f = open(example_xyz,"r") + example_xyz = f.read() + +res = spec_plot(example_xyz) diff --git a/app.py b/app.py deleted file mode 100644 index 1942fe3..0000000 --- a/app.py +++ /dev/null @@ -1,64 +0,0 @@ -import streamlit as st -import ipywidgets as widgets -from ipywidgets import embed -import ipyspeck -import streamlit.components.v1 as components -import glob - -st.set_page_config( - layout="centered", - page_title="Specklit", - page_icon=":sparkles:") - -def add_spec_param(spec_xyz,atom_Scale,bond_Scale,outline,atomShade,bonds,bondThreshold): - #Modify atoms size - spec_xyz.atomScale = atom_Scale - #change bonds size - spec_xyz.bondScale = bond_Scale - #highlight borders - spec_xyz.outline = outline - spec_xyz.atomShade = atomShade - spec_xyz.bonds = bonds - spec_xyz.bondThreshold = bondThreshold - return spec_xyz - -def spec_plot(_xyz): - spec_xyz = ipyspeck.speck.Speck(data=_xyz, title='') - spec_xyz = add_spec_param(spec_xyz,atom_Scale,bond_Scale,outline,atom_Shade,bonds,bondThreshold) - spec_xyz.setColorSchema(schema='newcpk') - c = widgets.Box([spec_xyz], layout=widgets.Layout(width="800px",height="700px")) - snippet = embed.embed_snippet(c) - html = embed.html_template.format(title="", snippet=snippet) - components.html(html,height = 1000, width = 900) - return spec_xyz - -ex_files = glob.glob("examples/*.xyz") - -st.sidebar.title(" XYZ to SPECK-Structures :tada:") -with st.sidebar.expander(label = "Examples",expanded=True): - st.markdown("[Source](https://github.com/wwwtyro/speck/tree/gh-pages/static/samples)") - example_xyz = st.selectbox("Select a molecule",ex_files) - f = open(example_xyz,"r") - example_xyz = f.read() - - -st.sidebar.markdown("# Parameter section:") -st.sidebar.info("You can also add your own coordinates below. :coffee:") -_xyz = st.sidebar.text_area( - label = "What are the Coordinates ?", - value= example_xyz, height = 200) - -st.code(_xyz.splitlines()[1]) - - -atom_Scale = st.sidebar.slider('Atom Scale', 0.1, 1.0, 0.35) -bond_Scale = st.sidebar.slider('Bond Scale', 0.1, 1.0, 0.5) -atom_Shade = st.sidebar.slider('Atom Shade', 0.1, 1.0, 0.0) -bondThreshold = st.sidebar.slider('Bond Threshold', 0.1, 5.0, 1.2) -bonds = st.sidebar.checkbox("Bonds",value = True) -outline = st.sidebar.checkbox('Outline',value = True) -res = spec_plot(_xyz) - -with st.expander("References:",expanded=True): - st.markdown("[Speck Online](http://wwwtyro.github.io/speck/)") - st.markdown("[Speck Python package](https://pypi.org/project/ipyspeck/)") \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4aa2f52 --- /dev/null +++ b/setup.py @@ -0,0 +1,17 @@ +import setuptools + +setuptools.setup( + name="st_speckmol", + version="0.0.3", + author="Avratanu Biswas", + author_email="avrab.yt@gmail.com", + description="Streamlit component for for Speck molecule visualization.", + long_description="Streamlit component for visualizing SPECK molecules - https://github.com/wwwtyro/speck", + long_description_content_type="text/plain", + url="https://github.com/avrabyt/Specklit", + packages=setuptools.find_packages(), + include_package_data=True, + classifiers=[], + python_requires=">=3.6", + install_requires=["streamlit >= 0.63", "ipyspeck==0.6.1", "ipywidgets==7.6.3"], +) diff --git a/speckmol/__pycache__/funx.cpython-310.pyc b/speckmol/__pycache__/funx.cpython-310.pyc new file mode 100644 index 0000000..1d814c3 Binary files /dev/null and b/speckmol/__pycache__/funx.cpython-310.pyc differ diff --git a/speckmol/__pycache__/funx.cpython-38.pyc b/speckmol/__pycache__/funx.cpython-38.pyc new file mode 100644 index 0000000..4adb44e Binary files /dev/null and b/speckmol/__pycache__/funx.cpython-38.pyc differ diff --git a/speckmol/funx.py b/speckmol/funx.py new file mode 100644 index 0000000..6f0cb78 --- /dev/null +++ b/speckmol/funx.py @@ -0,0 +1,45 @@ +import streamlit.components.v1 as components +import ipywidgets as widgets +from ipywidgets import embed +import ipyspeck + +def spec_plot(_xyz, wbox_height="700px", + wbox_width="800px", + component_h = 700, + component_w = 800, + scroll = False): + + """ Plots the speckmol molecule using the ipyspeck library and returns + the . + + Parameters + ---------- + _xyz : str + The xyz string of the molecule. + wbox_height : str + The height of the widget box. + wbox_width : str + The width of the widget box. + component_h : int + The height of the streamlit html component. + component_w : int + The width of the streamlit html component. + scroll : bool + If True, the streamlit component will scroll. + + Returns + ------- + spec_xyz : + The speckmol molecule. spec_xyz.keys() returns the keys of the + molecule. For example - spec_xyz.keys() returns ['atomScale', + 'bondScale', 'atomShade', 'bondThreshold', 'bondColor', 'atomColor', + 'outline', 'bonds', 'atomScale', 'atomColor', 'atomScale', 'atomScale] + These keys are useful for modifying the molecule. + + """ + spec_xyz = ipyspeck.speck.Speck(data=_xyz) + widg = widgets.Box([spec_xyz], layout=widgets.Layout(height=wbox_height,width=wbox_width)) + sc = embed.embed_snippet(widg) + html = embed.html_template.format(title="", snippet=sc) + components.html(html,height = component_h, width = component_w,scrolling=scroll) + return spec_xyz \ No newline at end of file diff --git a/st_speckmol/__init__.py b/st_speckmol/__init__.py new file mode 100644 index 0000000..b4db558 --- /dev/null +++ b/st_speckmol/__init__.py @@ -0,0 +1,48 @@ +import streamlit.components.v1 as components +import ipywidgets as widgets +from ipywidgets import embed +import ipyspeck + +def spec_plot(_xyz, wbox_height="700px", + wbox_width="800px", + component_h = 700, + component_w = 800, + scroll = False): + + """ Plots the speckmol molecule using the ipyspeck library and returns + the . + + Parameters + ---------- + _xyz : str + The xyz string of the molecule. + wbox_height : str + The height of the widget box. + wbox_width : str + The width of the widget box. + component_h : int + The height of the streamlit html component. + component_w : int + The width of the streamlit html component. + scroll : bool + If True, the streamlit component will scroll. + + Returns + ------- + spec_xyz : + The speckmol molecule. spec_xyz.keys() returns the keys of the + molecule. For example - spec_xyz.keys() returns ['atomScale', + 'bondScale', 'atomShade', 'bondThreshold', 'bondColor', 'atomColor', + 'outline', 'bonds', 'atomScale', 'atomColor', 'atomScale', 'atomScale] + These keys are useful for modifying the molecule. + + """ + # Read the xyz file + spec_xyz = ipyspeck.speck.Speck(data = _xyz) + # Create the widget box + widg = widgets.Box([spec_xyz], layout=widgets.Layout(height=wbox_height,width=wbox_width)) + # Embed the widget box in the streamlit html component + sc = embed.embed_snippet(widg) + html = embed.html_template.format(title="", snippet=sc) + components.html(html,height = component_h, width = component_w,scrolling=scroll) + return spec_xyz \ No newline at end of file