Get the selected atoms from Marvin Space

User a8020badc4

18-05-2011 10:48:06

Hello,


Is there a way of retrieving the id of the selected atom(s) in Marvin Space?


I want to be able to select the 4 atoms for a dihedral bond and then post them with a form.  I'm happy with the posting bit I just need a way of retrieving the atom id's (i.e. alert(atom_list) would do just fine).


Do I need to loop thorugh all the atoms and check if they are selected?


I've tried something simple like the below code to retrieve the atom count but I can't get it to work.


function selMol(){

var cnt = document.MSpaceApplet.getAtomCount();

alert(cnt);

};

Can anyone help with this?


Thanks,


S

ChemAxon eb65a25631

19-05-2011 09:56:21

Hi,


i couldn't find any suitable method to easily determine the selected atoms, so It must be done the slightly complicated way like this:


 function getSelectedAtoms() {
        var activeCell = document.MSpaceApplet.getMSpaceEasy().getGraphicScene().getActiveCell();
        var components = activeCell.getComponentIterator();
        var result = new Array();
        var k = 0;
        for(var i = components; i.hasNext(); ) {
            var component = i.next();
            alert(component.isGraphicComponent());
            var atomSelection = component.getAtomSelections();45
            for (var j = 0; j<atomSelection.length;j++ ) {
                if (atomSelection[j])
                    result[k++] = component.getSelectedAtom(j);
            }
        }
        return result;
    }

this function returns the selected atom's MolAtom classes.


You can find the accessible methods of MolAtom class on the following URL:


http://www.chemaxon.com/marvin/help/developer/beans/api/index.html


or exactly:


http://www.chemaxon.com/marvin/help/developer/beans/api/chemaxon/struc/MolAtom.html


 


Regards,


András