Hi Zhenting,
When I need a slightly more complicated sort in Python, I always refer to
https://docs.python.org/3.3/howto/sorting.html
Originally written by Andrew Dalke of this parish. One useful tip he gives
is that in Python, you always get a stable sort. That means if you sort on
one key and then on a second, items that have the same 2nd key will be left
in the order they were in after the first sort. This makes sorting on
multiple criteria a matter of doing individual sorts in succession. Also,
to reverse the sense of the sort, use the “reverse=true” parameter for the
sort function.

HTH,
Dave


On Sun, 5 Apr 2020 at 13:18, Zhenting Gao <183310...@qq.com> wrote:

> Hi Paolo,
> Your previous reply already helped me.
> If I need to sort multiple properties, with different directions, What
> would the code be?
> Would it be easier to put mols into a pandas dataframe? If so, how to do
> it?
>
> Best regards
> Zhenting
> ---Original---
> *From:* "Paolo Tosco"<paolo.tosco.m...@gmail.com>
> *Date:* Fri, Apr 3, 2020 23:58 PM
> *To:* "Zhenting Gao"<183310...@qq.com>;"Rdkit-discuss"<
> Rdkit-discuss@lists.sourceforge.net>;
> *Subject:* Re: [Rdkit-discuss] How to sort a list of mol objects
>
> Hi Zhenting,
>
> you mean sort by a property value?
> For example, this would sort your list by decreasing value of the ACTIVITY
> property (e.g., assuming it is a pIC50):
>
> mol_list.sort(key=lambda m: float(m.GetProp("ACTIVITY")), reverse=True)
>
> Cheers,
> p.
> On 03/04/2020 16:38, Zhenting Gao wrote:
>
> Hi,
>
> I create a list of mol objects, now I want to sort these mol objects, so
> that I can save the top 100 mols into an SDF file.
> Could you help?
>
> Best
> Zhenting
> 4/3/2020
>
>
> _______________________________________________
> Rdkit-discuss mailing 
> listRdkit-discuss@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
-- 
David Cosgrove
Freelance computational chemistry and chemoinformatics developer
http://cozchemix.co.uk
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to