sphinx-parser

sphinx_parser - Your pyiron-like module.


Keywords
pyiron
License
Other
Install
pip install sphinx-parser==0.0.1

Documentation

Sphinx

Overview

This hosts the python binder of the DFT code Sphinx.

How to use

Stinx's input parser is created from the yaml-file located at src/input_data.yml. The input file is generated by src/generator.py. You can use the parser via:

from sphinx_parser.input import sphinx

This instance sphinx is used to create all possible input classes for Sphinx by choosing the class via dot-notation and call create. For example in order to generate the class kPoints, you can run:

kPoints = sphinx.basis.kPoints.create()

You can find the input in the parent class, i.e.:

basis = sphinx.basis.create(kPoints=kPoints)

Finally, you can translate it into the Sphinx format via:

from sphinx_parser.toolkit import to_sphinx

sphinx_input = to_sphinx(basis)

You can then write it to a file via:

with open('sphinx.in', 'w') as f:
    f.write(sphinx_input)

Minimum working example

import numpy as np
from ase.build import bulk
import os


cwd = "TEST"
# cwd.mkdir(exist_ok=True)
if not os.path.exists(cwd):
    os.mkdir(cwd)

from sphinx_parser.input import sphinx
from sphinx_parser.ase import get_structure_group
from sphinx_parser.toolkit import to_sphinx
from sphinx_parser.potential import get_paw_from_structure
from sphinx_parser.jobs import calc_static


structure = bulk("Al", cubic=True)
structure[1].symbol = "Ni"

input_sx = calc_static(structure)

with open(os.path.join(cwd, "input.sx"), "w") as f:
    f.write(to_sphinx(input_sx))

import subprocess

command = ["sphinx"]

process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, cwd=cwd)
stdout, stderr = process.communicate()

collect_energy_dat(os.path.join(cwd, "energy.dat"))

More detailed example:

import numpy as np
from ase.build import bulk
import os


cwd = "TEST"
# cwd.mkdir(exist_ok=True)
if not os.path.exists(cwd):
    os.mkdir(cwd)

from sphinx_parser.input import sphinx
from sphinx_parser.ase import get_structure_group
from sphinx_parser.toolkit import to_sphinx
from sphinx_parser.potential import get_paw_from_structure


structure = bulk("Al", cubic=True)
structure[1].symbol = "Ni"

struct_group = get_structure_group(structure)
main_group = sphinx.main.create(scfDiag=sphinx.main.scfDiag.create(maxSteps=10, blockCCG={}))
pawPot_group = get_paw_from_structure(structure)
basis_group = sphinx.basis.create(eCut=25, kPoint=sphinx.basis.kPoint.create(coords=3 * [0.5]))
paw_group = sphinx.PAWHamiltonian.create(xc=1, spinPolarized=False, ekt=0.2)
initial_guess_group = sphinx.initialGuess.create(
    waves=sphinx.initialGuess.waves.create(lcao=sphinx.initialGuess.waves.lcao.create()), rho=sphinx.initialGuess.rho.create(atomicOrbitals=True)
)

input_sx = sphinx.create(
    pawPot=pawPot_group, structure=struct_group, main=main_group, basis=basis_group, PAWHamiltonian=paw_group, initialGuess=initial_guess_group
)

with open(os.path.join(cwd, "input.sx"), "w") as f:
    f.write(to_sphinx(input_sx))

import subprocess

command = ["sphinx"]

process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, cwd=cwd)
stdout, stderr = process.communicate()

collect_energy_dat(os.path.join(cwd, "energy.dat"))