コード例 #1
0
        public virtual void TestRemoveAtomContainer_IAtomContainer()
        {
            IChemObjectSet <T> som = (IChemObjectSet <T>)NewChemObject();
            T ac1 = NewContainerObject();
            T ac2 = NewContainerObject();

            som.Add(ac1);
            som.Add(ac2);
            som.Remove(ac1);
            Assert.AreEqual(1, som.Count);
            Assert.AreEqual(ac2, som[0]);
        }
コード例 #2
0
ファイル: Splitter.cs プロジェクト: proftodd/csrxnsplitter
 private static void filterInorganicsFromIterator(IChemObjectSet <IAtomContainer> rxnIt)
 {
     for (int i = rxnIt.Count - 1; i >= 0; --i)
     {
         var sub     = rxnIt[i];
         var formula = MolecularFormulaManipulator.GetMolecularFormula(sub);
         if (!MolecularFormulaManipulator.ContainsElement(formula, ChemicalElement.C))
         {
             rxnIt.Remove(sub);
         }
     }
 }
コード例 #3
0
        public virtual void TestBug2679343()
        {
            IChemObjectSet <T> som = (IChemObjectSet <T>)NewChemObject();
            T ac1 = NewContainerObject();
            T ac2 = NewContainerObject();

            som.Add(ac1);
            som.Add(ac2);
            som.Add(ac2);
            Assert.AreEqual(3, som.Count);
            som.Remove(ac2);
            Assert.AreEqual(1, som.Count);
        }
コード例 #4
0
 public static void RemoveElectronContainer(IChemObjectSet <IAtomContainer> set, IElectronContainer electrons)
 {
     foreach (var atomContainer in set)
     {
         if (atomContainer.Contains(electrons))
         {
             atomContainer.Remove(electrons);
             var molecules = ConnectivityChecker.PartitionIntoMolecules(atomContainer);
             if (molecules.Count > 1)
             {
                 set.Remove(atomContainer);
                 for (int k = 0; k < molecules.Count; k++)
                 {
                     set.Add(molecules[k]);
                 }
             }
             return;
         }
     }
 }
コード例 #5
0
        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]);
        }