Doing an energ/force calculation with openbabel

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

Doing an energ/force calculation with openbabel

Troels Kofoed Jacobsen
Hi all

I'm trying to design a calculator for use with ASE (Atomic Simulation
Environment: https://wiki.fysik.dtu.dk/ase/) which uses openbabel to get
energies using UFF and ghemical (for now). For this, I have a couple of
questions.

Is it possible to automatically add bonds. In our code, we do not
represent bonds as we usually just perform DFT calculations. I know
that avogadro/openbabel adds bonds automatically when reading an .xyz
file with openbable, so this should be possible.

When I set up the force field, I can get the energy with FF.Energy(). Is
it possible to get the gradient with respect to nuclear/atomic
coordinates. Something like this must be available for use in
openbabels internal structure optimizers.

And lastly: When doing an optimization, how do I get the new
coordinates? My calculation is like:

"""
import openbabel as ob

FF = ob.OBForceField.FindForceField("UFF")

mol = ob.OBMol()
a = mol.NewAtom()
a.SetAtomicNum(1)
a.SetVector(0,0,0)

b = mol.NewAtom()
b.SetAtomicNum(1)
b.SetVector(0,0,1)
mol.AddBond(1, 2, 1)   # atoms indexed from 1

FF.Setup(mol)
print FF.Energy(), FF.GetUnit()

FF.ConjugateGradients(1000)
print FF.Energy(), FF.GetUnit()

print FF.GetCoordinates(mol)
"""
The last line just returns "True"


Thanks for your time reading this.

Best regards
Troels Kofoed Jacobsen

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Doing an energ/force calculation with openbabel

Noel O'Boyle
Administrator
On 11 March 2010 11:07, Troels Kofoed Jacobsen <[hidden email]> wrote:

> Hi all
>
> I'm trying to design a calculator for use with ASE (Atomic Simulation
> Environment: https://wiki.fysik.dtu.dk/ase/) which uses openbabel to get
> energies using UFF and ghemical (for now). For this, I have a couple of
> questions.
>
> Is it possible to automatically add bonds. In our code, we do not
> represent bonds as we usually just perform DFT calculations. I know
> that avogadro/openbabel adds bonds automatically when reading an .xyz
> file with openbable, so this should be possible.

OBMol.ConnectTheDots() followed by OBMol.PerceiveBondOrders(). See API
at http://openbabel.org/api/2.2.0/classOpenBabel_1_1OBMol.shtml

> When I set up the force field, I can get the energy with FF.Energy(). Is
> it possible to get the gradient with respect to nuclear/atomic
> coordinates. Something like this must be available for use in
> openbabels internal structure optimizers.

I will leave this to the others. Also I think you have a separate
email on this topic.

> And lastly: When doing an optimization, how do I get the new
> coordinates? My calculation is like:
>
> """
> import openbabel as ob
>
> FF = ob.OBForceField.FindForceField("UFF")
>
> mol = ob.OBMol()
> a = mol.NewAtom()
> a.SetAtomicNum(1)
> a.SetVector(0,0,0)
>
> b = mol.NewAtom()
> b.SetAtomicNum(1)
> b.SetVector(0,0,1)
> mol.AddBond(1, 2, 1)   # atoms indexed from 1
>
> FF.Setup(mol)
> print FF.Energy(), FF.GetUnit()
>
> FF.ConjugateGradients(1000)
> print FF.Energy(), FF.GetUnit()
>
> print FF.GetCoordinates(mol)
> """
> The last line just returns "True"

True means success. This is always good. If you check the coordinates
of the atoms, e.g. mol.GetAtom(1).GetVector() you will see new values.

>
> Thanks for your time reading this.

You've made my day. After a quick google, I see that you are a fellow
open source developer - who else can understand the effort required?
:-)

> Best regards
> Troels Kofoed Jacobsen
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> OpenBabel-discuss mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Doing an energ/force calculation with openbabel

Geoffrey Hutchison
In reply to this post by Troels Kofoed Jacobsen
> I'm trying to design a calculator for use with ASE (Atomic Simulation
> Environment: https://wiki.fysik.dtu.dk/ase/) which uses openbabel to get
> energies using UFF and ghemical (for now). For this, I have a couple of
> questions.

Two quick notes, since I see Noel answered some of the other questions
1) Don't bother with Ghemical. We implemented it because it was easy and there was an existing open source implementation for validation. It's basically the old Tripos force field, so UFF and MMFF94 both have significant advantages.

2) One warning. Your code is licensed under the LGPLv3, which is incompatible with the GPLv2 license of Open Babel. My suggestion is to use "LGPLv3 or GPLv2", which will work fine.

