Code Monkey home page Code Monkey logo

hsd-python's Introduction

HSD โ€” Make your structured data human friendly

Utilities to read and write files in the Human-friendly Structured Data (HSD) format.

The HSD-format is very similar to both JSON and YAML, but tries to minimize the effort for humans to read and write it. It ommits special characters as much as possible (in contrast to JSON) and is not indentation dependent (in contrast to YAML). It was developed originally as the input format for the scientific simulation tool (DFTB+), but is of general purpose. Data stored in HSD can be easily mapped to a subset of JSON or XML and vica versa.

Detailed documentation can be found on Read the Docs.

Installation

The package can be installed via conda-forge:

conda install --channel "conda-forge" hsd-python

Alternatively, the package can be downloaded and installed via pip into the active Python interpreter (preferably using a virtual python environment) by

pip install hsd

or into the user space issueing

pip install --user hsd

Quick tutorial

A typical, self-explaining input written in HSD looks like

driver {
  conjugate_gradients {
    moved_atoms = 1 2 "7:19"
    max_steps = 100
  }
}

hamiltonian {
  dftb {
    scc = yes
    scc_tolerance = 1e-10
    mixer {
      broyden {}
    }
    filling {
      fermi {
        # This is comment which will be ignored
        # Note the attribute (unit) of the field below
        temperature [kelvin] = 100
      }
    }
    k_points_and_weights {
      supercell_folding {
        2   0   0
        0   2   0
        0   0   2
        0.5 0.5 0.5
      }
    }
  }
}

The above input can be parsed into a Python dictionary with:

import hsd
hsdinput = hsd.load("test.hsd")

The dictionary hsdinput will then look as:

{
    "driver": {
        "conjugate_gradients" {
            "moved_atoms": [1, 2, "7:19"],
            "max_steps": 100
        }
    },
    "hamiltonian": {
        "dftb": {
            "scc": True,
            "scc_tolerance": 1e-10,
            "mixer": {
                "broyden": {}
            },
            "filling": {
                "fermi": {
                    "temperature": 100,
                    "temperature.attrib": "kelvin"
                }
            }
            "k_points_and_weights": {
                "supercell_folding": [
                    [2, 0, 0],
                    [0, 2, 0],
                    [0, 0, 2],
                    [0.5, 0.5, 0.5]
                ]
            }
        }
    }
}

Being a simple Python dictionary, it can be easily queried and manipulated in Python

hsdinput["driver"]["conjugate_gradients"]["max_steps"] = 200

and then stored again in HSD format

hsd.dump(hsdinput, "test2.hsd")

License

The hsd-python package is licensed under the BSD 2-clause license.

hsd-python's People

Contributors

aradi avatar awvwgk avatar bhourahine avatar jubich avatar vanderhe avatar

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.