Esempio n. 1
0
        public static ExplicitBitVect ToBitVectorOrNull(string fp)
        {
            var array = new List <int>();

            for (int i = 0; i < fp.Length; i++)
            {
                switch (fp[i])
                {
                case '0':
                    break;

                case '1':
                    array.Add(i);
                    break;

                default:
                    return(null);
                }
            }
            var o = new ExplicitBitVect((uint)fp.Length);

            foreach (var i in array)
            {
                o.setBit((uint)i);
            }
            return(o);
        }
Esempio n. 2
0
    static void Main()
    {
        // ----- Object creation -----

        Console.WriteLine("Creating some objects:");

        ROMol m1 = RWMol.MolFromSmiles("c1ccccc1");

        Console.WriteLine(" mol: " + m1 + " " + m1.getNumAtoms());
        ROMol m2 = RWMol.MolFromSmiles("c1ccccn1");

        Console.WriteLine(" smi: " + m1 + " " + m1.MolToSmiles());
        Console.WriteLine(" smi2: " + m2 + " " + m2.MolToSmiles());


        ExplicitBitVect fp1 = RDKFuncs.LayeredFingerprintMol(m1);
        ExplicitBitVect fp2 = RDKFuncs.LayeredFingerprintMol(m2);

        Console.WriteLine(" sim: " + RDKFuncs.TanimotoSimilarityEBV(fp1, fp2));

        //rxnTest();
        //smiTest();
        morganTest();

        Console.WriteLine("Goodbye");
    }
Esempio n. 3
0
 public static ExplicitBitVect FoldToTargetDensity(ExplicitBitVect fp, double density = 0.3, int minLength = 64)
 {
     while (fp.GetNumOnBits() / fp.Count() > density && fp.Count() / 2 > minLength)
     {
         fp = RDKFuncs.FoldFingerprint(fp, 2);
     }
     return(fp);
 }
Esempio n. 4
0
        /// <summary>
        /// Calculated similarity between two fingerprints,
        /// handles any folding that may need to be done to ensure that they are compatible
        /// </summary>
        /// <param name="fp1"></param>
        /// <param name="fp2"></param>
        /// <param name="metric">Default is <see cref="TanimotoSimilarity(ExplicitBitVect, ExplicitBitVect)"/></param>
        /// <returns>The calculated similarity</returns>
        public static double FingerprintSimilarity(ExplicitBitVect fp1, ExplicitBitVect fp2, Func <ExplicitBitVect, ExplicitBitVect, double> metric = null)
        {
            metric = metric ?? TanimotoSimilarity;
            var sz1 = fp1.GetNumBits();
            var sz2 = fp2.GetNumBits();

            if (sz1 < sz2)
            {
                fp2 = RDKFuncs.FoldFingerprint(fp2, (uint)(sz2 / sz1));
            }
            else if (sz2 < sz1)
            {
                fp1 = RDKFuncs.FoldFingerprint(fp1, (uint)(sz1 / sz2));
            }
            return(metric(fp1, fp2));
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            // ----- Object creation -----

            Console.WriteLine("Creating some objects:");

            ROMol m1 = RWMol.MolFromSmiles("c1ccccc1");

            Console.WriteLine(" mol: " + m1 + " " + m1.getNumAtoms());
            ROMol m2 = RWMol.MolFromSmiles("c1ccccn1");

            Console.WriteLine(" smi: " + m1 + " " + m1.MolToSmiles());
            Console.WriteLine(" smi2: " + m2 + " " + m2.MolToSmiles());


            ExplicitBitVect fp1 = RDKFuncs.LayeredFingerprintMol(m1);
            ExplicitBitVect fp2 = RDKFuncs.LayeredFingerprintMol(m2);

            Console.WriteLine(" sim: " + RDKFuncs.TanimotoSimilarityEBV(fp1, fp2));

            //rxnTest();
            //smiTest();
            //morganTest();

            ROMol m3     = RWMol.MolFromSmiles("c1ccccc1");
            uint  nAtoms = m3.getNumAtoms(true);

            Console.WriteLine("Bulk memory leak test");
            for (uint i = 0; i < 10000; ++i)
            {
                ROMol m4 = RWMol.MolFromSmiles("Clc1cccc(N2CCN(CCC3CCC(CC3)NC(=O)c3cccs3)CC2)c1Cl");
                if ((i % 1000) == 0)
                {
                    Console.WriteLine(" Done: " + i);
                }
                m4.Dispose();
                //GC.Collect();
            }

            Console.WriteLine("Goodbye");
        }
