Skip to content
Snippets Groups Projects
Commit 3901b26e authored by Yakubov, Sergey's avatar Yakubov, Sergey
Browse files

add source file and Docker config

parent c5a91649
No related branches found
No related tags found
No related merge requests found
Pipeline #364805 passed with stage
in 21 seconds
#
source code
# This project contains source code and Dockerfile for the amml convert application
FROM ubuntu:20.04
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && apt-get -y install tzdata
#RUN DEBIAN_FRONTEND="noninteractive" apt-get update && apt-get -y install tzdata
RUN apt-get update \
&& apt-get install -y \
python3 \
python3-pip \
&& apt-get clean
RUN pip3 install scipy numpy matplotlib
COPY /src /src
COPY /src /app
#! /usr/bin/env python3
import sys, os, re
import fnmatch
def get_outcar(file_outcar):
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Input: OUTCAR from VASP
# Output: phonon frequencies and modes (gamma point only)
f = open(file_outcar,'r')
full_text = f.read()
f.close()
aux = re.compile('(?=ions per type)(.*?)(?=\n)',
re.DOTALL).findall(full_text)
line = list(map(int,aux[len(aux)-1].split('=')[1].split()))
tp = []
for i in range(len(line)):
for j in range(line[i]):
tp.append(i)
virial = []
'''
aux = re.compile('(?=in kB)(.*?)(?=external pressure)',
re.DOTALL).findall(full_text)
for i in range(len(aux)):
press = list(map(float,aux[i].split('\n')[0].split()[2:8]))
v0 = list(map(lambda x: x*1.0e3, [press[0],press[3],press[5],press[3],press[1],press[4],press[5],press[4],press[2]]))
virial.append(v0)
'''
box = []
aux = re.compile('(?=VOLUME and BASIS-vectors are now)(.*?)(?=length of vectors)',
re.DOTALL).findall(full_text)
for i in range(len(aux)):
b0 = list(map(float,aux[i].split('\n')[5].split()[0:3]))
b0 += list(map(float,aux[i].split('\n')[6].split()[0:3]))
b0 += list(map(float,aux[i].split('\n')[7].split()[0:3]))
box.append(b0)
coord = []
force = []
aux = re.compile('(?=TOTAL-FORCE)(.*?)(?=total drift)',
re.DOTALL).findall(full_text)
for i in range(len(aux)):
c0 = []
f0 = []
block = aux[i].split('\n')[2:-2]
for j in range(len(block)):
c0 += list(map(float,block[j].split()[0:3]))
f0 += list(map(float,block[j].split()[3:6]))
coord.append(c0)
force.append(f0)
energy = []
#aux = re.compile('(?=ion-electron TOTEN)(.*?)(?=\n)',
aux = re.compile('(?=free energy TOTEN )(.*?)(?=\n)',
re.DOTALL).findall(full_text)
for i in range(len(aux)):
energy.append(float(aux[i].split('=')[1].split()[0]))
return tp,box,coord,force,energy,virial
#
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
def get_cp2k_cell(files):
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Input:
# Output:
pattern = '*.inp'
file_name = fnmatch.filter(files, pattern)[0]
f = open(file_name,'r')
full_text = f.read()
f.close()
aux = re.compile('(?=&CELL)(.*?)(?=&END CELL)',
re.DOTALL).findall(full_text)
A = aux[0].split('\n')
cell = []
cell += (map(float,A[1].split()[1:4]))
cell += list(map(float,A[2].split()[1:4]))
cell += list(map(float,A[3].split()[1:4]))
return cell
#
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
def get_cp2k_coord(files,cell):
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Input:
# Output:
pattern = '*_pos.xyz'
file_name = fnmatch.filter(files, pattern)[0]
f = open(file_name,'r')
full_text = f.read()
f.close()
ha2ev = 27.2114
A = full_text.strip().split('\n')
na = int(A[0])
if len(A)%(na+2)!=0:
print("check file length")
nt = int(len(A)/(na+2))
coord = [[0 for x in range(3*na)] for x in range(nt)]
symbol = []
box = []
energy = []
for it in range(nt):
box.append(cell)
energy.append(float(A[it*(na+2)+1].split()[-1])*ha2ev)
for ia in range(na):
i = it*(na+2)+ia+2
xyz = list(map(float, A[i].split()[1:4]))
coord[it][3*ia] = xyz[0]
coord[it][3*ia+1] = xyz[1]
coord[it][3*ia+2] = xyz[2]
if it == 0:
symbol.append(A[i].split()[0])
tp = [0]
for ia in range(1,na):
if symbol[ia]==symbol[ia-1]:
tp.append(tp[-1])
else:
tp.append(tp[-1]+1)
return tp,box,energy,coord
#
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
def get_cp2k_force(files):
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Input:
# Output:
pattern = '*_force.xyz'
file_name = fnmatch.filter(files, pattern)[0]
f = open(file_name,'r')
full_text = f.read()
f.close()
hab2eva = 51.42208619083232
A = full_text.strip().split('\n')
na = int(A[0])
if len(A)%(na+2)!=0:
print("check file length")
nt = int(len(A)/(na+2))
force = [[0 for x in range(3*na)] for x in range(nt)]
for it in range(nt):
for ia in range(na):
i = it*(na+2)+ia+2
xyz = list(map(float, A[i].split()[1:4]))
force[it][3*ia] = xyz[0]*hab2eva
force[it][3*ia+1] = xyz[1]*hab2eva
force[it][3*ia+2] = xyz[2]*hab2eva
return force
#
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
def write_raw(tp,box,coord,force,energy,virial):
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# Write raw files
#
n = min(len(box),len(coord),len(force),len(energy))
print(len(box),len(coord),len(force),len(energy))
f = open('box.raw','w')
for i in range(n):
print(' '.join(map(str, box[i])),file=f)
f.close()
f = open('coord.raw','w')
for i in range(n):
print(' '.join(map(str, coord[i])),file=f)
f.close()
f = open('force.raw','w')
for i in range(n):
print(' '.join(map(str, force[i])),file=f)
f.close()
f = open('energy.raw','w')
for i in range(n):
print(str(energy[i]),file=f)
f.close()
if virial:
f = open('virial.raw','w')
for i in range(len(virial)):
print(' '.join(map(str, virial[i])),file=f)
f.close()
f = open('type.raw','w')
print(' '.join(map(str, tp)),file=f)
f.close()
#
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#=============================================================================
# Main program starts here
#
if '-vo' in sys.argv: # from VASP OUTCAR
i=sys.argv.index('-vo')
tp,box,coord,force,energy,virial = get_outcar(sys.argv[i+1])
if '-cp2k' in sys.argv: # from CP2K folder
cell = get_cp2k_cell(sys.argv)
tp,box,energy,coord = get_cp2k_coord(sys.argv,cell)
force = get_cp2k_force(sys.argv)
virial = []
if not(len(box)==len(coord)==len(force)==len(energy)):
print("error: number of frames inconsistent")
print(len(box),len(coord),len(force),len(energy))
sys.exit()
write_raw(tp,box,coord,force,energy,virial)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment