Building 3D Coordinates in Java with OpenBabel

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Building 3D Coordinates in Java with OpenBabel

Leonid Chepelev
Hello, 

(Sorry I posted this on Nabble OpenBabel forum already, but that seems to be simply an archive of this list.)

I would like to convert SMILES strings to their 3D forms in the SDF format. However, the difficulty is that I am now forced to use the Java API of OpenBabel to do this. 

One approach would be to use the class OBBuilder to build 3D structures.  However, this class seems to not be present in the Java API of openbabel, making it impossible to use. 

Another approach would be to generate the 3D structure with converter options, as is shown in the following code. 

import org.openbabel.*; 

public class Main { 
    public static void main(String[] args) { 
       System.loadLibrary("openbabel_java"); 
       OBConversion conv = new OBConversion(); 
       OBMol mol = new OBMol(); 
       conv.SetInFormat("smi"); 
       conv.ReadString(mol, "C(Cl)(=O)CCC(=O)Cl"); 
       conv.SetOutFormat("sdf"); 
       conv.SetOptions("gen3D", OBConversion.Option_type.OUTOPTIONS); 
       System.out.print(conv.WriteString(mol)); 
    } 


However, the problem is that the gen3D option does not seem to have any effect (with INOPTION and GENOPTION option types), and the result is quite unexpected with OUTOPTION, as follows. 


 OpenBabel05071010562D 

