-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python code for manipulating CJSON #712
Comments
@MSoegtropIMC if you have some particular suggestions / requests, please leave some comments here. |
I certainly can make a suggestion for a Python class structure to represent CJSON. I wonder if there is some official documentation for CJSON - I couldn't find any. Are you sure that this one big array method is really noticeably faster or is this an assumption? At some point one has to do something with the read in data, so I would think at some point in time one has to take it apart anyway. To me this looks a bit like saving time once during read but spending it multiple times later. Also I would think that for really large files which come in from the disk, constructing python objects is still faster than reading JSON from disk. |
Can you please help me out with code or file in which changes have to be made also what does 'atom[i]["coordinates"] = [x, y, z]' repreasants. @ghutchis |
Here's an example CJSON file (gzipped for GitHub):
Note that to edit / change coordinates in the JSON, you'd do something like:
Note that the coordinates are set as a numeric array. The request is to build up a Python class for manipulating the CJSON, e.g.
This doesn't need to be one patch. It's probably more of a long-term goal. For example, take a look at: |
Sorry that I didn't follow up on this - I went a bit further down from chemistry to first principles with my problem, but should come back again some time, so I would appreciate progress with this. Is there already a python class to represent an atoms and bonds? If not, I can suggest one. As @ghutchis described, the idea is to have two classes "Atom" and "Bond" and to convert CJSON to lists of these classes. I would find it convenient if the Atoms would have a list of their bonds, but this might be a bit slow - one could maybe do this as a separate step. |
That depends. There's obviously support to parse CJSON into Avogadro Atoms / Bonds. I think the question is whether there's a benefit to working with the CJSON without the Avogadro pieces. |
Are these C++ classes or do you already have python wrappers for these C++ classes? |
We have Python wrappers built using pybind11: There are a few examples here: The main question is more "what do people want" from the bindings. It's really easy to add pieces to |
@ghutchis I understood the feature request/problem, I am starting with the issue but can you please help me with directory, in which directory I need to make/push the .py file, bit new here so its bit confusing, would avogadrolibs/scripts be fine? |
This code would be part of the Now you might wonder why there's only So something like Similarly, I'd like to move the class from from avogadro import connect
for filename in glob.iglob("*.xyz"):
connect.openFile(filename)
connect.saveGraphic(filename[:-4] + ".png") |
If you say so should I push the avogadro-remote.py script here https://github.com/OpenChemistry/avogadrolibs/tree/master/python/avogadr as connect.py or you would do it? |
#1360 I have added this script to support reading, getting data and retrieving it back into cjson. |
Okay, initial support has been merged. More suggestions are welcome. |
CJSON often has large arrays for performance reasons. Sometimes it's nice to have representations with lists of atoms with x,y,z.
IIRC, there's some Python code for interconverting CJSON representations and atom[i]["coordinates"] = [x, y, z]
We should add code like this to the
python
module to facilitate manipulating / creating CJSON representations.The text was updated successfully, but these errors were encountered: