public void TestFerrocene()
        {
            IAtomContainer ferrocene = builder.NewAtomContainer();

            ferrocene.Atoms.Add(builder.NewAtom("C"));
            ferrocene.Atoms.Add(builder.NewAtom("C"));
            ferrocene.Atoms.Add(builder.NewAtom("C"));
            ferrocene.Atoms.Add(builder.NewAtom("C"));
            ferrocene.Atoms.Add(builder.NewAtom("C"));
            ferrocene.Atoms[4].FormalCharge = -1;
            ferrocene.Atoms.Add(builder.NewAtom("C"));
            ferrocene.Atoms.Add(builder.NewAtom("C"));
            ferrocene.Atoms.Add(builder.NewAtom("C"));
            ferrocene.Atoms.Add(builder.NewAtom("C"));
            ferrocene.Atoms.Add(builder.NewAtom("C"));
            ferrocene.Atoms[9].FormalCharge = -1;
            ferrocene.Atoms.Add(builder.NewAtom("Fe"));
            ferrocene.Atoms[10].FormalCharge = +2;
            ferrocene.AddBond(ferrocene.Atoms[0], ferrocene.Atoms[1], BondOrder.Double);
            ferrocene.AddBond(ferrocene.Atoms[1], ferrocene.Atoms[2], BondOrder.Single);
            ferrocene.AddBond(ferrocene.Atoms[2], ferrocene.Atoms[3], BondOrder.Double);
            ferrocene.AddBond(ferrocene.Atoms[3], ferrocene.Atoms[4], BondOrder.Single);
            ferrocene.AddBond(ferrocene.Atoms[4], ferrocene.Atoms[0], BondOrder.Single);
            ferrocene.AddBond(ferrocene.Atoms[5], ferrocene.Atoms[6], BondOrder.Double);
            ferrocene.AddBond(ferrocene.Atoms[6], ferrocene.Atoms[7], BondOrder.Single);
            ferrocene.AddBond(ferrocene.Atoms[7], ferrocene.Atoms[8], BondOrder.Double);
            ferrocene.AddBond(ferrocene.Atoms[8], ferrocene.Atoms[9], BondOrder.Single);
            ferrocene.AddBond(ferrocene.Atoms[9], ferrocene.Atoms[5], BondOrder.Single);

            var expectedTypes = new string[] { "C.2", "C.2", "C.2", "C.2", "Any", "C.2", "C.2", "C.2", "C.2", "Any", "Fe" };

            AssertAtomTypes(testedAtomTypes, expectedTypes, ferrocene);
        }
        /// <summary>
        /// Get the expected set of molecules. [C-]-C = C
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();

            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms[0].FormalCharge = -1;
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Double);

            try
            {
                AddExplicitHydrogens(molecule);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }

            setOfProducts.Add(molecule);
            return(setOfProducts);
        }
        /// <summary>
        /// get the molecule 1: [C-]-[C+] - C
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExampleReactants()
        {
            var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet();

            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms[0].FormalCharge = -1;
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms[1].FormalCharge = +1;
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single);
            try
            {
                AddExplicitHydrogens(molecule);
                MakeSureAtomTypesAreRecognized(molecule);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }

            setOfReactants.Add(molecule);
            return(setOfReactants);
        }
Exemple #4
0
        /// <summary>
        /// Get the Ethene structure.
        /// </summary>
        /// <returns>The IAtomContainer</returns>
        /// <exception cref="CDKException"></exception>
        private IChemObjectSet <IAtomContainer> GetExampleReactants()
        {
            var            setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet();
            IAtomContainer molecule       = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[2], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[3], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[4], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[5], BondOrder.Single);
            try
            {
                AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);

                CDK.LonePairElectronChecker.Saturate(molecule);
            }
            catch (CDKException e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }
            setOfReactants.Add(molecule);
            return(setOfReactants);
        }
