Consider ethanol, where each carbon atom has a valency of 4 and oxygen a valency of -2. I would like to determine these values for many compounds given their SMILES or InChI keys. (For the purpose of computing the degree of reduction, which in the case of ethanol is 6)
I would like to find a systematic method to calculate this for many molecules. I attempted to use Open Babel as described below, but I am open to any other programmatic solution.
Attempt with Open Babel on Python:
I attempted the following with openbabel.pybel (after installing the appropriate packages):
from openbabel import pybel
ethanol = 'CCO' # SMILES
mol = pybel.readstring('smi', ethanol)
for atom in mol.atoms:
print(f"type={atom.type} charge={atom.formalcharge} \
degree(valence)={atom.degree} implicitvalence={atom.implicitvalence}")
This returns the error:
AttributeError: 'OBAtom' object has no attribute 'GetImplicitValence'
If I understand correctly the implicit valence is the value I am after. I am stuck and the documentation is not helping (is not even consistent with the behavior of the module)
openbabel.__version__
returns 3.0.0
.
This is based on a 6 year old question