I'm moving this discussion to the development list, I think it's more appropriate. I've tried to debug the issue and I've checked the state of the molecule after each operation. I've tested the code in Python with v.2.3.2 and the latest source code from Git.
This is what happens when I follow the procedure I described before to process this SMILES string: '[N-]=[N+]=NC' mol.DeleteHydrogens() -> [N-]=[N+]=NC mol.UnsetFlag(ob.OB_PH_CORRECTED_MOL) -> [N-]=[N+]=NC mol.SetAutomaticFormalCharge(True) -> [N-]=[N+]=NC mol.AddHydrogens(False, True, 7.4) -> [N-]=[NH2+].C If I apply the formal charge correction used in Avogadro, the charge information is lost, but the result is the same: mol.DeleteHydrogens() -> [N-]=[N+]=NC mol.UnsetFlag(ob.OB_PH_CORRECTED_MOL) -> [N-]=[N+]=NC for a in MOLATOMS: a.SetFormalCharge(0) -> [N]=[N]=NC mol.SetAutomaticFormalCharge(True) -> [N]=[N]=NC mol.AddHydrogens(False, True, 7.4) -> [N-]=[NH2+].C In both cases, one bond gets lost and the molecule gets fragmented, and the culprit seems to be AddHydrogens(), but only when the pH is set: mol.DeleteHydrogens() -> [N-]=[N+]=NC mol.UnsetFlag(ob.OB_PH_CORRECTED_MOL) -> [N-]=[N+]=NC mol.SetAutomaticFormalCharge(True) -> [N-]=[N+]=NC mol.AddHydrogens(False, False) -> [N-]=[N+]=NC It's fairly obvious that something is wrong in way pH is handled. Unfortunately, I have to process a fair amount of molecules containing this group, so I have to come up with a post-processing code to fix molecules before they get written, but I'm open to consider alternatives. I'll be happy to help further debugging the issue. Cheers, S On 03/07/2016 09:50 AM, Stefano Forli wrote: > Hi, > I have a problem adding hydrogens (correcting for the pH) to molecules > containing the azide group. > I'm attaching a script that reproduces the bug. Basically, the procedure I > use is the following: > > mol.DeleteHydrogens() > mol.UnsetFlag(ob.OB_PH_CORRECTED_MOL) > mol.SetAutomaticFormalCharge(True) > mol.AddHydrogens(False, True, 7.4) > > Using this code, the amine nitrogen gets properly protonated, but the azide > group gets disconnected from the molecule, one of the azide nitrogens > disappears and the remaining ones get hydrogenated. > > If I don't use SetAutomaticFormalCharge(), the azide is fine, but the amine > doesn't get protonated. > I've tested writing the output molecules in Mol2 and PDB, and the missing > nitrogen never gets written in the molecule. > Surprisingly, the both number of heavy atoms and the formula reported by OB > does not change, meaning the nitrogen is still there, somewhere. > Is this a bug or am I doing something wrong? > > Thanks, > > S > > -- Stefano Forli, PhD Assistant Professor of Integrative Structural and Computational Biology, Molecular Graphics Laboratory Dept. of Integrative Structural and Computational Biology, MB-112A The Scripps Research Institute 10550 North Torrey Pines Road La Jolla, CA 92037-1000, USA. tel: +1 (858)784-2055 fax: +1 (858)784-2860 email: fo...@scripps.edu http://www.scripps.edu/~forli/ ------------------------------------------------------------------------------ Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140 _______________________________________________ OpenBabel-Devel mailing list OpenBabel-Devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-devel