Beispiel #1
0
def test_relax_parameters_no_algo(init_relax_parameters,
                                  init_simple_workchain):
    """Test no provided algo tag."""
    mock_workchain = init_simple_workchain
    del init_relax_parameters.relax.algo
    massager = ParametersMassage(mock_workchain, init_relax_parameters)
    assert massager.exit_code is not None
Beispiel #2
0
def test_relax_parameters_pos_shape(init_relax_parameters):
    """Test position and shape relxation combinations."""
    del init_relax_parameters.relax.volume
    massager = ParametersMassage(None, init_relax_parameters)
    assert massager.exit_code is None
    parameters = massager.parameters
    assert parameters.isif == 4
Beispiel #3
0
def test_relax_parameters_energy(init_relax_parameters):
    """Test no provided force cutoff. It should be set to a default value."""
    del init_relax_parameters.relax.force_cutoff
    massager = ParametersMassage(None, init_relax_parameters)
    assert massager.exit_code is None
    parameters = massager.parameters
    assert parameters.ediffg == 0.01
Beispiel #4
0
def test_vasp_parameter_override(init_relax_parameters):
    """Test of the override functionality works as intended."""
    init_relax_parameters.vasp = AttributeDict()
    # Redefine to from 3 to 0.
    init_relax_parameters.vasp.isif = 0
    massager = ParametersMassage(None, init_relax_parameters)
    assert massager.exit_code is None
    assert massager.parameters.isif == 0
Beispiel #5
0
def test_relax_parameters_override(init_relax_parameters):
    """Test what happens if we override a parameters."""
    value = 1
    init_relax_parameters.isif = value
    massager = ParametersMassage(None, init_relax_parameters)
    assert massager.exit_code is None
    parameters = massager.parameters
    assert parameters.isif == value
Beispiel #6
0
def test_relax_parameters_shape(init_relax_parameters):
    """Test only shape relaxation."""
    del init_relax_parameters.relax.volume
    del init_relax_parameters.relax.positions
    massager = ParametersMassage(None, init_relax_parameters)
    assert massager.exit_code is None
    parameters = massager.parameters
    assert parameters.isif == 5
Beispiel #7
0
def test_relax_parameters_all_set(init_relax_parameters):
    """Test all standard relaxation parameters are set."""
    massager = ParametersMassage(None, init_relax_parameters)
    assert massager.exit_code is None
    parameters = massager.parameters
    assert parameters.ediffg == -0.01
    assert parameters.ibrion == 2
    assert parameters.nsw == 60
    assert parameters.isif == 3
Beispiel #8
0
def test_relax_parameters_nothing(init_relax_parameters):
    """Test if no relaxation parameters for volume, positions and shape are given."""
    del init_relax_parameters.relax.volume
    del init_relax_parameters.relax.positions
    del init_relax_parameters.relax.shape
    massager = ParametersMassage(None, init_relax_parameters)
    assert massager.exit_code is None
    parameters = massager.parameters
    assert parameters == AttributeDict()
Beispiel #9
0
def test_charge_parameters():
    """Test charge parameters."""
    parameters = AttributeDict()
    parameters.charge = AttributeDict()
    parameters.charge.from_wave = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    parameters.charge.from_wave = False
    parameters.charge.from_charge = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.icharg == 1
    parameters.charge.from_charge = False
    parameters.charge.from_atomic = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.icharg == 2
    parameters.charge.from_atomic = False
    parameters.charge.from_potential = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.icharg == 4
    parameters.charge.from_potential = False
    parameters.charge.constant_charge = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.icharg == 11
    parameters.charge.constant_charge = False
    parameters.charge.constant_atomic = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.icharg == 12
