Skip to content

Commit ffcabcf

Browse files
authored
Add template for Sphinx based documentation (#13)
* Add template for Sphinx based documentation. * Add comments to Dockerfile * Remove install_engine.sh * Update pyproject.toml * Update README.md
1 parent e696aa2 commit ffcabcf

12 files changed

Lines changed: 226 additions & 50 deletions

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# This is a template Dockerfile in case you want to offer your users the
2+
# possibility to run your wrapper using Docker (for example, this may be handy
3+
# when the installation of a required simulation engine is complicated)
4+
15
FROM python:3.10
26
LABEL org.opencontainers.image.authors="you@domain.org"
37

@@ -14,5 +18,6 @@ RUN echo "Install the engine here"
1418
# Install your package. Dependencies, including `simphony-osp` will be
1519
# automatically installed.
1620
RUN pip install .
17-
# Maybe you also need to install an ontology
21+
# Maybe you also need to install a specific ontology that your wrapper makes
22+
# use of (like `package_name/ontology.yml` for this prototype wrapper example).
1823
RUN pico install some_ontology_maybe.yml

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ SimPhoNy. **Before you start**, please have a look at the
66
(in particular the
77
[wrapper development section](https://simphony.readthedocs.io/en/v4.0.0rc4/developers/wrappers.html)).
88

9-
You may clone this repository and use it as a template to create your own
10-
wrapper. It provides project configuration files, a folder structure and even a
11-
minimalistic implementation of a wrapper.
9+
Clone this repository to use it as a template to create your own
10+
wrapper. It provides project configuration files, a folder structure, an
11+
example of a minimalistic implementation of a wrapper, tests, and a documentation
12+
template. While writing the documentation, you can show it on your web browser
13+
using [sphinx-autobuild](https://github.com/executablebooks/sphinx-autobuild).
1214

1315
The version number of this project matches the number of the
1416
[`simphony-osp`](https://pypi.org/project/simphony-osp/4.0.0rc4/) package
@@ -17,7 +19,8 @@ version for which it was last updated. As SimPhoNy follows the
1719
prototype should be compatible with the newest version of SimPhoNy as long as
1820
their major version numbers match.
1921

20-
**Do not forget to choose a license and change the file `LICENSE.md` before
21-
publishing your wrapper!**
22+
**Do not forget to choose a license and change the license information in the
23+
files `LICENSE.md`, `pyproject.toml` and `docs/conf.py` before publishing your
24+
wrapper!**
2225

2326
*Contact*: [Material Informatics team at Fraunhofer IWM](mailto:simphony@iwm.fraunhofer.de)

docs/conf.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""Configuration file for the Sphinx documentation builder."""
2+
3+
# --- Project information --- #
4+
5+
project = "MyWrapperName"
6+
copyright = "2022, Materials Informatics team at Fraunhofer IWM"
7+
author = "Materials Informatics team at Fraunhofer IWM"
8+
9+
10+
# --- General configuration --- #
11+
12+
extensions = [
13+
"myst_parser", # Markdown support
14+
"sphinx.ext.autodoc", # API reference
15+
"sphinx.ext.napoleon", # Google and NumPy style docstrings support
16+
"sphinx.ext.viewcode", # Link to source in API reference
17+
"sphinx_copybutton", # Copy button for code blocks
18+
"nbsphinx", # Jupyter notebook support
19+
"IPython.sphinxext.ipython_console_highlighting", # Syntax highlighting
20+
"sphinx.ext.autosectionlabel", # Auto-generate section labels.
21+
"sphinx_panels", # Show panels in a grid layout or as drop-downs
22+
]
23+
24+
master_doc = "index"
25+
26+
myst_heading_anchors = 5
27+
28+
suppress_warnings = ["autosectionlabel.*"]
29+
exclude_patterns = ["**.ipynb_checkpoints"]
30+
nbsphinx_allow_errors = False
31+
32+
33+
# --- HTML output options --- #
34+
html_theme = "sphinx_book_theme"
35+
html_favicon = "static/favicon.png" # Noto Sans open book emoji
36+
html_logo = "static/logo.png"
37+
html_theme_options = {
38+
"github_url": "https://github.com/my_organization/my_wrapper",
39+
"repository_url": "https://github.com/my_organization/my_wrapper",
40+
"use_repository_button": True,
41+
"repository_branch": "main",
42+
"path_to_docs": "docs",
43+
"logo_only": True,
44+
"show_navbar_depth": 1,
45+
}
46+
47+
48+
html_static_path = ["static"]
49+
html_css_files = ["custom.css"]

docs/index.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# MyWrapperName
2+
3+
```{note}
4+
⚠️ This is a template for the documentation of your wrapper. Modify it to suit
5+
your needs.
6+
```
7+
8+
MyWrapperName is a SimPhoNy wrapper that enables the use of MySimualtionEngine
9+
on the SimPhoNy Open Simulation Platform.
10+
11+
MySimulationEngine is a sample molecular dynamics simulation engine. Given a
12+
collection of atoms, their initial positions, and their velocities, it can
13+
calculate their future positions, under the assumption that atoms do not exert
14+
any kind of force among themselves neither there are any external forces acting
15+
on them.
16+
17+
```{toctree}
18+
:hidden: true
19+
:maxdepth: 2
20+
21+
installation
22+
usage
23+
License <https://example.org/my_license_file_can_be_githubs_one>
24+
```

docs/installation.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Installation
2+
3+
This wrapper requires a working installation of MySimulationEngine. Follow
4+
these steps or check [this documentation to install](https://example.org)
5+
MySimulationEngine.
6+
7+
The next step is to install the wrapper itself. MyWrapperName is available on
8+
PyPI, so it can be installed using the `pip` package manager.
9+
10+
```shell
11+
pip install package-name
12+
```
13+
14+
Finally, the wrapper requires MyOntology to operate. Download the
15+
[ontology file](https://example.org/ontology_file.ttl) and
16+
[ontology package](https://example.org/ontology_package.yml), then install the
17+
latter using the command below.
18+
19+
```shell
20+
pico install ontology.yml
21+
```
22+
23+
## Advanced users
24+
25+
If you are a developer or an advanced user, you might be interested in
26+
installing MyWrapperName from source.
27+
28+
```shell
29+
git clone https://github.com/my_organization/my_wrapper
30+
pip install ./my_wrapper
31+
```

docs/static/custom.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.caption-text,
2+
h1,
3+
h2,
4+
h3,
5+
h4 {
6+
color: #6580a1 !important;
7+
}
8+
9+
.btn-outline-primary {
10+
border-color: #6580a1 !important;
11+
}
12+
13+
.btn-outline-primary:hover {
14+
background-color: #6580a1 !important;
15+
color: azure !important;
16+
}
17+
18+
@media (min-width: 1200px) {
19+
.container-xl {
20+
max-width: 1550px;
21+
}
22+
#site-navigation {
23+
max-width: 20%;
24+
}
25+
}

docs/static/favicon.png

11.2 KB
Loading

docs/static/graph_pattern.drawio.svg

Lines changed: 4 additions & 0 deletions
Loading

docs/static/logo.png

1.96 KB
Loading

docs/usage.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Usage
2+
3+
Given a collection of atoms, their initial positions, and their velocities,
4+
MyWrapperName uses MySimulationEngine to calculate their future positions,
5+
under the assumption that atoms do not exert any kind of force among themselves
6+
neither there are any external forces acting on them.
7+
8+
To use MyWrapperName, start by importing it from the `simphony_osp.wrappers`
9+
module, as well as by importing the `ontology_namespace` namespace.
10+
11+
```python
12+
from simphony_osp.namespaces import ontology_namespace
13+
from simphony_osp.wrappers import SimulationWrapper
14+
```
15+
16+
The next step is to call `SimulationWrapper` to create a SimPhoNy session
17+
18+
```python
19+
session = SimulationWrapper()
20+
session.locked = True # prevent session from closing after with statement
21+
```
22+
23+
and populate it with your input data.
24+
25+
```python
26+
with session:
27+
for i in range(3):
28+
atom = ontology_namespace.Atom()
29+
atom[ontology_namespace.hasPart] = {
30+
ontology_namespace.Position(value=[i, i, i], unit="m"),
31+
ontology_namespace.Velocity(value=[i, -i, i], unit="m/s"),
32+
}
33+
```
34+
35+
MyWrapperName uses individuals belonging to classes from MyOntology to
36+
represent atoms, their positions and velocities. MyWrapperName expects to find
37+
the following pattern in the session's knowledge graph.
38+
39+
<figure style="display: table; text-align:center; margin-left: auto; margin-right:auto">
40+
41+
![Sample linked data](./static/graph_pattern.drawio.svg)
42+
43+
<figcaption style="display: table-caption; caption-side: bottom; text-align:center">
44+
45+
_Pattern that MyWrapperName interprets in the session's knowledge graph in
46+
order to recognize the atoms, their positions and their velocities._
47+
48+
</figcaption>
49+
50+
</figure>
51+
52+
Finally, use SimPhoNy's `compute` command to run the simulation, optionally
53+
specifying the number of time steps to consider in seconds (defaults to `1`).
54+
Negative values can be provided in order to run the simulation backwards in
55+
time.
56+
57+
```python
58+
session.compute()
59+
# session.compute(time_steps=5)
60+
```
61+
62+
After running the simulation, all the same atom, position and velocity ontology
63+
individuals will still be available in the session, but their positions will
64+
have changed. As there are no forces acting on the atoms, their velocities
65+
will remain constant.
66+

0 commit comments

Comments
 (0)