I am trying to use Open Babel (OB) to compute universal force field (UFF) given an xyz
file. I read each xyz
file and turn it into a pybel molecule. Here is the code I have so far
def xyz_to_smiles(fname: str) -> str:
mol = next(pybel.readfile("xyz", fname))
smi = mol.write(format="smi")
return smi.split()[0].strip(), mol
def get_qm9_OB(target_index=np.arange(0, 133884)):
smiles = []
molecule = []
for i in target_index:
mol_idx = f"{i+1:06d}"
tmp_smiles, tmp_molecule = xyz_to_smiles('../dsgdb9nsd.xyz/dsgdb9nsd_' + mol_idx + '.xyz')
smiles.append(tmp_smiles)
molecule.append(tmp_molecule)
return molecule, smiles
molecules, smiles = get_qm9_OB(target_index=np.arange(100,200))
for i in range(len(smiles)):
mol = molecules[i].OBMol
ff = ob.OBForceField.FindForceField('UFF')
ff.Setup(mol)
ff.GetAtomTypes(mol)
ff.GetCoordinates(mol)
for at in ob.OBMolAtomIter(mol):
type = at.GetData("FFAtomType") # an OBPairData object
print(type.GetValue())
Now, I am trying to compute bond stretching interactions. My questions are:
- How can I get the UFF constants for bond stretching? (IOW, is there an OB equivalent for RDKit function
GetUFFBondStretchParams
?) - Is there a function to calculate bond stretching interactions for each bond? (IOW, is there an OB implementation of either harmonic oscillator or the Morse function?)
How can I get coordinates from
OBAtom
object? I foundGetCoordinate()
but the output is<Swig Object of type 'double *' at 0x1a1eb4a9f0>
Alternatively,
GetVector()
outputs<openbabel.vector3; proxy of <Swig Object of type 'OpenBabel::vector3 *' at 0x1a1fbddbd0> >
How can I get the actual values?
P.S. I posted the problem on OB mailing list, with no answers.
xyz_to_smiles
. Now you can see how it reads the file. Let me know what part you don't understand so that I can clarify. $\endgroup$