Skip to content

Commit

Permalink
final cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
pfebrer committed Sep 28, 2023
1 parent 2a713cb commit 7870e52
Show file tree
Hide file tree
Showing 33 changed files with 788 additions and 989 deletions.
2 changes: 1 addition & 1 deletion docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All methods and submodules are listed :ref:`here <genindex>` and
default_geom
physics
mixing
viz/index
unit_constant
utilities

Expand All @@ -38,5 +39,4 @@ All methods and submodules are listed :ref:`here <genindex>` and
:caption: Advanced usage

nodes
viz/index

33 changes: 29 additions & 4 deletions docs/api/viz/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,37 @@
Visualization
=============

.. currentmodule:: sisl.viz
.. module:: sisl.viz

Visualizations of `sisl` objects and data.
The visualization module contains tools to plot common visualizations, as well
as to create custom visualizations that support multiple plotting backends
automatically.

Plot classes
-----------------

Plot classes are workflow classes that implement some specific plotting.

.. autosummary::
:toctree: generated/

Plot
BandsPlot
FatbandsPlot
GeometryPlot
SitesPlot
GridPlot
WavefunctionPlot
PdosPlot

Utilities
---------

Utilities to build custom plots

.. autosummary::
:toctree: generated/
:recursive:
:toctree: generated/

get_figure
merge_plots
Figure
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
sisl\_toolbox.siesta.atom.AtomInput
===================================

.. currentmodule:: sisl_toolbox.siesta.atom

.. autoclass:: AtomInput



.. rubric:: Methods

.. autosummary::



~AtomInput.ae


~AtomInput.excite


~AtomInput.from_input


~AtomInput.from_yaml


~AtomInput.pg


~AtomInput.plot


~AtomInput.write_all_electron


~AtomInput.write_generation


~AtomInput.write_header


~AtomInput.write_test







Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
solve_poisson
=============================================

.. currentmodule:: sisl_toolbox.transiesta.poisson

.. autofunction:: solve_poisson
1 change: 1 addition & 0 deletions docs/visualization/viz_module/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The following notebooks will help you develop a deeper understanding of what eac
:name: viz-plotly-showcase-gallery

showcase/GeometryPlot.ipynb
showcase/SitesPlot.ipynb
showcase/GridPlot.ipynb
showcase/BandsPlot.ipynb
showcase/FatbandsPlot.ipynb
Expand Down
2 changes: 1 addition & 1 deletion docs/visualization/viz_module/showcase/FatbandsPlot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"metadata": {},
"outputs": [],
"source": [
"fatbands.split_groups(on=\"species\")"
"fatbands.split_orbs(on=\"species\", name=\"$species\")"
]
},
{
Expand Down
160 changes: 160 additions & 0 deletions docs/visualization/viz_module/showcase/SitesPlot.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"tags": [
"notebook-header"
]
},
"source": [
"[![GitHub issues by-label](https://img.shields.io/github/issues-raw/pfebrer/sisl/SitesPlot?style=for-the-badge)](https://github.com/pfebrer/sisl/labels/SitesPlot)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" \n",
" \n",
"SitesPlot\n",
"=========\n",
"\n",
"The `SitesPlot` is simply an adaptation of `GeometryPlot`'s machinery to any class that can be represented as sites in space. The main difference is that it doesn't show bonds, and also inputs with the word `atoms` are renamed to `sites`. Therefore, see `GeometryPlot`'s showcase notebook to understand the full customization possibilities.\n",
"\n",
"We are just going to show how you can plot the k points of a `BrillouinZone` object with it."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sisl\n",
"import sisl.viz\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's create a circle of K points:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"g = sisl.geom.graphene()\n",
"\n",
"# Create the circle\n",
"bz = sisl.BrillouinZone.param_circle(\n",
" g,\n",
" kR=0.0085,\n",
" origin= [0.0, 0.0, 0.0],\n",
" normal= [0.0, 0.0, 1.0],\n",
" N_or_dk=25,\n",
" loop=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And then generate some fake vectorial data for it:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data = np.zeros((len(bz), 3))\n",
"\n",
"data[:, 0] = - bz.k[:, 1]\n",
"data[:, 1] = bz.k[:, 0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And now plot the k points, showing the vectorial data as arrows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot k points as sites\n",
"bz.plot.sites(\n",
" axes=\"xy\", drawing_mode=\"line\", sites_style={\"color\": \"black\", \"size\": 2},\n",
" arrows={\"data\": data, \"color\": \"red\", \"width\": 3, \"name\": \"Force\"}\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"-----\n",
"This next cell is just to create the thumbnail for the notebook in the docs "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"nbsphinx-thumbnail"
]
},
"outputs": [],
"source": [
"thumbnail_plot = _\n",
"\n",
"if thumbnail_plot:\n",
" thumbnail_plot.show(\"png\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": [
"notebook-footer"
]
},
"source": [
"-------------"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
9 changes: 4 additions & 5 deletions src/sisl/nodes/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Node(NDArrayOperatorsMixin):
_prev_evaluated_inputs: Dict[str, Any]

# Current output value of the node
_output: Any
_output: Any = _blank

# Nodes that are connected to this node's inputs
_input_nodes: Dict[str, Node]
Expand Down Expand Up @@ -116,7 +116,7 @@ def __call__(self, *args, **kwargs):
def setup(self, *args, **kwargs):
"""Sets up the node based on its initial inputs."""
# Parse inputs into arguments.
bound_params = self.__class__.__signature__.bind_partial(*args, **kwargs)
bound_params = inspect.signature(self.function).bind_partial(*args, **kwargs)
bound_params.apply_defaults()

self._inputs = bound_params.arguments
Expand Down Expand Up @@ -192,7 +192,6 @@ def __init_subclass__(cls):
if parameter.kind == parameter.VAR_KEYWORD:
cls._kwargs_inputs_key = key

cls.__init__.__signature__ = init_sig
cls.__signature__ = no_self_sig

return super().__init_subclass__()
Expand Down Expand Up @@ -401,7 +400,7 @@ def get_tree(self):

@property
def default_inputs(self):
params = self.__class__.__signature__.bind_partial()
params = inspect.signature(self.function).bind_partial()
params.apply_defaults()
return params.arguments

Expand Down Expand Up @@ -486,7 +485,7 @@ def update_inputs(self, **inputs):
explicit_kwargs = inputs.pop(self._kwargs_inputs_key, None)

# Parse the inputs. We do this to separate the kwargs from the rest of the inputs.
bound = self.__class__.__signature__.bind_partial(**inputs)
bound = inspect.signature(self.function).bind_partial(**inputs)
inputs = bound.arguments

# Now that we have parsed the inputs, put back the args key (if any).
Expand Down
1 change: 1 addition & 0 deletions src/sisl/nodes/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ def function(*args, **kwargs):
)

