partridgejiang / cheminfo-to-web

An experimental project to recompile native chemoinformatics libs into JavaScript.
https://partridgejiang.github.io/cheminfo-to-web/
MIT License
13 stars 3 forks source link

InChIKey #2

Closed bergwerf closed 4 years ago

bergwerf commented 4 years ago

It looks like you know quite a bit better than me how to work with the InChI C library :) (and how to get it to compile to JavaScript). Could you help me with adding a function to also obtain an InChIKey?

bergwerf commented 4 years ago

I am also looking into https://github.com/metamolecular/inchi-js

partridgejiang commented 4 years ago

Hi @bergwerf, I have updated InChI.js in the repo to include a wrapper function to calculate InChI Key from InChI string:

// use script file inchi.js first
var module = InChIModule();
var molToInChIJson = module.cwrap('molToInchiJson', 'string', ['string', 'string']);
var getInChIKeyJson = module.cwrap('getInChIKeyJson', 'string', ['string', 'number', 'number']);
var molData = '.......';   // suppose we have MOL format file data here
// get InChI from MOL data
var inchiJson = JSON.parse(molToInChIJson(molData, ''));
// get InChI Key from InChI
var inchiKeyJson = JSON.parse(getInChIKeyJson(inchiJson.inchi, 1, 1));  // get key and xtra1, xtra2 block
if (inchiKeyJson.success)
  console.log(inchiKeyJson.inchiKey, inchiKeyJson.xtra1, inchiKeyJson.xtra2);
bergwerf commented 4 years ago

Awesome! Thank you for your effort.