As far as the gradient, we'd need to expose that -- it's not something which anyone considered would be very useful. It could certainly go into SVN trunk for the OB-2.3 releases. (You can already get the forces on each atom if that's enough for you.)

Cheers,
-Geoff


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Doing an energ/force calculation with openbabel

Troels Kofoed Jacobsen
In reply to this post by Noel O'Boyle
>
> OBMol.ConnectTheDots() followed by OBMol.PerceiveBondOrders(). See API
> at http://openbabel.org/api/2.2.0/classOpenBabel_1_1OBMol.shtml
>

This is exactly what I need, THANKS!

> > When I set up the force field, I can get the energy with FF.Energy(). Is
> > it possible to get the gradient with respect to nuclear/atomic
> > coordinates. Something like this must be available for use in
> > openbabels internal structure optimizers.
>
> I will leave this to the others. Also I think you have a separate
> email on this topic.

Yes, sorry about that. I thought the first mail didn't go through as I
wasn't subscribed at the time.

Best regards
Troels Kofoed Jacobsen


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Doing an energ/force calculation with openbabel

Troels Kofoed Jacobsen
In reply to this post by Geoffrey Hutchison
> 2) One warning. Your code is licensed under the LGPLv3, which is incompatible with the GPLv2 license of Open Babel. My suggestion is to use "LGPLv3 or GPLv2", which will work fine.

Hmm, thats annoying, as I don't think I'm able to change the license of
ASE. I'll try to figure out a solution. Thanks for reminding me!

> As far as the gradient, we'd need to expose that -- it's not something which anyone considered would be very useful. It could certainly go into SVN trunk for the OB-2.3 releases. (You can already get the forces on each atom if that's enough for you.)

Forces on individual atoms will do just fine. I didn't find them in the
documetation, however. Can you give me a pointer?


Best regards
Troels Kofoed Jacobsen

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Doing an energ/force calculation with openbabel

Geoffrey Hutchison
> Forces on individual atoms will do just fine. I didn't find them in the
> documetation, however. Can you give me a pointer?

Some information is in the OBForceField class with GetCoordinates()
http://openbabel.org/api/2.2.0/classOpenBabel_1_1OBForceField.shtml#8be38bcae14834b6849d777e19885955

You would retrieve the forces through the OBConformerData class:
http://openbabel.org/api/2.2.0/classOpenBabel_1_1OBConformerData.shtml

Hope that helps,
-Geoff
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Doing an energ/force calculation with openbabel

Troels Kofoed Jacobsen
On Sat, Mar 13, 2010 at 09:19:19AM -0500, Geoffrey Hutchison wrote:

> > Forces on individual atoms will do just fine. I didn't find them in the
> > documetation, however. Can you give me a pointer?
>
> Some information is in the OBForceField class with GetCoordinates()
> http://openbabel.org/api/2.2.0/classOpenBabel_1_1OBForceField.shtml#8be38bcae14834b6849d777e19885955
>
> You would retrieve the forces through the OBConformerData class:
> http://openbabel.org/api/2.2.0/classOpenBabel_1_1OBConformerData.shtml
>
> Hope that helps,
> -Geoff

Thanks a lot.

I now have:

FF.GetCoordinates(mol)
data = ob.toConformerData(mol.GetData(4))
f = data.GetForces()

However, f is now of type:
<Swig Object of type 'std::vector< std::vector< OpenBabel::vector3,std::allocator< OpenBabel::vector3 > >,std::allocator< std::vector< OpenBabel::vector3,std::allocator< >OpenBabel::vector3 > > > > *' at 0x2d174e0>

I have a really hard time getting any data out of that.

Best regards
Troels Kofoed Jacobsen

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Doing an energ/force calculation with openbabel

Noel O'Boyle
Administrator
On 13 March 2010 16:50, Troels Kofoed Jacobsen <[hidden email]> wrote:

> On Sat, Mar 13, 2010 at 09:19:19AM -0500, Geoffrey Hutchison wrote:
>> > Forces on individual atoms will do just fine. I didn't find them in the
>> > documetation, however. Can you give me a pointer?
>>
>> Some information is in the OBForceField class with GetCoordinates()
>> http://openbabel.org/api/2.2.0/classOpenBabel_1_1OBForceField.shtml#8be38bcae14834b6849d777e19885955
>>
>> You would retrieve the forces through the OBConformerData class:
>> http://openbabel.org/api/2.2.0/classOpenBabel_1_1OBConformerData.shtml
>>
>> Hope that helps,
>> -Geoff
>
> Thanks a lot.
>
> I now have:
>
> FF.GetCoordinates(mol)
> data = ob.toConformerData(mol.GetData(4))
> f = data.GetForces()
>
> However, f is now of type:
> <Swig Object of type 'std::vector< std::vector< OpenBabel::vector3,std::allocator< OpenBabel::vector3 > >,std::allocator< std::vector< OpenBabel::vector3,std::allocator< >OpenBabel::vector3 > > > > *' at 0x2d174e0>
>
> I have a really hard time getting any data out of that.

I'm afraid that this means that you can't access it right now. We
haven't wrapped vectors of vectors of vector3s. Could you file this as
a bug?

> Best regards
> Troels Kofoed Jacobsen
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> OpenBabel-discuss mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Doing an energ/force calculation with openbabel

Troels Kofoed Jacobsen
> I'm afraid that this means that you can't access it right now. We
> haven't wrapped vectors of vectors of vector3s. Could you file this as
> a bug?

Here you go:
https://sourceforge.net/tracker/?func=detail&aid=2969937&group_id=40728&atid=428740

Thanks for your help!

/Troels Kofoed Jacobsen

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss