JMSketch.selectAtom(atomNum, false)

User 870ab5b546

23-10-2013 21:14:41

I'm finding that when I use setMol() to replace an existing drawing in Marvin 5.4.1.1 that has the same atoms and bonds, but differs by having some different colored boxes, atom selections, and molecule property), the atom selections of the previous MRV remain.  I find this really surprising.  Moreover, I'm unable to use selectAtom(atomNum, false) or selectAllAtoms(false) to turn off the atom selections; in fact, they seem to have the effect of turning them on.


Can you confirm that in MarvinSketch 5.4.1.1, the Javascript command selectAtom(atomNum, false) has exactly the same effect as selectAtom(atomNum, true)?  


If that's the case, I don't suppose you can provide a version of MarvinSketch 5.4.1.1 that has this bug fixed?  If not, do you have a workaround for this bug?


And in what version, if any, is the bug fixed?

ChemAxon 4fa3cf533c

24-10-2013 08:58:52

Hello,


This was a bug, selectAtom was not working properly, and was fixed in 5.6.1.


If updating is not an option,  you'll have to iterate through every atom, use setSelected(false) on every selected atom, and you should remove those atoms from the MDocument calling getSelectionDocument(), and removeAtomFromGraphs() methods.


Hope this helps,


Tamas Fazekas-Vigh

User 870ab5b546

28-10-2013 13:45:38

getSelectionDocument() is not in the API.  In what class is it?  The compiler recognizes neither MDocument.getSelectionDocument() nor Molecule.getSelectionDocument().


The problem I posted earlier, but which I have now deleted, was unrelated to JChem.

User 870ab5b546

28-10-2013 20:15:03

I found a method that compiled in JChem 6.1.0:


mechDoc.selectAllObjects(false);

However, MarvinSketch 5.4.1.1 is still carrying over selections from a previous molecule when it loads a new molecule.  For example, I draw this molecule in MarvinSketch 5.4.1.1:


<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray
atomID="a1 a2 a3 a4 a5 a6"
elementType="C Br N N C Br"
formalCharge="0 0 0 1 0 -1"
x2="-4.405625343322754 -3.2987506008148193 -7.812291622161865 2.9443747997283936 4.051249780654907 7.699999809265137"
y2="-0.2960416227579117 0.9070834368467331 0.6285417079925537 0.8691666722297668 -0.23770833015441895 0.3499999940395355"
/>
<bondArray>
<bond atomRefs2="a1 a2" order="1" />
<bond atomRefs2="a4 a5" order="1" />
</bondArray>
</molecule>
</MChemicalStruct>
<MRectangle id="o2">
<MPoint x="-9.625000476837158" y="2.117499828338623" />
<MPoint x="-1.3956252336502075" y="2.117499828338623" />
<MPoint x="-1.3956252336502075" y="-1.3956252336502075" />
<MPoint x="-9.625000476837158" y="-1.3956252336502075" />
</MRectangle>
<MRectangle id="o3">
<MPoint x="1.034687578678131" y="2.141562521457672" />
<MPoint x="9.264062821865082" y="2.141562521457672" />
<MPoint x="9.264062821865082" y="-1.3715625405311584" />
<MPoint x="1.034687578678131" y="-1.3715625405311584" />
</MRectangle>
<MPolyline id="o4" headLength="0.8" headWidth="0.5">
<MRectanglePoint pos="5" rectRef="o2" />
<MRectanglePoint pos="7" rectRef="o3" />
</MPolyline>
<MEFlow id="o5" arcAngle="150.0" headSkip="0.15" headLength="0.5"
headWidth="0.4" tailSkip="0.25">
<MEFlowBasePoint atomRef="m1.a3" />
<MAtomSetPoint atomRefs="m1.a3 m1.a1" weights="0.25 0.75" />
</MEFlow>
</MDocument>
</cml>

I submit it to the back end, and I get this MRV back, and I use applet.setMol() to load it into Marvin:


