Skip to content

Commit

Permalink
Energy ratio bug (#30)
Browse files Browse the repository at this point in the history
* Catch divide-by-zero error in `energy_ratio.py` (#29)
* Update version

---------

Co-authored-by: Alex Morehead <[email protected]>
  • Loading branch information
maabuu and amorehead authored Mar 15, 2024
1 parent b363659 commit 58e7581
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion posebusters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"check_volume_overlap",
]

__version__ = "0.2.10"
__version__ = "0.2.11"
5 changes: 5 additions & 0 deletions posebusters/modules/energy_ratio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module to check energy of ligand conformations."""

from __future__ import annotations

import logging
Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 20 additions & 0 deletions tests/conftest/mol_disconnected_atoms.sdf
Original file line number Diff line number Diff line change
@@ -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
$$$$
5 changes: 5 additions & 0 deletions tests/test_modules/test_energy_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 58e7581

Please sign in to comment.