Repository navigation
Expand file tree
/
Copy pathsetup_init.py
More file actions
executable file
·3471 lines (2987 loc) · 132 KB
/
Copy pathsetup_init.py
File metadata and controls
executable file
·3471 lines (2987 loc) · 132 KB
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# ******************************************
#
# SHARC Program Suite
#
# Copyright (c) 2023 University of Vienna
#
# This file is part of SHARC.
#
# SHARC 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.
#
# SHARC 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
# inside the SHARC manual. If not, see <http://www.gnu.org/licenses/>.
#
# ******************************************
# Interactive script for the setup of initial condition excitation calculations for SHARC
#
# usage: python setup_init.py
import math
import sys
import re
import os
import stat
import shutil
import datetime
from optparse import OptionParser
import readline
import time
import ast
import random
# =========================================================
# compatibility stuff
if sys.version_info[0] != 3:
print('This is a script for Python 3!')
sys.exit(0)
if sys.version_info[1] < 5:
def any(iterable):
for element in iterable:
if element:
return True
return False
def all(iterable):
for element in iterable:
if not element:
return False
return True
# some constants
DEBUG = False
CM_TO_HARTREE = 1. / 219474.6 # 4.556335252e-6 # conversion factor from cm-1 to Hartree
HARTREE_TO_EV = 27.211396132 # conversion factor from Hartree to eV
U_TO_AMU = 1. / 5.4857990943e-4 # conversion from g/mol to amu
BOHR_TO_ANG = 0.529177211
PI = math.pi
version = '3.0'
versionneeded = [0.2, 1.0, 2.0, float(version)]
versiondate = datetime.date(2023, 4, 1)
IToMult = {
1: 'Singlet',
2: 'Doublet',
3: 'Triplet',
4: 'Quartet',
5: 'Quintet',
6: 'Sextet',
7: 'Septet',
8: 'Octet',
'Singlet': 1,
'Doublet': 2,
'Triplet': 3,
'Quartet': 4,
'Quintet': 5,
'Sextet': 6,
'Septet': 7,
'Octet': 8
}
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
def try_read(word, index, typefunc, default):
try:
return typefunc(word[index])
except IndexError:
return typefunc(default)
except ValueError:
print('Could not initialize object!')
quit(1)
# ======================================================================================================================
class ATOM:
def __init__(self, symb='??', num=0., coord=[0., 0., 0.], m=0., veloc=[0., 0., 0.]):
self.symb = symb
self.num = num
self.coord = coord
self.mass = m
self.veloc = veloc
self.Ekin = 0.5 * self.mass * sum([self.veloc[i]**2 for i in range(3)])
def init_from_str(self, initstring=''):
f = initstring.split()
self.symb = try_read(f, 0, str, '??')
self.num = try_read(f, 1, float, 0.)
self.coord = [try_read(f, i, float, 0.) for i in range(2, 5)]
self.mass = try_read(f, 5, float, 0.) * U_TO_AMU
self.veloc = [try_read(f, i, float, 0.) for i in range(6, 9)]
self.Ekin = 0.5 * self.mass * sum([self.veloc[i]**2 for i in range(3)])
def __str__(self):
s = '%2s % 5.1f ' % (self.symb, self.num)
s += '% 12.8f % 12.8f % 12.8f ' % tuple(self.coord)
s += '% 12.8f ' % (self.mass / U_TO_AMU)
s += '% 12.8f % 12.8f % 12.8f' % tuple(self.veloc)
return s
def EKIN(self):
self.Ekin = 0.5 * self.mass * sum([self.veloc[i]**2 for i in range(3)])
return self.Ekin
def geomstring(self):
s = ' %2s % 5.1f % 12.8f % 12.8f % 12.8f % 12.8f' % (self.symb, self.num, self.coord[0], self.coord[1], self.coord[2], self.mass / U_TO_AMU)
return s
def velocstring(self):
s = ' ' * 11 + '% 12.8f % 12.8f % 12.8f' % tuple(self.veloc)
return s
# ======================================================================================================================
class STATE:
def __init__(self, i=0, e=0., eref=0., dip=[0., 0., 0.]):
self.i = i
self.e = e.real
self.eref = eref.real
self.dip = dip
self.Excited = False
self.Eexc = self.e - self.eref
self.Fosc = (2. / 3. * self.Eexc * sum([i * i.conjugate() for i in self.dip])).real
if self.Eexc == 0.:
self.Prob = 0.
else:
self.Prob = self.Fosc / self.Eexc**2
def init_from_str(self, initstring):
f = initstring.split()
self.i = try_read(f, 0, int, 0)
self.e = try_read(f, 1, float, 0.)
self.eref = try_read(f, 2, float, 0.)
self.dip = [try_read(f, i, float, 0.) for i in range(3, 6)]
self.Excited = try_read(f, 2, bool, False)
self.Eexc = self.e - self.eref
self.Fosc = (2. / 3. * self.Eexc * sum([i * i.conjugate() for i in self.dip])).real
if self.Eexc == 0.:
self.Prob = 0.
else:
self.Prob = self.Fosc / self.Eexc**2
def __str__(self):
s = '%03i % 18.10f % 18.10f ' % (self.i, self.e, self.eref)
for i in range(3):
s += '% 12.8f % 12.8f ' % (self.dip[i].real, self.dip[i].imag)
s += '% 12.8f % 12.8f %s' % (self.Eexc * HARTREE_TO_EV, self.Fosc, self.excited)
return s
def Excite(self, max_Prob, erange):
try:
Prob = self.Prob / max_Prob
except ZeroDivisionError:
Prob = -1.
if not (erange[0] <= self.Eexc <= erange[1]):
Prob = -1.
self.excited = (random.random() < Prob)
# ======================================================================================================================
class INITCOND:
def __init__(self, atomlist=[], eref=0., epot_harm=0.):
self.atomlist = atomlist
self.eref = eref
self.Epot_harm = epot_harm
self.natom = len(atomlist)
self.Ekin = sum([atom.Ekin for atom in self.atomlist])
self.statelist = []
self.nstate = 0
self.Epot = epot_harm
def addstates(self, statelist):
self.statelist = statelist
self.nstate = len(statelist)
self.Epot = self.statelist[0].e - self.eref
def init_from_file(self, f, eref, index):
while True:
line = f.readline()
# if 'Index %i' % (index) in line:
if re.search(r'Index\s+%i' % (index), line):
break
if line == '\n':
continue
if line == '':
print('Initial condition %i not found in file %s' % (index, f.name))
quit(1)
f.readline() # skip one line, where "Atoms" stands
atomlist = []
while True:
line = f.readline()
if 'States' in line:
break
atom = ATOM()
atom.init_from_str(line)
atomlist.append(atom)
statelist = []
while True:
line = f.readline()
if 'Ekin' in line:
break
state = STATE()
state.init_from_str(line)
statelist.append(state)
epot_harm = 0.
while not line == '\n' and not line == '':
line = f.readline()
if 'epot_harm' in line.lower():
epot_harm = float(line.split()[1])
break
self.atomlist = atomlist
self.eref = eref
self.Epot_harm = epot_harm
self.natom = len(atomlist)
self.Ekin = sum([atom.Ekin for atom in self.atomlist])
self.statelist = statelist
self.nstate = len(statelist)
if self.nstate > 0:
self.Epot = self.statelist[0].e - self.eref
else:
self.Epot = epot_harm
def __str__(self):
s = 'Atoms\n'
for atom in self.atomlist:
s += str(atom) + '\n'
s += 'States\n'
for state in self.statelist:
s += str(state) + '\n'
s += 'Ekin % 16.12f a.u.\n' % (self.Ekin)
s += 'Epot_harm % 16.12f a.u.\n' % (self.Epot_harm)
s += 'Epot % 16.12f a.u.\n' % (self.Epot)
s += 'Etot_harm % 16.12f a.u.\n' % (self.Epot_harm + self.Ekin)
s += 'Etot % 16.12f a.u.\n' % (self.Epot + self.Ekin)
s += '\n\n'
return s
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
def check_initcond_version(string, must_be_excited=False):
if 'sharc initial conditions file' not in string.lower():
return False
f = string.split()
for i, field in enumerate(f):
if 'version' in field.lower():
try:
v = float(f[i + 1])
if v not in versionneeded:
return False
except IndexError:
return False
if must_be_excited:
if 'excited' not in string.lower():
return False
return True
# ======================================================================================================================
def centerstring(string, n, pad=' '):
length = len(string)
if length >= n:
return string
else:
return pad * ((n - length + 1) // 2) + string + pad * ((n - length) // 2)
# ======================================================================================================================
def displaywelcome():
print('Script for setup of initial conditions started...\n')
string = '\n'
string += ' ' + '=' * 80 + '\n'
input = [' ',
'Setup trajectories for SHARC dynamics',
' ',
'Authors: Sebastian Mai, Severin Polonius',
' ',
'Version: %s' % (version),
'Date: %s' % (versiondate.strftime("%d.%m.%y")),
' ']
for inp in input:
string += '||{:^80}||\n'.format(inp)
string += ' ' + '=' * 80 + '\n\n'
string += '''
This script automatizes the setup of excited-state calculations for initial conditions
for SHARC dynamics.
'''
print(string)
# ======================================================================================================================
def open_keystrokes():
global KEYSTROKES
KEYSTROKES = open('KEYSTROKES.tmp', 'w')
def close_keystrokes():
KEYSTROKES.close()
shutil.move('KEYSTROKES.tmp', 'KEYSTROKES.setup_init')
# ===================================
def question(question, typefunc, default=None, autocomplete=True, ranges=False):
if typefunc == int or typefunc == float:
if default is not None and not isinstance(default, list):
print('Default to int or float question must be list!')
quit(1)
if typefunc == str and autocomplete:
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete") # activate autocomplete
else:
readline.parse_and_bind("tab: ") # deactivate autocomplete
while True:
s = question
if default is not None:
if typefunc == bool or typefunc == str:
s += ' [%s]' % (str(default))
elif typefunc == int or typefunc == float:
s += ' ['
for i in default:
s += str(i) + ' '
s = s[:-1] + ']'
if typefunc == str and autocomplete:
s += ' (autocomplete enabled)'
if typefunc == int and ranges:
s += ' (range comprehension enabled)'
s += ' '
line = input(s)
line = re.sub(r'#.*$', '', line).strip()
if not typefunc == str:
line = line.lower()
if line == '' or line == '\n':
if default is not None:
KEYSTROKES.write(line + ' ' * (40 - len(line)) + ' #' + s + '\n')
return default
else:
continue
if typefunc == bool:
posresponse = ['y', 'yes', 'true', 't', 'ja', 'si', 'yea', 'yeah', 'aye', 'sure', 'definitely']
negresponse = ['n', 'no', 'false', 'f', 'nein', 'nope']
if line in posresponse:
KEYSTROKES.write(line + ' ' * (40 - len(line)) + ' #' + s + '\n')
return True
elif line in negresponse:
KEYSTROKES.write(line + ' ' * (40 - len(line)) + ' #' + s + '\n')
return False
else:
print("I didn't understand you.")
continue
if typefunc == str:
KEYSTROKES.write(line + ' ' * (40 - len(line)) + ' #' + s + '\n')
return line
if typefunc == float:
# float will be returned as a list
f = line.split()
try:
for i in range(len(f)):
f[i] = typefunc(f[i])
KEYSTROKES.write(line + ' ' * (40 - len(line)) + ' #' + s + '\n')
return f
except ValueError:
print('Please enter floats!')
continue
if typefunc == int:
# int will be returned as a list
f = line.split()
out = []
try:
for i in f:
if ranges and '~' in i:
q = i.split('~')
for j in range(int(q[0]), int(q[1]) + 1):
out.append(j)
else:
out.append(int(i))
KEYSTROKES.write(line + ' ' * (40 - len(line)) + ' #' + s + '\n')
return out
except ValueError:
if ranges:
print('Please enter integers or ranges of integers (e.g. "-3~-1 2 5~7")!')
else:
print('Please enter integers!')
continue
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
def get_general():
'''This routine questions from the user some general information:
- initconds file
- number of states
- number of initial conditions
- interface to use'''
INFOS = {}
print(centerstring('Initial conditions file', 60, '-') + '\n')
# open the initconds file
try:
initfile = 'initconds'
initf = open(initfile)
line = initf.readline()
if check_initcond_version(line):
print('Initial conditions file "initconds" detected. Do you want to use this?')
if not question('Use file "initconds"?', bool, True):
initf.close()
raise IOError
else:
initf.close()
raise IOError
except IOError:
print('\nIf you do not have an initial conditions file, prepare one with wigner.py!\n')
print('Please enter the filename of the initial conditions file.')
while True:
initfile = question('Initial conditions filename:', str, 'initconds')
initfile = os.path.expanduser(os.path.expandvars(initfile))
if os.path.isdir(initfile):
print('Is a directory: %s' % (initfile))
continue
if not os.path.isfile(initfile):
print('File does not exist: %s' % (initfile))
continue
try:
initf = open(initfile, 'r')
except IOError:
print('Could not open: %s' % (initfile))
continue
line = initf.readline()
if check_initcond_version(line):
break
else:
print('File does not contain initial conditions!')
continue
# read the header
ninit = int(initf.readline().split()[1])
natom = int(initf.readline().split()[1])
INFOS['ninit'] = ninit
INFOS['natom'] = natom
initf.seek(0) # rewind the initf file
INFOS['initf'] = initf
print('\nFile "%s" contains %i initial conditions.' % (initfile, ninit))
print('Number of atoms is %i\n' % (natom))
print(centerstring('Range of initial conditions', 60, '-'))
print('\nPlease enter the range of initial conditions for which an excited-state calculation should be performed as two integers separated by space.')
while True:
irange = question('Initial condition range:', int, [1, ninit])
if len(irange) != 2:
print('Enter two numbers separated by spaces!')
continue
if irange[0] > irange[1]:
print('Range empty!')
continue
if irange[0] == irange[1] == 0:
print('Only preparing calculation at equilibrium geometry!')
break
if irange[1] > ninit:
print('There are only %i initial conditions in file %s!' % (ninit, initfile))
continue
if irange[0] <= 0:
print('Only positive indices allowed!')
continue
break
print('\nScript will use initial conditions %i to %i (%i in total).\n' % (irange[0], irange[1], irange[1] - irange[0] + 1))
INFOS['irange'] = irange
print(centerstring('Number of states', 60, '-'))
print('\nPlease enter the number of states as a list of integers\ne.g. 3 0 3 for three singlets, zero doublets and three triplets.')
while True:
states = question('Number of states:', int)
if len(states) == 0:
continue
if any(i < 0 for i in states):
print('Number of states must be positive!')
continue
break
print('')
nstates = 0
for mult, i in enumerate(states):
nstates += (mult + 1) * i
print('Number of states: ' + str(states))
print('Total number of states: %i\n' % (nstates))
INFOS['states'] = states
INFOS['nstates'] = nstates
print(centerstring('Choose the quantum chemistry interface', 60, '-'))
print('\nPlease specify the quantum chemistry interface (enter any of the following numbers):')
for i in Interfaces:
print('%i\t%s' % (i, Interfaces[i]['description']))
print('')
while True:
num = question('Interface number:', int)[0]
if num in Interfaces:
break
else:
print('Please input one of the following: %s!' % ([i for i in Interfaces]))
INFOS['interface'] = num
INFOS['needed'] = []
# Setup SOCs
print('\n' + centerstring('Spin-orbit couplings (SOCs)', 60, '-') + '\n')
if len(states) > 1:
if 'soc' in Interfaces[num]['features']:
print('Do you want to compute spin-orbit couplings?\n')
soc = question('Spin-Orbit calculation?', bool, True)
if soc:
print('Will calculate spin-orbit matrix.')
else:
print('Interface cannot provide SOCs: not calculating spin-orbit matrix.')
soc = False
else:
print('Only singlets specified: not calculating spin-orbit matrix.')
soc = False
print('')
INFOS['soc'] = soc
if INFOS['soc']:
INFOS['needed'].extend(Interfaces[num]['features']['soc'])
# Setup Dyson spectra
if 'dyson' in Interfaces[num]['features']:
n = [0, 0]
for i, j in enumerate(states):
n[i % 2] += j
if n[0] >= 1 and n[1] >= 1:
print('\n' + centerstring('Ionization probability by Dyson norms', 60, '-') + '\n')
print('Do you want to compute Dyson norms between neutral and ionic states?')
INFOS['ion'] = question('Dyson norms?', bool, False)
if INFOS['ion']:
INFOS['needed'].extend(Interfaces[num]['features']['dyson'])
# Setup initconds with reference overlap
if 'overlap' in Interfaces[num]['features']:
print('\n' + centerstring('Overlaps to reference states', 60, '-') + '\n')
print('Do you want to compute the overlaps between the states at the equilibrium geometry and the states at the initial condition geometries?')
INFOS['refov'] = question('Reference overlaps?', bool, False)
if INFOS['refov']:
INFOS['needed'].extend(Interfaces[num]['features']['overlap'])
# Setup theodore
if 'theodore' in Interfaces[num]['features']:
print('\n' + centerstring('TheoDORE wave function analysis', 60, '-') + '\n')
print('Do you want to run TheoDORE to obtain one-electron descriptors for the electronic wave functions?')
INFOS['theodore'] = question('TheoDORE?', bool, False)
if INFOS['theodore']:
INFOS['needed'].extend(Interfaces[num]['features']['theodore'])
INFOS['cwd'] = os.getcwd()
print('')
return INFOS
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
Interfaces = {
1: {'script': 'SHARC_MOLPRO.py',
'name': 'molpro',
'description': 'MOLPRO (only CASSCF)',
'get_routine': 'get_MOLPRO',
'prepare_routine': 'prepare_MOLPRO',
'features': {'overlap': ['wfoverlap'],
'dyson': ['wfoverlap'],
'nacdr': ['wfoverlap'],
'phases': ['wfoverlap'],
'soc': []},
'pysharc': False
},
2: {'script': 'SHARC_COLUMBUS.py',
'name': 'columbus',
'description': 'COLUMBUS (CASSCF, RASSCF and MRCISD), using SEWARD integrals',
'get_routine': 'get_COLUMBUS',
'prepare_routine': 'prepare_COLUMBUS',
'features': {'overlap': ['wfoverlap'],
'dyson': ['wfoverlap'],
'phases': ['wfoverlap'],
'nacdr': [],
'soc': []},
'pysharc': False
},
3: {'script': 'SHARC_Analytical.py',
'name': 'analytical',
'description': 'Analytical PESs',
'get_routine': 'get_Analytical',
'prepare_routine': 'prepare_Analytical',
'features': {'overlap': [],
'dipolegrad': [],
'phases': [],
'soc': []},
'pysharc': False
},
4: {'script': 'SHARC_MOLCAS.py',
'name': 'molcas',
'description': 'MOLCAS (CASSCF, CASPT2, MS-CASPT2)',
'get_routine': 'get_MOLCAS',
'prepare_routine': 'prepare_MOLCAS',
'features': {'overlap': [],
'dyson': ['wfoverlap'],
'dipolegrad': [],
'phases': [],
'nacdr': [],
'soc': []},
'pysharc': False
},
5: {'script': 'SHARC_AMS-ADF.py',
'name': 'ams-adf',
'description': 'AMS-ADF (DFT, TD-DFT)',
'get_routine': 'get_AMS',
'prepare_routine': 'prepare_AMS',
'features': {'overlap': ['wfoverlap'],
'dyson': ['wfoverlap'],
'theodore': ['theodore'],
'phases': ['wfoverlap'],
'soc': []},
'pysharc': False
},
6: {'script': 'SHARC_RICC2.py',
'name': 'ricc2',
'description': 'TURBOMOLE (ricc2 with CC2 and ADC(2))',
'get_routine': 'get_RICC2',
'prepare_routine': 'prepare_RICC2',
'features': {'overlap': ['wfoverlap'],
'theodore': ['theodore'],
'phases': ['wfoverlap'],
'soc': []},
'pysharc': False
},
7: {'script': 'SHARC_LVC.py',
'name': 'lvc',
'description': 'LVC Hamiltonian',
'get_routine': 'get_LVC',
'prepare_routine': 'prepare_LVC',
'features': {'overlap': [],
'nacdr': [],
'phases': [],
'soc': []},
'pysharc': True,
'pysharc_driver': 'pysharc_lvc.py'
},
8: {'script': 'SHARC_GAUSSIAN.py',
'name': 'gaussian',
'description': 'GAUSSIAN (DFT, TD-DFT)',
'get_routine': 'get_GAUSSIAN',
'prepare_routine': 'prepare_GAUSSIAN',
'features': {'overlap': ['wfoverlap'],
'dyson': ['wfoverlap'],
'theodore': ['theodore'],
'phases': ['wfoverlap']},
'pysharc': False
},
9: {'script': 'SHARC_ORCA.py',
'name': 'orca',
'description': 'ORCA (DFT, TD-DFT, HF, CIS)',
'get_routine': 'get_ORCA',
'prepare_routine': 'prepare_ORCA',
'features': {'overlap': ['wfoverlap'],
'dyson': ['wfoverlap'],
'theodore': ['theodore'],
'phases': ['wfoverlap'],
'soc': []},
'pysharc': False
},
10: {'script': 'SHARC_BAGEL.py',
'name': 'bagel',
'description': 'BAGEL (CASSCF, CASPT2, (X)MS-CASPT2)',
'get_routine': 'get_BAGEL',
'prepare_routine': 'prepare_BAGEL',
'features': {'overlap': ['wfoverlap'],
'dyson': ['wfoverlap'],
'nacdr': [],
'dipolegrad': [],
'phases': [], },
'pysharc': False
},
}
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
def checktemplate_MOLPRO(filename):
necessary = ['basis', 'closed', 'occ', 'nelec', 'roots']
try:
f = open(filename)
data = f.readlines()
f.close()
except IOError:
print('Could not open template file %s' % (filename))
return False
i = 0
for line in data:
if necessary[i] in line:
i += 1
if i + 1 == len(necessary):
return True
print('The template %s seems to be incomplete! It should contain: ' % (filename) + str(necessary))
return False
# =================================================
def get_MOLPRO(INFOS):
'''This routine asks for all questions specific to MOLPRO:
- path to molpro
- scratch directory
- MOLPRO.template
- wf.init
'''
string = '\n ' + '=' * 80 + '\n'
string += '||' + centerstring('MOLPRO Interface setup', 80) + '||\n'
string += ' ' + '=' * 80 + '\n\n'
print(string)
print(centerstring('Path to MOLPRO', 60, '-') + '\n')
path = os.getenv('MOLPRO')
path = os.path.expanduser(os.path.expandvars(path))
if not path == '':
path = '$MOLPRO/'
else:
path = None
# if path!='':
# print('Environment variable $MOLPRO detected:\n$MOLPRO=%s\n' % (path))
# if question('Do you want to use this MOLPRO installation?',bool,True):
# INFOS['molpro']=path
# if not 'molpro' in INFOS:
print('\nPlease specify path to MOLPRO directory (SHELL variables and ~ can be used, will be expanded when interface is started).\n')
INFOS['molpro'] = question('Path to MOLPRO executable:', str, path)
print('')
print(centerstring('Scratch directory', 60, '-') + '\n')
print('Please specify an appropriate scratch directory. This will be used to temporally store the integrals. The scratch directory will be deleted after the calculation. Remember that this script cannot check whether the path is valid, since you may run the calculations on a different machine. The path will not be expanded by this script.')
INFOS['scratchdir'] = question('Path to scratch directory:', str)
print('')
print(centerstring('MOLPRO input template file', 60, '-') + '\n')
print('''Please specify the path to the MOLPRO.template file. This file must be a valid MOLPRO input file for a CASSCF calculation. It should contain the following settings:
- memory settings
- Basis set (possibly also Douglas-Kroll settings etc.)
- CASSCF calculation with:
* Number of frozen, closed and occupied orbitals
* wf and state cards for the specification of the wavefunction
MOLPRO.template files can easily be created using molpro_input.py (Open a second shell if you need to create one now).
The MOLPRO interface will generate the remaining MOLPRO input automatically.
''')
if os.path.isfile('MOLPRO.template'):
if checktemplate_MOLPRO('MOLPRO.template'):
print('Valid file "MOLPRO.template" detected. ')
usethisone = question('Use this template file?', bool, True)
if usethisone:
INFOS['molpro.template'] = 'MOLPRO.template'
if 'molpro.template' not in INFOS:
while True:
filename = question('Template filename:', str)
if not os.path.isfile(filename):
print('File %s does not exist!' % (filename))
continue
if checktemplate_MOLPRO(filename):
break
INFOS['molpro.template'] = filename
print('')
print(centerstring('Initial wavefunction: MO Guess', 60, '-') + '\n')
print('''Please specify the path to a MOLPRO wavefunction file containing suitable starting MOs for the CASSCF calculation. Please note that this script cannot check whether the wavefunction file and the Input template are consistent!
If you optimized your geometry with MOLPRO/CASSCF you can reuse the "wf" file from the optimization.
''')
if question('Do you have an initial wavefunction file?', bool, True):
while True:
filename = question('Initial wavefunction file:', str, 'wf.init')
if os.path.isfile(filename):
break
else:
print('File not found!')
INFOS['molpro.guess'] = filename
else:
print('WARNING: Remember that CASSCF calculations may run very long and/or yield wrong results without proper starting MOs.')
time.sleep(2)
INFOS['molpro.guess'] = False
print(centerstring('MOLPRO Ressource usage', 60, '-') + '\n')
print('''Please specify the amount of memory available to MOLPRO (in MB). For calculations including moderately-sized CASSCF calculations and less than 150 basis functions, around 2000 MB should be sufficient.
''')
INFOS['molpro.mem'] = abs(question('MOLPRO memory:', int, [500])[0])
print('''Please specify the number of CPUs to be used by EACH calculation.
''')
INFOS['molpro.ncpu'] = abs(question('Number of CPUs:', int, [1])[0])
if 'wfoverlap' in INFOS['needed']:
print('\n' + centerstring('WFoverlap setup', 60, '-') + '\n')
INFOS['molpro.wfpath'] =
8
questio
AE3D
n('Path to wavefunction overlap executable:', str, '$SHARC/wfoverlap.x')
# TODO: not asked for: numfrozcore, numocc
return INFOS
# =================================================
def prepare_MOLPRO(INFOS, iconddir):
# write MOLPRO.resources
try:
sh2pro = open('%s/MOLPRO.resources' % (iconddir), 'w')
except IOError:
print('IOError during prepareMOLPRO, iconddir=%s' % (iconddir))
quit(1)
string = '''molpro %s
scratchdir %s/%s/
memory %i
ncpu %i
''' % (INFOS['molpro'], INFOS['scratchdir'], iconddir, INFOS['molpro.mem'], INFOS['molpro.ncpu'])
if 'wfoverlap' in INFOS['needed']:
string += 'wfoverlap %s\n' % (INFOS['molpro.wfpath'])
else:
string += '\nnooverlap\n'
sh2pro.write(string)
sh2pro.close()
# copy MOs and template
cpfrom = INFOS['molpro.template']
cpto = '%s/MOLPRO.template' % (iconddir)
shutil.copy(cpfrom, cpto)
if INFOS['molpro.guess']:
cpfrom = INFOS['molpro.guess']
cpto = '%s/wf.init' % (iconddir)
shutil.copy(cpfrom, cpto)
return
# ======================================================================================================================
# ======================================================================================================================
# ======================================================================================================================
def checktemplate_COLUMBUS(TEMPLATE, mult):
'''Checks whether TEMPLATE is a file or directory. If a file or does not exist, it quits with exit code 1, if it is a directory, it checks whether all important input files are there. Does not check for all input files, since runc does this, too.
Arguments:
1 string: path to TEMPLATE
returns whether input is for isc keyword or socinr keyword
and returns the DRT of the given multiplicity'''
exist = os.path.exists(TEMPLATE)
if exist:
isfile = os.path.isfile(TEMPLATE)
if isfile:
# print('TEMPLATE=%s exists and is a file!' % (TEMPLATE))
return None, None, None
necessary = ['control.run', 'mcscfin', 'tranin', 'propin']
lof = os.listdir(TEMPLATE)
for i in necessary:
if i not in lof:
# print('Did not find input file %s! Did you prepare the input according to the instructions?' % (i))
return None, None, None
cidrtinthere = False
ciudginthere = False
for i in lof:
if 'cidrtin' in i:
cidrtinthere = True
if 'ciudgin' in i:
ciudginthere = True
if not cidrtinthere or not ciudginthere:
# print('Did not find input file %s.*! Did you prepare the input according to the instructions?' % (i))
return None, None, None
else:
# print('Directory %s does not exist!' % (TEMPLATE))
return None, None, None
# get integral program
try:
intprog = open(TEMPLATE + '/intprogram')
line = intprog.readline()
if 'hermit' in line:
INTPROG = 'dalton'
elif 'seward' in line:
INTPROG = 'seward'
else:
return None, None, None
except IOError:
return None, None, None
# check cidrtin and cidrtin* for the multiplicity
try:
cidrtin = open(TEMPLATE + '/cidrtin')
line = cidrtin.readline().split()
if line[0].lower() == 'y':
maxmult = int(cidrtin.readline().split()[0])
cidrtin.readline()
nelec = int(cidrtin.readline().split()[0])
if mult <= maxmult and (mult + nelec) % 2 != 0:
return 1, (mult + 1) // 2, INTPROG # socinr=1, single=-1, isc=0
else:
return None, None, None
else:
mult2 = int(cidrtin.readline().split()[0])
if mult != mult2:
# print('Multiplicity %i cannot be treated in directory %s (single DRT)!' % (mult,TEMPLATE))
return None, None, None
return -1, 1, INTPROG
except IOError:
# find out in which DRT the requested multiplicity is
for i in range(1, 9): # COLUMBUS can treat at most 8 DRTs
try:
cidrtin = open(TEMPLATE + '/cidrtin.%i' % i)
except IOError:
return None, None, None
cidrtin.readline()
mult2 = int(cidrtin.readline().split()[0])
if mult == mult2:
return 0, i, INTPROG
cidrtin.close()
# =================================================