I’m working with Geoff on the python plugin architecture. There are a couple 
small change to the cjson format I’d like to propose. Currently, the cjson has 
structure that is implied but not explicit in the file itself, and this forces 
an adopter of the file to extrapolate the format instead of just reading it. 
Making the structure explicit will make it much easier to use the cjson format, 
as well as making it more intuitive when looking at or editing the file 
directly.

The changes would be:

(1) group atom coordinates by atom:

i.e.:
 “3d”: [
[1,2,3],
[1,2,5],
etc
]

instead of:
“3d”: [
1,2,3,1,2,5,
etc
]

(2) group bonds by bond:

i.e.:

  "index" :
      [
        [0,1],
        [0,34],
        [0,35],
...
     ]

instead of:

  "index" :
      [
        0,
        1,
        0,
        34,
        0,
        35,
        ...
    ]


The difference this makes in the plugin is the difference between this:

coords_json = cjson["atoms"]["coords"]["3d"]
atoms = [ (*coords_json[i*3:(i+1)*3]) for i in range(0, int(len(coords_json) / 
3)) ]

and just this:

atoms = cjson["atoms"]["coords"]["3d"]

No conversion necessary.

For writing, the difference is between:


structure["atoms"]["coords"]["3d"] = [ c for a in atom_tuples for c in a ]

vs just:

structure["atoms"]["coords"]["3d"] = atom_tuples

if you already have atoms in a tuple format such as: atom_tuples = [(1,2,3), 
(2,3,4)]

When the file semantically reflects the actual structure, we can just use the 
cjson as-is without doing anything. Currently, where it doesn’t reflect the 
actual structure, I have to do list comprehensions that are not terribly 
intuitive to marshall the structure back and forth.

What do you all think? Can we make this change?

--
Paul Boone
Lead Developer, Wilmer Lab | http://wilmerlab.com/
Center for Simulation and Modeling | https://www.sam.pitt.edu/
University of Pittsburgh




------------------------------------------------------------------------------
_______________________________________________
Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/avogadro-devel

Reply via email to