Great example of functools.partial.
For those who like functional programming, it can also be used with map and
imap when a function needs more than one parameters.
George.
Sent from my giPhone
> On 12 Oct 2017, at 19:04, Andy Jennings <andy.j.jenni...@gmail.com> wrote:
>
> Hi Paolo,
>
> That's outstanding - thanks very much.
>
> Best,
> Andy
>
>> On Thu, Oct 12, 2017 at 10:27 AM, Paolo Tosco <paolo.to...@unito.it> wrote:
>> Dear Andy,
>>
>> you may accomplish that within the scope of a Python script using
>> functools.partial:
>>
>> In [1]: from rdkit import Chem
>>
>> In [2]: import functools
>>
>> In [3]: # redefine Chem.SDMolSupplier to include a custom default parameter
>>
>> In [4]: Chem.SDMolSupplier = functools.partial(Chem.SDMolSupplier, removeHs
>> = False)
>>
>> In [5]: suppl = Chem.SDMolSupplier('/home/paolo/sdf/bilastine.sdf')
>>
>> In [6]: # hydrogens have not been stripped
>>
>> In [7]: suppl[0].GetNumAtoms()
>> Out[7]: 71
>>
>> In [8]: # If you wish to invoke the original function with the original
>> default parameter:
>>
>> In [9]: suppl = Chem.SDMolSupplier.func('/home/paolo/sdf/bilastine.sdf')
>>
>> In [10]: # hydrogens have been stripped as the original function was invoked
>>
>> In [11]: suppl[0].GetNumAtoms()
>> Out[11]: 34
>> HTH, cheers
>> p.
>>> On 10/12/17 18:09, Andy Jennings wrote:
>>> Hi,
>>>
>>> First off: great work on the RDKit - a great resource for those of us that
>>> like to cook up our own solutions to problems.
>>>
>>> The default behavior of certain calls (e.g. Chem.SDMolSupplier,
>>> Chem.MolToSmiles) has default behavior that is the opposite of what I would
>>> generally want. For instance I might be processing docking files and want
>>> to keep those pesky hydrogens, or I want to keep the stereochemical
>>> information when I dump a smiles string.
>>>
>>> I can understand why the current defaults might have been arrived at so I'm
>>> not advocating the change in default behavior. Rather, I'm curious if one
>>> could set the default behavior for an entire script (I write mostly
>>> python). It maybe/is lazy of me but every so often I get caught out and
>>> have to backtrack through a workflow.
>>>
>>> Best,
>>> Andy
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>>
>>>
>>> _______________________________________________
>>> Rdkit-discuss mailing list
>>> Rdkit-discuss@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss