def test_incar_parser_invalid_tag(): """Test passing a tag that is not recognized. """ test_string = '''SOMEINVALIDTAG = .TRUE.''' with pytest.raises(SystemExit): parsed = Incar(incar_string=test_string)
def test_incar_parser_write(incar_parser, tmp_path): """Check the write functions for both file paths and file objects. """ incar = incar_parser.get_dict() # Write the content incar_write_path = tmp_path / 'INCAR' incar_parser.write(file_path=incar_write_path) # Then reload and compare incar_reloaded = Incar(file_path=incar_write_path).get_dict() assert incar == incar_reloaded # Write again with file object with open(incar_write_path, 'w') as handler: incar_parser.write(file_handler=handler) # Then reload again and compare with open(incar_write_path, 'r') as handler: incar_reloaded = Incar(file_handler=handler).get_dict() assert incar == incar_reloaded
def test_incar_parser_invalid_tag(): """Test passing a tag that is not recognized and its override. """ test_string = '''SOMEINVALIDTAG = .TRUE.''' parsed = Incar(incar_string=test_string, validate_tags=False) incar_dict = parsed.get_dict() assert list(incar_dict.keys())[0] == 'someinvalidtag'
def incar_parser(request, tmpdir_factory): """Load INCAR file. """ testdir = os.path.dirname(__file__) incarfile = testdir + '/INCAR' tmpfile = str(tmpdir_factory.mktemp('data').join('INCAR')) incar_truncate(request.param, incarfile, tmpfile) incar = Incar(file_path=tmpfile) return incar
def test_incar_parser_from_string(): """Test passing a string. """ test_str = 'LOPTICS = .True.\nAddgrid=.false.' incar_io = Incar(incar_string=test_str) incar_dict = incar_io.get_dict() assert incar_dict.pop('loptics') is True assert incar_dict.pop('addgrid') is False assert not incar_dict
def test_from_string(): """Test passing a string. """ test_str = 'TRUE = .True.\nFalse=.false.' incar_io = Incar(incar_string=test_str) incar_dict = incar_io.get_dict() assert incar_dict.pop('true') is True assert incar_dict.pop('false') is False assert not incar_dict
def test_incar_from_dict(incar_dict): """Test passing a dictionary. """ incar_io = Incar(incar_dict=incar_dict) comp_dict = { 'encut': 350, 'sigma': 0.05, 'lreal': False, 'prec': 'Accurate' } assert str(sorted(incar_io.get_dict())) == str(sorted(comp_dict))
def incar_parser_file_object(request, tmpdir_factory): """Load INCAR file using a file object. """ testdir = os.path.dirname(__file__) incarfile = testdir + '/INCAR' tmpfile = str(tmpdir_factory.mktemp('data').join('INCAR')) incar_truncate(request.param, incarfile, tmpfile) incar = None with open(tmpfile) as file_handler: incar = Incar(file_handler=file_handler) return incar
def _parsed_object(self): """ Return an instance of parsevasp.incar.Incar. Corresponds to the stored data in inputs.parameters. """ incar_dict = self._data_obj.get_dict() try: return Incar(incar_dict=incar_dict, logger=self._logger) except SystemExit as error: raise InputValidationError(error.args[0])
def _parse_file(self, inputs): """Create a DB Node from an INCAR file.""" result = inputs result = {} if isinstance(self._data_obj, get_data_class('dict')): return {'incar': self._data_obj} try: incar = Incar(file_path=self._data_obj.path, logger=self._logger) except SystemExit: self._logger.warning('Parsevasp exitited abnormally. Returning None.') return {'incar': None} result['incar'] = incar.get_dict() return result
def test_incar_parser_from_string_complexr(): """Test passing a more complex string. """ test_string = '''LOPTICS = .True. EVENONLY = .False. # this is a comment; FLOAT\t=\t1.45e-03 ISMEAR = THIS ; SIGMA = THAT NBANDS = 45 # endline comment; may contain '#' and ';' NOPARAM = this is not a parameter DIPOL = 1 2 -33 5 ''' parsed = Incar(incar_string=test_string) incar_dict = parsed.get_dict() assert incar_dict['loptics'] is True assert incar_dict['evenonly'] is False assert incar_dict['ismear'] == 'THIS' assert incar_dict['sigma'] == 'THAT' assert incar_dict['dipol'] == [1, 2, -33, 5] assert incar_dict['nbands'] == 45 assert 'noparam' not in incar_dict assert 'float' not in incar_dict
def test_parser(): """Test passing a more complex string. """ test_string = '''TRUE = .True. FALSE=.False. # this is a comment; FLOAT\t=\t1.45e-03 SOMEOTHERTHING = THIS ; ANDTHAT = .TRUE. INT = 45 # endline comment; may contain '#' and ';' NOPARAM = this is not a parameter LIST = 1 2 -33 5 ''' parsed = Incar(incar_string=test_string) incar_dict = parsed.get_dict() assert incar_dict['true'] is True assert incar_dict['false'] is False assert incar_dict['someotherthing'] == 'THIS' assert incar_dict['andthat'] is True assert incar_dict['list'] == [1, 2, -33, 5] assert incar_dict['int'] == 45 assert 'noparam' not in incar_dict assert 'float' not in incar_dict