Skip to content

Commit

Permalink
Implement separate folder mode for split k-points
Browse files Browse the repository at this point in the history
  • Loading branch information
zhubonan committed Jan 12, 2024
1 parent 76a7da0 commit 908b189
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 7 additions & 1 deletion easyunfold/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ def easyunfold():
@click.option('--out-file', '-o', default='easyunfold.json', help='Name of the output file')
@click.option('--no-expand', help='Do not expand the kpoints by symmetry', default=False, is_flag=True)
@click.option('--nk-per-split', help='Number of band structure kpoints per split.', type=int)
@click.option('--separate-folders/--no-separate-folders',
help='Whether to use separate folders for each split.',
default=False,
show_default=True)
@click.option('--scf-kpoints',
help='File (IBZKPT) to provide SCF kpoints for self-consistent calculations. Needed for hybrid functional calculations.',
type=click.Path(exists=True, dir_okay=False))
@click.option('--yes', '-y', is_flag=True, default=False, help='Skip and confirmation.', hidden=True) # hide help
def generate(pc_file, code, sc_file, matrix, kpoints, time_reversal, out_file, no_expand, symprec, nk_per_split, scf_kpoints, yes):
def generate(pc_file, code, sc_file, matrix, kpoints, time_reversal, out_file, no_expand, symprec, nk_per_split, scf_kpoints, yes,
separate_folders):
"""
Generate the kpoints for performing supercell calculations.
Expand Down Expand Up @@ -155,6 +160,7 @@ def generate(pc_file, code, sc_file, matrix, kpoints, time_reversal, out_file, n
out_kpt_name,
nk_per_split=nk_per_split,
scf_kpoints_and_weights=scf_kpoints_and_weights,
use_separate_folders=separate_folders,
source=sc_file,
)

Expand Down
15 changes: 9 additions & 6 deletions easyunfold/unfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import re
import warnings
from typing import Union, List, Tuple
from pathlib import Path
from packaging import version

import numpy as np
Expand Down Expand Up @@ -332,6 +333,7 @@ def write_sc_kpoints(self,
file: str,
nk_per_split: Union[None, list] = None,
scf_kpoints_and_weights: Union[None, list] = None,
use_separate_folders=False,
**kwargs):
"""
Write the supercell kpoints to a file.
Expand All @@ -358,12 +360,13 @@ def write_sc_kpoints(self,
for i_spilt, kpt in enumerate(splits):
if scf_kpoints_and_weights:
kpt, weights = concatenate_scf_kpoints(scf_kpoints_and_weights[0], scf_kpoints_and_weights[1], kpt)
write_kpoints(kpt,
f'{file}_{i_spilt + 1:03d}',
f'supercell kpoints split {i_spilt + 1}',
code=self.dft_code,
weights=weights,
**kwargs)
if use_separate_folders:
folder = f'split-{i_spilt+1:03d}'
Path(folder).mkdir(exist_ok=True)
fname = str(folder / file)
else:
fname = f'{file}_{i_spilt + 1:03d}'
write_kpoints(kpt, fname, f'supercell kpoints split {i_spilt + 1}', code=self.dft_code, weights=weights, **kwargs)

def write_pc_kpoints(self, file: str, expanded: bool = False, **kwargs):
"""Write the primitive cell kpoints"""
Expand Down

0 comments on commit 908b189

Please sign in to comment.