forked from ponychen123/qetools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxsd2qe.pl
executable file
·122 lines (110 loc) · 3.55 KB
/
xsd2qe.pl
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
#!perl
#this script tranform xsd file to qe input file, just set filename of xsd. but remerber to alter relative input parameters in qe.txt
#ponychen
#20190604
#email:[email protected]
use strict;
use Getopt::Long;
use MaterialsScript qw(:all);
#change following parameters depend upon you
my $filename = "00"; #your xsd file name
my $doc = $Documents{"$filename.xsd"};
my $pos = Documents->New("qe.txt"); #output txt name
my $isfrac = "True"; #True:the atom coordination are Direct False:the atom COORDINATION ARE CARTESIAN
#some inner parameters
my $lattice = $doc->SymmetryDefinition;
my $FT;
my @num_atom;
my $FT1;
my $FT2;
my $FT3;
my %element;
#some input parameters for qe
my $str1 = " &CONTROL
calculation = \'scf\' ,
restart_mode = \'from_scratch\' ,
outdir = \'./temp/\' ,
pseudo_dir = \'./\' ,
prefix = \'Fe.mag\' ,
etot_conv_thr = 1.0D-5 ,
forc_conv_thr = 1D-5 ,
nstep = 100 ,
tstress = .true. ,
tprnfor = .true. ,
/
&SYSTEM
ibrav = 0,
nat = 6,
ntyp = 1,
ecutwfc = 50 ,
ecutrho = 500 ,
occupations = \'tetrahedra_opt\' ,
! degauss = 0.002 ,
! smearing = \'marzari-vanderbilt\' ,
nspin = 2 ,
starting_magnetization(1) = 1.0,
/
&ELECTRONS
conv_thr = 1.0D-7 ,
mixing_mode = \'plain\' ,
/
&IONS
ion_dynamics = \'bfgs\' ,
/
CELL_PARAMETERS angstrom \n";
$pos->Append($str1);
#cell parameters
$pos->Append(sprintf "%f %f %f \n",$lattice->VectorA->X, $lattice->VectorA->Y, $lattice->VectorA->Z);
$pos->Append(sprintf "%f %f %f \n",$lattice->VectorB->X, $lattice->VectorB->Y, $lattice->VectorB->Z);
$pos->Append(sprintf "%f %f %f \n",$lattice->VectorC->X, $lattice->VectorC->Y, $lattice->VectorC->Z);
#sort the atom by atomic number and create a hash for between elementsymbol and atomic mass
my $atoms = $doc->UnitCell->Atoms;
my @sortedAt = sort {$a->AtomicNumber <=> $b->AtomicNumber} @$atoms;
$element{$sortedAt[0]->ElementSymbol}=$sortedAt[0]->Mass;
my $atom_num = $sortedAt[0]->AtomicNumber;
foreach my $atom (@sortedAt) {
if ($atom->AtomicNumber == $atom_num) {
next;
} else {
$element{$atom->ElementSymbol}=$atom->Mass;
$atom_num = $atom->AtomicNumber;
}
}
#pseudopotential
$pos->Append("ATOMIC_SPECIES\n");
foreach my $ele (keys %element) {
$pos->Append(sprintf " %s\t%9.6f\t***.UPF\n",$ele,$element{$ele});
}
#atom coordination
$pos->Append("ATOMIC_POSITIONS angstrom\n");
foreach my $atom (@sortedAt) {
if ($atom->IsFixed("X")) {
$FT1 = "0";
} else {
$FT1 = "1";
}
if ($atom->IsFixed("Y")) {
$FT2 = "0";
} else {
$FT2 = "1";
}
if ($atom->IsFixed("Z")) {
$FT3 = "0";
} else {
$FT3 = "1";
}
if ($atom->IsFixed("FractionalXYZ")) {
$FT = "0 0 0";
} elsif ($atom->IsFixed("XYZ")) {
$FT = "0 0 0";
} else {
$FT = "$FT1 $FT2 $FT3";
}
if ($isfrac eq "False"){
$pos->Append(sprintf "%s\t%9.6f\t%9.6f\t%9.6f\t%s\n",$atom->ElementSymbol,$atom->X,$atom->Y,$atom->Z,$FT);}
else{
$pos->Append(sprintf "%s\t%9.6f\t%9.6f\t%9.6f\t%s\n",$atom->ElementSymbol,$atom->FractionalXYZ->X,$atom->FractionalXYZ->Y,$atom->FractionalXYZ->Z,$FT);}
}
#kpoints
$pos->Append("KPOINTS automatic\n");
$pos->Append(" 2 7 3 1 1 1");