Skip to content

Commit

Permalink
Merge pull request #26 from hentt30/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
hentt30 committed Jul 13, 2021
2 parents a6b126f + a3ce50d commit 87b71a2
Show file tree
Hide file tree
Showing 29 changed files with 390 additions and 249 deletions.
6 changes: 3 additions & 3 deletions docs/source/_build/html/_sources/execute.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ correction tag
- ]_ will be used for each optimization, where :math:`d` is the distance of the nearest neighbor in the unit cell. (Default: :math:`0.15 + 0.84d`)
- conduction_cut_guess: Initial Guess for the Nelder-Mead algorithm for cut in valence correction. If not provided, the default value of :math:`0.15 + 0.84d` will be used will be used for each optimization, where :math:`d` is the distance of the nearest neighbor in the unit cell. (Default: :math:`0.15 + 0.84d`)
- tolerance: Minimum level of precision for the result of the Nelder-Mead algorithm (Default: 0.01)
- fractionary_valence_treshold: :ref:`Treshold <frac_correction>` :math:`\epsilon` for fractionary valence correction (Default: 10).
- fractional_valence_treshold: :ref:`Treshold <frac_correction>` :math:`\epsilon` for fractionary valence correction (Default: 10).
- overwrite_vbm: In some special cases [6]_, it is necessary to overwrite the value of band projection in a given orbital and ion. This tag is made for these situations. It is necessary to inform the chemical element symbol of the corresponding ion, the orbital and the value to be replaced. The program immediately overwrites the old projection values for the last valence band and use the new values for DFT -1/2 calculations (Default: No overwrite)
- overwrite_vbm: In some special cases [6]_, it is necessary to overwrite the value of band projection in a given orbital and ion. This tag is made for these situations. It is necessary to inform the chemical element symbol of the corresponding ion, the orbital and the value to be replaced. The program immediately overwrites the old projection values for the first conduction band and use the new values for DFT -1/2 calculations (Default: No overwrite)

Expand Down Expand Up @@ -169,8 +169,8 @@ The example below shows an use of correction tag in the :code:`minushalf.yaml` f
valence_cut_guess: 2.0
conduction_cut_guess: 1.0
tolerance: 0.01
fractionary_valence_treshold: 15
fractionary_conduction_treshold: 23
fractional_valence_treshold: 15
fractional_conduction_treshold: 23
overwrite_vbm:
- [C, p, 23.4]
- [Si, d, 11]
Expand Down
49 changes: 23 additions & 26 deletions docs/source/execute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,17 @@ Currently, minushalf only supports one software, but one hope to add more soon.
vasp tag
################
The vasp tag is a set of various informations that specifies the settings
for executing VASP. These informations are:
The vasp tag specifies the command needed to perform first principles calculations. This tag has the following fields:

- number_of_cores: The number of cores used to run VASP. (Default: 1)
- path: entry-point for the executable (Default: vasp)
- command: Command used to perform first principles calculations. (Default: ['mpirun','vasp'])

Thus, the command that runs the software is :code:`mpirun -np $ {number_of_cores} $ {path}`. The example below
The :code:`mpirun` command is used for convenience and can be overridden depending on the local settings of the user's machine. The example below
shows an use of the vasp tag in the :code:`minushalf.yaml file`:

