Example #1
0
        private AtomContainer GetBunchOfUnbondedAtoms()
        {
            IAtomContainer molecule = TestMoleculeFactory.MakeAlphaPinene();

            FixCarbonHCount(molecule);
            molecule.RemoveAllElectronContainers();
            return((AtomContainer)molecule);
        }
Example #2
0
        /// <summary>
        /// Generates a random structure based on the atoms in the given <see cref="IAtomContainer"/>.
        /// </summary>
        public IAtomContainer Generate()
        {
            int  iteration      = 0;
            bool structureFound = false;

            do
            {
                iteration++;
                atomContainer.RemoveAllElectronContainers();
                bool bondFormed;
                do
                {
                    bondFormed = false;
                    foreach (var atom in atomContainer.Atoms)
                    {
                        if (!satCheck.IsSaturated(atom, atomContainer))
                        {
                            var partner = GetAnotherUnsaturatedNode(atom);
                            if (partner != null)
                            {
                                var cmax1 = satCheck.GetCurrentMaxBondOrder(atom, atomContainer);
                                var cmax2 = satCheck.GetCurrentMaxBondOrder(partner, atomContainer);
                                var max   = Math.Min(cmax1, cmax2);
                                var order = Math.Min(Math.Max(1.0, random.NextInt((int)Math.Round(max))), 3.0);
                                Debug.WriteLine($"Forming bond of order {order}");
                                atomContainer.Bonds.Add(atomContainer.Builder.NewBond(atom, partner, BondManipulator.CreateBondOrder(order)));
                                bondFormed = true;
                            }
                        }
                    }
                } while (bondFormed);
                if (ConnectivityChecker.IsConnected(atomContainer) && satCheck.IsSaturated(atomContainer))
                {
                    structureFound = true;
                }
            } while (!structureFound && iteration < 20);
            Debug.WriteLine($"Structure found after #iterations: {iteration}");
            return(atomContainer.Builder.NewAtomContainer(atomContainer));
        }