Beispiel #10
0
def test_smearing_parameters():
    """Test smearing parameters."""
    parameters = AttributeDict()
    parameters.smearing = AttributeDict()
    parameters.smearing.gaussian = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.ismear == 0
    parameters.smearing.gaussian = False
    parameters.smearing.fermi = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.ismear == -1
    parameters.smearing.fermi = False
    parameters.smearing.tetra = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.ismear == -5
    parameters.smearing.tetra = False
    parameters.smearing.mp = 4
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.ismear == 4
Beispiel #11
0
    def init_inputs(self):
        """Make sure all the required inputs are there and valid, create input dictionary for calculation."""
        self.ctx.inputs = AttributeDict()

        # Set the code
        self.ctx.inputs.code = self.inputs.code

        # Set the structure (poscar)
        self.ctx.inputs.structure = self.inputs.structure

        # Set the kpoints (kpoints)
        self.ctx.inputs.kpoints = self.inputs.kpoints

        # Perform inputs massage to accommodate generalization in higher lying workchains
        # and set parameters
        parameters_massager = ParametersMassage(self, self.inputs.parameters)
        # Check exit codes from the parameter massager and set it if it exists
        if parameters_massager.exit_code is not None:
            return parameters_massager.exit_code
        self.ctx.inputs.parameters = parameters_massager.parameters

        # Set settings
        if 'settings' in self.inputs:
            self.ctx.inputs.settings = self.inputs.settings

        # Set options
        # Options is very special, not storable and should be
        # wrapped in the metadata dictionary, which is also not storable
        # and should contain an entry for options
        if 'options' in self.inputs:
            options = {}
            options.update(self.inputs.options)
            self.ctx.inputs.metadata = {}
            self.ctx.inputs.metadata['options'] = options
            # Override the parser name if it is supplied by the user.
            parser_name = self.ctx.inputs.metadata['options'].get(
                'parser_name')
            if parser_name:
                self.ctx.inputs.metadata['options'][
                    'parser_name'] = parser_name
            # Set MPI to True, unless the user specifies otherwise
            withmpi = self.ctx.inputs.metadata['options'].get('withmpi', True)
            self.ctx.inputs.metadata['options']['withmpi'] = withmpi

        # Verify and set potentials (potcar)
        if not self.inputs.potential_family.value:
            self.report(
                'An empty string for the potential family name was detected.')  # pylint: disable=not-callable
            return self.exit_codes.ERROR_NO_POTENTIAL_FAMILY_NAME  # pylint: disable=no-member
        try:
            self.ctx.inputs.potential = get_data_class(
                'vasp.potcar').get_potcars_from_structure(
                    structure=self.inputs.structure,
                    family_name=self.inputs.potential_family.value,
                    mapping=self.inputs.potential_mapping.get_dict())
        except ValueError as err:
            return compose_exit_code(
                self.exit_codes.ERROR_POTENTIAL_VALUE_ERROR.status, str(err))  # pylint: disable=no-member
        except NotExistent as err:
            return compose_exit_code(
                self.exit_codes.ERROR_POTENTIAL_DO_NOT_EXIST.status, str(err))  # pylint: disable=no-member

        try:
            self._verbose = self.inputs.verbose.value
        except AttributeError:
            pass
        # Set the charge density (chgcar)
        if 'chgcar' in self.inputs:
            self.ctx.inputs.charge_density = self.inputs.chgcar

        # Set the wave functions (wavecar)
        if 'wavecar' in self.inputs:
            self.ctx.inputs.wavefunctions = self.inputs.wavecar

        return self.exit_codes.NO_ERROR  # pylint: disable=no-member
Beispiel #12
0
def test_catch_invalid_tags(init_relax_parameters, init_simple_workchain):
    init_relax_parameters.vasp = AttributeDict()
    mock_workchain = init_simple_workchain
    init_relax_parameters.vasp.smear = 1  # This is an invalid tag
    massager = ParametersMassage(mock_workchain, init_relax_parameters)
    assert massager.exit_code is not None
Beispiel #13
0
def test_orbital_projections():  # pylint: disable=too-many-statements
    """Test the parameters associated with orbital projections."""
    parameters = AttributeDict()
    parameters.bands = AttributeDict()
    parameters.bands.decompose_wave = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.lorbit == 5
    parameters.bands.decompose_wave = False
    parameters.bands.decompose_bands = True
    parameters.bands.decompose_auto = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.lorbit == 14
    parameters.bands.decompose_auto = False
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.lorbit == 10
    parameters.bands.lm = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.lorbit == 11
    parameters.bands.phase = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.lorbit == 12
    parameters.bands.lm = False
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.lorbit == 12

    # Now do the once with a Wigner-Seitz radius supplied
    parameters.bands.wigner_seitz_radius = [2.0]
    parameters.bands.lm = False
    parameters.bands.phase = False
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.lorbit == 0
    print(massager.parameters.rwigs)
    assert int(massager.parameters.rwigs[0]) == 2
    parameters.bands.lm = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.lorbit == 1
    parameters.bands.phase = True
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.lorbit == 2
    parameters.bands.lm = False
    massager = ParametersMassage(None, parameters)
    assert massager.exit_code is None
    assert massager.parameters.lorbit == 2

    # Should raise ValueError if Wigner-Seitz radius is not defined as a list.
    parameters.bands.wigner_seitz_radius = 2.0
    with pytest.raises(ValueError):
        massager = ParametersMassage(None, parameters)