Hello,

I am trying to use the optimize options of OpenBabel. I have written
the following code using some of the online examples (I am simplifying
the code), but it doesn't work as expected:

// Open the file
OpenBabel::OBConversion obConversion;
OpenBabel::OBMol obMol;
obConversion.SetInFormat("xyz");
obConversion.ReadFile(&obMol,"Ligand.xyz");

// Define the forcefield
OpenBabel::OBForceField *ff = OpenBabel::OBForceField::FindForceField("MMFF94");
// Setup the forcefield.
ff->Setup(obMol);
// Print the energy and unit before optimization
cout << ff->Energy() << " " << ff->GetUnit() << endl;

// Perform the minimization
ff->SteepestDescent(1000);
cout << ff->Energy() << " " << ff->GetUnit() << endl;
ff->ConjugateGradients(1000);
cout << ff->Energy() << " " << ff->GetUnit() << endl;

// Write the output
OpenBabel::OBMol mol;
OpenBabel::OBConversion conv;
ff->GetCoordinates(mol);
conv.SetOutFormat("xyz");
conv.WriteFile(&mol,"Ligand_Opt.xyz");
cout << mol.NumAtoms() << endl;

The output is for example:
285.045 kcal/mol
57.897 kcal/mol
57.8942 kcal/mol
0

So the two optimization are working. However, the molecule is not
written in the Ligand_Opt.xyz file since the mol object is empty as
seen by the "0" in the output. I must be doing something wrong with
"ff->GetCoordinates(mol);" but I have not find what.

Can you please help me or point me toward the good direction.

Thank you

Nicolas

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to