Debian Codegraph @

cclib/parser/turbomoleparser.py

raw
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (c) 2018, the cclib development team
4 #
5 # This file is part of cclib (http://cclib.github.io) and is distributed under
6 # the terms of the BSD 3-Clause License.
7
8 """Parser for Turbomole output files."""
9
10 from __future__ import print_function
11
12 import re
13
14 import numpy
15
16 from cclib.parser import logfileparser
17 from cclib.parser import utils
18
19 class AtomBasis:
20 def __init__(self, atname, basis_name, inputfile):
21 self.symmetries=[]
22 self.coefficients=[]
23 self.atname=atname
24 self.basis_name=basis_name
25
26 self.parse_basis(inputfile)
27
28 def parse_basis(self, inputfile):
29 i=0
30 line=inputfile.next()
31
32 while(line[0]!="*"):
33 (nbasis_text, symm)=line.split()
34 self.symmetries.append(symm)
35
36 nbasis=int(nbasis_text)
37 coeff_arr=numpy.zeros((nbasis, 2), float)
38
39 for j in range(0, nbasis, 1):
40 line=inputfile.next()
41 (e1_text, e2_text)=line.split()
42 coeff_arr[j][0]=float(e1_text)
43 coeff_arr[j][1]=float(e2_text)
44
45 self.coefficients.append(coeff_arr)
46 line=inputfile.next()
47
48 class Turbomole(logfileparser.Logfile):
49 """A Turbomole log file."""
50
51 def __init__(self, *args, **kwargs):
52 super(Turbomole, self).__init__(logname="Turbomole", *args, **kwargs)
53
54 def __str__(self):
55 """Return a string representation of the object."""
56 return "Turbomole output file %s" % (self.filename)
57
58 def __repr__(self):
59 """Return a representation of the object."""
60 return 'Turbomole("%s")' % (self.filename)
61
62 def normalisesym(self, label):
63 """Normalise the symmetries used by Turbomole."""
64 raise NotImplementedError('Now yet implemented for Turbomole.')
65
66 def before_parsing(self):
67 self.geoopt = False # Is this a GeoOpt? Needed for SCF targets/values.
68 self.periodic_table = utils.PeriodicTable()
69
70 @staticmethod
71 def split_molines(inline):
72 """Splits the lines containing mocoeffs (each of length 20)
73 and converts them to float correctly.
74 """
75 line = inline.replace("D", "E")
76 f1 = line[0:20]
77 f2 = line[20:40]
78 f3 = line[40:60]
79 f4 = line[60:80]
80
81 if(len(f4) > 1):
82 return [float(f1), float(f2), float(f3), float(f4)]
83 if(len(f3) > 1):
84 return [float(f1), float(f2), float(f3)]
85 if(len(f2) > 1):
86 return [float(f1), float(f2)]
87 if(len(f1) > 1):
88 return [float(f1)]
89
90 def extract(self, inputfile, line):
91 """Extract information from the file object inputfile."""
92
93 ## This information is in the control file.
94 # $rundimensions
95 # dim(fock,dens)=1860
96 # natoms=20
97 # nshell=40
98 # nbf(CAO)=60
99 # nbf(AO)=60
100 # dim(trafo[SAO<-->AO/CAO])=60
101 # rhfshells=1
102 if line[3:10]=="natoms=":
103 self.natom=int(line[10:])
104
105 if line[3:11] == "nbf(AO)=":
106 nmo = int(line.split('=')[1])
107 self.set_attribute('nbasis', nmo)
108 self.set_attribute('nmo', nmo)
109
110 # Extract the version number and optionally the build number.
111 searchstr = ": TURBOMOLE"
112 index = line.find(searchstr)
113 if index > -1:
114 line = line[index + len(searchstr):]
115 tokens = line.split()
116 self.metadata["package_version"] = tokens[0][1:].replace("-", ".")
117 # Don't add revision information to the main package version for now.
118 if tokens[1] == "(":
119 revision = tokens[2]
120
121 ## Atomic coordinates in job.last:
122 # +--------------------------------------------------+
123 # | Atomic coordinate, charge and isotop information |
124 # +--------------------------------------------------+
125 #
126 #
127 # atomic coordinates atom shells charge pseudo isotop
128 # -2.69176330 -0.00007129 -0.44712612 c 3 6.000 0 0
129 # -1.69851645 -0.00007332 2.06488947 c 3 6.000 0 0
130 # 0.92683848 -0.00007460 2.49592179 c 3 6.000 0 0
131 # 2.69176331 -0.00007127 0.44712612 c 3 6.000 0 0
132 # 1.69851645 -0.00007331 -2.06488947 c 3 6.000 0 0
133 #...
134 # -7.04373606 0.00092244 2.74543891 h 1 1.000 0 0
135 # -9.36352819 0.00017229 0.07445322 h 1 1.000 0 0
136 # -0.92683849 -0.00007461 -2.49592179 c 3 6.000 0 0
137 # -1.65164853 -0.00009927 -4.45456858 h 1 1.000 0 0
138 if 'Atomic coordinate, charge and isotop information' in line:
139 while 'atomic coordinates' not in line:
140 line = next(inputfile)
141
142 atomcoords = []
143 atomnos = []
144 line = next(inputfile)
145 while len(line) > 2:
146 atomnos.append(self.periodic_table.number[line.split()[3].upper()])
147 atomcoords.append([utils.convertor(float(x), "bohr", "Angstrom")
148 for x in line.split()[:3]])
149 line = next(inputfile)
150
151 self.append_attribute('atomcoords', atomcoords)
152 self.set_attribute('atomnos', atomnos)
153 self.set_attribute('natom', len(atomcoords))
154
155 # Frequency values in aoforce.out
156 # mode 7 8 9 10 11 12
157 #
158 # frequency 53.33 88.32 146.85 171.70 251.75 289.44
159 #
160 # symmetry a a a a a a
161 #
162 # IR YES YES YES YES YES YES
163 # |dDIP/dQ| (a.u.) 0.0002 0.0000 0.0005 0.0004 0.0000 0.0000
164 # intensity (km/mol) 0.05 0.00 0.39 0.28 0.00 0.00
165 # intensity ( % ) 0.05 0.00 0.40 0.28 0.00 0.00
166 #
167 # RAMAN YES YES YES YES YES YES
168 #
169 # 1 c x 0.00000 0.00001 0.00000 -0.01968 -0.04257 0.00001
170 # y -0.08246 -0.08792 0.02675 -0.00010 0.00000 0.17930
171 # z 0.00001 0.00003 0.00004 -0.10350 0.11992 -0.00003
172 if 'NORMAL MODES and VIBRATIONAL FREQUENCIES (cm**(-1))' in line:
173 vibfreqs, vibsyms, vibirs, vibdisps = [], [], [], []
174 while '**** force : all done ****' not in line:
175 if line.strip().startswith('frequency'):
176 freqs = [float(i.replace('i', '-')) for i in line.split()[1:]]
177 vibfreqs.extend(freqs)
178 self.skip_line(inputfile, ['b'])
179 line = next(inputfile)
180 if line.strip().startswith('symmetry'):
181 syms = line.split()[1:]
182 vibsyms.extend(syms)
183
184 self.skip_lines(inputfile, ['b', 'IR', 'dQIP'])
185 line = next(inputfile)
186 if line.strip().startswith('intensity (km/mol)'):
187 irs = [self.float(f) for f in line.split()[2:]]
188 vibirs.extend(irs)
189
190 self.skip_lines(inputfile, ['intensity', 'b', 'raman', 'b'])
191 line = next(inputfile)
192 x, y, z = [], [], []
193 while line.split():
194 x.append([float(i) for i in line.split()[3:]])
195 line = next(inputfile)
196 y.append([float(i) for i in line.split()[1:]])
197 line = next(inputfile)
198 z.append([float(i) for i in line.split()[1:]])
199 line = next(inputfile)
200
201 for j in range(len(x[0])):
202 disps = []
203 for i in range(len(x)):
204 disps.append([x[i][j], y[i][j], z[i][j]])
205 vibdisps.append(disps)
206
207 line = next(inputfile)
208
209 self.set_attribute('vibfreqs', vibfreqs)
210 self.set_attribute('vibsyms', vibsyms)
211 self.set_attribute('vibirs', vibirs)
212 self.set_attribute('vibdisps', vibdisps)
213
214 # In this section we are parsing mocoeffs and moenergies from
215 # the files like: mos, alpha and beta.
216 # $scfmo scfconv=6 format(4d20.14)
217 # # SCF total energy is -382.3457535740 a.u.
218 # #
219 # 1 a eigenvalue=-.97461484059799D+01 nsaos=60
220 # 0.69876828353937D+000.32405121159405D-010.87670894913921D-03-.85232349313288D-07
221 # 0.19361534257922D-04-.23841194890166D-01-.81711001390807D-020.13626356942047D-02
222 # ...
223 # ...
224 # $end
225 if (line.startswith('$scfmo') or line.startswith('$uhfmo')) and line.find('scfconv') > 0:
226 if line.strip().startswith('$uhfmo_alpha'):
227 self.unrestricted = True
228
229 # Need to skip the first line to start with lines starting with '#'.
230 line = next(inputfile)
231 while line.strip().startswith('#') and not line.find('eigenvalue') > 0:
232 line = next(inputfile)
233
234 moenergies = []
235 mocoeffs = []
236
237 while not line.strip().startswith('$'):
238 info = re.match(".*eigenvalue=(?P<moenergy>[0-9D\.+-]{20})\s+nsaos=(?P<count>\d+).*", line)
239 eigenvalue = self.float(info.group('moenergy'))
240 orbital_energy = utils.convertor(eigenvalue, 'hartree', 'eV')
241 moenergies.append(orbital_energy)
242 single_coeffs = []
243 nsaos = int(info.group('count'))
244
245 while(len(single_coeffs) < nsaos):
246 line = next(inputfile)
247 single_coeffs.extend(Turbomole.split_molines(line))
248
249 mocoeffs.append(single_coeffs)
250 line = next(inputfile)
251
252 max_nsaos = max([len(i) for i in mocoeffs])
253 for i in mocoeffs:
254 while len(i) < max_nsaos:
255 i.append(numpy.nan)
256
257 if not hasattr(self, 'mocoeffs'):
258 self.mocoeffs = []
259
260 if not hasattr(self, 'moenergies'):
261 self.moenergies = []
262
263 self.mocoeffs.append(mocoeffs)
264 self.moenergies.append(moenergies)
265
266 # Parsing the scfenergies, scfvalues and scftargets from job.last file.
267 # scf convergence criterion : increment of total energy < .1000000D-05
268 # and increment of one-electron energy < .1000000D-02
269 #
270 # ...
271 # ...
272 # current damping : 0.700
273 # ITERATION ENERGY 1e-ENERGY 2e-ENERGY NORM[dD(SAO)] TOL
274 # 1 -382.34543727790 -1396.8009423 570.56292464 0.000D+00 0.556D-09
275 # Exc = -57.835278090846 N = 69.997494722
276 # max. resid. norm for Fia-block= 2.782D-05 for orbital 33a
277 # ...
278 # ...
279 # current damping : 0.750
280 # ITERATION ENERGY 1e-ENERGY 2e-ENERGY NORM[dD(SAO)] TOL
281 # 3 -382.34575357399 -1396.8009739 570.56263988 0.117D-03 0.319D-09
282 # Exc = -57.835593208072 N = 69.999813370
283 # max. resid. norm for Fia-block= 7.932D-06 for orbital 33a
284 # max. resid. fock norm = 8.105D-06 for orbital 33a
285 #
286 # convergence criteria satisfied after 3 iterations
287 #
288 #
289 # ------------------------------------------
290 # | total energy = -382.34575357399 |
291 # ------------------------------------------
292 # : kinetic energy = 375.67398458525 :
293 # : potential energy = -758.01973815924 :
294 # : virial theorem = 1.98255043001 :
295 # : wavefunction norm = 1.00000000000 :
296 # ..........................................
297 if 'scf convergence criterion' in line:
298 total_energy_threshold = self.float(line.split()[-1])
299 one_electron_energy_threshold = self.float(next(inputfile).split()[-1])
300 scftargets = [total_energy_threshold, one_electron_energy_threshold]
301 self.append_attribute('scftargets', scftargets)
302 iter_energy = []
303 iter_one_elec_energy = []
304 while 'convergence criteria satisfied' not in line:
305 if 'ITERATION ENERGY' in line:
306 line = next(inputfile)
307 info = line.split()
308 iter_energy.append(self.float(info[1]))
309 iter_one_elec_energy.append(self.float(info[2]))
310 line = next(inputfile)
311
312 assert len(iter_energy) == len(iter_one_elec_energy), \
313 'Different number of values found for total energy and one electron energy.'
314 scfvalues = [[x - y, a - b] for x, y, a, b in
315 zip(iter_energy[1:], iter_energy[:-1], iter_one_elec_energy[1:], iter_one_elec_energy[:-1])]
316 self.append_attribute('scfvalues', scfvalues)
317 while 'total energy' not in line:
318 line = next(inputfile)
319
320 scfenergy = utils.convertor(self.float(line.split()[4]), 'hartree', 'eV')
321 self.append_attribute('scfenergies', scfenergy)
322
323 # **********************************************************************
324 # * *
325 # * RHF energy : -74.9644564256 *
326 # * MP2 correlation energy (doubles) : -0.0365225363 *
327 # * *
328 # * Final MP2 energy : -75.0009789619 *
329 # ...
330 # * Norm of MP1 T2 amplitudes : 0.0673494687 *
331 # * *
332 # **********************************************************************
333 # OR
334 # **********************************************************************
335 # * *
336 # * RHF energy : -74.9644564256 *
337 # * correlation energy : -0.0507799360 *
338 # * *
339 # * Final CCSD energy : -75.0152363616 *
340 # * *
341 # * D1 diagnostic : 0.0132 *
342 # * *
343 # **********************************************************************
344 if 'C C S D F 1 2 P R O G R A M' in line:
345 while 'ccsdf12 : all done' not in line:
346 if 'Final MP2 energy' in line:
347 mp2energy = [utils.convertor(self.float(line.split()[5]), 'hartree', 'eV')]
348 self.append_attribute('mpenergies', mp2energy)
349
350 if 'Final CCSD energy' in line:
351 ccenergy = [utils.convertor(self.float(line.split()[5]), 'hartree', 'eV')]
352 self.append_attribute('ccenergies', ccenergy)
353
354 line = next(inputfile)
355
356 # *****************************************************
357 # * *
358 # * SCF-energy : -74.49827196840999 *
359 # * MP2-energy : -0.19254365976227 *
360 # * total : -74.69081562817226 *
361 # * *
362 # * (MP2-energy evaluated from T2 amplitudes) *
363 # * *
364 # *****************************************************
365 if 'm p g r a d - program' in line:
366 while 'ccsdf12 : all done' not in line:
367 if 'MP2-energy' in line:
368 line = next(inputfile)
369 if 'total' in line:
370 mp2energy = [utils.convertor(self.float(line.split()[3]), 'hartree', 'eV')]
371 self.append_attribute('mpenergies', mp2energy)
372 line = next(inputfile)
373
374 def deleting_modes(self, vibfreqs, vibdisps, vibirs):
375 """Deleting frequencies relating to translations or rotations"""
376 i = 0
377 while i < len(vibfreqs):
378 if vibfreqs[i] == 0.0:
379 # Deleting frequencies that have value 0 since they
380 # do not correspond to vibrations.
381 del vibfreqs[i], vibdisps[i], vibirs[i]
382 i -= 1
383 i += 1
384
385 def after_parsing(self):
386 if hasattr(self, 'vibfreqs'):
387 self.deleting_modes(self.vibfreqs, self.vibdisps, self.vibirs)
388
389
390 class OldTurbomole(logfileparser.Logfile):
391 """A Turbomole output file. Code is outdated and is not being used."""
392
393 def __init__(self, *args):
394 # Call the __init__ method of the superclass
395 super(Turbomole, self).__init__(logname="Turbomole", *args)
396
397 def __str__(self):
398 """Return a string representation of the object."""
399 return "Turbomole output file %s" % (self.filename)
400
401 def __repr__(self):
402 """Return a representation of the object."""
403 return 'Turbomole("%s")' % (self.filename)
404
405 def atlist(self, atstr):
406 # turn atstr from atoms section into array
407
408 fields=atstr.split(',')
409 list=[]
410 for f in fields:
411 if(f.find('-')!=-1):
412 rangefields=f.split('-')
413 start=int(rangefields[0])
414 end=int(rangefields[1])
415
416 for j in range(start, end+1, 1):
417 list.append(j-1)
418 else:
419 list.append(int(f)-1)
420 return(list)
421
422 def normalisesym(self, label):
423 """Normalise the symmetries used by Turbomole."""
424 return ans
425
426 def before_parsing(self):
427 self.geoopt = False # Is this a GeoOpt? Needed for SCF targets/values.
428
429 def split_molines(self, inline):
430 line=inline.replace("D", "E")
431 f1=line[0:20]
432 f2=line[20:40]
433 f3=line[40:60]
434 f4=line[60:80]
435
436 if(len(f4)>1):
437 return( (float(f1), float(f2), float(f3), float(f4)) )
438 if(len(f3)>1):
439 return( (float(f1), float(f2), float(f3)) )
440 if(len(f2)>1):
441 return( (float(f1), float(f2)) )
442 if(len(f1)>1):
443 return([float(f1)])
444 return
445
446 def extract(self, inputfile, line):
447 """Extract information from the file object inputfile."""
448
449 if line[3:11]=="nbf(AO)=":
450 nmo=int(line[11:])
451 self.nbasis=nmo
452 self.nmo=nmo
453 if line[3:9]=="nshell":
454 temp=line.split('=')
455 homos=int(temp[1])
456
457 if line[0:6] == "$basis":
458 print("Found basis")
459 self.basis_lib=[]
460 line = inputfile.next()
461 line = inputfile.next()
462
463 while line[0] != '*' and line[0] != '$':
464 temp=line.split()
465 line = inputfile.next()
466 while line[0]=="#":
467 line = inputfile.next()
468 self.basis_lib.append(AtomBasis(temp[0], temp[1], inputfile))
469 line = inputfile.next()
470 if line == "$ecp\n":
471 self.ecp_lib=[]
472
473 line = inputfile.next()
474 line = inputfile.next()
475
476 while line[0] != '*' and line[0] != '$':
477 fields=line.split()
478 atname=fields[0]
479 ecpname=fields[1]
480 line = inputfile.next()
481 line = inputfile.next()
482 fields=line.split()
483 ncore = int(fields[2])
484
485 while line[0] != '*':
486 line = inputfile.next()
487 self.ecp_lib.append([atname, ecpname, ncore])
488
489 if line[0:6] == "$coord":
490 if line[0:11] == "$coordinate":
491 # print "Breaking"
492 return
493
494 # print "Found coords"
495 self.atomcoords = []
496 self.atomnos = []
497 atomcoords = []
498 atomnos = []
499
500 line = inputfile.next()
501 if line[0:5] == "$user":
502 # print "Breaking"
503 return
504
505 while line[0] != "$":
506 temp = line.split()
507 atsym=temp[3].capitalize()
508 atomnos.append(self.table.number[atsym])
509 atomcoords.append([utils.convertor(float(x), "bohr", "Angstrom")
510 for x in temp[0:3]])
511 line = inputfile.next()
512 self.atomcoords.append(atomcoords)
513 self.atomnos = numpy.array(atomnos, "i")
514
515 if line[14:32] == "atomic coordinates":
516 atomcoords = []
517 atomnos = []
518
519 line = inputfile.next()
520
521 while len(line) > 2:
522 temp = line.split()
523 atsym = temp[3].capitalize()
524 atomnos.append(self.table.number[atsym])
525 atomcoords.append([utils.convertor(float(x), "bohr", "Angstrom")
526 for x in temp[0:3]])
527 line = inputfile.next()
528
529 if not hasattr(self,"atomcoords"):
530 self.atomcoords = []
531
532 self.atomcoords.append(atomcoords)
533 self.atomnos = numpy.array(atomnos, "i")
534
535 if line[0:6] == "$atoms":
536 print("parsing atoms")
537 line = inputfile.next()
538 self.atomlist=[]
539 while line[0]!="$":
540 temp=line.split()
541 at=temp[0]
542 atnosstr=temp[1]
543 while atnosstr[-1] == ",":
544 line = inputfile.next()
545 temp=line.split()
546 atnosstr=atnosstr+temp[0]
547 # print "Debug:", atnosstr
548 atlist=self.atlist(atnosstr)
549
550 line = inputfile.next()
551
552 temp=line.split()
553 # print "Debug basisname (temp):",temp
554 basisname=temp[2]
555 ecpname=''
556 line = inputfile.next()
557 while(line.find('jbas')!=-1 or line.find('ecp')!=-1 or
558 line.find('jkbas')!=-1):
559 if line.find('ecp')!=-1:
560 temp=line.split()
561 ecpname=temp[2]
562 line = inputfile.next()
563
564 self.atomlist.append( (at, basisname, ecpname, atlist))
565
566 # I have no idea what this does, so "comment" out
567 if line[3:10]=="natoms=":
568 # if 0:
569
570 self.natom=int(line[10:])
571
572 basistable=[]
573
574 for i in range(0, self.natom, 1):
575 for j in range(0, len(self.atomlist), 1):
576 for k in range(0, len(self.atomlist[j][3]), 1):
577 if self.atomlist[j][3][k]==i:
578 basistable.append((self.atomlist[j][0],
579 self.atomlist[j][1],
580 self.atomlist[j][2]))
581 self.aonames=[]
582 counter=1
583 for a, b, c in basistable:
584 ncore=0
585 if len(c) > 0:
586 for i in range(0, len(self.ecp_lib), 1):
587 if self.ecp_lib[i][0]==a and \
588 self.ecp_lib[i][1]==c:
589 ncore=self.ecp_lib[i][2]
590
591 for i in range(0, len(self.basis_lib), 1):
592 if self.basis_lib[i].atname==a and self.basis_lib[i].basis_name==b:
593 pa=a.capitalize()
594 basis=self.basis_lib[i]
595
596 s_counter=1
597 p_counter=2
598 d_counter=3
599 f_counter=4
600 g_counter=5
601 # this is a really ugly piece of code to assign the right labels to
602 # basis functions on atoms with an ecp
603 if ncore == 2:
604 s_counter=2
605 elif ncore == 10:
606 s_counter=3
607 p_counter=3
608 elif ncore == 18:
609 s_counter=4
610 p_counter=4
611 elif ncore == 28:
612 s_counter=4
613 p_counter=4
614 d_counter=4
615 elif ncore == 36:
616 s_counter=5
617 p_counter=5
618 d_counter=5
619 elif ncore == 46:
620 s_counter=5
621 p_counter=5
622 d_counter=6
623
624 for j in range(0, len(basis.symmetries), 1):
625 if basis.symmetries[j]=='s':
626 self.aonames.append("%s%d_%d%s" % \
627 (pa, counter, s_counter, "S"))
628 s_counter=s_counter+1
629 elif basis.symmetries[j]=='p':
630 self.aonames.append("%s%d_%d%s" % \
631 (pa, counter, p_counter, "PX"))
632 self.aonames.append("%s%d_%d%s" % \
633 (pa, counter, p_counter, "PY"))
634 self.aonames.append("%s%d_%d%s" % \
635 (pa, counter, p_counter, "PZ"))
636 p_counter=p_counter+1
637 elif basis.symmetries[j]=='d':
638 self.aonames.append("%s%d_%d%s" % \
639 (pa, counter, d_counter, "D 0"))
640 self.aonames.append("%s%d_%d%s" % \
641 (pa, counter, d_counter, "D+1"))
642 self.aonames.append("%s%d_%d%s" % \
643 (pa, counter, d_counter, "D-1"))
644 self.aonames.append("%s%d_%d%s" % \
645 (pa, counter, d_counter, "D+2"))
646 self.aonames.append("%s%d_%d%s" % \
647 (pa, counter, d_counter, "D-2"))
648 d_counter=d_counter+1
649 elif basis.symmetries[j]=='f':
650 self.aonames.append("%s%d_%d%s" % \
651 (pa, counter, f_counter, "F 0"))
652 self.aonames.append("%s%d_%d%s" % \
653 (pa, counter, f_counter, "F+1"))
654 self.aonames.append("%s%d_%d%s" % \
655 (pa, counter, f_counter, "F-1"))
656 self.aonames.append("%s%d_%d%s" % \
657 (pa, counter, f_counter, "F+2"))
658 self.aonames.append("%s%d_%d%s" % \
659 (pa, counter, f_counter, "F-2"))
660 self.aonames.append("%s%d_%d%s" % \
661 (pa, counter, f_counter, "F+3"))
662 self.aonames.append("%s%d_%d%s" % \
663 (pa, counter, f_counter, "F-3"))
664 elif basis.symmetries[j]=='g':
665 self.aonames.append("%s%d_%d%s" % \
666 (pa, counter, f_counter, "G 0"))
667 self.aonames.append("%s%d_%d%s" % \
668 (pa, counter, f_counter, "G+1"))
669 self.aonames.append("%s%d_%d%s" % \
670 (pa, counter, f_counter, "G-1"))
671 self.aonames.append("%s%d_%d%s" % \
672 (pa, counter, g_counter, "G+2"))
673 self.aonames.append("%s%d_%d%s" % \
674 (pa, counter, g_counter, "G-2"))
675 self.aonames.append("%s%d_%d%s" % \
676 (pa, counter, g_counter, "G+3"))
677 self.aonames.append("%s%d_%d%s" % \
678 (pa, counter, g_counter, "G-3"))
679 self.aonames.append("%s%d_%d%s" % \
680 (pa, counter, g_counter, "G+4"))
681 self.aonames.append("%s%d_%d%s" % \
682 (pa, counter, g_counter, "G-4"))
683 break
684 counter=counter+1
685
686 if line=="$closed shells\n":
687 line = inputfile.next()
688 temp = line.split()
689 occs = int(temp[1][2:])
690 self.homos = numpy.array([occs-1], "i")
691
692 if line == "$alpha shells\n":
693 line = inputfile.next()
694 temp = line.split()
695 occ_a = int(temp[1][2:])
696 line = inputfile.next() # should be $beta shells
697 line = inputfile.next() # the beta occs
698 temp = line.split()
699 occ_b = int(temp[1][2:])
700 self.homos = numpy.array([occ_a-1,occ_b-1], "i")
701
702 if line[12:24]=="OVERLAP(CAO)":
703 line = inputfile.next()
704 line = inputfile.next()
705 overlaparray=[]
706 self.aooverlaps=numpy.zeros( (self.nbasis, self.nbasis), "d")
707 while line != " ----------------------\n":
708 temp=line.split()
709 overlaparray.extend(map(float, temp))
710 line = inputfile.next()
711 counter=0
712
713 for i in range(0, self.nbasis, 1):
714 for j in range(0, i+1, 1):
715 self.aooverlaps[i][j]=overlaparray[counter]
716 self.aooverlaps[j][i]=overlaparray[counter]
717 counter=counter+1
718
719 if ( line[0:6] == "$scfmo" or line[0:12] == "$uhfmo_alpha" ) and line.find("scf") > 0:
720 temp = line.split()
721
722 if temp[1][0:7] == "scfdump":
723 # self.logger.warning("SCF not converged?")
724 print("SCF not converged?!")
725
726 if line[0:12] == "$uhfmo_alpha": # if unrestricted, create flag saying so
727 unrestricted = 1
728 else:
729 unrestricted = 0
730
731 self.moenergies=[]
732 self.mocoeffs=[]
733
734 for spin in range(unrestricted + 1): # make sure we cover all instances
735 title = inputfile.next()
736 while(title[0] == "#"):
737 title = inputfile.next()
738
739 # mocoeffs = numpy.zeros((self.nbasis, self.nbasis), "d")
740 moenergies = []
741 moarray=[]
742
743 if spin == 1 and title[0:11] == "$uhfmo_beta":
744 title = inputfile.next()
745 while title[0] == "#":
746 title = inputfile.next()
747
748 while(title[0] != '$'):
749 temp=title.split()
750
751 orb_symm=temp[1]
752
753 try:
754 energy = float(temp[2][11:].replace("D", "E"))
755 except ValueError:
756 print(spin, ": ", title)
757
758 orb_en = utils.convertor(energy,"hartree","eV")
759
760 moenergies.append(orb_en)
761 single_mo = []
762
763 while(len(single_mo)<self.nbasis):
764 self.updateprogress(inputfile, "Coefficients", self.cupdate)
765 title = inputfile.next()
766 lines_coeffs=self.split_molines(title)
767 single_mo.extend(lines_coeffs)
768
769 moarray.append(single_mo)
770 title = inputfile.next()
771
772 # for i in range(0, len(moarray), 1):
773 # for j in range(0, self.nbasis, 1):
774 # try:
775 # mocoeffs[i][j]=moarray[i][j]
776 # except IndexError:
777 # print "Index Error in mocoeffs.", spin, i, j
778 # break
779
780 mocoeffs = numpy.array(moarray,"d")
781 self.mocoeffs.append(mocoeffs)
782 self.moenergies.append(moenergies)
783
784 if line[26:49] == "a o f o r c e - program":
785 self.vibirs = []
786 self.vibfreqs = []
787 self.vibsyms = []
788 self.vibdisps = []
789
790 # while line[3:31] != "**** force : all done ****":
791
792 if line[12:26] == "ATOMIC WEIGHTS":
793 #begin parsing atomic weights
794 self.vibmasses=[]
795 line=inputfile.next() # lines =======
796 line=inputfile.next() # notes
797 line=inputfile.next() # start reading
798 temp=line.split()
799 while(len(temp) > 0):
800 self.vibmasses.append(float(temp[2]))
801 line=inputfile.next()
802 temp=line.split()
803
804 if line[5:14] == "frequency":
805 if not hasattr(self,"vibfreqs"):
806 self.vibfreqs = []
807 self.vibfreqs = []
808 self.vibsyms = []
809 self.vibdisps = []
810 self.vibirs = []
811
812 temp=line.replace("i","-").split()
813
814 freqs = [self.float(f) for f in temp[1:]]
815 self.vibfreqs.extend(freqs)
816
817 line=inputfile.next()
818 line=inputfile.next()
819
820 syms=line.split()
821 self.vibsyms.extend(syms[1:])
822
823 line=inputfile.next()
824 line=inputfile.next()
825 line=inputfile.next()
826 line=inputfile.next()
827
828 temp=line.split()
829 irs = [self.float(f) for f in temp[2:]]
830 self.vibirs.extend(irs)
831
832 line=inputfile.next()
833 line=inputfile.next()
834 line=inputfile.next()
835 line=inputfile.next()
836
837 x=[]
838 y=[]
839 z=[]
840
841 line=inputfile.next()
842 while len(line) > 1:
843 temp=line.split()
844 x.append(map(float, temp[3:]))
845
846 line=inputfile.next()
847 temp=line.split()
848 y.append(map(float, temp[1:]))
849
850 line=inputfile.next()
851 temp=line.split()
852 z.append(map(float, temp[1:]))
853 line=inputfile.next()
854
855 # build xyz vectors for each mode
856
857 for i in range(0, len(x[0]), 1):
858 disp=[]
859 for j in range(0, len(x), 1):
860 disp.append( [x[j][i], y[j][i], z[j][i]])
861 self.vibdisps.append(disp)
862
863 # line=inputfile.next()
864
865 def after_parsing(self):
866
867 # delete all frequencies that correspond to translations or rotations
868
869 if hasattr(self,"vibfreqs"):
870 i = 0
871 while i < len(self.vibfreqs):
872 if self.vibfreqs[i]==0.0:
873 del self.vibfreqs[i]
874 del self.vibdisps[i]
875 del self.vibirs[i]
876 del self.vibsyms[i]
877 i -= 1
878 i += 1
879
880