コード例 #1
0
ファイル: test_input_file.py プロジェクト: hentt30/minushalf
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
コード例 #2
0
ファイル: test_occupation.py プロジェクト: hentt30/minushalf
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
コード例 #3
0
def occupation(orbital_quantum_number: str, occupation_percentage: str,
               quiet: bool):
    """
    Perform fractional occupation on the atom and generate the potential for this occupation.
    The occupation can subtract any fraction of the electron between 0 and 0.5, half occupation is the default.

    Requires:

        ORBITAL_QUANTUM_NUMBER: A string that defines the orbital(s) in which the occupation will be made,
        it can assume four values: (0: s | 1: p | 2: d | 3: f). if going to modify multiple orbitals,
        pass a string with numbers separated by commas : ("0,1,2,3").


        OCCUPATION_PERCENTAGE: A string that defines percentual of half an electron to be used in the occupation.
        The default is 100%, which states for 0.5e. For multiple occupations in different orbitals, pass a string
        separated by commas ("100,50,40,100"). For simplicity, to avoid the excessive repetition of the number
        100, just replace the number with * ("*,30,*"). If this argument is not used, the occupation of
        half an electron will be made for all orbitals assed as arguments.


        INP: Input file of the run-atomic command.

    Returns:

        INP_OCC : Input file modified for fractional occupation.


        INP.ae: A copy of the input file for the calculation.


        VTOTAL_OCC: Contains the atom potential for fractional occupation.


        OUT: Contains detailed information about the run.


        AECHARGE: Contains in four columns values of r, the “up” and “down” parts of the total
        charge density, and the total core charge density (the charges multiplied by 4πr 2 ).


        CHARGE: is exactly identical to AECHARGE and is generated for backwards compatibility.


        RHO: Like CHARGE, but without the 4πr 2 factor


        AEWFNR0...AEWFNR3: All-electron valence wavefunctions as function of radius, for s, p, d,
        and f valence orbitals (0, 1, 2, 3, respectively — some channels might not be available).
        They include a factor of r, the s orbitals also going to zero at the origin.
    """

    welcome_message("minushalf")

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

    input_file = InputFile.from_file()
    logger.info("Adding minus one half electron correction on INP")

    try:
        quantum_numbers = np.array(orbital_quantum_number.split(","),
                                   dtype=int)
    except ValueError as wrong_input:
        raise ValueError(
            "Invalid value for secondary quantum number") from wrong_input

    for quantum_number in quantum_numbers:
        if quantum_number < 0 or quantum_number > 3:
            raise ValueError("Invalid value for secondary quantum number")

    percentuals = np.ones(len(quantum_numbers)) * 100

    for index, percentual in enumerate(occupation_percentage.split(",")):
        if percentual != "*":
            if float(percentual) < 0 or float(percentual) > 100:
                raise ValueError("Invalid value for occupation percentual")
            percentuals[index] = float(percentual)

    for quantum_number, percentual in zip(quantum_numbers, percentuals):
        input_file.electron_occupation(0.5 * (percentual / 100),
                                       quantum_number)

    os.rename('INP', 'INP.ae')
    input_file.to_file()

    logger.info("Run atomic program")
    try:
        atomic_program.run()
    except Exception as program_fail:
        raise Exception('Problems in atomic program') from program_fail

    logger.info("Atomic program finished execution.")

    if not os.path.exists('./VTOTAL1'):
        raise FileNotFoundError("Problems in INP file generation")
    logger.info("Changing VTOTAL1 to VTOTAL_OCC")
    os.rename("VTOTAL1", "VTOTAL_OCC")

    logger.info("Changing INP to INP_OCC")
    os.rename('INP', 'INP_OCC')

    end_message()