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