Exemple #5
0
        /// <summary>
        /// Get the expected set of molecules.
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();

            IAtomContainer molecule1 = builder.NewAtomContainer();//CreateFromSmiles("[C+]");
            IAtom          carb      = builder.NewAtom("C");

            carb.FormalCharge = 1;
            molecule1.Atoms.Add(carb);
            molecule1.Atoms.Add(builder.NewAtom("H"));
            molecule1.AddBond(molecule1.Atoms[0], molecule1.Atoms[1], BondOrder.Single);
            molecule1.Atoms.Add(builder.NewAtom("H"));
            molecule1.AddBond(molecule1.Atoms[0], molecule1.Atoms[2], BondOrder.Single);
            molecule1.Atoms.Add(builder.NewAtom("H"));
            molecule1.AddBond(molecule1.Atoms[0], molecule1.Atoms[3], BondOrder.Single);

            IAtomContainer molecule2 = builder.NewAtomContainer();//CreateFromSmiles("[C-]#[O+]");

            carb = builder.NewAtom("C");
            carb.FormalCharge = -1;
            molecule2.LonePairs.Add(new LonePair(carb));
            molecule2.Atoms.Add(carb);
            IAtom oxy = builder.NewAtom("O");

            oxy.FormalCharge = 1;
            molecule2.Atoms.Add(oxy);
            molecule2.AddBond(molecule2.Atoms[0], molecule2.Atoms[1], BondOrder.Triple);

            setOfProducts.Add(molecule1);
            setOfProducts.Add(molecule2);
            return(setOfProducts);
        }
Exemple #6
0
        public void MethyleneCyclopropeneTest()
        {
            IAtomContainer mol = builder.NewAtomContainer();

            AbstractSignatureTest.AddCarbons(mol, 4);
            AbstractSignatureTest.AddHydrogens(mol, 1, 2);
            AbstractSignatureTest.AddHydrogens(mol, 2, 1);
            AbstractSignatureTest.AddHydrogens(mol, 3, 1);
            mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Double);
            mol.AddBond(mol.Atoms[0], mol.Atoms[2], BondOrder.Single);
            mol.AddBond(mol.Atoms[0], mol.Atoms[3], BondOrder.Single);
            mol.AddBond(mol.Atoms[2], mol.Atoms[3], BondOrder.Double);
            MoleculeSignature molSig = new MoleculeSignature(mol);

            string sigFor2Height1 = molSig.SignatureStringForVertex(2, 1);
            string sigFor3Height1 = molSig.SignatureStringForVertex(3, 1);

            Assert.IsTrue(
                sigFor2Height1.Equals(sigFor3Height1),
                "Height 1 signatures for atoms 2 and 3" + " should be the same");

            string sigFor2Height2 = molSig.SignatureStringForVertex(2, 1);
            string sigFor3Height2 = molSig.SignatureStringForVertex(3, 1);

            Assert.IsTrue(
                sigFor2Height2.Equals(sigFor3Height2),
                "Height 2 signatures for atoms 2 and 3" + " should be the same");
        }
        /// <summary>
        /// Get the expected set of molecules.
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var            setOfProducts = builder.NewAtomContainerSet();
            IAtomContainer molecule1     = builder.NewAtomContainer();

            molecule1.Atoms.Add(builder.NewAtom("O"));
            molecule1.Atoms.Add(builder.NewAtom("C"));
            molecule1.AddBond(molecule1.Atoms[0], molecule1.Atoms[1], BondOrder.Double);
            molecule1.Atoms.Add(builder.NewAtom("H"));
            molecule1.AddBond(molecule1.Atoms[1], molecule1.Atoms[2], BondOrder.Single);
            molecule1.Atoms.Add(builder.NewAtom("H"));
            molecule1.AddBond(molecule1.Atoms[1], molecule1.Atoms[3], BondOrder.Single);
            molecule1.Atoms[0].FormalCharge = 1;
            molecule1.Atoms.Add(builder.NewAtom("H"));
            molecule1.AddBond(molecule1.Atoms[0], molecule1.Atoms[4], BondOrder.Single);
            setOfProducts.Add(molecule1);

            IAtomContainer molecule2 = builder.NewAtomContainer();

            molecule2.Atoms.Add(builder.NewAtom("C"));
            molecule2.Atoms.Add(builder.NewAtom("H"));
            molecule2.AddBond(molecule2.Atoms[0], molecule2.Atoms[1], BondOrder.Single);
            molecule2.Atoms.Add(builder.NewAtom("H"));
            molecule2.AddBond(molecule2.Atoms[0], molecule2.Atoms[2], BondOrder.Single);
            molecule2.Atoms.Add(builder.NewAtom("H"));
            molecule2.AddBond(molecule2.Atoms[0], molecule2.Atoms[3], BondOrder.Single);
            molecule2.SingleElectrons.Add(new SingleElectron(molecule2.Atoms[0]));
            setOfProducts.Add(molecule2);

            return(setOfProducts);
        }
