Skip to content

Commit

Permalink
cli: support for feff calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Sep 19, 2022
1 parent 43a22fb commit 0462eae
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions emmet-cli/emmet/cli/utils.py
Expand Up @@ -9,6 +9,7 @@
from enum import Enum
from fnmatch import fnmatch
from glob import glob
from pathlib import Path

import click
import mgzip
Expand Down Expand Up @@ -149,10 +150,14 @@ def get_timestamp_dir(prefix="launcher"):
return "_".join([prefix, time_now])


def is_vasp_dir(list_of_files):
def get_dir_type(list_of_files):
for f in list_of_files:
if f.startswith("INCAR"):
return True
return "vasp"
elif f.startswith("feff.inp"):
return "feff"
else:
return None


def make_block(base_path):
Expand Down Expand Up @@ -188,19 +193,26 @@ def get_symlinked_path(root, base_path_index):
launch_dir = os.path.join(block_dir, root_split[-1])
if not os.path.exists(launch_dir):
if run:
os.rename(root, launch_dir)
rename_dir(root, launch_dir)
logger.debug(f"{root} -> {launch_dir}")
else:
launch = get_timestamp_dir(prefix="launcher")
launch_dir = os.path.join(block_dir, launch)
if run:
os.rename(root, launch_dir)
os.symlink(launch_dir, root)
rename_dir(root, launch_dir)
logger.debug(f"{root} -> {launch_dir}")

return launch_dir


def rename_dir(root, launch_dir):
fn = "ORIG_PATH"
with Path(os.sep.join([root, fn])).open("w") as f:
f.write(root)

os.rename(root, launch_dir)


def create_orig_inputs(vaspdir):
ctx = click.get_current_context()
run = ctx.parent.parent.params["run"]
Expand Down Expand Up @@ -254,7 +266,9 @@ def get_vasp_dirs():
if not bool(st.st_mode & perms):
raise EmmetCliError(f"Insufficient permissions {st.st_mode} for {dn}.")

if is_vasp_dir(files):
dir_type = get_dir_type(files)

if dir_type:
gzipped = False
for f in files:
fn = os.path.join(root, f)
Expand All @@ -272,7 +286,7 @@ def get_vasp_dirs():
f"Insufficient permissions {st.st_mode} for {fn}."
)

if run and not f.endswith(".gz"):
if run and dir_type == "vasp" and not f.endswith(".gz"):
fn_gz = fn + ".gz"
if os.path.exists(fn_gz):
os.remove(fn_gz) # remove left-over gz (cancelled job)
Expand All @@ -288,7 +302,9 @@ def get_vasp_dirs():

# NOTE skip symlink'ing on MP calculations from the early days
vasp_dir = get_symlinked_path(root, base_path_index) if reorg else root
create_orig_inputs(vasp_dir)
if dir_type == "vasp":
create_orig_inputs(vasp_dir)

dirs[:] = [] # don't descend further (i.e. ignore relax1/2)
logger.log(logging.INFO if gzipped else logging.DEBUG, vasp_dir)
yield vasp_dir
Expand Down

0 comments on commit 0462eae

Please sign in to comment.