File: runDFTBPGabedit

package info (click to toggle)
gabedit 2.5.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,476 kB
  • sloc: ansic: 319,608; cpp: 2,081; sh: 1,573; makefile: 577; csh: 181
file content (274 lines) | stat: -rw-r--r-- 5,996 bytes parent folder | download | duplicates (2)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
# requirement : dftb+-1.3 xyz2gen tool,  see : https://www.dftb-plus.info/tools/dptools/

filename=$1 ; [ 0 = $# ] || shift
outname=$1 ; [ 0 = $# ] || shift

if [ -z "$filename" ]
then
   clear
   echo " " 
   echo "==========================================="
   echo "                 runDFTBGabedit "
   echo "-------------------------------------------"
   echo "Example:"
   echo "       runDFTBGabedit h2.inp h2.out "
   echo "==========================================="
   echo " " 
   exit 1
fi
fileinp=$filename
filename=${fileinp%.inp}
filename=${filename%.com}

DEFAULTDIR=`pwd`
if test ! -s "$fileinp"
then
   echo " " 
   echo "============================================"
   echo " I cannot find $fileinp file"
   echo "============================================"
   echo " " 
   exit 2
fi

cd $DEFAULTDIR
#cat $fileinp
fn=`echo "$filename" | sed "s/.*\///" | sed "s/\..*//"`
ffn=${fn}_$$
#echo $fn

fxyz=${ffn}.xyz
#create xyz file
awk 'BEGIN{
	natoms=0;
}
{
	i++;
	#printf("i=%d s=%s\n",i,$1);
	if(i==1) option=$1
	if(i==3) 
	{ 
		natoms=$1
		charge=$2 
		mult=$3
		printf("%d\n",natoms);
		printf("%s\n",option);
	}
	if(i>3 && i<=natoms+3)
	{
		printf("%s %s %s %s\n",$1,$9,$10,$11);
	}
}
END{
}' $fileinp > $fxyz

# convert xyz in gen file
xyz2gen $fxyz

fhsd=${ffn}.hsd
fgen=${ffn}.gen
echo "Geometry = GenFormat {" > $fhsd
echo "  <<< \"$fgen\"" >> $fhsd
echo "}">>$fhsd

awk -v ffn=$ffn 'BEGIN{
i=1
}
{
	if(i==1) 
	{
		option=$1
		if(option==2)
		{
			printf("Driver = ConjugateGradient {\n");
			printf("MovedAtoms = 1:-1\n");
			printf("MaxForceComponent = 1.0e-4\n");
			printf("MaxSteps = 200\n");
			printf("OutputPrefix = \"geomOpt\"\n",ffn);
			printf("}\n");
		}
		if(option==1)
		{
			printf("Options{ CalculateForces = Yes }\n");
		}
		exit 1
	}
}
END{
}' $fileinp >> $fhsd

fxyzOpt=${ffn}Opt.xyz

echo "Hamiltonian = DFTB {" >> $fhsd
echo "  SCC = Yes" >> $fhsd
echo "  SCCTolerance = 1.0E-5" >> $fhsd
echo "  MaxSCCIterations = 50" >> $fhsd
echo "  MaxAngularMomentum = {" >> $fhsd
AT=H && n=(`grep -c $AT $fxyz`) && [ n > 0 ] && echo "$AT = \"s\"" >> $fhsd
AT=C && n=(`grep -c $AT $fxyz`) && [ n > 0 ] && echo "$AT = \"p\"" >> $fhsd
AT=O && n=(`grep -c $AT $fxyz`) && [ n > 0 ] && echo "$AT = \"p\"" >> $fhsd
AT=N && n=(`grep -c $AT $fxyz`) && [ n > 0 ] && echo "$AT = \"p\"" >> $fhsd
AT=P && n=(`grep -c $AT $fxyz`) && [ n > 0 ] && echo "$AT = \"p\"" >> $fhsd
echo "  }" >> $fhsd

echo "  Filling = Fermi {">> $fhsd
echo "      Temperature [Kelvin] = 20">> $fhsd
echo "  }" >> $fhsd
echo "  SlaterKosterFiles = Type2FileNames {" >> $fhsd
echo "        Prefix = "/home/allouche/Softwares/DFTBP/parameters/mio-1-1/"" >> $fhsd
echo "        Separator = \"-\"" >> $fhsd
echo "        Suffix = \".skf\"" >> $fhsd
echo "  }" >> $fhsd
echo "}" >> $fhsd
echo "ParserOptions = {" >> $fhsd
echo "ParserVersion = 3" >> $fhsd
echo "}" >> $fhsd


