atom selection in MRV?

User 870ab5b546

28-11-2011 14:55:43

I heard a rumor that you would be introducing an atom selection field into the MRV code, so that we can load molecules into MarvinSketch with certain atoms already selected.  When will this feature be available?

ChemAxon 5433b8e56b

28-11-2011 15:26:54

Hi Bob,


as it currently seems, it can be included in 5.8, but it is too early to tell it for a hundred percent sure that it will be convenient to use it from the GUI for the first time. We are keen on to implement a setting to this export option in the GUI but we are facing capacity issues with this. From the API it will be usable for sure.


Regards,
Istvan

User 870ab5b546

28-11-2011 15:40:45

I'm not sure what you mean by "usable from the GUI."  My question is, if the MRV indicates that some atoms are selected, and you load the MRV into the applet, will the atoms display as selected?  And if I select atoms, then get the MRV, will the selections appear in the MRV?


In fact, we've already implemented a solution to the problem of storing selected atoms in the MRV and displaying them upon loading the applet.  We use MSketch.isAtomSelected() to find which atoms are selected, and we use MSketch.setMolProperty() to store them in the MRV as a colon-separated string.  When we load the applet with a molecule, we use MSketch.getMolProperty() to get the colon-separated string of selected atoms and then use MSketch.selectAtom() to select them.


However, I've come across a problem when we set the atom selections.  Although we put the call to selectAtom() in the body onload property, it turns out that in some browsers (esp. Safari for MacOS 10.6), the applet does not always finish loading before the browser starts to execute the methods in body onload.  (The W3C specification does not require onload to wait until the applrts are loaded.)  As a result, we sometimes get a Javascript error.  Do you know of any way to ensure that Marvin is completely loaded before we execute the Javascript method?

ChemAxon 5433b8e56b

28-11-2011 16:02:23

Well, in relation to the selection storing, i can say, marvin will load the selection, and highlight the selected atoms, and there is an export option, if you call getMol("mrv:S") on a 5.8 applet, it will give back an mrv that contains the selection. The GUI option to save the selection when you press save in the desktop application, may be late a bit, and comes in a patch for 5.8, but we are keen on to make such an option also available from the GUI.


To the browser related question, i would say that, maybe we have faced such issues with firefox, and internet explorer also, when we tried to call javascript methods from the same <script> tag where the msketch_* methods were being called. Even when we put the call for the applet into a different <script> tag we have to place some other html tag between the two script tag to avoid an exception with a massage that indicated that the applet object is not initialized, or the called method is missing. This is maybe a similar issue, and it is maybe based on the visibility of the object between two different running threads, or something inside the java plugin or the browser. Maybe you should give it a try, and place the call for the selectAtom calls to the end of the body and check wheter it is working or not.


Regards,
Istvan

User 870ab5b546

28-11-2011 22:25:04

We make the call to start the applet in the body of the HTML, and we make the call to the method that talks to the applet in the body onload property.  I tried this:


function loadSelections() {
var applet = document.responseApplet;
if (applet) selectSelected(applet, 'selectedAtoms', ':');
else setTimeout('loadSelections();', 500);
} // loadSelections()

function selectSelected(applet, propName, divider) {
var selectedAtoms = new String(applet.getMolProperty(propName));
if (selectedAtoms != '' && canParseToInt(selectedAtoms.charAt(0))) {
var atomNums = selectedAtoms.split(divider);
for (var numNum = 0; numNum < atomNums.length; numNum++) {
var atomNum = parseInt(atomNums[numNum]);
applet.selectAtom(atomNum - 1, true);
} // for each atom to be selected
} // if property is readable
} // selectSelected()

But no joy.

User 870ab5b546

29-11-2011 22:21:38

OK, I figured out how to do it.


function loadSelections() {
selectSelected(document.responseApplet, 'selectedAtoms', ':');
} // loadSelections()

function selectSelected(applet, propName, divider) {
var selectedAtoms = new String(applet.getMolProperty(propName));
if (selectedAtoms != '' && canParseToInt(selectedAtoms.charAt(0))) {
var atomNums = selectedAtoms.split(divider);
for (var numNum = 0; numNum < atomNums.length; numNum++) {
var atomNum = parseInt(atomNums[numNum]);
applet.selectAtom(atomNum - 1, true);
} // for each atom to be selected
} // if property is readable
} // selectSelected()


...

<script type="text/javascript">
msketch_name = appletName;
msketch_begin('/nosession/marvin', panelWidth, panelHeight);
msketch_param('molbg', '#ffffff');
...
msketch_param('molLoaderFinishedEvent', 'js:loadSelections();');
msketch_mayscript = true;
msketch_end();
</script>

The molLoadFinishedEvent parameter ensures that the applet will have loaded completely before the loadSelections() method is called.