*Q: I came across your post on cif-developers that says: In the end, what
we have is a package that can convert CIF 2.0 records to JSON format if
desired.*



* How can I use it? I'd like to test my own CIF parser and I thought I
could do this by making own converter to json and comparing the results. So
how do I convert CIF to JSON using JMol?*

A:

The CIF data is structured as a set of key/value pairs, just like JSON.
Jmol automatically reads the CIF data into its own structured variables,
and you can format those as JSON for output. So it is as simple as this:

load quartz.cif
x = getProperty("fileInfo")
print format("JSON", x)

Or, to a file:

load quartz.cif
x = getProperty("fileInfo")
y = format("JSON", x)
write var y "quartz.json"

or all in one go:

load quartz.cif
write inline @{format("JSON",getProperty("fileInfo"))} "quartz.json"

You also can do this from the command line, meaning you can do it on
"headless" servers (using JmolData.jar) or without ever opening Jmol for
viewing:


Jmol.jar -ionj "load quartz.cif;write inline
@{format('JSON',getProperty('fileInfo'))}
'quartz.json' "

(-i silent; -o output to sysout; -n no display; -j script)

etc.

Note that tables like this:

loop_
_atom_site_label
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
Si  0.46970   0.00000   0.00000
O   0.41350   0.26690   0.11910


become arrays like this:

"_atom_site_label": [ "Si","O" ],
"_atom_site_fract_z": [ "0.00000","0.11910" ],
"_atom_site_fract_y": [ "0.00000","0.26690" ],
"_atom_site_fract_x": [ "0.46970","0.41350" ],

Note that the numbers are strings, specifically because sometimes we see
"numbers" that look like this in CIF files:   0.467(90)


-Bob Hanson

-- 
Robert M. Hanson
Larson-Anderson Professor of Chemistry
St. Olaf College
Northfield, MN
http://www.stolaf.edu/people/hansonr


If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to