#echo "==========================================================="
#echo "FHSD=$fhsd"
#cat $fhsd
#echo "==========================================================="

# RUN DFTB+
CURDIR=$PWD
export OMP_NUM_THREADS=1
export OUT=$CURDIR/${ffn}.log
echo "DIR=$CURDIR" > $OUT
[ -d /opt/tmp/$LOGNAME ] || mkdir /opt/tmp/$LOGNAME
x=$$
export TMPD=/opt/tmp/$LOGNAME/${ffn}$x
mkdir $TMPD
cp $fgen $TMPD/.
cp $fhsd $TMPD/dftb_in.hsd
cd $TMPD
/home/allouche/Softwares/DFTBP/bin/dftb+ >>  $OUT
echo "=================================================================" >>  $OUT
echo "TMPD=$TMPD" >> $OUT
if test -s "$TMPD/geomOpt.xyz"
then
echo "GEOMETRY XYZ" >> $OUT
cat $TMPD/geomOpt.xyz >> $OUT
echo "=================================================================" >>  $OUT
fi

if test -s "$TMPD/geomOpt.gen"
then
echo "GEOMETRY GEN" >> $OUT
cat $TMPD/geomOpt.gen >> $OUT
echo "=================================================================" >>  $OUT
fi

if test -s "$TMPD/detailed.out"
then
echo "DETAILED" >> $OUT
cat $TMPD/detailed.out >> $OUT
echo "=================================================================" >>  $OUT
fi


if test -s "$TMPD/hessian.out"
then
echo "HESSIAN" >> $OUT
cat $TMPD/hessian.out >> $OUT
echo "=================================================================" >>  $OUT
fi
cd ..
/bin/rm -r $TMPD
cd $CURDIR

#echo see $OUT file

tmpfile=${ffn}.tmp
grep 'Total Energy:' $OUT | tail -1 > ${ffn}.tmp
#echo tmp=$tmpfile
#cat $tmpfile
energy=$(awk '{printf("%f",$3);}' $tmpfile)
#echo "======================="
#echo "WARNING dipole set to 0"
#echo "======================="
echo "0.0" > $tmpfile
echo "0.0" >> $tmpfile
echo "0.0" >> $tmpfile
read mux muy muz <<< $(cat $tmpfile | awk '{ print $1; }')
#echo Mu = $mux $muy $muz
#echo $outname
echo $energy >  $outname
echo $mux $muy $muz >>  $outname
#echo 
awk 'BEGIN{
id=0
}
{
	if(id==1)
	{ 
		if(NF != 3) id++; 
		else printf("%s %s %s\n",$1,$2,$3);
	}  
	if($0 ~ /Total Forces/) { id=1;}
}' $OUT >  $tmpfile

#echo TMPFILE  ===================
#cat  $tmpfile
#echo END TMPFILE ========================
cat  $tmpfile >> $outname

#cat $outname

# get natoms charge and mult
awk 'BEGIN{
	natoms=0;
	i=0
}
{
	i++;
	#printf("i=%d s=%s\n",i,$1);
	if(i==3) 
	{ 
		natoms=$1
		charge=$2 
		mult=$3
		printf("%s\n%s\n%s\n",natoms, charge, mult);
		exit 0
	}
}
END{
}' $fileinp > $tmpfile
read natoms charge spin muz <<< $(cat $tmpfile | awk '{ print $1; }')

awk 'BEGIN{
id=0
idd=0
}
{
	if(id>=1) { id++;}
	if(id>3) if(NF<4) { id=0; exit 0;}
	if(id>3) { printf(" %s %s %s %s 0 0.0 2 1 %s %s %s 0\n",$1,$1,$1,$1,$2,$3,$4); }  
	if($0 ~ /GEOMETRY XYZ/) { id=1;}
}' $OUT > $tmpfile

n=(`grep -c "Geometry did NOT converge" $OUT`)
[ "$n" -gt 0 ] && echo "WARNING!!!!!!!!!!!!!!!!!!!!!!!!!"
grep 'Geometry did NOT converge' $OUT
[ "$n" -gt 0 ] && echo "================================================================="

nl=`wc -l < $tmpfile`
if [ $nl != "0" ]
then
echo Geometry >> $outname
echo $natoms $charge $spin >> $outname
cat $tmpfile >> $outname
fi



#echo file=$outname
#cat $outname

rm $fhsd
rm $fgen
rm $fxyz
rm $tmpfile
rm $OUT