Re: [Rdkit-discuss] Display Molecules within IPython Console

2020-09-01 Thread Scalfani, Vincent
Hi Greg,

Draw.ShowMol(m) works perfectly and even works in a loop to view multiple 
molecules (one at a time). thanks!

Hi Ivan, thanks for the terminal graphics code example. I think the ASCII art 
structures are fun and useful. I've used that in Open Babel before to quickly 
view molecules. Such an ASCII structure view method in RDKit would be great and 
I would be interested in trying it.

Vin


From: Ivan Tubert-Brohman 
Sent: Tuesday, September 1, 2020 9:29 AM
To: Scalfani, Vincent 
Cc: rdkit-discuss@lists.sourceforge.net 
Subject: [EXTERNAL] Re: [Rdkit-discuss] Display Molecules within IPython Console

Hi Vin,

If you are running the IPython console on a terminal emulator that supports 
graphics, you could display the molecule by printing out the necessary terminal 
escape codes followed by the image buffer. The solution is terminal-specific; 
here's an example that works using the Kitty terminal:

from base64 import standard_b64encode
import io

def serialize_gr_command(cmd, payload=None):
   cmd = ','.join('{}={}'.format(k, v) for k, v in cmd.items())
   ans = []
   w = ans.append
   w(b'\033_G'), w(cmd.encode('ascii'))
   if payload:
  w(b';')
  w(payload)
   w(b'\033\\')
   return b''.join(ans)

def write_chunked(cmd, data):
   data = standard_b64encode(data)
   while data:
  chunk, data = data[:4096], data[4096:]
  m = 1 if data else 0
  cmd['m'] = m
  sys.stdout.buffer.write(serialize_gr_command(cmd, chunk))
  sys.stdout.flush()
  cmd.clear()

def cat_mol(mol):
img = Chem.Draw.MolToImage(mol)
buf = io.BytesIO()
img.save(buf, format='png')
write_chunked({'a': 'T', 'f': 100}, buf.getvalue())

And then you can do something like this:
[image.png]

I'm sure the above could be adapted to work with iterm2 or other terminals that 
support graphics, but that's left as an exercise to the reader.

An alternative I often use when graphics are not available is to render the 
structure as ASCII art, but that may be an acquired taste. The above would look 
like this:

[image.png]

I'll leave the code that does that for some other day.

Best,
Ivan

On Tue, Sep 1, 2020 at 9:57 AM Scalfani, Vincent 
mailto:vfscalf...@ua.edu>> wrote:
Hello,

Is it possible to display a molecule image directly in an IPython console (not 
a Jupyter Notebook)? Or maybe I need to send the image file directly to my 
image viewer? I would like to be able to quickly view the molecules without 
using a Jupyter Notebook or having to save the PNGs. For example:

In [6]: from rdkit import Chem
   ...: from rdkit.Chem.Draw import IPythonConsole
   ...: from rdkit.Chem import Draw

In [7]: m = Chem.MolFromSmiles('c1ncncc1C(=O)[O-]')

In [8]: m
Out[8]: 

In [9]: Chem.Draw.MolToImage(m)
Out[9]: 


Thanks for your help.

Vin


---

Vincent F. Scalfani

The University of Alabama

<mailto:vfscalf...@ua.edu>


___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net<mailto:Rdkit-discuss@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


[Rdkit-discuss] Display Molecules within IPython Console

2020-09-01 Thread Scalfani, Vincent
Hello,

Is it possible to display a molecule image directly in an IPython console (not 
a Jupyter Notebook)? Or maybe I need to send the image file directly to my 
image viewer? I would like to be able to quickly view the molecules without 
using a Jupyter Notebook or having to save the PNGs. For example:

In [6]: from rdkit import Chem
   ...: from rdkit.Chem.Draw import IPythonConsole
   ...: from rdkit.Chem import Draw

In [7]: m = Chem.MolFromSmiles('c1ncncc1C(=O)[O-]')

