/// <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.FindIdentical(inchiMolGraph, AtomMatcher.CreateElementMatcher(), BondMatcher.CreateAnyMatcher()) .MatchAll(mol) .Limit(1) .ToAtomMap(); 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> /// Adds a Molecule to the list of templates use by this TemplateHandler. /// </summary> /// <param name="molecule">The molecule to be added to the TemplateHandler</param> public void AddMolecule(IAtomContainer molecule) { if (!GeometryUtil.Has2DCoordinates(molecule)) { throw new ArgumentException("Template did not have 2D coordinates"); } // we want a consistent scale! GeometryUtil.ScaleMolecule(molecule, GeometryUtil.GetScaleFactor(molecule, StructureDiagramGenerator.DefaultBondLength)); templates.Add(molecule); anonPatterns.Add(VentoFoggia.CreateSubstructureFinder(molecule, anonAtomMatcher, anonBondMatcher)); elemPatterns.Add(VentoFoggia.CreateSubstructureFinder(molecule, elemAtomMatcher, anonBondMatcher)); }
/// <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); }
void Main() { IAtomContainer queryStructure = null; IChemObjectSet <IAtomContainer> ms = null; { #region 1 IAtomContainer query = queryStructure; Pattern pattern = VentoFoggia.CreateSubstructureFinder(query); int hits = 0; foreach (var m in ms) { if (pattern.Matches(m)) { hits++; } } #endregion } { #region 2 IAtomContainer query = queryStructure; Pattern pattern = VentoFoggia.CreateSubstructureFinder(query); int hits = 0; foreach (var m in ms) { int[] match = pattern.Match(m); if (match.Length > 0) { hits++; } } #endregion } }
public override Pattern Create(IAtomContainer container) { return(VentoFoggia.FindSubstructure(container)); }