Skip to content

Commit

Permalink
fix mapper now supports leaving atoms.
Browse files Browse the repository at this point in the history
  • Loading branch information
stsouko committed Dec 15, 2020
1 parent b83f2cd commit f5d18b6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions CGRtools/algorithms/standardize.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#
from CachedMethods import class_cached_property
from collections import defaultdict
from itertools import count
from typing import List
from ..containers import molecule, query # cyclic imports resolve
from ..containers.bonds import Bond
Expand Down Expand Up @@ -1439,15 +1440,17 @@ def fix_mapping(self) -> bool:
else:
flag = False

for bad_query, good_query, fix, valid in self.__remapping_compiled_rules:
for bad_query, good_query, fix, valid in self.__remapping_compiled_rules:
cgr = ~self
first_free = max(cgr) + 1
free_number = count(first_free)
cgr_c = set(cgr.center_atoms)
del self.__dict__['__cached_method_compose']
del self.__dict__['__cached_method_compose']

for mapping in bad_query.get_mapping(cgr, automorphism_filter=False):
if not seen.isdisjoint(mapping.values()): # prevent matching same RC
continue
mapping = {mapping[n]: mapping[m] for n, m in fix.items()}
mapping = {mapping[n]: next(free_number) if m is None else mapping[m] for n, m in fix.items()}

reverse = {m: n for n, m in mapping.items()}
for m in self.products:
Expand All @@ -1466,14 +1469,15 @@ def fix_mapping(self) -> bool:
for m in self.products:
m.remap(reverse)
del self.__dict__['__cached_method_compose']
free_number = count(first_free)
continue
break

if seen:
self.flush_cache()
return True
return flag

@classmethod
def load_remapping_rules(cls, reactions):
"""
Expand All @@ -1484,11 +1488,11 @@ def load_remapping_rules(cls, reactions):
for bad, good in reactions:
if str(bad) != str(good):
raise ValueError('bad and good reaction should be equal')

cgr_good, cgr_bad = ~good, ~bad
gc = cgr_good.augmented_substructure(cgr_good.center_atoms, deep=1)
bc = cgr_bad.augmented_substructure(cgr_bad.center_atoms, deep=1)

atoms = set(bc.atoms_numbers + gc.atoms_numbers)

pr_g, pr_b, re_g, re_b = set(), set(), set(), set()
Expand Down

0 comments on commit f5d18b6

Please sign in to comment.