Giter Site home page Giter Site logo

chicolucio / ph-diagrams Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 2.0 3.29 MB

A Python package to plot fractional composition diagrams and pH-log c diagrams

Home Page: https://phdiagrams.herokuapp.com/

License: MIT License

Python 0.36% Jupyter Notebook 99.63% Procfile 0.01% Shell 0.01% CSS 0.01%
analytical-chemistry chemistry physical-chemistry python speciation streamlit streamlit-webapp

ph-diagrams's Introduction

Francisco Bustamante

Python

LICENSE

Contributions are welcome

Project generated with PyScaffold

Documentation Status

PyPI-Server

pH diagrams

A Python package to plot fractional composition diagrams and pH-log c diagrams

header animation

Interactive web app:

Streamlit app

Installation

pip install pH-diagrams

Usage

The class Acid must be imported from ph_diagrams. To create diagrams for the acetic acid:

>>> from ph_diagrams import Acid
>>> import matplotlib.pyplot as plt
>>> fig, axs = plt.subplots(nrows=1, ncols=2)
>>> acetic_acid = Acid(pKa=(4.76,), acid_concentration=0.1)
>>> acetic_acid.plot(plot_type='distribution', backend='matplotlib',
                     title='Acetic acid - Distribution diagram',
                     ax=axs[0], legend=False)
>>> acetic_acid.plot(plot_type='pC', backend='matplotlib',
                     title='Acetic acid - pH-log c diagram', ax=axs[1])
>>> plt.show()

As can be seen, the parameter pKa must be a tuple even if there is only one value. The above example generates the following plot, with both diagrams side by side:

acetic acid example

The plots above were made with Matplotlib, the default backend.

Changing the backend parameter to plotly, and removing the ax parameter (it works only with Matplotlib), will open a browser window for each plot. Since Plotly is interactive, the user can zoom, pan, and see values on hover.

Full documentation is hosted on Read the Docs.

A live interactive version of this project can be seen clicking in the following badge:

Streamlit app

The web app was made with Streamlit and hosted on Heroku.

A brief explanation on the chemical theory behind each diagram can be seen here.

Local Streamlit app and Jupyter notebooks

This repo has Jupyter Notebooks and scripts for a fully functional Streamlit app. First, create a virtual environment, clone the repo and install dependencies:

python -m venv .venv
source .venv/bin/activate
git clone [email protected]:chicolucio/pH-diagrams.git
cd pH-diagrams
pip install -r requirements.txt

This considers that you have Jupyter Notebook installed. If not, install it with pip install notebook.

For more basic usage examples, see the tutorial.ipynb notebook on notebooks folder. In the same folder, the tutorial_interactive_ipywidgets.ipynb file shows how to use ipywidgets to create interactive diagrams. Just run jupyter notebook on a terminal from the repo root folder and select the files.

A local version of the Streamlit app can be used running, from the repo root folder, streamlit run Home.py on a terminal. A browser window will open (if not, follow the instructions shown on the terminal output).

Contributing

All contributions are welcome.

Issues

Feel free to submit issues regarding:

  • recommendations
  • more examples for the tutorial
  • enhancement requests and new useful features
  • code bugs

Pull requests

  • before starting to work on your pull request, please submit an issue first
  • fork the repo
  • clone the project to your own machine
  • commit changes to your own branch
  • push your work back up to your fork
  • submit a pull request so that your changes can be reviewed

For full contribution guidelines and details check out our contributing guide.

Citing

If you use this project in a scientific publication or in classes, please consider citing as

F. L. S. Bustamante & H. B. Soares & N. O. Souza, pH diagrams, 2021. Available at: https://github.com/chicolucio/pH-diagrams

ph-diagrams's People

Contributors

chicolucio avatar helenabenevenuto avatar natashaosouza avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ph-diagrams's Issues

Resolver questão das fórmulas

  • O Matplotlib reconhece código LaTeX sem maiores problemas para as legendas
  • O Plotly possui diversos problemas de interação com LaTeX
    • necessidade de ter o MathJax local ou via CDN
    • não tem comportamento muito previsível em hover ou em labels (ver refs abaixo)

Possíveis soluções:

  • função usando LaTeX para uso com Matplotlib e função usando HTML para Plotly conforme #4
    • 👎 repetição de lógica/código
    • 👎 não lida bem com cargas
  • delegar criação das fórmulas para a classe Substance do chempy
    • 👍 pode usar os métodos latex_name e html_name
    • 👎 mais uma dependência...
    • 👍 lida com a questão da representação correta das cargas: - ao invés de -1; 2- ao invés de -2
    • 👎 não lida bem índices 0 e 1: H_0A^- ao invés de A^- e H_1A ao invés de HA
      • pode ser contornado da mesma forma que é contornado nas funções atuais
    • 👍 pode ser uma única função, com um argumento onde se diz qual tipo de retorno é desejado
from chempy import Substance
...

def formulas(output='latex'):
    ...
    if output == 'latex':
         ...
    if output == 'html':
         ...
    ...

Tendo, no momento, a considerar a solução com o chempy melhor.

Referências para problemas do Plotly com LaTeX:

[BUG] `streamlit-ph` does not work

Describe the bug

streamlit-ph script does not work.

To Reproduce
Steps to reproduce the behavior:

  1. install the package
  2. run streamlit-ph on terminal
  3. message: Error: Invalid value: File does not exist: Home.py

Expected behavior
Browser window opens with Streamlit app

Screenshots
NA

Specification

  • pH-diagrams version: 0.3.2
  • Python version: 3.10
  • platform: Linux (but will happen in all platforms)

Additional context
The file is not part of the package. Maybe the project should be restructured in a way that the Streamlit app becomes a module.

Gráficos interativos com Matplotlib

  • possibilidade de mudar valores de pKa e verificar atualizações dos gráficos em tempo real
    • sliders do ipywidget para cada pKa: de 0 a 14, com step 0.5
    • quantos sliders?
    • condições de contorno de cada de slider
      • pKa2 mínimo tem que ser igual ou maior que o pKa1

[BUG] Notebooks do not work on Google Colab

Describe the bug
Python version of Google Colab is too old (3.7) and the package requires >=3.8

To Reproduce
Steps to reproduce the behavior:

  1. open notebooks with Colab link
  2. uncomment the lines at the first as request
  3. Does not work (should add src before ph_diagrams)
  4. Try install the package with pip install pH-diagrams
  5. Does not work

Expected behavior
Just works...

Screenshots
NA

Specification

  • pH-diagrams: 0.3.2
  • Python version: 3.7
  • platform: Google Colab

Additional context

And that is how Google deals with it: googlecolab/colabtools#2165 I'm considering drop Colab links...

All notebooks work in a local environment with Python >= 3.8.

Deepnote can be an alternative. But it has issues with ipywidgets:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.