Just wanted to chime in that I'm also excited by this functionality!

an alternative to the SVG classes would be to nest atoms and bonds in svg
groups;

<g id='bond-0'>
    <path d='M 13.6364,129.156 21.7657,139.549'
style='fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1'
/>
    <path d='M 21.7657,139.549 29.895,149.943'
style='fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1'
/>
</g>

You could also put the atoms and bonds in their own groups if it was easy:

<g class='bonds'>
    <g id='bond-0'>...</g>
    <g id='bond-1'>...</g>
</g>
<g class='atoms' visibility='hidden'>
     <circle cx='13.6364' cy='129.156' r='4.46307' id='atom-0'
style='fill:#fff;stroke:#fff;stroke-width:1px;fill-opacity:0;stroke-opacity:0'/>
    ...
</g>

That being said, I'm not sure that does much more for someone writing in
d3.js functionality that you couldn't do with the existing code. So if
trying to do that messes up the rest of the drawing code ignore the comment
:)


Thanks for the work on this!
-- Peter


On Tue, Feb 5, 2019 at 7:46 AM Greg Landrum <greg.land...@gmail.com> wrote:

> Sure. I don't have my Mac with me, so that'll need to wait until I'm back
> in Basel on the weekend.
>
> -greg
>
>
>
> On Tue, Feb 5, 2019 at 2:39 PM Lukas Pravda <lpra...@ebi.ac.uk> wrote:
>
>> If it is not too much trouble to ask, please build it for mac os
>> (10.14.3) python 3.6.x.
>>
>>
>>
>> Thanks!
>>
>> Lukas
>>
>>
>>
>> *From: *Greg Landrum <greg.land...@gmail.com>
>> *Date: *Tuesday, 5 February 2019 at 13:40
>> *To: *Lukas Pravda <lpra...@ebi.ac.uk>
>> *Cc: *RDKIT mailing list <rdkit-discuss@lists.sourceforge.net>
>> *Subject: *Re: [Rdkit-discuss] Bond tags in SVGs
>>
>>
>>
>>
>>
>>
>>
>> On Tue, Feb 5, 2019 at 12:23 PM Lukas Pravda <lpra...@ebi.ac.uk> wrote:
>>
>>
>>
>> Thanks for this. It looks excellent!! Is there a way how I can test this?
>> Other than cloning and compiling the repository? So far I have been using
>> rdkit solely from python and its conda builds, so don’t really know how to
>> test it.
>>
>>
>>
>> At the moment you would need to get a copy of the repo and build it. I
>> can do a build so that it's conda-installable though. Which OS are you
>> using?
>>
>>
>>
>> If I understand this correctly, the atom and bond class ids are added
>> only after TagAtoms() is called, or are they added at the ‘DrawMolecule()’
>> stage?
>>
>>
>>
>> Bond classes are added as the bonds are written. Atom classes can only be
>> added at the TagAtoms() stage - there's not an object in the SVG for many
>> atoms without TagAtoms() being called.
>>
>>
>>
>> I can imagine a lot of possible scenarios and use cases with this new
>> functionality. However, in order to make the function TagAtoms()
>> sufficiently general, a bit more control over the javascript used in the
>> events would be needed. As a possible suggestions, I can imagine to pass as
>> the third parameter a lambda selector, which would in turn feed the JS
>> function with parameters to display names/charges/whatever. Also it would
>> be nice to have a mean how to pass dict of key-val properties for both
>> atoms and bonds so that you can incorporate related data into the svg.
>>
>>
>>
>> Having said that, in my opinion if svgs end up as a part of
>> html/javascript application, it is the best to expose this interactivity
>> directly from the client, rather than ‘pre-generating’ the behaviour on the
>> server. So I’m not sure If it is worth investing time into mimicking this
>> functionality in C++/python code, Whoever is in a need of generating
>> interactive svgs, can directly consume the svg string and modify it
>> according to their needs.
>>
>>
>>
>> Yeah, that's more or less what I was thinking. We want to write something
>> that can be reasonably easily modified after the fact to produce something
>> useful.
>>
>>
>>
>>
>>
>> To sum up, I think it should enough just to tag positions and identifiers
>> of atoms/bonds exactly as you do and possibly further extend them with a
>> mean how to pass some extra data to all of it. Then users can modify svgs
>> whichever way they want, but others might think differently.
>>
>>
>>
>> Excellent!
>>
>>
>>
>> -greg
>>
>>
>>
>>
>>
>> Best,
>>
>> Lukas
>>
>> *From: *Greg Landrum <greg.land...@gmail.com>
>> *Date: *Sunday, 3 February 2019 at 17:49
>> *To: *Lukas Pravda <lpra...@ebi.ac.uk>
>> *Cc: *RDKIT mailing list <rdkit-discuss@lists.sourceforge.net>
>> *Subject: *Re: [Rdkit-discuss] Bond tags in SVGs
>>
>>
>>
>> Hi Lukas,
>>
>>
>>
>> I had a chance to do a bit of work on this recently and I'd be interested
>> to hear your feedback.
>>
>>
>>
>> Bonds are now tagged with their bond IDs (using classes) and the
>> "TagAtoms()" function now adds clickable transparent circles above each
>> atom. These are also tagged with atom IDs using classes. TagAtoms() also
>> lets you add callback functions for events associated with the atom
>> circles. At the moment these are simply called with the atom id, but
>> there's almost certainly a better way to do that. Suggestions are very
>> welcome.
>>
>>
>>
>> Here's a gist showing what's currently on the branch:
>> https://gist.github.com/greglandrum/d23517cb449003252cf09b5bd14d8637
>>
>>
>>
>>
>>
>> On Tue, Dec 4, 2018 at 6:46 PM Lukas Pravda <lpra...@ebi.ac.uk> wrote:
>>
>> Hi Greg,
>>
>>
>>
>> that’s what I have been thinking, unlucky. Essentially, I want to color
>> the molecule in web-browser with various annotations and make it
>> interactive. For that part I’m converting it internally to the d3.js
>> internal representation (https://d3js.org/) and connecting it to its
>> environment. For most of the parts I’m just fine with the position of atoms
>> in svg using the tag property.
>>
>>
>>
>> What I wanted to avoid is to replicate rdkit svg drawing code in
>> javascript so that I don’t want to consume the dump of rdkit.Mol object.
>> What I wanted to do instead is to use existing svg images and parse them
>> into d3.js, so I know which paths belong to which bond.
>>
>>
>>
>> At this point my only idea is to color bonds individually and based on
>> the overlay/proximity use kd-tree to reverse-engineer which bonds the paths
>> belong to, which is a bit overkill in my view.
>>
>>
>>
>> Lukas
>>
>>
>>
>>
>>
>> *From: *Greg Landrum <greg.land...@gmail.com>
>> *Date: *Tuesday, 4 December 2018 at 17:24
>> *To: *Lukas Pravda <lpra...@ebi.ac.uk>
>> *Cc: *RDKIT mailing list <rdkit-discuss@lists.sourceforge.net>
>> *Subject: *Re: [Rdkit-discuss] Bond tags in SVGs
>>
>>
>>
>> Hi Lukas,
>>
>>
>>
>> There's not currently a way to do this at the moment. The closest you can
>> get is by calling AddMoleculeMetadata():
>>
>>
>>
>> In [6]: d = Draw.MolDraw2DSVG(200,200)
>>
>>
>>
>> In [8]: d.DrawMolecule(nm)
>>
>>
>>
>> In [10]: d.AddMoleculeMetadata(nm)
>>
>>
>>
>> In [11]: d.FinishDrawing()
>>
>>
>>
>> In [12]: svg = d.GetDrawingText()
>>
>>
>>
>> In [14]: print(svg)
>>
>> <?xml version='1.0' encoding='iso-8859-1'?>
>>
>> <svg version='1.1' baseProfile='full'
>>
>>               xmlns='http://www.w3.org/2000/svg'
>>
>>                       xmlns:rdkit='http://www.rdkit.org/xml'
>>
>>                       xmlns:xlink='http://www.w3.org/1999/xlink'
>>
>>                   xml:space='preserve'
>>
>> width='200px' height='200px' >
>>
>> <rect style='opacity:1.0;fill:#FFFFFF;stroke:none' width='200'
>> height='200' x='0' y='0'> </rect>
>>
>> <path d='M 9.09091,126.243 100,73.7568'
>> style='fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoi
>>
>> n:miter;stroke-opacity:1' />
>>
>> <path d='M 100,73.7568 190.909,126.243'
>> style='fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoi
>>
>> n:miter;stroke-opacity:1' />
>>
>> <metadata>
>>
>> <rdkit:mol xmlns:rdkit = "http://www.rdkit.org/xml"; version="0.9">
>>
>> <rdkit:atom idx="1" atom-smiles="[CH3]" drawing-x="9.09091"
>> drawing-y="126.243" x="-1.29904" y="-0.25" z="0" />
>>
>> <rdkit:atom idx="2" atom-smiles="[CH2]" drawing-x="100"
>> drawing-y="73.7568" x="0" y="0.5" z="0" />
>>
>> <rdkit:atom idx="3" atom-smiles="[CH3]" drawing-x="190.909"
>> drawing-y="126.243" x="1.29904" y="-0.25" z="0" />
>>
>> <rdkit:bond idx="1" begin-atom-idx="1" end-atom-idx="2" bond-smiles="-" />
>>
>> <rdkit:bond idx="2" begin-atom-idx="2" end-atom-idx="3" bond-smiles="-" />
>>
>> </rdkit:mol></metadata>
>>
>> </svg>
>>
>>
>>
>> This gets you the information you need to connect bond indices to the
>> atoms, but I suspect that's not what you're looking for.
>>
>>
>>
>> In general you are guaranteed that the order of the bonds in the output
>> SVG is the same as the order in the input molecule, but you can have
>> multiple paths for a given bond. For example here, where the end atoms have
>> different colors:
>>
>>
>>
>> In [25]: print(svg)
>>
>> <?xml version='1.0' encoding='iso-8859-1'?>
>>
>> <svg version='1.1' baseProfile='full'
>>
>>               xmlns='http://www.w3.org/2000/svg'
>>
>>                       xmlns:rdkit='http://www.rdkit.org/xml'
>>
>>                       xmlns:xlink='http://www.w3.org/1999/xlink'
>>
>>                   xml:space='preserve'
>>
>> width='200px' height='200px' >
>>
>> <rect style='opacity:1.0;fill:#FFFFFF;stroke:none' width='200'
>> height='200' x='0' y='0'> </rect>
>>
>> <path d='M 9.09091,100 59.1479,100'
>> style='fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:mi
>>
>> ter;stroke-opacity:1' />
>>
>> <path d='M 59.1479,100 109.205,100'
>> style='fill:none;fill-rule:evenodd;stroke:#FF0000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:mi
>>
>> ter;stroke-opacity:1' />
>>
>> <text x='109.205' y='107.5'
>> style='font-size:15px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text
>>
>> -anchor:start;fill:#FF0000' ><tspan>OH</tspan></text>
>>
>> <metadata>
>>
>> <rdkit:mol xmlns:rdkit = "http://www.rdkit.org/xml"; version="0.9">
>>
>> <rdkit:atom idx="1" atom-smiles="[CH3]" drawing-x="9.09091"
>> drawing-y="100" x="-0.75" y="5.55112e-17" z="0" />
>>
>> <rdkit:atom idx="2" atom-smiles="[OH]" drawing-x="122.71" drawing-y="100"
>> x="0.75" y="-5.55112e-17" z="0" />
>>
>> <rdkit:bond idx="1" begin-atom-idx="1" end-atom-idx="2" bond-smiles="-" />
>>
>> </rdkit:mol></metadata>
>>
>> </svg>
>>
>>
>>
>> What are you looking to be able to do? That may make it easier to either
>> come up with a work around or figure out what a new feature addition might
>> look like.
>>
>>
>>
>> -greg
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Mon, Dec 3, 2018 at 6:57 PM Lukas Pravda <lpra...@ebi.ac.uk> wrote:
>>
>> Hi all,
>>
>>
>>
>> I was wondering if there is a way how you can tag <path> elements (bonds)
>> in the svg created by rdkit.
>>
>>
>>
>> i.e. transform something like this:
>>
>> <path d='M 265.658,263.25 342.74,218.746' style='...' />
>>
>> <path d='M 342.74,218.746 419.822,174.241' style='...' />
>>
>>
>>
>> Into:
>>
>> <path bondId='1' d='M 265.658,263.25 342.74,218.746' style='...' />
>>
>> <path bondId='2' d='M 342.74,218.746 419.822,174.241' style='...' />
>>
>>
>>
>> Or similar. I’ve found possibility of tagging atoms in the SVG using
>> Draw.rdMolDraw2D.MolDraw2DSVG.drawOptions() method that exposes property
>> includeAtomTags. This then renders following additional elements into the
>> SVG:
>>
>> rdkit:atom idx="4" label="O<sup>-</sup>" x="153.479" y="82.8259" />
>>
>>
>>
>> But I have not seen anything like this for bonds (latest release of RDKIT
>> and python). Thanks, in advance for any hints. I was wondering about using
>> *highlightBondLists* and then based on the svg infer the bond
>> annotation, but that seems to be a bit of an overkill.
>>
>>
>>
>> Cheers,
>>
>> Lukas
>>
>>
>>
>>
>>
>> _______________________________________________
>> 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

Reply via email to