In [8]: m
Out[8]: 

In [9]: Chem.Draw.MolToImage(m)
Out[9]: 


Thanks for your help.

Vin


---

Vincent F. Scalfani

The University of Alabama



___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] RDKit installation problem

2020-08-03 Thread Scalfani, Vincent
Hi Sebastian,

As far as I can tell, the latest version available in conda is 2020.03.3. As 
Dave mentioned, I was able to get this version by specifying python 3.7:

More information on this method here:

http://rdkit.blogspot.com/2019/10/sharing-conda-environments.html

You can also specify the rdkit version instead:

https://github.com/rdkit/conda-rdkit/issues/84

Vin




From: Francois Berenger 
Sent: Sunday, August 2, 2020 8:32 PM
To: Sebastián J. Castro 
Cc: rdkit-discuss@lists.sourceforge.net 
Subject: Re: [Rdkit-discuss] RDKit installation problem

Dear Sebastian,

Since last week, you should also be able to install rdkit on Linux
via linuxbrew:

---
sudo apt install linuxbrew-wrapper
brew tap rdkit/rdkit
brew update
brew install rdkit

# to test it
/home/linuxbrew/.linuxbrew/bin/python3
import rdkit
---

Thanks to Nuri Jung on github (@jnooree) for proposing a fix
to the brew rdkit install formula.

Regards,
F.

On 02/08/2020 03:03, Sebastián J. Castro wrote:
> I have try the installation suggested at
> http://www.rdkit.org/docs/Install.html:
>
> $ conda create -c rdkit -n my-rdkit-env rdkit
>
> But I get 2017 version instead of 2020 (last released).
>
> I don't know how to install it. Can you help me?
>
> I have Ubuntu 20.04 LTS
>
> Thank you
>
> Best regards!
>
> --
>
> Dr. Sebastián J. Castro
> Departamento de Ciencias Farmacéuticas
> Facultad de Ciencias Químicas
> Universidad Nacional de Córdoba
> UNITEFA-CONICET
> ___
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


[Rdkit-discuss] RDKit Application for Google Season of the Docs

2020-04-23 Thread Scalfani, Vincent
Dear RDKit Community,


Greg and I are putting together an application for the Google Season of the 
Docs program:


https://developers.google.com/season-of-docs


The program connects open source organizations with technical writers. A 
technical writer would work with several RDKit community mentors to advance the 
documentation over a 3 month period (starting in August).


We have a few project ideas already including expansion of the RDKit Book to 
include additional undocumented methods, creating a beginner friendly guide to 
making the most of the Python API Docs, and creating an official RDKit with 
Pandas Book. Detailed project descriptions will be available on the RDKit blog 
soon, and I'm also happy to share directly with you.


We are seeking mentors to help us advance the RDKit documentation and 
participate in Google Season of the Docs. Here are the mentor responsibilities:


https://developers.google.com/season-of-docs/docs/admin-mentor-responsibilities


We'll need to submit our application by May 4, so please do get in touch if you 
are interested.


Thanks,


Vin Scalfani




___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] Count rings in bicyclic compounds

2020-03-17 Thread Scalfani, Vincent
Hello Ivan and all,


I found this old thread about counting rings in bicyclics and I would like to 
add it to the RDKit Cookbook, however, I'm not able to get the fuse function to 
work. I get a 'Mol object is not iterable' error.


Any help appreciated. Thanks.


Vin


From: Ivan Tubert-Brohman 
Sent: Wednesday, December 5, 2018 9:06 AM
To: baptiste.cana...@gmail.com
Cc: RDKit Discuss
Subject: Re: [Rdkit-discuss] Count rings in bicyclic compounds

Hi Baptiste,

RDKit focuses on "simple rings". As far as I know, it has no builtin function 
to return all possible cycles in a molecule.

