From c29661899edc34bbf1298679dbdf447258042e61 Mon Sep 17 00:00:00 2001 From: M <35793078+PhysXu@users.noreply.github.com> Date: Sun, 25 Aug 2024 14:34:52 +0800 Subject: [PATCH] Add files via upload --- writeXYZ for Prismatic.ipynb | 769 +++++++++++++++++++++++++++++++++++ 1 file changed, 769 insertions(+) create mode 100644 writeXYZ for Prismatic.ipynb diff --git a/writeXYZ for Prismatic.ipynb b/writeXYZ for Prismatic.ipynb new file mode 100644 index 0000000..5c12bc6 --- /dev/null +++ b/writeXYZ for Prismatic.ipynb @@ -0,0 +1,769 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "1000b5d1-3e37-4712-95a4-4ede6d3a7b93", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b3e5f906-5e09-4529-be1c-5107b3bf358c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
ElementXYZ
0Li0.0000000.0000000.000000
1Li0.0000000.00000014.145616
2Li0.00000024.6202220.000000
3Li0.00000024.62022214.145616
4Li14.2144910.0000000.000000
...............
1008O5.68579626.2615708.104311
1009O8.528695-1.6413486.041305
1010O8.52869526.2615708.104311
1011O11.371593-1.6413486.041305
1012O11.37159326.2615708.104311
\n", + "

1013 rows × 4 columns

\n", + "
" + ], + "text/plain": [ + " Element X Y Z\n", + "0 Li 0.000000 0.000000 0.000000\n", + "1 Li 0.000000 0.000000 14.145616\n", + "2 Li 0.000000 24.620222 0.000000\n", + "3 Li 0.000000 24.620222 14.145616\n", + "4 Li 14.214491 0.000000 0.000000\n", + "... ... ... ... ...\n", + "1008 O 5.685796 26.261570 8.104311\n", + "1009 O 8.528695 -1.641348 6.041305\n", + "1010 O 8.528695 26.261570 8.104311\n", + "1011 O 11.371593 -1.641348 6.041305\n", + "1012 O 11.371593 26.261570 8.104311\n", + "\n", + "[1013 rows x 4 columns]" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "column_names = ['Element', 'X', 'Y', 'Z']\n", + "coords = pd.read_excel(r'C:\\Users\\STEM\\Desktop\\LiCoO2 initial.xlsx', header=None, names=column_names)\n", + "coords" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "110f4169-b74c-49eb-bd41-664b0358225b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
ElementXYZoccupancyisotropic thermal parameters
0Li0.0000000.0000000.00000010.08
1Li0.0000000.00000014.14561610.08
2Li0.00000024.6202220.00000010.08
3Li0.00000024.62022214.14561610.08
4Li14.2144910.0000000.00000010.08
.....................
1008O5.68579626.2615708.10431110.08
1009O8.528695-1.6413486.04130510.08
1010O8.52869526.2615708.10431110.08
1011O11.371593-1.6413486.04130510.08
1012O11.37159326.2615708.10431110.08
\n", + "

1013 rows × 6 columns

\n", + "
" + ], + "text/plain": [ + " Element X Y Z occupancy \\\n", + "0 Li 0.000000 0.000000 0.000000 1 \n", + "1 Li 0.000000 0.000000 14.145616 1 \n", + "2 Li 0.000000 24.620222 0.000000 1 \n", + "3 Li 0.000000 24.620222 14.145616 1 \n", + "4 Li 14.214491 0.000000 0.000000 1 \n", + "... ... ... ... ... ... \n", + "1008 O 5.685796 26.261570 8.104311 1 \n", + "1009 O 8.528695 -1.641348 6.041305 1 \n", + "1010 O 8.528695 26.261570 8.104311 1 \n", + "1011 O 11.371593 -1.641348 6.041305 1 \n", + "1012 O 11.371593 26.261570 8.104311 1 \n", + "\n", + " isotropic thermal parameters \n", + "0 0.08 \n", + "1 0.08 \n", + "2 0.08 \n", + "3 0.08 \n", + "4 0.08 \n", + "... ... \n", + "1008 0.08 \n", + "1009 0.08 \n", + "1010 0.08 \n", + "1011 0.08 \n", + "1012 0.08 \n", + "\n", + "[1013 rows x 6 columns]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Add the occupancy and isotropic thermal parameters\n", + "\n", + "coords['occupancy']=1\n", + "coords['isotropic thermal parameters']=0.08\n", + "coords" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3ca4b865-37e7-4123-809d-e2b10dfecf19", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
ElementXYZoccupancyisotropic thermal parameters
0Li0.0000000.0000000.00000010.06
1Li0.0000000.00000014.14561610.06
2Li0.00000024.6202220.00000010.06
3Li0.00000024.62022214.14561610.06
4Li14.2144910.0000000.00000010.06
.....................
1008O5.68579626.2615708.10431110.08
1009O8.528695-1.6413486.04130510.08
1010O8.52869526.2615708.10431110.08
1011O11.371593-1.6413486.04130510.08
1012O11.37159326.2615708.10431110.08
\n", + "

