forked from mattbernst/composite-thermochemistry-nwchem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gn.py
1176 lines (924 loc) · 39.8 KB
/
Gn.py
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
import glob
import hashlib
import sys
import math
import time
# 'nwchem.py' is an intrinsic module
import nwchem
#______________________________________________________
#
#________________ PHYSICAL CONSTANTS _________________
#______________________________________________________
kCalPerHartree = 627.509541
Boltzmann = 1.3806488E-23
Avogadro = 6.02214129E+23
JoulePerKcal = 4.184E+03
T298 = 298.15
kT_298_perMol = (Boltzmann * T298 * Avogadro) / JoulePerKcal / kCalPerHartree
class G4_mp2(object):
"""
G4(MP2) composite method for Python under NWChem 6.5
Implementation by Matt B. Ernst and Daniel R. Haney
7/18/2015
Gaussian-4 theory using reduced order perturbation theory
Larry A. Curtiss,Paul C. Redfern,Krishnan Raghavachari
THE JOURNAL OF CHEMICAL PHYSICS 127, 124105 2007
1 optimize @ B3LYP/6-31G(2df,p)
2 Ezpe = zpe at B3LYP/6-31G(2df,p)
3 E(MP2) = MP2(fc)/6-31G(d)
4 E(ccsd(t)) = CCSD(fc,T)/6-31G(d)
5 E(HF/G3LXP) = HF/G3LargeXP
6 E(G3LargeXP) = MP2(fc)/G3LargeXP
7 E(HF1) = HF/g4mp2-aug-cc-pVTZ
8 E(HF2) = HF/g4mp2-aug-cc-pVQZ
E(HFlimit) = extrapolated HF limit, =CBS
delta(HF) = E(HFlimit) - E(HF/G3LargeXP)
E(SO) = spin orbit energy
Ehlc = High Level Correction
E(G4(MP2)) = E(CCSD(T)) +
E(G3LargeXP) - E(MP2) +
Delta(HFlimit) +
E(SO) +
E(HLC) +
Ezpe * scale_factor
"""
def __init__(self, charge=0, multiplicity="singlet", tracing=False,
debug=False, integral_memory_cache=3500000000,
integral_disk_cache=0):
multiplets = ["(null)", "singlet", "doublet", "triplet", "quartet",
"quintet", "hextet","septet", "octet"]
self.integral_memory_cache = integral_memory_cache
self.integral_disk_cache = integral_disk_cache
self.nOpen = None
self.multiplicity_numeric = multiplets.index(multiplicity.lower())
self.charge = charge
self.multiplicity = multiplicity
if multiplicity != "singlet":
self.hftype = "uhf"
else:
self.hftype = "rhf"
self.correlated_basis = [("6-31G*", "cartesian"),
("g3mp2largexp", "spherical")]
self.cbs_basis = [("g4mp2-aug-cc-pvtz", "spherical"),
("g4mp2-aug-cc-pvqz", "spherical")]
self.tracing = tracing
self.debug_flag = debug
#Zero Point Energy scale factor for B3LYP/6-31G(2df,p)
self.ZPEScaleFactor = 0.9854 # Curtiss scale factor for Gaussian 09
#self.ZPEScaleFactor = 0.9798 # Truhlar scale Factor for NWChem 6.5
self.atoms = []
self.Ezpe = 0.0
self.Emp2 = 0.0
self.Eccsdt = 0.0
self.Ehfg3lxp = 0.0
self.Emp2g3lxp = 0.0
self.Ehf1 = 0.0
self.Ehf2 = 0.0
self.Ecbs = 0.0
self.Ehlc = 0.0
self.Ethermal = 0.0
self.Hthermal = 0.0
self.E0 = 0.0
self.E298 = 0.0
self.H298 = 0.0
self.dhf0 = 0.0
self.dhf298 = 0.0
# valence electron variables
self.nAlpha = 0
self.nBeta = 0
self.nFrozen = 0
self.geohash = self.geometry_hash()
def say(self, s):
"""Write to stderr console. No implicit newline "\n".
:param s: message to write
:type s : str
"""
if nwchem.ga_nodeid() == 0:
sys.stderr.write(s)
def log(self, s):
"""Write to stdout console.
:param s: message to write
:type s : str
"""
if nwchem.ga_nodeid() == 0:
sys.stdout.write(s + "\n")
def report(self, s):
"""Write to stderr, stdout.
Add newline to stderr.
:param s: message to write
:type s : str
"""
#self.say(s + '\n')
self.log(s)
def debug(self, s):
"""Write message to stderr if debug_flag is on.
:param s: message to write
:type s : str
"""
if self.debug_flag:
self.say("DEBUG: {0}\n".format(s))
def initialize_atoms_list(self):
"""Use NWChem's RTDB geometry to initialize self.atoms,
e.g. CH3OH gives ['C','H','H','H','O''H']
"""
# rtdb_get() returns a string if only one atom
# or a list of atoms (i.e., tags).
# Absent type handling,
# len('CU') is the same as len(['C','U'])
tags = nwchem.rtdb_get("geometry:geometry:tags")
if type(tags) == str:
self.atoms.append(tags)
self.debug('AtomsList: %s\n' % tags)
else:
self.atoms.extend(tags)
if self.debug_flag:
atmstr=''
for atm in tags:
atmstr += ' '+atm
self.debug('AtomsList: %s\n' % atmstr)
self.debug('NumAtoms={0}\n'.format(len(self.atoms)))
def geometry_hash(self):
"""Produce a hashed geometry identifier from the geometry in the
RTDB. This is useful to generate file names for writing and reading
geometry to/from disk.
:return: sha1 hex digest of geometry
:rtype : str
"""
keys = [nwchem.rtdb_first()]
while True:
try:
keys.append(nwchem.rtdb_next())
except nwchem.NWChemError:
break
ckey = [k for k in keys if "coords" in k and "geometry" in k][0]
tkey = [k for k in keys if "tags" in k and "geometry" in k][0]
coords = nwchem.rtdb_get(ckey)
tags = nwchem.rtdb_get(tkey)
fused = " ".join([str(c) for c in coords]) + " ".join([str(t) for t in tags])
result = hashlib.sha1(fused).hexdigest()
return result
def is_molecule(self):
"""Determine if this is a molecular system (more than 1 atom)
:return: True if more than 1 atom, else False
:rtype : bool
"""
return len(self.atoms) > 1
def is_atom(self):
"""Determine if this is an atomic system (just 1 atom)
:return: True if exactly 1 atom, else False
:rtype : bool
"""
return len(self.atoms) == 1
def report_summary(self):
"""Report results in GAMESS G3(MP2) output format for easy comparison.
"""
Szpe = self.Ezpe * self.ZPEScaleFactor
dMP2 = self.Emp2g3lxp - self.Emp2
dHF = self.Ecbs - self.Ehfg3lxp
summary = [
("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~NWChem6.5"),
(" SUMMARY OF G4(MP2) CALCULATIONS"),
(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"),
(" B3LYP/6-31G(2df,p)= % 12.6f HF/maug-cc-p(T+d)Z= % 12.6f" % (self.Eb3lyp, self.Ehf1)),
(" HF/CBS = % 12.6f HF/maug-cc-p(Q+d)Z= % 12.6f" % (self.Ecbs, self.Ehf2)),
(" MP2/6-31G(d) = % 12.6f CCSD(T)/6-31G(d) = % 12.6f" % (self.Emp2, self.Eccsdt)),
(" HF/G3MP2LARGEXP = % 12.6f MP2/G3MP2LARGEXP = % 12.6f" % (self.Ehfg3lxp, self.Emp2g3lxp)),
(" DE(MP2) = % 12.6f DE(HF) = % 12.6f" % (dMP2, dHF)),
(" ZPE(B3LYP) = % 12.6f ZPE SCALE FACTOR = % 12.6f" % (Szpe, self.ZPEScaleFactor)),
(" HLC = % 12.6f FREE ENERGY = % 12.6f" % (self.Ehlc, 0.0)),
(" THERMAL ENERGY = % 12.6f THERMAL ENTHALPY = % 12.6f" % (self.Ethermal, self.Hthermal)),
(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"),
(" E(G4(MP2)) @ 0K = % 12.6f E(G4(MP2)) @298K = % 12.6f" % (self.E0, self.E298)),
(" H(G4(MP2)) = % 12.6f G(G4(MP2)) = % 12.6f" % (self.H298, 0.0)),
(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"),
]
for line in summary:
self.report(line)
def report_dHf(self):
"""Report change in heat of formation going from 0 K to 298 K.
"""
heatsOfFormation = [
#("\n"),
(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"),
(" HEAT OF FORMATION (0K): % 10.2f kCal/mol" % self.dhf0),
(" HEAT OF FORMATION (298K): % 10.2f kCal/mol" % self.dhf298),
(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
]
for line in heatsOfFormation:
self.report(line)
def report_all(self):
self.report_summary ()
self.report_dHf ()
def send_nwchem_cmd(self, s):
"""Send a command to be parsed as NWChem job input language.
:param s: command to sent
:type s : str
"""
nwchem.input_parse(s)
self.debug("cmd: [%s]" % s)
def set_charge(self, charge=0):
"""Set NWChem system charge
:param charge: total system charge
:type charge : int
"""
self.charge = charge
self.send_nwchem_cmd("charge %s" % charge)
def element_number(self, element):
"""Get the atomic number associated with a full element name,
like "lithium". Return 0 if lookup fails.
:param element: element name
:type element : str
:return: atomic number
:rtype : int
"""
elementNames = [ 'zero', # placeholder
'HYDROGEN','HELIUM','LITHIUM','BERYLLIUM','BORON','CARBON',
'NITROGEN','OXYGEN','FLUORINE','NEON','SODIUM','MAGNESIUM',
'ALUMINIUM','SILICON','PHOSPHORUS','SULFUR','CHLORINE','ARGON',
'POTASSIUM','CALCIUM','SCANDIUM','TITANIUM','VANADIUM','CHROMIUM',
'MANGANESE','IRON','COBALT','NICKEL','COPPER','ZINC','GALLIUM',
'GERMANIUM','ARSENIC','SELENIUM','BROMINE','KRYPTON'
]
number = elementNames.index(element.upper())
if number == -1:
number = 0
return number
def symbol_number(self, symbol):
"""Get the atomic number associated with an element symbol, like "Li".
Return 0 if lookup fails.
:param symbol: element symbol
:type symbol : str
:return: atomic number
:rtype : int
"""
atomicSymbols = [ 'zero', # placeholder
'H', 'HE',
'LI','BE','B' ,'C' ,'N' ,'O' ,'F' ,'NE',
'NA','MG','AL','SI','P' ,'S' ,'CL','AR',
'K' ,'CA',
'SC','TI','V' ,'CR','MN','FE','CO','NI','CU','ZN',
'GA','GE','AS','SE','BR','KR'
]
number = atomicSymbols.index(symbol.upper())
if number == -1:
number = 0
return number
def atomic_number(self, s):
"""Get the atomic number of an element symbol or name. Try to treat
the input as a symbol first, then as an element if that fails.
:param s: element symbol or name
:type s : str
:return: atomic number
:rtype : int
"""
return self.symbol_number(s) or self.element_number(s)
def atom_core_orbitals(self, atomicNumber, convention="gamess"):
"""This replicates the core electron pair lookup table in
src/geom/geom_core.F
:param atomicNumber: atomic number of an atom
:type atomicNumber : int
:param convention: "gamess" or "nwchem" table
:type convention : str
:return: number of core orbitals for atom
:rtype : int
"""
#NWChem version 6.5
nwchemCoreOrbitals = [0, # zero index place holder
0, 0,
1, 1, 1, 1, 1, 1, 1, 1,
5, 5, 5, 5, 5, 5, 5, 5,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,43,43,43,43,
43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,
43,43,43,43,]
# GAMESS version 12
gamessCoreOrbitals = [0, # zero index place holder
0, 0,
1, 1, 1, 1, 1, 1, 1, 1,
5, 5, 5, 5, 5, 5, 5, 5,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,14,14,14,14,14,14,
23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,
27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
34,34,34,34,34,34,34,34,34,34,39,39,39,39,39,39,
43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,50]
cmap = {"gamess" : gamessCoreOrbitals, "nwchem" : nwchemCoreOrbitals}
try:
nCoreOrbitals = cmap[convention.lower()]
except KeyError:
raise ValueError("Uknown core orbital convention " + repr(convention))
if atomicNumber <= len(nCoreOrbitals):
n = nCoreOrbitals[atomicNumber]
else:
n = 0
return n
def sum_core_orbitals(self, convention="gamess"):
"""Sum the total number of frozen core orbitals in a system.
nFrozen isn't consistently logged to RTDB by
Tensor Contraction Engine methods, so do the work ourselves.
:param convention: orbital freeze convention, "gamess" or "nwchem"
:type convention : str
:return: sum of frozen core orbitals
:rtype : int
"""
total = sum([self.atom_core_orbitals(self.atomic_number(a),
convention=convention)
for a in self.atoms])
return total
def spin_orbit_energy(self):
"""Get spin orbit energy correction according to nature of system and charge.
:return: spin orbit energy correction
:rtype : float
"""
if self.is_molecule(): # no spin orbit corrections for molecules
correction = 0.0
else: # It's an atom
atom = self.atoms[0]
correction = self.E_spin_orbit(self.atomic_number(atom),
self.charge)
return correction
def atomic_DHF (self, elementNum):
"""Get atomic heats of formation at 0 K and 298 K, in
kcal/mol.
:param elementNum: atomic number
:type elementNum : int
:return: atomic heats of formation
:rtype : tuple
"""
#atom [dHf(0), dHf(298)] in kcal/mol
atomDHF = [
[0.0,0.0], # 00 zero placeholder
[51.63, 52.103 ], # 01 Hydrogen
[0.00, 0.00 ], # 02 Helium
[37.70, 38.07 ], # 03 Lithium
[76.40, 77.40 ], # 04 Beryllium
[135.10, 136.30 ], # 05 Boron
[169.98, 171.29 ], # 06 Carbon
[112.53, 112.97 ], # 07 Nitrogen
[58.99, 59.56 ], # 08 Oxygen
[18.47, 18.97 ], # 09 Fluorine
[0.00, 0.00 ], # 10 Neon
[25.76, 25.69 ], # 11 Sodium
[34.87, 35.16 ], # 12 Magnesium
[80.20, 80.80 ], # 13 Aluminum
[107.20, 108.20 ], # 14 Silicon
[75.45, 75.65 ], # 15 Phosphorus
[65.71, 66.25 ], # 16 Sulfur
[28.59, 28.99 ], # 17 Chlorine
[0.00, 0.00 ], # 18 Argon
[21.27, 21.49 ], # 19 Potassium
[42.50, 42.29 ], # 20 Calcium
[0.0,0.0],[0.0,0.0], # transition elements 21-30 Sc-Zn
[0.0,0.0],[0.0,0.0],
[0.0,0.0],[0.0,0.0],
[0.0,0.0],[0.0,0.0],
[0.0,0.0],[0.0,0.0],
[65.00, 65.00 ], # 31 Gallium
[88.91, 88.91 ], # 32 Germanium
[73.90, 72.42 ], # 33 Arsenic
[55.76, 54.27 ], # 34 Selenium
[26.74, 28.18 ], # 35 Bromine
[0.0, 0.0 ], # 36 Krypton
]
self.debug('atomic_DHF: elementNum=%d' % elementNum)
try:
result = atomDHF[elementNum]
self.debug('atomic_DHF: E,H=%.2f,%.2f' % (result[0], result[1]))
except IndexError:
self.debug('atomic_DHF: error: element %d not in table?' % elementNum)
result = (0.0, 0.0)
return result
def E0_atom(self, elementNum):
"""List of precalculated atomic G4(MP2) energies at 0K
Returns E(0K), E(298.15K) tuple.
:param elementNum: atomic number
:type elementNum : int
:return: energy at 0 K and 298 K
:rtype : tuple
"""
e0_g4mp2 = [ 0.0 , # 00 zero index place holder
-0.502094 , # 01 H Hydrogen
-2.892437 , # 02 He Helium
-7.434837 , # 03 Li Lithium
-14.618701 , # 04 Be Beryllium
-24.610037 , # 05 B Boron
-37.794204 , # 06 C Carbon
-54.532825 , # 07 N Nitrogen
-75.002483 , # 08 O Oxygen
-99.659686 , # 09 F Fluorine
-128.854769 , # 10 Ne Neon
-161.860999 , # 11 Na Sodium
-199.646948 , # 12 Mg Magnesium
-241.944728 , # 13 Al Aluminum
-288.947800 , # 14 Si Silicon
-340.837016 , # 15 P Phosphorus
-397.676523 , # 16 S Sulfur
-459.703691 , # 17 Cl Chlorine
-527.083295 , # 18 Ar Argon
-599.166975 , # 19 K Potassium
-676.784184 , # 20 Ca Calcium
0.0,0.0,0.0, # 21-23 transition metals
0.0,0.0,0.0, # 24-26 transition metals
0.0,0.0,0.0, # 27-29 transition metals
0.0, # 30 transition metals
-1923.601298 , # 31 Ga Gallium
-2075.700329 , # 32 Ge Germanium
-2234.578295 , # 33 As Arsenic
-2400.243694 , # 34 Se Selenium
-2572.850476 , # 35 Br Bromine
-2752.487773 , # 36 Kr Krypton
]
# Ideal gas kinetic energy contribution
eth = (5.0/2) * kT_298_perMol
try:
e0 = e0_g4mp2[elementNum]
e298 = e0 + eth
result = (e0, e298)
except IndexError:
result = (0.0, 0.0)
return result
def calc_deltaHf(self):
"""Calculate heat of formation at 0K and 298K.
ALWAYS returns False, silently fails so that the summary is printed.
:return: failure code (True for failure, False for success)
:rtype : bool
"""
sum_atoms_E0 = 0.0
sum_atoms_E298 = 0.0
sum_atoms_dhf0 = 0.0
sum_atoms_dhf298 = 0.0
if self.is_molecule():
for atom in self.atoms:
e0, e298 = self.E0_atom(self.atomic_number(atom))
sum_atoms_E0 += e0
sum_atoms_E298 += e298
d0, d298 = self.atomic_DHF(self.atomic_number(atom))
sum_atoms_dhf0 += d0
sum_atoms_dhf298 += d298
self.debug('sumDHF0,sumDHF298 = %.2f,%.2f' % (sum_atoms_dhf0, sum_atoms_dhf298))
else:
return False
self.dhf0 = (self.E0 - sum_atoms_E0) * kCalPerHartree + sum_atoms_dhf0
self.dhf298 = (self.H298 - sum_atoms_E298) * kCalPerHartree + sum_atoms_dhf298
self.debug('dhf0,dhf298 = %.2f,%.2f' % (self.dhf0, self.dhf298))
return False
def init_g4mp2(self):
"""Say hello.
"""
title = nwchem.rtdb_get("title")
self.say(" %s -- NWChem G4(MP2) Composite Method\n" % (title))
return False
def build_SCF_cmd(self):
"""Prepare SCF block with multiplicity-appropriate choice of
HF form.
:return: SCF control block
:rtype : str
"""
memory_cache_words = self.integral_memory_cache / 8
disk_cache_words = self.integral_disk_cache / 8
tpl = "scf ; semidirect memsize {0} filesize {1}; {2} ; {3} ; end"
block = tpl.format(memory_cache_words, disk_cache_words,
self.multiplicity, self.hftype)
return block
def E_spin_orbit(self, atomic_number, charge):
"""EspinOrbit tabulates the spin orbit energies
of atomic species in the first three rows as listed in
Gaussian-4 theory
Larry A. Curtiss,Paul C. Redfern,Krishnan Raghavachari
JOURNAL OF CHEMICAL PHYSICS 126, 084108 (2007)
DOI: 10.1063/1.2436888
This table contains lists of spin orbit energies for
[neutral,positive,negative] species.
When Curtiss lists no values, 0.0 is returned.
Values may not agree with current NIST listings.
Although table values are in milli-Hartrees,
function E_spin_orbit returns values in Hartrees.
:param atomic_number: atomic number of atomic species
:type atomic_number : int
:param charge: charge on atomic species
:type charge : int
:return: energy in Hartrees
:rtype : float
"""
# [neutral, Z+, Z- ]
ESpinOrbit = [
[ 0.0, 0.0, 0.0 ], # 00 zero index place holder
[ 0.0, 0.0, 0.0 ], # 01 H Hydrogen
[ 0.0, 0.0, 0.0 ], # 02 He Helium
[ 0.0, 0.0, 0.0 ], # 03 Li Lithium
[ 0.0, 0.0, 0.0 ], # 04 Be Beryllium
[-0.05, 0.0, -0.03], # 05 B Boron
[-0.14, -0.2, 0.0 ], # 06 C Carbon
[ 0.0, -0.43, 0.0 ], # 07 N Nitrogen
[-0.36, 0.0, -0.26], # 08 O Oxygen
[-0.61, -0.67, 0.0 ], # 09 F Fluorine
[ 0.0, -1.19, 0.0 ], # 10 Ne Neon
[ 0.0, 0.0, 0.0 ], # 11 Na Sodium
[ 0.0, 0.0, 0.0 ], # 12 Mg Magnesium
[-0.34, 0.0, -0.28], # 13 Al Aluminum
[-0.68, -0.93, 0.0 ], # 14 Si Silicon
[ 0.0, -1.43, -0.45], # 15 P Phosphorus
[-0.89, 0.0, -0.88], # 16 S Sulfur
[-1.34, -1.68, 0.0 ], # 17 Cl Chlorine
[ 0.0, -2.18, 0.0 ], # 18 Ar Argon
[ 0.0, 0.0, 0.0 ], # 19 K Potassium
[ 0.0, 0.0, 0.0 ], # 20 Ca Calcium
[ 0.0, 0.0, 0.0 ], # 21 Sc Scandium
[ 0.0, 0.0, 0.0 ], # 22 Ti Titanium
[ 0.0, 0.0, 0.0 ], # 23 V Vanadium
[ 0.0, 0.0, 0.0 ], # 24 Cr Chromium
[ 0.0, 0.0, 0.0 ], # 25 Mn Manganese
[ 0.0, 0.0, 0.0 ], # 26 Fe Iron
[ 0.0, 0.0, 0.0 ], # 27 Co Cobalt
[ 0.0, 0.0, 0.0 ], # 28 Ni Nickel
[ 0.0, 0.0, 0.0 ], # 29 Cu Copper
[ 0.0, 0.0, 0.0 ], # 30 Zn Zinc
[-2.51, 0.0, 0.0 ], # 31 Ga Gallium
[-4.41, -5.37, 0.0 ], # 32 Ge Germanium
[ 0.0, -8.04, 0.0 ], # 33 As Arsenic
[-4.3, 0.0, 0.0 ], # 34 Se Selenium
[-5.6, -6.71, 0.0 ], # 35 Br Bromine
[ 0.0, -8.16, 0.0 ] # 36 Kr Krypton
]
if not atomic_number in range(len(ESpinOrbit)):
return 0.0
if charge > 0:
ion = 1
elif charge < 0:
ion = 2
else:
ion = 0
milliHa_to_Ha = 0.001
espin = ESpinOrbit[atomic_number][ion] * milliHa_to_Ha
return espin
def reset_symmetry(self):
"""Reload geometry and force symmetry down if TCE must be used.
"""
xyzs = glob.glob(self.geohash + "*.xyz")
xyzs.sort()
#handle atomic calculations that have no geometry optimization step
if not xyzs:
return
geofile = xyzs[-1]
#TODO: use Abelian symmetries instead of c1
if self.multiplicity != "singlet":
symmetry_block = "symmetry c1;"
else:
symmetry_block = ""
geoblock = "geometry units angstroms print xyz; {0} load {1}; end"
self.send_nwchem_cmd(geoblock.format(symmetry_block, geofile))
def basis_prepare(self, basis, input="", output="",
coordinates="spherical", context="scf"):
"""Set up commands to store vectors to a file and/or project or
load stored vectors for use as initial guess. Also handles
switching between basis sets.
:param basis: name of current basis set
:type basis :str
:param input: optional name of basis set for vector input
:type input : str
:param output: optional name of basis set for vector output
:type output : str
:param coordinates: "cartesian" or "spherical", for current basis
:type coordinates : str
:param context: "scf" or "dft" vectors setup context
:type context : str
"""
def simplename(basis_name):
name = basis_name[:]
t = {"-" : "_", "*" : "star", "+" : "plus",
"(" : "", ")" : "", "," : "_"}
for key, value in t.items():
name = name.replace(key, value)
return name
sn = simplename(basis)
sn_input = simplename(input)
sn_output = simplename(output)
basis_cmd = "basis {0} {1} ; * library {2} ; end".format(sn, coordinates, basis)
self.send_nwchem_cmd(basis_cmd)
self.send_nwchem_cmd('set "ao basis" {0}'.format(sn))
if input and output:
t = "{context}; vectors input project {small} {small}.movecs output {large}.movecs; end"
vectors = t.format(context=context, small=sn_input, large=sn_output)
elif input:
t = "{context}; vectors input {small}.movecs; end"
vectors = t.format(context=context, small=sn_input)
elif output:
t = "{context}; vectors input atomic output {large}.movecs; end"
vectors = t.format(context=context, large=sn_output)
else:
self.say("MUST SUPPLY AT LEAST ONE OF input, output for basis_prepare")
sys.exit(1)
self.send_nwchem_cmd(vectors)
def prepare_scf_vectors(self):
"""Set up converged scf vectors before first correlated steps so they
can be used to initialize later calculations.
"""
self.basis_prepare(self.correlated_basis[0][0],
output=self.correlated_basis[0][0],
coordinates=self.correlated_basis[0][1])
self.send_nwchem_cmd(self.build_SCF_cmd())
nwchem.task_energy("scf")
def optimize(self):
"""# 1 optimize B3LYP/6-31G(2df,p)
"""
self.say('optimize.')
self.send_nwchem_cmd("basis noprint ; * library 6-31G(2df,p) ; end")
#self.send_nwchem_cmd("basis spherical noprint ; * library 6-31G(2df,p) ; end")
scfcmd = self.build_SCF_cmd()
self.send_nwchem_cmd(scfcmd)
# canonical B3LYP spec
# GAMESS-US b3lyp uses VWN_5
# Gaussian uses VWN_3
# NWChem uses something entirely different
b3lyp_GAMESS = 'xc HFexch 0.2 slater 0.8 becke88 nonlocal 0.72 vwn_5 0.19 lyp 0.81'
b3lyp_Gaussian = 'xc HFexch 0.2 slater 0.8 becke88 nonlocal 0.72 vwn_3 0.19 lyp 0.81'
b3lyp_NWChem = 'xc b3lyp'
blips = b3lyp_Gaussian
memory_cache_words = self.integral_memory_cache / 8
disk_cache_words = self.integral_disk_cache / 8
mem = "semidirect memsize {0} filesize {1}".format(memory_cache_words,
disk_cache_words)
if self.multiplicity != "singlet":
self.send_nwchem_cmd('dft ; odft ; mult %d ; %s ; %s ; end' % (self.multiplicity_numeric, blips, mem))
else:
self.send_nwchem_cmd('dft ; %s ; %s ; end' % (blips, mem))
# fetch and copy atom names list (tags) which enumerates atoms.
# only available _after_ SCF statement
self.initialize_atoms_list()
self.send_nwchem_cmd("driver; maxiter 999; xyz {0}; end".format(self.geohash))
self.send_nwchem_cmd("scf; maxiter 999; end")
# optimize the geometry, ignore energy and gradient results
if self.is_atom():
en = nwchem.task_energy("dft")
else:
self.debug("task_optimize(dft)")
en, grad = nwchem.task_optimize("dft")
self.Eb3lyp = en
#self.report("debug: HF/6-31G(2df,p) SCF:energy = %f Ha" % (en))
def E_zpe(self):
"""Run hessian on equilibrium geometry, get zero point energy.
n
Note: linear tri-atomics and larger give high ZPE values in
NWChem @ HF/6-31G*
"""
self.say('ZPE.')
AUKCAL = 627.5093314
c = 2.99792458E+10
h = 6.62606957E-27
kgas = 1.3806488E-16 # cgs units
Rgas = 1.9872041/1000.0/AUKCAL # atomic units
temperature = 298.15
if self.is_atom():
self.Ezpe = 0.0
self.Ethermal = 1.5 * Rgas * temperature # 3/2 * RT
self.Hthermal = self.Ethermal + (Rgas * temperature)
return False
# run hessian on equilibrium geometry
# ignore ZPE, calculate it from vibrations list
zpe, vibs, intens = nwchem.task_freq("dft")
# Handroll the ZPE because NWChem's zpe accumulates
# truncation error from 3 sigfig physical constants.
vibsum = 0.0
for freq in vibs:
if (freq > 0.1):
vibsum += freq
cm2Ha = 219474.6 # cm-1 to Hartree conversion
self.Ezpe = vibsum / (2.0 * cm2Ha)
# shamelessly swipe code from NWCHEM/src/vib_wrtFreq.F
eth = 0.0
hth = 0.0
xdum = 0.0
for freq in vibs:
if (freq > 0.1):
thetav = freq * (h * c / kgas) #freqency temperature in Kelvin from cm-1
if (temperature > 0.0):
xdum = math.exp(-thetav/temperature)
else:
xdum = 0.0
xdum = xdum / (1.0 - xdum)
eth = eth + thetav * (0.5 + xdum)
eth = eth * Rgas
# linear boolean is available only after task_freq('scf') runs
# NWChem only writes the flag if molecule is linear
try:
is_linear = nwchem.rtdb_get("vib:linear")
except:
is_linear = False
if (is_linear):
# translational(3/2RT) and rotation(2/2RT) thermal corrections
eth = eth + 2.5 * Rgas * temperature
else:
# translational(3/2RT) and rotation(3/2RT) thermal corrections
eth = eth + 3.0 * Rgas * temperature
# Hthermal = eth+pV=eth+RT, since pV=RT
hth = eth + Rgas * temperature
self.debug("Handrolled E,H thermal= %.6f, %.6f\n" % (eth,hth))
self.Ethermal = eth
self.Hthermal = hth
def E_mp2(self):
"""Calculate the MP2 energy at the B3LYP-optimized geometry.
# 3 E_(MP2) = MP2(fc)/6-31G(d)//B3LYP/6-31G(2df,p)
:return: failure code (True for failure, False for success)
:rtype : bool
"""
self.say('MP2(fc).')
self.basis_prepare(self.correlated_basis[0][0],
input=self.correlated_basis[0][0],
coordinates=self.correlated_basis[0][1])
scfcmd = self.build_SCF_cmd()
self.send_nwchem_cmd(scfcmd)
self.send_nwchem_cmd("unset mp2:*")
self.send_nwchem_cmd("mp2 ; freeze atomic ; end")
try:
if self.multiplicity != "singlet":
self.send_nwchem_cmd("unset tce:*")
self.send_nwchem_cmd("tce ; scf ; mp2 ; freeze atomic ; end")
en = nwchem.task_energy("tce")
else:
en = nwchem.task_energy("mp2")
self.debug('MP2 frozen: en=%.6f\n' % en)
except:
self.report("FAILED: MP2(fc)/6-31G(2df,p) energy")
return True
else:
self.Emp2 = en
return False
def E_ccsdt(self):
"""# 4 E_(ccsd(t)) = CCSD(fc,T)/6-31G(d)
Get CCSDT(fc)/6-31G(d) energy
"""
self.say("CCSD(T).")
if self.multiplicity != "singlet" or self.is_atom():
self.send_nwchem_cmd("unset tce:*")
self.send_nwchem_cmd("tce ; ccsd(t) ; freeze atomic ; end")
en = nwchem.task_energy("tce")
else:
self.send_nwchem_cmd("ccsd ; freeze atomic ; end")
en = nwchem.task_energy("ccsd(t)")
self.debug('CCSD(T): en=%.6f\n' % en)
self.Eccsdt = en
def E_hf_g3lxp(self):
"""# 5 E_(HF/G3LXP) = HF/G3LargeXP
"""
self.basis_prepare(self.correlated_basis[1][0],
input=self.correlated_basis[0][0],
output=self.correlated_basis[1][0],
coordinates=self.correlated_basis[1][1])
en = nwchem.task_energy("scf")
self.Ehfg3lxp = en
self.debug("HF/G3LargeXP SCF:energy = %f Ha" % (en))
def E_mp2_g3lxp(self):
"""# 5 E_(HF/G3LXP) = MP2fc/G3LargeXP
"""
self.basis_prepare(self.correlated_basis[1][0],
input=self.correlated_basis[1][0],
coordinates=self.correlated_basis[1][1])
self.send_nwchem_cmd("unset mp2:*")
self.send_nwchem_cmd("mp2 ; freeze atomic ; end")
if self.multiplicity != "singlet" or self.is_atom():
self.send_nwchem_cmd("unset tce:*")
self.send_nwchem_cmd("tce ; mp2 ; freeze atomic ; end")
en = nwchem.task_energy("tce")
else:
en = nwchem.task_energy("mp2")
self.debug('MP(2,fc)/g3mp2large: en=%.6f\n' % en)
self.Emp2g3lxp = en
def E_hf1(self):
"""Use g4mp2-aug-cc-pvtz basis set to get first HF energy.
"""
self.say("HF1.")
self.basis_prepare(self.cbs_basis[0][0],
input=self.correlated_basis[0][0],
output=self.cbs_basis[0][0],
coordinates=self.cbs_basis[0][1])