For a molecule with a "basis set" of N rings, there can be up to 2^N-1 ring 
systems, which can be obtained by taking all possible subsets (aka the 
powerset) of rings and fusing them. Below is an implementation based on fusing 
simple rings. Another possibility would be to write an exhaustive ring search 
(DFS or BFS) of the molecular graph and report all cycles that are found, 
instead of only the simple ones.

Warning: do not run this code on fullerenes or similar molecules unless you are 
prepared to wait for a long, long time!

def all_bond_rings(mol):
"""
Generate all ring systems for a molecule. A Ring is a set of bond indexes.

:type mol: rdkit.Chem.Mol
:rtype: set of int
"""
ring_info = mol.GetRingInfo()
rings = [set(r) for r in ring_info.BondRings()]

# Truncate nrings to the basis set size because RDKit returns redundant
# rings (e.g., 6 instead of 5 for cubane).
nfrags = len(Chem.GetMolFrags(mol))
nrings = mol.GetNumBonds() - mol.GetNumAtoms() + nfrags
del rings[nrings:]

for i in range(1, len(rings)+1):
for comb in itertools.combinations(rings, i):
fused = fuse(comb)
if fused:
yield fused

def fuse(rings):
"""
Return the ring system that results from fusing the given rings, if the
rings are fusable into a single ring system; otherwise None.

:type rings: list of set of int
:rtype: set of in
"""
pending = list(rings)
fused = set(pending.pop())
while pending:
for i in range(len(pending)):
ring = pending[i]
if fused & ring: # rings are fused
fused ^= ring
del pending[i]
break
else:
# None of the pending rings were fusable!
return None
return fused

Hope this helps,
Ivan



On Wed, Dec 5, 2018 at 5:54 AM Baptiste CANAULT 
mailto:baptiste.cana...@gmail.com>> wrote:
Hi RDKiters,

I would like to identify all cycles present in a molecular structure. However, 
when the molecules correspond to bicyclic compounds, the ring count does not 
correspond to the number actually observed in the structure. Simple example:

>>> m = Chem.MolFromSmiles('C1CC2CCC1O2')
>>> r = m.GetRingInfo()
>>> r.NumRings()
2

In reality, this molecular structure has 3 cycles with the cyclohexan. Am I 
completely wrong and is there a trick to identify all the cycles present in a 
structure?

Thanks in advance,

Best regards,

Baptiste
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] Inchi which flavour??

2019-10-09 Thread Scalfani, Vincent
Hi Macjek and Mike,

If I understand your question correctly, you can specify InChI option 
parameters when calculating InChIs. Here is an example:

m = Chem.MolFromSmiles('CCC1=CN=C(NC1=O)NC')
Chem.MolToInchi(m)
'InChI=1S/C7H11N3O/c1-3-5-4-9-7(8-2)10-6(5)11/h4H,3H2,1-2H3,(H2,8,9,10,11)'

Now, try with one of the non-standard options such as FixedH:

Chem.MolToInchi(m,'/FixedH')
'InChI=1/C7H11N3O/c1-3-5-4-9-7(8-2)10-6(5)11/h4H,3H2,1-2H3,(H2,8,9,10,11)/f/h8,10H'

To answer the question of what happens when the InChI calculation fails, I get 
an empty string.

m = 
Chem.MolFromSmiles('[C@H]1([C@H](C1C2[C@@H]([C@@H]2C(=O)O)C(=O)O)C(=O)O)C(=O)O')
Chem.MolToInchi(m)
'  '

There is also an InChI option that can warn on empty structures, and calculate 
an empty InChI, which I am assuming is supposed to be ‘InChI=1S//’, however, 
when trying this option I get the same result as above.

Chem.MolToInchi(m,'/WarnOnEmptyStructure')
'  '

I hope that helps.

Vin

From: Maciek Wójcikowski 
Sent: Wednesday, October 9, 2019 3:41 AM
To: Greg Landrum 
Cc: RDKit Discuss 
Subject: Re: [Rdkit-discuss] Inchi which flavour??

