Re: [Rdkit-discuss] Programatic access to the mol sanitation process results

2018-03-09 Thread Peter Gedeck
Hello Lukas,

The file rdkit/TestRunner.py contains a class/context manager called 
OutputRedirectC. If I remember correctly, this allowed capturing these 
messages. It's not used anywhere in the RDkit code base, so it not work 
anymore. Anyway, give it a try and if it works, you can modify it to redirect 
the output into a variable or StringIO. 

Best,

Peter


> On 9 Mar 2018, at 9:34 AM, Lukas Pravda  wrote:
> 
> Hello Greg, 
>  
> I’m very sorry for the late reply. Thank you for the hint on disabling the 
> log message, it works on my end. However, I was more interested in catching 
> the other bit i.e. which part of the structure is wrong, rather than which 
> part of the sanitization process failed. That is accessing the message 
> ‘Explicit valence for atom # 1 O, 3, is greater than permitted’ in form to 
> find out that it is the misbehaving oxygen which causes failure of the 
> sanitization process. Perhaps piping the log information into a variable or 
> something like that.
>  
> Best,
> Lukas
>  
>  
>  
> From: Greg Landrum >
> Date: Thursday, 22 February 2018 at 13:32
> To: Lukas Pravda >
> Cc: RDKit Discuss  >
> Subject: Re: [Rdkit-discuss] Programatic access to the mol sanitation process 
> results
>  
> Hi Lukas,
>  
> On Thu, Feb 22, 2018 at 1:14 PM, Lukas Pravda  > wrote:
>> Dear rdkiters,
>>  
>> I’m constructing molecules from scratch using python 3.5.4 and RDKit 
>> 2017.09.2 and due to the variety of reasons some of them are violating 
>> general principles of chemistry in a way implemented in rdkit, so I’m 
>> getting information like:
>>  
>> Explicit valence for atom # 14 N, 4, is greater than permitted etc.
>>  
>> I wonder if there is a way how to retrieve this piece of information in a 
>> programmatic way. In order to work with it. Presently, rdkit only prints 
>> this out into terminal and Chem.SanitizeMol() only returns first 
>> sanitization flag with the issue. Ideally, I’d like no information to be 
>> printed into console, while keeping the log info ‘Explicit valence for atom 
>> # 14 N, 4, is greater than permitted’ preferably in a structured way (in a 
>> property/method?), in order to further deal with those erroneous cases.
>  
> At last part of this is pretty straightforward.
>  
> There are two parts: 
> - making it so error messages don't go to the console 
> - capturing the failed operation.
>  
> The first is a bit fragile (i.e. doesn't always work), so you will sometimes 
> end up still seeing error messages (as here), but the second should be 
> reliable:
>  
> In [30]: rdBase.DisableLog('rdApp.*')
>  
> In [31]: m = Chem.MolFromSmiles('c11',sanitize=False)
>  
> In [32]: Chem.SanitizeMol(m,catchErrors=True)
> [14:29:37] Can't kekulize mol.  Unkekulized atoms: 0 1 2 3 4
>  
> Out[32]: rdkit.Chem.rdmolops.SanitizeFlags.SANITIZE_KEKULIZE
>  
> In [35]: 
> Chem.SanitizeMol(Chem.MolFromSmiles('CO(C)C',sanitize=False),catchErrors=True)
> [14:31:37] Explicit valence for atom # 1 O, 3, is greater than permitted
> Out[35]: rdkit.Chem.rdmolops.SanitizeFlags.SANITIZE_PROPERTIES
>  
>  
> You can see that the return value indicates what went wrong in the 
> sanitization.
>  
> I hope this helps,
> -greg
>  
>  
>  
>  
> --
> 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


Re: [Rdkit-discuss] Programatic access to the mol sanitation process results

2018-03-09 Thread Lukas Pravda
Hello Greg, 

 

I’m very sorry for the late reply. Thank you for the hint on disabling the log 
message, it works on my end. However, I was more interested in catching the 
other bit i.e. which part of the structure is wrong, rather than which part of 
the sanitization process failed. That is accessing the message ‘Explicit 
valence for atom # 1 O, 3, is greater than permitted’ in form to find out that 
it is the misbehaving oxygen which causes failure of the sanitization process. 
Perhaps piping the log information into a variable or something like that.

 

Best,

Lukas

 

 

 

From: Greg Landrum 
Date: Thursday, 22 February 2018 at 13:32
To: Lukas Pravda 
Cc: RDKit Discuss 
Subject: Re: [Rdkit-discuss] Programatic access to the mol sanitation process 
results

 

Hi Lukas,

 

On Thu, Feb 22, 2018 at 1:14 PM, Lukas Pravda  wrote:

Dear rdkiters,

 

I’m constructing molecules from scratch using python 3.5.4 and RDKit 2017.09.2 
and due to the variety of reasons some of them are violating general principles 
of chemistry in a way implemented in rdkit, so I’m getting information like:

 

Explicit valence for atom # 14 N, 4, is greater than permitted etc.

 

I wonder if there is a way how to retrieve this piece of information in a 
programmatic way. In order to work with it. Presently, rdkit only prints this 
out into terminal and Chem.SanitizeMol() only returns first sanitization flag 
with the issue. Ideally, I’d like no information to be printed into console, 
while keeping the log info ‘Explicit valence for atom # 14 N, 4, is greater 
than permitted’ preferably in a structured way (in a property/method?), in 
order to further deal with those erroneous cases.

 

At last part of this is pretty straightforward.

 

There are two parts: 

- making it so error messages don't go to the console 

- capturing the failed operation.

 

The first is a bit fragile (i.e. doesn't always work), so you will sometimes 
end up still seeing error messages (as here), but the second should be reliable:

 

In [30]: rdBase.DisableLog('rdApp.*')

 

In [31]: m = Chem.MolFromSmiles('c11',sanitize=False)

 

In [32]: Chem.SanitizeMol(m,catchErrors=True)

[14:29:37] Can't kekulize mol.  Unkekulized atoms: 0 1 2 3 4

 

Out[32]: rdkit.Chem.rdmolops.SanitizeFlags.SANITIZE_KEKULIZE

 

In [35]: 
Chem.SanitizeMol(Chem.MolFromSmiles('CO(C)C',sanitize=False),catchErrors=True)

[14:31:37] Explicit valence for atom # 1 O, 3, is greater than permitted

Out[35]: rdkit.Chem.rdmolops.SanitizeFlags.SANITIZE_PROPERTIES

 

 

You can see that the return value indicates what went wrong in the sanitization.

 

I hope this helps,

-greg

 

 

 

 

--
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


Re: [Rdkit-discuss] rotatable bond

2018-03-09 Thread Maciek Wójcikowski
Hi Mariana,

You can do exactly what this function is doing - counting matches of a
SMARTS definition of rotatable bond. For a bond you can check if it matches
mentioned SMARTS. The definition is here:
http://www.rdkit.org/Python_Docs/rdkit.Chem.Lipinski-module.html

SMARTS_DEF = '[!$(*#*)&!D1]-&!@[!$(*#*)&!D1]'
> bond = mol.GetBondWithIdx(5)  # Get any bond in a molecule
> rot_mol = Chem.MolFromSmarts(SMARTS_DEF)
> rot_bond = rot_mol.GetBondWithIdx(0)
> if bond.Match(rot_bond):
> print(rotatable)


Note there are more advanced definitions of such bonds, above example is
taken from RDKit's Lipinski module.


Pozdrawiam,  |  Best regards,
Maciek Wójcikowski
mac...@wojcikowski.pl

2018-03-09 13:56 GMT+01:00 Mariana Assmann :

> Hi everyone,
>
> is it possible to check for a single bond if it is rotatable? I only found
> a function to calculate the total number of rotatable bonds in the
> molecule, but nothing specific to a selected bond.
>
> Best regards,
> Mariana
>
> 
> --
> 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


Re: [Rdkit-discuss] useQueryQueryMatches with recursive SMARTS

2018-03-09 Thread Ivan Tubert-Brohman
Hi Greg,

Thank you. After more thought I decided that query-to-query matching is not
the best way to go for my task, regardless of what it does with recursive
SMARTS, so don't lose sleep about it on my behalf. :-) Still, it's good to
know about this behavior for future reference.

Best,
Ivan


On Fri, Mar 9, 2018 at 12:13 AM, Greg Landrum 
wrote:

> Hi Ivan,
>
> On Wed, Mar 7, 2018 at 8:58 PM, Ivan Tubert-Brohman  schrodinger.com> wrote:
>
>>
>> Is it reasonable to expect that a SMARTS should match itself when
>> useQueryQueryMatches=True?
>>
>
> Not my favorite kind of answer to give, but... "it depends"
>
>
>>   query = Chem.MolFromSmarts('[C;!$(C=O)]Cl')
>>   query.HasSubstructMatch(query, useQueryQueryMatches=True)
>>
>> The above returns False. Without useQueryQueryMatches, it returns True,
>> but I think I need useQueryQueryMatches for my application because
>> queries are not generally valid molecules, and in some cases
>> HasSubstructMatch ends up raising exceptions (for example when the
>> SMARTS specifies hydrogen counts).
>>
>> If I remove the recursive part of the SMARTS above, I get a match, so I
>> suspect that the query-query search doesn't play well with recursive SMARTS.
>>
>
> That is the expected, though not particularly nice, behavior. The code is
> currently quite conservative about when it says that two queries match each
> other: if it sees a recursive query it just says "no".
> There may be a straightforward fix for this, but in general making the
> query-query matcher more flexible is one of those "it would be so cool, but
> it's s much work" projects, so I'm not going to make any promises.
>
> Best,
> -greg
>
>
>
>
>> Best,
>> Ivan
>>
>> 
>> --
>> 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