Exemple #8
0
        /// <summary>
        /// Get the example set of molecules.
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExampleReactants()
        {
            var            setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet();
            IAtomContainer molecule       = builder.NewAtomContainer();//CreateFromSmiles("C-C#[O+]")

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[2], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[3], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[4], BondOrder.Single);
            IAtom oxy = builder.NewAtom("O");

            oxy.FormalCharge = 1;
            molecule.Atoms.Add(oxy);
            molecule.AddBond(molecule.Atoms[4], molecule.Atoms[5], BondOrder.Triple);

            try
            {
                AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);

                CDK.LonePairElectronChecker.Saturate(molecule);
                MakeSureAtomTypesAreRecognized(molecule);
            }
            catch (CDKException e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }

            setOfReactants.Add(molecule);
            return(setOfReactants);
        }
        public void TestAutomatic_Set_Active_Bond()
        {
            /* ionize all possible double bonds */
            IAtomContainer reactant = builder.NewAtomContainer();//Miles("C=CC")

            reactant.Atoms.Add(builder.NewAtom("C"));
            reactant.Atoms.Add(builder.NewAtom("C"));
            reactant.Atoms.Add(builder.NewAtom("C"));
            reactant.AddBond(reactant.Atoms[0], reactant.Atoms[1], BondOrder.Double);
            reactant.AddBond(reactant.Atoms[1], reactant.Atoms[2], BondOrder.Single);
            AddExplicitHydrogens(reactant);

            var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet();

            setOfReactants.Add(reactant);

            /* initiate */
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(reactant);
            MakeSureAtomTypesAreRecognized(reactant);

            IReactionProcess type = new ElectronImpactPDBReaction();
            var setOfReactions    = type.Initiate(setOfReactants, null);

            Assert.AreEqual(2, setOfReactions.Count);

            IAtomContainer molecule = setOfReactions[0].Products[0];

            Assert.AreEqual(1, molecule.Atoms[0].FormalCharge.Value);
            Assert.AreEqual(1, molecule.GetConnectedSingleElectrons(molecule.Atoms[1]).Count());

            molecule = setOfReactions[1].Products[0];
            Assert.AreEqual(1, molecule.Atoms[1].FormalCharge.Value);
            Assert.AreEqual(1, molecule.GetConnectedSingleElectrons(molecule.Atoms[0]).Count());
        }
