I've discovered a subtle bug in the calculation of OBAtom::KBOSum(),
specifically in OBAtom::GetImplicitValence, that causes the incorrect
value to be returned for hydrogens with valence greater than one.

This manifests itself as the failure of obgrep to match the SMARTS
[v2] against the molecule C[H]C.  Without this OpenBabel's SMARTS
can't be used to identify molecules with dubious hydrogen valences.

The problem is fixed by the attached patch which corrects the special
case for hydrogen in OBAtom::GetImplicitValence().  The desired
invariant is that GetImplicitValence should never return a value less
than GetValence, i.e. implicit hydrogens or radicals may be present,
but the explicit bonds can never be ignored.

Index: src/atom.cpp
===================================================================
*** src/atom.cpp        (revision 4680)
--- src/atom.cpp        (working copy)
*************** namespace OpenBabel
*** 501,508 ****
    unsigned int OBAtom::GetImplicitValence() const
    {
      //Special case for [H] to avoid infite loop: SMARTS Match() <-> 
AssignSpinMultiplicity()
!     if(GetAtomicNum() == 1)
!       return GetFormalCharge() ? 0 : 1;
      OBMol *mol = (OBMol*)((OBAtom*)this)->GetParent();
      if (mol && !mol->HasImplicitValencePerceived())
        
atomtyper.AssignImplicitValence(*((OBMol*)((OBAtom*)this)->GetParent()));
--- 501,512 ----
    unsigned int OBAtom::GetImplicitValence() const
    {
      //Special case for [H] to avoid infite loop: SMARTS Match() <-> 
AssignSpinMultiplicity()
!     if(GetAtomicNum() == 1) {
!       unsigned int val = GetValence();
!       if (val == 0 && GetFormalCharge() == 0 && GetSpinMultiplicity() == 0)
!         return 1;
!       return val;
!     }
      OBMol *mol = (OBMol*)((OBAtom*)this)->GetParent();
      if (mol && !mol->HasImplicitValencePerceived())
        
atomtyper.AssignImplicitValence(*((OBMol*)((OBAtom*)this)->GetParent()));



Thanks in advance,

Roger
--
Roger Sayle, Ph.D.
CEO and founder
NextMove Software Ltd
Cambridge, UK

------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel

Reply via email to