  0  0  0     0  0            999 V3000 
M  V30 BEGIN CTAB 
M  V30 COUNTS 8 7 0 0 0 
M  V30 BEGIN ATOM 
M  V30 1 C 0 0 0 0 
M  V30 2 Cl 0 0 0 0 
M  V30 3 O 0 0 0 0 
M  V30 4 C 0 0 0 0 
M  V30 5 C 0 0 0 0 
M  V30 6 C 0 0 0 0 
M  V30 7 O 0 0 0 0 
M  V30 8 Cl 0 0 0 0 
M  V30 END ATOM 
M  V30 BEGIN BOND 
M  V30 1 1 1 2 
M  V30 2 2 1 3 
M  V30 3 1 1 4 
M  V30 4 1 4 5 
M  V30 5 1 5 6 
M  V30 6 2 6 7 
M  V30 7 1 6 8 
M  V30 END BOND 
M  V30 END CTAB 
M  END 
$$$$ 

Would you happen to know what is going on? Am I doing something wrong? Or perhaps the 3D generation capability is not yet available through the OpenBabel Java API, in which case I would have to do SYSTEM calls? Perhaps I should use the CDK 3D structure generator as an alternative?

Thank you very much for any help.

------------------------------------------------------------------------------


_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Building 3D Coordinates in Java with OpenBabel

Noel O'Boyle
Administrator
On 7 May 2010 17:47, Leonid Chepelev <[hidden email]> wrote:
> Hello,
>
> (Sorry I posted this on Nabble OpenBabel forum already, but that seems to be
> simply an archive of this list.)

It should have appeared here - must be some problem.

> I would like to convert SMILES strings to their 3D forms in the SDF format.
> However, the difficulty is that I am now forced to use the Java API of
> OpenBabel to do this.
>
> One approach would be to use the class OBBuilder to build 3D structures.
>  However, this class seems to not be present in the Java API of openbabel,
> making it impossible to use.

Yes - it'll be there in the next release though.

In the meanwhile you need to use the Gen3D Operation with code
something similar to the following Python code:

gen3d = openbabel.OBOp.FindType("Gen3D")
gen3d.Do(myOBMol)

> Another approach would be to generate the 3D structure with converter
> options, as is shown in the following code.
>
> import org.openbabel.*;
>
> public class Main {
>     public static void main(String[] args) {
>        System.loadLibrary("openbabel_java");
>        OBConversion conv = new OBConversion();
>        OBMol mol = new OBMol();
>        conv.SetInFormat("smi");
>        conv.ReadString(mol, "C(Cl)(=O)CCC(=O)Cl");
>        conv.SetOutFormat("sdf");
>        conv.SetOptions("gen3D", OBConversion.Option_type.OUTOPTIONS);
>        System.out.print(conv.WriteString(mol));
>     }
> }
>
> However, the problem is that the gen3D option does not seem to have any
> effect (with INOPTION and GENOPTION option types), and the result is quite
> unexpected with OUTOPTION, as follows.
>
>
>  OpenBabel05071010562D
>
>   0  0  0     0  0            999 V3000
> M  V30 BEGIN CTAB
> M  V30 COUNTS 8 7 0 0 0
> M  V30 BEGIN ATOM
> M  V30 1 C 0 0 0 0
> M  V30 2 Cl 0 0 0 0
> M  V30 3 O 0 0 0 0
> M  V30 4 C 0 0 0 0
> M  V30 5 C 0 0 0 0
> M  V30 6 C 0 0 0 0
> M  V30 7 O 0 0 0 0
> M  V30 8 Cl 0 0 0 0
> M  V30 END ATOM
> M  V30 BEGIN BOND
> M  V30 1 1 1 2
> M  V30 2 2 1 3
> M  V30 3 1 1 4
> M  V30 4 1 4 5
> M  V30 5 1 5 6
> M  V30 6 2 6 7
> M  V30 7 1 6 8
> M  V30 END BOND
> M  V30 END CTAB
> M  END
> $$$$
>
> Would you happen to know what is going on? Am I doing something wrong? Or
> perhaps the 3D generation capability is not yet available through the
> OpenBabel Java API, in which case I would have to do SYSTEM calls? Perhaps I
> should use the CDK 3D structure generator as an alternative?
>
> Thank you very much for any help.
> ------------------------------------------------------------------------------
>
>
> _______________________________________________
> OpenBabel-discuss mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>
>

------------------------------------------------------------------------------

_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Building 3D Coordinates in Java with OpenBabel

Leonid Chepelev

Yes - it'll be there in the next release though.

In the meanwhile you need to use the Gen3D Operation with code
something similar to the following Python code:

gen3d = openbabel.OBOp.FindType("Gen3D")
gen3d.Do(myOBMol)


Hello Noel, and thank you very much for the advice! It sort of works now.

The following code in Java produces some sort of 3D coordinates, with errors that the parameter files for the MM geometry optimization cannot be found (I am guessing that's because I've copied the openbabel jar into my project's lib folder).

import org.openbabel.*;

public class Main {
    public static void main(String[] args) throws Exception {
        System.loadLibrary("openbabel_java");
        OBConversion conv = new OBConversion();
        OBMol mol = new OBMol();
        conv.SetInFormat("smi");
        conv.ReadString(mol, "C(Cl)(=O)CCC(=O)Cl");
        conv.SetOutFormat("sdf");
        OBOp gen3d = OBOp.FindType("Gen3D");
        gen3d.Do(mol);
        System.out.print(conv.WriteString(mol));
     }
}


The output produced is as follows.


 OpenBabel05091014533D

 12 11  0  0  0  0  0  0  0  0999 V2000
    1.0000    0.0000    0.0000 C   0  0  0  0  0
    0.1290    1.5086    0.0000 Cl  0  0  0  0  0
    0.3862   -1.0631    0.0000 O   0  0  0  0  0
    2.4820    0.0000    0.0000 C   0  0  0  0  0
    2.9894    1.4328    0.0000 C   0  0  0  0  0
    4.4714    1.4328    0.0000 C   0  0  0  0  0
    5.0852    0.3697    0.0000 O   0  0  0  0  0
    5.3424    2.9414    0.0000 Cl  0  0  0  0  0
    2.8524   -0.5242   -0.8561 H   0  0  0  0  0
    2.8337   -0.4977    0.8795 H   0  0  0  0  0
    2.6189    1.9570    0.8561 H   0  0  0  0  0
    2.6377    1.9305   -0.8795 H   0  0  0  0  0
  1  4  1  0  0  0
  1  3  2  0  0  0
  1  2  1  0  0  0
  4  5  1  0  0  0
  4  9  1  0  0  0
  4 10  1  0  0  0
  5  6  1  0  0  0
  5 11  1  0  0  0
  5 12  1  0  0  0
  6  8  1  0  0  0
  6  7  2  0  0  0
M  END
$$$$
==============================
*** Open Babel Error  in OpenBabel::OBForceFieldMMFF94::ParseParamFile
  Cannot open parameter file
==============================
*** Open Babel Error  in OpenBabel::OBForceFieldUFF::ParseParamFile
  Cannot open UFF.prm
==============================
*** Open Babel Error  in OpenBabel::OBForceFieldUFF::SetTypes
  Cannot open UFF.prm


Next, I will compare the 3D geometries generated by CDK and those generated by OpenBabel by overlaying the two resultant geometries with PM6 and B3LYP/6−311+G(d,p) optimized geometries (with G09) and calculating the RMSD for a few hundred compounds, for each approach to see which method is most accurate. I am guessing you guys would bet that both should be very similar, as the methodology used by OpenBabel and CDK is essentially the same?

In any case, thank you for the help, I don't need to do it through system calls and writing to disk now.

Regards,

Leonid Chepelev

------------------------------------------------------------------------------


_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Building 3D Coordinates in Java with OpenBabel

Noel O'Boyle
Administrator
On 9 May 2010 20:08, Leonid Chepelev <[hidden email]> wrote:

>>
>> Yes - it'll be there in the next release though.
>>
>> In the meanwhile you need to use the Gen3D Operation with code
>> something similar to the following Python code:
>>
>> gen3d = openbabel.OBOp.FindType("Gen3D")
>> gen3d.Do(myOBMol)
>>
>
> Hello Noel, and thank you very much for the advice! It sort of works now.
> The following code in Java produces some sort of 3D coordinates, with errors
> that the parameter files for the MM geometry optimization cannot be found (I
> am guessing that's because I've copied the openbabel jar into my project's
> lib folder).
> import org.openbabel.*;
> public class Main {
>     public static void main(String[] args) throws Exception {
>         System.loadLibrary("openbabel_java");
>         OBConversion conv = new OBConversion();
>         OBMol mol = new OBMol();
>         conv.SetInFormat("smi");
>         conv.ReadString(mol, "C(Cl)(=O)CCC(=O)Cl");
>         conv.SetOutFormat("sdf");
>         OBOp gen3d = OBOp.FindType("Gen3D");
>         gen3d.Do(mol);
>         System.out.print(conv.WriteString(mol));
>      }
> }
>
> The output produced is as follows.
>
>  OpenBabel05091014533D
>  12 11  0  0  0  0  0  0  0  0999 V2000
>     1.0000    0.0000    0.0000 C   0  0  0  0  0
>     0.1290    1.5086    0.0000 Cl  0  0  0  0  0
>     0.3862   -1.0631    0.0000 O   0  0  0  0  0
>     2.4820    0.0000    0.0000 C   0  0  0  0  0
>     2.9894    1.4328    0.0000 C   0  0  0  0  0
>     4.4714    1.4328    0.0000 C   0  0  0  0  0
>     5.0852    0.3697    0.0000 O   0  0  0  0  0
>     5.3424    2.9414    0.0000 Cl  0  0  0  0  0
>     2.8524   -0.5242   -0.8561 H   0  0  0  0  0
>     2.8337   -0.4977    0.8795 H   0  0  0  0  0
>     2.6189    1.9570    0.8561 H   0  0  0  0  0
>     2.6377    1.9305   -0.8795 H   0  0  0  0  0
>   1  4  1  0  0  0
>   1  3  2  0  0  0
>   1  2  1  0  0  0
>   4  5  1  0  0  0
>   4  9  1  0  0  0
>   4 10  1  0  0  0
>   5  6  1  0  0  0
>   5 11  1  0  0  0
>   5 12  1  0  0  0
>   6  8  1  0  0  0
>   6  7  2  0  0  0
> M  END
> $$$$
> ==============================
> *** Open Babel Error  in OpenBabel::OBForceFieldMMFF94::ParseParamFile
>   Cannot open parameter file
> ==============================
> *** Open Babel Error  in OpenBabel::OBForceFieldUFF::ParseParamFile
>   Cannot open UFF.prm
> ==============================
> *** Open Babel Error  in OpenBabel::OBForceFieldUFF::SetTypes
>   Cannot open UFF.prm

You need to set BABEL_DATADIR or else the ring templates and
forcefields are not going to work.

> Next, I will compare the 3D geometries generated by CDK and those generated
> by OpenBabel by overlaying the two resultant geometries with PM6 and
> B3LYP/6-311+G(d,p) optimized geometries (with G09) and calculating the RMSD
> for a few hundred compounds, for each approach to see which method is most
> accurate. I am guessing you guys would bet that both should be very similar,
> as the methodology used by OpenBabel and CDK is essentially the same?

Just to note, comp chem does a local optimisation. To do a global
optimisation you need to do a conformer search and locally optimise
each. With OB, what you're actually comparing is the accuracy of
MMFF94 geometries and those from B3LYP. This is already well studied.

> In any case, thank you for the help, I don't need to do it through system
> calls and writing to disk now.
> Regards,
> Leonid Chepelev

------------------------------------------------------------------------------

_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Building 3D Coordinates in Java with OpenBabel

Leonid Chepelev
Just to note, comp chem does a local optimisation. To do a global
optimisation you need to do a conformer search and locally optimise
each. With OB, what you're actually comparing is the accuracy of
MMFF94 geometries and those from B3LYP. This is already well studied.


Yes, I know that this is well studied, but I am aiming to see whether OpenBabel does as well as CDK relative to a "sort of true" structure taken from a reference database and reoptimized with DFT in gas phase (and consequently, whether I should prefer one to the other for a particular set of cases), not whether MMFF does a comparable job to DFT in geometry optimization. Obviously if one of the toolkits shows a result that is considerably different from the other, two things could be happening: A) there were bugs in implementing the 0D to 3D conversion or B) one toolkit has a slightly more accurate/exhaustive geometry optimization technique (very hard to imagine). If A is the case, I will see large individual errors in geometries, and if B is the case, I will observe a consistent small difference. My primary concern is case A - that is, whether the three-dimensional geometries are properly assigned, given handling chiral centers and various other points where 3D geometry generation can go wrong.

