-
Notifications
You must be signed in to change notification settings - Fork 75
/
structure.py
33 lines (25 loc) · 1.04 KB
/
structure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
"""Command line utilities to create and inspect `StructureData` nodes."""
import click
from aiida.cmdline.params import options
from aiida.cmdline.utils import decorators, echo
from . import cmd_data
@cmd_data.group('structure')
def cmd_structure():
"""Commands to create and inspect `StructureData` nodes."""
@cmd_structure.command('import')
@click.argument('filename', type=click.File('r'))
@options.DRY_RUN()
@decorators.with_dbenv()
def cmd_import(filename, dry_run):
"""Import a `StructureData` from a Quantum ESPRESSO input file."""
from aiida_quantumespresso.tools.pwinputparser import PwInputFile
with open(filename, 'r') as input_file:
parser = PwInputFile(input_file.read())
structure = parser.get_structuredata()
formula = structure.get_formula()
if dry_run:
echo.echo_success('parsed structure with formula {}'.format(formula))
else:
structure.store()
echo.echo_success('parsed and stored StructureData<{}> with formula {}'.format(structure.pk, formula))