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

Mapping multi chain components #47

Merged
merged 23 commits into from
Nov 25, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7a41133
adding first pseudo code for protein chain mapping
RiesBen Aug 28, 2024
0efc3f6
Update atom_mapper.py
RiesBen Aug 29, 2024
7894b28
Tests for mapping multimer components
ijpulidos Sep 18, 2024
6b2ecc8
WIP -- Implementing splitting by framents instead of chains
ijpulidos Sep 20, 2024
d01fd35
Split components by molecule fragments/connectivity
ijpulidos Sep 23, 2024
4e680b9
WIP -- Support for multimer mapping. Merge fragment mappings into one.
ijpulidos Sep 23, 2024
fdb636a
Fix tests fixtures and expected mapped atoms.
ijpulidos Sep 25, 2024
b192038
Adding test data for multimer mutation components
ijpulidos Sep 26, 2024
7bdb8ac
Handling multimer component mapping
ijpulidos Sep 26, 2024
ab98c3a
Fix filename for test file
ijpulidos Sep 26, 2024
afb9fc9
Merge branch 'main' into 46-mapping-multimer-protein-components
ijpulidos Sep 26, 2024
024504a
Merge branch 'main' into 46-mapping-multimer-protein-components
IAlibay Oct 22, 2024
cd34743
add review feedback
jthorton Nov 7, 2024
9c62af5
patch the testing env
jthorton Nov 7, 2024
28691c3
try and fix 3.9 tests
jthorton Nov 7, 2024
ce21ea7
add missing init file
jthorton Nov 7, 2024
e0d7e1c
Merge branch 'main' into 46-mapping-multimer-protein-components
IAlibay Nov 11, 2024
48ff4cc
make suggest mappings agnostic to the type of components
jthorton Nov 12, 2024
acc534d
make type hints work with 3.9
jthorton Nov 12, 2024
1db0d98
fix type hint and enforce components are the same type
jthorton Nov 12, 2024
2f294aa
Merge branch 'main' into 46-mapping-multimer-protein-components
IAlibay Nov 18, 2024
183da6c
Merge branch 'main' into 46-mapping-multimer-protein-components
jthorton Nov 21, 2024
00709d5
update type hints, raise an error for different numbers of subcomponents
jthorton Nov 22, 2024
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
57 changes: 48 additions & 9 deletions src/kartograf/atom_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import copy
import dill
import inspect
import numpy as np
from enum import Enum

Expand All @@ -18,7 +17,7 @@

from typing import Callable, Iterable, Optional, Union

from gufe import SmallMoleculeComponent
from gufe import SmallMoleculeComponent, ProteinComponent
from gufe import AtomMapping, AtomMapper, LigandAtomMapping

from numpy.typing import NDArray
Expand Down Expand Up @@ -855,6 +854,20 @@

return mapping

def _split_protein_component_chains(self, protein: ProteinComponent)->list[ProteinComponent]:
chain_components = []
rdmol = protein.to_rdkit()

Check warning on line 859 in src/kartograf/atom_mapper.py

View check run for this annotation

Codecov / codecov/patch

src/kartograf/atom_mapper.py#L858-L859

Added lines #L858 - L859 were not covered by tests
# TODO: Implement splitting up A into chain components

return chain_components

Check warning on line 862 in src/kartograf/atom_mapper.py

View check run for this annotation

Codecov / codecov/patch

src/kartograf/atom_mapper.py#L862

Added line #L862 was not covered by tests

def _merge_protein_component_chain_mappings(self, A:ProteinComponent, B:ProteinComponent,
sub_mappings: list[AtomMapping])->AtomMapping:
merged_mapping = {}

Check warning on line 866 in src/kartograf/atom_mapper.py

View check run for this annotation

Codecov / codecov/patch

src/kartograf/atom_mapper.py#L866

Added line #L866 was not covered by tests
# TODO: Implement finding largest mapped overlaps in all possible chains
# TODO: return merged mapping

return AtomMapping(componentA=A, componentB=B, mapping=merged_mapping)

Check warning on line 870 in src/kartograf/atom_mapper.py

View check run for this annotation

Codecov / codecov/patch

src/kartograf/atom_mapper.py#L870

Added line #L870 was not covered by tests
jthorton marked this conversation as resolved.
Show resolved Hide resolved
def suggest_mappings(
self, A: SmallMoleculeComponent, B: SmallMoleculeComponent
jthorton marked this conversation as resolved.
Show resolved Hide resolved
) -> Iterator[AtomMapping]:
Expand All @@ -873,10 +886,36 @@
Iterator[AtomMapping]
returns an interator of possible atom mappings.
"""
yield LigandAtomMapping(
A,
B,
self.suggest_mapping_from_rdmols(
molA=A.to_rdkit(), molB=B.to_rdkit()
),
)

if isinstance(A, ProteinComponent) or isinstance(B, ProteinComponent):
# 1. identify Component Chains
if isinstance(A, ProteinComponent):
componentA_chains = self._split_protein_component_chains(A)

Check warning on line 893 in src/kartograf/atom_mapper.py

View check run for this annotation

Codecov / codecov/patch

src/kartograf/atom_mapper.py#L892-L893

Added lines #L892 - L893 were not covered by tests

if isinstance(B, ProteinComponent):
componentB_chains = self._split_protein_component_chains(B)

Check warning on line 896 in src/kartograf/atom_mapper.py

View check run for this annotation

Codecov / codecov/patch

src/kartograf/atom_mapper.py#L895-L896

Added lines #L895 - L896 were not covered by tests

# 2. calculate all possible mappings
jthorton marked this conversation as resolved.
Show resolved Hide resolved
chain_mappings = []
for A_chain in componentA_chains:
for B_chain in componentB_chains:
chain_map = LigandAtomMapping(

Check warning on line 902 in src/kartograf/atom_mapper.py

View check run for this annotation

Codecov / codecov/patch

src/kartograf/atom_mapper.py#L899-L902

Added lines #L899 - L902 were not covered by tests
A_chain,
B_chain,
self.suggest_mapping_from_rdmols(
molA=A_chain.to_rdkit(), molB=B_chain.to_rdkit()
),
)
chain_mappings.append(chain_map)

Check warning on line 909 in src/kartograf/atom_mapper.py

View check run for this annotation

Codecov / codecov/patch

src/kartograf/atom_mapper.py#L909

Added line #L909 was not covered by tests

# 3. find largest overlap of chain mappings and return a merge.
yield self._merge_protein_component_chain_mappings(chain_mappings)

Check warning on line 912 in src/kartograf/atom_mapper.py

View check run for this annotation

Codecov / codecov/patch

src/kartograf/atom_mapper.py#L912

Added line #L912 was not covered by tests

else: # SmallMoleculeComponent case
yield LigandAtomMapping(
A,
B,
self.suggest_mapping_from_rdmols(
molA=A.to_rdkit(), molB=B.to_rdkit()
),
)
Loading