Exemple #10
0
        /// <inheritdoc/>
        public override void MakeEdge(int vertexIndex1, int vertexIndex2, string vertexSymbol1, string vertexSymbol2, string edgeLabel)
        {
            switch (edgeLabel)
            {
            case "":
                container.AddBond(container.Atoms[vertexIndex1], container.Atoms[vertexIndex2], BondOrder.Single);
                break;

            case "=":
                container.AddBond(container.Atoms[vertexIndex1], container.Atoms[vertexIndex2], BondOrder.Double);
                break;

            case "#":
                container.AddBond(container.Atoms[vertexIndex1], container.Atoms[vertexIndex2], BondOrder.Triple);
                break;

            case "p":
                IBond bond = builder.NewBond(container.Atoms[vertexIndex1], container.Atoms[vertexIndex2], BondOrder.Single);
                bond.IsAromatic = true;
                container.Bonds.Add(bond);
                break;

            default:
                break;
            }
        }
        public void TestM25()
        {
            //CreateFromSmiles("C[O*]")
            IAtomContainer expected1 = builder.NewAtomContainer();

            expected1.Atoms.Add(builder.NewAtom("C"));
            expected1.Atoms.Add(builder.NewAtom("O"));
            expected1.SingleElectrons.Add(builder.NewSingleElectron(expected1.Atoms[1]));
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[1], BondOrder.Single);
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[2], BondOrder.Single);
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[3], BondOrder.Single);
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[4], BondOrder.Single);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(expected1);

            string[] expectedTypes = { "C.sp3", "O.sp3.radical", "H", "H", "H" };
            Assert.AreEqual(expectedTypes.Length, expected1.Atoms.Count);
            for (int i = 0; i < expectedTypes.Length; i++)
            {
                IAtom     nextAtom      = expected1.Atoms[i];
                IAtomType perceivedType = matcher.FindMatchingAtomType(expected1, nextAtom);
                Assert.IsNotNull(perceivedType, "Missing atom type for: " + nextAtom + " " + i + " expected: " + expectedTypes[i]);
                Assert.AreEqual(expectedTypes[i], perceivedType.AtomTypeName, "Incorrect atom type perceived for: " + nextAtom);
            }
        }
        public void TestM19()
        {
            //CreateFromSmiles("C=[N*+]")
            IAtomContainer expected1 = builder.NewAtomContainer();

            expected1.Atoms.Add(builder.NewAtom("C"));
            expected1.Atoms.Add(builder.NewAtom("N"));
            expected1.Atoms[1].FormalCharge = 1;
            expected1.SingleElectrons.Add(builder.NewSingleElectron(expected1.Atoms[1]));
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[1], BondOrder.Double);
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[2], BondOrder.Single);
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[3], BondOrder.Single);
            expected1.AddBond(expected1.Atoms[1], expected1.Atoms[4], BondOrder.Single);

            string[] expectedTypes = { "C.sp2", "N.plus.sp2.radical", "H", "H", "H" };
            Assert.AreEqual(expectedTypes.Length, expected1.Atoms.Count);
            for (int i = 0; i < expectedTypes.Length; i++)
            {
                IAtom     nextAtom      = expected1.Atoms[i];
                IAtomType perceivedType = matcher.FindMatchingAtomType(expected1, nextAtom);
                Assert.IsNotNull(perceivedType, "Missing atom type for: " + nextAtom + " " + i + " expected: " + expectedTypes[i]);
                Assert.AreEqual(expectedTypes[i], perceivedType.AtomTypeName, "Incorrect atom type perceived for: " + nextAtom);
            }
        }
