Re: [Rdkit-discuss] High-quality matplotlib drawing?

2019-08-07 Thread Greg Landrum
That's an interesting question. I think there probably are some ways of
tweaking this and improving things, but I don't have a convenient way to
test. If you can share the python (+data) you used to construct that PDF I
will see if I can come up with a solution.

-greg


On Thu, Aug 8, 2019 at 2:23 AM Wout Bittremieux 
wrote:

> Dear RDKit team,
>
> I'm trying to draw a molecule on a spectrum plot from Matplotlib using
> MolToImage. This is some abbreviated code:
>
> ```
> import matplotlib.pyplot as plt
> from rdkit import Chem
> from rdkit.Chem import Draw
>
> fig, ax = plt.subplots()
>
> ax.plot(...)
>
> im = Draw.MolToImage(Chem.MolFromSmiles(smiles))
> ax.imshow(im, aspect='auto', extent=(x, x+width, y, y + height))
>
> plt.savefig('fig.pdf')
> plt.close()
> ```
>
> Unfortunately the quality of the molecule drawing is rather poor (see
> attachment; nonsensical spectrum and molecule). This seems to be true
> for non-SVG drawing in general, and unfortunately it's not really
> possible to combine SVG output with Matplotlib functionality.
>
> Is there any way I can improve the quality of the MolToImage output?
> I've tried to change some of the DrawingOptions, but the result always
> remains very pixelated and low quality.
>
> Thank you,
> Wout
> ___
> 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] High-quality matplotlib drawing?

2019-08-07 Thread Wout Bittremieux

Dear RDKit team,

I'm trying to draw a molecule on a spectrum plot from Matplotlib using 
MolToImage. This is some abbreviated code:


```
import matplotlib.pyplot as plt
from rdkit import Chem
from rdkit.Chem import Draw

fig, ax = plt.subplots()

ax.plot(...)

im = Draw.MolToImage(Chem.MolFromSmiles(smiles))
ax.imshow(im, aspect='auto', extent=(x, x+width, y, y + height))

plt.savefig('fig.pdf')
plt.close()
```

Unfortunately the quality of the molecule drawing is rather poor (see 
attachment; nonsensical spectrum and molecule). This seems to be true 
for non-SVG drawing in general, and unfortunately it's not really 
possible to combine SVG output with Matplotlib functionality.


Is there any way I can improve the quality of the MolToImage output? 
I've tried to change some of the DrawingOptions, but the result always 
remains very pixelated and low quality.


Thank you,
Wout


fig.pdf
Description: Adobe PDF document
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] GetSubstructMatches() as smiles

2019-08-07 Thread Andrew Dalke
On Aug 7, 2019, at 13:08, Paolo Tosco  wrote:
> You can use
> 
> Chem.MolFragmentToSmiles(mol, match)
> 
> where match is a tuple of atom indices returned by GetSubstructMatch().

Note however that if only the atom indices are given then 
Chem.MolFragmentToSmiles() will include all bonds which connect those atoms, 
even if the original SMARTS does not match those bonds. For example:

>>> from rdkit import Chem
>>> pat = Chem.MolFromSmarts("*~*~*~*") # match 4 linear atoms
>>> mol = Chem.MolFromSmiles("C1CCC1") # ring of size 4
>>> atom_indices = mol.GetSubstructMatch(pat)
>>> atom_indices
(0, 1, 2, 3)
>>> Chem.MolFragmentToSmiles(mol, atom_indices)  # returns the ring
'C1CCC1'


If this is important, then you need to pass the correct bond indices to 
MolFragmentToSmiles(). This can be done by using the bonds in the query graph 
to get the bond indices in the molecule graph. I believe the following is 
correct:

def get_match_bond_indices(query, mol, match_atom_indices):
bond_indices = []
for query_bond in query.GetBonds():
atom_index1 = match_atom_indices[query_bond.GetBeginAtomIdx()]
atom_index2 = match_atom_indices[query_bond.GetEndAtomIdx()]
bond_indices.append(mol.GetBondBetweenAtoms(
 atom_index1, atom_index2).GetIdx())
return bond_indices

(Does a function like this already exist in RDKit?)

I'll use it to get the bond indices for the *~*~*~* match:

>>> bond_indices = get_match_bond_indices(pat, mol, atom_indices)
>>> bond_indices
[0, 1, 2]

Passing the atom and bond indices gives the expected match SMILES: 

>>> Chem.MolFragmentToSmiles(mol, atom_indices, bond_indices)
''

Cheers,

Andrew
da...@dalkescientific.com




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


Re: [Rdkit-discuss] GetSubstructMatches() as smiles

2019-08-07 Thread Paolo Tosco
Hi Mel,

You can use

Chem.MolFragmentToSmiles(mol, match)

where match is a tuple of atom indices returned by GetSubstructMatch().

Cheers,
p.

> On 7 Aug 2019, at 11:36, Melissa Adasme  wrote:
> 
> Dear rdkitters,
> 
> I'm trying to find substructures (query molecules built from SMARTS) matching 
> my molecules (SMILES). I found the GetSubstructMatches() method which works 
> pretty well returning the indices of matching atoms in my molecule. 
> 
> I wonder if there is a way to directly obtain the SMILES of the found 
> substructures instead of the atom indexes or maybe a way to transform the 
> indexes to smiles?
> 
> Many thanks in advance!
> Mel
> 
> ___
> 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] GetSubstructMatches() as smiles

2019-08-07 Thread Melissa Adasme
Dear rdkitters,

I'm trying to find substructures (query molecules built from SMARTS)
matching my molecules (SMILES). I found the GetSubstructMatches() method
which works pretty well returning the indices of matching atoms in my
molecule.

I wonder if there is a way to directly obtain the SMILES of the found
substructures instead of the atom indexes or maybe a way to transform the
indexes to smiles?

Many thanks in advance!
Mel
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss