Skip to content

Commit

Permalink
Merge pull request #303 from libAtoms/cli_eval_kwargs
Browse files Browse the repository at this point in the history
enable additional kwargs for "wfl eval <potential> ..."
  • Loading branch information
bernstei authored Apr 25, 2024
2 parents d493fa8 + 6cc6a22 commit 9526496
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
11 changes: 11 additions & 0 deletions wfl/cli/cli_options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
import json
from wfl.configset import ConfigSet, OutputSpec
from ase.io.extxyz import key_val_str_to_dict

Expand Down Expand Up @@ -38,6 +39,16 @@ def param_fname(f):
f = click.option("--param-fname", "-pf", type=click.Path(), help="Path to the potential parameter file")(f)
return f

def _parse_kwargs(ctx, param, value):
if value is not None:
return json.loads(value)
else:
return {}

def kwargs(f):
f = click.option("--kwargs", "-kw", callback=_parse_kwargs, help="JSON text with additional Calculator constructor kwargs")(f)
return f

def prop_prefix(f):
f = click.option("--prop-prefix", "-pp", help='Prefix to be pre-pended to all evaluate properties. '
'Defaults to "gap_"/"ace_"/"mace_" as appropriate')(f)
Expand Down
19 changes: 13 additions & 6 deletions wfl/cli/commands/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ def pyjulip_ace(param_fname):
@opt.inputs
@opt.outputs
@opt.param_fname
@opt.kwargs
@opt.prop_prefix
@opt.num_inputs_per_python_subprocess
def gap(ctx, inputs, outputs, param_fname, prop_prefix, num_inputs_per_python_subprocess):
def gap(ctx, inputs, outputs, param_fname, kwargs, prop_prefix, num_inputs_per_python_subprocess):
"""evaluates GAP"""

from quippy.potential import Potential

if prop_prefix is None:
prop_prefix = "gap_"

calc = (Potential, [], {"param_filename": param_fname})
kwargs_use = {"param_filename": param_fname}
kwargs_use.update(kwargs)
calc = (Potential, [], kwargs_use)

generic.calculate(
inputs=inputs,
Expand All @@ -41,15 +44,16 @@ def gap(ctx, inputs, outputs, param_fname, prop_prefix, num_inputs_per_python_su
@opt.inputs
@opt.outputs
@opt.param_fname
@opt.kwargs
@opt.prop_prefix
@opt.num_inputs_per_python_subprocess
def ace(ctx, inputs, outputs, param_fname, prop_prefix, num_inputs_per_python_subprocess):
def ace(ctx, inputs, outputs, param_fname, kwargs, prop_prefix, num_inputs_per_python_subprocess):
"""evaluates ACE"""

if prop_prefix is None:
prop_prefix = 'ace_'

calc = (pyjulip_ace, [param_fname], {})
calc = (pyjulip_ace, [param_fname], kwargs)

generic.calculate(
inputs=inputs,
Expand All @@ -64,17 +68,20 @@ def ace(ctx, inputs, outputs, param_fname, prop_prefix, num_inputs_per_python_su
@opt.inputs
@opt.outputs
@opt.param_fname
@opt.kwargs
@opt.prop_prefix
@opt.num_inputs_per_python_subprocess
def mace(ctx, inputs, outputs, param_fname, prop_prefix, num_inputs_per_python_subprocess):
def mace(ctx, inputs, outputs, param_fname, kwargs, prop_prefix, num_inputs_per_python_subprocess):
"""evaluates MACE"""

from mace.calculators import MACECalculator

if prop_prefix is None:
prop_prefix = 'mace_'

calc = (MACECalculator, [], {"model_paths": param_fname, "device": "cpu"})
kwargs_use = {"model_paths": param_fname, "device": "cpu"}
kwargs_use.update(kwargs)
calc = (MACECalculator, [], kwargs_use)

generic.calculate(
inputs=inputs,
Expand Down
6 changes: 5 additions & 1 deletion wfl/generate/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def _run_autopara_wrappable(atoms, calculator, fmax=1.0e-3, smax=None, steps=100

if keep_symmetry:
# noinspection PyUnresolvedReferences,PyUnresolvedReferences
from ase.spacegroup.symmetrize import FixSymmetry
try:
from ase.constraints import FixSymmetry
except ImportError:
# fall back to previous import location (pre MR 3288)
from ase.spacegroup.symmetrize import FixSymmetry

all_trajs = []

Expand Down

0 comments on commit 9526496

Please sign in to comment.