public void TestSort_IAtomContainerSet()
        {
            // Create some IAtomContainers
            var cycloPentane   = builder.NewRing(5, "C");
            var cycloHexane    = builder.NewRing(6, "C");
            var hexaneNitrogen = builder.NewRing(6, "N");

            hexaneNitrogen.Bonds.RemoveAt(0);
            var cycloHexaneNitrogen = builder.NewRing(6, "N");
            var cycloHexeneNitrogen = builder.NewRing(6, "N");

            cycloHexeneNitrogen.Bonds[0].Order = BondOrder.Double;

            // Add them to a IAtomContainerSet
            var atomContainerSet = builder.NewAtomContainerSet();

            atomContainerSet.Add(cycloHexane);
            atomContainerSet.Add(cycloHexeneNitrogen);
            atomContainerSet.Add(cycloPentane);
            atomContainerSet.Add(hexaneNitrogen);
            atomContainerSet.Add(cycloHexaneNitrogen);

            // Sort the IAtomContainerSet
            AtomContainerSetManipulator.Sort(atomContainerSet);

            // Assert.assert the correct order
            Assert.AreSame(cycloPentane, atomContainerSet[0], "first order: cycloPentane");
            Assert.AreSame(cycloHexane, atomContainerSet[1], "second order: cycloHexane");
            Assert.AreSame(hexaneNitrogen, atomContainerSet[2], "third order: hexaneNitrogen");
            Assert.AreSame(cycloHexaneNitrogen, atomContainerSet[3], "forth order: cycloHexaneNitrogen");
            Assert.AreSame(cycloHexeneNitrogen, atomContainerSet[4], "firth order: cycloHexeneNitrogen");
        }
        /// <summary>
        /// Get the expected set of molecules.
        /// TODO:reaction. Set the products
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();

            setOfProducts.Add(null);
            return(setOfProducts);
        }
        public void TestAssignrPiMarsilliFactors_IAtomContainerSet()
        {
            GasteigerPEPEPartialCharges peoe = new GasteigerPEPEPartialCharges();

            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("F"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);

            AddExplicitHydrogens(molecule);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            CDK.LonePairElectronChecker.Saturate(molecule);
            foreach (var atom in molecule.Atoms)
            {
                atom.Charge = 0;
            }

            var set = builder.NewAtomContainerSet();

            set.Add(molecule);
            set.Add(molecule);

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

            Assert.IsNotNull(peoe.AssignrPiMarsilliFactors(set));
        }
        /// <summary>
        /// Get the expected set of molecules. [C-]-C = C
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();

            var 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);
        }
Example #5
0
        /// <summary>
        /// Get the expected set of molecules.
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();
            var molecule      = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("O"));
            molecule.Atoms[0].FormalCharge = 1;
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single);
            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.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[3], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[4], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[5], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[6], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[7], BondOrder.Single);
            try
            {
                AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
                CDK.LonePairElectronChecker.Saturate(molecule);
            }
            catch (CDKException e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }

            setOfProducts.Add(molecule);
            return(setOfProducts);
        }
        /// <summary>
        /// Get the expected set of molecules.
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();
            var 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);

            var 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(CDK.Builder.NewSingleElectron(molecule2.Atoms[0]));
            setOfProducts.Add(molecule2);

            return(setOfProducts);
        }
Example #7
0
        /// <summary>
        /// Get the expected set of molecules.
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();
            //[O+]=C-[C-]-C

            var molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("O"));
            molecule.Atoms[0].FormalCharge = +1;
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms[2].FormalCharge = -1;
            molecule.LonePairs.Add(CDK.Builder.NewLonePair(molecule.Atoms[0]));
            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.Single);

            try
            {
                AddExplicitHydrogens(molecule);
                AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);

                CDK.LonePairElectronChecker.Saturate(molecule);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }
            setOfProducts.Add(molecule);
            return(setOfProducts);
        }
Example #8
0
        public void TestNewMoleculeSet()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            var set = builder.NewAtomContainerSet();

            Assert.IsNotNull(set);
        }
