Canonical SMILES algorithm

User 16d6255802

06-05-2014 13:20:49

Quick question for you all,


The tool I am building for my University matches a molecule drawn on a Marvin for JavaScript instance with a SMILES value saved in a database. It's working great but I've hit a small snag. (nomenclature101.com)


The issue I have is when hydrogens are explicitly drawn, the exported SMILES value changes which means it will not match it's value in the database even though the drawing is actually correct. Is there a way that you can think of around this?


A chemistry professor offered these 2 options:


- Hide the hydrogen button from the applet
- Use the "Canonical SMILES algorithm" which always gives the same SMILES value no matter if the hydrogens are implicit or explicit.


Would either of these options work? Is there a way to do this?


Any help would be greatly appreciated!!


Jamey

User 16d6255802

06-05-2014 13:56:00

Another option may be for me to export the molecule's name instead of it's SMILE value. I did some digging, and although I know it can be done (Name is one of the "Save As" options in the applet), I cannot find any documentation on how I could pull the drawn molecule's name via JavaScript. Could you maybe point me in the right direction for this info?

User 16d6255802

06-05-2014 14:37:03

Okay, please disregard. I figured out how to export the molecules name instead of the SMILES value. This always gives me a proper name, no matter if the hydrogens are implicit or explicit. Im going to move forward with this. :)

ChemAxon f052bdfe3c

07-05-2014 19:11:09

I am glad that you found a solution.


Best regards,


Efi

User 867bf5be52

07-09-2015 12:24:12










JameyLaroche wrote:

Quick question for you all,


The tool I am building for my University matches a molecule drawn on a Marvin for JavaScript instance with a SMILES value saved in a database. It's working great but I've hit a small snag. (nomenclature101.com)


The issue I have is when hydrogens are explicitly drawn, the exported SMILES value changes which means it will not match it's value in the database even though the drawing is actually correct. Is there a way that you can think of around this?


A chemistry professor offered these 2 options:


- Hide the hydrogen button from the applet
- Use the "Canonical SMILES algorithm" which always gives the same SMILES value no matter if the hydrogens are implicit or explicit.


Would either of these options work? Is there a way to do this?


Any help would be greatly appreciated!!


Jamey



Hello I'd like to reopen this topic, since I'm dealing with the same problem. Unfortunatelly I cannot use name, because smiles is used in further processing.


Can anybody help me with this?


Thank you Martin

ChemAxon f052bdfe3c

07-09-2015 13:44:45

Hi Martin,


Can you detail your problem please? Is it the SMILES comparison? Could you send some non- confidential example please?


Best regards,


Efi

User 867bf5be52

07-09-2015 14:17:03

Hi ehoffmann,


thanks for trying to help. Yes I'm comparing two structures in smiles format(marvin for javascript + webservices), these are:


Cl[C@@H]1C[C@H]1Br   and


[H][C@@]1(Cl)C[C@@]1([H])Br   (both exported in Smiles format).


These are the same structures, only the second one has explicitly drawn 2 hydrogen atoms.


I need to tell that these are the same thru smiles. Is there a way?


Thank you


M.

ChemAxon 76c88f5366

08-09-2015 08:52:17

Hi Martin,


You can convert the SMILES format to Unique SMILES (which is comparable) by using the Format Conversion function with the parameter: "smiles:u".


You can read about the Unique SMILES format here: https://docs.chemaxon.com/display/FF/SMILES


Here you can find the description about the Format Conversion in the JChem WebServices API doc (8.2 Format Conversion section): https://restdemo.chemaxon.com/apidocs


I hope, this will help.


Regards,
Eszter

User 867bf5be52

08-09-2015 12:10:32

Hi Eszter,


thank you for your help. Unfortunatelly if I try to export unique smiles directly from editor like this:


sketcher.exportStructure("smiles:u", {}).then(function(structure){
console.log(structure)

});

I'm getting:


Uncaught (in promise) {f: "format cannot be null", i: null}

The only way now seems to be (as you suggested) call a molconvert webservice with exported structure directly like:


 $.ajax({
url: getDefaultServices()["molconvertws"],
type: "post",
data: {
structure: structure,
inputFormat: "smiles",
parameters: "smiles:u"
}
})....

This way everything works fine and the structures from my previous post are same.


Just one question... this way I need to make 2 requests  to the same url (/webservices/rest-v0/util/calculate/molExport). Do you plan to include this functionality directly into Marvin JS? I've seen the exportStructure method of the sketcher has options parameter, which is according to docs not used..


Anyway my problem is solved now, so thank you very much


Martin

User 867bf5be52

08-09-2015 15:25:21

One more thing, I haven't found bug tracker for marvin js so I'm posting here.


In latest Firefox, if the sketcher instance is hidden and importStructure is called then this is thrown in console and structure is not imported :


[marvin UnchaughtException]:Class$S101: (NS_ERROR_FAILURE) : 

other browsers work fine, so I thing this is a bug.


Thanks M.

ChemAxon 76c88f5366

09-09-2015 08:09:02

Hi Martin,


Thank you for reporting the Firefox- issue, we will investigate it.


