Skip to content

Commit 8649c92

Browse files
committed
Remove deprecated arguments and methods. Rename atom_to_site_cost_future to atom_to_site_cost.
1 parent 532d7d6 commit 8649c92

12 files changed

Lines changed: 49 additions & 468 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
### Changed
2121

22-
- **Breaking change**: Custom `atom_to_site_cost_f` and `atom_to_site_cost_future_f` functions passed to `libcasm.mapping.mapsearch.MappingSearch` or `libcasm.mapping.mapsearch.AtomMappingSearchData` constructors must now accept `libcasm.mapping.mapsearch.LatticeMappingSearchData` as the first parameter instead of `libcasm.xtal.Lattice`. This provides access to the full lattice mapping context including the deformation gradient. The built-in cost functions `libcasm.mapping.mapsearch.make_atom_to_site_cost` and `libcasm.mapping.mapsearch.make_atom_to_site_cost_future` have been updated accordingly.
23-
- Changed `libcasm.mapping.mapsearch.make_atom_to_site_cost_future` so that the displacement cost is calculated using the mean of the parent-to-child and child-to-parent costs, rather than just the parent-to-child cost. This makes the cost function symmetric with respect to swapping the parent and child structures.
22+
- **Breaking change**: Removed `atom_to_site_cost_future_f` arguments. Custom `atom_to_site_cost_f` functions passed to `libcasm.mapping.mapsearch.MappingSearch` or `libcasm.mapping.mapsearch.AtomMappingSearchData` constructors must now accept `libcasm.mapping.mapsearch.LatticeMappingSearchData` as the first parameter instead of `libcasm.xtal.Lattice`. This provides access to the full lattice mapping context including the deformation gradient. The built-in cost function `libcasm.mapping.mapsearch.make_atom_to_site_cost` has been updated accordingly.
23+
- Renamed `libcasm.mapping.mapsearch.make_atom_to_site_cost_future` to replace `libcasm.mapping.mapsearch.make_atom_to_site_cost`
24+
- Changed `libcasm.mapping.mapsearch.make_atom_to_site_cost` so that the displacement cost is calculated using the mean of the parent-to-child and child-to-parent costs, rather than just the parent-to-child cost. This makes the cost function symmetric with respect to swapping the parent and child structures.
2425
- Thread safety updates in casm/mapping/impl/ to StrainCostCalculator, LatticeMap, MappingNode, and StrucMapper.
2526

27+
### Removed
28+
29+
- Removed deprecatd mapping_impl::LatticeNode constructors. Use standalone methods to calculate LatticeNode members instead.
30+
2631

2732
## [2.4.1] - 2026-02-25
2833

