Skip to content

Commit

Permalink
Allow modcell function to be used for relax task
Browse files Browse the repository at this point in the history
This allow arbitrary modifications to be apply just before the cell
file content is sent off.
  • Loading branch information
zhubonan committed Jul 8, 2022
1 parent 6b18da2 commit 5970db3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion disp/cli/cmd_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,16 @@ def deploy_search(lpad, code, seed, project, num, exe, cycles, keep, wf_name,
show_default=True,
help='Code to use for relaxation',
default='castep')
@click.option(
'--modcell',
help=
'Function to be used to modified to cell file. Such function should receives a list of lines and return a new list of lines.'
)
@click.option('--cluster', is_flag=True, default=False)
@pass_lpad
def deploy_relax(lpad, code, seed, cell, base_cell, param, project, exe,
cycles, keep, dryrun, priority, gzip, record_db, category,
cluster, extra_cell_file, castep_code):
cluster, extra_cell_file, castep_code, modcell):
"""
Deploy a workflow to do relaxation of a particular structure
"""
Expand Down Expand Up @@ -323,6 +328,21 @@ def deploy_relax(lpad, code, seed, cell, base_cell, param, project, exe,
else:
cell_content = cell_from_file(str(cell_path))

# Allow a custom python function to be used to modified the cell
if modcell is not None:
tokens = modcell.split(':')
if len(tokens) == 2:
func_name = tokens[1]
mod = __import__(tokens[0].replace('.py', ''), globals(),
locals(), [str(func_name)], 0)
modfunc = getattr(mod, func_name)
else:
raise ValueError(
'--modcell options should be in the format of `filename:func`.'
)
# Apply the function
cell_content = '\n'.join(modfunc(cell_content.split('\n')))

# Apply extra cell lines if necessary
if extra_cell_content:
cell_content += '\n' + extra_cell_content
Expand Down

0 comments on commit 5970db3

Please sign in to comment.