Exemple #13
0
        public void TestCalculatePositive_IAtomContainer_IAtom()
        {
            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
            molecule.Atoms[1].FormalCharge = +1;
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[3], BondOrder.Double);

            AddExplicitHydrogens(molecule);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            CDK.LonePairElectronChecker.Saturate(molecule);

            for (int i = 0; i < molecule.Atoms.Count; i++)
            {
                if (i == 1)
                {
                    Assert.AreNotSame(0.0, StabilizationCharges.CalculatePositive(molecule, molecule.Atoms[i]));
                }
                else
                {
                    Assert.AreEqual(0.0, StabilizationCharges.CalculatePositive(molecule, molecule.Atoms[i]), 0.001);
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// Get the expected set of molecules.
        /// </summary>
        /// <returns>The IAtomContainerSet</returns>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();
            //C[C+]O|
            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms[1].FormalCharge = 1;
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("O"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single);

            try
            {
                AddExplicitHydrogens(molecule);

                AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
                CDK.LonePairElectronChecker.Saturate(molecule);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }
            setOfProducts.Add(molecule);
            return(setOfProducts);
        }
        public void Test12DimethylBenzene()
        {
            var            builder  = CDK.Builder;
            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Double);
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[3], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[3], molecule.Atoms[4], BondOrder.Double);
            molecule.AddBond(molecule.Atoms[4], molecule.Atoms[5], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[5], molecule.Atoms[0], BondOrder.Double);
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[6], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[7], BondOrder.Single);

            // 2,3-dimethyl-1,3-butadiene matches
            IAtomContainer query1 = builder.NewAtomContainer();

            query1.Atoms.Add(builder.NewAtom("C"));
            query1.Atoms.Add(builder.NewAtom("C"));
            query1.Atoms.Add(builder.NewAtom("C"));
            query1.Atoms.Add(builder.NewAtom("C"));
            query1.Atoms.Add(builder.NewAtom("C"));
            query1.Atoms.Add(builder.NewAtom("C"));
            query1.AddBond(query1.Atoms[0], query1.Atoms[1], BondOrder.Single);
            query1.AddBond(query1.Atoms[1], query1.Atoms[2], BondOrder.Double);
            query1.AddBond(query1.Atoms[3], query1.Atoms[0], BondOrder.Double);
            query1.AddBond(query1.Atoms[0], query1.Atoms[4], BondOrder.Single);
            query1.AddBond(query1.Atoms[1], query1.Atoms[5], BondOrder.Single);
            QueryAtomContainer queryContainer1 = QueryAtomContainerCreator.CreateSymbolAndBondOrderQueryContainer(query1);

            Assert.IsTrue(new UniversalIsomorphismTester().IsSubgraph(molecule, queryContainer1));

            // 2,3-dimethyl-2-butene does not match
            IAtomContainer query2 = builder.NewAtomContainer();

            query2.Atoms.Add(builder.NewAtom("C"));
            query2.Atoms.Add(builder.NewAtom("C"));
            query2.Atoms.Add(builder.NewAtom("C"));
            query2.Atoms.Add(builder.NewAtom("C"));
            query2.Atoms.Add(builder.NewAtom("C"));
            query2.Atoms.Add(builder.NewAtom("C"));
            query2.AddBond(query2.Atoms[0], query2.Atoms[1], BondOrder.Double);
            query2.AddBond(query2.Atoms[1], query2.Atoms[2], BondOrder.Single);
            query2.AddBond(query2.Atoms[3], query2.Atoms[0], BondOrder.Single);
            query2.AddBond(query2.Atoms[0], query2.Atoms[4], BondOrder.Single);
            query2.AddBond(query2.Atoms[1], query2.Atoms[5], BondOrder.Single);
            QueryAtomContainer queryContainer2 = QueryAtomContainerCreator.CreateSymbolAndBondOrderQueryContainer(query2);

            Assert.IsFalse(new UniversalIsomorphismTester().IsSubgraph(molecule, queryContainer2));
        }
