Skip to content

Commit 04aba38

Browse files
committed
Merge branch 'cleanup'
2 parents 6824721 + 9e07ea4 commit 04aba38

28 files changed

+908
-2284
lines changed

.appveyor.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
on: [push, pull_request]
3+
4+
jobs:
5+
test-new:
6+
7+
steps:
8+
- name: Checkout code
9+
uses: actions/checkout@v2
10+
11+
- uses: actions/setup-python@v1
12+
with:
13+
python-version: '3.x'
14+
15+
- name: Install requirements (PIP)
16+
run: pip3 install pytest sphinx
17+
18+
- name: Run test pytest
19+
run: python3 -m pytest
20+
21+
- name: Run doctest
22+
run: cd docs; make doctest

CHANGELOG.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
==========
2+
Change Log
3+
==========
4+
5+
6+
Unreleased
7+
==========
8+
9+
Added
10+
-----
11+
12+
* Basic functionality to manipulate HSD-data in Python.
13+
14+
* Pip installation

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2011-2020 DFTB+ developers group
1+
Copyright (c) 2011-2021 DFTB+ developers group
22

33
All rights reserved.
44

README.rst

Lines changed: 83 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
1-
************************************
2-
HSD — Human-friendly Structured Data
3-
************************************
1+
**********************************************
2+
HSD — Make your structured data human friendly
3+
**********************************************
44

5-
This Python package contains utilities to read and write files in
6-
the Human-friendly Structured Data (HSD) format.
5+
This package contains utilities to read and write files in the Human-friendly
6+
Structured Data (HSD) format.
77

8-
It is licensed under the *BSD 2-clause license*.
8+
The HSD-format is very similar to both JSON and YAML, but tries to minimize the
9+
effort for **humans** to read and write it. It ommits special characters as much
10+
as possible (in contrast to JSON) and is not indentation dependent (in contrast
11+
to YAML). It was developed originally as the input format for the scientific
12+
simulation tool (`DFTB+ <https://github.com/dftbplus/dftbplus>`_), but is
13+
of general purpose. Data stored in HSD can be easily mapped to a subset of JSON
14+
or XML and vica versa.
15+
16+
Detailed `documentation <https://hsd-python.readthedocs.io/>`_ can be found on
17+
`Read the Docs <https://hsd-python.readthedocs.io/>`_.
918

1019

1120
Installation
1221
============
1322

14-
To install the python package in development mode use
23+
The package can be installed via conda-forge::
1524

16-
.. code::
25+
conda install hsd-python
1726

18-
pip install -e src
27+
Alternatively, the package can be downloaded and installed via pip into the
28+
active Python interpreter (preferably using a virtual python environment) by ::
1929

30+
pip install hsd
31+
32+
or into the user space issueing ::
33+
34+
pip install --user hsd
2035

21-
The HSD format
22-
==============
2336

24-
The HSD-format is very similar to both JSON and XML, but tries to minimize the
25-
effort for humans to read and write it. It ommits special characters as much as
26-
possible but (in contrast to YAML for example) is not indentation dependent.
37+
Quick tutorial
38+
==============
2739

28-
It was developed originally as the input format for a scientific simulation tool
29-
(`DFTB+ <https://github.com/dftbplus/dftbplus>`_), but is absolutely general. A
30-
typical input written in HSD looks like ::
40+
A typical, self-explaining input written in HSD looks like ::
3141

