fun with MolAtom properties

User 870ab5b546

25-05-2011 14:58:23

You've set up atom properties as a Map<String, Object>.  I've created a property whose value is an Integer.  When I get the value with getProperty(), I cast the value to an Integer before I use it.  All well and good.  


However, if I export the Molecule to MRV, then import it again, I get a ClassCastException when I try to cast the property value to an Integer.  Instead, I need to cast it to a String.  


But if I start with a Molecule that has not been converted to a String, then I get a ClassCastException when I try to cast the property value to a String.  It will only allow me to cast it to an Integer.


I have no way of knowing whether a Molecule had its atom properties set before or after it was imported, so I now have to use instanceof to check whether I need to cast the property value to a String, then parse it to an int, or whether I can cast it to an Integer and then get the primitive value.


The upshot: In your documentation, you should say that if a Molecule is imported from a String, atom properties will automatically be assigned to the String class, regardless of their original class.

ChemAxon 25dcd765a3

26-05-2011 13:38:32

Hi Bob,


We examine this issue.


Thank you for the report.

ChemAxon e500b51457

26-05-2011 17:15:52

Hi Bob,

We tried to reproduce the problem - without success. I have attached our example code.
Please modify the test code or attach your example in order to reproduce this issue.

Thanks,
Erika

User 870ab5b546

27-05-2011 03:25:09

I figured it out.  I need to set the "dataType" attribute to integer.

ChemAxon 25dcd765a3

27-05-2011 07:53:07

Does it mean that you edit the mrv file directly with a text editor?

User 870ab5b546

27-05-2011 15:42:37

We have an applet, LewisSketch, that we use to draw Lewis structures.  In many ways it's a stripped-down version of Marvin, but it has one feature that Marvin lacks: The ability to place any number of unshared electrons around an atom.  (Equally important, it lacks a feature that Marvin has: The ability to show the correct number of unshared electrons around an atom.)  Our applet outputs the drawn structure in a format that JChem recognizes so we can use JChem methods to analyze some aspects of the structure.  We have been using an extended MOL format to store the number of unshared electrons of each atom, and we would use our own code to extract the unshared electrons form the MOL and store them in an array parallel to the atom array.  Now that the MRV format has atom properties, however, we can abandon our extended MOL format and use MRV instead, dispensing with the parallel array.  We are also now able to use a MolComparator that considers the number of unshared electrons of each atom in MolSearches.  


In summary, our applet creates the MRV by "hand" from the structure drawn by the student.  I had written dataType="xsd:string" in the code that produced the MRV because I didn't recognize the purpose of that field when I looked at the MRV after I added a property to an atom with the Marvin applet.