Exemple #16
0
        public void TestOspDoubleB()
        {
            //CreateFromSmiles("O=C")
            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("O"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[3], BondOrder.Single);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            CDK.LonePairElectronChecker.Saturate(molecule);

            molecule.Atoms[0].IsReactiveCenter = true;
            molecule.Atoms[1].IsReactiveCenter = true;
            molecule.Bonds[0].IsReactiveCenter = true;

            var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet();

            setOfReactants.Add(molecule);

            IReactionProcess type = new HeterolyticCleavagePBReaction();
            var paramList         = new List <IParameterReaction>();
            var param             = new SetReactionCenter();

            param.IsSetParameter = true;
            paramList.Add(param);
            type.ParameterList = paramList;

            /* initiate */
            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(1, setOfReactions.Count);

            // expected products

            //CreateFromSmiles("[O-][C+]")
            IAtomContainer expected1 = builder.NewAtomContainer();

            expected1.Atoms.Add(builder.NewAtom("O"));
            expected1.Atoms[0].FormalCharge = -1;
            expected1.Atoms.Add(builder.NewAtom("C"));
            expected1.Atoms[1].FormalCharge = +1;
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[1], BondOrder.Single);
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.AddBond(expected1.Atoms[1], expected1.Atoms[2], BondOrder.Single);
            expected1.AddBond(expected1.Atoms[1], expected1.Atoms[3], BondOrder.Single);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(expected1);
            CDK.LonePairElectronChecker.Saturate(expected1);
            IAtomContainer     product1  = setOfReactions[0].Products[0];
            QueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(expected1);

            Assert.IsTrue(uiTester.IsIsomorph(product1, queryAtom));
        }
        public static IAtomContainer MakeSandwich(int ringSize, bool hasMethyl)
        {
            IAtomContainer mol = builder.NewAtomContainer();

            AbstractSignatureTest.AddCarbons(mol, (ringSize * 2));
            mol.Atoms.Add(builder.NewAtom("Fe"));
            int center = ringSize * 2;

            // face A
            for (int i = 0; i < ringSize - 1; i++)
            {
                mol.AddBond(mol.Atoms[i], mol.Atoms[i + 1], BondOrder.Single);
                mol.AddBond(mol.Atoms[i], mol.Atoms[center], BondOrder.Single);
            }
            mol.AddBond(mol.Atoms[ringSize - 1], mol.Atoms[0], BondOrder.Single);
            mol.AddBond(mol.Atoms[ringSize - 1], mol.Atoms[center], BondOrder.Single);

            //        // face B
            for (int i = 0; i < ringSize - 1; i++)
            {
                mol.AddBond(mol.Atoms[ringSize + 1], mol.Atoms[i + ringSize + 1], BondOrder.Single);
                mol.AddBond(mol.Atoms[ringSize + 1], mol.Atoms[center], BondOrder.Single);
            }
            mol.AddBond(mol.Atoms[(2 * ringSize) - 1], mol.Atoms[ringSize], BondOrder.Single);
            mol.AddBond(mol.Atoms[(2 * ringSize) - 1], mol.Atoms[center], BondOrder.Single);

            if (hasMethyl)
            {
                mol.Atoms.Add(builder.NewAtom("C"));
                mol.AddBond(mol.Atoms[0], mol.Atoms.Last(), BondOrder.Single);
            }

            return(mol);
        }
        public override void TestInitiate_IAtomContainerSet_IAtomContainerSet()
        {
            IReactionProcess type = new HyperconjugationReaction();
            var setOfReactants    = ChemObjectBuilder.Instance.NewAtomContainerSet();

            /* [C+]CC */
            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms[0].FormalCharge = 1;
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single);
            AddExplicitHydrogens(molecule);

            setOfReactants.Add(molecule);

            /* automatic search of the center active */
            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter();

            param.IsSetParameter = false;
            paramList.Add(param);
            type.ParameterList = paramList;

            /* initiate */
            MakeSureAtomTypesAreRecognized(molecule);

            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(2, setOfReactions.Count);
            Assert.AreEqual(2, setOfReactions[0].Products.Count);

            IAtomContainer product = setOfReactions[0].Products[0];
            /* C=CC */
            IAtomContainer molecule2 = builder.NewAtomContainer();

            molecule2.Atoms.Add(builder.NewAtom("C"));
            molecule2.Atoms.Add(builder.NewAtom("C"));
            molecule2.AddBond(molecule2.Atoms[0], molecule2.Atoms[1], BondOrder.Double);
            molecule2.Atoms.Add(builder.NewAtom("C"));
            molecule2.AddBond(molecule2.Atoms[1], molecule2.Atoms[2], BondOrder.Single);
            AddExplicitHydrogens(molecule2);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, product));

            product = setOfReactions[0].Products[1];
            /* [H+] */
            molecule2 = builder.NewAtomContainer();
            molecule2.Atoms.Add(builder.NewAtom("H"));
            molecule2.Atoms[0].FormalCharge = 1;

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, product));
        }
        public IAtomContainer MakeCCC()
        {
            IAtomContainer container = builder.NewAtomContainer();

            container.Atoms.Add(builder.NewAtom("C", new Vector2(-1, -1)));
            container.Atoms.Add(builder.NewAtom("C", new Vector2(0, 0)));
            container.Atoms.Add(builder.NewAtom("C", new Vector2(1, -1)));
            container.AddBond(container.Atoms[0], container.Atoms[1], BondOrder.Single);
            container.AddBond(container.Atoms[1], container.Atoms[2], BondOrder.Single);
            return(container);
        }
        public static IAtomContainer MakeCyclobutane()
        {
            IAtomContainer mol = builder.NewAtomContainer();

            AddCarbons(mol, 4);
            mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Single);
            mol.AddBond(mol.Atoms[0], mol.Atoms[3], BondOrder.Single);
            mol.AddBond(mol.Atoms[1], mol.Atoms[2], BondOrder.Single);
            mol.AddBond(mol.Atoms[2], mol.Atoms[3], BondOrder.Single);
            return(mol);
        }
 /// <summary>
 /// This method creates <i>E</i>-but-2-ene.
 /// </summary>
 static DoubleBondStereochemistryTest()
 {
     molecule = new AtomContainer();
     molecule.Atoms.Add(new Atom("C"));
     molecule.Atoms.Add(new Atom("C"));
     molecule.Atoms.Add(new Atom("C"));
     molecule.Atoms.Add(new Atom("C"));
     molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
     molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Double);
     molecule.AddBond(molecule.Atoms[2], molecule.Atoms[3], BondOrder.Single);
     ligands = new IBond[] { molecule.Bonds[0], molecule.Bonds[2] };
 }
