Exemple #1
0
        public async Task <ActionResult <FunctionalGroup> > GetFunctionalGroups(string smiles)
        {
            var fG = await _context.AppFunctionalgroup.ToListAsync();

            ChemInfo.Molecule molecule = new ChemInfo.Molecule(smiles);
            var retVal = new List <AppFunctionalgroupDTO>();

            foreach (var group in fG)
            {
                string smarts = group.Smarts;
                if (!string.IsNullOrEmpty(group.Smarts))
                {
                    if (molecule.FindFunctionalGroup(group))
                    {
                        retVal.Add(new AppFunctionalgroupDTO()
                        {
                            Id     = group.Id,
                            Name   = group.Name,
                            Smarts = group.Smarts
                        }
                                   );
                    }
                }
            }
            return(Ok(retVal));
        }
Exemple #2
0
        public async Task <ActionResult <IEnumerable <FunctionalGroupAPI> > > Smiles(string id)
        {
            var fgList = await _context.AppFunctionalgroup.ToListAsync();

            List <FunctionalGroup> fgFound = new List <FunctionalGroup>();

            ChemInfo.Molecule molecule = new ChemInfo.Molecule(id.Trim());
            if (molecule == null)
            {
                return(NotFound());
            }
            if (molecule.Atoms.Length != 0)
            {
                foreach (var fg in fgList)
                {
                    string smarts = fg.Smarts;
                    if (!string.IsNullOrEmpty(fg.Smarts))
                    {
                        if (molecule.FindFunctionalGroup(fg))
                        {
                            fgFound.Add(fg);
                        }
                    }
                }
                if (molecule.Aromatic)
                {
                    fgFound.Add(_context.AppFunctionalgroup
                                .FirstOrDefault(m => m.Id == 35));
                }
                if (molecule.Heterocyclic)
                {
                    fgFound.Add(_context.AppFunctionalgroup
                                .FirstOrDefault(m => m.Id == 118));
                }
                if (molecule.HeterocyclicAromatic)
                {
                    fgFound.Add(_context.AppFunctionalgroup
                                .FirstOrDefault(m => m.Id == 224));
                }
            }
            List <FunctionalGroupAPI> retVal = new List <FunctionalGroupAPI>();

            foreach (var fg in fgFound)
            {
                retVal.Add(new FunctionalGroupAPI
                {
                    Id     = fg.Id,
                    Name   = fg.Name,
                    Smarts = fg.Smarts,
                    URL    = fg.URL,
                    Image  = fg.Image,
                });
            }
            return(retVal);
        }
        private void testChemicalListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <DSSToxChemicals> chemicals = new List <DSSToxChemicals>();
            // Open the document for editing.
            string fileName = documentPath + "\\DSSTox_ToxCastRelease_20151019.xlsx";

            using (DocumentFormat.OpenXml.Packaging.SpreadsheetDocument document = DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(fileName, false))
            {
                DocumentFormat.OpenXml.Packaging.WorkbookPart  wbPart    = document.WorkbookPart;
                DocumentFormat.OpenXml.Packaging.WorksheetPart wsPart    = wbPart.WorksheetParts.First();
                DocumentFormat.OpenXml.Spreadsheet.SheetData   sheetData = wsPart.Worksheet.Elements <DocumentFormat.OpenXml.Spreadsheet.SheetData>().First();

                string text  = string.Empty;
                bool   first = true;
                foreach (DocumentFormat.OpenXml.Spreadsheet.Row r in sheetData.Elements <DocumentFormat.OpenXml.Spreadsheet.Row>())
                {
                    if (!first)
                    {
                        foreach (DocumentFormat.OpenXml.Spreadsheet.Cell c in r.Elements <DocumentFormat.OpenXml.Spreadsheet.Cell>())
                        {
                            text = text + this.GetExcelCellValue(c, wbPart) + '\t';
                        }
                        chemicals.Add(new DSSToxChemicals(text));
                    }
                    first = false;
                    text  = string.Empty;
                }
                document.Close();
            }
            foreach (DSSToxChemicals chem in chemicals)
            {
                if (!string.IsNullOrEmpty(chem.Structure_SMILES))
                {
                    ChemInfo.Molecule mol = new ChemInfo.Molecule(chem.Structure_SMILES);
                    if (mol != null)
                    {
                        foreach (ChemInfo.FunctionalGroup f in this.fGroups)
                        {
                            if ((f.Name != "ESTER-SULFIDE") || (f.Name != "KETENIMINE"))
                            {
                                mol.FindFunctionalGroup(f);
                            }
                        }
                    }
                    chem.AddFunctionalGroups(mol.FunctionalGroups);
                }
            }
            fileName = documentPath + "\\chemicals.json";
            System.IO.File.WriteAllText(fileName, Newtonsoft.Json.JsonConvert.SerializeObject(chemicals, Newtonsoft.Json.Formatting.Indented));
        }
        public async Task <ActionResult <AppFunctionalgroup> > GetMolecule(string smiles)
        {
            var fG = await _context.AppFunctionalgroup.ToListAsync();

            ChemInfo.Molecule molecule = new ChemInfo.Molecule(smiles);
            var retVal = new List <AppFunctionalgroupDTO>();

            foreach (var group in fG)
            {
                string smarts = group.Smarts;
                if (!string.IsNullOrEmpty(group.Smarts))
                {
                    molecule.FindFunctionalGroup(group);
                }
            }
            return(Ok(molecule));
        }
        // GET: FunctionalGroups
        public async Task <IActionResult> Index(string nameSearchString, string smilesSearchString)
        {
            var retVal = new List <AppFunctionalgroup>();
            var groups = from s in _context.AppFunctionalgroup
                         select s;

            if (!String.IsNullOrEmpty(nameSearchString))
            {
                groups = groups.Where(s => s.Name.Contains(nameSearchString, StringComparison.OrdinalIgnoreCase));
            }

            if (!String.IsNullOrEmpty(smilesSearchString))
            {
                await Task.Run(() =>
                {
                    ChemInfo.Molecule molecule = new ChemInfo.Molecule(smilesSearchString);
                    foreach (var fg in groups)
                    {
                        string smarts = fg.Smarts;
                        if (!string.IsNullOrEmpty(fg.Smarts))
                        {
                            if (molecule.FindFunctionalGroup(fg.Smarts))
                            {
                                retVal.Add(fg);
                            }
                        }
                    }
                });
            }
            else
            {
                retVal.AddRange(groups.ToList());
            }

            return(View(retVal.ToAsyncEnumerable()));
        }
        public async Task <IActionResult> Index(int?Id, int?funcGroupId, int?namedReactionId, string nameSearchString, string smilesSearchString)
        {
            if (!string.IsNullOrEmpty(smilesSearchString))
            {
                ViewData["SearchString"] = smilesSearchString.Trim();
            }
            var viewModel = new SustainableChemistryWeb.ViewModels.FunctionalGroupIndexData();

            viewModel.FunctionalGroups = await _context.AppFunctionalgroup
                                         .Include(i => i.AppNamedreaction)
                                         .ThenInclude(i => i.AppReference)
                                         .AsNoTracking()
                                         .OrderBy(i => i.Name)
                                         .ToListAsync();

            List <FunctionalGroup> fgFound = new List <FunctionalGroup>();

            ChemInfo.Molecule molecule  = null;
            string            IUPacName = string.Empty;
            string            CASNo     = string.Empty;
            string            DTXSID    = string.Empty;

            if (!String.IsNullOrEmpty(smilesSearchString))
            {
                if (TestCASNo(ref CASNo, ref smilesSearchString, ref IUPacName, ref DTXSID))
                {
                    molecule = new ChemInfo.Molecule(smilesSearchString.Trim());
                    if (molecule.Atoms.Length != 0)
                    {
                        foreach (var fg in viewModel.FunctionalGroups)
                        {
                            string smarts = fg.Smarts;
                            if (!string.IsNullOrEmpty(fg.Smarts))
                            {
                                if (molecule.FindFunctionalGroup(fg))
                                {
                                    fgFound.Add(fg);
                                }
                            }
                        }
                        if (molecule.Aromatic)
                        {
                            fgFound.Add(_context.AppFunctionalgroup
                                        .FirstOrDefault(m => m.Id == 35));
                        }
                        if (molecule.Heterocyclic)
                        {
                            fgFound.Add(_context.AppFunctionalgroup
                                        .FirstOrDefault(m => m.Id == 118));
                        }
                        if (molecule.HeterocyclicAromatic)
                        {
                            fgFound.Add(_context.AppFunctionalgroup
                                        .FirstOrDefault(m => m.Id == 224));
                        }
                    }
                }
                else
                {
                    return(RedirectToAction("Index", "Home", new { message = "Search String \"" + smilesSearchString + "\" was not found." }));
                }
            }
            else if (!String.IsNullOrEmpty(nameSearchString))
            {
                ViewData["NameSearchString"] = nameSearchString.Trim();
                fgFound.AddRange(viewModel.FunctionalGroups.Where(s => s.Name.Contains(nameSearchString, StringComparison.OrdinalIgnoreCase)));
                ViewData["FunctionalGroupName"] = nameSearchString.Trim();
            }

            else if (funcGroupId != null)
            {
                ViewData["FunctionalGroupID"] = funcGroupId.Value;
                FunctionalGroup group = viewModel.FunctionalGroups.Where(
                    i => i.Id == funcGroupId.Value).Single();
                fgFound.Add(group);
            }

            if (funcGroupId != null)
            {
                ViewData["FunctionalGroupID"] = funcGroupId.Value;
                FunctionalGroup group = viewModel.FunctionalGroups.Where(
                    i => i.Id == funcGroupId.Value).Single();
                viewModel.NamedReactions        = group.AppNamedreaction;
                ViewData["FunctionalGroupName"] = group.Name;
            }

            if (namedReactionId != null)
            {
                ViewData["NamedReactionID"] = namedReactionId.Value;
                NamedReaction rxn = viewModel.NamedReactions.Where(
                    i => i.Id == namedReactionId.Value).Single();
                var referenceViewModels = new List <SustainableChemistryWeb.ViewModels.ReferenceViewModel>();
                ViewData["NamedReactionName"] = rxn.Name;
                foreach (var referecnce in rxn.AppReference)
                {
                    referenceViewModels.Add(new SustainableChemistryWeb.ViewModels.ReferenceViewModel
                    {
                        Id = referecnce.Id,
                        FunctionalGroupId = referecnce.FunctionalGroupId,
                        FunctionalGroup   = viewModel.FunctionalGroups.Where(
                            i => i.Id == referecnce.FunctionalGroupId).Single(),
                        ReactionId = referecnce.ReactionId,
                        Reaction   = referecnce.Reaction,
                        Risdata    = referecnce.Risdata
                    });
                }
                viewModel.References = referenceViewModels;
            }
            if (!string.IsNullOrEmpty(nameSearchString) || !string.IsNullOrEmpty(smilesSearchString) || funcGroupId != null)
            {
                viewModel.FunctionalGroups = fgFound.OrderBy(i => i.Name);
            }
            ViewData["SmilesString"] = smilesSearchString;
            ViewData["CASNO"]        = CASNo;
            ViewData["IUPACName"]    = IUPacName;
            ViewData["DTXSID"]       = DTXSID;
            return(View(viewModel));
        }