Skip to content

Commit

Permalink
Merge pull request #13 from basf/refactor-inorganics-filter
Browse files Browse the repository at this point in the history
Refactor inorganics filter
  • Loading branch information
c-w-feldmann authored May 17, 2024
2 parents 0cb53ea + 57b1eed commit 37d8a76
Showing 1 changed file with 7 additions and 4 deletions.
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

0 comments on commit 37d8a76

Please sign in to comment.