public MoleculeBuilder FromSmiles(string smiles)
        {
            var builder = new StringBuilder();

            // Switch the current directory to the application's bin directory so
            // it can find all the related Open Babel files
            using(new TemporarilySwitchCurrentDirectory(new DirectoryInfo(AppDomain.CurrentDomain.RelativeSearchPath)))
            {
                var process = new Process
                {
                    StartInfo =
                    {
                        FileName = @".\obabel.exe",
                        Arguments = string.Format("-:\"{0}\" -omol --gen3d", smiles),
                        UseShellExecute = false,
                        RedirectStandardOutput = true
                    }
                };

                process.OutputDataReceived += (sender, args) => builder.AppendLine(args.Data);
                process.Start();
                process.BeginOutputReadLine();
                process.WaitForExit();
            }

            var mol = builder.ToString();
            var reader = new MolReader(() => new StringReader(mol));

            atomData = reader.AtomData;
            bondData = reader.BondData;

            return this;
        }
示例#2
0
        public void MedianTest()
        {
            Assert.AreEqual(Benzene.BalabanJ, Math.Round(this._molSet.Median("BalabanJ"), 4));
            Assert.AreEqual(Benzene.Kappa3, Math.Round(this._molSet.Median("Kappa3"), 4));
            Assert.AreEqual(Benzene.LabuteASA, Math.Round(this._molSet.Median("Labute ASA"), 4));
            Assert.AreEqual(Benzene.Chi0, Math.Round(this._molSet.Median("Chi0"), 4));

            var propane        = new MolReader(FileNames.PropaneFilePath).GetMol();
            var benzene        = new MolReader(FileNames.BenzeneFilePath).GetMol();
            var cyclosporin    = new MolReader(FileNames.CyclosporineFilePath).GetMol();
            var phenylPyridine = new MolReader(FileNames.PyridineFilePath).GetMol();

            this._molSet = new MolDescriptorSet(new List <MolDescriptor>
            {
                new MolDescriptor(propane),
                new MolDescriptor(benzene),
                new MolDescriptor(cyclosporin),
                new MolDescriptor(phenylPyridine)
            });

            var BalabanJMedian  = (PhenylPyridine.BalabanJ + Benzene.BalabanJ) / 2;
            var Kappa3Median    = (PhenylPyridine.Kappa3 + Benzene.Kappa3) / 2;
            var LabuteASAMedian = (PhenylPyridine.LabuteASA + Benzene.LabuteASA) / 2;
            var Chi0Median      = (PhenylPyridine.Chi0 + Benzene.Chi0) / 2;

            Assert.AreEqual(Math.Round(BalabanJMedian, 4), Math.Round(this._molSet.Median("BalabanJ"), 4));
            Assert.AreEqual(Math.Round(Kappa3Median, 4), Math.Round(this._molSet.Median("Kappa3"), 4));
            Assert.AreEqual(Math.Round(LabuteASAMedian, 4), Math.Round(this._molSet.Median("Labute ASA"), 4));
            Assert.AreEqual(Math.Round(Chi0Median, 4), Math.Round(this._molSet.Median("Chi0"), 4));
        }