Exemple #22
0
        static IAtomContainer But2ene()
        {
            IAtomContainer container = CDK.Builder.NewAtomContainer();

            container.Atoms.Add(Atom("C", 1));
            container.Atoms.Add(Atom("C", 1));
            container.Atoms.Add(Atom("C", 3));
            container.Atoms.Add(Atom("C", 3));
            container.AddBond(container.Atoms[0], container.Atoms[1], BondOrder.Double);
            container.AddBond(container.Atoms[0], container.Atoms[2], BondOrder.Single);
            container.AddBond(container.Atoms[1], container.Atoms[3], BondOrder.Single);
            return(container);
        }
 static TetrahedralChiralityTest()
 {
     molecule = new AtomContainer();
     molecule.Atoms.Add(new Atom("Cl"));
     molecule.Atoms.Add(new Atom("C"));
     molecule.Atoms.Add(new Atom("Br"));
     molecule.Atoms.Add(new Atom("I"));
     molecule.Atoms.Add(new Atom("H"));
     molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
     molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single);
     molecule.AddBond(molecule.Atoms[1], molecule.Atoms[3], BondOrder.Single);
     molecule.AddBond(molecule.Atoms[1], molecule.Atoms[4], BondOrder.Single);
     ligands = new IAtom[] { molecule.Atoms[4], molecule.Atoms[3], molecule.Atoms[2], molecule.Atoms[0] };
 }
        private IChemObjectSet <IAtomContainer> GetExampleReactants()
        {
            var            setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet();
            IAtomContainer molecule       = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("O"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[3], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[4], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[5], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[6], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[7], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[8], BondOrder.Single);

            IAtom atom = molecule.Atoms[0];

            atom.FormalCharge = 1;
            molecule.SingleElectrons.Add(new SingleElectron(atom));

            setOfReactants.Add(molecule);
            return(setOfReactants);
        }
