Skip to content

Commit

Permalink
Merge 3906257 into 1b77cd7
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallsen committed Aug 29, 2018
2 parents 1b77cd7 + 3906257 commit 495922c
Show file tree
Hide file tree
Showing 30 changed files with 688 additions and 597 deletions.
15 changes: 6 additions & 9 deletions aiida_vasp/calcs/immigrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
from aiida_vasp.utils.aiida_utils import get_data_node


def get_quantity_node(parser, quantity):
return parser.get_quantity(quantity, None)[quantity]


class VaspImmigrantJobProcess(JobProcess):
"""
JobProcess subclass for importing non-aiida VASP runs.
Expand Down Expand Up @@ -72,11 +68,12 @@ def return_empty_list():


def get_incar_input(dir_path):
return get_quantity_node(IncarParser(file_path=dir_path.join('INCAR').strpath), 'incar')
incar = IncarParser(file_path=dir_path.join('INCAR').strpath).incar
return get_data_node('parameter', dict=incar)


def get_poscar_input(dir_path):
return get_quantity_node(PoscarParser(file_path=dir_path.join('POSCAR').strpath), 'poscar-structure')
return PoscarParser(file_path=dir_path.join('POSCAR').strpath).structure


def get_potcar_input(dir_path, structure=None, potcar_spec=None):
Expand All @@ -97,14 +94,14 @@ def get_potcar_input(dir_path, structure=None, potcar_spec=None):

def get_kpoints_input(dir_path, structure=None):
structure = structure or get_poscar_input(dir_path)
kpoints = get_quantity_node(KpParser(file_path=dir_path.join('KPOINTS').strpath), 'kpoints-kpoints')
kpoints = KpParser(file_path=dir_path.join('KPOINTS').strpath).kpoints
kpoints.set_cell_from_structure(structure)
return kpoints


def get_chgcar_input(dir_path):
return get_quantity_node(ChgcarParser(file_path=dir_path.join('CHGCAR').strpath), 'chgcar')
return ChgcarParser(file_path=dir_path.join('CHGCAR').strpath).chgcar


def get_wavecar_input(dir_path):
return get_quantity_node(WavecarParser(file_path=dir_path.join('WAVECAR').strpath), 'wavecar')
return WavecarParser(file_path=dir_path.join('WAVECAR').strpath).wavecar
5 changes: 2 additions & 3 deletions aiida_vasp/calcs/tests/test_vasp2w90.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ def test_write_poscar(fresh_aiida_env, vasp2w90_calc_and_ref, vasp_structure_pos
inp = vasp_calc.get_inputs_dict()
with tempfile.NamedTemporaryFile() as temp_file:
vasp_calc.write_poscar(inp, temp_file.name)
result_structure = PoscarParser(file_path=temp_file.name).get_quantity('poscar-structure', {})['poscar-structure']
ref_structure = vasp_structure_poscar.get_quantity('poscar-structure', {})['poscar-structure']
result_structure = PoscarParser(file_path=temp_file.name).structure
ref_structure = vasp_structure_poscar.structure
assert result_structure.cell, ref_structure.cell
assert result_structure.get_formula() == ref_structure.get_formula()

vasp_structure_poscar._parsed_data.update(vasp_structure_poscar.get_quantity('poscar-structure', {})) # pylint: disable=protected-access
ref_string = vasp_structure_poscar._parsed_object.get_string() # pylint: disable=protected-access
with open(temp_file.name, 'r') as poscar:
assert_contents_equivalent(poscar.read(), ref_string)
Expand Down
2 changes: 1 addition & 1 deletion aiida_vasp/commands/mock_vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def mock_vasp():
assert PoscarParser(file_path=poscar.strpath), 'POSCAR could not be parsed.'
assert KpParser(file_path=kpoints.strpath), 'KPOINTS could not be parsed.'

system = incar_parser.get_quantity('incar', {})['incar'].get_dict().get('system', '')
system = incar_parser.incar.get('system', '')
test_case = re.findall(r'test-case:(.*)$', system)

if not test_case:
Expand Down
15 changes: 11 additions & 4 deletions aiida_vasp/io/chgcar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tools for parsing CHGCAR files."""

from aiida_vasp.utils.aiida_utils import get_data_class
from aiida_vasp.io.parser import BaseFileParser
from aiida_vasp.parsers.node_composer import NodeComposer


class ChgcarParser(BaseFileParser):
Expand All @@ -10,13 +10,14 @@ class ChgcarParser(BaseFileParser):
PARSABLE_ITEMS = {
'chgcar': {
'inputs': [],
'nodeName': 'chgcar',
'name': 'chgcar',
'prerequisites': []
},
}

def __init__(self, *args, **kwargs):
super(ChgcarParser, self).__init__(*args, **kwargs)
self._chgcar = None
self.init_with_kwargs(**kwargs)

def _parse_file(self, inputs):
Expand All @@ -28,7 +29,13 @@ def _parse_file(self, inputs):
if chgcar is None:
return {'chgcar': None}

result['chgcar'] = get_data_class('vasp.chargedensity')()
result['chgcar'].set_file(chgcar)
result['chgcar'] = chgcar

return result

