/* (C) 2022 Cadence Design Systems, Inc. (Cadence) All rights reserved. TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is provided to current licensees or subscribers of Cadence products or SaaS offerings (each a "Customer"). Customer is hereby permitted to use, copy, and modify the Sample Code, subject to these terms. Cadence claims no rights to Customer's modifications. Modification of Sample Code is at Customer's sole and exclusive risk. Sample Code may require Customer to have a then current license or subscription to the applicable Cadence offering. THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be liable for any damages or liability in connection with the Sample Code or its use. */ /***************************************************************************** * Searching fingerprint database ****************************************************************************/ using System; using OpenEye.OEChem; using OpenEye.OEGraphSim; public class SearchFP { public static int Main(string[] args) { OEInterface itf = new OEInterface(); OEChem.OEConfigure(itf, interfaceData); OEFPDatabaseOptions defopts = new OEFPDatabaseOptions(10, OESimMeasure.Tanimoto); OEGraphSim.OEConfigureFPDatabaseOptions(itf, defopts); OEGraphSim.OEConfigureFingerPrint(itf, OEGraphSim.OEGetFPType(OEFPType.Tree)); if (!OEChem.OEParseCommandLine(itf, args, "SearchFP")) { OEChem.OEThrow.Fatal("Unable to interpret command line!"); } String qfname = itf.GetString("-query"); String mfname = itf.GetString("-molfname"); String ofname = itf.GetString("-out"); // initialize databases OEWallTimer timer = new OEWallTimer(); timer.Start(); oemolistream ifs = new oemolistream(); if (!ifs.open(qfname)) OEChem.OEThrow.Fatal("Cannot open input file!"); OEGraphMol query = new OEGraphMol(); if (!OEChem.OEReadMolecule(ifs, query)) OEChem.OEThrow.Fatal("Cannot read query molecule!"); OEMolDatabase moldb = new OEMolDatabase(); if (!moldb.Open(mfname)) OEChem.OEThrow.Fatal("Cannot open molecule database!"); oemolostream ofs = new oemolostream(); if (!ofs.open(ofname)) OEChem.OEThrow.Fatal("Cannot open output file!"); OEFPTypeBase fptype = OEGraphSim.OESetupFingerPrint(itf); OEChem.OEThrow.Info("Using fingerprint type " + fptype.GetFPTypeString()); OEFPDatabase fpdb = new OEFPDatabase(fptype); OEFingerPrint emptyfp = new OEFingerPrint(); emptyfp.SetFPTypeBase(fptype); uint nrmols = moldb.GetMaxMolIdx(); OEGraphMol mol = new OEGraphMol(); for (uint idx = 0; idx < nrmols; ++idx) { if (moldb.GetMolecule(mol, idx)) fpdb.AddFP(mol); else fpdb.AddFP(emptyfp); } uint nrfps = fpdb.NumFingerPrints(); OEChem.OEThrow.Info(timer.Elapsed().ToString("##0.00") + " sec to initialize databases"); OEFPDatabaseOptions opts = new OEFPDatabaseOptions(); OEGraphSim.OESetupFPDatabaseOptions(opts, itf); // search fingerprint database timer.Start(); OESimScoreIter siter = fpdb.GetSortedScores(query, opts); OEChem.OEThrow.Info(timer.Elapsed().ToString("##0.00") + " sec to search " + nrfps + " fingerprints"); timer.Start(); OEGraphMol hit = new OEGraphMol(); for (siter.ToFirst(); siter.IsValid(); siter.Increment()) { if (moldb.GetMolecule(hit, siter.Target().GetIdx())) OEChem.OEWriteMolecule(ofs, hit); } OEChem.OEThrow.Info(timer.Elapsed().ToString("##0.00") + " sec to write " + opts.GetLimit() + " hits"); return 0; } private static string interfaceData=@" !BRIEF [-query] [-molfname] [-out] !CATEGORY ""input/output options"" !PARAMETER -query !ALIAS -q !TYPE string !REQUIRED true !KEYLESS 1 !VISIBILITY simple !BRIEF Input query filename !END !PARAMETER -molfname !ALIAS -mol !TYPE string !REQUIRED true !KEYLESS 2 !VISIBILITY simple !BRIEF Input molecule filename !END !PARAMETER -out !ALIAS -o !TYPE string !REQUIRED true !KEYLESS 3 !VISIBILITY simple !BRIEF Output molecule filename !END !END "; }