From 84588cf587b1e9825be68707b718030109e1711d Mon Sep 17 00:00:00 2001 From: aditya Date: Thu, 5 Oct 2023 01:55:40 +0530 Subject: [PATCH 1/7] Added cjson.py which can be used to read cjson current method added is get_atoms_coords which will get the co-ordinates of all atoms Signed-off-by: aditya Signed-off-by: Aditya Omar --- .vscode/settings.json | 6 +++++ .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 170 bytes .../__pycache__/cjson.cpython-310.pyc | Bin 0 -> 1546 bytes python/avogadro/cjson.py | 21 ++++++++++++++++++ 4 files changed, 27 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 python/avogadro/__pycache__/__init__.cpython-310.pyc create mode 100644 python/avogadro/__pycache__/cjson.cpython-310.pyc create mode 100644 python/avogadro/cjson.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..d1ae2711e3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "cSpell.words": [ + "avogadrolibs", + "Cjson" + ] +} \ No newline at end of file diff --git a/python/avogadro/__pycache__/__init__.cpython-310.pyc b/python/avogadro/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..31df41019a06161ff8bbf9e791c0857a9a190a52 GIT binary patch literal 170 zcmd1j<>g`kf>p<4Q*D9tV-N=!FabFZKwQiNBvKht7@8Rw8B!R788n%yc+!gUa}_f4 zGE4LdD*ZGWZ?P5>W#*NvWGDjZ0u#TC^)vEwQ}y$66N~f{%kt9`Q;PC)GLwq+3o1)8 j^7G(g`tk7~gW}_XM&07D$<0qG%}KRm1lbHSjE4yTxo#>D literal 0 HcmV?d00001 diff --git a/python/avogadro/__pycache__/cjson.cpython-310.pyc b/python/avogadro/__pycache__/cjson.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..05d865b80eb9dfcde7ee8fcd05401da0a08e90b6 GIT binary patch literal 1546 zcmaJ>-EJF26rP#gbvDKc=?|1Zkt~EjmS`N>+bF8k3hpcfNQg*iwB1=d8?ATTnQ@UV z=gL717YOwYTJCzuOYjhL%T->13&eNE-VoG?S)H?Ie$JWmouAQLTWyB%`yU?`-$so6 zNt3GsYwRJ&z7M9D;uSk$Uos_BbjDP)6h~a~Z&)wBz&;z~#IFv4$wQF+46I-{&5nfP zN}REyNJT2fKURrq;h(4tmEzx0o3PmS$)gji>zqTg86=a*Md<;=6PZ5a9UNfu63Dl-I<=6uAUSobEU3rkNad|%GyDQZBY$hGn2sf zU;F)IJudosoSA<1Oph{UbX7jF{mIN7>-uu7A1>XS%zP?kS(i>qikl@*JAA$!aO^c( zIW0FMhLC~+paTewEfCSA`1S2m;rL6j5U==Yw1~a~ZpC7J%ZLN)=gi*u5y0vD9<&aC z=cX6=7~pCjQz(2~=}h%vLpS+!SXRYXnLGBI!RIe9^_|H~sxo&{We5);U$GWxyd@sBnFvrsIh<6z&G&_F7v8ZR=ygw#NJT8iZ{r zot7aSn=oSucFMOoGPl#fYYx1Djt+-hpFmi!m&hLSg{&#Qi!K30yXWp<+6(H#P$WI!#ooT>}i46FZ?L?z8#+DzG8w za#T1Ou>-cTnj(tL!0!M%jcL@4`fH!{3lW{Yqu}#ANlT@DaM$M^#aWitw?UO$xu$ z9B;C?t`tKL2+D(Mf?~3AyGv3i{dcc-Zwm*)+tcPd_&yOG6wCbX{~;Q{X*>;eHZG*} zD7dj!(~9JdluxHwwc0V19YcL$J|)&8_HRE1i99ouNg_) Date: Thu, 5 Oct 2023 02:08:01 +0530 Subject: [PATCH 2/7] changed dict name as it is a keyword Signed-off-by: aditya Signed-off-by: Aditya Omar --- python/avogadro/cjson.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/python/avogadro/cjson.py b/python/avogadro/cjson.py index 19659c4a38..6880f5f768 100644 --- a/python/avogadro/cjson.py +++ b/python/avogadro/cjson.py @@ -7,15 +7,13 @@ def __open_file(self, filePath): py_dict_data = json.load(cjsonFile) return py_dict_data def __to_cjson(self, element_coords): - dict = {"element-coordinates" :element_coords} - cjsonData = json.dumps(dict, indent=4) + cjson_dict = {"element-coordinates" :element_coords} + cjsonData = json.dumps(cjson_dict, indent=4) print(cjsonData) def get_atoms_coords(self,filePath): data = self.__open_file(filePath) coords = data["atoms"]["coords"]["3d"] elements = data["atoms"]["elements"]["number"] - # element_coords = {} element_coords = [(*coords[i*3:(i+1)*3], elements[i]) for i in range(0, int(len(coords) / 3))] print(type(element_coords)) - self.__to_cjson(element_coords) - + self.__to_cjson(element_coords) \ No newline at end of file From 5b810163c9cc9b2d42051d3fc790b3f964ec3a98 Mon Sep 17 00:00:00 2001 From: Aditya Omar Date: Thu, 12 Oct 2023 02:30:40 +0530 Subject: [PATCH 3/7] updated .gitignore file for python and removed debugging statements Signed-off-by: Aditya Omar --- .gitignore | 156 +++++++++++++++++- .vscode/settings.json | 6 - .../__pycache__/__init__.cpython-310.pyc | Bin 170 -> 0 bytes .../__pycache__/cjson.cpython-310.pyc | Bin 1546 -> 0 bytes python/avogadro/cjson.py | 7 +- 5 files changed, 158 insertions(+), 11 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 python/avogadro/__pycache__/__init__.cpython-310.pyc delete mode 100644 python/avogadro/__pycache__/cjson.cpython-310.pyc diff --git a/.gitignore b/.gitignore index b56ad0a304..c9490da5c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,156 @@ docs/build -.DS_Store \ No newline at end of file +.DS_Store +.vscode +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index d1ae2711e3..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cSpell.words": [ - "avogadrolibs", - "Cjson" - ] -} \ No newline at end of file diff --git a/python/avogadro/__pycache__/__init__.cpython-310.pyc b/python/avogadro/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 31df41019a06161ff8bbf9e791c0857a9a190a52..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 170 zcmd1j<>g`kf>p<4Q*D9tV-N=!FabFZKwQiNBvKht7@8Rw8B!R788n%yc+!gUa}_f4 zGE4LdD*ZGWZ?P5>W#*NvWGDjZ0u#TC^)vEwQ}y$66N~f{%kt9`Q;PC)GLwq+3o1)8 j^7G(g`tk7~gW}_XM&07D$<0qG%}KRm1lbHSjE4yTxo#>D diff --git a/python/avogadro/__pycache__/cjson.cpython-310.pyc b/python/avogadro/__pycache__/cjson.cpython-310.pyc deleted file mode 100644 index 05d865b80eb9dfcde7ee8fcd05401da0a08e90b6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1546 zcmaJ>-EJF26rP#gbvDKc=?|1Zkt~EjmS`N>+bF8k3hpcfNQg*iwB1=d8?ATTnQ@UV z=gL717YOwYTJCzuOYjhL%T->13&eNE-VoG?S)H?Ie$JWmouAQLTWyB%`yU?`-$so6 zNt3GsYwRJ&z7M9D;uSk$Uos_BbjDP)6h~a~Z&)wBz&;z~#IFv4$wQF+46I-{&5nfP zN}REyNJT2fKURrq;h(4tmEzx0o3PmS$)gji>zqTg86=a*Md<;=6PZ5a9UNfu63Dl-I<=6uAUSobEU3rkNad|%GyDQZBY$hGn2sf zU;F)IJudosoSA<1Oph{UbX7jF{mIN7>-uu7A1>XS%zP?kS(i>qikl@*JAA$!aO^c( zIW0FMhLC~+paTewEfCSA`1S2m;rL6j5U==Yw1~a~ZpC7J%ZLN)=gi*u5y0vD9<&aC z=cX6=7~pCjQz(2~=}h%vLpS+!SXRYXnLGBI!RIe9^_|H~sxo&{We5);U$GWxyd@sBnFvrsIh<6z&G&_F7v8ZR=ygw#NJT8iZ{r zot7aSn=oSucFMOoGPl#fYYx1Djt+-hpFmi!m&hLSg{&#Qi!K30yXWp<+6(H#P$WI!#ooT>}i46FZ?L?z8#+DzG8w za#T1Ou>-cTnj(tL!0!M%jcL@4`fH!{3lW{Yqu}#ANlT@DaM$M^#aWitw?UO$xu$ z9B;C?t`tKL2+D(Mf?~3AyGv3i{dcc-Zwm*)+tcPd_&yOG6wCbX{~;Q{X*>;eHZG*} zD7dj!(~9JdluxHwwc0V19YcL$J|)&8_HRE1i99ouNg_) Date: Thu, 12 Oct 2023 03:09:59 +0530 Subject: [PATCH 4/7] Added doc_strings Signed-off-by: Aditya Omar --- python/avogadro/cjson.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/python/avogadro/cjson.py b/python/avogadro/cjson.py index 49b8d02caf..2434e30a6f 100644 --- a/python/avogadro/cjson.py +++ b/python/avogadro/cjson.py @@ -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) \ No newline at end of file + cjson_dict = {"element-coordinates" :element_coords} + return self.__to_cjson(cjson_dict) \ No newline at end of file From 475933b93fe8324a436436bf4c1559056cb18f01 Mon Sep 17 00:00:00 2001 From: Aditya Omar Date: Sat, 21 Oct 2023 14:47:52 +0530 Subject: [PATCH 5/7] added get_elements function which returns atomic number of elements present Signed-off-by: Aditya Omar --- python/avogadro/cjson.py | 7 ++- python/avogadro/h2o.cjson | 112 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 python/avogadro/h2o.cjson diff --git a/python/avogadro/cjson.py b/python/avogadro/cjson.py index 2434e30a6f..6b5667a36b 100644 --- a/python/avogadro/cjson.py +++ b/python/avogadro/cjson.py @@ -38,4 +38,9 @@ def get_atoms_coords(self,filePath): elements = data["atoms"]["elements"]["number"] element_coords = [(*coords[i*3:(i+1)*3], elements[i]) for i in range(0, int(len(coords) / 3))] cjson_dict = {"element-coordinates" :element_coords} - return self.__to_cjson(cjson_dict) \ No newline at end of file + return self.__to_cjson(cjson_dict) + + def get_elements(self, filePath): + data = self.__open_file(filePath) + elements = data["atoms"]["elements"]["number"] + return elements \ No newline at end of file diff --git a/python/avogadro/h2o.cjson b/python/avogadro/h2o.cjson new file mode 100644 index 0000000000..0ea06eb5ce --- /dev/null +++ b/python/avogadro/h2o.cjson @@ -0,0 +1,112 @@ +{ + "atoms": { + "coords": { + "3d": [ + -1.1664071083068848, + -0.06516236066818237, + -7.939339639051468e-07, + -1.1341277640126144, + 0.4850611475774994, + -0.7737656886248392, + -2.039371142295559, + -0.035370620243069625, + 0.3735580701221557 + ] + }, + "elements": { + "number": [ + 8, + 1, + 1 + ] + }, + "formalCharges": [ + 0, + 0, + 0 + ], + "labels": [ + "", + "", + "" + ], + "layer": [ + 0, + 0, + 0 + ] + }, + "bonds": { + "connections": { + "index": [ + 0, + 1, + 0, + 2 + ] + }, + "order": [ + 1, + 1 + ] + }, + "chemicalJson": 1, + "layer": { + "enable": { + "Ball and Stick": [ + true + ], + "Cartoons": [ + true + ], + "Close Contacts": [ + false + ], + "Crystal Lattice": [ + false + ], + "Force": [ + false + ], + "Labels": [ + false + ], + "Licorice": [ + false + ], + "Meshes": [ + false + ], + "Non-Covalent": [ + false + ], + "Van der Waals": [ + false + ], + "Wireframe": [ + false + ], + "undef": [ + false + ] + }, + "locked": [ + false + ], + "settings": { + "Ball and Stick": [ + "true true 0.300000 0.100000" + ], + "Cartoons": [ + "false false false false false true false" + ] + }, + "visible": [ + true + ] + }, + "properties": { + "totalCharge": 0, + "totalSpinMultiplicity": 1 + } +} \ No newline at end of file From e729f506a5e2f8bb04dff7b04e404920d8775dbe Mon Sep 17 00:00:00 2001 From: Aditya Omar Date: Sat, 21 Oct 2023 17:22:44 +0530 Subject: [PATCH 6/7] added get and set functions for coordinates and elements Signed-off-by: Aditya Omar --- python/avogadro/cjson.py | 43 +++++++++++++-- python/avogadro/h2o.cjson | 112 -------------------------------------- 2 files changed, 38 insertions(+), 117 deletions(-) delete mode 100644 python/avogadro/h2o.cjson diff --git a/python/avogadro/cjson.py b/python/avogadro/cjson.py index 6b5667a36b..5fffd371d4 100644 --- a/python/avogadro/cjson.py +++ b/python/avogadro/cjson.py @@ -14,7 +14,7 @@ class Cjson: """ def __init__(self): pass - def __open_file(self, filePath): + def __from_cjson(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) @@ -33,14 +33,47 @@ def get_atoms_coords(self,filePath): Atomic Number of Element ] """ - data = self.__open_file(filePath) + data = self.__from_cjson(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))] cjson_dict = {"element-coordinates" :element_coords} return self.__to_cjson(cjson_dict) - def get_elements(self, filePath): - data = self.__open_file(filePath) + ''' + returns all the elements present in cjson file + ''' + data = self.__from_cjson(filePath) elements = data["atoms"]["elements"]["number"] - return elements \ No newline at end of file + return elements + def get_coordinates(self,filePath): + ''' + returns the coordinate array + ''' + data = self.__from_cjson(filePath) + coords = data["atoms"]["coords"]["3d"] + return coords + def set_atoms_coordinates(self, filePath, coords_array): + ''' + it updates the coordinates array in cjson file + ''' + data = self.__from_cjson(filePath) + data["atoms"]["coords"]["3d"] = coords_array + return data + def set_elements(self, filePath, elements_array): + ''' + It sets all the elements present in the cjson file + where elements are set/recognized by their atomic numbers + ''' + data = self.__from_cjson(filePath) + data["atoms"]["elements"]["number"] = elements_array + return data + def set_coordinates(self, filePath, coords_array): + ''' + It helps to set all coordinates of the + cjson file where coordinates of all elements + can be changed by an input array of coords_array + ''' + data = self.__from_cjson(filePath) + data["atoms"]["coords"]["3d"] = coords_array + return data \ No newline at end of file diff --git a/python/avogadro/h2o.cjson b/python/avogadro/h2o.cjson deleted file mode 100644 index 0ea06eb5ce..0000000000 --- a/python/avogadro/h2o.cjson +++ /dev/null @@ -1,112 +0,0 @@ -{ - "atoms": { - "coords": { - "3d": [ - -1.1664071083068848, - -0.06516236066818237, - -7.939339639051468e-07, - -1.1341277640126144, - 0.4850611475774994, - -0.7737656886248392, - -2.039371142295559, - -0.035370620243069625, - 0.3735580701221557 - ] - }, - "elements": { - "number": [ - 8, - 1, - 1 - ] - }, - "formalCharges": [ - 0, - 0, - 0 - ], - "labels": [ - "", - "", - "" - ], - "layer": [ - 0, - 0, - 0 - ] - }, - "bonds": { - "connections": { - "index": [ - 0, - 1, - 0, - 2 - ] - }, - "order": [ - 1, - 1 - ] - }, - "chemicalJson": 1, - "layer": { - "enable": { - "Ball and Stick": [ - true - ], - "Cartoons": [ - true - ], - "Close Contacts": [ - false - ], - "Crystal Lattice": [ - false - ], - "Force": [ - false - ], - "Labels": [ - false - ], - "Licorice": [ - false - ], - "Meshes": [ - false - ], - "Non-Covalent": [ - false - ], - "Van der Waals": [ - false - ], - "Wireframe": [ - false - ], - "undef": [ - false - ] - }, - "locked": [ - false - ], - "settings": { - "Ball and Stick": [ - "true true 0.300000 0.100000" - ], - "Cartoons": [ - "false false false false false true false" - ] - }, - "visible": [ - true - ] - }, - "properties": { - "totalCharge": 0, - "totalSpinMultiplicity": 1 - } -} \ No newline at end of file From 3b81c7e4b86590384e60ad103ea3951f2deb0ba8 Mon Sep 17 00:00:00 2001 From: Aditya Omar Date: Sat, 21 Oct 2023 18:20:40 +0530 Subject: [PATCH 7/7] fixed logical error in set functions Signed-off-by: Aditya Omar --- python/avogadro/cjson.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/avogadro/cjson.py b/python/avogadro/cjson.py index 5fffd371d4..7d07468d63 100644 --- a/python/avogadro/cjson.py +++ b/python/avogadro/cjson.py @@ -59,7 +59,7 @@ def set_atoms_coordinates(self, filePath, coords_array): ''' data = self.__from_cjson(filePath) data["atoms"]["coords"]["3d"] = coords_array - return data + return self.__to_cjson(data) def set_elements(self, filePath, elements_array): ''' It sets all the elements present in the cjson file @@ -67,7 +67,7 @@ def set_elements(self, filePath, elements_array): ''' data = self.__from_cjson(filePath) data["atoms"]["elements"]["number"] = elements_array - return data + return self.__to_cjson(data) def set_coordinates(self, filePath, coords_array): ''' It helps to set all coordinates of the @@ -76,4 +76,4 @@ def set_coordinates(self, filePath, coords_array): ''' data = self.__from_cjson(filePath) data["atoms"]["coords"]["3d"] = coords_array - return data \ No newline at end of file + return self.__to_cjson(data) \ No newline at end of file