<?xml version="1.0" encoding="UTF-8"?>
<cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/help/formats/schema/mrvSchema_6_1_0.xsd" version="ChemAxon file format v6.1, generated by v6.1.0">
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<propertyList>
<property dictRef="selectedAtoms" title="selectedAtoms">
<scalar>1</scalar>
</property>
</propertyList>
<atomArray atomID="a1 a2 a3 a4 a5 a6" elementType="C Br N N C Br" isSelected="true false false false false false" formalCharge="0 0 0 1 0 -1" x2="-4.405625343322754 -3.2987506008148193 -7.812291622161865 2.9443747997283936 4.051249780654907 7.699999809265137" y2="-0.2960416227579117 0.9070834368467331 0.6285417079925537 0.8691666722297668 -0.23770833015441895 0.3499999940395355"/>
<bondArray>
<bond id="b1" atomRefs2="a1 a2" order="1"/>
<bond id="b2" atomRefs2="a4 a5" order="1"/>
</bondArray>
</molecule>
</MChemicalStruct>
<MRectangle id="o2" color="#ff0000" lineColor="#ff0000">
<MPoint x="-9.625000476837158" y="2.117499828338623"/>
<MPoint x="-1.3956252336502075" y="2.117499828338623"/>
<MPoint x="-1.3956252336502075" y="-1.3956252336502075"/>
<MPoint x="-9.625000476837158" y="-1.3956252336502075"/>
</MRectangle>
<MRectangle id="o3">
<MPoint x="1.034687578678131" y="2.141562521457672"/>
<MPoint x="9.264062821865082" y="2.141562521457672"/>
<MPoint x="9.264062821865082" y="-1.3715625405311584"/>
<MPoint x="1.034687578678131" y="-1.3715625405311584"/>
</MRectangle>
<MPolyline id="o4" headLength="0.8" headWidth="0.5">
<MRectanglePoint pos="5" rectRef="o2"/>
<MRectanglePoint pos="7" rectRef="o3"/>
</MPolyline>
<MEFlow id="o5" arcAngle="150.0" headSkip="0.15" headLength="0.5" headWidth="0.4" tailSkip="0.25" baseElectronContainerIndex="-1" baseElectronIndexInContainer="0">
<MEFlowBasePoint atomRef="m1.a3"/>
<MAtomSetPoint atomRefs="m1.a3 m1.a1" weights="0.25 0.75"/>
</MEFlow>
</MDocument>
</cml>


Here is the code I use to load the MRV into MarvinSketch 5.4.1.1 and select the appropriate atoms:


	applet.setMol(submissionValue);
loadSelections();

function loadSelections() {
selectSelected(document.responseApplet,
'selectedAtoms',
':',
'Press the applet\'s Select button to see which atoms have been selected.');
} // loadSelections()

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

After I press the Select button in MarvinSketch, I see the CH3 is selected (correctly).  I unselect it, delete the electron-flow arrow, draw a couple of new ones, and submit this MRV:


<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<propertyList>
<property dictRef="selectedAtoms" title="selectedAtoms">
<scalar>1</scalar>
</property>
</propertyList>
<atomArray
atomID="a1 a2 a3 a4 a5 a6"
elementType="C Br N N C Br"
formalCharge="0 0 0 1 0 -1"
x2="-4.405625343322754 -3.2987506008148193 -7.812291622161865 2.9443747997283936 4.051249780654907 7.699999809265137"
y2="-0.2960416227579117 0.9070834368467331 0.6285417079925537 0.8691666722297668 -0.23770833015441895 0.3499999940395355"
/>
<bondArray>
<bond atomRefs2="a1 a2" order="1" />
<bond atomRefs2="a4 a5" order="1" />
</bondArray>
</molecule>
</MChemicalStruct>
<MRectangle id="o2" color="#ff0000" lineColor="#ff0000">
<MPoint x="-9.625000476837158" y="2.117499828338623" />
<MPoint x="-1.3956252336502075" y="2.117499828338623" />
<MPoint x="-1.3956252336502075" y="-1.3956252336502075" />
<MPoint x="-9.625000476837158" y="-1.3956252336502075" />
</MRectangle>
<MRectangle id="o3">
<MPoint x="1.034687578678131" y="2.141562521457672" />
<MPoint x="9.264062821865082" y="2.141562521457672" />
<MPoint x="9.264062821865082" y="-1.3715625405311584" />
<MPoint x="1.034687578678131" y="-1.3715625405311584" />
</MRectangle>
<MPolyline id="o4" headLength="0.8" headWidth="0.5">
<MRectanglePoint pos="5" rectRef="o2" />
<MRectanglePoint pos="7" rectRef="o3" />
</MPolyline>
<MEFlow id="o5" arcAngle="150.0" headSkip="0.15" headLength="0.5"
headWidth="0.4" tailSkip="0.25">
<MEFlowBasePoint atomRef="m1.a3" />
<MAtomSetPoint atomRefs="m1.a3 m1.a2" weights="0.25 0.75" />
</MEFlow>
<MEFlow id="o6" arcAngle="-243.32835847969886" headSkip="0.25"
headLength="0.5" headWidth="0.4" tailSkip="0.15">
<MAtomSetPoint atomRefs="m1.a1 m1.a2" />
<MAtomSetPoint atomRefs="m1.a2" />
</MEFlow>
</MDocument>
</cml>

