Example #1
0
def create_input(chemical_symbol: str, exchange_correlation_code: str,
                 calculation_code: str, maximum_iterations: int, filename: str,
                 quiet: bool):
    """
    Create the input file for the run-atomic command.


    Requires:

        CHEMICAL_SYMBOL: Chemical symbol of the atom (H, He, Na, Li...). Check the list
                         of available atoms in the docs


    Returns:

        INP: The input file for run-atomic command
    """

    welcome_message("minushalf")

    if quiet:
        logger.remove()
        logger.add(sys.stdout, level="ERROR")

    input_file = InputFile.minimum_setup(chemical_symbol.capitalize(),
                                         exchange_correlation_code,
                                         maximum_iterations, calculation_code)
    logger.info("Creating INP file")

    input_file.to_file(filename)

    end_message()
Example #2
0
    def _generate_atom_potential(
        self,
        base_path: str,
        symbol: str,
    ) -> None:
        """
        Make a dir with the atoms name,generate
        the input file and run the atomic program

            Args:
                symbol (str): Atom symbol
                base_path (str): Path to mkpotcar{symbol}
        """

        folder_path = os.path.join(base_path, "pseudopotential")
        if os.path.exists(folder_path):
            shutil.rmtree(folder_path)
        os.mkdir(folder_path)
        input_file = InputFile.minimum_setup(
            symbol,
            self.exchange_correlation_type,
            self.max_iterations,
            self.calculation_code,
        )
        input_file.to_file(os.path.join(folder_path, "INP"))
        process = Popen(['minushalf', 'run-atomic', "--quiet"],
                        stdout=PIPE,
                        stderr=PIPE,
                        cwd=folder_path)

        _, stderr = process.communicate()
        if stderr:

            raise Exception("Call to atomic program failed")
Example #3
0
def test_electron_occupation_na():
    """
        Test occupation in INP file for Na
        """
    inp = InputFile.minimum_setup('Na', 'pb')
    inp.electron_occupation(0.5, 0)

    for orbital in inp.valence_orbitals:
        if orbital["l"] == 0:
            assert np.isclose(orbital["occupation"][0], 0.5)
Example #4
0
def test_failing_occupation_with_default_params_O():
    """
    Test passing invalid secondary quantum number
    """
    inp_oxygen = InputFile.minimum_setup("O", "pb")
    lines = inp_oxygen.to_stringlist()
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open("INP", "w") as file:
            file.writelines(lines)

        result = runner.invoke(occupation, ["0,-1", "*,*"])
        assert result.exit_code == 1
Example #5
0
def test_failing_occupation_with_default_params_Au():
    """
    Test wrong occuparion percentual passed to command
    """
    inp_oxygen = InputFile.minimum_setup("Au", "pb")
    lines = inp_oxygen.to_stringlist()
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open("INP", "w") as file:
            file.writelines(lines)

        result = runner.invoke(occupation, ["2", "-1"])
        assert result.exit_code == 2
Example #6
0
def test_failing_occupation_with_default_params_Yb():
    """
    Test invalid occupation number for Yb
    """
    inp_oxygen = InputFile.minimum_setup("Yb", "pb")
    lines = inp_oxygen.to_stringlist()
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open("INP", "w") as file:
            file.writelines(lines)

        result = runner.invoke(occupation, ["0,3", "50,101"])
        assert result.exit_code == 1
Example #7
0
def test_electron_occupation_yb():
    """
        Test occupation in INP file for Yb
        """
    inp = InputFile.minimum_setup('Yb', 'pb')
    inp.electron_occupation(0.5, 0)
    inp.electron_occupation(0.5, 3)

    for orbital in inp.valence_orbitals:
        if orbital["l"] == 0:
            assert np.isclose(orbital["occupation"][0], 1.5)
        elif orbital["l"] == 3:
            assert np.isclose(orbital["occupation"][0], 13.5)
