[Openchemistry-developers] cjson: nested lists instead of 1D lists for multidimensional data?
Ian Daniher
ian at nonolithlabs.com
Wed Jun 13 17:11:39 EDT 2012
Hi All,
Right now, Chemical JSON uses a 1D list for all of the multidimensional
information including 3d coordinates for atoms and bonds.
When parsing the format, this results in the following:
ethane["atoms"]["coords"]["3d"]
>
> [1.18508, -0.003838, 0.987524, 0.751621, -0.022441, -0.020839, 1.166929,
> 0.833015, -0.569312, 1.115519, -0.932892, -0.514525, -0.751587, 0.022496,
> 0.020891, -1.166882, -0.833372, 0.568699, -1.115691, 0.932608, 0.515082,
> -1.184988, 0.004424, -0.987522]
Getting the x, y, z coordinates of the first atom is overcomplicated in
both javascript and python. A reasonable use case might be looping through
ethane["atoms"] and drawing based on the location of each.
In python, this would look like:
for i in range(len(ethane["atoms"]["elements"]["number"])):
start = 0+i
end = 3*(1+i)
x, y, z = ethane["atoms"]["coords"]["3d"][start:end]
draw(x,y,z)
If the list was nested, it would look like the following:
for i in range(len(ethane["atoms"]["elements"]["number"])):
x, y, z = ethane["atoms"]["coords"]["3d"][i]
draw(x, y, z)
Fewer things to keep track of, fewer places to screw up, more implicit
information. Everyone wins.
Not sure what sort of performance hit you get with nested array
serialization, but this might let you remove the "3d" subobject as
dimensionality of coordinates would be explicit.
The same argument applies to the "bonds" subobject.
Best!
--
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/openchemistry-developers/attachments/20120613/7a37868c/attachment.html>
More information about the Openchemistry-developers
mailing list