Skip to content
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
18 changes: 0 additions & 18 deletions janus_core/calculations/geom_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class GeomOpt(BaseCalculation):
filter_class
Filter class, or name of class from ase.filters to wrap around atoms.
Default is `FrechetCellFilter`.
filter_func
Deprecated. Please use `filter_class`.
filter_kwargs
Keyword arguments to pass to filter_class. Default is {}.
optimizer
Expand Down Expand Up @@ -117,7 +115,6 @@ def __init__(
symmetry_tolerance: float = 0.001,
angle_tolerance: float = -1.0,
filter_class: Callable | str | None = FrechetCellFilter,
filter_func: Callable | str | None = None,
filter_kwargs: dict[str, Any] | None = None,
optimizer: Callable | str = LBFGS,
opt_kwargs: ASEOptArgs | None = None,
Expand Down Expand Up @@ -173,8 +170,6 @@ def __init__(
filter_class
Filter class, or name of class from ase.filters to wrap around atoms.
Default is `FrechetCellFilter`.
filter_func
Deprecated. Please use `filter_class`.
filter_kwargs
Keyword arguments to pass to filter_class. Default is {}.
optimizer
Expand All @@ -200,10 +195,6 @@ def __init__(
)
)

# Handle deprecated filter_func, but warn later after logging is set up
if filter_func:
filter_class = filter_func

self.fmax = fmax
self.steps = steps
self.symmetrize = symmetrize
Expand Down Expand Up @@ -242,15 +233,6 @@ def __init__(
if not self.struct.calc:
raise ValueError("Please attach a calculator to `struct`.")

# Warn for deprecated filter_func now that logging is set up
if filter_func:
warnings.warn(
"`filter_func` has been deprecated, but currently overrides "
"`filter_class`. Please only set `filter_class`.",
FutureWarning,
stacklevel=2,
)

# Set output files
self.write_kwargs["filename"] = self._build_filename(
"opt.extxyz", filename=self.write_kwargs.get("filename")
Expand Down
20 changes: 2 additions & 18 deletions janus_core/cli/geomopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Tracker,
WriteKwargs,
)
from janus_core.cli.utils import deprecated_option, yaml_converter_callback
from janus_core.cli.utils import yaml_converter_callback

app = Typer()

Expand Down Expand Up @@ -125,15 +125,6 @@ def geomopt(
rich_help_panel="Calculation",
),
] = None,
filter_func: Annotated[
str | None,
Option(
help="Deprecated. Please use --filter",
rich_help_panel="Calculation",
callback=deprecated_option,
hidden=True,
),
] = None,
pressure: Annotated[
float,
Option(
Expand Down Expand Up @@ -216,8 +207,6 @@ def geomopt(
filter_class
Name of filter from ase.filters to wrap around atoms. If using
--opt-cell-lengths or --opt-cell-fully, defaults to `FrechetCellFilter`.
filter_func
Deprecated. Please use `filter_class`.
pressure
Scalar pressure when optimizing cell geometry, in GPa. Passed to the filter
function if either `opt_cell_lengths` or `opt_cell_fully` is True. Default is
Expand Down Expand Up @@ -303,19 +292,14 @@ def geomopt(

_set_minimize_kwargs(minimize_kwargs, opt_cell_lengths, pressure)

if filter_func and filter_class:
raise ValueError("--filter-func is deprecated, please only use --filter")

if opt_cell_fully or opt_cell_lengths:
# Use default filter unless filter explicitly passed
if filter_class:
opt_cell_fully_dict = {"filter_class": filter_class}
elif filter_func:
opt_cell_fully_dict = {"filter_func": filter_func, "filter_class": None}
else:
opt_cell_fully_dict = {}
else:
if filter_class or filter_func:
if filter_class:
raise ValueError(
"--opt-cell-lengths or --opt-cell-fully must be set to use a filter"
)
Expand Down
13 changes: 0 additions & 13 deletions tests/test_geom_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,3 @@ def test_traj_kwargs_new_dir(tmp_path):
assert traj_path.exists()
traj = read(traj_path, index=":")
assert len(traj) == 3


def test_deprecation_filter_func(tmp_path):
"""Test FutureWarning raised for model in calc_kwargs."""
with pytest.warns(FutureWarning, match="`filter_func` has been deprecated"):
geom_opt = GeomOpt(
struct=DATA_PATH / "NaCl.cif",
arch="mace_mp",
model=MODEL_PATH,
fmax=0.001,
filter_func="UnitCellFilter",
)
assert isinstance(geom_opt.filtered_struct, UnitCellFilter)
60 changes: 0 additions & 60 deletions tests/test_geomopt_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,63 +999,3 @@ def test_info(tmp_path):
assert atoms.info["system_name"] == "NaCl"
assert "config_type" in atoms.info
assert atoms.info["config_type"] == "geom_opt"


def test_filter_func_deprecated(tmp_path):
"""Test filter_func sets filter."""
file_prefix = tmp_path / "NaCl"
log_path = tmp_path / "test.log"

result = runner.invoke(
app,
[
"geomopt",
"--struct",
DATA_PATH / "NaCl.cif",
"--arch",
"mace_mp",
"--model",
MACE_PATH,
"--opt-cell-fully",
"--filter-func",
"UnitCellFilter",
"--log",
log_path,
"--file-prefix",
file_prefix,
"--no-tracker",
],
)
assert result.exit_code == 0
assert_log_contains(
log_path,
includes=["Starting geometry optimization", "Using filter: UnitCellFilter"],
)


def test_filter_func_error(tmp_path):
"""Test setting filter_func without --opt-cell-fully or --opt-cell-lengths."""
results_path = tmp_path / "NaCl-opt.extxyz"
log_path = tmp_path / "test.log"
summary_path = tmp_path / "summary.yml"

result = runner.invoke(
app,
[
"geomopt",
"--struct",
DATA_PATH / "NaCl-deformed.cif",
"--arch",
"mace_mp",
"--out",
results_path,
"--filter-func",
"UnitCellFilter",
"--log",
log_path,
"--summary",
summary_path,
],
)
assert result.exit_code == 1
assert isinstance(result.exception, ValueError)