include/casm/mapping/MappingSearch.hh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,13 @@ MappingNode make_mapping_node(
162162
/// \brief Performs structure mapping searches
163163
struct MappingSearch {
164164
/// \brief Constructor
165-
MappingSearch(double _min_cost = 0.0, double _max_cost = 1e20,
166-
int _k_best = 1,
167-
AtomCostFunction _atom_cost_f = IsotropicAtomCost(),
168-
TotalCostFunction _total_cost_f = WeightedTotalCost(0.5),
169-
AtomToSiteCostFunction _atom_to_site_cost_f =
170-
make_atom_to_site_cost_future,
171-
bool _enable_remove_mean_displacement = true,
172-
double _infinity = 1e20, double _cost_tol = 1e-5);
165+
MappingSearch(
166+
double _min_cost = 0.0, double _max_cost = 1e20, int _k_best = 1,
167+
AtomCostFunction _atom_cost_f = IsotropicAtomCost(),
168+
TotalCostFunction _total_cost_f = WeightedTotalCost(0.5),
169+
AtomToSiteCostFunction _atom_to_site_cost_f = make_atom_to_site_cost,
170+
bool _enable_remove_mean_displacement = true, double _infinity = 1e20,
171+
double _cost_tol = 1e-5);
173172

174173
/// \brief A queue of structure mappings, sorted by total
175174
/// cost only

include/casm/mapping/SearchData.hh

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,25 +224,9 @@ using AtomToSiteCostFunction = std::function<double(
224224
Eigen::Vector3d const &displacement, std::string const &atom_type,
225225
std::vector<std::string> const &allowed_atom_types, double infinity)>;
226226

227-
/// \brief A function, such as `make_atom_to_site_cost`,
228-
/// which calculates the atom-to-site mapping cost given the
229-
/// lattice in which the displacements are calculated under
230-
/// periodic boundary conditions, the site-to-atom
231-
/// displacement, atom_type, allowed_atom_types,
232-
/// and value to use for unallowed mappings (infinity).
233-
using DispOnlyAtomToSiteCostFunction = std::function<double(
234-
Eigen::Vector3d const &displacement, std::string const &atom_type,
235-
std::vector<std::string> const &allowed_atom_types, double infinity)>;
236-
237227
/// \brief Make the mapping cost for a particular atom
238228
/// to a particular structure site
239229
double make_atom_to_site_cost(
240-
Eigen::Vector3d const &displacement, std::string const &atom_type,
241-
std::vector<std::string> const &allowed_atom_types, double infinity);
242-
243-
/// \brief Make the mapping cost for a particular atom
244-
/// to a particular structure site
245-
double make_atom_to_site_cost_future(
246230
LatticeMappingSearchData const &lattice_mapping_data,
247231
Eigen::Vector3d const &displacement, std::string const &atom_type,
248232
std::vector<std::string> const &allowed_atom_types, double infinity);
@@ -255,8 +239,7 @@ struct AtomMappingSearchData {
255239
AtomMappingSearchData(
256240
std::shared_ptr<LatticeMappingSearchData const> _lattice_mapping_data,
257241
Eigen::Vector3d const &_trial_translation_cart,
258-
AtomToSiteCostFunction _atom_to_site_cost_f =
259-
make_atom_to_site_cost_future,
242+
AtomToSiteCostFunction _atom_to_site_cost_f = make_atom_to_site_cost,
260243
double _infinity = 1e20);
261244

262245
/// \brief Holds lattice mapping-specific data used

include/casm/mapping/impl/StrucMapping.hh

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,6 @@ struct LatticeNode { // Note: See full description in StrucMapping.cc
158158
LatticeNode(xtal::Superlattice parent, xtal::Superlattice child,
159159
Eigen::Matrix3d stretch, Eigen::Matrix3d isometry, double cost,
160160
std::string cost_method);
161-
162-
// TODO: We should prefer putting the logic of how LatticeNode members are
163-
// calculated in standalone methods rather than constructors...
164-
165-
/// \brief Construct a LatticeNode by calculating the deformation tensor that
166-
/// maps a particular child superlattice to a particular parent superlattice
167-
/// [deprecated]
168-
LatticeNode(xtal::Lattice const &parent_prim,
169-
xtal::Lattice const &parent_scel,
170-
xtal::Lattice const &unmapped_child_prim,
171-
xtal::Lattice const &unmapped_child_scel, Index child_N_atom,
172-
double _cost = big_inf());
173-
174-
/// \brief Construct a LatticeNode using the mapping calculated by LatticeMap
175-
/// [deprecated]
176-
LatticeNode(LatticeMap const &lattice_map, xtal::Lattice const &parent_prim,
177-
xtal::Lattice const &unmapped_child_prim);
178161
};
179162

180163
/// \brief Construct a LatticeNode by calculating the deformation tensor that

python/libcasm/mapping/mapsearch/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
SymmetryBreakingAtomCost,
1313
WeightedTotalCost,
1414
make_atom_to_site_cost,
15-
make_atom_to_site_cost_future,
1615
make_superstructure_data,
1716
make_trial_translations,
1817
)

python/src/mapping_mapsearch.cpp

Lines changed: 11 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -30,64 +30,33 @@ MappingSearch make_MappingSearch(
3030
double _min_cost, double _max_cost, int _k_best,
3131
std::optional<AtomCostFunction> _atom_cost_f,
3232
std::optional<TotalCostFunction> _total_cost_f,
33-
std::optional<DispOnlyAtomToSiteCostFunction> _atom_to_site_cost_f,
34-
bool _enable_remove_mean_displacement, double _infinity, double _cost_tol,
35-
std::optional<AtomToSiteCostFunction> _atom_to_site_cost_future_f) {
33+
std::optional<AtomToSiteCostFunction> _atom_to_site_cost_f,
34+
bool _enable_remove_mean_displacement, double _infinity, double _cost_tol) {
3635
if (!_atom_cost_f) {
3736
_atom_cost_f = IsotropicAtomCost();
3837
}
3938
if (!_total_cost_f) {
4039
_total_cost_f = WeightedTotalCost(0.5);
4140
}
42-
AtomToSiteCostFunction f;
43-
if (_atom_to_site_cost_future_f) {
44-
f = _atom_to_site_cost_future_f.value();
45-
} else {
46-
if (!_atom_to_site_cost_f) {
47-
_atom_to_site_cost_f =
48-
DispOnlyAtomToSiteCostFunction(make_atom_to_site_cost);
49-
}
50-
// convert to AtomToSiteCostFunction
51-
f = [_atom_to_site_cost_f](
52-
LatticeMappingSearchData const &lattice_mapping_data,
53-
Eigen::Vector3d const &displacement, std::string const &atom_type,
54-
std::vector<std::string> const &allowed_atom_types,
55-
double infinity) {
56-
return _atom_to_site_cost_f.value()(displacement, atom_type,
57-
allowed_atom_types, infinity);
58-
};
41+
if (!_atom_to_site_cost_f) {
42+
_atom_to_site_cost_f = make_atom_to_site_cost;
5943
}
6044
return MappingSearch(_min_cost, _max_cost, _k_best, _atom_cost_f.value(),
61-
_total_cost_f.value(), f,
45+
_total_cost_f.value(), _atom_to_site_cost_f.value(),
6246
_enable_remove_mean_displacement, _infinity, _cost_tol);
6347
}
6448

6549
std::shared_ptr<AtomMappingSearchData> make_AtomMappingSearchData(
6650
std::shared_ptr<LatticeMappingSearchData const> lattice_mapping_data,
6751
Eigen::Vector3d const &trial_translation_cart,
68-
std::optional<DispOnlyAtomToSiteCostFunction> _atom_to_site_cost_f,
69-
double infinity,
70-
std::optional<AtomToSiteCostFunction> _atom_to_site_cost_future_f) {
71-
AtomToSiteCostFunction f;
72-
if (_atom_to_site_cost_future_f) {
73-
f = _atom_to_site_cost_future_f.value();
74-
} else {
75-
if (!_atom_to_site_cost_f) {
76-
_atom_to_site_cost_f =
77-
DispOnlyAtomToSiteCostFunction(make_atom_to_site_cost);
78-
}
79-
// convert to AtomToSiteCostFunction
80-
f = [_atom_to_site_cost_f](
81-
LatticeMappingSearchData const &lattice_mapping_data,
82-
Eigen::Vector3d const &displacement, std::string const &atom_type,
83-
std::vector<std::string> const &allowed_atom_types,
84-
double infinity) {
85-
return _atom_to_site_cost_f.value()(displacement, atom_type,
86-
allowed_atom_types, infinity);
87-
};
52+
std::optional<AtomToSiteCostFunction> _atom_to_site_cost_f,
53+
double infinity) {
54+
if (!_atom_to_site_cost_f) {
55+
_atom_to_site_cost_f = make_atom_to_site_cost;
8856
}
8957
return std::make_shared<AtomMappingSearchData>(
90-
lattice_mapping_data, trial_translation_cart, f, infinity);
58+
lattice_mapping_data, trial_translation_cart,
59+
_atom_to_site_cost_f.value(), infinity);
9160
}
9261

9362
} // namespace CASMpy
@@ -499,60 +468,12 @@ PYBIND11_MODULE(_mapping_mapsearch, m) {
499468
)pbdoc");
500469

501470
m.def("make_atom_to_site_cost", &make_atom_to_site_cost,
502-
py::arg("displacement"), py::arg("atom_type"),
503-
py::arg("allowed_atom_types"), py::arg("infinity"),
504-
R"pbdoc(
505-
Returns the cost for mapping a particular atom to a particular site
506-
507-
508-
.. deprecated:: 2.3.0
509-
The :func:`make_atom_to_site_cost_future` method, which takes
510-
`lattice` as a parameter, is planned to replace this
511-
method in libcasm-mapping>=3.0.0.
512-
513-
The mapping cost:
514-
515-
- of a vacancy to any site that allows vacancies is set to
516-
0.0.
517-
- of an atom to a site that does not allow the atom type is
518-
infinity
519-
- otherwise, the mapping cost is equal to displacement length
520-
squared
521-
522-
Notes
523-
-----
524-
Atoms are treated as vacancies if they are named \"Va\", \"VA\",
525-
or \"va\".
526-
527-
Parameters
528-
----------
529-
displacement : array_like, shape=(3,)
530-
The minimum length displacement, accounting for periodic
531-
boundaries, from the site to the atom.
532-
atom_type : str,
533-
The atom (or vacancy) type.
534-
allowed_atom_types : List[str]
535-
The atom (or vacancy) types allowed on the site.
536-
infinity: float
537-
The value to use for the cost of unallowed mappings
538-
539-
Returns
540-
-------
541-
cost : float
542-
The atom (or vacancy) mapping cost.
543-
)pbdoc");
544-
545-
m.def("make_atom_to_site_cost_future", &make_atom_to_site_cost_future,
546471
py::arg("lattice_mapping_data"), py::arg("displacement"),
547472
py::arg("atom_type"), py::arg("allowed_atom_types"),
548473
py::arg("infinity"),
549474
R"pbdoc(
550475
Returns the cost for mapping a particular atom to a particular site
551476
552-
.. deprecated:: 2.3.0
553-
This method is planned to replace :func:`make_atom_to_site_cost` in
554-
libcasm-mapping>=3.0.0, and this method will be removed.
555-
556477
The mapping cost:
557478
558479
- of a vacancy to any site that allows vacancies is set to
@@ -642,7 +563,6 @@ PYBIND11_MODULE(_mapping_mapsearch, m) {
642563
py::arg("lattice_mapping_data"), py::arg("trial_translation_cart"),
643564
py::arg("atom_to_site_cost_f") = std::nullopt,
644565
py::arg("infinity") = 1e20,
645-
py::arg("atom_to_site_cost_future_f") = std::nullopt,
646566
R"pbdoc(
647567
.. rubric:: Constructor
648568
@@ -662,30 +582,8 @@ PYBIND11_MODULE(_mapping_mapsearch, m) {
662582
particular site. Expected to match the same signature as
663583
:func:`~libcasm.mapping.mapsearch.make_atom_to_site_cost`, which
664584
is the default method.
665-
666-
.. deprecated:: 2.3.0
667-
The signature of
668-
:func:`~libcasm.mapping.mapsearch.make_atom_to_site_cost`
669-
will change in libcasm-mapping>=3.0.0 to accept the lattice
670-
used for finding the displacements under periodic boundary
671-
conditions. The function
672-
:func:`~libcasm.mapping.mapsearch.make_atom_to_site_cost_future`
673-
will be used as the default.
674-
675585
infinity : float = 1e20
676586
The value to use for the cost of unallowed mappings.
677-
678-
atom_to_site_cost_future_f : Optional[Callable] = None
679-
A function used to calculate the cost of mapping an atom to a
680-
particular site. Expected to match the same signature as
681-
:func:`~libcasm.mapping.mapsearch.make_atom_to_site_cost_future`.
682-
If provided, this function will be used with priority over
683-
`atom_to_site_cost_f`.
684-
685-
.. deprecated:: 2.3.0
686-
This argument will be removed in libcasm-mapping>=3.0.0.
687-
688-
689587
)pbdoc")
690588
.def(
691589
"lattice_mapping_data",
@@ -1110,7 +1008,6 @@ PYBIND11_MODULE(_mapping_mapsearch, m) {
11101008
py::arg("atom_to_site_cost_f") = std::nullopt,
11111009
py::arg("enable_remove_mean_displacement") = true,
11121010
py::arg("infinity") = 1e20, py::arg("cost_tol") = 1e-5,
1113-
py::arg("atom_to_site_cost_future_f") = std::nullopt,
11141011
R"pbdoc(
11151012
.. rubric:: Constructor
11161013
@@ -1153,16 +1050,6 @@ PYBIND11_MODULE(_mapping_mapsearch, m) {
11531050
particular site. Expected to match the same signature as
11541051
:func:`~libcasm.mapping.mapsearch.make_atom_to_site_cost`, which
11551052
is the default method.
1156-
1157-
.. deprecated:: 2.3.0
1158-
The signature of
1159-
:func:`~libcasm.mapping.mapsearch.make_atom_to_site_cost`
1160-
will change in libcasm-mapping>=3.0.0 to accept the lattice
1161-
used for finding the displacements under periodic boundary
1162-
conditions. The function
1163-
:func:`~libcasm.mapping.mapsearch.make_atom_to_site_cost_future`
1164-
will be used as the default.
1165-
11661053
enable_remove_mean_displacement : bool = True
11671054
If true, the translation and displacements of an atom
11681055
mapping are adjusted consistently so that the mean displacment
@@ -1172,16 +1059,6 @@ PYBIND11_MODULE(_mapping_mapsearch, m) {
11721059
unallowed atom-to-site mappings.
11731060
cost_tol : float = 1e-5
11741061
Tolerance for checking if mapping costs are approximately equal.
1175-
atom_to_site_cost_future_f : Optional[Callable] = None
1176-
A function used to calculate the cost of mapping an atom to a
1177-
particular site. Expected to match the same signature as
1178-
:func:`~libcasm.mapping.mapsearch.make_atom_to_site_cost_future`.
1179-
If provided, this function will be used with priority over
1180-
`atom_to_site_cost_f`.
1181-
1182-
.. deprecated:: 2.3.0
1183-
This argument will be removed in libcasm-mapping>=3.0.0.
1184-
11851062
)pbdoc")
11861063
.def_readonly("min_cost", &MappingSearch::min_cost,
11871064
"float: Keep mappings with total cost >= min_cost.")

python/tests/test_MappingNode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def mapping_search():
4646
k_best=10,
4747
atom_cost_f=mapsearch.IsotropicAtomCost(),
4848
total_cost_f=mapsearch.WeightedTotalCost(lattice_cost_weight=0.5),
49-
atom_to_site_cost_future_f=mapsearch.make_atom_to_site_cost_future,
49+
atom_to_site_cost_f=mapsearch.make_atom_to_site_cost,
5050
enable_remove_mean_displacement=False,
5151
infinity=1e20,
5252
cost_tol=1e-5,
@@ -433,7 +433,7 @@ def test_mapping_node_comparison(hcp_search_data, mapping_search):
433433
k_best=100,
434434
atom_cost_f=mapsearch.IsotropicAtomCost(),
435435
total_cost_f=mapsearch.WeightedTotalCost(lattice_cost_weight=0.5),
436-
atom_to_site_cost_future_f=mapsearch.make_atom_to_site_cost_future,
436+
atom_to_site_cost_f=mapsearch.make_atom_to_site_cost,
437437
enable_remove_mean_displacement=False,
438438
infinity=1e20,
439439
cost_tol=1e-5,

0 commit comments

Comments
 (0)