/// <summary> /// Tries to saturate a bond by increasing its bond orders by 1.0. /// </summary> /// <returns>true if the bond could be increased</returns> public bool SaturateByIncreasingBondOrder(IBond bond, IAtomContainer atomContainer) { var atoms = BondManipulator.GetAtomArray(bond); var atom = atoms[0]; var partner = atoms[1]; Debug.WriteLine(" saturating bond: ", atom.Symbol, "-", partner.Symbol); var atomTypes1 = structgenATF.GetAtomTypes(atom.Symbol); var atomTypes2 = structgenATF.GetAtomTypes(partner.Symbol); foreach (var aType1 in atomTypes1) { Debug.WriteLine($" considering atom type: {aType1}"); if (CouldMatchAtomType(atomContainer, atom, aType1)) { Debug.WriteLine($" trying atom type: {aType1}"); foreach (var aType2 in atomTypes2) { Debug.WriteLine($" considering partner type: {aType1}"); if (CouldMatchAtomType(atomContainer, partner, aType2)) { Debug.WriteLine($" with atom type: {aType2}"); if (BondManipulator.IsLowerOrder(bond.Order, aType2.MaxBondOrder) && BondManipulator.IsLowerOrder(bond.Order, aType1.MaxBondOrder)) { bond.Order = BondManipulator.IncreaseBondOrder(bond.Order); Debug.WriteLine($"Bond order now {bond.Order}"); return(true); } } } } } return(false); }
public bool HasPerfectConfiguration(IAtom atom, IAtomContainer ac) { var bondOrderSum = ac.GetBondOrderSum(atom); var maxBondOrder = ac.GetMaximumBondOrder(atom); var atomTypes = structgenATF.GetAtomTypes(atom.Symbol); if (!atomTypes.Any()) { return(true); } Debug.WriteLine("*** Checking for perfect configuration ***"); try { Debug.WriteLine($"Checking configuration of atom {ac.Atoms.IndexOf(atom)}"); Debug.WriteLine($"Atom has bondOrderSum = {bondOrderSum}"); Debug.WriteLine($"Atom has max = {bondOrderSum}"); } catch (Exception) { } foreach (var atomType in atomTypes) { if (bondOrderSum == atomType.BondOrderSum && maxBondOrder == atomType.MaxBondOrder) { try { Debug.WriteLine($"Atom {ac.Atoms.IndexOf(atom)} has perfect configuration"); } catch (Exception) { } return(true); } } try { Debug.WriteLine($"*** Atom {ac.Atoms.IndexOf(atom)} has imperfect configuration ***"); } catch (Exception) { } return(false); }
/// <summary> /// Finds the AtomType matching the Atom's element symbol, formal charge and /// hybridization state. /// </summary> /// <param name="atomContainer">AtomContainer</param> /// <param name="atom">the target atom</param> /// <exception cref="CDKException">Exception thrown if something goes wrong</exception> /// <returns>the matching AtomType</returns> public IEnumerable <IAtomType> PossibleAtomTypes(IAtomContainer atomContainer, IAtom atom) { var bondOrderSum = atomContainer.GetBondOrderSum(atom); var maxBondOrder = atomContainer.GetMaximumBondOrder(atom); var charge = atom.FormalCharge.Value; var hcount = atom.ImplicitHydrogenCount.Value; var types = factory.GetAtomTypes(atom.Symbol); foreach (var type in types) { Debug.WriteLine(" ... matching atom ", atom, " vs ", type); if (bondOrderSum - charge + hcount <= type.BondOrderSum && !BondManipulator.IsHigherOrder(maxBondOrder, type.MaxBondOrder)) { yield return(type); } } Debug.WriteLine(" No Match"); yield break; }
private static bool CreateBondsWithRebondTool(IAtomContainer molecule) { var tool = new RebondTool(2.0, 0.5, 0.5); try { foreach (var atom in molecule.Atoms) { try { var types = factory.GetAtomTypes(atom.Symbol); var type = types.FirstOrDefault(); if (type != null) { // just pick the first one AtomTypeManipulator.Configure(atom, type); } else { Trace.TraceWarning("Could not configure atom with symbol: " + atom.Symbol); } } catch (Exception e) { Trace.TraceWarning("Could not configure atom (but don't care): " + e.Message); Debug.WriteLine(e); } } tool.Rebond(molecule); } catch (Exception e) { Trace.TraceError($"Could not rebond the polymer: {e.Message}"); Debug.WriteLine(e); } return(true); }