/// <summary> /// Atom-atom mapping of the input molecule to the bare container constructed from the InChI connection table. /// This makes it possible to map the positions of the mobile hydrogens in the InChI back to the input molecule. /// </summary> /// <param name="inchiMolGraph">molecule (bare) as defined in InChI</param> /// <param name="mol">user input molecule</param> /// <exception cref="CDKException"></exception> private static void MapInputMoleculeToInChIMolgraph(IAtomContainer inchiMolGraph, IAtomContainer mol) { var iter = VentoFoggia.CreateIdenticalFinder(inchiMolGraph, AtomMatcher.CreateElementMatcher(), BondMatcher.CreateAnyMatcher()) .MatchAll(mol) .Limit(1) .ToAtomMaps(); var i = iter.FirstOrDefault(); if (i != null) { foreach (var e in i) { var src = e.Key; var dst = e.Value; var position = src.Id; dst.Id = position; Debug.WriteLine($"Mapped InChI {src.Symbol} {src.Id} to {dst.Symbol} {dst.Id}"); } } else { throw new ArgumentException($"{CANSMI.Create(inchiMolGraph)} {CANSMI.Create(mol)}"); } }
public IAtomContainer RemoveMolecule(IAtomContainer molecule) { for (int i = 0; i < templates.Count; i++) { if (VentoFoggia.CreateIdenticalFinder(templates[i], anonAtomMatcher, anonBondMatcher).Matches(molecule)) { elemPatterns.RemoveAt(i); anonPatterns.RemoveAt(i); var ret = templates[i]; templates.RemoveAt(i); return(ret); } } return(null); }
/// <summary> /// Checks if one of the loaded templates is isomorph to the given /// Molecule. If so, it assigns the coordinates from the template to the /// respective atoms in the Molecule, and marks the atoms as ISPLACED. /// </summary> /// <param name="molecule">The molecule to be check for potential templates</param> /// <returns>True if there was a possible mapping</returns> public bool MapTemplateExact(IAtomContainer molecule) { foreach (var template in templates) { var mappings = VentoFoggia.CreateIdenticalFinder(template, anonAtomMatcher, anonBondMatcher).MatchAll(molecule); foreach (var atoms in mappings.ToAtomMaps()) { foreach (var e in atoms) { e.Value.Point2D = e.Key.Point2D; e.Value.IsPlaced = true; } if (atoms.Count != 0) { return(true); } } } return(false); }