Mike,

On top of what Greg said what might be particularly useful is an options 
parameter where you can pass some non default params to InChI call.

śr., 9 paź 2019, 07:22 użytkownik Greg Landrum 
mailto:greg.land...@gmail.com>> napisał:
Hi Mike,

The InChI API itself is not exposed. The contents of the module are in the 
documentation along with some explanations of how to call it:
http://rdkit.org/docs/source/rdkit.Chem.rdinchi.html

If something is missing there, please let us know.
-greg


On Tue, Oct 8, 2019 at 5:20 PM 
mailto:mi...@novadatasolutions.co.uk>> wrote:
Dear RdKit users,
I was reading the inchi module docs and I couldn't find methods to call the 
InChI API.  Are these exposed in RDKit?
It says the default is the standard Inchi.  What happens when this conversion 
fails?

Thanks,
Mike
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] Problems with SMILES using MolFromSmiles

2019-09-24 Thread Scalfani, Vincent
Dear Navid,

RDKit rejects tetravalent Nitrogen by default. This thread below may help. It 
shows how to load the SMILES with sanitization off, then perform a partial 
sanitization.

https://sourceforge.net/p/rdkit/mailman/message/32589379/

Vin



From: Navid Shervani-Tabar 
Sent: Tuesday, September 24, 2019 6:55 PM
To: RDKit Discuss 
Subject: [Rdkit-discuss] Problems with SMILES using MolFromSmiles

Hello,

I have noticed that RDKit have some problems with some SMILES when trying to 
use MolFromSmiles. With further attention, I have noticed that all of these 
SMILES include nitrogen atoms. Some examples include:

[NH3]CCC(=O)[O]
NC(=[NH2])C(=O)[O]
NC(=[NH2])[CH2].C(=O)=O
CNC(=[NH2])C(=O)[O]
CNC(=[NH2])C(=O)[O]
C[C@@H](C[NH3])C(=O)[O]

I was wondering if there is a way to fix this issue and study those molecules. 
Thanks!

Best,
Navid
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] RDkit and Pubchem

2017-12-01 Thread Scalfani, Vincent
Hi Jubi,

If you need the entire dataset and are not creating queries via the API, you 
can download all PubChem Data via ftp here:

ftp://ftp.ncbi.nlm.nih.gov/pubchem/

Then download the SDFs, and extract out SMILES (I’ve used regular expressions 
that match the appropriate data tag with good success).

Vin
University of Alabama






From: Jason Biggs [mailto:jasondbi...@gmail.com]
Sent: Friday, December 1, 2017 1:12 PM
To: Sundar 
Cc: RDKit Discuss 
Subject: Re: [Rdkit-discuss] RDkit and Pubchem

Pubchem has an easy to use rest API, described here: 
https://pubchemdocs.ncbi.nlm.nih.gov/pug-rest

If you have a compound ID, you can query properties via something

https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/2244/property/CanonicalSMILES,IsomericSMILES,InChI/JSON

It comes back in JSON format, but you can have it return XML or plain text.

If you want an SDF file, something like
https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/2244/SDF?record_type=3d

setting up a python function to query this shouldn't be difficult.

Jason Biggs

On Fri, Dec 1, 2017 at 12:51 PM, Sundar 
> wrote:
I would like to download at least SMILES (great if I can also download mol 
files).
And the same is true for Pubchem Compound ID or using Substance ID.
Or even download the whole data set using an assay id. Anything could help.
Thanks,
Jubi

On Fri, Dec 1, 2017 at 11:55 AM, Tim Dudgeon 
> wrote:

In what way? Given a single PubChem compound or substance ID you just want to 
pull the smiles or molfile into RDKit?

Tim
On 01/12/17 17:26, Sundar wrote:
Hi RDkit users,
I was wondering if RDkit has a means of downloading compounds from Pubchem.
Also let me other ways that helps here.
Thanks,
Jubi


--

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

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