Example #9
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);
        }
Example #10
0
        public static void CleanDataSet(string dataFile)
        {
            var som = builder.NewAtomContainerSet();

            try
            {
                Console.Out.WriteLine("Start clean dataset...");
                using (var fin = new StreamReader(dataFile))
                    using (var imdl = new EnumerableSDFReader(fin, builder))
                    {
                        Console.Out.WriteLine("READY");
                        int c = 0;
                        foreach (var m in imdl)
                        {
                            c++;
                            if (c % 1000 == 0)
                            {
                                Console.Out.WriteLine("...");
                            }
                            if (m.Atoms.Count > 2)
                            {
                                if (m.Atoms[0].Point3D != null)
                                {
                                    som.Add(m);
                                }
                            }
                        }
                    }
                Console.Out.Write("Read File in..");
            }
            catch (Exception exc)
            {
                Console.Out.WriteLine($"Could not read Molecules from file {dataFile} due to: {exc.Message}");
            }
            Console.Out.WriteLine($"{som.Count} Templates are read in");
            WriteChemModel(som, dataFile, "_CLEAN");
        }
Example #11
0
        public void TestWrite_IAtomContainerSet()
        {
            StringWriter writer = new StringWriter();
            IChemObjectSet <IAtomContainer> molSet = builder.NewAtomContainerSet();
            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molSet.Add(molecule);

            SDFWriter sdfWriter = new SDFWriter(writer);

            sdfWriter.Write(molSet);
            sdfWriter.Close();
            Assert.AreNotSame(0, writer.ToString().Length);
        }
Example #12
0
        public void badSmilesLine()
        {
            IChemObjectBuilder              bldr  = CDK.Builder;
            string                          input = "C\nn1cccc1\nc1ccccc1\n";
            DefaultChemObjectReader         cor   = new SMILESReader(new StringReader(input));
            IChemObjectSet <IAtomContainer> mols  = cor.Read(bldr.NewAtomContainerSet());

            Assert.AreEqual(3, mols.Count);
            Assert.AreEqual(1, mols[0].Atoms.Count);
            Assert.IsNull(mols[0].GetProperty <string>(EnumerableSMILESReader.BadSmilesInput));
            Assert.AreEqual(0, mols[1].Atoms.Count);
            Assert.IsNotNull(mols[1].GetProperty <string>(EnumerableSMILESReader.BadSmilesInput));
            Assert.AreEqual(6, mols[2].Atoms.Count);
            Assert.IsNull(mols[2].GetProperty <string>(EnumerableSMILESReader.BadSmilesInput));
        }
        public void TestGetAllMolecules_IReactionScheme_IAtomContainerSet()
        {
            IReactionScheme reactionScheme = builder.NewReactionScheme();
            IReaction       reaction1      = builder.NewReaction();

            reaction1.Products.Add(builder.NewAtomContainer());
            IReaction reaction2 = builder.NewReaction();

            reaction2.Products.Add(builder.NewAtomContainer());
            reactionScheme.Add(reaction1); // 1
            reactionScheme.Add(reaction2); // 2

            Assert.AreEqual(
                2,
                ReactionSchemeManipulator.GetAllAtomContainers(reactionScheme,
                                                               builder.NewAtomContainerSet()).Count);
        }
        /// <summary>
        /// Get the expected set of molecules.
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();

            var 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);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[3], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[3], molecule.Atoms[4], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[4], molecule.Atoms[5], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[4], molecule.Atoms[6], BondOrder.Single);

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

            molecule.Atoms[0].FormalCharge = 0;
            molecule.SingleElectrons.Add(CDK.Builder.NewSingleElectron(molecule.Atoms[0]));

            try
            {
                AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
                MakeSureAtomTypesAreRecognized(molecule);
            }
            catch (CDKException e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }

            setOfProducts.Add(molecule);
            return(setOfProducts);
        }
