1 | #!/usr/bin/perl
|
---|
2 |
|
---|
3 | $basisname = $ARGV[0];
|
---|
4 | $basisname =~ s/.nw$//;
|
---|
5 |
|
---|
6 | $name{"H"}="hydrogen";
|
---|
7 | $name{"He"}="helium";
|
---|
8 | $name{"Li"}="lithium";
|
---|
9 | $name{"Be"}="beryllium";
|
---|
10 | $name{"B"}="boron";
|
---|
11 | $name{"C"}="carbon";
|
---|
12 | $name{"N"}="nitrogen";
|
---|
13 | $name{"O"}="oxygen";
|
---|
14 | $name{"F"}="fluorine";
|
---|
15 | $name{"Ne"}="neon";
|
---|
16 | $name{"Na"}="sodium";
|
---|
17 | $name{"Mg"}="magnesium";
|
---|
18 | $name{"Al"}="aluminum";
|
---|
19 | $name{"Si"}="silicon";
|
---|
20 | $name{"P"}="phosphorus";
|
---|
21 | $name{"S"}="sulfur";
|
---|
22 | $name{"Cl"}="chlorine";
|
---|
23 | $name{"Ar"}="argon";
|
---|
24 | $name{"K"}="potassium";
|
---|
25 | $name{"Ca"}="calcium";
|
---|
26 | $name{"Sc"}="scandium";
|
---|
27 | $name{"Ti"}="titanium";
|
---|
28 | $name{"V"}="vanadium";
|
---|
29 | $name{"Cr"}="chromium";
|
---|
30 | $name{"Mn"}="manganese";
|
---|
31 | $name{"Fe"}="iron";
|
---|
32 | $name{"Co"}="cobalt";
|
---|
33 | $name{"Ni"}="nickel";
|
---|
34 | $name{"Cu"}="copper";
|
---|
35 | $name{"Zn"}="zinc";
|
---|
36 | $name{"Ga"}="gallium";
|
---|
37 | $name{"Ge"}="germanium";
|
---|
38 | $name{"As"}="arsenic";
|
---|
39 | $name{"Se"}="selenium";
|
---|
40 | $name{"Br"}="bromine";
|
---|
41 | $name{"Kr"}="krypton";
|
---|
42 | $name{"Rb"}="rubidium";
|
---|
43 | $name{"Sr"}="strontium";
|
---|
44 | $name{"Y"}="yttrium";
|
---|
45 | $name{"Zr"}="zirconium";
|
---|
46 | $name{"Nb"}="niobium";
|
---|
47 | $name{"Mo"}="molybdenum";
|
---|
48 | $name{"Tc"}="technetium";
|
---|
49 | $name{"Ru"}="ruthenium";
|
---|
50 | $name{"Rh"}="rhodium";
|
---|
51 | $name{"Pd"}="palladium";
|
---|
52 | $name{"Ag"}="silver";
|
---|
53 | $name{"Cd"}="cadminium";
|
---|
54 | $name{"In"}="indium";
|
---|
55 | $name{"Sn"}="tin";
|
---|
56 | $name{"Sb"}="antimony";
|
---|
57 | $name{"Te"}="tellurium";
|
---|
58 | $name{"I"}="iodine";
|
---|
59 | $name{"Xe"}="xenon";
|
---|
60 | $name{"Cs"}="cesium";
|
---|
61 | $name{"Ba"}="barium";
|
---|
62 | $name{"La"}="lanthanium";
|
---|
63 | $name{"Ce"}="cerium";
|
---|
64 | $name{"Pr"}="praseodymium";
|
---|
65 | $name{"Nd"}="neodymium";
|
---|
66 | $name{"Pm"}="promethium";
|
---|
67 | $name{"Sm"}="samarium";
|
---|
68 | $name{"Eu"}="europium";
|
---|
69 | $name{"Gd"}="gadolinium";
|
---|
70 | $name{"Tb"}="terbium";
|
---|
71 | $name{"Dy"}="dysprosium";
|
---|
72 | $name{"Ho"}="holmium";
|
---|
73 | $name{"Er"}="erbium";
|
---|
74 | $name{"Tm"}="thulium";
|
---|
75 | $name{"Yb"}="ytterbium";
|
---|
76 | $name{"Lu"}="lutetium";
|
---|
77 | $name{"Hf"}="hafnium";
|
---|
78 | $name{"Ta"}="tantalum";
|
---|
79 | $name{"W"}="tungsten";
|
---|
80 | $name{"Re"}="rhenium";
|
---|
81 | $name{"Os"}="osmium";
|
---|
82 | $name{"Ir"}="iridium";
|
---|
83 | $name{"Pt"}="platinum";
|
---|
84 | $name{"Au"}="gold";
|
---|
85 | $name{"Hg"}="mercury";
|
---|
86 | $name{"Tl"}="thallium";
|
---|
87 | $name{"Pb"}="lead";
|
---|
88 | $name{"Bi"}="bismuth";
|
---|
89 | $name{"Po"}="polonium";
|
---|
90 | $name{"At"}="astatine";
|
---|
91 | $name{"Rn"}="radon";
|
---|
92 | $name{"Fr"}="francium";
|
---|
93 | $name{"Ra"}="radium";
|
---|
94 | $name{"Ac"}="actinium";
|
---|
95 | $name{"Th"}="thorium";
|
---|
96 | $name{"Pa"}="protactinium";
|
---|
97 | $name{"U"}="uranium";
|
---|
98 | $name{"Np"}="neptunium";
|
---|
99 | $name{"Pu"}="plutonium";
|
---|
100 | $name{"Am"}="americium";
|
---|
101 | $name{"Cm"}="curium";
|
---|
102 | $name{"Bk"}="berkelium";
|
---|
103 | $name{"Cf"}="californium";
|
---|
104 | $name{"Es"}="einsteinum";
|
---|
105 | $name{"Fm"}="fermium";
|
---|
106 | $name{"Md"}="mendelevium";
|
---|
107 | $name{"No"}="nobelium";
|
---|
108 | $name{"Lr"}="lawrencium";
|
---|
109 |
|
---|
110 | $atom = none;
|
---|
111 | $retrieve = 0;
|
---|
112 | $pure = 0;
|
---|
113 | $pured = 0; # if $pure or $pured d's are pure
|
---|
114 | $puref = 1; # if $pure or $puref f's are pure; by default all f's are pure
|
---|
115 | # make sure puream is 1 for correlation consistent and ano basis sets
|
---|
116 | # and 6-311g and sto-ng
|
---|
117 | if ($basisname =~ /cc-p/ || $basisname =~ /ANO/
|
---|
118 | || $basisname =~ /^6-311G/
|
---|
119 | || $basisname =~ /^6-311\+/
|
---|
120 | || $basisname =~ /^STO-[1-9]G/
|
---|
121 | ) {
|
---|
122 | $pure = 1;
|
---|
123 | }
|
---|
124 | $basisname =~ tr/A-Z/a-z/;
|
---|
125 | $basisname =~ tr/+/P/;
|
---|
126 | $basisname =~ tr/\*/S/;
|
---|
127 | $basisname =~ tr/\(/L/;
|
---|
128 | $basisname =~ tr/\)/R/;
|
---|
129 | $basisname =~ tr/,/_/;
|
---|
130 | $basisname =~ tr/ /_/;
|
---|
131 | printf "Reading NWChem basis from %s.nw\n", $basisname;
|
---|
132 | printf "Writing MPQC basis to %s.kv\n", $basisname;
|
---|
133 | open(NWCHEMBASIS, "<$basisname.nw");
|
---|
134 | open(MPQCBASIS, ">$basisname.kv");
|
---|
135 | #open(MPQCBASIS, "|cat");
|
---|
136 | $firstatom=1;
|
---|
137 | $savedcomments="";
|
---|
138 | while (<NWCHEMBASIS>) {
|
---|
139 | # print;
|
---|
140 | # next;
|
---|
141 | GOTLINE:
|
---|
142 | #printf "-----> %s\n", $_;
|
---|
143 | if (/^ *(BASIS.* +[^ ]* +)([A-Z]*)/) {
|
---|
144 | $retrieve = 1;
|
---|
145 | $spherical_option = $2;
|
---|
146 | $basis = $1;
|
---|
147 | $line = "$1$2";
|
---|
148 | $basis =~ s/^[^\"]*\"//; #"
|
---|
149 | $basis =~ s/\"[^\"]*$//; #"
|
---|
150 | printf "Basis = %s\n", $basis;
|
---|
151 | if ($spherical_option eq "SPHERICAL") {
|
---|
152 | $pure = 1;
|
---|
153 | }
|
---|
154 | #printf "%s\n", $line;
|
---|
155 | printf MPQCBASIS "%%%s\n", $line;
|
---|
156 | }
|
---|
157 | elsif (/^ *END/) {
|
---|
158 | $retrieve = 0;
|
---|
159 | }
|
---|
160 | elsif (/^ *\#(.*)/) {
|
---|
161 | my $comment = $1;
|
---|
162 | $comment =~ s/ *$//;
|
---|
163 | $savedcomments = sprintf("%s%%%s\n", $savedcomments, $comment);
|
---|
164 | }
|
---|
165 | elsif ($retrieve == 1) {
|
---|
166 | /^(.*)/;
|
---|
167 | $_ = $1;
|
---|
168 | #printf "%s\n", $_;
|
---|
169 | if (/^ *([A-Z][a-z]*) +([A-Za-z]+)/) {
|
---|
170 | if (!($1 eq $atom)) {
|
---|
171 | if ($atom eq none) {
|
---|
172 | $atom = $1;
|
---|
173 | my $am = $2;
|
---|
174 | print "first shell: atom = $atom am = $am\n";
|
---|
175 | &start_atom;
|
---|
176 | &start_shell($am);
|
---|
177 | }
|
---|
178 | else {
|
---|
179 | &finish_shell;
|
---|
180 | &finish_atom;
|
---|
181 | $atom = $1;
|
---|
182 | my $am = $2;
|
---|
183 | print "new atom: atom = $atom am = $am\n";
|
---|
184 | &start_atom;
|
---|
185 | &start_shell($am);
|
---|
186 | }
|
---|
187 | }
|
---|
188 | else {
|
---|
189 | &finish_shell;
|
---|
190 | my $am = $2;
|
---|
191 | print "new shell on old atom: atom = $atom am = $am\n";
|
---|
192 | &start_shell($am);
|
---|
193 | }
|
---|
194 | goto GOTLINE;
|
---|
195 | }
|
---|
196 | else {
|
---|
197 | $exp_coef_lines[$#exp_coef_lines+1] = $1;
|
---|
198 | }
|
---|
199 | }
|
---|
200 | }
|
---|
201 | if (!($atom eq none)) {
|
---|
202 | &finish_shell;
|
---|
203 | &finish_atom;
|
---|
204 | }
|
---|
205 | printf MPQCBASIS "%s", $savedcomments;
|
---|
206 | $savedcomments = "";
|
---|
207 | printf MPQCBASIS ")\n";
|
---|
208 | close(MPQCBASIS);
|
---|
209 | close(NWCHEMBASIS);
|
---|
210 |
|
---|
211 |
|
---|
212 | sub start_atom {
|
---|
213 | if ($firstatom) {
|
---|
214 | print MPQCBASIS "basis:(\n";
|
---|
215 | $firstatom=0;
|
---|
216 | }
|
---|
217 | printf MPQCBASIS "%s", $savedcomments;
|
---|
218 | $savedcomments = "";
|
---|
219 | printf MPQCBASIS " %s: \"%s\": [\n", $name{$atom}, $basis;
|
---|
220 | }
|
---|
221 |
|
---|
222 | sub finish_atom {
|
---|
223 | printf MPQCBASIS " ]\n";
|
---|
224 | }
|
---|
225 |
|
---|
226 | sub start_shell {
|
---|
227 | my $am = shift;
|
---|
228 |
|
---|
229 | printf MPQCBASIS "%s", $savedcomments;
|
---|
230 | $savedcomments = "";
|
---|
231 | while (<NWCHEMBASIS>) {
|
---|
232 | last;
|
---|
233 | }
|
---|
234 | @coefandexp = split;
|
---|
235 | $ncoef = $#coefandexp;
|
---|
236 | my $amlower = $am;
|
---|
237 | $amlower =~ tr/A-Z/a-z/;
|
---|
238 | printf MPQCBASIS " (type:";
|
---|
239 | if ($amlower eq "sp") {
|
---|
240 | printf MPQCBASIS " [am = p am = s]\n";
|
---|
241 | }
|
---|
242 | else {
|
---|
243 | printf MPQCBASIS " [", $amlower;
|
---|
244 | $icoef = 0;
|
---|
245 | while ($icoef < $ncoef) {
|
---|
246 | if ($icoef != 0) {
|
---|
247 | printf MPQCBASIS " ";
|
---|
248 | }
|
---|
249 | if ((($amlower eq "d") && $pured) || (($amlower eq "f") && $puref)) {
|
---|
250 | printf MPQCBASIS "(am = %s puream = 1)", $amlower;
|
---|
251 | }
|
---|
252 | elsif ($amlower eq "s" || $amlower eq "p" || !$pure) {
|
---|
253 | printf MPQCBASIS "am = %s", $amlower;
|
---|
254 | }
|
---|
255 | else {
|
---|
256 | printf MPQCBASIS "(am = %s puream = 1)", $amlower;
|
---|
257 | }
|
---|
258 | $icoef++;
|
---|
259 | }
|
---|
260 | printf MPQCBASIS "]\n", $amlower;
|
---|
261 | }
|
---|
262 | printf MPQCBASIS " {exp";
|
---|
263 | if ($amlower eq "sp") {
|
---|
264 | printf MPQCBASIS " coef:1 coef:0";
|
---|
265 | }
|
---|
266 | else {
|
---|
267 | $icoef = 0;
|
---|
268 | while ($icoef < $ncoef) {
|
---|
269 | printf MPQCBASIS " coef:%d", $icoef;
|
---|
270 | $icoef++;
|
---|
271 | }
|
---|
272 | }
|
---|
273 | printf MPQCBASIS "} = {\n";
|
---|
274 | }
|
---|
275 |
|
---|
276 | # This does the formatting of the exponent/coefficient lines in a way to
|
---|
277 | # make the lines the same as the original format, if possible. This has
|
---|
278 | # the advantage making easier to examine diffs of the basis sets to check
|
---|
279 | # for problems.
|
---|
280 | sub print_lines_1 {
|
---|
281 | my $i;
|
---|
282 |
|
---|
283 | foreach $i (0..$#exp_coef_lines) {
|
---|
284 | $exp_coef_lines[$i] =~ s/^ +//;
|
---|
285 | $exp_coef_lines[$i] =~ s/ +$//;
|
---|
286 | }
|
---|
287 |
|
---|
288 | my $remove_last_digit_from_exponent = 1;
|
---|
289 | foreach $i (0..$#exp_coef_lines) {
|
---|
290 | my $line = $exp_coef_lines[$i];
|
---|
291 | @fields = split(/ +/,$line);
|
---|
292 | my $exponent = $fields[0];
|
---|
293 | if (!($exponent =~ /0$/)) {
|
---|
294 | $remove_last_digit_from_exponent = 0;
|
---|
295 | }
|
---|
296 | if (&nright($exponent) == 8) {
|
---|
297 | $remove_last_digit_from_exponent = 0;
|
---|
298 | }
|
---|
299 | }
|
---|
300 |
|
---|
301 | foreach $i (0..$#exp_coef_lines) {
|
---|
302 | my $line = $exp_coef_lines[$i];
|
---|
303 | @fields = split(/ +/,$line);
|
---|
304 | my $exponent = $fields[0];
|
---|
305 | if ($remove_last_digit_from_exponent == 1) {
|
---|
306 | $exponent =~ s/0$//;
|
---|
307 | }
|
---|
308 | printf MPQCBASIS " %s%s", &space(5,$exponent), $exponent;
|
---|
309 | foreach $i (1..$#fields) {
|
---|
310 | my $coef = $fields[$i];
|
---|
311 | if (!($coef =~ /^-/)) {
|
---|
312 | $coef = " $coef";
|
---|
313 | }
|
---|
314 | printf MPQCBASIS " %s%s", &space(5,$coef), $coef;
|
---|
315 | }
|
---|
316 | print MPQCBASIS "\n";
|
---|
317 | }
|
---|
318 | }
|
---|
319 |
|
---|
320 | # This is a very simple printout of the lines.
|
---|
321 | sub print_lines_2 {
|
---|
322 | my $i;
|
---|
323 | foreach $i (0..$#exp_coef_lines) {
|
---|
324 | printf MPQCBASIS "%s\n", $exp_coef_lines[$i];
|
---|
325 | }
|
---|
326 | }
|
---|
327 |
|
---|
328 | sub finish_shell {
|
---|
329 | &print_lines_2();
|
---|
330 |
|
---|
331 | $#exp_coef_lines = -1;
|
---|
332 | printf MPQCBASIS " })\n";
|
---|
333 | }
|
---|
334 |
|
---|
335 | sub space {
|
---|
336 | my $n = shift;
|
---|
337 | my $f = shift;
|
---|
338 |
|
---|
339 | my $left_digits = $f;
|
---|
340 | $left_digits =~ s/\..*//;
|
---|
341 | my $nleft = length($left_digits);
|
---|
342 |
|
---|
343 | my $nspace = $n - $nleft;
|
---|
344 |
|
---|
345 | my $i;
|
---|
346 | my $res = "";
|
---|
347 | foreach $i (0..$nspace-1) {
|
---|
348 | $res = " $res";
|
---|
349 | }
|
---|
350 |
|
---|
351 | return $res;
|
---|
352 | }
|
---|
353 |
|
---|
354 | sub nright {
|
---|
355 | my $f = shift;
|
---|
356 |
|
---|
357 | my $right_digits = $f;
|
---|
358 | $right_digits =~ s/.*\.//;
|
---|
359 | return length($right_digits);
|
---|
360 | }
|
---|