Example #8
0
def test_electron_occupation_au():
    """
        Test occupation in INP file for Au
        """
    inp = InputFile.minimum_setup('Au', 'pb')
    inp.electron_occupation(0.1, 0)
    inp.electron_occupation(0.4, 2)

    for orbital in inp.valence_orbitals:
        if orbital["l"] == 0:
            assert np.isclose(orbital["occupation"][0], 0.9)
        elif orbital["l"] == 2:
            assert np.isclose(orbital["occupation"][0], 9.6)
Example #9
0
def test_electron_occupation_si():
    """
        Test occupation in INP file for Si
        """
    inp = InputFile.minimum_setup('Si', 'pb')
    inp.electron_occupation(0.4, 0)
    inp.electron_occupation(0.3, 1)

    for orbital in inp.valence_orbitals:
        if orbital["l"] == 0:
            assert np.isclose(orbital["occupation"][0], 1.6)
        elif orbital["l"] == 1:
            assert np.isclose(orbital["occupation"][0], 1.7)
Example #10
0
def test_electron_occupation_ag():
    """
        Test occupation in INP file for Ag
        """
    inp = InputFile.minimum_setup('Ag', 'pb')
    inp.electron_occupation(0.5, 2)
    inp.electron_occupation(0.2, 0)

    for orbital in inp.valence_orbitals:
        if orbital["l"] == 2:
            assert np.isclose(orbital["occupation"][0], 9.5)
        elif orbital["l"] == 0:
            assert np.isclose(orbital["occupation"][0], 0.8)
Example #11
0
def test_minimum_setup(file_path):
    """
    Test minimum setup function to
    generate INP files with the elements
    symbol and the functional of exchange and exchange
    correlation
    """

    for element in ElectronicDistribution:
        symbol = str(element)
        path = file_path(f"{symbol}/INP")
        inp = InputFile.minimum_setup(symbol, 'pb')
        with open(path, "r") as file:
            assert file.read() == "".join(inp.to_stringlist())
Example #12
0
def test_from_file(file_path):
    """
    Test from_file path to generate instances
    of the InputFile class with an INP text file
    """
    for element in ElectronicDistribution:
        symbol = str(element)
        path = file_path(f"{symbol}/INP_COMMENTED")

        inp_from_file = InputFile.from_file(path)
        inp_minimum_setup = InputFile.minimum_setup(symbol, 'pb')

        from_file_string = "".join(inp_from_file.to_stringlist())
        minimum_setup_string = "".join(inp_minimum_setup.to_stringlist())

        assert from_file_string == minimum_setup_string
Example #13
0
def test_occupation_with_default_params_Yb():
    """
    Test occupation command in the p orbital of ytterbium
    """
    inp_oxygen = InputFile.minimum_setup("Yb", "pb")
    lines = inp_oxygen.to_stringlist()
    runner = CliRunner()
    with runner.isolated_filesystem():
        with open("INP", "w") as file:
            file.writelines(lines)

        result = runner.invoke(occupation, ["0", "50"])
        assert result.exit_code == 0
        occupied_file = InputFile.from_file("INP_OCC")
        for orbital in occupied_file.valence_orbitals:
            if orbital["l"] == 0:
                assert np.isclose(orbital["occupation"][0], 1.75) == True
Example #14
0
def test_atomic_with_all_elements():
    """
    Test if the atomic run produce the correct output for
    elements in the periodic table
    """
    runner = CliRunner()

    for element in ElectronicDistribution:
        inp = InputFile.minimum_setup(str(element), "pb")
        lines = inp.to_stringlist()
        with runner.isolated_filesystem():
            with open("INP", "w") as file:
                file.writelines(lines)
            result = runner.invoke(run_atomic, [])
            assert result.exit_code == 0
            assert os.path.exists("VTOTAL0") == True
            assert os.path.exists("VTOTAL.ae") == True
            assert os.path.exists("VTOTAL2") == True
            assert os.path.exists("VTOTAL3") == True