示例#1
0
        public static void Main(string[] args)
        {
            {
                var mol = new AtomContainer();
                #region Detect
                Atom a0 = new Atom("C"); mol.Atoms.Add(a0);
                Atom a1 = new Atom("C"); mol.Atoms.Add(a1);
                Atom a2 = new Atom("C"); mol.Atoms.Add(a2);
                Atom h1 = new Atom("H"); mol.Atoms.Add(h1);
                Atom h2 = new Atom("H"); mol.Atoms.Add(h2);
                Atom h3 = new Atom("H"); mol.Atoms.Add(h3);
                Atom h4 = new Atom("H"); mol.Atoms.Add(h4);
                Atom h5 = new Atom("H"); mol.Atoms.Add(h5);
                mol.AddBond(a0, a1, BondOrder.Double);
                mol.AddBond(a1, a2, BondOrder.Single);
                mol.AddBond(a0, h1, BondOrder.Single);
                mol.AddBond(a0, h2, BondOrder.Single);
                mol.AddBond(a1, h3, BondOrder.Single);
                mol.AddBond(a2, h4, BondOrder.Single);
                mol.AddBond(a2, h5, BondOrder.Single);
                SingleElectron se = new SingleElectron(a2);
                mol.Add(se);

                var pi_systems = ConjugatedPiSystemsDetector.Detect(mol);
                #endregion
            }
        }
示例#2
0
        public void TestDontDeleteSingleElectrons()
        {
            AtomContainer atomCon = new AtomContainer();
            // make two molecules; one with an LonePair, the other with a SingleElectron
            IAtomContainer mol1  = new AtomContainer();
            Atom           atom1 = new Atom("C");

            mol1.Atoms.Add(atom1);
            LonePair lp1 = new LonePair(atom1);

            mol1.LonePairs.Add(lp1);
            // mol2
            IAtomContainer mol2  = new AtomContainer();
            Atom           atom2 = new Atom("C");

            mol2.Atoms.Add(atom2);
            SingleElectron se2 = new SingleElectron(atom2);

            mol2.SingleElectrons.Add(se2);

            atomCon.Add(mol1);
            atomCon.Add(mol2);

            // now partition
            IChemObjectSet <IAtomContainer> moleculeSet = ConnectivityChecker.PartitionIntoMolecules(atomCon);

            Assert.IsNotNull(moleculeSet);
            Assert.AreEqual(2, moleculeSet.Count);

            Assert.IsTrue(ConnectivityChecker.IsConnected(moleculeSet[0]));
            Assert.IsTrue(ConnectivityChecker.IsConnected(moleculeSet[1]));

            // make sure
            Assert.AreEqual(1, moleculeSet[0].Atoms.Count);
            Assert.AreEqual(1, moleculeSet[0].GetElectronContainers().Count());
            Assert.AreEqual(1, moleculeSet[1].Atoms.Count);
            Assert.AreEqual(1, moleculeSet[1].GetElectronContainers().Count());
            // we don't know which partition contains the LP and which the electron
            Assert.IsTrue(moleculeSet[0].GetConnectedSingleElectrons(
                              moleculeSet[0].Atoms[0]).Count() == 0 ||
                          moleculeSet[1].GetConnectedSingleElectrons(
                              moleculeSet[1].Atoms[0]).Count() == 0);
            Assert.IsTrue(moleculeSet[0].GetConnectedLonePairs(
                              moleculeSet[0].Atoms[0]).Count() == 0 ||
                          moleculeSet[1].GetConnectedLonePairs(
                              moleculeSet[1].Atoms[0]).Count() == 0);
        }