Giter VIP home page Giter VIP logo

ketcher-rails's Introduction

Ketcherails

Description

This gem provides the possibility to use Ketcher v1. editor with Rails and contains server actions implementations. Ketcher editor has been originally built by GGA Software

Usage

This is a self-mountable Rails engine.

Add it to your app Gemfile

gem 'ketcherails', git: 'https://github.com/ComPlat/ketcher-rails'

Inkscape should also be installed (sudo apt-get install inkscape for Linux).

To take advantage of the molecule common template features, the app should have a user model for Warden based authentication.

The User model should have/expose a boolean attribute 'is_templates_moderator' to authorize the template editing.

Or bypass this by stubbing the current_user (see f9d14e5 of a blank test app).

The user custom template feature also relies on user Warden authentication.

You need to set the application active_job handler (eg with DelayedJob see f147743)

Routes are mounted to /ketcher:

  • full page editor: /ketcher

  • client api demo editor: /ketcher/demo

  • Template management pages: /ketcher/common_templates

Insert the ketcher into an iframe; Molfile setter/getter, and SVG getter functions are available :

      <iframe width="80%" height="800" id="ifKetcher" src="/ketcher"></iframe>
      
      <script>
        function ketcher() {
          const ketcherFrame = document.getElementById('ifKetcher');
          if (ketcherFrame && ('contentDocument' in ketcherFrame)) {
            return ketcherFrame.contentWindow.ketcher;
          }
          return document.frames['ifKetcher'].window.ketcher;
        };
        function getSVG() {
          document.getElementById("result").innerHTML =  ketcher().getSVG();
        };
        function getMolfile() {
          document.getElementById("result").innerHTML = ketcher().getMolfile();
        };
        function setMolfile() {
          const molfile = "\n  Ketcher 06271817312D 1   1.00000     0.00000     0\n\n  3  3  0     0  0            999 V2000\n    1.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    0.5000   -0.8660    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n  1  2  1  0     0  0\n  2  3  1  0     0  0\n  1  3  1  0     0  0\nM  END\n$$$$\n"
          ketcher().setMolecule(molfile);
        };
      </script>

      <button onclick="getSVG()">get SVG</button>
      <button onclick="getMolfile()">get Molfile</button>
      <button onclick="setMolfile()">Draw cyclopropane</button>

(see app/view/ketcherails/ketcher/demo.html, or app/assets/javascripts/ketcher/demo.html, or go to ketcher/demo in your application)

License

This project uses GPLv3 license.

ketcher-rails's People

Contributors

sergeykot avatar pitrem avatar allenskywalker92 avatar cllde8 avatar jasonychuang avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.