/// <summary> /// Labels the Atom's and Bond's in each AtomContainer using the a1, a2, b1, b2 /// scheme often used in CML. It will also set id's for all AtomContainers, naming /// them m1, m2, etc. /// It will not the AtomContainerSet itself. /// </summary> private static void CreateIDsForAtomContainerSet(IChemObjectSet <IAtomContainer> containerSet, List <string> tabuList) { if (tabuList == null) { tabuList = AtomContainerSetManipulator.GetAllIDs(containerSet).ToList(); } if (null == containerSet.Id) { atomContainerSetCount = SetId(ATOMCONTAINERSET_PREFIX, atomContainerSetCount, containerSet, tabuList); } if (policy == UniquePolicy.Object) { // start atom and bond indices within a container set always from 1 atomCount = 0; bondCount = 0; } foreach (var ac in containerSet) { CreateIDsForAtomContainer(ac, tabuList); } }
internal IAtomContainer Generate2(IChemObjectSet <IAtomContainer> atomContainers) { int iteration = 0; bool structureFound = false; do { iteration++; bool bondFormed; do { bondFormed = false; var atomContainersArray = atomContainers.ToList(); for (var atomContainersArrayIndex = 0; atomContainersArrayIndex < atomContainersArray.Count; atomContainersArrayIndex++) { var ac = atomContainersArray[atomContainersArrayIndex]; if (ac == null) { continue; } var atoms = ac.Atoms.ToList(); // ToList is required because some atoms are added to ac.Atoms in the loop. foreach (var atom in atoms) { if (!satCheck.IsSaturated(atom, ac)) { var partner = GetAnotherUnsaturatedNode(atom, ac, atomContainers); if (partner != null) { var toadd = AtomContainerSetManipulator.GetRelevantAtomContainer(atomContainers, partner); var cmax1 = satCheck.GetCurrentMaxBondOrder(atom, ac); var cmax2 = satCheck.GetCurrentMaxBondOrder(partner, toadd); var max = Math.Min(cmax1, cmax2); var order = Math.Min(Math.Max(1, max), 3); //(double)Math.Round(Math.Random() * max) Debug.WriteLine($"cmax1, cmax2, max, order: {cmax1}, {cmax2}, {max}, {order}"); if (toadd != ac) { var indexToRemove = atomContainersArray.IndexOf(toadd); if (indexToRemove != -1) { atomContainersArray[indexToRemove] = null; } atomContainers.Remove(toadd); ac.Add(toadd); } ac.Bonds.Add(ac.Builder.NewBond(atom, partner, BondManipulator.CreateBondOrder(order))); bondFormed = true; } } } } } while (bondFormed); if (atomContainers.Count == 1 && satCheck.IsSaturated(atomContainers[0])) { structureFound = true; } } while (!structureFound && iteration < 5); if (atomContainers.Count == 1 && satCheck.IsSaturated(atomContainers[0])) { structureFound = true; } if (!structureFound) { return(null); } return(atomContainers[0]); }