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

Refactor inorganics filter #13

Merged
merged 2 commits into from
May 17, 2024
Merged
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
11 changes: 7 additions & 4 deletions molpipeline/mol2mol/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class InorganicsFilter(_MolToMolPipelineElement):
"""Filters Molecules which do not contain any organic (i.e. Carbon) atoms."""

CARBON_INORGANICS = ["O=C=O", "[C-]#[O+]"] # CO2 and CO are not organic
CARBON_INORGANICS_MAX_ATOMS = 3

def __init__(
self,
Expand Down Expand Up @@ -258,8 +259,10 @@ def pretransform_single(self, value: RDKitMol) -> OptionalMol:
return InvalidInstance(
self.uuid, "Molecule contains no organic atoms.", self.name
)
smiles = Chem.MolToSmiles(value)
print(smiles)
if smiles in self.CARBON_INORGANICS:
return InvalidInstance(self.uuid, "Molecule is not organic.", self.name)

# Only check for inorganic molecules if the molecule is small enough
if value.GetNumAtoms() <= self.CARBON_INORGANICS_MAX_ATOMS:
smiles = Chem.MolToSmiles(value)
if smiles in self.CARBON_INORGANICS:
return InvalidInstance(self.uuid, "Molecule is not organic.", self.name)
return value
Loading