Exemple #25
0
        /// <summary>
        /// Get the expected set of molecules.
        /// </summary>
        /// <returns>The IAtomContainerSet</returns>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();

            IAtomContainer expected1 = builder.NewAtomContainer();

            expected1.Atoms.Add(builder.NewAtom("C"));
            expected1.Atoms.Add(builder.NewAtom("O"));
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[1], BondOrder.Single);
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[2], BondOrder.Single);
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[3], BondOrder.Single);
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[4], BondOrder.Single);
            expected1.AddBond(expected1.Atoms[1], expected1.Atoms[5], BondOrder.Single);
            try
            {
                AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(expected1);
                CDK.LonePairElectronChecker.Saturate(expected1);
            }
            catch (CDKException e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }

            IAtomContainer expected2 = builder.NewAtomContainer();

            expected2.Atoms.Add(builder.NewAtom("C"));
            expected2.Atoms[0].FormalCharge = +1;
            expected2.Atoms.Add(builder.NewAtom("H"));
            expected2.Atoms.Add(builder.NewAtom("H"));
            expected2.Atoms.Add(builder.NewAtom("H"));
            expected2.AddBond(expected2.Atoms[0], expected2.Atoms[1], BondOrder.Single);
            expected2.AddBond(expected2.Atoms[0], expected2.Atoms[2], BondOrder.Single);
            expected2.AddBond(expected2.Atoms[0], expected2.Atoms[3], BondOrder.Single);
            try
            {
                AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(expected2);
            }
            catch (CDKException e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }

            setOfProducts.Add(expected1);
            setOfProducts.Add(expected2);
            return(setOfProducts);
        }
        /// <summary>
        /// Make a square with four different elements, to test things like atom color.
        /// </summary>
        /// <returns>an unlikely S-N-O-P square</returns>
        public IAtomContainer MakeSNOPSquare()
        {
            IAtomContainer container = builder.NewAtomContainer();

            container.Atoms.Add(builder.NewAtom("S", new Vector2(-1, -1)));
            container.Atoms.Add(builder.NewAtom("N", new Vector2(1, -1)));
            container.Atoms.Add(builder.NewAtom("O", new Vector2(1, 1)));
            container.Atoms.Add(builder.NewAtom("P", new Vector2(-1, 1)));
            container.AddBond(container.Atoms[0], container.Atoms[1], BondOrder.Single);
            container.AddBond(container.Atoms[0], container.Atoms[3], BondOrder.Single);
            container.AddBond(container.Atoms[1], container.Atoms[2], BondOrder.Single);
            container.AddBond(container.Atoms[2], container.Atoms[3], BondOrder.Single);
            return(container);
        }
Exemple #27
0
        public static IAtomContainer GetIsobutane(IChemObjectBuilder builder)
        {
            IAtomContainer mol = builder.NewAtomContainer();

            mol.Atoms.Add(builder.NewAtom("C"));
            mol.Atoms.Add(builder.NewAtom("C"));
            mol.Atoms.Add(builder.NewAtom("C"));
            mol.Atoms.Add(builder.NewAtom("C"));

            mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Single);
            mol.AddBond(mol.Atoms[0], mol.Atoms[2], BondOrder.Single);
            mol.AddBond(mol.Atoms[0], mol.Atoms[3], BondOrder.Single);
            return(mol);
        }
        public static void AddRing(int atomToAttachTo, int ringSize, IAtomContainer mol)
        {
            int numberOfAtoms = mol.Atoms.Count;
            int previous      = atomToAttachTo;

            for (int i = 0; i < ringSize; i++)
            {
                mol.Atoms.Add(builder.NewAtom("C"));
                int current = numberOfAtoms + i;
                mol.AddBond(mol.Atoms[previous], mol.Atoms[current], BondOrder.Single);
                previous = current;
            }
            mol.AddBond(mol.Atoms[numberOfAtoms], mol.Atoms[numberOfAtoms + (ringSize - 1)], BondOrder.Single);
        }
Exemple #29
0
        public IAtomContainer MakeRing(int ringSize)
        {
            IAtomContainer ring = builder.NewAtomContainer();

            for (int i = 0; i < ringSize; i++)
            {
                ring.Atoms.Add(builder.NewAtom("C"));
                if (i > 0)
                {
                    ring.AddBond(ring.Atoms[i - 1], ring.Atoms[i], BondOrder.Single);
                }
            }
            ring.AddBond(ring.Atoms[0], ring.Atoms[ringSize - 1], BondOrder.Single);
            return(ring);
        }
Exemple #30
0
        public IAtomContainer MakeSquare()
        {
            IAtomContainer square = builder.NewAtomContainer();

            square.Atoms.Add(builder.NewAtom("C"));
            square.Atoms.Add(builder.NewAtom("C"));
            square.Atoms.Add(builder.NewAtom("C"));
            square.Atoms.Add(builder.NewAtom("C"));
            square.AddBond(square.Atoms[0], square.Atoms[1], BondOrder.Single);
            square.AddBond(square.Atoms[0], square.Atoms[3], BondOrder.Single);
            square.AddBond(square.Atoms[1], square.Atoms[2], BondOrder.Single);
            square.AddBond(square.Atoms[2], square.Atoms[3], BondOrder.Single);

            return(Layout(square));
        }