ncats / NCATSFind

Chrome plugin for resolving / rendering chemical structures from names and images.
12 stars 6 forks source link

Molecules <10 atoms won't copy #1

Closed tylerperyea closed 10 years ago

tylerperyea commented 10 years ago

In the copy/paste written for firefox functions, there is some bug that makes small molecules (<10 atoms) refuse to paste in chemdraw.

This is probably some assumption made on the length of a line...

The suspected function is:

function cDrawMol(molFile){
    var molFile = molFile.replace(/\n\n/g, "\n"+"!"+"\n");
    if (molFile.charCodeAt(0) == 10) molFile = '!' + molFile;
    console.log(molFile);
    var mdlCTba = [];
    for (var j = -1; j < molFile.length; j = j + 2) {
      var a = 10;
      if (j > -1)
        a = molFile.charCodeAt(j);
      if (a == 10) {
        a = findNextNL(molFile, j+1) - j - 1;
      }
      if (molFile.length < j+2)
        molFile += ' ';
      var b = molFile.charCodeAt(j+1);
      if (b == 10) { 
        b = findNextNL(molFile, j+2) - j - 2;
      }
      mdlCTba.push(a + 256*b);
    }
    return String.fromCharCode.apply(String, mdlCTba);
}
southalln commented 10 years ago

Apparently, ChemDraw is expected a closing $$$$ in the molfile from CT flavor --- ketcher's molfile doesn't provide this, so I've added. A proper fix would probably check first for a closing $$$$ and add if not present ....