Example #15
0
        /// <summary>
        /// Get the expected set of molecules. 2-methylnaphthalene.
        /// C=1C=CC2=CC(=CC=C2(C=1))C
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();

            //C=1C=CC2=CC(=CC=C2(C=1))C
            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.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[3], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[3], molecule.Atoms[4], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[4], molecule.Atoms[5], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[5], molecule.Atoms[6], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[6], molecule.Atoms[7], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[7], molecule.Atoms[8], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[8], molecule.Atoms[9], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[9], molecule.Atoms[10], BondOrder.Double);
            molecule.AddBond(molecule.Atoms[10], molecule.Atoms[1], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[9], molecule.Atoms[4], BondOrder.Single);

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

            setOfProducts.Add(molecule);
            return(setOfProducts);
        }
Example #16
0
        public IChemObjectSet <IAtomContainer> ParseCompoundsBlock(XElement parser)
        {
            var set = builder.NewAtomContainerSet();

            // assume the current element is PC-Compounds
            if (!parser.Name.Equals(Name_EL_PCCOMPOUNDS))
            {
                return(null);
            }
            foreach (var elm in parser.Elements(Name_EL_PCCOMPOUND))
            {
                IAtomContainer molecule = ParseMolecule(elm, builder);
                if (molecule.Atoms.Count > 0)
                {
                    // skip empty PC-Compound's
                    set.Add(molecule);
                }
            }
            return(set);
        }
Example #17
0
        public void TestIsEmpty_MoleculeSet()
        {
            IChemModel chemModel = (IChemModel)NewChemObject();
            IChemObjectBuilder builder = chemModel.Builder;

            Assert.IsNotNull(chemModel);
            Assert.IsTrue(chemModel.IsEmpty());

            IAtom atom = builder.NewAtom();
            IAtomContainer mol = builder.NewAtomContainer();
            IChemObjectSet<IAtomContainer> mset = builder.NewAtomContainerSet();

            mol.Atoms.Add(atom);
            mset.Add(mol);
            chemModel.MoleculeSet = mset;
            Assert.IsFalse(chemModel.IsEmpty(), "chem model with a molecule set should not be empty");
            mol.Atoms.Remove(atom);
            Assert.IsFalse(chemModel.IsEmpty(), "chem model with a (empty) molecule set should not be empty");
            chemModel.MoleculeSet = null;
            Assert.IsTrue(chemModel.IsEmpty(), "chemo model with no molecule set should be empty");
        }
Example #18
0
        /// <summary>
        /// Get the expected set of molecules.
        /// </summary>
        /// <returns>The IAtomContainerSet</returns>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();
            //CreateFromSmiles("[C+](H)(H)-[O-]");
            IAtomContainer molecule = builder.NewAtomContainer();
            IAtom          carbon   = builder.NewAtom("C");

            carbon.FormalCharge = 1;
            molecule.Atoms.Add(carbon);
            IAtom oxyg = builder.NewAtom("O");

            oxyg.FormalCharge = -1;
            molecule.Atoms.Add(oxyg);
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
            molecule.Atoms.Add(new Atom("H"));
            molecule.Atoms.Add(new Atom("H"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[2], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[3], BondOrder.Single);

            setOfProducts.Add(molecule);
            return(setOfProducts);
        }
        /// <summary>
        /// Get the expected set of molecules.
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExpectedProducts()
        {
            var setOfProducts = builder.NewAtomContainerSet();

            /* C=C */
            var molecule1 = builder.NewAtomContainer();

            molecule1.Atoms.Add(builder.NewAtom("C"));
            molecule1.Atoms.Add(builder.NewAtom("C"));
            molecule1.AddBond(molecule1.Atoms[0], molecule1.Atoms[1], BondOrder.Double);
            try
            {
                AddExplicitHydrogens(molecule1);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }

            /* [C*] */
            var 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);
            IAtom atom = molecule2.Atoms[0];

            molecule2.SingleElectrons.Add(CDK.Builder.NewSingleElectron(atom));

            setOfProducts.Add(molecule1);
            setOfProducts.Add(molecule2);
            return(setOfProducts);
        }