1
$\begingroup$

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

$\endgroup$
5
  • 1
    $\begingroup$ Possible duplicate of Counting valency of atoms, in a molecule with python $\endgroup$
    – Mithoron
    Dec 5, 2019 at 0:46
  • 2
    $\begingroup$ There's no 'implicit valence' in Open Babel 3 because we found it to be a very confusing concept. I think you should ask a more general question outside your specifics with Pybel. $\endgroup$ Dec 10, 2019 at 16:37
  • $\begingroup$ @GeoffHutchison Thank you for noting that. I edited my question to make it more general, I am open to use any tool that would get the job done, it does not have to be limited to python or open babel. $\endgroup$
    – jsb
    Dec 10, 2019 at 17:26
  • $\begingroup$ If you consider valency to be the number of bonds a compound forms, then it cannot be negative and oxygen’s valency is also 2. If you consider it as some kind of oxidation state, then it can be negative, but then carbon’s oxidation states are $\mathrm{-III}$ and $\mathrm{-I}$. $\endgroup$
    – Jan
    Dec 18, 2019 at 8:25
  • $\begingroup$ I'm positive this would now be on topic at Matter Modeling. However, from a chemical and definition point of view in regard to valence it does not make sense. Valence is a fixed number for each element. doi.org/10.1351/goldbook.V06588 This is 4 for carbon and 2 for oxygen and 1 for hydrogen… you need a table and probably not a program for this. $\endgroup$ Feb 22, 2023 at 18:50

1 Answer 1

1
$\begingroup$

It is possible to extract implicit and explicit valence from a SMILES string using rdkit.

I am using rdkit version 2022.9.4.

The definitions of implicit and explicit valence according to rdkit are:

GetExplicitValence((Atom)arg1) → int :
Returns the explicit valence of the atom.

GetImplicitValence((Atom)arg1) → int :
Returns the number of implicit Hs on the atom.

Here is fully reproducible code to get implicit and explicit valence of atoms in a molecule:

from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole
IPythonConsole.ipython_useSVG=True  

smiles = 'CCO'
mol = Chem.MolFromSmiles(smiles)
mol

implicit_valence = [(atom.GetSymbol(), atom.GetImplicitValence()) for atom in mol.GetAtoms()]
implicit_valence

# Outputs >> [('C', 3), ('C', 2), ('O', 1)]

explicit_valence = [(atom.GetSymbol(), atom.GetExplicitValence()) for atom in mol.GetAtoms()]
explicit_valence

# Outputs >> [('C', 1), ('C', 2), ('O', 1)]
$\endgroup$
4
  • 1
    $\begingroup$ Is there a word definition for implicit and explicit valence? Valence is a fixed number for each element, so they must use a much different definition. $\endgroup$ Feb 22, 2023 at 18:52
  • $\begingroup$ I could not find a definition per se, and I am not expertised in chemistry, but as far as I understand from their documentation, explicit valence is the number of bonds that atom forms in the molecule. And implicit valence is the number of implicit H atoms attached to the atom. $\endgroup$ Feb 22, 2023 at 19:04
  • 1
    $\begingroup$ @Martin-マーチン - some formats / representations (e.g., SMILES, ChemDraw, SD files) do not explicitly indicate hydrogen atoms - think a standard 2D organic molecule depiction. So these are "implicit" hydrogens vs. formats that require all atoms to be indicated (e.g., quantum chemistry). $\endgroup$ Feb 22, 2023 at 19:05
  • 1
    $\begingroup$ @Geoff Thank you for clearing that up. I can only wonder, why we reuse these terms, when the original is already confusing enough… $\endgroup$ Feb 22, 2023 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.