Module Program Dim pug_ws As PUG_SOAP.PUG = New PUG_SOAP.PUG Dim FILES As String() = { _ "CID_123.asnt", _ "CID_123.sdf", _ "CID_123.xml" _ } Dim STRUCTURES As String() = { _ "C", _ "CCCCCC", _ "c1ccc1", _ "c1cccccccccc1", _ "c1cccc2", _ "COBRA", _ "InChI=1/C9H8O4/c1-6(10)13-8-5-3-2-4-7(8)9(11)12/h2-5H,1H3,(H,11,12)", _ "InChI=1/2C9H8O4.Ca/c2*1-6(10)13-8-5-3-2-4-7(8)9(11)12;/h2*2-5H,1H3,(H,11,12);/q;;+2/p-2/f2C9H7O4.Ca/q2*-1;m" _ } Dim MFS As String() = { _ "C2H6", _ "CCCCCC", _ "c1ccc1", _ "c1c1", _ "COBRA" _ } Sub Main() Console.Out.WriteLine("Testing IdentitySearch...") For Each str As String In STRUCTURES IdentitySearch(str) Next str Console.Out.WriteLine("Done.") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Console.Out.WriteLine("Testing SubstructureSearch...") For Each file As String In FILES SubstructureSearch(file) Next file Console.Out.WriteLine("Done.") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Console.Out.WriteLine("Testing SuperstructureSearch...") For Each file As String In FILES SuperstructureSearch(file) Next file Console.Out.WriteLine("Done.") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Console.Out.WriteLine("Testing SimilaritySearch...") For Each file As String In FILES SimilaritySearch(file) Next file Console.Out.WriteLine("Done.") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Console.Out.WriteLine("Testing MFSearch...") For Each mf As String In MFS MSSearch(mf) Next mf Console.Out.WriteLine("Done.") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Console.Out.WriteLine("Testing Standardize...") For Each str As String In STRUCTURES Standardize(str) Next str Console.Out.WriteLine("Done.") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Console.Out.WriteLine("Testing Download...") Dim cids As Integer() = {1, 2, 3, 4, 5} Download(cids) Console.Out.WriteLine("Done.") End Sub Sub IdentitySearch(ByVal str As String) Dim strkey As String = pug_ws.InputStructure(str, decodeFormatByValue(str)) If pug_ws.GetOperationStatus(strkey) = PUG_SOAP.StatusType.eStatus_Success Then Console.Out.WriteLine("InputStructure({0}): {1}", str, strkey) Else Console.Error.WriteLine("InputStructure({0}) failed", str) Return End If Dim idOptions As PUG_SOAP.IdentitySearchOptions = New PUG_SOAP.IdentitySearchOptions idOptions.eIdentity = PUG_SOAP.IdentityType.eIdentity_SameConnectivity Dim listkey As String = pug_ws.IdentitySearch(strkey, idOptions, Nothing) Console.Out.WriteLine("IdentitySearch({0}, eIdentity_SameConnectivity): {1}", strkey, listkey) processSearchResult(listkey) End Sub Sub SubstructureSearch(ByVal file As String) Dim strkey As String = ImportStructureFromFile(file) If strkey <> String.Empty Then Dim ssOptions As PUG_SOAP.StructureSearchOptions = New PUG_SOAP.StructureSearchOptions() ssOptions.eStereo = PUG_SOAP.StereoType.eStereo_Ignore Dim listkey As String = pug_ws.SubstructureSearch(strkey, ssOptions, Nothing) Console.Out.WriteLine("SubstructureSearch({0}, eStereo_Ignore): {1}", strkey, listkey) processSearchResult(listkey) End If End Sub Sub SuperstructureSearch(ByVal file As String) Dim strkey As String = ImportStructureFromFile(file) If strkey <> String.Empty Then Dim ssOptions As PUG_SOAP.StructureSearchOptions = New PUG_SOAP.StructureSearchOptions() ssOptions.eStereo = PUG_SOAP.StereoType.eStereo_Ignore Dim listkey As String = pug_ws.SuperstructureSearch(strkey, ssOptions, Nothing) Console.Out.WriteLine("SuperstructureSearch({0}, eStereo_Ignore): {1}", strkey, listkey) processSearchResult(listkey) End If End Sub Sub SimilaritySearch(ByVal file As String) Dim strkey As String = ImportStructureFromFile(file) If strkey <> String.Empty Then Dim simOptions As PUG_SOAP.SimilaritySearchOptions = New PUG_SOAP.SimilaritySearchOptions() simOptions.threshold = 99 Dim listkey As String = pug_ws.SimilaritySearch2D(strkey, simOptions, Nothing) Console.Out.WriteLine("SimilaritySearch({0}, 99%): {1}", strkey, listkey) processSearchResult(listkey) End If End Sub Sub MSSearch(ByVal mf As String) Dim mf_options As PUG_SOAP.MFSearchOptions = New PUG_SOAP.MFSearchOptions() mf_options.AllowOtherElements = False Dim listkey As String = pug_ws.MFSearch(mf, mf_options, Nothing) Console.Out.WriteLine("MFSearch({0}, AllowOtherElements): {1}", mf, listkey) processSearchResult(listkey) End Sub Sub Standardize(ByVal str As String) Dim strkey As String = pug_ws.InputStructure(str, decodeFormatByValue(str)) If pug_ws.GetOperationStatus(strkey) = PUG_SOAP.StatusType.eStatus_Success Then Console.Out.WriteLine("InputStructure({0}): {1}", str, strkey) Else Console.Error.WriteLine("InputStructure({0}) failed", str) Return End If pug_ws.Standardize(strkey) Console.Out.WriteLine("Standardize({0}): {1}", str, strkey) Dim ot As OutcomeType = waitForCompletion(strkey, TimeSpan.FromSeconds(60)) If ot = OutcomeType.OutcomeTimeout Then Console.Error.WriteLine("Could not get {0} standardized within reasonable timespan", str) ElseIf ot = OutcomeType.OutcomeError Then Console.Error.WriteLine("Standardization of {0} failed: {1}", str, pug_ws.GetStatusMessage(strkey)) Else Dim CID As Integer Dim bCIDExists As Boolean pug_ws.GetStandardizedCID(strkey, CID, bCIDExists) Console.Out.WriteLine("CID({0}): {1}", str, IIf(bCIDExists, CID.ToString(), "unavailable")) Dim inchi As String = pug_ws.GetStandardizedStructure(strkey, PUG_SOAP.FormatType.eFormat_InChI) Console.Out.WriteLine("InChI({0}): {1}", str, inchi) End If End Sub Sub Download(ByVal cids As Integer()) Dim listkey As String = pug_ws.InputList(cids, PUG_SOAP.PCIDType.eID_CID) Dim dwldkey As String = pug_ws.Download(listkey, PUG_SOAP.FormatType.eFormat_SDF, PUG_SOAP.CompressType.eCompress_GZip, True) Dim ot As OutcomeType = waitForCompletion(dwldkey, TimeSpan.FromSeconds(60)) If ot = OutcomeType.OutcomeTimeout Then Console.Error.WriteLine("Could not get results within reasonable timespan") ElseIf ot = OutcomeType.OutcomeError Then Console.Error.WriteLine("Download failed: {0}", pug_ws.GetStatusMessage(dwldkey)) Else Console.Out.WriteLine("Download URL: {0}", pug_ws.GetDownloadUrl(dwldkey)) End If End Sub Function decodeFormatByValue(ByVal value As String) As PUG_SOAP.FormatType If value.StartsWith("InChI=", StringComparison.InvariantCultureIgnoreCase) Then Return PUG_SOAP.FormatType.eFormat_InChI Else Return PUG_SOAP.FormatType.eFormat_SMILES End If End Function Sub processSearchResult(ByVal listkey As String) Dim ot As OutcomeType = waitForCompletion(listkey, TimeSpan.FromSeconds(60)) If ot = OutcomeType.OutcomeTimeout Then Console.Error.WriteLine("Could not get results within reasonable timespan") ElseIf ot = OutcomeType.OutcomeError Then Console.Error.WriteLine("Search failed: {0}", pug_ws.GetStatusMessage(listkey)) Else Dim cids As Integer() = pug_ws.GetIDList(listkey) Dim s_cids As String() = Array.ConvertAll(cids, New Converter(Of Integer, String)(AddressOf int2str)) Console.Out.WriteLine("GetIDList({0}): {1}", listkey, String.Join(", ", s_cids)) End If End Sub Function int2str(ByVal i As Integer) As String Return i.ToString() End Function Function decodeFormatByFileExt(ByVal file As String) As PUG_SOAP.FormatType If (file.EndsWith(".asnt", StringComparison.InvariantCultureIgnoreCase)) Then Return PUG_SOAP.FormatType.eFormat_ASNT ElseIf (file.EndsWith(".asn", StringComparison.InvariantCultureIgnoreCase) Or file.EndsWith(".asnb", StringComparison.InvariantCultureIgnoreCase)) Then Return PUG_SOAP.FormatType.eFormat_ASNB ElseIf (file.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase)) Then Return PUG_SOAP.FormatType.eFormat_XML ElseIf (file.EndsWith(".sdf", StringComparison.InvariantCultureIgnoreCase)) Then Return PUG_SOAP.FormatType.eFormat_SDF Else Throw New FormatException("Cannot detect file format: " + file) End If End Function Function ImportStructureFromFile(ByVal file As String) As String Dim strkey As String = pug_ws.InputStructureBase64(IO.File.ReadAllBytes(file), decodeFormatByFileExt(file)) If pug_ws.GetOperationStatus(strkey) = PUG_SOAP.StatusType.eStatus_Success Then Console.Out.WriteLine("InputStructureBase64({0}): {1}", file, strkey) Return strkey Else Console.Error.WriteLine("InputStructureBase64({0}) failed: {1}", file, pug_ws.GetStatusMessage(strkey)) Return String.Empty End If End Function Enum OutcomeType As Integer OutcomeSuccess OutcomeTimeout OutcomeError End Enum Function waitForCompletion(ByVal rid As String, ByVal timeout As TimeSpan) As OutcomeType Dim start As DateTime = DateTime.Now Dim status As PUG_SOAP.StatusType = pug_ws.GetOperationStatus(rid) While status = PUG_SOAP.StatusType.eStatus_Queued Or status = PUG_SOAP.StatusType.eStatus_Running If timeout <> Nothing And DateTime.Now - start >= timeout Then Return OutcomeType.OutcomeTimeout End If System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)) status = pug_ws.GetOperationStatus(rid) End While If status <> PUG_SOAP.StatusType.eStatus_Success _ And status <> PUG_SOAP.StatusType.eStatus_HitLimit _ And status <> PUG_SOAP.StatusType.eStatus_TimeLimit Then Return OutcomeType.OutcomeError End If Return OutcomeType.OutcomeSuccess End Function End Module