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

MAJOR-BUG for node/edge predictions: Added ordered=True to to_mol #503

Merged
merged 6 commits into from
Jan 19, 2024
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
4 changes: 3 additions & 1 deletion graphium/data/smiles_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def smiles_to_unique_mol_id(smiles: str) -> Optional[str]:
mol_id: a string unique ID
"""
try:
mol = dm.to_mol(mol=smiles)
mol = dm.to_mol(
mol=smiles
) # Doesn't need `ordered=True` because the unique_id doesn't depend on the atom order
mol_id = dm.unique_id(mol)
except:
mol_id = ""
Expand Down
4 changes: 2 additions & 2 deletions graphium/features/featurizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def mol_to_adj_and_features(
"""

if isinstance(mol, str):
mol = dm.to_mol(mol)
mol = dm.to_mol(mol, ordered=True)

# Add or remove explicit hydrogens
if explicit_H:
Expand Down Expand Up @@ -1071,7 +1071,7 @@ def mol_to_graph_dict(
input_mol = mol
try:
if isinstance(mol, str):
mol = dm.to_mol(mol)
mol = dm.to_mol(mol, ordered=True)
if explicit_H:
mol = Chem.AddHs(mol)
else:
Expand Down
8 changes: 7 additions & 1 deletion graphium/features/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import datamol as dm

from rdkit.Chem import rdMolDescriptors as rdMD
from loguru import logger


def get_prop_or_none(
Expand All @@ -33,6 +34,7 @@ def get_prop_or_none(
Returns:
The property or a list of `None` with lenght `n`.
"""
logger.warning("get_prop_or_none is deprecated. Use `datamol.to_fp` instead.")
try:
return prop(*args, **kwargs)
except RuntimeError:
Expand Down Expand Up @@ -75,8 +77,12 @@ def get_props_from_mol(

"""

logger.warning("get_props_from_mol is deprecated. Use `datamol.to_fp` instead.")

if isinstance(mol, str):
mol = dm.to_mol(mol)
mol = dm.to_mol(
mol
) # Doesn't need `ordered=True` because the fingerprints don't depend on the atom order

if isinstance(properties, str):
properties = [properties]
Expand Down
4 changes: 3 additions & 1 deletion profiling/profile_mol_to_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def main():

graphs = []
for s in tqdm(smiles):
mol = dm.to_mol(s)
mol = dm.to_mol(
s
) # Doesn't need `ordered=True` because this is just to test the speed of the featurizer
graphs.append(mol_to_graph_dict(mol, **featurizer))

print(graphs[0])
Expand Down