On 14/02/2013 16:48, David Lonie wrote: > There seems to a bug when adding hydrogens to a molecule with only a > single atom: > > $ cat /tmp/t.cml > <?xml version="1.0"?> > <molecule xmlns="http://www.xml-cml.org/schema"> > <atomArray> > <atom id="a1" elementType="C" x3="0.386206" y3="1.895920" > z3="-0.000004"/> > </atomArray> > </molecule> > > $ obabel -icml /tmp/t.cml -ocml -h > <?xml version="1.0"?> > <molecule spinMultiplicity="5" xmlns="http://www.xml-cml.org/schema"> > <atomArray> > <atom id="a1" elementType="C" spinMultiplicity="5" x3="0.386206" > y3="1.895920" z3="-0.000004"/> > </atomArray> > </molecule> > 1 molecule converted > > It works fine if there are 2 carbons. This is with today's trunk. > > Should I file a bug, or is this expected behavior for some reason?
AddHydrogens(false, false) (called by the -h option) makes implicit hydrogen into explicit hydrogen. It usually does not change the molecule by adding hydrogen to radicals, charged species or multiple bonds. So obabel -:[C] -:[C][C] -ocml -h <?xml version="1.0"?> <cml xmlns="http://www.xml-cml.org/schema"> <molecule spinMultiplicity="5"> <atomArray> <atom id="a1" elementType="C" spinMultiplicity="5"/> </atomArray> </molecule> <molecule spinMultiplicity="7"> <atomArray> <atom id="a1" elementType="C" spinMultiplicity="4"/> <atom id="a2" elementType="C" spinMultiplicity="4"/> </atomArray> <bondArray> <bond atomRefs2="a1 a2" order="1"/> </bondArray> </molecule> </cml> adds no hydrogen (explicit or implicit). I think this the correct behaviour. However there is a special behaviour for multi-atom molecules with no bonds (see line 2395 in mol.cpp): obabel -:[C].[C] -ocml -h <?xml version="1.0"?> <cml xmlns="http://www.xml-cml.org/schema"> <molecule> <atomArray> <atom id="a1" elementType="C"/> <atom id="a2" elementType="C"/> <atom id="a3" elementType="H"/> <atom id="a4" elementType="H"/> <atom id="a5" elementType="H"/> <atom id="a6" elementType="H"/> <atom id="a7" elementType="H"/> <atom id="a8" elementType="H"/> <atom id="a9" elementType="H"/> <atom id="a10" elementType="H"/> </atomArray> <bondArray> <bond atomRefs2="a1 a3" order="1"/> <bond atomRefs2="a1 a4" order="1"/> <bond atomRefs2="a1 a5" order="1"/> <bond atomRefs2="a1 a6" order="1"/> <bond atomRefs2="a2 a7" order="1"/> <bond atomRefs2="a2 a8" order="1"/> <bond atomRefs2="a2 a9" order="1"/> <bond atomRefs2="a2 a10" order="1"/> </bondArray> </molecule> </cml> It is this behaviour which is suspect in the essential non-editing obabel interface because the molecule is altered. Ii is there so that a compchem file with no bonds could be converted into a cml file with just the atoms (sometimes good enough): obabel -:[O].[C].[O] -ocml <?xml version="1.0"?> <cml xmlns="http://www.xml-cml.org/schema"> <molecule> <atomArray> <atom id="a1" elementType="O"/> <atom id="a2" elementType="C"/> <atom id="a3" elementType="O"/> </atomArray> </molecule> </cml> With normal use of obabel I expect this non-standard behaviour would rarely occur. But you are doing tricky things (like editing molecules) to subvert the licence. Have you considered writing an op and building it by itself in a DLL(*.obf) or shared library? It could be then be added to an existing OpenBabel installation (without any rebuilding) to give custom capability by running obabel. Chris ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ OpenBabel-Devel mailing list OpenBabel-Devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-devel