def setup(self, *args, **kwargs):
self.nodes = self.dryrun_nodes
super().setup(*args, **kwargs)

self.nodes = self.dryrun_nodes.copy(inputs=self._inputs)
Expand Down
7 changes: 0 additions & 7 deletions src/sisl/viz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
Visualization utilities
=======================
Various visualization modules are described here.
Plotly
======
The plotly backend.
"""

import os
Expand Down
19 changes: 18 additions & 1 deletion src/sisl/viz/_plotables.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ def register_plotable(plotable, plot_cls=None, setting_key=None, plotting_func=N
# Register the function in the plot_handler
plot_handler.register(name, plot_dispatch, default=default, **kwargs)

def register_data_source(data_source_cls, plot_cls, setting_key, name=None, default: Sequence[Type] = [], plot_handler_attr='plot', **kwargs):
def register_data_source(
data_source_cls, plot_cls, setting_key, name=None, default: Sequence[Type] = [], plot_handler_attr='plot',
data_source_init_kwargs: dict = {},
**kwargs
):

plot_cls_params = {
name: param.replace(kind=inspect.Parameter.KEYWORD_ONLY)
Expand All @@ -195,6 +199,15 @@ def register_data_source(data_source_cls, plot_cls, setting_key, name=None, defa

signature = inspect.signature(func)

register_this = True
for k in data_source_init_kwargs.keys():
if k not in signature.parameters:
register_this = False
break

if not register_this:
continue

new_parameters = []
data_args = []
replaced_data_args = {}
Expand Down Expand Up @@ -241,6 +254,10 @@ def _plot(obj, *args, __params_info=params_info, __signature=signature, **kwargs
data_kwargs[data_key] = bound.arguments.pop(k)
except Exception as e:
raise TypeError(f"Error while parsing arguments to create the {data_source_cls.__name__}")

Check warning on line 256 in src/sisl/viz/_plotables.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/viz/_plotables.py#L254-L256

Added lines #L254 - L256 were not covered by tests

for k, v in data_source_init_kwargs.items():
if k not in data_kwargs:
data_kwargs[k] = v

Check warning on line 260 in src/sisl/viz/_plotables.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/viz/_plotables.py#L258-L260

Added lines #L258 - L260 were not covered by tests

data = data_source_cls.new(obj, *args, **data_kwargs)

Check warning on line 262 in src/sisl/viz/_plotables.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/viz/_plotables.py#L262

Added line #L262 was not covered by tests

Expand Down
Loading

0 comments on commit 7870e52

Please sign in to comment.