Skip to content

Commit

Permalink
Merge pull request #57 from LindeSchoenmaker/intermediate_generator
Browse files Browse the repository at this point in the history
Add other intermediate generator to wrapper
  • Loading branch information
RiesBen authored Aug 1, 2024
2 parents 5e9b94b + 35f7af4 commit 8a5c602
Showing 1 changed file with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@

from rdkit import Chem

Check warning on line 2 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L2

Added line #L2 was not covered by tests

# Intermediate generator
# R-group enumeration intermediate generator
from rgroupinterm import rgroupenumeration
from rgroupinterm import pruners

Check warning on line 6 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L5-L6

Added lines #L5 - L6 were not covered by tests

# STONED SELFIES intermediate generator
from generator import generation
from generator import scoring

Check warning on line 10 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L9-L10

Added lines #L9 - L10 were not covered by tests
#notes
Expand All @@ -12,8 +16,36 @@

from gufe import SmallMoleculeComponent

Check warning on line 17 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L17

Added line #L17 was not covered by tests


class Intermediator():
def __init__(self, enumerate_kekule=False, permutate=False, insert_small=False):
self.enumerate_kekule = enumerate_kekule
self.permutate = permutate
self.insert_small = insert_small

Check warning on line 23 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L19-L23

Added lines #L19 - L23 were not covered by tests

def generate_intermediate(self, molA: SmallMoleculeComponent, molB: SmallMoleculeComponent):

Check warning on line 25 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L25

Added line #L25 was not covered by tests

rdmolA = Chem.MolFromSmiles(Chem.MolToSmiles(molA.to_rdkit()))
rdmolB = Chem.MolFromSmiles(Chem.MolToSmiles(molB.to_rdkit()))

Check warning on line 28 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L27-L28

Added lines #L27 - L28 were not covered by tests

generator = rgroupenumeration.EnumRGroups(self.enumerate_kekule, self.permutate, self.insert_small)
df_interm, _ = generator.generate_intermediates([rdmolA, rdmolB])

Check warning on line 31 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L30-L31

Added lines #L30 - L31 were not covered by tests

pruner = pruners.BasePruner(

Check warning on line 33 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L33

Added line #L33 was not covered by tests
[pruners.TanimotoScorer(transformer=pruners.HarmonicMeanTransformer(exponent=4))],
topn=1)

df_interm['Parent_1'] = rdmolA
df_interm['Parent_2'] = rdmolB
df_interm['Pair'] = 0
pruned_df = pruner(df_interm)
rd_mol_intermediate = pruned_df['Intermediate'].values[0]
rd_mol_intermediate = Chem.AddHs(rd_mol_intermediate)
Chem.AllChem.EmbedMolecule(rd_mol_intermediate)

Check warning on line 43 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L37-L43

Added lines #L37 - L43 were not covered by tests

return SmallMoleculeComponent.from_rdkit(rdkit=rd_mol_intermediate,

Check warning on line 45 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L45

Added line #L45 was not covered by tests
name=molA.name+"_"+molB.name+"_intermediate")

class Intermediator_STONEDSELFIES():
def __init__(self, scoring_method=None, fp_type:str="ECFP4", num_tries:int=5,

Check warning on line 49 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L48-L49

Added lines #L48 - L49 were not covered by tests
num_random_smiles: int= 10, collect_bidirectional:bool=True,
exponent_path:int=4, n_rounds:int=1, num_random_samples:int=500,
Expand Down Expand Up @@ -87,4 +119,4 @@ def generate_intermediate(self, molA: SmallMoleculeComponent, molB: SmallMolecul
selected_intermediate = next(iter(sorted_smiles_dict))
rd_mol_intermediate = Chem.MolFromSmiles(selected_intermediate)
return SmallMoleculeComponent.from_rdkit(rdkit=rd_mol_intermediate,

Check warning on line 121 in src/konnektor/network_tools/intermediate_generators/intermediator.py

View check run for this annotation

Codecov / codecov/patch

src/konnektor/network_tools/intermediate_generators/intermediator.py#L119-L121

Added lines #L119 - L121 were not covered by tests
name=molA.name+"_"+molB.name+"_intermediate")
name=molA.name+"_"+molB.name+"_intermediate")

0 comments on commit 8a5c602

Please sign in to comment.