.. code-block:: yaml
vasp:
number_of_cores: 4
path: vasp_bin
command: ['mpirun','-np','6','vasp']
atomic_program tag
Expand Down Expand Up @@ -134,14 +131,14 @@ correction tag
- correction_code: Code thar specifies the potential correction (Default: v)
- potfiles_folder: Path to folder that holds the potential files for each atom. The files must be named in the following pattern :code:`${POTENTIAL_FILE_NAME}.${LOWERCASE_CHEMICAL_SYMBOL}` (Default: minushalf_potfiles)
- amplitude: Scaling factor to be used to correct the artificially generated potential. In the vast majority of cases, the amplitude value is 1.0. However, there are some special cases where this value needs to be adjusted [5]_. Therefore, we recommend that you do not change this value unless you know exactly what you are doing (Default: 1.0)
- valence_cut_guess: Initial Guess for the Nelder-Mead algorithm for cut in valence correction. If not provided, the default value of :math:`0.15 + 0.84d` [6
- ]_ will be used for each optimization, where :math:`d` is the distance of the nearest neighbor in the unit cell. (Default: :math:`0.15 + 0.84d`)
- valence_cut_guess: Initial Guess for the Nelder-Mead algorithm for cut in valence correction. If not provided, the default value of :math:`0.15 + 0.84d` [6]_ will be used for each optimization, where :math:`d` is the distance of the nearest neighbor in the unit cell. (Default: :math:`0.15 + 0.84d`)
- conduction_cut_guess: Initial Guess for the Nelder-Mead algorithm for cut in valence correction. If not provided, the default value of :math:`0.15 + 0.84d` will be used will be used for each optimization, where :math:`d` is the distance of the nearest neighbor in the unit cell. (Default: :math:`0.15 + 0.84d`)
- tolerance: Minimum level of precision for the result of the Nelder-Mead algorithm (Default: 0.01)
- fractionary_valence_treshold: :ref:`Treshold <frac_correction>` :math:`\epsilon` for fractionary valence correction (Default: 10).
- overwrite_vbm: In some special cases [6]_, it is necessary to overwrite the value of band projection in a given orbital and ion. This tag is made for these situations. It is necessary to inform the chemical element symbol of the corresponding ion, the orbital and the value to be replaced. The program immediately overwrites the old projection values for the last valence band and use the new values for DFT -1/2 calculations (Default: No overwrite)
- overwrite_vbm: In some special cases [6]_, it is necessary to overwrite the value of band projection in a given orbital and ion. This tag is made for these situations. It is necessary to inform the chemical element symbol of the corresponding ion, the orbital and the value to be replaced. The program immediately overwrites the old projection values for the first conduction band and use the new values for DFT -1/2 calculations (Default: No overwrite)

- tolerance: Absolute tolerance for the result of the Nelder-Mead algorithm (Default: 0.01)
- fractional_valence_treshold: :ref:`Treshold <frac_correction>` :math:`\epsilon` for fractional valence correction (Default: 10).
- fractional_conduction_treshold: :ref:`Treshold <frac_correction>` :math:`\epsilon` for fractional conduction correction (Default: 10).
- overwrite_vbm: In some special cases [6]_, it is necessary to consider another band as the VBM. This tag is made for these situations. It is necessary to inform the kpoint and the band number that specifies the band location. The program immediately overwrites the old projection values and uses the new values for DFT -1/2 calculations (Default: No overwrite)
- overwrite_cbm: In some special cases [6]_, it is necessary to consider another band as the CBM. This tag is made for these situations. It is necessary to inform the kpoint and the band number that specifies the band location. The program immediately overwrites the old projection values and uses the new values for DFT -1/2 calculations (Default: No overwrite)
- inplace: This tag allows you to decide whether all calculations will be done in the root folder or not. It is recommended to pass it as :code:`True` if non-self-consistent calculations are being performed for the Gap calculation, since the program only copies the input files, the output files needed for the non-self-consistent calculation will not be considered (Default: False)

The values that the correction_code tag can assume are listed below:

Expand All @@ -151,11 +148,13 @@ The values that the correction_code tag can assume are listed below:
---------------------------

- v: Simple valence correction
- vf: Fractionary valence correction
- vf: Fractional valence correction
- c: Simple conduction correction
- cf: Fractional conduction correction
- vc: Simple valence and simple conduction corrections
- vfc: Fractionary valence and simple conduction corrections
- vcf: Simple valence and fractionary conduction corrections
- vfcf: Fractionary valence and fractionary conduction corrections
- vfc: Fractional valence and simple conduction corrections
- vcf: Simple valence and fractional conduction corrections
- vfcf: Fractional valence and fractional conduction corrections


