User 870ab5b546
02-03-2011 03:11:58
I'm having a bizarre problem with Javascript methods acting on the MRV string acquired from MarvinSketch.
Here's a snippet of code:
var molstruct = document.responseApplet.getMol('mrv');
if (molstruct.indexOf('mrvAlias') >= 0) {
toAlert('You probably meant to add a shortcut group such as Ph or Et to your structure, but you added an atom alias instead. (Aliases and shortcut groups look alike, but ACE cannot interpret aliases properly.) To replace the alias with a shortcut group, type the name of the shortcut group in the Marvin window (not in the textbox in the More window), then click on the alias.');
return;
} // if response contains an alias
alert('molstruct.indexOf(\'z3=\') = ' + molstruct.indexOf('z3=')
+ ', molstruct.indexOf(\'<bondStereo>W\') = '
+ molstruct.indexOf('<bondStereo>W')
+ ', molstruct.indexOf(\'<bondStereo>H\') = '
+ molstruct.indexOf('<bondStereo>H')
+ ', molstruct.indexOf(\'<?xml\') = '
+ molstruct.indexOf('<?xml')
+ ', molstruct =\n' + molstruct
);
Here's the alert that appears:
molstruct.indexOf('z3=') = -1, molstruct.indexOf('<bondStereo>W') = -1, molstruct.indexOf('<bondStereo>H') = -1, molstruct.indexOf('<?xml') = -1, molstruct =
<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray
atomID="a1 a2 a3 a4 a5 a6 a7"
elementType="C H C H C C N"
isotope="0 2 0 0 0 0 0"
mrvSpecIsotopeSymbolPreferred="0 1 0 0 0 0 0"
x3="-3.698240000000001 -6.182217282306649 -5.238240000000001 -5.238240000000001 -6.008240000000001 -7.548240000000002 -2.1820789781346113"
y3="2.982933333333334 2.4379499478168993 2.982933333333334 1.8929333333333338 4.316666666666667 4.316666666666667 2.9393442988856555"
z3="0.0 0.0 0.0 0.0 0.0 0.0 0.0"
/>
<bondArray>
<bond atomRefs2="a5 a3" order="1" />
<bond atomRefs2="a3 a1" order="1" />
<bond atomRefs2="a3 a2" order="1">
<bondStereo>H</bondStereo>
</bond>
<bond atomRefs2="a3 a4" order="1">
<bondStereo>W</bondStereo>
</bond>
<bond atomRefs2="a5 a6" order="1" />
<bond atomRefs2="a1 a7" order="3" />
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>
Any idea why the Javascript indexOf() method should fail to find the strings that are so obviously present in molstruct? The replace() method also fails to find \n and \r characters.
Interestingly, if I put molstruct into an array as the only member, then join all members of the array to get a new string, the new string appears to be identical to the original one, but the indexOf() method gives the expected values.
This behavior is occurring in Safari 5 on Mac. I have no idea whether it happens in other systems.