exportResult using php

User e34a92cce5

20-05-2010 22:40:24

Hi,


I am trying to use the following code to generate an output file from a search (the runCompleteSearch function works fine!) and it throws me a soap fault error [SOAP Fault: (faultcode: soapenv:Server, faultstring: Format not specified.)]  when using the exportResult function


Here is the php code:


<?php
$search_param = array(  'connectionHandlerId' => strip_tags($soap_conn->getConnection($conn_param)->return),
                        'tableName' => $_POST['search_library'],
                        'queryMolecule' => stripslashes($_POST['structure_query']),
                        'queryOptions' => $search_type_string,
                        'beginIndex' => '0',
                        'count' => $_POST['max_count'],
                        'outputFormat' => 'smiles',
                        'dataFieldNames' => $data_field_names);


$search_results = $soap->runCompleteSearch($search_param);
    //var_dump($search_results->return);
    $xml_results = simplexml_load_string($search_results->return);

    print("Number of results: $xml_results->ResultCount</br>");
    $num_hits = intval($xml_results->ResultCount);
    $search_id = strval($xml_results->SearchId);

$export_param = array(  'searchId' => strip_tags($search_id),
                            'endOfLineChar' => '\n',
                            'outputFormat' => 'smiles',
                            'dataFieldNames' => $data_field_names);

    $export_results = $soap->exportResult($export_param);
    var_dump($export_results->return);

?>


User c1ce6b3d19

25-05-2010 06:49:40

Renju,


Sorry for the late reply.


Try using the all uppercase letters instead.  Use 'SMILES' instead of 'smiles'.


 



    $export_param = array(  'searchId' => strip_tags($search_id),
                            'endOfLineChar' => '\n',
                            'outputFormat' => 'SMILES',
                            'dataFieldNames' => $data_field_names);

Does this help? 


Jon


User e34a92cce5

25-05-2010 15:50:34

Thanks, Jon. That helps. It might be helpful to indicate that in the example provided in the documentation at https://www.chemaxon.com/webservices/soap/JChemSearchWS.html#exportresult


Now, when I specify 'SDFILE' in the outputFormat tag and cd_id in the dataFieldNames, I get the following that certainly does not look like an SD file. Could you look into what's going wrong here?


Code:



$export_param = array(  'searchId' => $_SESSION['JC_SEARCH_ID'],
      'outputFormat' => 'SDFILE',
      'endOfLineChar' => '\n',
      'dataFieldNames' => $_SESSION['DATA_FIELDS']);
 

$export_results = $soap->exportResult($export_param);
 echo $export_results->return;

Result (attached):


 

User c1ce6b3d19

27-05-2010 09:52:23

Renju,


Thanks for the info. 


We'll update the documentation in the next release. 


 


We are currently looking into your problem with the sdf output. 


 


Jon

User c1ce6b3d19

01-06-2010 22:08:24

Renju,


While I am trying to reproduce your problem, I had a thought.  


Perhaps the end of line character is missing or swallowed before it reaches the server and it is using the "cd_id" as the end of line character.


Please post what is received by the web service by starting the soap monitor.  Instructions can be found here:


https://www.chemaxon.com/webservices/FAQ.html#soapmonitor


 


Thanks,


Jon

User c1ce6b3d19

03-06-2010 11:52:31

Renju,


I think there are two fixes needed here.


The input parameter name is 'endLineChar' and not 'endOfLineChar'.  