If you have seen a comparison between the two (or more) toolkits along these lines or any sort of benchmarking studies, I would be very grateful if you could point me to them. Of course, an easier thing to do here is to try the "broken telephone" test - that is, whether all the canonical SMILES I feed OpenBabel's 3D generator will be the same as those obtained after converting the generated 3D geometries back into canonical SMILES...

Speaking of conformational searches, I had been under the impression that some sort of rudimentary conformational analysis, as has been implemented in obconformer, was already taking place when I called gen3D - but from what you have said I am guessing that this is not the case and I would have to hack something together to enable this.

In any case, thank you very much for your helpful comments!

------------------------------------------------------------------------------


_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Building 3D Coordinates in Java with OpenBabel

Noel O'Boyle
Administrator
On 10 May 2010 01:06, Leonid Chepelev <[hidden email]> wrote:

>> Just to note, comp chem does a local optimisation. To do a global
>> optimisation you need to do a conformer search and locally optimise
>> each. With OB, what you're actually comparing is the accuracy of
>> MMFF94 geometries and those from B3LYP. This is already well studied.
>>
>
> Yes, I know that this is well studied, but I am aiming to see whether
> OpenBabel does as well as CDK relative to a "sort of true" structure taken
> from a reference database and reoptimized with DFT in gas phase (and
> consequently, whether I should prefer one to the other for a particular set
> of cases), not whether MMFF does a comparable job to DFT in geometry
> optimization.

