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

fixes implementation of transmuting_methyl_into_ring_score #526

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 9 additions & 3 deletions openfe/setup/atom_mapping/lomap_scorers.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,11 @@ def creates_heterocyle(mol):

def transmuting_methyl_into_ring_score(mapping: LigandAtomMapping,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to ask this, but could you add a direct test for this here? It'll help document intentions in the future.

beta=0.1, penalty=6.0):
"""Penalises ring forming
"""Penalises having a non-mapped ring atoms become a non-ring
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Penalises having a non-mapped ring atoms become a non-ring
"""Penalises having a non-mapped ring atoms become a non-ring group

Or something like that.


Check if any atoms transition to/from rings in the mapping, if so
returns a score of::
This score would for example penalise R-CH3 to R-Ph where R is the same
mapped atom and both CH3 and Ph are unmapped. Does not penalise R-H to R-Ph.
If any atoms trigger the rule returns a score of::

1 - exp(-1 * beta * penalty)

Expand All @@ -312,12 +313,15 @@ def transmuting_methyl_into_ring_score(mapping: LigandAtomMapping,
molB = mapping.componentB.to_rdkit()
molA_to_molB = mapping.componentA_to_componentB


ringbreak = False
for i, j in molA_to_molB.items():
atomA = molA.GetAtomWithIdx(i)

for bA in atomA.GetBonds():
otherA = bA.GetOtherAtom(atomA)
if otherA.GetAtomicNum() == 1:
continue
if otherA.GetIdx() in molA_to_molB:
# if other end of bond in core, ignore
continue
Expand All @@ -328,6 +332,8 @@ def transmuting_methyl_into_ring_score(mapping: LigandAtomMapping,
otherB = bB.GetOtherAtom(atomB)
if otherB.GetIdx() in molA_to_molB.values():
continue
if otherB.GetAtomicNum() == 1:
continue

if otherA.IsInRing() ^ otherB.IsInRing():
ringbreak = True
Expand Down
31 changes: 31 additions & 0 deletions openfe/tests/setup/atom_mapping/test_lomap_scorers.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,34 @@ def test_lomap_regression(lomap_basic_test_files_dir, # in a dir for lomap
scores[i, i] = 0

assert_allclose(matrix, scores)


def test_transmuting_methyl_into_ring_score():
"""
Sets up two mappings:
RC_to_RPh = [CCC]C -> [CCC]Ph
RH_to_RPh = [CCC]H -> [CCC]Ph
Where square brackets show mapped (core) region

The first mapping should trigger this rule, the second shouldn't
"""
def makemol(smi):
m = Chem.MolFromSmiles(smi)
m = Chem.AddHs(m)
m.Compute2DCoords()

return openfe.SmallMoleculeComponent(m)

core = 'CCC{}'
RC = makemol(core.format('C'))
RPh = makemol(core.format('c1ccccc1'))
RH = makemol(core.format('[H]'))

RC_to_RPh = openfe.LigandAtomMapping(RC, RPh, {i: i for i in range(3)})
RH_to_RPh = openfe.LigandAtomMapping(RH, RPh, {i: i for i in range(3)})

score1 = lomap_scorers.transmuting_methyl_into_ring_score(RC_to_RPh)
score2 = lomap_scorers.transmuting_methyl_into_ring_score(RH_to_RPh)

assert score2 == 0.0
assert score1 == pytest.approx(1 - math.exp(-0.1 * 6.0))
Loading