DV_creator.py 3.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
####################################################################################################
## Copyright (C) 2020 Udo von Toussaint, F. J. Dominguez-Gutierrez, Michele Compostella, Markus Rampp
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
##
#####################################################################################################
##
## General Notes:
Michele Compostella's avatar
Michele Compostella committed
22
## FaVAD: Fingerprinting And Visualization Analyzer of Defects. Version: 1.0
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
## Python script to generate the set of standard descriptor vectors
## Please modify the code to create the chosen reference descriptor vector of the standard defect
## The geometry of the standard defect is defined in a xyz file
##
#####################################################################################################

import numpy as np
from numpy import *
import matplotlib.pyplot as plt
import linecache
import subprocess
import sys
#########################################################
num_lines = sum(1 for line in open('bcc_geometry.xyz'))
num_atom = int(linecache.getline('bcc_geometry.xyz',1))
print('checking xyz file')
num_lines = num_lines-2
if ( num_lines== num_atom): 
   print('xyz is in good shape')
else:
   sys.exit("xyz file corrupted, please check its format")
##### computing descriptor vectors of damaged sample ####
print('computing standard descriptor vector')
# command line for hundreds to thousands of atoms
cmd = 'quip atoms_filename=bcc_geometry.xyz descriptor_str="soap cutoff=3.0 l_max=4 n_max=4 atom_sigma=0.5 n_Z=1 Z={74} n_species=1 species_Z={74}" > vectors.dat'
#
subprocess.call(cmd,shell=True)

i = 0
arr = []
# Cleaning quip output file
# Start reading DV at line 11
for i in range(11,11+num_atom):
     dv_1 = np.array(linecache.getline('vectors.dat',i)[7::].split())
     dv = dv_1.astype(np.float)
     arr.append(dv)

arr = np.array(arr)
#### Printing out results
#### bcc DV ##################################
print('Results are given in: bcc_vector.dat')
file_1 = open('bcc_vector.dat','w')
for i in range(0,51):
    file_1.write("{0} \n".format(arr[0,i]))


#### interstitial DV ##################################
#print('Results are given in: interstitial_vector.dat')
#file_1 = open('interstitial_vector.dat','w')
#for i in range(0,51):
73
#    file_1.write("{0} \n".format(arr[432,i]))
74

75
#### vacancy DV ##################################
76 77 78
#print('Results are given in: vacancy_vector.dat')
#file_1 = open('vacancy_vector.dat','w')
#for i in range(0,51):
79
#    file_1.write("{0} \n".format(arr[274,i]))
80

81 82 83 84 85
#### typea DV ##################################
print('Results are given in: typea_vector.dat')
file_1 = open('typea_vector.dat','w')
for i in range(0,51):
    file_1.write("{0} \n".format(arr[273,i]))
86 87 88 89 90 91 92 93



#cleaning files
print('cleaning...')
cmd1 = 'rm vectors.dat'
subprocess.call(cmd1,shell=True)
print('Done!')