I understand - just checking.

> Obviously if one of the toolkits shows a result that is
> considerably different from the other, two things could be happening: A)
> there were bugs in implementing the 0D to 3D conversion or B) one toolkit
> has a slightly more accurate/exhaustive geometry optimization technique
> (very hard to imagine). If A is the case, I will see large individual errors
> in geometries, and if B is the case, I will observe a consistent small
> difference. My primary concern is case A - that is, whether the
> three-dimensional geometries are properly assigned, given handling chiral
> centers and various other points where 3D geometry generation can go wrong.
> If you have seen a comparison between the two (or more) toolkits along these
> lines or any sort of benchmarking studies, I would be very grateful if you
> could point me to them. Of course, an easier thing to do here is to try the
> "broken telephone" test - that is, whether all the canonical SMILES I feed
> OpenBabel's 3D generator will be the same as those obtained after converting
> the generated 3D geometries back into canonical SMILES...

Let us know how it goes. I don't know of any such comparison between
toolkits. I know that in the development version stereochemistry is
handling correctly (except for ring templates with stereochemistry),
but you are likely to find some problems in the release.

> Speaking of conformational searches, I had been under the impression that
> some sort of rudimentary conformational analysis, as has been implemented in
> obconformer, was already taking place when I called gen3D - but from what
> you have said I am guessing that this is not the case and I would have to
> hack something together to enable this.

I've just checked the source
(http://openbabel.svn.sourceforge.net/viewvc/openbabel/openbabel/branches/openbabel-2-2-x/src/ops/gen3d.cpp?revision=3339&view=markup)
and it seems that it should be okay. The lines are as follows:

  pFF->SteepestDescent(250, 1.0e-4);
  pFF->WeightedRotorSearch(200, 25);
  pFF->ConjugateGradients(250, 1.0e-6);

The weighted rotor search is a type of conformer search.

> In any case, thank you very much for your helpful comments!

------------------------------------------------------------------------------

_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Building 3D Coordinates in Java with OpenBabel

Leonid Chepelev
Hi,


Let us know how it goes. I don't know of any such comparison between
toolkits. I know that in the development version stereochemistry is
handling correctly (except for ring templates with stereochemistry),
but you are likely to find some problems in the release.


Will do - though I am not certain at the moment how much time it will take for the few hundred compounds that I have the data for. I will let you all know how it goes here when it is done.
 
I've just checked the source
(http://openbabel.svn.sourceforge.net/viewvc/openbabel/openbabel/branches/openbabel-2-2-x/src/ops/gen3d.cpp?revision=3339&view=markup)
and it seems that it should be okay. The lines are as follows:

 pFF->SteepestDescent(250, 1.0e-4);
 pFF->WeightedRotorSearch(200, 25);
 pFF->ConjugateGradients(250, 1.0e-6);

The weighted rotor search is a type of conformer search.


Excellent! So I won't need to hack together anything extra.

Thank you for the help, and talk to you later!

Regards,

Leonid Chepelev
 

------------------------------------------------------------------------------


_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss