-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from avrabyt/component-develop
🚀 Specklit - Component - st_speckmol
- Loading branch information
Showing
11 changed files
with
173 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# production | ||
|
||
dist | ||
# misc | ||
.DS_Store | ||
|
||
*.egg-info | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |