Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure SD tags are parsed from OEGraphMol #1778

Merged
merged 5 commits into from
Dec 1, 2023
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
2 changes: 2 additions & 0 deletions docs/releasehistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Releases follow the `major.minor.micro` scheme recommended by [PEP440](https://w

### Bugfixes

- [PR #1778](https://github.com/openforcefield/openff-toolkit/pull/1778): Ensures SD data tags are preserved in `Molecule.from_openeye` if the input is of type `oechem.OEGraphMol`.

### New features

### Improved documentation and warnings
Expand Down
11 changes: 11 additions & 0 deletions openff/toolkit/_tests/test_toolkits.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,17 @@ def test_to_from_openeye_core_props_unset(self):
== expected_output_smiles
)

def test_sd_tags_in_graph_mol_preserved(self):
from openeye import oechem

graph = oechem.OEGraphMol()

oechem.OEParseSmiles(graph, "CCO")

oechem.OEAddSDData(graph, "cat", "meow")

assert Molecule.from_openeye(graph).properties["cat"] == "meow"

def test_to_from_openeye_none_partial_charges(self):
"""Test to ensure that to_openeye and from_openeye correctly handle None partial charges"""
import math
Expand Down
2 changes: 2 additions & 0 deletions openff/toolkit/topology/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,8 @@ def assign_fractional_bond_orders(
def _invalidate_cached_properties(self) -> None:
"""
Indicate that the chemical entity has been altered.

Note that this does not clear the `.properties` dictionary attribute.
"""
self._conformers = None
self._partial_charges = None
Expand Down
12 changes: 9 additions & 3 deletions openff/toolkit/utils/openeye_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,12 @@ def from_openeye(

from openeye import oechem

# Save the existing SD tags, if any, since they're lost in the cast to
# OEMol of the input is OEGraphMol. See issue #1711
existing_sd_tags = {
pair.GetTag(): pair.GetValue() for pair in oechem.OEGetSDDataIter(oemol)
}

oemol = oechem.OEMol(oemol)

# Add explicit hydrogens if they're implicit
Expand Down Expand Up @@ -1207,9 +1213,9 @@ def describe_oeatom(oeatom) -> str:
if oemol.GetTitle() != "":
molecule.name = oemol.GetTitle()

# Copy any attached SD tag information
for dp in oechem.OEGetSDDataPairs(oemol):
molecule._properties[dp.GetTag()] = dp.GetValue()
# Attach any SD tag information we saved before casting input to new OEMol
for key, value in existing_sd_tags.items():
molecule._properties[key] = value

off_to_oe_idx = dict() # {oemol_idx: molecule_idx}
atom_mapping = {}
Expand Down