Collections:
openbabel.cheminfo.org/v1/convert - Web API
How to make a HTTP request to the Open Babel Web API at openbabel.cheminfo.org/v1/convert?
✍: FYIcenter.com
You can call the Open Babel Web API at https://openbabel.cheminfo.org/v1/convert with a HTTP POST request as shown below.
1. Use "curl" command to call the Web API to generate a 3D SDF file from a given SMILES string.
curl https://openbabel.cheminfo.org/v1/convert \ --form input='c1ccccc1' --form inputFormat='smiles -- SMILES format' \ --form outputFormat='sdf -- MDL MOL format' --form coordinates='3D' \ --form hydrogens='Delete' {"result":"\n OpenBabel01122301573D\n\n 6 6 0 0 0 0 0 0 0 0999 V2000\n 1.3831 -0.2216 0.0059 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.5071 -1.3070 -0.0080 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8711 -1.0906 -0.0144 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.3727 0.2109 -0.0040 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.4966 1.2959 0.0106 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.8813 1.0799 0.0144 C 0 0 0 0 0 0 0 0 0 0 0 0\n ... }
Note that the "--form" options encode POST data as "multipart/form-data". If you use the "--data" option to encode POST data as "application/x-www-form-urlencoded", you will get an error:
curl https://openbabel.cheminfo.org/v1/convert \ --data 'input=c1ccccc1&inputFormat=smiles+--+SMILES+format&outputFormat=sdf+--+MDL+MOL+format&coordinates=3D&hydrogens=Delete' {"statusCode":415,"code":"FST_ERR_CTP_INVALID_MEDIA_TYPE", "error":"Unsupported Media Type", "message":"Unsupported Media Type: application/x-www-form-urlencoded"}
2. Use PHP script to call the Web API to generate a 3D SDF file from a given SMILES string.
php > $post = [ php > 'input' => 'c1ccccc1', php > 'inputFormat' => 'smiles -- SMILES format', php > 'outputFormat' => 'sdf -- MDL MOL format', php > 'coordinates' => '3D', php > 'hydrogens' => 'Delete' php > ]; php > php > $log = fopen('curl.log', 'w'); php > $ch = curl_init('https://openbabel.cheminfo.org/v1/convert'); php > curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); php > curl_setopt($ch, CURLOPT_POSTFIELDS, $post); php > curl_setopt($ch, CURLOPT_VERBOSE, 1); php > curl_setopt($ch, CURLOPT_STDERR, $log); php > $response = curl_exec($ch); php > curl_close($ch); php > fclose($log); php > php > print($response); {"result":"\n OpenBabel01122301293D\n\n 6 6 0 0 0 0 0 0 0 0999 V2000\n 1.3831 -0.2215 0.0055 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.5068 -1.3068 -0.0081 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.8712 -1.0907 -0.0144 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.3730 0.2107 -0.0047 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.4968 1.2959 0.0101 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.8811 1.0798 0.0139 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0 0 0 0\n 1 6 2 0 0 0 0\n 2 3 2 0 0 0 0\n 3 4 1 0 0 0 0\n 4 5 2 0 0 0 0\n 5 6 1 0 0 0 0\nM END\n$$$$\n","log":"1 molecule converted\n"}
By default, CURLOPT_POSTFIELDS option will encode POST data as "multipart/form-data", not "application/x-www-form-urlencoded".
⇒ Open Babel Documentation and Resources
2023-01-24, 503🔥, 0💬
Popular Posts:
Molecule Summary: ID: FYI-1003612 Names: InChIKey: ZPWWVFANUGXHSA-UHFFFAOYS A-NSMILES: Cn1nccc1c2cc(...
Molecule Summary: ID: FYI-1002032 Names: InChIKey: BDAGIHXWWSANSR-UHFFFAOYS A-NSMILES: O=CO Received...
Molecule Summary: ID: FYI-1002224 Names: InChIKey: SXSBYAFKYBVTDA-UHFFFAOYS A-NSMILES: CN4CCC(COc2nc...
Molecule Summary: ID: FYI-1002832 Names: InChIKey: BJKUXYQNBWGORD-SDNWHVSQS A-NSMILES: CC14CCC=CC1=C...
Molecule Summary: ID: FYI-1000261 SMILES: C=C(C)[NH+](C)C(=O)C1=NC (=C)CC=C1N1N=CC=N1Received at FYI...