Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to tmpdir behaviour; tweaks to the tutorial docs #175

Merged
merged 9 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/tutorials/tutorial_2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ Having transformed into a supercell, the calculation of the screening parameters
The code is doing this because of what we provided for the ``orbital_groups`` in the input file:

.. literalinclude:: ../../tutorials/tutorial_2/si.json
:lines: 10-12
:lineno-start: 10
:lines: 9-11
:lineno-start: 9
:emphasize-lines: 2

which tells the code to use the same parameter for orbitals belonging to the same group. In this instance we are calculating a single screening parameter for all four filled orbitals, and a single screening parameter for the empty orbitals.
Expand Down
100 changes: 51 additions & 49 deletions koopmans/workflows/_folding.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,56 +30,58 @@ def _run(self):
self.print('Folding to supercell', style='subheading')

if self.parameters.init_orbitals in ['mlwfs', 'projwfs']:
# Loop over the various subblocks that we have wannierized separately
for block in self.projections:
# Create the calculator
calc_w2k = self.new_calculator('wann2kcp', spin_component=block.spin, wan_mode='wannier2kcp',
directory=block.directory)
calc_w2k.prefix = 'w2kcp'

# Checking that gamma_trick is consistent with gamma_only
if calc_w2k.parameters.gamma_trick and not self.kpoints.gamma_only:
calc_w2k.parameters.gamma_trick = False
elif not calc_w2k.parameters.gamma_trick and self.kpoints.gamma_only:
calc_w2k.parameters.gamma_trick = True
with utils.chdir('wannier'):
# Loop over the various subblocks that we have wannierized separately
for block in self.projections:
# Create the calculator
calc_w2k = self.new_calculator('wann2kcp', spin_component=block.spin, wan_mode='wannier2kcp',
directory=block.directory)
calc_w2k.prefix = 'w2kcp'

# Checking that gamma_trick is consistent with gamma_only
if calc_w2k.parameters.gamma_trick and not self.kpoints.gamma_only:
calc_w2k.parameters.gamma_trick = False
elif not calc_w2k.parameters.gamma_trick and self.kpoints.gamma_only:
calc_w2k.parameters.gamma_trick = True
else:
pass

# Run the calculator
self.run_calculator(calc_w2k)

if self.parameters.spin_polarized:
spins = ['up', 'down']
else:
pass

# Run the calculator
self.run_calculator(calc_w2k)

if self.parameters.spin_polarized:
spins = ['up', 'down']
else:
spins = [None, None]

# Merging evcw files
for occ in [True, False]:
for spin, evc_index in zip(spins, [1, 2]):
subset = self.projections.get_subset(occ=occ, spin=spin)

if len(subset) > 1:
output_directory = Path(subset[0].merge_directory)
output_directory.mkdir(exist_ok=True)
if self.parameters.spin_polarized:
evc_fname = f'evcw.dat'
else:
evc_fname = f'evcw{evc_index}.dat'
command = ' '.join([f'{calculators.bin_directory}/merge_evc.x -nr {np.prod(self.kpoints.grid)}']
+ [f'-i {b.directory}/{evc_fname}' for b in subset]
+ [f'-o {output_directory}/{evc_fname}'])
if occ:
label = 'occupied'
else:
label = 'empty'
label += f' spin {evc_index}'
if self.parameters.from_scratch or not (output_directory / evc_fname).exists():
self.parameters.from_scratch = True
self.print(f'Merging the {label} band blocks... ', end='')
utils.system_call(command)
self.print('done')
else:
self.print(f'Not merging the {label} band blocks as this is already complete')
spins = [None, None]

# Merging evcw files
for occ in [True, False]:
for spin, evc_index in zip(spins, [1, 2]):
subset = self.projections.get_subset(occ=occ, spin=spin)

if len(subset) > 1:
output_directory = Path(subset[0].merge_directory)
output_directory.mkdir(exist_ok=True)
if self.parameters.spin_polarized:
evc_fname = f'evcw.dat'
else:
evc_fname = f'evcw{evc_index}.dat'
command = ' '.join([f'{calculators.bin_directory}/merge_evc.x -nr '
f'{np.prod(self.kpoints.grid)}']
+ [f'-i {b.directory}/{evc_fname}' for b in subset]
+ [f'-o {output_directory}/{evc_fname}'])
if occ:
label = 'occupied'
else:
label = 'empty'
label += f' spin {evc_index}'
if self.parameters.from_scratch or not (output_directory / evc_fname).exists():
self.parameters.from_scratch = True
self.print(f'Merging the {label} band blocks... ', end='')
utils.system_call(command)
self.print('done')
else:
self.print(f'Not merging the {label} band blocks as this is already complete')