Esempio n. 6
0
        static void CreateSomeObjects()
        {
            // ----- Object creation -----
            Console.WriteLine("Creating some objects:");

            ROMol m1 = RWMol.MolFromSmiles("c1ccccc1");

            Console.WriteLine(" mol: " + m1 + " " + m1.getNumAtoms());
            ROMol m2 = RWMol.MolFromSmiles("c1ccccn1");

            Console.WriteLine(" smi: " + m1 + " " + m1.MolToSmiles());
            Console.WriteLine(" smi2: " + m2 + " " + m2.MolToSmiles());

            ExplicitBitVect fp1 = RDKFuncs.LayeredFingerprintMol(m1);
            ExplicitBitVect fp2 = RDKFuncs.LayeredFingerprintMol(m2);

            Console.WriteLine(" sim: " + RDKFuncs.TanimotoSimilarityEBV(fp1, fp2));

            const string SMILES_benzene = "c1ccccc1";
            ROMol        m3             = RWMol.MolFromSmiles(SMILES_benzene);
            uint         nAtoms         = m3.getNumAtoms(true);

            Console.WriteLine($"The number of atoms in {SMILES_benzene} is {nAtoms}.");
        }
 public static double AsymmetricSimilarity(ExplicitBitVect bv1, ExplicitBitVect bv2)
 => RDKFuncs.AsymmetricSimilarity(bv1, bv2);
 public static double CosineSimilarity(ExplicitBitVect bv1, ExplicitBitVect bv2)
 => RDKFuncs.CosineSimilarity(bv1, bv2);
 public static double TanimotoSimilarity(ExplicitBitVect bv1, ExplicitBitVect bv2)
 => RDKFuncs.TanimotoSimilarityEBV(bv1, bv2);
 public static double SokalSimilarity(ExplicitBitVect bv1, ExplicitBitVect bv2)
 => RDKFuncs.SokalSimilarity(bv1, bv2);
 public static double RusselSimilarity(ExplicitBitVect bv1, ExplicitBitVect bv2)
 => RDKFuncs.RusselSimilarity(bv1, bv2);
 public static double McConnaugheySimilarity(ExplicitBitVect bv1, ExplicitBitVect bv2)
 => RDKFuncs.McConnaugheySimilarity(bv1, bv2);
 public static double KulczynskiSimilarity(ExplicitBitVect bv1, ExplicitBitVect bv2)
 => RDKFuncs.KulczynskiSimilarity(bv1, bv2);
 public static double DiceSimilarity(ExplicitBitVect bv1, ExplicitBitVect bv2)
 => RDKFuncs.DiceSimilarity(bv1, bv2);
Esempio n. 15
0
 public static ExplicitBitVect LayeredFingerprint(ROMol mol,
                                                  LayerFlags layerFlags = (LayerFlags)(-1), int minPath     = 1, int maxPath = 7, int fpSize = 2048,
                                                  UInt_Vect atomCounts  = null, ExplicitBitVect setOnlyBits = null, bool branchedPaths = true, UInt_Vect fromAtoms = null)
 {
     return(RDKFuncs.LayeredFingerprintMol(mol, (uint)layerFlags, (uint)minPath, (uint)maxPath, (uint)fpSize, atomCounts, setOnlyBits, branchedPaths, fromAtoms));
 }
Esempio n. 16
0
 public static ExplicitBitVect PatternFingerprint(ROMol mol,
                                                  int fpSize = 2048, UInt_Vect atomCounts = null, ExplicitBitVect setOnlyBits = null)
 {
     return(RDKFuncs.PatternFingerprintMol(mol, (uint)fpSize, atomCounts, setOnlyBits));
 }
 public static double TverskySimilarity(ExplicitBitVect bv1, ExplicitBitVect bv2, double a, double b)
 => RDKFuncs.TverskySimilarity(bv1, bv2, a, b);
 public static double AllBitSimilarity(ExplicitBitVect bv1, ExplicitBitVect bv2)
 => RDKFuncs.AllBitSimilarity(bv1, bv2);
 public static double BraunBlanquetSimilarity(ExplicitBitVect bv1, ExplicitBitVect bv2)
 => RDKFuncs.BraunBlanquetSimilarity(bv1, bv2);