public async Task <IActionResult> Create([Bind("Id,Name,Smarts,ImageFile,URL")] SustainableChemistryWeb.ViewModels.FunctionalGroupViewModel functionalGroupView) { if (ModelState.IsValid) { string name = System.IO.Path.GetFileName(functionalGroupView.ImageFile.FileName); FunctionalGroup appFunctionalGroup = new FunctionalGroup() { Name = functionalGroupView.Name, Smarts = functionalGroupView.Smarts, Image = "Images/FunctionalGroups/" + name, URL = functionalGroupView.URL }; if (functionalGroupView.ImageFile.Length > 0) { using (var stream = new System.IO.FileStream(_hostingEnvironment.WebRootPath + "/Images/FunctionalGroups/" + name, System.IO.FileMode.Create)) { await functionalGroupView.ImageFile.CopyToAsync(stream); stream.Close(); } } _context.Add(appFunctionalGroup); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(functionalGroupView)); }
public AtomOption(FunctionalGroup fg) { Element = fg; Foreground = new SolidColorBrush(Colors.Black); Content = new FunctionalGroupBlock { ParentGroup = fg }; }
public FunctionalGroupTextSource(FunctionalGroup parentGroup, bool isFlipped = false) { foreach (var term in parentGroup.ExpandIntoTerms(isFlipped)) { foreach (var part in term.Parts) { Runs.Add(new LabelTextSourceRun { IsAnchor = term.IsAnchor, IsEndParagraph = false, IsSubscript = part.Type == FunctionalGroupPartType.Subscript, IsSuperscript = part.Type == FunctionalGroupPartType.Superscript, Text = part.Text }); } } }
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)); }
public void CreateFunctionalGroupCharacters(Atom atom, Options options) { FunctionalGroup fg = atom.Element as FunctionalGroup; double baFromNorth = Vector.AngleBetween(BasicGeometry.ScreenNorth, atom.BalancingVector(true)); CompassPoints nesw = BasicGeometry.SnapTo2EW(baFromNorth); bool reverse = nesw == CompassPoints.West; #region Set Up Atom Colours string atomColour = "000000"; if (options.ColouredAtoms) { if (!string.IsNullOrEmpty(fg.Colour)) { atomColour = fg.Colour; // Strip out # as OoXml does not use it atomColour = atomColour.Replace("#", ""); } } #endregion Set Up Atom Colours List <FunctionalGroupTerm> terms = fg.ExpandIntoTerms(reverse); #region Step 1 - Generate the characters and measure Bounding Boxes var cursorPosition = atom.Position; List <AtomLabelCharacter> fgCharacters = new List <AtomLabelCharacter>(); TtfCharacter hydrogenCharacter = _TtfCharacterSet['H']; Rect fgBoundingBox = Rect.Empty; Rect anchorBoundingBox = Rect.Empty; foreach (var term in terms) { foreach (var part in term.Parts) { foreach (char c in part.Text) { Rect bb = AddCharacter(c, part.Type); fgBoundingBox.Union(bb); if (term.IsAnchor) { anchorBoundingBox.Union(bb); } } } } #endregion Step 1 - Generate the characters and measure Bounding Boxes #region Step 2 - Move all characters such that the anchor term is centered on the atom position double offsetX; double offsetY; if (reverse) { offsetX = fgBoundingBox.Width - anchorBoundingBox.Width / 2; offsetY = anchorBoundingBox.Height / 2; } else { offsetX = anchorBoundingBox.Width / 2; offsetY = anchorBoundingBox.Height / 2; } offsetY = offsetY + anchorBoundingBox.Top - atom.Position.Y; foreach (var alc in fgCharacters) { alc.Position = new Point(alc.Position.X - offsetX, alc.Position.Y - offsetY); } #endregion Step 2 - Move all characters such that the anchor term is centered on the atom position #region Step 3 - Transfer characters into main list foreach (var alc in fgCharacters) { _AtomLabelCharacters.Add(alc); } #endregion Step 3 - Transfer characters into main list #region Step 4 - Convex Hull _convexhHulls.Add(atom.Path, ConvexHull(atom.Path)); #endregion Step 4 - Convex Hull // Local Function Rect AddCharacter(char c, FunctionalGroupPartType type) { TtfCharacter ttf = _TtfCharacterSet[c]; var thisCharacterPosition = GetCharacterPosition(cursorPosition, ttf); var alc = new AtomLabelCharacter(thisCharacterPosition, ttf, atomColour, c, atom.Path, atom.Parent.Path); alc.IsSubScript = type == FunctionalGroupPartType.Subscript; alc.IsSuperScript = type == FunctionalGroupPartType.Superscript; alc.IsSmaller = alc.IsSubScript || alc.IsSuperScript; Rect thisBoundingBox; if (alc.IsSmaller) { // Start by assuming it's SubScript thisCharacterPosition.Offset(0, OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Height * OoXmlHelper.SUBSCRIPT_DROP_FACTOR, _meanBondLength)); if (alc.IsSuperScript) { // Shift up by height of H to make it SuperScript thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Height, _meanBondLength)); } // Reset the character's position alc.Position = thisCharacterPosition; thisBoundingBox = new Rect(alc.Position, new Size(OoXmlHelper.ScaleCsTtfToCml(alc.Character.Width, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, OoXmlHelper.ScaleCsTtfToCml(alc.Character.Height, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR)); cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(alc.Character.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0); } else { thisBoundingBox = new Rect(alc.Position, new Size(OoXmlHelper.ScaleCsTtfToCml(alc.Character.Width, _meanBondLength), OoXmlHelper.ScaleCsTtfToCml(alc.Character.Height, _meanBondLength))); cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(alc.Character.IncrementX, _meanBondLength), 0); } fgCharacters.Add(alc); return(thisBoundingBox); } }
public FunctionalGroupVisual(FunctionalGroup fg) { ParentGroup = fg; }