def _init_outcar(self, path): """Init with a filepath.""" self._parsed_data = {} self._parsable_items = self.__class__.PARSABLE_ITEMS self._data_obj = SingleFile(path=path) # Since OUTCAR can be fairly large, we will parse it only # once and store the parsevasp Outcar object. try: self._outcar = Outcar(file_path=path, logger=self._logger) except SystemExit: self._logger.warning('Parsevasp exited abruptly. Returning None.') self._outcar = None
def outcar_parser(request, tmpdir_factory): """Load OUTCAR file. """ testdir = os.path.dirname(__file__) outcarfile = testdir + '/OUTCAR' tmpfile = str(tmpdir_factory.mktemp('data').join('OUTCAR')) outcar_truncate(request.param, outcarfile, tmpfile) outcar = Outcar(file_path=tmpfile) return outcar
def outcar_parser(request): """A fixture that loads OUTCAR.""" try: name = request.param except AttributeError: # Test not parametrized name = 'OUTCAR' testdir = os.path.dirname(__file__) outcarfile = testdir + '/' + name outcar = Outcar(file_path=outcarfile) return outcar
def outcar_parser_file_objects(request, tmpdir_factory): """Load OUTCAR file from a file object. """ testdir = os.path.dirname(__file__) outcarfile = testdir + '/OUTCAR' tmpfile = str(tmpdir_factory.mktemp('data').join('OUTCAR')) outcar_truncate(request.param, outcarfile, tmpfile) outcar = None with open(tmpfile) as file_handler: outcar = Outcar(file_handler=file_handler) return outcar
def outcar_parser_file_objects(request): """A fixture that loads OUTCAR using file object.""" try: name = request.param except AttributeError: # Test not parametrized name = 'OUTCAR' testdir = os.path.dirname(__file__) outcarfile = testdir + '/' + name outcar = None with open(outcarfile) as file_handler: outcar = Outcar(file_handler=file_handler) return outcar
def test_crashed_outcar(outcar_parser): """Test incomplete OUTCAR""" testdir = os.path.dirname(__file__) outcarfile = os.path.join(testdir, 'OUTCAR.crashed') with pytest.raises(SystemExit): outcar = Outcar(file_path=outcarfile)
class OutcarParser(BaseFileParser): """ Interface to parsevasp's OUTCAR parser. The quantities listed here are not yet ejected in the xml file: - symmetries - elastic moduli And we can thus not fully rely on the xml parser. No possibilities to write OUTCAR files have been implemented. """ PARSABLE_ITEMS = { 'elastic_moduli': { 'inputs': [], 'name': 'elastic_moduli', 'prerequisites': [] }, 'symmetries': { 'inputs': [], 'name': 'symmetries', 'prerequisites': [] }, 'symmetries_extended': { 'inputs': [], 'name': 'symmetries', 'prerequisites': [] }, 'magnetization': { 'inputs': [], 'name': 'magnetization', 'prerequisites': [] }, 'site_magnetization': { 'inputs': [], 'name': 'site_magnetization', 'prerequisites': [] }, 'run_stats': { 'inputs': [], 'name': 'run_stats', 'prerequisites': [], } } def __init__(self, *args, **kwargs): """ Initialize OUTCAR parser file_path : str File path. data : SingleFileData AiiDA Data class install to store a single file. settings : ParserSettings """ super(OutcarParser, self).__init__(*args, **kwargs) self._outcar = None self._settings = kwargs.get('settings', None) if 'file_path' in kwargs: self._init_outcar(kwargs['file_path']) if 'data' in kwargs: self._init_outcar(kwargs['data'].get_file_abs_path()) def _init_outcar(self, path): """Init with a filepath.""" self._parsed_data = {} self._parsable_items = self.__class__.PARSABLE_ITEMS self._data_obj = SingleFile(path=path) # Since OUTCAR can be fairly large, we will parse it only # once and store the parsevasp Outcar object. try: self._outcar = Outcar(file_path=path, logger=self._logger) except SystemExit: self._logger.warning('Parsevasp exited abruptly. Returning None.') self._outcar = None def _parse_file(self, inputs): # Since all quantities will be returned by properties, we can't pass # inputs as a parameter, so we store them in self._parsed_data for key, value in inputs.items(): self._parsed_data[key] = value quantities_to_parse = DEFAULT_OPTIONS.get('quantities_to_parse') if self._settings is not None and self._settings.quantity_names_to_parse: quantities_to_parse = self._settings.quantity_names_to_parse result = {} if self._outcar is None: # parsevasp threw an exception, which means OUTCAR could not be parsed. for quantity in quantities_to_parse: if quantity in self.parsable_items: result[quantity] = None return result for quantity in quantities_to_parse: if quantity in self.parsable_items: result[quantity] = getattr(self, quantity) return result @property def run_stats(self): """Fetch the run statistics""" return self._outcar.get_run_stats() @property def symmetries(self): """Fetch the symmetries, but only the point group (if it exists).""" extended = self.symmetries_extended sym = { 'point_group': extended['point_group'], 'primitive_translations': extended['primitive_translations'], 'num_space_group_operations': extended['num_space_group_operations'] } return sym @property def symmetries_extended(self): """Fetch the symmetries, including operations etc.""" sym = self._outcar.get_symmetry() # We do not want to store the site symmetry at origin sym = {key: value for key, value in sym.items() if key != 'site_symmetry_at_origin'} return sym @property def elastic_moduli(self): """Fetch the elastic moduli.""" return self._outcar.get_elastic_moduli() @property def magnetization(self): """Fetch the full cell magnetization.""" return self._outcar.get_magnetization()['full_cell'] @property def site_magnetization(self): """Fetch the site dependent magnetization.""" return self._outcar.get_magnetization()