Skip to content

Commit

Permalink
Merge pull request #29 from hentt30/develop
Browse files Browse the repository at this point in the history
[feat]: One correction per orbital in minushalf execute
  • Loading branch information
hentt30 committed Jul 17, 2021
2 parents 570192c + d19baf7 commit 7589157
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 35 deletions.
4 changes: 2 additions & 2 deletions docs/source/execute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ on the values obtained in the optimization of the CUT and the resulting band ene
.. code-block:: xml
Valence correction cuts:
(C):3.13 a.u
(C,p):3.13 a.u
----------------------------------------------------------------
Conduction correction cuts:
(Si):2.77 a.u
(Si,p):2.77 a.u
----------------------------------------------------------------
GAP: 4.37eV
Expand Down
21 changes: 11 additions & 10 deletions minushalf/corrections/vasp_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ def execute(self) -> tuple:
self.sum_correction_percentual = self._get_sum_correction_percentual()

for symbol, orbitals in self.correction_indexes.items():
cut = self._find_best_correction(symbol, orbitals)
cuts_per_atom_orbital[symbol] = cut
for orbital in orbitals:
cut = self._find_best_correction(symbol, orbital)
cuts_per_atom_orbital[(symbol, orbital)] = cut

gap = self._get_result_gap()
return (cuts_per_atom_orbital, gap)
Expand Down Expand Up @@ -262,12 +263,11 @@ def _get_sum_correction_percentual(self) -> float:

return total_sum

def _find_best_correction(self, symbol: str, orbitals: list) -> float:
def _find_best_correction(self, symbol: str, orbital: str) -> tuple:
"""
Correct the potcar of the atom symbol in the
orbital given. Then, find the best cut to the
the correciton.
Args:
symbol (str): Atom symbol
orbital (str): Orbital type (s,p,d,f)
Expand All @@ -276,7 +276,7 @@ def _find_best_correction(self, symbol: str, orbitals: list) -> float:
the optimum cut and the gap generated
by the correction.
"""
folder_name = "mkpotcar_{}".format(symbol.lower())
folder_name = f"mkpotcar_{symbol.lower()}_{orbital.lower()}"
path = os.path.join(self.root_folder, folder_name)
if os.path.exists(path):
shutil.rmtree(path)
Expand All @@ -288,11 +288,12 @@ def _find_best_correction(self, symbol: str, orbitals: list) -> float:
atoms_map = self.software_factory.get_atoms_map()
number_equal_neighbors = self.software_factory.get_number_of_equal_neighbors(
atoms_map=atoms_map, symbol=symbol)
for orbital in orbitals:
value = (100 / (1 + number_equal_neighbors)) * (
self.band_projection[orbital][symbol] /
self.sum_correction_percentual)
percentuals[orbital] = round(value)

value = (100 / (1 + number_equal_neighbors)) * (
self.band_projection[orbital][symbol] /
self.sum_correction_percentual)
percentuals[orbital] = round(value)

self._generate_occupation_potential(path, percentuals)