The special newline character (\n) must be enclosed inside of double quotes (") when inside of php. 



$export_param = array(  'searchId' => $_SESSION['JC_SEARCH_ID'],
      'outputFormat' => 'SDFILE',
      'endLineChar' => "\n",
      'dataFieldNames' => $_SESSION['DATA_FIELDS']);


Let me know if this helps.


Thanks,


Jon

User e34a92cce5

03-06-2010 12:27:00

That certainly helps! Would you then retain the input parameter name as 'endLineChar' in the future releases or would you change it to 'endOfLineChar'. That way I know if I need to change it when upgrading to newer versions of web services. As I have commented earlier, I just think that the web services tool is just a fantastic idea. Only hope that PubChem web services would have worked just as well!


Thanks, Jon

User c1ce6b3d19

03-06-2010 12:49:00

Renju,


While I agree with you that endOfLineChar is a bit more readable, we don't plan on changing this parameter name due to the incompatibilities that could arise as you stated. 


If there are any changes to the interface, we will include it in the release notes. 


I'm glad you enjoy working with our web services. 


Jon

User e34a92cce5

28-06-2010 04:32:21

I am getting a Java heap space error (SOAP fault) when exporting a large set (5000 structures). How do I increase it on the web services server?

User c1ce6b3d19

28-06-2010 07:02:14

Renju,


You may be running out of java memory.  Try to change the maximum heap size to a larger number when starting the server.


 


 Memory Setup


 


To configure the default java heap size to your specific database, edit the Java Heap size (Default: 256MB) at<JChemWebServices_dir>/bin/startup{.bat or .sh} 
Windows: set JAVA_OPTS=-Xmx256M 
Unix/Linux: JAVA_OPTS='-Xmx256M'


 


This and other setup information can be found here: https://www.chemaxon.com/webservices/adminGuide.html#setup


Jon

User e34a92cce5

28-06-2010 12:33:27

Thanks for the reply, Jon. I had set the heap space to 1024M and so I don't think that 5000 compounds would have taken more than that. I looked a bit further into this and it looks like the runCompleteSearch was disregarding the maximum hits count that I was setting it to. Here is the code again:


$search_type_string = "sep=! t:".$_POST['search_type']."!simThreshold:".$sim_thresh."!maxHitCount:".$_POST['max_count']."0!maxTime:60000!returnNonHits:n!stereoSearchType:s!doubleBondStereo:M!charge:d!isotope:d!radical:d!valence:d!tautomer:n!vagueBond:1".$filter_query_string;
       


$search_param = array(  'connectionHandlerId' => strip_tags($soap_client_conn->getConnection($conn_param)->return),
                            'tableName' => $_POST['search_library'],
                            'queryMolecule' => stripslashes($_POST['structure_query']),
                            'queryOptions' => $search_type_string,
                            'beginIndex' => '0',
                            'count' => $_POST['max_count'],
                            'outputFormat' => 'smiles',
                            'dataFieldNames' => $data_field_names);





Even though I set the $_POST['max_count'] to say, 5000, when I compute the $xml_results->ResultCount, it gives me the full result count say, 50K or even more based on the search parameter and hence when trying to download the SDF from the search, it tries to download the whole result set. I think that's where it is running out of heap space and 1024M does not look big enough for it to run the task.

User c1ce6b3d19

28-06-2010 17:39:19

Renju,


The number returned in the <Result Count> tag of a call to RunCompleteSearch (this same number is also returned by the Web Service method "getResultCount") is the maximum number of results found in the search, not necessarily the number of results returned.  The returned results may be modified by the count parameter to the RunCompleteSearch method as well as the maxResultCount search option. 


Can you confirm how many actual structures are in the result of the call to RunCompleteSearch?


Jon

User e34a92cce5

28-06-2010 19:23:49

That's exactly where I am setting the maximum hits I want the web service to return  (in the count parameter of the runCompleteSearch method). I am also setting the maxHitCount search option to match the same number of hits that I would like the web service to return. In spite of that the getResultCount gets me way more than what I ask. So invariably the getResultCount always gives me more than what I specify in the count parameter and in the maxHitCount option (btw, I tried maxResultCount option and it said that that was an invalid option).


The problem is that when I try to download the data it gives me all the results that come from the getResultCount. So, it's as if my count parameter and in the maxHitCount optionare ignored.



User c1ce6b3d19

30-06-2010 09:32:16

Renju,


Sorry, you are right, I meant the "maxHitCount" instead of "maxResultCount" in my earlier message.


I just want to confirm a few things:


Are you using the same search ID as what was returned from the runCompleteSearch method which used the count parameter to limit the number of hits?


Can you confirm the number of actual rows returned from runCompleteSearch is in the neighborhood of 50k and not 5k?


Jon

User e34a92cce5

30-06-2010 19:20:57

Hi Jon,


Sorry abt this but this was a bug in the code; my maxHitCount had an extra '0' in the string and that's why it was disregarding the count parameter and giving 10 times more hits. So, that's solved.

User c1ce6b3d19

01-07-2010 09:21:57

Renju,


Thanks for the information.  Then the errors are appropriate.  


 


Jon

User e34a92cce5

12-07-2011 04:43:11

Hi Jon,


I have a question on how to manage open web service connections at runtime. As seen from my earlier posts,  I use PHP's Soap Client to talk to Web Services.  In the way I have designed the user interface, users run a structure search and get to see the results (that are captured in PHP arrays and variables) in the next step. Now, I do not close the connection after the search is run. That's because I offer an SDF export function (running on a different PHP script) that requires the original connectionID when the search was run. If I close the connectionID that was used for running the search, then the JChemWS exportResult function throws an error saying that it cannot find the searchID. So, when this happens my open connections keep going up until the database server refuses to accept any more connections. Is there a way around this?


Thanks

User c1ce6b3d19

13-07-2011 08:41:17

Renju,


For more complex handling of connections, please use the other methods of ConnectionWS.  


http://www.chemaxon.com/webservices/soap/ConnectionWS.html


Most likely you will need toset the Connection timeout value to an appropriate length.  


After using setConnectionTimeout the service will close the database connection if no searches have been made during the timeout period.  You may also use the ping method to keep the connection alive, which might be used continuously while a webpage is open.  The Close method will end the connection immediately, perhaps when a webpage is closed.  


Jon