Skip to content

Commit

Permalink
Added doc_strings
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Omar <[email protected]>
  • Loading branch information
adityaomar3 committed Oct 11, 2023
1 parent 261e7d9 commit 5077326
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions python/avogadro/cjson.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
"""
/******************************************************************************
This source file is part of the Avogadro project.
This source code is released under the New BSD License, (the "License").
******************************************************************************/
"""
import json
class Cjson:
"""
This Class is intended to read Cjson files
with python libraries and perform certain
methods on files and convert them back to Cjson
files as required
"""
def __init__(self):
pass
def __open_file(self, filePath):
'''Use to read CJson formats by converting them to python dictionaries'''
with open(filePath, 'r') as cjsonFile:
py_dict_data = json.load(cjsonFile)
return py_dict_data
def __to_cjson(self, element_coords):
cjson_dict = {"element-coordinates" :element_coords}
cjsonData = json.dumps(cjson_dict, indent=4)
def __to_cjson(self, cjson_dict_file):
'''It converts python dictionaries to CJson format'''
cjsonData = json.dumps(cjson_dict_file, indent=4)
return (cjsonData)
def get_atoms_coords(self,filePath):
"""
It helps to get the co-ordinates of individual elements/atoms in the format
[
x co-ordinate
y co-ordinate
z co-ordinate
Atomic Number of Element
]
"""
data = self.__open_file(filePath)
coords = data["atoms"]["coords"]["3d"]
elements = data["atoms"]["elements"]["number"]
element_coords = [(*coords[i*3:(i+1)*3], elements[i]) for i in range(0, int(len(coords) / 3))]
return self.__to_cjson(element_coords)
cjson_dict = {"element-coordinates" :element_coords}
return self.__to_cjson(cjson_dict)

0 comments on commit 5077326

Please sign in to comment.