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, 1002🔥, 0💬
Popular Posts:
Molecule Summary: ID: FYI-1002230 Names: InChIKey: NTXSTPOPNLTDQG-UHFFFAOYS A-NSMILES: O=C(CNc1ccc(N...
Molecule Summary: ID: FYI-1001988 SMILES: [H+].C1=NC2=C(N1COCCO)N= C(NC2=O)NReceived at FYIcenter.co...
Molecule Summary: ID: FYI-1000384 SMILES: C/C(C)=C\\CC/C(C)=C/CC/C (C)=C/CCC(C)=OReceived at FYIcent...
Molecule Summary: ID: FYI-1000980 SMILES: S=C1S/C(=C/c2ccccc2C)C(= O)N1CCN(CC)CCReceived at FYIcente...
Molecule Summary: ID: FYI-1002257 Names: InChIKey: AVYKQOAMZCAHRG-UHFFFAOYS A-NSMILES: CCO[Si](CCC(F...