Exemplo n.º 1
0
        static void Demo()
        {
            var toluene           = RWMol.MolFromSmiles("Cc1ccccc1");
            var mol1              = RWMol.MolFromMolFile(Path.Combine("Data", "input.mol"));
            var stringWithMolData = new StreamReader(Path.Combine("Data", "input.mol")).ReadToEnd();
            var mol2              = RWMol.MolFromMolBlock(stringWithMolData);

            using (var suppl = new SDMolSupplier(Path.Combine("Data", "5ht3ligs.sdf")))
            {
                while (!suppl.atEnd())
                {
                    var mol = suppl.next();
                    if (mol == null)
                    {
                        continue;
                    }
                    Console.WriteLine(mol.getAtoms().Count);

                    using (var maccs = RDKFuncs.MACCSFingerprintMol(mol))
                    {
                        Console.WriteLine(ToString(maccs));
                    }
                }
            }

            using (var gzsuppl = new ForwardSDMolSupplier(new gzstream("Data/actives_5ht3.sdf.gz")))
            {
                while (!gzsuppl.atEnd())
                {
                    var mol = gzsuppl.next();
                    if (mol == null)
                    {
                        continue;
                    }
                    Console.WriteLine(mol.getAtoms().Count);
                    using (var maccs = RDKFuncs.MACCSFingerprintMol(mol))
                    {
                        Console.WriteLine(ToString(maccs));
                    }
                }
            }
        }
Exemplo n.º 2
0
        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 = new SDMolSupplier(sdfName))
            {
                int numSuppliedMol = 0;

                while (!suppl.atEnd())
                {
                    using (var mol = suppl.next())
                    {
                        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";
                        }
                        Excel.Range cells = ((dynamic)newSheet).Cells;
                        try
                        {
                            using (var keys = mol.getPropList())
                            {
                                foreach (var key in keys)
                                {
                                    switch (key)
                                    {
                                    case "_Name":
                                        cells[row, ColumnTitle] = mol.getProp(key);
                                        break;

                                    default:
                                        if (key.StartsWith("_", StringComparison.Ordinal))
                                        {
                                            break;
                                        }
                                        if (!keyIndex.TryGetValue(key, out int index))
                                        {
                                            keyIndex[key]   = (index = endIndex++);
                                            cells[1, index] = key;
                                        }
                                        var prop = mol.getProp(key);
                                        cells[row, index] = prop;
                                        break;
                                    }
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            cells[row, ColumnTitle] = exception.Message;
                        }
                        cells[row, ColumnMolBlock] = mol.MolToMolBlock();
                        row++;
                    }

                    numSuppliedMol++;
                    if (EnableProgressBar)
                    {
                        ProgressDialog.Current.ReportWithCancellationCheck($"Reading: {numSuppliedMol}");
                    }
                }
            }
        }