Skip to content

Commit

Permalink
Merge branch 'main' into extend_error_handling_physchem_rdkit
Browse files Browse the repository at this point in the history
  • Loading branch information
c-w-feldmann authored May 17, 2024
2 parents 64061a2 + 37d8a76 commit 25298c1
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 25298c1

Please sign in to comment.