self.atom_potential = self._get_atom_potential_class(path, symbol)
Expand Down
2 changes: 1 addition & 1 deletion minushalf/utils/fractionary_correction_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ def get_fractionary_correction_indexes(band_projection: pd.DataFrame,

correction_indexes = defaultdict(list)
for row, column in itertools.product(rows_name, columns_name):
if band_projection[column][row] >= treshold:
if band_projection[column][row] > treshold:
correction_indexes[row].append(column)
return correction_indexes
10 changes: 6 additions & 4 deletions minushalf/utils/make_minushalf_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ def make_minushalf_results(
if valence_cuts:
file.write("Valence correction cuts:\n")
for key, value in valence_cuts.items():
symbol = key
symbol, orbital = key
cut = value
file.write("\t({}):{:.2f} a.u\n".format(symbol, cut))
file.write("\t({},{}):{:.2f} a.u\n".format(
symbol, orbital, cut))
file.write(
"----------------------------------------------------------------\n"
)
## Write conduction cuts
if conduction_cuts:
file.write("Conduction correction cuts:\n")
for key, value in conduction_cuts.items():
symbol = key
symbol, orbital = key
cut = value
file.write("\t({}):{:.2f} a.u\n".format(symbol, cut))
file.write("\t({},{}):{:.2f} a.u\n".format(
symbol, orbital, cut))
file.write(
"----------------------------------------------------------------\n"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Valence correction cuts:
(Ag):1.23 a.u
(Br):2.33 a.u
(Ag,d):1.23 a.u
(Br,f):2.33 a.u
----------------------------------------------------------------
Conduction correction cuts:
(Ag):1.23 a.u
(Br):2.33 a.u
(Ag,s):1.23 a.u
(Br,p):2.33 a.u
----------------------------------------------------------------
GAP: 2.33eV
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Valence correction cuts:
(Ag):1.23 a.u
(Br):2.33 a.u
(Ag,p):1.23 a.u
(Br,s):2.33 a.u
----------------------------------------------------------------
GAP: 2.33eV
11 changes: 5 additions & 6 deletions tests/unit/utils/test_get_fractionary_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_aln_2d_cbm_treshold_29(file_path):
cbm_projection = band_structure.cbm_projection()
cbm_df = projection_to_df(cbm_projection)
correction_indexes = get_fractionary_correction_indexes(cbm_df,
treshold=29)
treshold=28)
assert correction_indexes["N"][0] == "s"
assert correction_indexes["Al"][0] == "s"

Expand All @@ -102,7 +102,7 @@ def test_aln_2d_cbm_treshold_30(file_path):
cbm_projection = band_structure.cbm_projection()
cbm_df = projection_to_df(cbm_projection)
correction_indexes = get_fractionary_correction_indexes(cbm_df,
treshold=30)
treshold=29)
assert correction_indexes["N"][0] == "s"
assert len(correction_indexes["Al"]) == 0

Expand Down Expand Up @@ -153,7 +153,7 @@ def test_gec_2d_vbm_changing_treshold_12(file_path):
vbm_projection = band_structure.vbm_projection()
vbm_df = projection_to_df(vbm_projection)
correction_indexes = get_fractionary_correction_indexes(vbm_df,
treshold=12)
treshold=11)
assert correction_indexes["C"][0] == "p"
assert correction_indexes["Ge"][0] == "d"

Expand All @@ -179,7 +179,7 @@ def test_gec_2d_vbm_changing_treshold_13(file_path):
vbm_projection = band_structure.vbm_projection()
vbm_df = projection_to_df(vbm_projection)
correction_indexes = get_fractionary_correction_indexes(vbm_df,
treshold=13)
treshold=12)
assert correction_indexes["C"][0] == "p"
assert len(correction_indexes["Ge"]) == 0

Expand Down Expand Up @@ -253,8 +253,7 @@ def test_bn_2d_vbm_without_treshold(file_path):

vbm_projection = band_structure.vbm_projection()
vbm_df = projection_to_df(vbm_projection)
correction_indexes = get_fractionary_correction_indexes(vbm_df,
treshold=1)
correction_indexes = get_fractionary_correction_indexes(vbm_df, treshold=0)
assert correction_indexes["N"][0] == "p"
assert correction_indexes["B"][0] == "p"

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/utils/test_make_minushalf_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def test_only_valence_cuts(file_path):
expected_file_path = file_path(
"/minushalf_results/minushalf_results_only_valence_cuts.dat")
valence_cuts = {
"Ag": 1.23,
"Br": 2.33,
("Ag", "p"): 1.23,
("Br", "s"): 2.33,
}
gap = 2.334
filename = "minushalf_results_only_valence_cuts.dat"
Expand All @@ -37,12 +37,12 @@ def test_conduction_cuts(file_path):
expected_file_path = file_path(
"/minushalf_results/minushalf_results_conduction_cuts.dat")
valence_cuts = {
"Ag": 1.23,
"Br": 2.33,
("Ag", "d"): 1.23,
("Br", "f"): 2.33,
}
conduction_cuts = {
"Ag": 1.23,
"Br": 2.33,
("Ag", "s"): 1.23,
("Br", "p"): 2.33,
}
gap = 2.334
filename = "minushalf_results_conduction_cuts.dat"
Expand Down

0 comments on commit 7589157

Please sign in to comment.