@property
def chgcar(self):
if self._chgcar is None:
composer = NodeComposer(file_parsers=[self])
self._chgcar = composer.compose('vasp.chargedensity')
return self._chgcar
21 changes: 13 additions & 8 deletions aiida_vasp/io/doscar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""DOSCAR (VASP format) utilities"""
import numpy as np

from aiida_vasp.utils.aiida_utils import get_data_class
from aiida_vasp.parsers.node_composer import NodeComposer
from aiida_vasp.io.parser import BaseFileParser

# Map from number of columns in DOSCAR to dtype.
Expand All @@ -28,14 +28,14 @@ class DosParser(BaseFileParser):
PARSABLE_ITEMS = {
'doscar-dos': {
'inputs': [],
'nodeName': 'dos',
'name': 'dos',
'prerequisites': [],
'alternatives': ['dos']
},
}

def __init__(self, *args, **kwargs):
super(DosParser, self).__init__(*args, **kwargs)
self._dos = None
self.init_with_kwargs(**kwargs)

def _parse_file(self, inputs):
Expand All @@ -46,17 +46,15 @@ def _parse_file(self, inputs):

header, pdos, tdos = self._read_doscar()

result['doscar-dos'] = {}
result['header'] = header

for array in [pdos, tdos]:
if array.size == 0:
return {'doscar-dos': None}

dosnode = get_data_class('array')()
dosnode.set_array('pdos', pdos)
dosnode.set_array('tdos', tdos)

result['doscar-dos'] = dosnode
result['doscar-dos']['pdos'] = pdos
result['doscar-dos']['tdos'] = tdos

return result

Expand Down Expand Up @@ -122,3 +120,10 @@ def _read_doscar(self):
header['weight'] = weight

return header, pdos, tdos

@property
def dos(self):
if self._dos is None:
composer = NodeComposer(file_parsers=[self])
self._dos = composer.compose('array', quantities=['doscar-dos'])
return self._dos
43 changes: 11 additions & 32 deletions aiida_vasp/io/eigenval.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@

import numpy as np

from aiida_vasp.utils.aiida_utils import get_data_class
from aiida_vasp.io.parser import BaseFileParser


class EigParser(BaseFileParser):
"""Contains regex and functions to find grammar elements in EIGENVALUE files."""

PARSABLE_ITEMS = {
'eigenval-bands': {
'inputs': ['structure', 'kpoints', 'occupations'],
'nodeName': 'bands',
'prerequisites': ['structure', 'occupations'],
'alternatives': ['bands']
'eigenval-eigenvalues': {
'inputs': [],
'name': 'eigenvalues',
'prerequisites': [],
},
'eigenval-kpoints': {
'inputs': ['structure'],
'name': 'kpoints',
'prerequisites': ['structure'],
},
}

Expand All @@ -35,33 +38,9 @@ def _parse_file(self, inputs):
result = {}

header, kpoints, bands = self._read_eigenval()

result['header'] = header

bsnode = get_data_class('array.bands')()
kpout = get_data_class('array.kpoints')()

structure = inputs.get('structure')
if structure is None:
return {'eigenval-bands': None, 'kpoints': None}

bsnode.set_cell(structure.get_ase().get_cell())
kpout.set_cell(structure.get_ase().get_cell())

kpoints_inp = inputs.get('kpoints')
if kpoints_inp:
bsnode.set_kpointsdata(kpoints_inp)

if kpoints_inp.labels:
bsnode.labels = kpoints_inp.labels
else:
bsnode.set_kpoints(kpoints[:, :3], weights=kpoints[:, 3], cartesian=False)

bsnode.set_bands(bands, occupations=inputs['occupations'])
kpout.set_kpoints(kpoints[:, :3], weights=kpoints[:, 3], cartesian=False)

result['eigenval-bands'] = bsnode
result['eigenval-kpoints'] = kpout
result['eigenval-eigenvalues'] = bands
result['eigenval-kpoints'] = kpoints

return result

Expand Down
28 changes: 6 additions & 22 deletions aiida_vasp/io/incar.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ class IncarParser(BaseFileParser):
PARSABLE_ITEMS = {
'incar': {
'inputs': [],
'parsers': ['INCAR'],
'nodeName': '',
'name': 'incar',
'prerequisites': []
},
}
Expand All @@ -381,7 +380,7 @@ def __init__(self, *args, **kwargs):
def _init_with_data(self, data):
"""Initialise with a given kpointsData object."""
self._data_obj = data
self._parsable_items = self.__class__.PARSABLE_ITEMS
self.parsable_items = self.__class__.PARSABLE_ITEMS
self._parsed_data = {}

@property
Expand Down Expand Up @@ -415,24 +414,9 @@ def _parse_file(self, inputs):
self._logger.warning("Parsevasp exitited abnormally. " "Returning None.")
return {'incar': None}

result = parsevasp_to_aiida(incar)

result['incar'] = incar.get_dict()
return result


def parsevasp_to_aiida(incar):
"""
Parsevasp to Aiida conversion.
Generate an Aiida ParameterData that contains the
entries found in INCAR using parsevasp.
"""

incar_dict = incar.get_dict()

result = {}

result['incar'] = get_data_class('parameter')(dict=incar_dict)

return result
@property
def incar(self):
return self.get_quantity('incar', {})['incar']

0 comments on commit 495922c

Please sign in to comment.