The example below shows an use of correction tag in the :code:`minushalf.yaml` file:
Expand All @@ -169,13 +168,11 @@ The example below shows an use of correction tag in the :code:`minushalf.yaml` f
valence_cut_guess: 2.0
conduction_cut_guess: 1.0
tolerance: 0.01
fractionary_valence_treshold: 15
fractionary_conduction_treshold: 23
overwrite_vbm:
- [C, p, 23.4]
- [Si, d, 11]
overwrite_cbm:
- [Ag, f, 9]
fractional_valence_treshold: 15
fractional_conduction_treshold: 23
overwrite_vbm: [4,9] # Kpoint and band number, respectively
overwrite_cbm: [1,3] # Kpoint and band number, respectively
inplace: False
Expand Down Expand Up @@ -209,7 +206,7 @@ For the input file, the following initial settings were chosen:
software: VASP
vasp:
number_of_cores: 4
command: ['mpirun','-np','4','vasp']
correction:
correction_code: vc
Expand Down
2 changes: 1 addition & 1 deletion minushalf/commands/correct_potfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def correct_potfile(
is_conduction = True

for new_cut in cut_numbers:
logger.info("Correcting POTFILE for cut = {:.2f} ".format(new_cut))
logger.info("Correcting POTFILE for cut = {:.2f} a.u".format(new_cut))
new_potential = atomic_potential.correct_potential(
new_cut, amplitude, is_conduction)
atomic_potential.correct_file(new_potential, new_cut, amplitude,
Expand Down
101 changes: 66 additions & 35 deletions minushalf/commands/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import shutil
from collections import OrderedDict
from typing import List
import numpy as np
import pandas as pd
import click
Expand All @@ -16,8 +17,8 @@
welcome_message,
end_message,
make_minushalf_results,
get_fractionary_corrections_indexes,
get_simple_corrections_indexes,
get_fractionary_correction_indexes,
get_simple_correction_indexes,
)
from minushalf.softwares import (VaspFactory)
from minushalf.corrections import (VaspCorrection)
Expand Down Expand Up @@ -68,30 +69,35 @@ def get_atoms_list(factory: SoftwaresAbstractFactory) -> list:
return list(OrderedDict.fromkeys(atoms))


def overwrite_band_projection(new_values: list,
band_projection: pd.DataFrame) -> pd.DataFrame:
def overwrite_band_projection(
band_location: List[int],
factory: SoftwaresAbstractFactory) -> pd.DataFrame:
"""
Overwrite values in VBM or CBM band projection
Args:
new_values (list): Arguments passed in overwrite_vbm or overwrite_cbm.
band_location (List[int]): Kpoint and band number, respectively.
band_projection (pd.Dataframe): Dataframe with the value of projections
of VBM or CBM.
factory (SoftwaresAbstractFactory): Software factory to create band structure class
Returns:
modified_band_projection (pd.Dataframe): Band projection data frame
with the values overwrited.
"""
for case in new_values:
atom = case[0].capitalize()
orbital = case[1].lower()
projection = int(case[2])
band_projection[orbital][atom] = projection
return band_projection
eigenvalues = factory.get_eigenvalues()
fermi_energy = factory.get_fermi_energy()
atoms_map = factory.get_atoms_map()
num_bands = factory.get_number_of_bands()
band_projection_file = factory.get_band_projection_class()

band_structure = BandStructure(eigenvalues, fermi_energy, atoms_map,
num_bands, band_projection_file)
vbm_projection = band_structure.band_projection(*band_location)
normalized_df = projection_to_df(vbm_projection)
return normalized_df


@click.command()
Expand Down Expand Up @@ -159,28 +165,28 @@ def execute(quiet: bool):
shutil.rmtree(root_folder)
os.mkdir(root_folder)

## get vbm projection
logger.info("Get Vbm and CBM projections")
## get the bands projections (VBM and CBM)
logger.info("Get VBM and CBM projections")
vbm_projection = get_vbm_projection(software_factory)
cbm_projection = get_cbm_projection(software_factory)

### Overwrite band projections
if len(minushalf_yaml.correction[
CorrectionDefaultParams.overwrite_vbm.name]) > 0:
CorrectionDefaultParams.overwrite_vbm.name]) == 2:
logger.warning(
"You're changing directly the band character. This is not recommendend unless you know exactly what are you doing."
)
vbm_projection = overwrite_band_projection(
minushalf_yaml.correction[
CorrectionDefaultParams.overwrite_vbm.name], vbm_projection)
CorrectionDefaultParams.overwrite_vbm.name], software_factory)
if len(minushalf_yaml.correction[
CorrectionDefaultParams.overwrite_cbm.name]) > 0:
CorrectionDefaultParams.overwrite_cbm.name]) == 2:
logger.warning(
"You're changing directly the band character. This is not recommendend unless you know exactly what are you doing."
)
cbm_projection = overwrite_band_projection(
minushalf_yaml.correction[
CorrectionDefaultParams.overwrite_cbm.name], cbm_projection)
CorrectionDefaultParams.overwrite_cbm.name], software_factory)

## get atoms list
logger.info("Get atoms list")
Expand All @@ -201,7 +207,7 @@ def execute(quiet: bool):
"minushalf_yaml": minushalf_yaml,
"band_projection": vbm_projection,
"atoms": atoms,
"is_conduction": False
"is_conduction": False,
}
conduction_options = {
"root_folder": root_folder,
Expand All @@ -215,7 +221,7 @@ def execute(quiet: bool):

logger.info("Doing corrections")
if minushalf_yaml.correction["correction_code"] == CorrectionCode.v.name:
valence_options["correction_indexes"] = get_simple_corrections_indexes(
valence_options["correction_indexes"] = get_simple_correction_indexes(
vbm_projection)
valence_correction = correction(**valence_options)
valence_cuts, valence_gap = valence_correction.execute()
Expand All @@ -225,21 +231,21 @@ def execute(quiet: bool):
"correction_code"] == CorrectionCode.vf.name:

valence_options[
"correction_indexes"] = get_fractionary_corrections_indexes(
"correction_indexes"] = get_fractionary_correction_indexes(
vbm_projection,
treshold=minushalf_yaml.
correction["fractionary_valence_treshold"])
correction["fractional_valence_treshold"])

