public static ROMol Parse(string smarts) { if (smarts == null) { throw new ArgumentNullException(nameof(smarts)); } var pattern = SmartsCache.GetOrAdd(smarts, a_smarts => { ROMol query = Chem.MolFromSmarts(a_smarts); if (query == null) { return(nullSmarts); } query.setProp("source", "SMARTS"); return(query); }); if (object.ReferenceEquals(pattern, nullSmarts)) { return(null); } return(pattern); }
/// <summary> /// Read test data from file /// </summary> static IEnumerable <TestData> ReadTestData(string resourceName) { using (var r = new StreamReader(NCDK.ResourceLoader.GetAsStream($"NCDKExcel.test_data.QED.{resourceName}"))) { int lineNo = 1; string line; while ((line = r.ReadLine()) != null) { if (!(line.Length == 0 || line[0] == '#')) { var temp = line.Trim().Split(','); var smiles = temp[0]; var expected = double.Parse(temp[1]); var mol = Chem.MolFromSmiles(smiles); if (mol == null) { throw new AssertFailedException($"molecule construction failed on line {lineNo}"); } yield return(new TestData() { LineNo = lineNo, Smiles = smiles, Mol = mol, Expected = expected, }); } lineNo++; } yield break; } }
public async Task <IActionResult> Edit(int id, [Bind("ChemID,ChemComp,ChemAbbrev,ColorID,WarehouseLocationID")] Chem chem) { if (id != chem.ChemID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(chem); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ChemExists(chem.ChemID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(chem)); }
public void ExamplesTest() { // Paroxetine 0.935 Assert.AreEqual(0.934, QED.Calculate(Chem.MolFromSmiles("c1cc2OCOc2cc1OCC1CNCCC1c1ccc(F)cc1")), 0.01); // Leflunomide 0.929 Assert.AreEqual(0.911, QED.Calculate(Chem.MolFromSmiles("C1=NOC(C)=C1C(=O)Nc1ccc(cc1)C(F)(F)F")), 0.01); // Clomipramine 0.779 Assert.AreEqual(0.818, QED.Calculate(Chem.MolFromSmiles("CN(C)CCCN1c2ccccc2CCc2ccc(Cl)cc21")), 0.01); // Tegaserod 0.213 Assert.AreEqual(0.235, QED.Calculate(Chem.MolFromSmiles("CCCCCNC(=N)NN=CC1=CNc2ccc(CO)cc21")), 0.01); }
static void Main(string[] args) { IAtomContainer mol1 = Chem.MolFromSmiles("[C:1]([C:5]1[CH:10]=[CH:9][C:8]([OH:11])=[CH:7][CH:6]=1)([CH3:4])([CH3:3])[CH3:2]"); IMolecularFormula form1 = MolecularFormulaManipulator.GetMolecularFormula(mol1); Console.WriteLine(MolecularFormulaManipulator.GetString(form1)); IAtomContainer mol2 = Chem.MolFromFile("/Users/john/My Documents/1,3-diisopropenylbenzene.mol"); var form2 = MolecularFormulaManipulator.GetMolecularFormula(mol2); Console.WriteLine(MolecularFormulaManipulator.GetString(form2)); }
public async Task <IActionResult> Create([Bind("ChemID,ChemComp,ChemAbbrev,ColorID,WarehouseLocationID")] Chem chem) { if (ModelState.IsValid) { _context.Add(chem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(chem)); }
public void KekulizeTest() { { var mol = Chem.MolFromSmiles("c1ccccc1"); Chem.Kekulize(mol); Assert.IsTrue(mol.getAtomWithIdx(0).getIsAromatic()); } { var mol = Chem.MolFromSmiles("c1ccccc1"); Chem.Kekulize(mol, clearAromaticFlags: true); Assert.IsFalse(mol.getAtomWithIdx(0).getIsAromatic()); } }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Chemistry = await _context.Chemistry.FirstOrDefaultAsync(m => m.ChemID == id); if (Chemistry == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Chemistry = await _context.Chemistry.FindAsync(id); if (Chemistry != null) { _context.Chemistry.Remove(Chemistry); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public TempFile GenerateTemporary(string text, double width, double height) { var min = Math.Min(width, height); if (min < Config.MinimumEdgePixels) { double scale = Config.MinimumEdgePixels / min; width *= scale; height *= scale; } RWMol mol = null; mol = Chem.MolFromSmiles(text); if (mol == null) { mol = Chem.MolFromSmarts(text); } if (mol == null) { return(null); } var tempFile = new TempFile("." + Config.ImageType); var filename = tempFile.FileName; MolToFile(mol, filename, new Tuple <int, int>((int)width, (int)height)); if (filename.EndsWith(".svg")) { string svg; using (var r = new StreamReader(filename)) { svg = r.ReadToEnd(); } if (ImageBGIsTransparent()) { using (var r = new StreamWriter(filename)) { r.Write(re_rect_tag.Replace(svg, "")); } } } return(tempFile); }
public void PropertiesTest() { var m = Chem.MolFromSmiles("N=C(CCSCc1csc(N=C(N)N)n1)NS(N)(=O)=O"); var p = QED.CreateProperties(m); Assert.AreEqual(337.045, p[MW], 0.01); Assert.AreEqual(-0.55833, p[ALOGP], 0.01); Assert.AreEqual(6, p[HBA]); Assert.AreEqual(5, p[HBD]); Assert.AreEqual(173.33, p[PSA], 0.01); Assert.AreEqual(7, p[ROTB]); Assert.AreEqual(1, p[AROM]); Assert.AreEqual(3, p[ALERTS]); p = QED.CreateProperties(m.AddHs()); Assert.AreEqual(337.045, p[MW], 0.01); Assert.AreEqual(-0.55833, p[ALOGP], 0.01); Assert.AreEqual(6, p[HBA]); Assert.AreEqual(5, p[HBD]); Assert.AreEqual(173.33, p[PSA], 0.01); Assert.AreEqual(7, p[ROTB]); Assert.AreEqual(1, p[AROM]); Assert.AreEqual(3, p[ALERTS]); }
/// <summary> /// Read molecules and their info from SD file. /// </summary> /// <param name="sdfName">File name of the SD File.</param> private static void _LoadSDFToNewSheet(string sdfName, ref object newSheet, ref int row) { var keyIndex = new Dictionary <string, int>(); const int ColumnTitle = 1; const int ColumnMolBlock = 2; int endIndex = ColumnMolBlock + 1; // for Title:1 using (var suppl = Chem.SDMolSupplier(sdfName)) { int numSuppliedMol = 0; foreach (var mol in suppl) { if (mol == null) { continue; } if (newSheet == null) { newSheet = Globals.ThisAddIn.Application.Sheets.Add(); ((dynamic)newSheet).Cells[1, ColumnTitle] = "Title"; ((dynamic)newSheet).Cells[1, ColumnMolBlock] = "MOL Text"; } using (var sr = new StringWriter()) { Excel.Range cells = ((dynamic)newSheet).Cells; try { using (var w = new MDLV2000Writer(sr)) { w.WriteMolecule(mol); } cells[row, ColumnTitle] = mol.Title; foreach (var prop in mol.GetProperties()) { switch (prop.Key) { case string key: if (key.Equals(CDKPropertyName.Title, StringComparison.Ordinal)) { break; } if (!keyIndex.TryGetValue(key, out int index)) { keyIndex[key] = (index = endIndex++); cells[1, index] = key; } cells[row, index] = prop.Value.ToString(); break; default: break; } } } catch (CDKException exception) { cells[row, ColumnTitle] = exception.Message; } cells[row, ColumnMolBlock] = sr.ToString(); } row++; numSuppliedMol++; if (EnableProgressBar) { ProgressDialog.Current.ReportWithCancellationCheck($"Reading: {numSuppliedMol}"); } } } }
public static string RDKit_StripMol(string smiles) { var stripped = Chem.StaticSaltRemover.StripMol(RDKitMol.Parse(smiles)); return(Chem.MolToSmiles(stripped)); }
public static string RDKit_RunReactionSmiles(string rxnIdent, string reactantsIdent) { var key = new Tuple <string, string>(rxnIdent, reactantsIdent); var result = RunReactionCache.GetOrAdd(key, tuple => { var a_rxnIdent = tuple.Item1; var a_reactantsIdent = tuple.Item2; try { var rxn = RDKitChemicalReaction.Parse(a_rxnIdent); var mols = new List <ROMol>(); foreach (var reactant_smiles in a_reactantsIdent.Split('.')) { var mol = RDKitMol.Parse(reactant_smiles); if (mol == null) { return(null); } mol = mol.AddHs(); mols.Add(mol); } if (rxn.getNumReactantTemplates() != mols.Count) { return(null); } var reactants = new ROMol_Vect(mols); var products_candidate_list = rxn.runReactants(reactants); if (products_candidate_list.Count == 0) { return(null); } return(string.Join(".", products_candidate_list.First().Select(mol => Chem.MolToSmiles(Chem.RemoveHs(mol))))); } catch (Exception ex) { return(ex.Message); } }); return(result); }