The implementation of the options parameter is not among our nearest future plans, but thank you for the feedback, we will take it into consideration.


Regards,
Eszter

ChemAxon 76c88f5366

09-09-2015 14:31:52

Hi Martin,


According to these pages (https://bugzilla.mozilla.org/show_bug.cgi?id=733698 ;


https://bugzilla.mozilla.org/show_bug.cgi?id=941146) it seems a Mozilla Firefox bug which caused problems with the iframe.


As a workaround I would suggest using "visibility:hidden" property instead of "display:none".


I hope this will help.


Eszter

User cbb759276f

02-10-2015 15:24:01

 I would like to ask a related question on unique SMILES. I wish to generate either  a unique SMILES (smiles:u) or a smiles without explicit hydrogens (smiles:-H) and then click "Get Mol" to output the unique SMILES onscreen, similar to the "Get a molecule" example:


https://marvinjs-demo.chemaxon.com/latest/examples/example-getmol.html


The example source code for this action is:


function initControl () {

// get mol button
$("#btn-getmol").on("click", function (e) {
marvinSketcherInstance.exportStructure("mrv").then(function(source) {
$("#molsource").text(source);
}, function(error) {
alert("Molecule export failed:"+error);
});
});
}


 


I've managed to modify this to generate SMILES easily enough:



function initControl () {

// get mol button
$("#btn-getmol").on("click", function (e) {
marvinSketcherInstance.exportStructure("smiles").then(function(source) {
$("#molsource").text(source);
}, function(error) {
alert("Molecule export failed:"+error);
});
});
}


 


 


Could this approach be combined with Martin's code above, such that mrv is passed from MarvinJS to the Webservices, which converts the format to unique SMILES and this can be output into the box? (I know nothing about Javascript!)


 



function initControl () {

// get mol button
$("#btn-getmol").on("click", function (e) {
marvinSketcherInstance.exportStructure("mrv").then(function(source) {


$.ajax({
url: getDefaultServices()["molconvertws"],
type: "post",
data: {
  structure: source,
  inputFormat: "mrv",
parameters: "smiles:u"
}
})


$("#molsource").text(source);
}, function(error) {
alert("Molecule export failed:"+error);
});
});
}


 


 

User 867bf5be52

05-10-2015 07:07:06

Hi ucc_chemistry,


Your code is "almost complete", you forgot to attach handlers to the ajax call (I omitted those in my code). So the complete source of initControl() would be:


 


function initControl() {


 


// get mol button


    $("#btn-getmol").on("click", function (e) {


        marvinSketcherInstance.exportStructure("mrv").then(function (source) {


 


            $.ajax({


                url: getDefaultServices()["molconvertws"],


                type: "post",


                data: {


                    structure: source,


                    inputFormat: "mrv",


                    parameters: "smiles:u"


                }


            }).done(function(uniqueSmiles){


                $("#molsource").text(uniqueSmiles);


            }).fail(function(xhr, textStatus, errorThrown){


                console.log("ajax request failed");


                console.log(xhr, textStatus, errorThrown);


            });


 


            $("#molsource").text(source);


        }, function (error) {


            alert("Molecule export failed:" + error);


        });


    });


}


 


One thing may be tricky. I'm calling getDefaultServices() to get URL of my service. This need that js/webservices.js to be included before calling this (in your html, not only in Marvin iframe) or you can hardcode your url in the parameter.


Hope this helps


Martin

User cbb759276f

05-10-2015 16:29:37

Thanks Martin - your help is greatly appreciated!!


 


I had to hardcode in the URL as you mention, but when I did, the text box returned "[Object][object]"  - I guess this is because the ajax call is returning an object rather than a string?


Anyway, I modified the code to call StringMolExport, rather than MolExport, and it's working fine now.


 


 


// get mol button

$("#btn-getmol").on("click", function (e) {

marvinSketcherInstance.exportStructure("mrv").then(function (source) {



$.ajax({

url: "http://localhost:8080/webservices/rest-v0/util/calculate/stringMolExport",

type: "post",

data: {
"structure": source,
"parameters": "smiles:-H"
}

}).done(function(uniqueSmiles){

$("#molsource").text(uniqueSmiles);

}).fail(function(xhr, textStatus, errorThrown){

console.log("ajax request failed");

console.log(xhr, textStatus, errorThrown);

});



$("#molsource").text(source);

}, function (error) {

alert("Molecule export failed:" + error);

});

});

}


 

ChemAxon 7c2d26e5cf

06-10-2015 10:58:51

Just one note.


The response type of molExport webservice is application/json.


https://restdemo.chemaxon.com/apidocs/#molExport


Ajax resolves the response as a JavaScript object.


If you retrieve its structure property, you get the generated molecule source.


$.ajax({
url: getDefaultServices()["molconvertws"],
type: "post",
data: {
"structure": source,
"parameters": "smiles:-H"
}
}).done(function(response){
var uniqueSmiles = response['structure'];
$("#molsource").text(uniqueSmiles);
}).fail(function(xhr, textStatus, errorThrown){
console.log("ajax request failed");
console.log(xhr, textStatus, errorThrown);
});