valence_fractionary_correction = correction(**valence_options)
valence_cuts, valence_gap = valence_fractionary_correction.execute()
make_minushalf_results(valence_cuts=valence_cuts, gap=valence_gap)

elif minushalf_yaml.correction[
"correction_code"] == CorrectionCode.vc.name:
valence_options["correction_indexes"] = get_simple_corrections_indexes(
valence_options["correction_indexes"] = get_simple_correction_indexes(
vbm_projection)
conduction_options[
"correction_indexes"] = get_simple_corrections_indexes(
"correction_indexes"] = get_simple_correction_indexes(
cbm_projection)
valence_correction = correction(**valence_options)
valence_cuts, _ = valence_correction.execute()
Expand All @@ -253,13 +259,13 @@ def execute(quiet: bool):
"correction_code"] == CorrectionCode.vfc.name:

valence_options[
"correction_indexes"] = get_fractionary_corrections_indexes(
"correction_indexes"] = get_fractionary_correction_indexes(
vbm_projection,
treshold=minushalf_yaml.
correction["fractionary_valence_treshold"])
correction["fractional_valence_treshold"])

conduction_options[
"correction_indexes"] = get_simple_corrections_indexes(
"correction_indexes"] = get_simple_correction_indexes(
cbm_projection)

valence_fractionary_correction = correction(**valence_options)
Expand All @@ -274,16 +280,16 @@ def execute(quiet: bool):
"correction_code"] == CorrectionCode.vfcf.name:

valence_options[
"correction_indexes"] = get_fractionary_corrections_indexes(
"correction_indexes"] = get_fractionary_correction_indexes(
vbm_projection,
treshold=minushalf_yaml.
correction["fractionary_valence_treshold"])
correction["fractional_valence_treshold"])

conduction_options[
"correction_indexes"] = get_fractionary_corrections_indexes(
"correction_indexes"] = get_fractionary_correction_indexes(
cbm_projection,
treshold=minushalf_yaml.
correction["fractionary_conduction_treshold"])
correction[" "])

valence_fractionary_correction = correction(**valence_options)
valence_cuts, _ = valence_fractionary_correction.execute()
Expand All @@ -296,14 +302,14 @@ def execute(quiet: bool):

elif minushalf_yaml.correction[
"correction_code"] == CorrectionCode.vcf.name:
valence_options["correction_indexes"] = get_simple_corrections_indexes(
valence_options["correction_indexes"] = get_simple_correction_indexes(
vbm_projection)

conduction_options[
"correction_indexes"] = get_fractionary_corrections_indexes(
"correction_indexes"] = get_fractionary_correction_indexes(
cbm_projection,
treshold=minushalf_yaml.
correction["fractionary_conduction_treshold"])
correction["fractional_conduction_treshold"])

valence_correction = correction(**valence_options)
valence_cuts, _ = valence_correction.execute()
Expand All @@ -313,4 +319,29 @@ def execute(quiet: bool):
make_minushalf_results(valence_cuts=valence_cuts,
gap=conduction_gap,
conduction_cuts=conduction_cuts)
elif minushalf_yaml.correction["correction_code"] == CorrectionCode.c.name:
conduction_options[
"correction_indexes"] = get_simple_correction_indexes(
cbm_projection)
conduction_options["only_conduction"] = True

conduction_simple_correction = correction(**conduction_options)
conduction_cuts, conduction_gap = conduction_simple_correction.execute(
)
make_minushalf_results(gap=conduction_gap,
conduction_cuts=conduction_cuts)
elif minushalf_yaml.correction[
"correction_code"] == CorrectionCode.cf.name:
conduction_options[
"correction_indexes"] = get_fractionary_correction_indexes(
cbm_projection,
treshold=minushalf_yaml.
correction["fractional_conduction_treshold"])
conduction_options["only_conduction"] = True

conduction_fractionary_correction = correction(**conduction_options)
conduction_cuts, conduction_gap = conduction_fractionary_correction.execute(
)
make_minushalf_results(gap=conduction_gap,
conduction_cuts=conduction_cuts)
end_message()

0 comments on commit 87b71a2

Please sign in to comment.