/// <summary>
        /// Tries to parses text as SMILES, InChI, or MolBlock and returns RDKit ROMol.
        /// </summary>
        /// <param name="molIdent">Text expression of molecule like SMILES, InChI, or MolBlock.</param>
        /// <returns>RDKit ROMol.</returns>
        public static ROMol Parse(string molIdent)
        {
            if (molIdent == null)
            {
                throw new ArgumentNullException(nameof(molIdent));
            }

            var mol = MolecularCache.GetOrAdd(molIdent, a_ident =>
            {
                string notationType = null;
                ROMol a_mol;

                a_mol = RWMol.MolFromSmiles(molIdent);
                if (a_mol != null)
                {
                    notationType = "SMILES";
                    goto L_Found;
                }

                using (var rv = new ExtraInchiReturnValues())
                {
                    a_mol = RDKFuncs.InchiToMol(molIdent, rv);
                    if (a_mol != null)
                    {
                        notationType = "InChI";
                        goto L_Found;
                    }
                }

                a_mol = RWMol.MolFromMolBlock(molIdent);
                if (a_mol != null)
                {
                    RDKFuncs.assignStereochemistryFrom3D(a_mol);
                    notationType = "MolBlock";
                    goto L_Found;
                }

                L_Found:
                if (a_mol == null)
                {
                    a_mol = nullMol;
                }
                else
                {
                    if (notationType != null)
                    {
                        a_mol.setProp("source", notationType);
                    }
                }

                return(a_mol);
            });

            if (object.ReferenceEquals(mol, nullMol))
            {
                return(null);
            }

            return(mol);
        }
Ejemplo n.º 2
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));
                    }
                }
            }
        }
Ejemplo n.º 3
0
 // TODO: Add strictParsing
 public static RWMol MolFromMolBlock(string molBlock, bool sanitize = true, bool removeHs = true)
 {
     return(RWMol.MolFromMolBlock(molBlock, sanitize, removeHs));
 }