Skip to main content

A fast parser of XML files output by VASP DFT code written in Cython.

Project description

https://travis-ci.org/tilde-lab/quantum_esperanto.svg?branch=master https://badge.fury.io/py/quantum_esperanto.svg

Quantum Esperanto is a fast parser of XML files output by DFT codes (vasp as of now) written in Cython. It takes advantage of lxml, a Python wrapper around libxml2 library, and its Cython interface. XML files are parsed to a Python dictionary in a transparent way. It is really fast, up to 10 times faster than the parser used by pymatgen project.

Installation

The development versions of libraries libxml2 and libxslt must be present in the system. Check with the command:

$ xslt-config

Also, C compiler such as gcc must be present. The recommended way of installing Quantum Esperanto is with pip from PyPI:

$ pip install quantum_esperanto

If one is interested in obtaining latest versions of the package, it can be installed using the source code from GitHub:

$ git clone https://github.com/tilde-lab/quantum_esperanto
$ cd quantum_esperanto
$ pip install .

The Python prerequisites for the package are numpy and lxml (should be installed automatically with pip).

It is possible to install the package in development mode. This will install Cython as well as nose test suite. To do it issue the following command after cloning the repository and changing the directory:

$ cd quantum_esperanto
$ pip install -e .[dev]

After install it is possible to run several tests to check if the installation was completed successfully. It can be done with the following commands in quantum_esperanto directory:

$ python setup.py test

If everything is OK, you’re all set to start using the package.

Usage

The parser can be used in a very simple way. First, the parser has to be instantiated, and then the parse_file method of the parser returns the dictionary of parsed values:

from quantum_esperanto.vasp import VaspParser
parser = VaspParser()
d = parser.parse_file('vasprun.xml')

The possible arguments for the parser are:

recover

(boolean, default: True) a flag that allows recovering broken XML. It is very useful in case of unfinished calculations; however, it exits on the first XML error and the returned dictionary contains parsed values up to the first XML error only. When XML recovery is needed, a warning is printed to stderr.

whitelist

(list, default: None) the list of parent tag names that are only needed to parsed. If None, then all tags are parsed.

Parsing result

The result of parsing is a dictionary that follows the structure of vasprun.xml. The keys of the dictionary are either tag names (for i, v, varray tags), or tag:tag name construction (for tags that do have name attribute), or just tags themselves. The values are either tag contents converted to the right type (specified by type tag attribute) or (in case of varrays and sets) Numpy arrays. Fortran overflows (denoted by *****) are converted to NaNs in case of float values and to MAXINT in case of integer values.

Example:

xml file

<structure name="primitive_cell" >
 <crystal>
  <varray name="basis" >
   <v>       1.43300000       1.43300000       1.43300000 </v>
   <v>       1.43300000      -1.43300000      -1.43300000 </v>
   <v>      -1.43300000       1.43300000      -1.43300000 </v>
  </varray>
  <i name="volume">     11.77059895 </i>
  <varray name="rec_basis" >
   <v>       0.34891835       0.34891835       0.00000000 </v>
   <v>       0.34891835      -0.00000000      -0.34891835 </v>
   <v>      -0.00000000       0.34891835      -0.34891835 </v>
  </varray>
 </crystal>
 <varray name="positions" >
  <v>       0.00000000       0.00000000       0.00000000 </v>
 </varray>
</structure>

resulting dictionary (printed with pprint):

{'structure:primitive_cell': {'crystal': {'basis': array([[ 1.433,  1.433,  1.433],
                                                          [ 1.433, -1.433, -1.433],
                                                          [-1.433,  1.433, -1.433]]),
                                          'rec_basis': array([[ 0.34891835,  0.34891835,  0.        ],
                                                              [ 0.34891835, -0.        , -0.34891835],
                                                              [-0.        ,  0.34891835, -0.34891835]]),
                                          'volume': 11.77059895},
                              'positions': array([[ 0.,  0.,  0.]])}}

License

Quantum Esperanto is licensed under MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quantum_esperanto-0.3.tar.gz (150.1 kB view details)

Uploaded Source

File details

Details for the file quantum_esperanto-0.3.tar.gz.

File metadata

  • Download URL: quantum_esperanto-0.3.tar.gz
  • Upload date:
  • Size: 150.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.8

File hashes

Hashes for quantum_esperanto-0.3.tar.gz
Algorithm Hash digest
SHA256 7c789f46785eb66bc4c6462f40d82b72221f3fcc07ed07e82c9b18184d09a4de
MD5 59348d707de2dfe887599e3bf7c39d83
BLAKE2b-256 590634ad225c305f0eaa7f62e13cc00881895c8d0ffffd97b8c6ffe632637b8b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page