The way I usually do it is by manipulating hydrogens directly in the molecule 
object:

    mol.DeleteHydrogens()
    mol.AddHydrogens(polaronly=False, correctForPh=True, pH=7.4)

The only caveat is that this method is not as reliable as the command line.
The outcome might be different from what obtained when using 'obabel' directly, 
and does not seem to be very robust (e.g., unreasonable formal charges, 
bonds...)
I suggest you to try with your molecules and double-check the output. Sometimes 
performing these operations before adding hydrogens seem to help:

    mol.UnsetFlag(openbabel.OB_PH_CORRECTED_MOL)
    mol.SetAutomaticFormalCharge(True)

There are a few open issues on the matter on GitHub.
Hope this helps,

Stefano

On 4/17/19 1:29 AM, Tim Dudgeon wrote:
> Yes, but I don't see how that helps work out how to call it from Python.
> I was trying something like this:
> 
>> obConversion.AddOption("p", obConversion.GENOPTIONS, "3.0")
> That seems vaguely consistent with how to set the option from Python given 
> how the CLI option works, but unfortunately it doesn't seem to work.
> 
> Tim
> 
> On 15/04/2019 13:03, Noel O'Boyle wrote:
>> Hi Tim,
>>
>> Many of these options are just wrappers around API functions, so it's 
>> worthwhile taking a look at the API documentation. In this case, here's the 
>> link to the relevant docs:
>>
>> http://openbabel.org/api/2.3/classOpenBabel_1_1OBPhModel.shtml
>>
>> Regards,
>> - Noel
>>
>> On Thu, 11 Apr 2019 at 16:11, Tim Dudgeon <tdudgeon...@gmail.com 
>> <mailto:tdudgeon...@gmail.com>> wrote:
>>
>>     Another Python options question.
>>     I can use the protonation option on the CLI:
>>
>>     > echo "C1=C(NC=N1)C[C@@H](C(=O)O)N" | obabel -i smi -o mol -p 3
>>     But I can't figure it out with the Python API:
>>
>>     > import openbabel
>>     >
>>     > obConversion = openbabel.OBConversion()
>>     > obConversion.SetInAndOutFormats("smi", "mol")
>>     > mol = openbabel.OBMol()
>>     > obConversion.AddOption("p", obConversion.GENOPTIONS, "3.0")
>>     > obConversion.ReadString(mol, "C1=C(NC=N1)C[C@@H](C(=O)O)N")
>>     > output = obConversion.WriteString(mol)
>>     > print output
>>     Output is generated but it's not protonated. Same if using OUTOPTIONS
>>     instead of GENOPTIONS.
>>
>>     Is the use of the options in Python documented anywhere?
>>
>>
>>
>>
>>
>>     _______________________________________________
>>     OpenBabel-discuss mailing list
>>     OpenBabel-discuss@lists.sourceforge.net 
>> <mailto:OpenBabel-discuss@lists.sourceforge.net>
>>     https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>>
> 
> 
> _______________________________________________
> OpenBabel-discuss mailing list
> OpenBabel-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
> 

-- 

  Stefano Forli, PhD

  Assistant Professor
  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/faculty/forli/

_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to