-
Notifications
You must be signed in to change notification settings - Fork 9
/
make_repr.py
executable file
·157 lines (141 loc) · 5.13 KB
/
make_repr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
#
# Using character table in format of make_repr_table.py script generated from anaddb
# utility of ABINIT package and crystallographic data in format (comment out first string,
# only representation names and characters allowed):
#
# The head of file generated with make_repr_table.py Should be modifyed by adding
# crystallographic data included inside block started by "REPRES_START" and ended with
# REPRES_STOP. Symmetry operations order in crystallographic block should be exactly the same
# as anaddb output file character table. The symmetry operations used by abinit could be translated
# from matrix form to international symbols with PHONOPY plot representation feature applied to
# FC_CONSTANTS file extracted from abinit output with ladytools utils. See the matrix labels in
# "Rotation matrices by transformation matrix" section.
#
# Example of crystallographic block:
# D2h(mmm) # 1 -1 2y my 2z mz 2x mx
#
#REPRES_START
# Ag Γ1+ 1 1 1 1 1 1 1 1
# B1g Γ3+ 1 1 -1 -1 1 1 -1 -1
# B2g Γ2+ 1 1 1 1 -1 -1 -1 -1
# B3g Γ4+ 1 1 -1 -1 -1 -1 1 1
# Au Γ1- 1 -1 1 -1 1 -1 1 -1
# B1u Γ3- 1 -1 -1 1 1 -1 -1 1
# B2u Γ2- 1 -1 1 -1 -1 1 -1 1
# B3u Γ4- 1 -1 -1 1 -1 1 1 -1
#REPRES_STOP
#
# Plot representations of phonons
#
# Author: Eugene Roginskii
#
def strType(var):
try:
if int(var) == float(var):
return 'int'
except:
try:
float(var)
return 'float'
except:
return 'str'
def isNumeric(var):
isnum=strType(var)
if (isnum == 'int' or isnum == 'float'):
return (True)
return(False)
def cmpvec(vec1,vec2,accuracy):
""" Compare vectors at a given accuracy
-1 -- wrong vector size
0 are not equivavent
1 are equivavent
"""
if((len(vec1)<3) or (len(vec2)<3)):
return(-1)
else:
k=0
for i in range(len(vec1)):
k+=abs(vec1[i]-vec2[i])
if(k>accuracy):
return(0)
else:
return(1)
import sys
import string
import re
import argparse
import numpy as np
import scipy as sc
from scipy import linalg
parser = argparse.ArgumentParser(description='Plot a table of Irreducible Representations using a given characters table. Read comments inside for instructions how to use.')
parser.add_argument('-i', '--input', required=True, type=str, dest="in_fn", help='input file name')
parser.add_argument('-o', '--output', required=True, type=str, dest="out_fn", help='output file name')
args = parser.parse_args()
if (args.in_fn == None):
print('Error. No input file name was provided')
sys.exit(1)
if (args.out_fn == None):
print('Error. No output file name was provided')
sys.exit(1)
try:
in_fh = open(args.in_fn, 'r')
except IOError:
print("ERROR Couldn't open abinit file, exiting...\n")
sys.exit(1)
cdat=[]
for line in in_fh:
if(re.match('^\s*#',line)):
continue
if(re.search('^\s*$', line)):
continue
if('REPRES_START' in line):
break
for line in in_fh:
if(re.match('^\s*#',line)):
continue
if(re.search('^\s*$', line)):
continue
if('REPRES_STOP' in line):
break
if(isNumeric(line.split()[2])):
cdat.append([line.split()[0],[float(line.split()[i]) for i in range(2,len(line.split()))]])
for c in cdat:
print(c)
try:
out_fh = open(args.out_fn, 'w')
except IOError:
print("ERROR Couldn't open abinit file, exiting...\n")
sys.exit(1)
out_fh.write(" N freq,cm-1 IR Characters\n")
for line in in_fh:
curir=""
if(re.match('^\s*#',line)):
continue
if(re.search('^\s*$', line)):
continue
if(isNumeric(line.split()[3])):
print("=== Mode %s ===" % line.split()[0])
buf=[float(line.split()[i]) for i in range(3,len(line.split()))]
print("%s %s" % (line.split()[1], "".join("%s " % buf[i] for i in range(len(buf)))))
for i in range(len(cdat)):
if(cmpvec(cdat[i][1],buf,0.01) == 1):
print("Found chars: %s" % "".join("%3.1f " % cdat[i][1][k] for k in range(len(cdat[i][1]))))
curir=cdat[i][0]
break
print("%10s %4s" % (line.split()[1],curir))
out_fh.write("%4d %8.2f %4s %s\n" %( int(line.split()[0]), float(line.split()[1]), curir, "".join("% 4.1f " % cdat[i][1][k] for k in range(len(cdat[i][1]))) ))