From eb0b0b77a67b8a7928b0b0ea1ef6d4ef02a7e419 Mon Sep 17 00:00:00 2001 From: AvratanuBiswas Date: Mon, 23 May 2022 15:45:00 +0200 Subject: [PATCH 1/8] :heavy_plus_sign: added init file and tested #1 --- speckmol/__pycache__/funx.cpython-310.pyc | Bin 0 -> 759 bytes speckmol/__pycache__/funx.cpython-38.pyc | Bin 0 -> 1766 bytes speckmol/funx.py | 45 ++++++++++++++++++++ st_speckmol/__init__.py | 48 ++++++++++++++++++++++ test.py | 12 ++++++ 5 files changed, 105 insertions(+) create mode 100644 speckmol/__pycache__/funx.cpython-310.pyc create mode 100644 speckmol/__pycache__/funx.cpython-38.pyc create mode 100644 speckmol/funx.py create mode 100644 st_speckmol/__init__.py create mode 100644 test.py diff --git a/speckmol/__pycache__/funx.cpython-310.pyc b/speckmol/__pycache__/funx.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1d814c3d06caa8712a34c290001b294792f9a491 GIT binary patch literal 759 zcmYjP!H&}~5Vf5+Nz-jAxY(?!wiUMe86Z^c0U(n=M#liz*d{|lXN&h;ZGcVu(UQn;z(CFl_>_J`L)Kl3enwGY74yX1{jeBFq*{(Tw0D?z6? J!6R=ce*ixn!ioR@ literal 0 HcmV?d00001 diff --git a/speckmol/__pycache__/funx.cpython-38.pyc b/speckmol/__pycache__/funx.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4adb44e3dbb873abf046e92a63533682c946d20d GIT binary patch literal 1766 zcmaJ?&2Hm15GG|wmX)MiB2YeuN1uXVh+%=;mk&#K6+HHZS4*gs&o>N70Zn)B3J!ywm$Lr0H+zgtS95bubmM3uR~ftFhCswlEEvuFp3vIs{(sYbCDS`H@P5fXw9Kj$E$mg_DH-LNKcg%0x%|0ik8mTGjgGp{9&E%mPxxR zS!EDZ#|{Zeec+2a&HjIrB>&$fwn@{Qlin`xGU&@;x5|dzvVVm)~+&i8$4WPU!Sg7+W7uD0dcpU8r3&Gno)Wp0l5T+9{Mb1B%? z@JtG+oZ{db<$o}_G$Je7XuX}dx4<66p2sUcv~X}#y4gKd?k4itQji(!H^nqmNTN)iki_2UdoZ*5M0QS-yj_5XtpfY!*T;B;Yz%O4(VF5J_Lb2cniOeQ~WkQ z#_D6x2a$p{id5)?`+6uh_iT{ZciI~|Y>DgP^<(ueOt8WAW1GU^Hs`30U8p-h^}q=S i?K$s=kHBV=Qz!sv&QCFD+C?4X1RvtWeWdE&zyAS{CkICW literal 0 HcmV?d00001 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 diff --git a/test.py b/test.py new file mode 100644 index 0000000..e0eff0d --- /dev/null +++ b/test.py @@ -0,0 +1,12 @@ +import streamlit as st +import glob +from speckmol.funx 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) \ No newline at end of file From 4833385b670b8821cbb5d64a31c48241e0beb28a Mon Sep 17 00:00:00 2001 From: Avra <96898985+avrabyt@users.noreply.github.com> Date: Mon, 23 May 2022 15:49:08 +0200 Subject: [PATCH 2/8] license added #1 --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE 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. From 8edeaaab44a4fe0a374d6861fcb46e69ea470d5b Mon Sep 17 00:00:00 2001 From: Avra <96898985+avrabyt@users.noreply.github.com> Date: Mon, 23 May 2022 15:58:47 +0200 Subject: [PATCH 3/8] adding setup.py #1 --- setup.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c084d33 --- /dev/null +++ b/setup.py @@ -0,0 +1,17 @@ +import setuptools + +setuptools.setup( + name="st_speckmol", + version="0.0.1", + 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.0",ipywidgets==7.7.0], +) From 922e8d66b2ab62505a35573536b45e1d0e77fff9 Mon Sep 17 00:00:00 2001 From: Avra <96898985+avrabyt@users.noreply.github.com> Date: Mon, 23 May 2022 16:01:10 +0200 Subject: [PATCH 4/8] Create MANIFEST.in --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ + From 7e11e19b9a6c7cd1139d70d0767a7d0a53266797 Mon Sep 17 00:00:00 2001 From: AvratanuBiswas Date: Mon, 23 May 2022 16:40:24 +0200 Subject: [PATCH 5/8] :hammer: component test released #1 :rocket:: --- .gitignore | 8 ++++++++ setup.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .gitignore 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/setup.py b/setup.py index c084d33..49fcc9c 100644 --- a/setup.py +++ b/setup.py @@ -13,5 +13,5 @@ include_package_data=True, classifiers=[], python_requires=">=3.6", - install_requires=["streamlit >= 0.63", "ipyspeck==0.6.0",ipywidgets==7.7.0], + install_requires=["streamlit >= 0.63", "ipyspeck==0.6.0", "ipywidgets==7.7.0"], ) From 0e60c22cbc376c0983d68fd93931183c534b603a Mon Sep 17 00:00:00 2001 From: Avratanu Biswas Date: Mon, 23 May 2022 21:10:35 +0200 Subject: [PATCH 6/8] :sparkles:compoenent ready-to-deploy #1 --- test.py => app-main.py | 4 +-- app.py | 64 ------------------------------------------ setup.py | 4 +-- 3 files changed, 4 insertions(+), 68 deletions(-) rename test.py => app-main.py (78%) delete mode 100644 app.py diff --git a/test.py b/app-main.py similarity index 78% rename from test.py rename to app-main.py index e0eff0d..d5c5ed1 100644 --- a/test.py +++ b/app-main.py @@ -1,6 +1,6 @@ import streamlit as st import glob -from speckmol.funx import spec_plot +from st_speckmol import spec_plot # Example files path ex_files = glob.glob("examples/*.xyz") @@ -9,4 +9,4 @@ f = open(example_xyz,"r") example_xyz = f.read() -res = spec_plot(example_xyz) \ No newline at end of file +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 index 49fcc9c..4aa2f52 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setuptools.setup( name="st_speckmol", - version="0.0.1", + version="0.0.3", author="Avratanu Biswas", author_email="avrab.yt@gmail.com", description="Streamlit component for for Speck molecule visualization.", @@ -13,5 +13,5 @@ include_package_data=True, classifiers=[], python_requires=">=3.6", - install_requires=["streamlit >= 0.63", "ipyspeck==0.6.0", "ipywidgets==7.7.0"], + install_requires=["streamlit >= 0.63", "ipyspeck==0.6.1", "ipywidgets==7.6.3"], ) From fb82a485271434af4469599727e94c8f444bb087 Mon Sep 17 00:00:00 2001 From: Avratanu Biswas Date: Mon, 23 May 2022 21:23:07 +0200 Subject: [PATCH 7/8] :sparkles:readme updated with example #1 --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index d443d6f..da53f2f 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,28 @@ Speck figures to Streamlit Web App ![Speclit demo](https://github.com/avrabyt/Specklit/blob/main/SpeckLit_demo.gif) +## 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) + +``` + + # References [Speck Online](http://wwwtyro.github.io/speck/) From 8da7ffbc4c21e17a393278bad3afc3fac819baaf Mon Sep 17 00:00:00 2001 From: Avratanu Biswas Date: Mon, 23 May 2022 21:24:22 +0200 Subject: [PATCH 8/8] :sparkles:readme updated #1 --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index da53f2f..78a893b 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ # Specklit Speck figures to Streamlit Web App -[![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) ## Installation `pip install st-speckmol==0.0.3` @@ -25,7 +22,9 @@ with st.sidebar: 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) # References