From 58e75818c04fe59deaeebfcd43ed156ceee1a3ad Mon Sep 17 00:00:00 2001 From: Martin <42468905+maabuu@users.noreply.github.com> Date: Fri, 15 Mar 2024 10:11:22 +0000 Subject: [PATCH] Energy ratio bug (#30) * Catch divide-by-zero error in `energy_ratio.py` (#29) * Update version --------- Co-authored-by: Alex Morehead --- posebusters/__init__.py | 2 +- posebusters/modules/energy_ratio.py | 5 +++++ tests/conftest.py | 5 +++++ tests/conftest/mol_disconnected_atoms.sdf | 20 ++++++++++++++++++++ tests/test_modules/test_energy_ratio.py | 5 +++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/conftest/mol_disconnected_atoms.sdf diff --git a/posebusters/__init__.py b/posebusters/__init__.py index 6f06360..0511b74 100644 --- a/posebusters/__init__.py +++ b/posebusters/__init__.py @@ -24,4 +24,4 @@ "check_volume_overlap", ] -__version__ = "0.2.10" +__version__ = "0.2.11" diff --git a/posebusters/modules/energy_ratio.py b/posebusters/modules/energy_ratio.py index 9d32261..a252162 100644 --- a/posebusters/modules/energy_ratio.py +++ b/posebusters/modules/energy_ratio.py @@ -1,4 +1,5 @@ """Module to check energy of ligand conformations.""" + from __future__ import annotations import logging @@ -80,6 +81,10 @@ def check_energy_ratio( logger.warning("Failed to calculate ensemble conformation energy for %s: %s", inchi, e) avg_energy = np.nan + if avg_energy == 0: + logger.warning("Average energy of molecule is 0 for %s", inchi) + avg_energy = np.nan + pred_factor = conf_energy / avg_energy ratio_passes = pred_factor <= threshold_energy_ratio diff --git a/tests/conftest.py b/tests/conftest.py index 9986556..bf4d259 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -180,3 +180,8 @@ def mol_lig_7ztl_bcn(): @pytest.fixture def mol_cond_7ztl_bcn(): return MolFromPDBFile("tests/conftest/7ZTL_BCN/7ZTL_BCN_protein.pdb", sanitize=False, proximityBonding=False) + + +@pytest.fixture +def mol_disconnnected_atoms(): + return MolFromMolFile("tests/conftest/mol_disconnected_atoms.sdf", sanitize=True) diff --git a/tests/conftest/mol_disconnected_atoms.sdf b/tests/conftest/mol_disconnected_atoms.sdf new file mode 100644 index 0000000..62616c5 --- /dev/null +++ b/tests/conftest/mol_disconnected_atoms.sdf @@ -0,0 +1,20 @@ + + RDKit 3D + + 12 0 0 0 0 0 0 0 0 0999 V2000 + -3.8457 60.3869 20.5367 K 0 0 0 0 0 15 0 0 0 0 0 0 + -17.1252 54.3726 26.7594 K 0 0 0 0 0 15 0 0 0 0 0 0 + 29.1964 53.9284 36.4555 Cl 0 0 0 0 0 15 0 0 0 0 0 0 + 6.9173 57.0285 8.5658 K 0 0 0 0 0 15 0 0 0 0 0 0 + 4.3879 73.7718 35.3121 K 0 0 0 0 0 15 0 0 0 0 0 0 + -16.8898 53.9997 26.2540 K 0 0 0 0 0 15 0 0 0 0 0 0 + -16.2661 85.6351 15.9899 Cl 0 0 0 0 0 15 0 0 0 0 0 0 + 24.5865 61.8500 43.6942 K 0 0 0 0 0 15 0 0 0 0 0 0 + 17.5242 55.2461 23.6907 K 0 0 0 0 0 15 0 0 0 0 0 0 + -21.4907 82.5627 19.9609 Cl 0 0 0 0 0 15 0 0 0 0 0 0 + -5.6100 66.1723 26.3135 K 0 0 0 0 0 15 0 0 0 0 0 0 + -16.4761 49.1911 30.6890 K 0 0 0 0 0 15 0 0 0 0 0 0 +M CHG 8 1 1 2 1 3 -1 4 1 5 1 6 1 7 -1 8 1 +M CHG 4 9 1 10 -1 11 1 12 1 +M END +$$$$ diff --git a/tests/test_modules/test_energy_ratio.py b/tests/test_modules/test_energy_ratio.py index deb5225..881b257 100644 --- a/tests/test_modules/test_energy_ratio.py +++ b/tests/test_modules/test_energy_ratio.py @@ -16,3 +16,8 @@ def test_check_energy_ratio_approximate_consistency(mol_1a30_clash_2, mol_1a30_c # check numbers are approximately equal assert np.isclose(energy_2, energy_3) + + +def test_check_energy_ratio_disconnected_atoms(mol_disconnnected_atoms): + out = check_energy_ratio(mol_disconnnected_atoms) + assert out["results"]["energy_ratio_passes"] is False