I submit, and I get back this MRV, which has two different atoms selected, and I load it into MarvinSketch:


<?xml version="1.0" encoding="UTF-8"?>
<cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/help/formats/schema/mrvSchema_6_1_0.xsd" version="ChemAxon file format v6.1, generated by v6.1.0">
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<propertyList>
<property dictRef="selectedAtoms" title="selectedAtoms">
<scalar>3:2</scalar>
</property>
</propertyList>
<atomArray atomID="a1 a2 a3 a4 a5 a6" elementType="C Br N N C Br" isSelected="false true true false false false" formalCharge="0 0 0 1 0 -1" x2="-4.405625343322754 -3.2987506008148193 -7.812291622161865 2.9443747997283936 4.051249780654907 7.699999809265137" y2="-0.2960416227579117 0.9070834368467331 0.6285417079925537 0.8691666722297668 -0.23770833015441895 0.3499999940395355"/>
<bondArray>
<bond id="b1" atomRefs2="a1 a2" order="1"/>
<bond id="b2" atomRefs2="a4 a5" order="1"/>
</bondArray>
</molecule>
</MChemicalStruct>
<MRectangle id="o2" color="#ff0000" lineColor="#ff0000">
<MPoint x="-9.625000476837158" y="2.117499828338623"/>
<MPoint x="-1.3956252336502075" y="2.117499828338623"/>
<MPoint x="-1.3956252336502075" y="-1.3956252336502075"/>
<MPoint x="-9.625000476837158" y="-1.3956252336502075"/>
</MRectangle>
<MRectangle id="o3">
<MPoint x="1.034687578678131" y="2.141562521457672"/>
<MPoint x="9.264062821865082" y="2.141562521457672"/>
<MPoint x="9.264062821865082" y="-1.3715625405311584"/>
<MPoint x="1.034687578678131" y="-1.3715625405311584"/>
</MRectangle>
<MPolyline id="o4" headLength="0.8" headWidth="0.5">
<MRectanglePoint pos="5" rectRef="o2"/>
<MRectanglePoint pos="7" rectRef="o3"/>
</MPolyline>
<MEFlow id="o5" color="#00ff00" lineColor="#00ff00" arcAngle="150.0" headSkip="0.15" headLength="0.5" headWidth="0.4" tailSkip="0.25" baseElectronContainerIndex="-1" baseElectronIndexInContainer="0">
<MEFlowBasePoint atomRef="m1.a3"/>
<MAtomSetPoint atomRefs="m1.a3 m1.a2" weights="0.25 0.75"/>
</MEFlow>
<MEFlow id="o6" arcAngle="-243.32835847969886" headSkip="0.25" headLength="0.5" headWidth="0.4" tailSkip="0.15" baseElectronContainerIndex="-1" baseElectronIndexInContainer="0">
<MAtomSetPoint atomRefs="m1.a1 m1.a2"/>
<MAtomSetPoint atomRefs="m1.a2"/>
</MEFlow>
</MDocument>
</cml>

However, when I press the Select button in MarvinSketch, it shows three atoms selected: NH3, CH3, and Br.  MarvinSketch seems to remember that the CH3 was selected even after the new MRV has been loaded.  Any workaround will have to convince MarvinSketch to forget about the old MRV selections.  Any ideas?


Finally, there are a number of methods in MDocument that refer to highlighting: highlight(MObject), etc.  Is "highlight" the same as "select"?  If not, what is it? 


-- Bob

ChemAxon 4fa3cf533c

30-10-2013 11:20:55

Sorry for my mistake, but I did not notice that you were talking about Javascript context.


Sadly, there are no workarounds there, only to update to 5.6.1 or newer version.


Highlighting documents only works for MObjects, and atoms and such are not MObjects, but it is for painting the highlight of the selected MObject (such as meflow).


 


Sincerely,


Tamas Fazekas-Vigh