示例#3
0
        public void TestSetup()
        {
            var propane     = new MolReader(FileNames.PropaneFilePath).GetMol();
            var benzene     = new MolReader(FileNames.BenzeneFilePath).GetMol();
            var cyclosporin = new MolReader(FileNames.CyclosporineFilePath).GetMol();

            this._molSet = new MolDescriptorSet(new List <MolDescriptor> {
                new MolDescriptor(propane), new MolDescriptor(benzene), new MolDescriptor(cyclosporin)
            });
        }
        public void PostedFileTest()
        {
            using (var stream = new FileStream(FileNames.MultiMolFilePath, FileMode.Open))
            {
                var postedFile = new Mock <HttpPostedFileBase>();
                postedFile.Setup(f => f.ContentLength).Returns((int)stream.Length).Verifiable();
                postedFile.Setup(f => f.FileName).Returns(FileNames.MultiMolFilePath.Split('/').Last()).Verifiable();
                postedFile.Setup(f => f.InputStream).Returns(stream).Verifiable();

                var reader = new MolReader(postedFile.Object);
                this._molCollection = reader.Open();
                Assert.AreEqual <int>(1597, this._molCollection.Count(), string.Format("PostedFileTest: {0} does not equal 1597", this._molCollection.Count()));
                File.Delete(reader.FilePath);
            }
        }
        public void GasteigerChargeTest()
        {
            var mol        = new MolReader(FileNames.BenzeneFilePath).GetMol();
            var chargedMol = mol.AssignGasteigerCharges();

            Assert.IsTrue(chargedMol.Atoms().Count() > 0);
            foreach (var atom in chargedMol.Atoms())
            {
                if (atom.IsCarbon())
                {
                    Assert.AreEqual(-0.0618, Math.Round(atom.GetPartialCharge(), 4));
                }
                else
                {
                    Assert.AreEqual(0.0618, Math.Round(atom.GetPartialCharge(), 4));
                }
            }

            mol        = new MolReader(FileNames.PropaneFilePath).GetMol();
            chargedMol = mol.AssignGasteigerCharges();
            Assert.IsTrue(chargedMol.Atoms().Count() > 0);
            foreach (var atom in chargedMol.Atoms())
            {
                if (atom.IsCarbon() && (atom.GetIdx() == 1 || atom.GetIdx() == 3))
                {
                    Assert.AreEqual(-0.0655, Math.Round(atom.GetPartialCharge(), 4));
                }
                else if (atom.IsCarbon() && atom.GetIdx() == 2)
                {
                    Assert.AreEqual(-0.0588, Math.Round(atom.GetPartialCharge(), 4));
                }
                else if (atom.IsHydrogen() && atom.Neighbors().First().IsCarbon() && (atom.Neighbors().First().GetIdx() == 1 || atom.Neighbors().First().GetIdx() == 3))
                {
                    Assert.AreEqual(0.0230, Math.Round(atom.GetPartialCharge(), 4));
                }
                else if (atom.IsHydrogen() && atom.Neighbors().First().IsCarbon() && atom.Neighbors().First().GetIdx() == 2)
                {
                    Assert.AreEqual(0.0260, Math.Round(atom.GetPartialCharge(), 4));
                }
            }
        }
        public void FeatureNamesTest()
        {
            var mol = new MolReader(FileNames.PropaneFilePath).GetMol();

            this._descriptor = new MolDescriptor(mol);

            Assert.AreEqual(_featureNames.Length, MolDescriptor.FeatureCount());

            foreach (var name in this._featureNames)
            {
                Assert.IsTrue(MolDescriptor.GetFeatureNames().Contains(name));
            }
            try
            {
                this._descriptor.FeatureValue("Fenske Descriptor");
                Assert.Fail("Fenske Descriptor is not a valid feature");
            }
            catch (ArgumentException)
            {
                // Expected
            }
        }
        public void FormalChargeTest()
        {
            var mol = new MolReader(FileNames.AceticAcidFilePath).GetMol();

            this._descriptor = new MolDescriptor(mol);
            Assert.AreEqual(0, this._descriptor.TotalCharge);

            var newMol = mol.AssignGasteigerCharges();

            Assert.AreEqual(0, Math.Round(newMol.Atoms().Sum(a => a.GetPartialCharge()), 4));

            mol = new MolReader(FileNames.AcetateFilePath).GetMol();
            this._descriptor = new MolDescriptor(mol);
            Assert.AreEqual(-1, this._descriptor.TotalCharge);

            newMol           = mol.AssignGasteigerCharges();
            this._descriptor = new MolDescriptor(newMol);
            Assert.AreEqual(-1, Math.Round(newMol.Atoms().Sum(a => a.GetPartialCharge()), 4));

            mol = new MolReader(FileNames.CyclosporineFilePath).GetMol();
            this._descriptor = new MolDescriptor(mol);
            Assert.AreEqual(0d, Math.Round(this._descriptor.TotalCharge, 4));
        }
        public void PropaneTest()
        {
            var mol = new MolReader(FileNames.PropaneFilePath).GetMol();

            this._descriptor = new MolDescriptor(mol);
            Assert.AreEqual(Propane.Title, this._descriptor.Title);
            Assert.AreEqual(Propane.Smiles, this._descriptor.Smiles);
            Assert.AreEqual(Propane.SingleCarbonCount, this._descriptor.FragmentCount("C"));
            Assert.AreEqual(Propane.DoubleCarbonCount, this._descriptor.FragmentCount("CC"));
            Assert.AreEqual(Propane.TripleCarbonCount, this._descriptor.FragmentCount("CCC"));
            Assert.AreEqual(0, this._descriptor.FragmentCount("c"));
            Assert.AreEqual(Propane.LabuteASA, Math.Round(this._descriptor.LabuteASA, 4));

            var frags = this._descriptor.FragmentCounts;

            foreach (var key in frags.Keys)
            {
                int count;
                var hasCount = frags.TryGetValue(key, out count);
                if (!hasCount)
                {
                    throw new KeyNotFoundException(string.Format("{0} is not a valid key", key));
                }
                Assert.AreEqual(0, count);
            }
            Assert.AreEqual(Propane.NumHeavyAtoms, this._descriptor.FeatureValue("Number Heavy Atoms").Value);
            Assert.AreEqual(Propane.PeoeVSA1, this._descriptor.PeoeVSA1);
            Assert.AreEqual(Propane.PeoeVSA2, this._descriptor.PeoeVSA2);
            Assert.AreEqual(Propane.PeoeVSA3, this._descriptor.PeoeVSA3);
            Assert.AreEqual(Propane.PeoeVSA4, this._descriptor.PeoeVSA4);
            Assert.AreEqual(Propane.PeoeVSA5, this._descriptor.PeoeVSA5);
            Assert.AreEqual(Propane.PeoeVSA6, Math.Round(this._descriptor.PeoeVSA6, 4));
            Assert.AreEqual(Propane.PeoeVSA7, this._descriptor.PeoeVSA7);
            Assert.AreEqual(Propane.PeoeVSA8, this._descriptor.PeoeVSA8);
            Assert.AreEqual(Propane.PeoeVSA9, this._descriptor.PeoeVSA9);
            Assert.AreEqual(Propane.PeoeVSA10, this._descriptor.PeoeVSA10);
            Assert.AreEqual(Propane.PeoeVSA11, this._descriptor.PeoeVSA11);
            Assert.AreEqual(Propane.PeoeVSA12, this._descriptor.PeoeVSA12);
            Assert.AreEqual(Propane.SmrVSA1, this._descriptor.SmrVSA1);
            Assert.AreEqual(Propane.SmrVSA2, this._descriptor.SmrVSA2);
            Assert.AreEqual(Propane.SmrVSA3, this._descriptor.SmrVSA3);
            Assert.AreEqual(Propane.SmrVSA4, this._descriptor.SmrVSA4);
            Assert.AreEqual(Propane.SmrVSA5, Math.Round(this._descriptor.SmrVSA5, 4));
            Assert.AreEqual(Propane.SmrVSA6, this._descriptor.SmrVSA6);
            Assert.AreEqual(Propane.SmrVSA7, this._descriptor.SmrVSA7);
            Assert.AreEqual(Propane.SmrVSA8, this._descriptor.SmrVSA8);
            Assert.AreEqual(Propane.SmrVSA9, this._descriptor.SmrVSA9);
            Assert.AreEqual(Propane.SmrVSA10, this._descriptor.SmrVSA10);
            Assert.AreEqual(Propane.SLogPVSA1, this._descriptor.SLogPVSA1);
            Assert.AreEqual(Propane.SLogPVSA2, this._descriptor.SLogPVSA2);
            Assert.AreEqual(Propane.SLogPVSA3, this._descriptor.SLogPVSA3);
            Assert.AreEqual(Propane.SLogPVSA4, this._descriptor.SLogPVSA4);
            Assert.AreEqual(Propane.SLogPVSA5, Math.Round(this._descriptor.SLogPVSA5, 4));
            Assert.AreEqual(Propane.SLogPVSA6, this._descriptor.SLogPVSA6);
            Assert.AreEqual(Propane.SLogPVSA7, this._descriptor.SLogPVSA7);
            Assert.AreEqual(Propane.SLogPVSA8, this._descriptor.SLogPVSA8);
            Assert.AreEqual(Propane.SLogPVSA9, this._descriptor.SLogPVSA9);
            Assert.AreEqual(Propane.SLogPVSA10, this._descriptor.SLogPVSA10);
            Assert.AreEqual(Propane.SLogPVSA11, this._descriptor.SLogPVSA11);
            Assert.AreEqual(Propane.SLogPVSA12, this._descriptor.SLogPVSA12);
            Assert.AreEqual(Propane.VsaEState9, Math.Round(this._descriptor.VsaEState9, 1));
            Assert.AreEqual(Propane.EStateVsa5, Math.Round(this._descriptor.EStateVsa5, 4));
            Assert.AreEqual(Propane.EStateVsa8, Math.Round(this._descriptor.EStateVsa8, 4));
            Assert.AreEqual(Propane.Chi0, Math.Round(this._descriptor.Chi0, 4));
            Assert.AreEqual(Propane.Chi1, Math.Round(this._descriptor.Chi1, 4));
            Assert.AreEqual(Propane.Chi0v, Math.Round(this._descriptor.Chi0v, 4));
            Assert.AreEqual(Propane.Chi1v, Math.Round(this._descriptor.Chi1v, 4));
            Assert.AreEqual(Propane.Chi2v, Math.Round(this._descriptor.Chi2v, 4));
            Assert.AreEqual(Propane.Chi3v, Math.Round(this._descriptor.Chi3v, 4));
            Assert.AreEqual(Propane.Chi4v, Math.Round(this._descriptor.Chi4v, 4));
            Assert.AreEqual(Propane.Chi0n, Math.Round(this._descriptor.Chi0n, 4));
            Assert.AreEqual(Propane.Chi1n, Math.Round(this._descriptor.Chi1n, 4));
            Assert.AreEqual(Propane.Chi2n, Math.Round(this._descriptor.Chi2n, 4));
            Assert.AreEqual(Propane.Chi3n, Math.Round(this._descriptor.Chi3n, 4));
            Assert.AreEqual(Propane.Chi4n, Math.Round(this._descriptor.Chi4n, 4));
            Assert.AreEqual(Propane.HallKierAlpha, Math.Round(this._descriptor.HallKierAlpha, 1));
            Assert.AreEqual(Propane.Kappa1, Math.Round(this._descriptor.Kappa1, 1));
            Assert.AreEqual(Propane.Kappa2, Math.Round(this._descriptor.Kappa2, 1));
            Assert.AreEqual(Propane.Kappa3, Math.Round(this._descriptor.Kappa3, 1));
            Assert.AreEqual(Propane.Ipc, Math.Round(this._descriptor.Ipc, 4));
            Assert.AreEqual(Propane.BalabanJ, Math.Round(this._descriptor.BalabanJ, 4));
        }
        public void CyclosporineTest()
        {
            var mol = new MolReader(FileNames.CyclosporineFilePath).GetMol();

            this._descriptor = new MolDescriptor(mol);
            Assert.AreEqual(Cyclosporine.Title, this._descriptor.Title);
            Assert.AreEqual(Cyclosporine.CarbonylCount, this._descriptor.FragmentCount(Fragments.Collection["fr_C=O"]));
            Assert.AreEqual(Cyclosporine.LabuteASA, Math.Round(this._descriptor.LabuteASA, 4));
            Assert.AreEqual(Cyclosporine.NumHeavyAtoms, this._descriptor.NumHeavyAtoms);

            /** These test are not run because the values given by RDKit (used as the truth argument in
             *  the asserts) appear to be incorrect. This is based upon the fact that the total charge
             *  calculated by RDKit after computing the Gasteiger charges for cyclosporine gives -4.55
             *  and the actual total charge for cyclosporine should be close to 0. In comparison, the
             *  total charge given by OpenBabel (after assigning Gasteiger charges) was close to 0.
             *
             *  Since the binning of the PEOE VSA algorithm is dependent upon Gasteiger charges, this
             *  leads me to believe that the binning given by RDKit is incorrect and hence is leading
             *  to false fails for these tests.
             * Assert.AreEqual(Cyclosporine.PeoeVSA1, Math.Round(this._descriptor.PeoeVSA1, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA2, Math.Round(this._descriptor.PeoeVSA2, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA3, Math.Round(this._descriptor.PeoeVSA3, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA4, Math.Round(this._descriptor.PeoeVSA4, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA5, Math.Round(this._descriptor.PeoeVSA5, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA6, Math.Round(this._descriptor.PeoeVSA6, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA7, Math.Round(this._descriptor.PeoeVSA7, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA8, Math.Round(this._descriptor.PeoeVSA8, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA9, Math.Round(this._descriptor.PeoeVSA9, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA10, Math.Round(this._descriptor.PeoeVSA10, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA11, Math.Round(this._descriptor.PeoeVSA11, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA12, Math.Round(this._descriptor.PeoeVSA12, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA13, Math.Round(this._descriptor.PeoeVSA13, 4));
             * Assert.AreEqual(Cyclosporine.PeoeVSA14, Math.Round(this._descriptor.PeoeVSA14, 4));
             * */
            Assert.AreEqual(Cyclosporine.SmrVSA1, Math.Round(this._descriptor.SmrVSA1, 4));
            Assert.AreEqual(Cyclosporine.SmrVSA2, Math.Round(this._descriptor.SmrVSA2, 4));
            Assert.AreEqual(Cyclosporine.SmrVSA3, Math.Round(this._descriptor.SmrVSA3, 4));
            Assert.AreEqual(Cyclosporine.SmrVSA4, Math.Round(this._descriptor.SmrVSA4, 4));
            Assert.AreEqual(Cyclosporine.SmrVSA5, Math.Round(this._descriptor.SmrVSA5, 4));
            Assert.AreEqual(Cyclosporine.SmrVSA6, Math.Round(this._descriptor.SmrVSA6, 4));
            Assert.AreEqual(Cyclosporine.SmrVSA7, Math.Round(this._descriptor.SmrVSA7, 4));
            Assert.AreEqual(Cyclosporine.SmrVSA8, Math.Round(this._descriptor.SmrVSA8, 4));
            Assert.AreEqual(Cyclosporine.SmrVSA9, Math.Round(this._descriptor.SmrVSA9, 4));
            Assert.AreEqual(Cyclosporine.SmrVSA10, Math.Round(this._descriptor.SmrVSA10, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA1, Math.Round(this._descriptor.SLogPVSA1, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA2, Math.Round(this._descriptor.SLogPVSA2, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA3, Math.Round(this._descriptor.SLogPVSA3, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA4, Math.Round(this._descriptor.SLogPVSA4, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA5, Math.Round(this._descriptor.SLogPVSA5, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA6, Math.Round(this._descriptor.SLogPVSA6, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA7, Math.Round(this._descriptor.SLogPVSA7, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA8, Math.Round(this._descriptor.SLogPVSA8, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA9, Math.Round(this._descriptor.SLogPVSA9, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA10, Math.Round(this._descriptor.SLogPVSA10, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA11, Math.Round(this._descriptor.SLogPVSA11, 4));
            Assert.AreEqual(Cyclosporine.SLogPVSA12, Math.Round(this._descriptor.SLogPVSA12, 4));
            Assert.AreEqual(Cyclosporine.VsaEState9, Math.Round(this._descriptor.VsaEState9, 4));
            Assert.AreEqual(Cyclosporine.EStateVsa1, Math.Round(this._descriptor.EStateVsa1, 4));
            Assert.AreEqual(Cyclosporine.EStateVsa2, Math.Round(this._descriptor.EStateVsa2, 4));
            Assert.AreEqual(Cyclosporine.EStateVsa3, Math.Round(this._descriptor.EStateVsa3, 4));
            Assert.AreEqual(Cyclosporine.EStateVsa4, Math.Round(this._descriptor.EStateVsa4, 4));
            Assert.AreEqual(Cyclosporine.EStateVsa5, Math.Round(this._descriptor.EStateVsa5, 4));
            Assert.AreEqual(Cyclosporine.EStateVsa6, Math.Round(this._descriptor.EStateVsa6, 4));
            Assert.AreEqual(Cyclosporine.EStateVsa7, Math.Round(this._descriptor.EStateVsa7, 4));
            Assert.AreEqual(Cyclosporine.EStateVsa8, Math.Round(this._descriptor.EStateVsa8, 4));
            Assert.AreEqual(Cyclosporine.EStateVsa9, Math.Round(this._descriptor.EStateVsa9, 4));
            Assert.AreEqual(Cyclosporine.EStateVsa10, Math.Round(this._descriptor.EStateVsa10, 4));
            Assert.AreEqual(Cyclosporine.EStateVsa11, Math.Round(this._descriptor.EStateVsa11, 4));
            Assert.AreEqual(Cyclosporine.Chi0, Math.Round(this._descriptor.Chi0, 4));
            Assert.AreEqual(Cyclosporine.Chi1, Math.Round(this._descriptor.Chi1, 4));
            Assert.AreEqual(Cyclosporine.Chi0v, Math.Round(this._descriptor.Chi0v, 4));
            Assert.AreEqual(Cyclosporine.Chi1v, Math.Round(this._descriptor.Chi1v, 4));
            Assert.AreEqual(Cyclosporine.Chi2v, Math.Round(this._descriptor.Chi2v, 4));
            Assert.AreEqual(Cyclosporine.Chi3v, Math.Round(this._descriptor.Chi3v, 4));
            Assert.AreEqual(Cyclosporine.Chi4v, Math.Round(this._descriptor.Chi4v, 4));
            Assert.AreEqual(Cyclosporine.Chi0n, Math.Round(this._descriptor.Chi0n, 4));
            Assert.AreEqual(Cyclosporine.Chi1n, Math.Round(this._descriptor.Chi1n, 4));
            Assert.AreEqual(Cyclosporine.Chi2n, Math.Round(this._descriptor.Chi2n, 4));
            Assert.AreEqual(Cyclosporine.Chi3n, Math.Round(this._descriptor.Chi3n, 4));
            Assert.AreEqual(Cyclosporine.Chi4n, Math.Round(this._descriptor.Chi4n, 4));
            Assert.AreEqual(Cyclosporine.HallKierAlpha, Math.Round(this._descriptor.HallKierAlpha, 4));
            Assert.AreEqual(Cyclosporine.Kappa1, Math.Round(this._descriptor.Kappa1, 4));
            Assert.AreEqual(Cyclosporine.Kappa2, Math.Round(this._descriptor.Kappa2, 4));
            Assert.AreEqual(Cyclosporine.Kappa3, Math.Round(this._descriptor.Kappa3, 4));
            Assert.AreEqual(Cyclosporine.Ipc.ToString("E4"), this._descriptor.Ipc.ToString("E4"));
            Assert.AreEqual(Cyclosporine.BalabanJ, Math.Round(this._descriptor.BalabanJ, 4));
        }