Ejemplo n.º 1
0
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)
Ejemplo n.º 2
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
    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])