Skip to content

Commit

Permalink
Merge pull request #2 from avrabyt/component-develop
Browse files Browse the repository at this point in the history
🚀 Specklit - Component - st_speckmol
  • Loading branch information
avrabyt authored May 23, 2022
2 parents 6e6ec9c + 8da7ffb commit 7d1b4ef
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 64 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# production

dist
# misc
.DS_Store

*.egg-info
__pycache__
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 12 additions & 0 deletions app-main.py
Original file line number Diff line number Diff line change
@@ -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)
64 changes: 0 additions & 64 deletions app.py

This file was deleted.

17 changes: 17 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import setuptools

setuptools.setup(
name="st_speckmol",
version="0.0.3",
author="Avratanu Biswas",
author_email="[email protected]",
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"],
)
Binary file added speckmol/__pycache__/funx.cpython-310.pyc
Binary file not shown.
Binary file added speckmol/__pycache__/funx.cpython-38.pyc
Binary file not shown.
45 changes: 45 additions & 0 deletions speckmol/funx.py
Original file line number Diff line number Diff line change
@@ -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 <class 'ipyspeck.speck.Speck'>.
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 : <class 'ipyspeck.speck.Speck'>
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
48 changes: 48 additions & 0 deletions st_speckmol/__init__.py
Original file line number Diff line number Diff line change
@@ -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 <class 'ipyspeck.speck.Speck'>.
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 : <class 'ipyspeck.speck.Speck'>
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

0 comments on commit 7d1b4ef

Please sign in to comment.