@@ -55,6 +55,7 @@ def __init__(
55
55
}
56
56
exc_keyword = [key for key in "td tda cis" .split () if key in keywords ]
57
57
self .nstates = self .nroots
58
+ self .exc_args = None
58
59
if exc_keyword :
59
60
self .exc_key = exc_keyword [0 ]
60
61
exc_dict = keywords [self .exc_key ]
@@ -101,6 +102,7 @@ def __init__(
101
102
self .gaussian_input = textwrap .dedent (self .gaussian_input )
102
103
103
104
self .parser_funcs = {
105
+ "energy" : self .parse_energy ,
104
106
"force" : self .parse_force ,
105
107
"hessian" : self .parse_hessian ,
106
108
"stable" : self .parse_stable ,
@@ -118,8 +120,7 @@ def __init__(
118
120
)
119
121
120
122
def make_exc_str (self ):
121
- # Ground state calculation
122
- if not self .track and (self .root is None ):
123
+ if self .exc_args is None :
123
124
return ""
124
125
root = self .root if self .root is not None else 1
125
126
root_str = f"root={ root } "
@@ -341,7 +342,25 @@ def store_and_track(self, results, func, atoms, coords, **prepare_kwargs):
341
342
return results
342
343
343
344
def get_energy (self , atoms , coords , ** prepare_kwargs ):
344
- return self .get_forces (atoms , coords , ** prepare_kwargs )
345
+ did_stable = False
346
+ if self .stable :
347
+ is_stable = self .run_stable (atoms , coords )
348
+ self .log (f"Wavefunction is now stable: { is_stable } " )
349
+ did_stable = True
350
+ inp = self .prepare_input (
351
+ atoms , coords , "sp" , did_stable = did_stable , ** prepare_kwargs
352
+ )
353
+ kwargs = {
354
+ "calc" : "energy" ,
355
+ }
356
+ results = self .run (inp , ** kwargs )
357
+ results = self .store_and_track (
358
+ results , self .get_energy , atoms , coords , ** prepare_kwargs
359
+ )
360
+ return results
361
+
362
+ def get_all_energies (self , atoms , coords , ** prepare_kwargs ):
363
+ return self .get_energy (atoms , coords , ** prepare_kwargs )
345
364
346
365
def get_forces (self , atoms , coords , ** prepare_kwargs ):
347
366
did_stable = False
@@ -574,33 +593,41 @@ def prepare_overlap_data(self, path):
574
593
all_energies [1 :] += exc_energies
575
594
return C , X , Y , all_energies
576
595
577
- def parse_force (self , path ):
596
+ def parse_energy (self , path ):
578
597
results = {}
579
- keys = ("SCF Energy" , "Total Energy" , "Cartesian Gradient" )
598
+ keys = ("SCF Energy" , "Total Energy" )
580
599
fchk_path = Path (path ) / f"{ self .fn_base } .fchk"
581
600
fchk_dict = self .parse_fchk (fchk_path , keys )
582
601
results ["energy" ] = fchk_dict ["SCF Energy" ]
583
- results ["forces" ] = - fchk_dict ["Cartesian Gradient" ]
584
602
585
603
if self .nstates :
586
604
# This sets the proper excited state energy in the
587
605
# results dict and also stores all energies.
588
606
exc_energies = self .parse_tddft (path )
589
607
# G16 root input is 1 based, so we substract 1 to get
590
608
# the right index here.
591
- root = self .root if self .root is not None else 1
592
- root_exc_en = exc_energies [root - 1 ]
593
609
gs_energy = fchk_dict ["SCF Energy" ]
594
- # Add excitation energy to ground state energy.
595
- results ["energy" ] += root_exc_en
596
- # Create a new array including the ground state energy
597
- # to save the energies of all states.
598
- all_ens = np .full (len (exc_energies ) + 1 , gs_energy )
599
- all_ens [1 :] += exc_energies
600
- results ["all_energies" ] = all_ens
610
+ # Modify "energy" when a root is selected
611
+ if self .root is not None :
612
+ root_exc_en = exc_energies [self .root - 1 ]
613
+ # Add excitation energy to ground state energy.
614
+ results ["energy" ] += root_exc_en
615
+ # Create a new array including the ground state energy
616
+ # to save the energies of all states.
617
+ all_ens = np .full (len (exc_energies ) + 1 , gs_energy )
618
+ all_ens [1 :] += exc_energies
619
+ results ["all_energies" ] = all_ens
601
620
602
621
return results
603
622
623
+ def parse_force (self , path ):
624
+ results = self .parse_energy (path )
625
+ keys = ("Cartesian Gradient" ,)
626
+ fchk_path = Path (path ) / f"{ self .fn_base } .fchk"
627
+ fchk_dict = self .parse_fchk (fchk_path , keys )
628
+ results ["forces" ] = - fchk_dict ["Cartesian Gradient" ]
629
+ return results
630
+
604
631
def parse_hessian (self , path ):
605
632
keys = (
606
633
"Total Energy" ,
0 commit comments