From 5375d073ebe0a35abf0f5c5f87c8f1e909eba777 Mon Sep 17 00:00:00 2001 From: leothan Date: Wed, 18 Jun 2025 13:02:54 -0500 Subject: [PATCH 1/8] change to unwrap_inputs round to 16 decimal places was added --- src/python/friendzone/utils/unwrap_inputs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/friendzone/utils/unwrap_inputs.py b/src/python/friendzone/utils/unwrap_inputs.py index f79278e..4db959b 100644 --- a/src/python/friendzone/utils/unwrap_inputs.py +++ b/src/python/friendzone/utils/unwrap_inputs.py @@ -27,7 +27,7 @@ def _compare_mol_and_point(mol, points): point_i = points.at(i) for j in range(3): - if atom_i.coord(j) != point_i.coord(j): + if round(atom_i.coord(j),16) != round(point_i.coord(j),16): return False return True From 2c6c0d546ed17cffaa7baae406476aba92025b7b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 18 Jun 2025 18:04:09 +0000 Subject: [PATCH 2/8] Committing clang-format changes --- src/python/friendzone/utils/unwrap_inputs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/friendzone/utils/unwrap_inputs.py b/src/python/friendzone/utils/unwrap_inputs.py index 4db959b..4a15b8a 100644 --- a/src/python/friendzone/utils/unwrap_inputs.py +++ b/src/python/friendzone/utils/unwrap_inputs.py @@ -27,7 +27,7 @@ def _compare_mol_and_point(mol, points): point_i = points.at(i) for j in range(3): - if round(atom_i.coord(j),16) != round(point_i.coord(j),16): + if round(atom_i.coord(j), 16) != round(point_i.coord(j), 16): return False return True From d0c108673859f75c62b3796b749d001f7b9bb01f Mon Sep 17 00:00:00 2001 From: leothan Date: Thu, 19 Jun 2025 08:34:36 -0500 Subject: [PATCH 3/8] comparing difference between atom_i.coord(j) and point_i.coord(j) --- src/python/friendzone/utils/unwrap_inputs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/friendzone/utils/unwrap_inputs.py b/src/python/friendzone/utils/unwrap_inputs.py index 4db959b..0ac489c 100644 --- a/src/python/friendzone/utils/unwrap_inputs.py +++ b/src/python/friendzone/utils/unwrap_inputs.py @@ -27,7 +27,7 @@ def _compare_mol_and_point(mol, points): point_i = points.at(i) for j in range(3): - if round(atom_i.coord(j),16) != round(point_i.coord(j),16): + if not(np.isclose(atom_i.coord(j) - point_i.coord(j),0.0)): return False return True From fa320764f14fdbf9d776756baabf82e8c1507069 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 19 Jun 2025 13:39:11 +0000 Subject: [PATCH 4/8] Committing clang-format changes --- src/python/friendzone/utils/unwrap_inputs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/friendzone/utils/unwrap_inputs.py b/src/python/friendzone/utils/unwrap_inputs.py index 0ac489c..19d50be 100644 --- a/src/python/friendzone/utils/unwrap_inputs.py +++ b/src/python/friendzone/utils/unwrap_inputs.py @@ -27,7 +27,7 @@ def _compare_mol_and_point(mol, points): point_i = points.at(i) for j in range(3): - if not(np.isclose(atom_i.coord(j) - point_i.coord(j),0.0)): + if not (np.isclose(atom_i.coord(j) - point_i.coord(j), 0.0)): return False return True From 1426ad8516481f97709cf848b76ea95d9445c4a4 Mon Sep 17 00:00:00 2001 From: leothan Date: Thu, 19 Jun 2025 14:35:58 -0500 Subject: [PATCH 5/8] change done to _compare_mol_and_point to handle differences between floating point arithmetic --- src/python/friendzone/utils/unwrap_inputs.py | 56 +++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/src/python/friendzone/utils/unwrap_inputs.py b/src/python/friendzone/utils/unwrap_inputs.py index 0ac489c..18d3248 100644 --- a/src/python/friendzone/utils/unwrap_inputs.py +++ b/src/python/friendzone/utils/unwrap_inputs.py @@ -13,11 +13,44 @@ # limitations under the License. from simde import TotalEnergy, EnergyNuclearGradientStdVectorD +import numpy as np +import numpy as np -def _compare_mol_and_point(mol, points): - """This function is essentially a work around for the comparisons not being - exposed to Python. +def _compare_mol_and_point(mol, points, atol=1e-12, rtol=0.0): + """ + Compare the 3D nuclear coordinates of a Molecule and a PointSet. + + This function is intended to ensure that gradient calculations + are being performed at the correct molecular geometry. + + Parameters + ---------- + mol : chemist.Molecule + The molecule whose nuclear coordinates are being compared. + + points : chemist.PointSet + The point set to compare against (usually created from the molecule's nuclei). + + atol : float, optional + Absolute tolerance used by np.isclose. Default is 1e-12. + This catches numerical noise due to Python/C++ floating-point boundary. + + rtol : float, optional + Relative tolerance used by np.isclose. Default is 0.0 (disabled), + which ensures no scaling with magnitude — appropriate for comparing coordinates. + + Returns + ------- + bool + True if all coordinate components match within the given tolerances. + False otherwise. + + Notes + ----- + Exact floating-point equality is not used because of small differences + (e.g., ~1e-314) introduced by Python/C++ interoperability. These are + not chemically meaningful and should be tolerated with a small `atol`. """ if mol.size() != points.size(): return False @@ -27,13 +60,22 @@ def _compare_mol_and_point(mol, points): point_i = points.at(i) for j in range(3): - if not(np.isclose(atom_i.coord(j) - point_i.coord(j),0.0)): - return False + a = atom_i.coord(j) + b = point_i.coord(j) + + if rtol == 0.0 and atol == 0.0: + # Strict comparison: values must be bitwise identical + if a != b: + return False + else: + # Use np.isclose to allow for floating-point tolerance + if not np.isclose(a, b, rtol=rtol, atol=atol): + return False return True -def unwrap_inputs(pt, inputs): +def unwrap_inputs(pt, inputs,atol=1e-12,rtol=0.0 ): """ Code factorization for unwrapping a module's inputs. Many of our friends expose interfaces which are analogous to high-level @@ -58,4 +100,4 @@ def unwrap_inputs(pt, inputs): raise RuntimeError('Property type: ' + str(pt.type()) + ' is not registered') - return mol + return mol \ No newline at end of file From ad5482322909293c3e5af735f43d07badd8b008f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 19 Jun 2025 19:41:01 +0000 Subject: [PATCH 6/8] Committing clang-format changes --- src/python/friendzone/utils/unwrap_inputs.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/python/friendzone/utils/unwrap_inputs.py b/src/python/friendzone/utils/unwrap_inputs.py index a551c2b..c81d99f 100644 --- a/src/python/friendzone/utils/unwrap_inputs.py +++ b/src/python/friendzone/utils/unwrap_inputs.py @@ -17,6 +17,7 @@ import numpy as np + def _compare_mol_and_point(mol, points, atol=1e-12, rtol=0.0): """ Compare the 3D nuclear coordinates of a Molecule and a PointSet. @@ -75,7 +76,7 @@ def _compare_mol_and_point(mol, points, atol=1e-12, rtol=0.0): return True -def unwrap_inputs(pt, inputs,atol=1e-12,rtol=0.0 ): +def unwrap_inputs(pt, inputs, atol=1e-12, rtol=0.0): """ Code factorization for unwrapping a module's inputs. Many of our friends expose interfaces which are analogous to high-level @@ -100,4 +101,4 @@ def unwrap_inputs(pt, inputs,atol=1e-12,rtol=0.0 ): raise RuntimeError('Property type: ' + str(pt.type()) + ' is not registered') - return mol \ No newline at end of file + return mol From 0bc952218d1741f846187c29f844d55e5a4f667c Mon Sep 17 00:00:00 2001 From: leothan Date: Thu, 19 Jun 2025 15:55:48 -0500 Subject: [PATCH 7/8] numpy was being called twice, now is done once --- src/python/friendzone/utils/unwrap_inputs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/python/friendzone/utils/unwrap_inputs.py b/src/python/friendzone/utils/unwrap_inputs.py index a551c2b..586605a 100644 --- a/src/python/friendzone/utils/unwrap_inputs.py +++ b/src/python/friendzone/utils/unwrap_inputs.py @@ -15,7 +15,6 @@ from simde import TotalEnergy, EnergyNuclearGradientStdVectorD import numpy as np -import numpy as np def _compare_mol_and_point(mol, points, atol=1e-12, rtol=0.0): """ From 50d5d5f36b537ac50783399d183a36a84ef7252a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 19 Jun 2025 20:56:41 +0000 Subject: [PATCH 8/8] Committing clang-format changes --- src/python/friendzone/utils/unwrap_inputs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/python/friendzone/utils/unwrap_inputs.py b/src/python/friendzone/utils/unwrap_inputs.py index d1115d9..71d3a25 100644 --- a/src/python/friendzone/utils/unwrap_inputs.py +++ b/src/python/friendzone/utils/unwrap_inputs.py @@ -16,7 +16,6 @@ import numpy as np - def _compare_mol_and_point(mol, points, atol=1e-12, rtol=0.0): """ Compare the 3D nuclear coordinates of a Molecule and a PointSet.