Re: [Rdkit-discuss] MolToImage size - bigger canvas, compound stays the same
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
|
From: Michał N. <mm...@gm...> - 2013-07-25 10:51:47
|
I've looked into the code and have some questions:
1. Why not to change MolDrawing constructor to something like:
def __init__(self,canvas=None):
self.canvas = canvas
if canvas:
self.canvasSize=canvas.size
if self.canvasSize:
self.dotsPerAngstrom = int(max(self.canvasSize) / 10)
self.atomPs = {}
self.boundingBoxes = {}
2. Why not to add MolDrawing as optional argument for methods like
MolToImage so then I can set my own values of 'dotsPerAngstrom',
'useFraction', 'colorBonds' etc.
3. Even better - why not to extract drawing parameters like
'dotsPerAngstrom', 'useFraction', 'colorBonds' etc. from MolDrawing to some
dict-like class (lets name it 'DrawingOptions') and add this class as an
optional parameter to MolDrawing constructor and all methods that construct
MolDrawing (MolToImage etc.)
Without those changes customization of compound drawing is very limited.
On Thu, Jul 25, 2013 at 11:10 AM, Michał Nowotka <mm...@gm...> wrote:
> My mistake again. There is nothing like 'dotsPerAngstrom' in
> RDKit_2012_09_1. At least Draw, module doesn't have it. Also, Draw module
> doesn't contain 'MolDrawing' module...
>
>
> On Thu, Jul 25, 2013 at 11:06 AM, Michał Nowotka <mm...@gm...> wrote:
>
>> OK, i've found 'dotsPerAngstrom' in Draw.
>> Unfortunately setting it to any higher value (tried 60, 160, 660, 1000)
>> doesn't change anything...
>>
>>
>> On Thu, Jul 25, 2013 at 11:03 AM, Michał Nowotka <mm...@gm...>wrote:
>>
>>> I'm getting:
>>>
>>> Draw.MolDrawing.dotsPerAngstrom=60
>>> AttributeError: 'module' object has no attribute 'MolDrawing'
>>>
>>> I'm using RDKit_2012_09_1
>>>
>>>
>>>
>>> On Thu, Jul 25, 2013 at 10:56 AM, Greg Landrum <gre...@gm...>wrote:
>>>
>>>>
>>>> On Thu, Jul 25, 2013 at 5:36 AM, Michał Nowotka <mm...@gm...>wrote:
>>>>
>>>>> When I do this:
>>>>>
>>>>> image = Draw.MolToImage(mol, size=(200, 200))
>>>>>
>>>>> I'm getting image with compound taking most of available canvas space.
>>>>> But this:
>>>>>
>>>>> image = Draw.MolToImage(mol, size=(500, 500))
>>>>>
>>>>> gives me an image with the compound of exact same size - it's just the
>>>>> canvas which is bigger. I guess this is because molfile already contains
>>>>> fixed 2D coordinates. Is there any possibility to regenerate it taking into
>>>>> account current image size?
>>>>>
>>>>
>>>> It's not the molfile.
>>>>
>>>> The class rdkit.Chem.Draw.MolDrawing.MolDrawing has a data member
>>>> called dotsPerAngstrom that is used as the "desired" number of pixels per
>>>> Angstrom in the drawing. This number is automatically reduced when a big
>>>> molecule is drawn onto a small canvas, but it is never increased in the
>>>> drawing code (by design).
>>>>
>>>> You can, however, change it on your own;
>>>> In [2]: from rdkit.Chem import Draw
>>>>
>>>> In [3]: Draw.MolDrawing.dotsPerAngstrom=60
>>>>
>>>> In [4]:
>>>> Draw.MolToImageFile(Chem.MolFromSmiles('c1ccccn1'),'blah.png',size=(500,500))
>>>>
>>>> Note: the dotsPerAngstrom value will still be reduced automatically
>>>> when rendering a large molecule.
>>>>
>>>> Hope this helps,
>>>> -greg
>>>>
>>>>
>>>
>>
>
|