1013 rows × 6 columns

\n", + "
" + ], + "text/plain": [ + " Element X Y Z occupancy \\\n", + "0 Li 0.000000 0.000000 0.000000 1 \n", + "1 Li 0.000000 0.000000 14.145616 1 \n", + "2 Li 0.000000 24.620222 0.000000 1 \n", + "3 Li 0.000000 24.620222 14.145616 1 \n", + "4 Li 14.214491 0.000000 0.000000 1 \n", + "... ... ... ... ... ... \n", + "1008 O 5.685796 26.261570 8.104311 1 \n", + "1009 O 8.528695 -1.641348 6.041305 1 \n", + "1010 O 8.528695 26.261570 8.104311 1 \n", + "1011 O 11.371593 -1.641348 6.041305 1 \n", + "1012 O 11.371593 26.261570 8.104311 1 \n", + "\n", + " isotropic thermal parameters \n", + "0 0.06 \n", + "1 0.06 \n", + "2 0.06 \n", + "3 0.06 \n", + "4 0.06 \n", + "... ... \n", + "1008 0.08 \n", + "1009 0.08 \n", + "1010 0.08 \n", + "1011 0.08 \n", + "1012 0.08 \n", + "\n", + "[1013 rows x 6 columns]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# If you want use different Uiso for different elements, run the Cell\n", + "\n", + "coords.loc[coords['Element'] == 'Li', 'isotropic thermal parameters'] = 0.06\n", + "coords" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "8df9ecc5-851d-47c5-8f42-3c57e0e8a78c", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\STEM\\AppData\\Local\\Temp\\ipykernel_1928\\469350156.py:1: FutureWarning: Downcasting behavior in `replace` is deprecated and will be removed in a future version. To retain the old behavior, explicitly call `result.infer_objects(copy=False)`. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`\n", + " coords['Element'] = coords['Element'].replace({'Li': 3, 'Co': 27, 'O': 8})\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
ElementXYZoccupancyisotropic thermal parameters
030.0000000.0000000.00000010.06
130.0000000.00000014.14561610.06
230.00000024.6202220.00000010.06
330.00000024.62022214.14561610.06
4314.2144910.0000000.00000010.06
.....................
100885.68579626.2615708.10431110.08
100988.528695-1.6413486.04130510.08
101088.52869526.2615708.10431110.08
1011811.371593-1.6413486.04130510.08
1012811.37159326.2615708.10431110.08
\n", + "

1013 rows × 6 columns

\n", + "
" + ], + "text/plain": [ + " Element X Y Z occupancy \\\n", + "0 3 0.000000 0.000000 0.000000 1 \n", + "1 3 0.000000 0.000000 14.145616 1 \n", + "2 3 0.000000 24.620222 0.000000 1 \n", + "3 3 0.000000 24.620222 14.145616 1 \n", + "4 3 14.214491 0.000000 0.000000 1 \n", + "... ... ... ... ... ... \n", + "1008 8 5.685796 26.261570 8.104311 1 \n", + "1009 8 8.528695 -1.641348 6.041305 1 \n", + "1010 8 8.528695 26.261570 8.104311 1 \n", + "1011 8 11.371593 -1.641348 6.041305 1 \n", + "1012 8 11.371593 26.261570 8.104311 1 \n", + "\n", + " isotropic thermal parameters \n", + "0 0.06 \n", + "1 0.06 \n", + "2 0.06 \n", + "3 0.06 \n", + "4 0.06 \n", + "... ... \n", + "1008 0.08 \n", + "1009 0.08 \n", + "1010 0.08 \n", + "1011 0.08 \n", + "1012 0.08 \n", + "\n", + "[1013 rows x 6 columns]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Chnage the Element to the element_No.\n", + "\n", + "coords['Element'] = coords['Element'].replace({'Li': 3, 'Co': 27, 'O': 8})\n", + "coords" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "3bee4319-3b82-4701-b9f3-4cc9e4f7e796", + "metadata": {}, + "outputs": [], + "source": [ + "fileName = r'C:\\Users\\STEM\\Desktop\\LiCoO2 final.xyz'\n", + "comment = 'LiCoO2'\n", + "cellDim = [14.214, 24.620, 14.146] # the size of cell\n", + "\n", + "with open(fileName, 'w') as fid:\n", + " # Write comment line (1st)\n", + " fid.write(f\"{comment}\\n\")\n", + "\n", + " # Write cell dimensions\n", + " fid.write(f\" {cellDim[0]} {cellDim[1]} {cellDim[2]}\\n\")\n", + "\n", + " # Write atomic data\n", + " dataAll = coords.values\n", + " for row in dataAll:\n", + " fid.write(f\"{int(row[0])} {row[1]:.6f} {row[2]:.6f} {row[3]:.6f} {int(row[4])} {row[5]:.6f}\\n\")\n", + "\n", + " # Write end of file, for compatibility\n", + " fid.write(\"-1\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "45732bd6-135b-4e1a-a7dc-7b4fe5b6af95", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}