Curls: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
"""In preparation""". | """In preparation""". | ||
Usage (written for python 3.5 and | Usage (written for python 3.5 and newer): | ||
Curls is a script for measuring the distance between two atoms... | |||
# copy following text to blank file named ""culrs.py"" | # copy following text to blank file named ""culrs.py"" | ||
| Line 44: | Line 46: | ||
# to run script type: | # to run script type: | ||
python3.6 XDATCAR < | python3.6 XDATCAR <atom1_number_from_poscar> <atom2_number_from_poscar> | ||
# to write script output to file: | # to write script output to file: | ||
python3.6 XDATCAR <atom1_number_from_poscar> <atom2_number_from_poscar> > <output.dat> | python3.6 XDATCAR <atom1_number_from_poscar> <atom2_number_from_poscar> > <output.dat> | ||
Latest revision as of 15:49, 26 February 2019
"""In preparation""". Usage (written for python 3.5 and newer):
Curls is a script for measuring the distance between two atoms...
- copy following text to blank file named ""culrs.py""
# /usr/bin/env python3
# coding: utf-8
import numpy as np
import pandas as pd
import sys
file=sys.argv[1]
cell_vec=pd.read_csv(file, delim_whitespace=True,skiprows=2,nrows=3,names=['x','y','z'])
cell_vec.head()
a1=np.array([float(cell_vec.loc[0].x),float(cell_vec.loc[0].y),float(cell_vec.loc[0].z)])
a2=np.array([float(cell_vec.loc[1].x),float(cell_vec.loc[1].y),float(cell_vec.loc[1].z)])
a3=np.array([float(cell_vec.loc[2].x),float(cell_vec.loc[2].y),float(cell_vec.loc[2].z)])
atoms_n=pd.read_csv(file, delim_whitespace=True,skiprows=5,nrows=1)
data=pd.read_csv(file, delim_whitespace=True,skiprows=7,names=['x','y','z'], index_col=False)
nloops=data.x.value_counts().loc["Direct"]
n_atoms=atoms_n.T.sum().loc[0]
n1=int(sys.argv[2])
n2=int(sys.argv[3])
low=1
for i in range(nloops):
up=low+n_atoms
frame=data[low:up]
low=low+n_atoms+1
atom_pos1=frame.iloc[n1-1]
coord1=(float(atom_pos1.x)*a1)+(float(atom_pos1.y)*a2)+(float(atom_pos1.z)*a3)
atom_pos2=frame.iloc[n2-1]
coord2=(float(atom_pos2.x)*a1)+(float(atom_pos2.y)*a2)+(float(atom_pos2.z)*a3)
distance=min(np.linalg.norm(coord1-coord2),
np.linalg.norm(coord1-(coord2+a1)),
np.linalg.norm(coord1-(coord2+a2)),
np.linalg.norm(coord1-(coord2+a1+a2)),
np.linalg.norm(coord1-(coord2-a1)),
np.linalg.norm(coord1-(coord2-a2)),
np.linalg.norm(coord1-(coord2-a1-a2))
)
print(distance)
- make ""culrs.py"" executable:
chmod +x curls.py
- to run script type:
python3.6 XDATCAR <atom1_number_from_poscar> <atom2_number_from_poscar>
- to write script output to file:
python3.6 XDATCAR <atom1_number_from_poscar> <atom2_number_from_poscar> > <output.dat>