partridgejiang / Kekule.js

A Javascript cheminformatics toolkit.
http://partridgejiang.github.io/Kekule.js
MIT License
248 stars 61 forks source link

Feature Request; Electron Pushing Curved Arrows #77

Open cleblond opened 5 years ago

cleblond commented 5 years ago

Any plans to add support for electron pushing/curved arrows as would be used in organic reaction mechanisms?

partridgejiang commented 5 years ago

It's not difficult to add those arrows to editor. However, I myself am too busy to implement it in recent days, so, please be patient.

AaronLlanos commented 5 years ago

+1

cleblond commented 5 years ago

I currently use Chemdoodle in my app since it can do curved arrows, but I'd love to do away with chemdoodle. I plan to attempt implementing curved arrows in kekule this weekend. My plan is to look at your recent lone pair tool/button commits to learn more about your code. Any helpful suggestions?

MrDarkHorse commented 5 years ago

Yes! This please!

cdnadmin commented 5 years ago

+1

monico-moreno commented 5 years ago

+1

jewelsjacobs commented 5 years ago

+1

gallawayc commented 5 years ago

👍

jbae159 commented 5 years ago

+1

devsupreme commented 5 years ago

Please!

kelleymccool commented 5 years ago

👍

partridgejiang commented 5 years ago

@cleblond I am starting to code for this feature today, maybe a initial implementation can be release the next week, please stay tuned, :).

partridgejiang commented 5 years ago

@cleblond The basic support for curved arrows is added to chem editor. Please check the new release files.

cleblond commented 5 years ago

Wow! Your fast. Thanks much!

I played with and and have a couple of comments: 1) The arrows should be able to start at any atom or bond and go to any atom or bond. 2) The arrow type (single electron or double), the starting atom or bond and the ending atom or bond should all be encoded in KJS.

Checkout Chemdoodle and MarvinJS which both support this. Most Chemistry folks I know prefer Chemdoodle version, so if you could mimic that.

AaronLlanos commented 5 years ago

@partridgejiang Thank you for the quick update!! I just wanted to weigh in on what @cleblond said and let it be known I am in full agreement on that. I did have a query to know if matching is included? For example, given StructureA and StructureB both with curved arrows, are the structures the same and do the arrows on the structures match up?

partridgejiang commented 5 years ago

@cleblond @AaronLlanos Is that a feature request for a automatic grading reaction mechanism question type? I'll start investigating it when free, maybe in this weekend. By the way, there may be some difficulties in comparing electron transferring arrow on the molecule level. For instance, the following reaction, there is an arrow cross two molecules. So in the internal structure of the reaction, the arrow should not be a child of a single molecule but a child of reaction or document, the comparison thus will be much more difficult. So any suggestions for that? reaction1

cleblond commented 5 years ago

Here is how I currently do it with chemdoodle mechanisms. I do this all on the server side. When you draw a reaction mechanism or structure in ChemDoodle, using the API you have the option of exporting the structure(s) as MOLfile format or Chemdoodles JSON format. I utilize both of these. The Molfile only describes the molecular structures, while the JSON provides details of not only the structures but the curved arrow topology, bonds etc. I take the Molfile structures and “Canonize” the atoms with RDKit. Initially I used the CanonicalRankAtoms method but didn’t like the indexing, so I decided to use atom.GetProp(‘_CIPRank’) which provides the Cahn-Ingold-Prelog ranking of the atoms. I may need to revisit this after more real world testing. I convert all the Molfiles to canonical smiles using OpenBabel and then canonize them (I put them in alpha order). I could have used RDkit for this as well, but Openbabel has proven to be very reliable. From here I reference the JSON atom positions to the CIP ordering along with the curved arrows and bond start/end points. Bond data is important because curved arrows can start or end at a bond. All this leads to a hash table of canonized curved arrow data. If the curved arrow data and smiles structures are the same then the mechanisms are the same.

partridgejiang commented 5 years ago

@cleblond Thanks a lot for your explanation. I'll have a try later.

AaronLlanos commented 5 years ago

I believe that a child of document or reaction would be most adequate. There definitely are cases where cross molecule curved arrows would be useful for my application like in your example above. It doesn't make sense that we keep the arrow as a child of Molecule. Is there a way that in the representation we can have Document/Reaction > CurvedArrow > BeginningNodeOrMarkerID/EndNodeOrMarkerID represented in the JSON? Does that make sense?

gitKearney commented 5 years ago

Thanks so much for implementing this!

AaronLlanos commented 5 years ago

@cleblond Thanks a lot for your explanation. I'll have a try later.

@partridgejiang were you able to expand your work on this?

MrDarkHorse commented 5 years ago

Also checking in on this feature. I spent a little time playing around with the existing feature (which we really appreciate, by the way!)

I think for this to be ultimately viable for our own purposes we're going to need to be able to attach the curved arrows to an electron/bond and keep track of the topography for structure matching purposes.

Very excited about the possibilities, though!

partridgejiang commented 5 years ago

Sorry that I was engaging in another project last month. I'll start to implement this feature soon, :).

MrDarkHorse commented 5 years ago

So I actually have a solution in our fork that allows you to anchor a curved arrow to either an atom, bond, or electron now. There is no matching involved, but it's a nice start.

cleblond commented 5 years ago

@MrDarkHorse where is this repo? public? Thanks

AaronLlanos commented 5 years ago

@cleblond https://github.com/AaronLlanos/Kekule.js/tree/moldraw-master

AaronLlanos commented 5 years ago

Also @cleblond please reference this comment into how I structured my fork: https://github.com/partridgejiang/Kekule.js/issues/36#issuecomment-446627209

SChemTeach commented 5 years ago

Any news on the project to include curved arrows that anchor on atoms or bonds in the master branch anytime soon? This feature is needed to use kekule.js for academic educational purposes. Thanks !

partridgejiang commented 5 years ago

@SChemTeach Yes I am working on it. However, it's a little harder than expected. Please be patient.

partridgejiang commented 5 years ago

Hi everyone, although a little too late, but the feature is finally implemented. New electron pushing arrows are available in the composer widget. The end of the arrow curve can be bound to a atom or bond in molecule. The class type will automatically switch between Kekule.Glyph.ElectronPushingArrow and Kekule.Glyph.Arc when binding to or unbinding from atom/bond. Enjoy, :).

cleblond commented 5 years ago

Awesome feature! I'm trying to figure out how to determine where the arrows start and stop from looking at the kekule json. What does "coordStickTarget":"@[2,4]" indicate?

partridgejiang commented 5 years ago

@cleblond Actually in the latest release, the start/stop object of an electron pushing arrow can be obtained by arrow.getDonor() and arrow.getReceptor(). The coordStickTarget property indicating that the end node of the arrow always has the same coordinates as another object (atom or bond, can be obtained by chemDocument.getChildAt(2).getChildAt(4) in the @[2,4] case).