3242
driver {
3343
conjugate_gradients {
@@ -45,11 +55,13 @@ typical input written in HSD looks like ::
4555
}
4656
filling {
4757
fermi {
48-
temperature [kelvin] = 1e-8
58+
# This is comment which will be ignored
59+
# Note the attribute (unit) of the field below
60+
temperature [kelvin] = 100
4961
}
5062
}
5163
k_points_and_weights {
52-
supercell_folding = {
64+
supercell_folding {
5365
2 0 0
5466
0 2 0
5567
0 0 2
@@ -59,13 +71,56 @@ typical input written in HSD looks like ::
5971
}
6072
}
6173

62-
Content in HSD format can be represented as JSON. Content in JSON format can
63-
similarly be represented as HSD, provided it satisfies one restriction for
64-
arrays: Either all elements of an array must be objects or none of them. (This
65-
allows for a clear separation of structure and data and allows for the very
66-
simple input format.)
74+
The above input can be parsed into a Python dictionary with::
75+
76+
import hsd
77+
hsdinput = hsd.load("test.hsd")
78+
79+
The dictionary ``hsdinput`` will then look as::
80+
81+
{
82+
"driver": {
83+
"conjugate_gradients" {
84+
"moved_atoms": [1, 2, "7:19"],
85+
"max_steps": 100
86+
}
87+
},
88+
"hamiltonian": {
89+
"dftb": {
90+
"scc": True,
91+
"scc_tolerance": 1e-10,
92+
"mixer": {
93+
"broyden": {}
94+
},
95+
"filling": {
96+
"fermi": {
97+
"temperature": 100,
98+
"temperature.attrib": "kelvin"
99+
}
100+
}
101+
"k_points_and_weights": {
102+
"supercell_folding": [
103+
[2, 0, 0],
104+
[0, 2, 0],
105+
[0, 0, 2],
106+
[0.5, 0.5, 0.5]
107+
]
108+
}
109+
}
110+
}
111+
}
112+
113+
Being a simple Python dictionary, it can be easily queried and manipulated in
114+
Python ::
115+
116+
hsdinput["driver"]["conjugate_gradients"]["max_steps"] = 200
117+
118+
and then stored again in HSD format ::
119+
120+
hsd.dump(hsdinput, "test2.hsd")
121+
122+
123+
License
124+
========
67125

68-
Content in HSD format can be represented as XML (DOM-tree). Likewise content in
69-
XML can be converted to HSD, provided it satisfies the restriction that every
70-
child has either data (text) or further children, but never both of
71-
them. (Again, this ensures the simplicity of the input format.)
126+
The hsd-python package is licensed under the `BSD 2-clause license <LICENSE>`_.

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/api.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
*****************
2+
API documentation
3+
*****************
4+
5+
.. testsetup::
6+
7+
import hsd
8+
9+
10+
High level routines
11+
===================
12+
13+
.. autofunction:: hsd.load_string
14+
15+
.. autofunction:: hsd.load
16+
17+
.. autofunction:: hsd.dump_string
18+
19+
.. autofunction:: hsd.dump
20+
21+
22+
23+
Lower level building blocks
24+
===========================
25+
26+
.. autoclass:: hsd.HsdParser
27+
:members:
28+
29+
.. autoclass:: hsd.HsdEventHandler
30+
:members:
31+
32+
.. autoclass:: hsd.HsdDictBuilder
33+
:members:

docs/conf.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
import os
14+
import sys
15+
sys.path.insert(0, os.path.abspath('../src'))
16+
17+
# -- Project information -----------------------------------------------------
18+
19+
project = 'hsd-python'
20+
copyright = '2021, DFTB+ developers group'
21+
author = 'DFTB+ developers group'
22+
23+
# The full version, including alpha/beta/rc tags
24+
release = '0.1'
25+
26+
27+
# -- General configuration ---------------------------------------------------
28+
29+
# Add any Sphinx extension module names here, as strings. They can be
30+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
31+
# ones.
32+
extensions = [
33+
'sphinx.ext.autodoc',
34+
'sphinx.ext.doctest',
35+
'sphinx.ext.napoleon'
36+
]
37+
38+
autodoc_member_order = 'bysource'
39+
40+
# Add any paths that contain templates here, relative to this directory.
41+
templates_path = ['_templates']
42+
43+
# List of patterns, relative to source directory, that match files and
44+
# directories to ignore when looking for source files.
45+
# This pattern also affects html_static_path and html_extra_path.
46+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
47+
48+
49+
# -- Options for HTML output -------------------------------------------------
50+
51+
# The theme to use for HTML and HTML Help pages. See the documentation for
52+
# a list of builtin themes.
53+
#
54+
# html_theme = 'alabaster'
55+
html_theme = 'sphinx_rtd_theme'
56+
57+
# Add any paths that contain custom static files (such as style sheets) here,
58+
# relative to this directory. They are copied after the builtin static files,
59+
# so a file named "default.css" will overwrite the builtin "default.css".
60+
html_static_path = ['_static']

docs/index.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.. hsd-python documentation master file, created by
2+
sphinx-quickstart on Mon Sep 13 11:38:29 2021.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
########################
7+
HSD-python documentation
8+
########################
9+
10+
.. toctree::
11+
:maxdepth: 2
12+
13+
introduction
14+
api

0 commit comments

Comments
 (0)