else:
# Create the calculator
Expand Down
2 changes: 1 addition & 1 deletion koopmans/workflows/_koopmans_dscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def perform_initialization(self) -> None:
fold_workflow = workflows.FoldToSupercellWorkflow.fromparent(self)

# Do this in the same directory as the wannierization
fold_workflow.run(subdirectory='init/wannier')
fold_workflow.run(subdirectory='init')

# Convert self.atoms to the supercell
self.primitive_to_supercell()
Expand Down
6 changes: 4 additions & 2 deletions koopmans/workflows/_singlepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def _run(self) -> None:
if all(self.atoms.pbc) and self.calculator_parameters['ui'].do_smooth_interpolation:
if not Path('pkipz/postproc').is_dir():
utils.system_call('mkdir pkipz/postproc')
utils.system_call(f'rsync -a ki/postproc/wannier pkipz/postproc/')
for dir in ['wannier', 'TMP', 'pdos']:
utils.system_call(f'rsync -a ki/postproc/{dir} pkipz/postproc/')

# KIPZ
utils.system_call('rsync -a ki/final/ kipz/init/')
Expand All @@ -143,7 +144,8 @@ def _run(self) -> None:
utils.system_call('rsync -a ki/init/wannier kipz/init/')
if all(self.atoms.pbc) and self.calculator_parameters['ui'].do_smooth_interpolation:
# Copy over the smooth PBE calculation from KI for KIPZ to use
utils.system_call('rsync -a ki/postproc/wannier kipz/postproc/')
for dir in ['wannier', 'TMP', 'pdos']:
utils.system_call(f'rsync -a ki/postproc/{dir} kipz/postproc/')

else:
# self.functional != all and self.method != 'dfpt'
Expand Down
4 changes: 0 additions & 4 deletions koopmans/workflows/_wannierize.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,6 @@ def new_calculator(self, calc_type, *args, **kwargs) -> CalcExtType:
if self._force_nspin2 and not self.parameters.spin_polarized:
calc.parameters.spin_component = 'up'

# Use a unified tmp directory
if 'outdir' in calc.parameters.valid:
calc.parameters.outdir = Path('wannier/TMP').resolve()

return calc

def merge_wannier_files(self, block: List[projections.ProjectionBlock], prefix: str = 'wann'):
Expand Down
17 changes: 13 additions & 4 deletions koopmans/workflows/_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ def run(self, subdirectory: Optional[Union[str, Path]] = None, from_scratch: Opt
self.print_preamble()

if not self.parent:
if self.parameters.from_scratch:
self._remove_tmpdirs()
self._run_sanity_checks()

if self.parent:
Expand Down Expand Up @@ -1287,17 +1289,24 @@ def plot_bandstructure(self,
# Close the figure
plt.close()

def _remove_tmpdirs(self):
'''
Removes tmpdirs
'''

all_outdirs = [calc.parameters.get('outdir', None) for calc in self.calculations]
outdirs = set([o.resolve() for o in all_outdirs if o is not None and o.resolve().exists()])
for outdir in outdirs:
shutil.rmtree(outdir)

def _teardown(self):
'''
Performs final tasks before the workflow completes
'''

# Removing tmpdirs
if not self.parameters.keep_tmpdirs:
all_outdirs = [calc.parameters.get('outdir', None) for calc in self.calculations]
outdirs = set([o.resolve() for o in all_outdirs if o is not None and o.resolve().exists()])
for outdir in outdirs:
shutil.rmtree(outdir)
self._remove_tmpdirs()


def get_version(module):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"nbnd": 5,
"ecutrho": 80.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 80.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 80.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"nbnd": 5,
"ecutrho": 80.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 80.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 80.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"nbnd": 5,
"ecutrho": 80.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 80.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 80.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"nbnd": 5,
"ecutrho": 120.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 120.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 120.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"nbnd": 5,
"ecutrho": 120.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 120.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 120.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"nbnd": 5,
"ecutrho": 120.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 120.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"nbnd": 5,
"ecutrho": 120.0,
"pseudopotentials": {
"H": "H_ONCV_PBE-1.2.upf",
"O": "O_ONCV_PBE-1.2.upf"
"O": "O_ONCV_PBE-1.2.upf",
"H": "H_ONCV_PBE-1.2.upf"
},
"pseudo_dir": {
"__path__": "../../../../../pseudos/sg15_v1.2/pbe"
Expand Down
Loading