Esempio n. 1
0
def test_write_parser(fresh_aiida_env, tmpdir, incar_dict_example):
    """Test writing an INCAR from a dict, read and compare."""

    # create AiiDA dictionary instance
    incar_params = get_data_class('dict')(dict=incar_dict_example)
    assert isinstance(incar_params, get_data_class('dict'))
    parser = IncarParser(data=incar_params)

    # now write
    temp_file = str(tmpdir.join('INCAR'))
    parser.write(temp_file)
    # read again
    parser_reparse = IncarParser(file_path=temp_file)
    result = parser_reparse.incar
    # compare
    comp_dict = {'encut': 350, 'sigma': 0.05, 'lreal': False, 'prec': 'Accurate'}
    assert str(sorted(result)) == str(sorted(comp_dict))

    # Test validation
    with_invalid = dict(incar_dict_example)
    with_invalid.update(foo='bar')
    incar_params = get_data_class('dict')(dict=with_invalid)
    parser = IncarParser(data=incar_params)
    with pytest.raises(InputValidationError):
        parser.write(temp_file)
Esempio n. 2
0
    def write_incar(self, dst):  # pylint: disable=unused-argument
        """
        Write the INCAR.

        Passes the parameters node (Dict) from to the INCAR parser for
        preparation and writes to dst.

        :param dst: absolute path of the file to write to
        """
        incar_parser = IncarParser(data=self.inputs.parameters)
        incar_parser.write(dst)