Skip to content

Commit

Permalink
Gaussian Troubleshooting Cleanup (#764)
Browse files Browse the repository at this point in the history
Cleaned up a couple of issue with the Gaussian Troubleshooting and added
some additional tests for the Troubleshooting
Also added new trsh methods
  • Loading branch information
alongd authored Sep 2, 2024
2 parents 9e5c210 + a8ecf99 commit 5a82b3c
Show file tree
Hide file tree
Showing 6 changed files with 37,602 additions and 54 deletions.
25 changes: 19 additions & 6 deletions arc/job/adapters/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,24 @@ def write_input_file(self) -> None:
self.level.method = 'cbs-qb3'

# Job type specific options
max_c = self.args['trsh'].split()[1] if 'max_cycles' in self.args['trsh'] else 100
max_c = 100
if 'trsh' in self.args and 'trsh' in self.args['trsh']:
for item in self.args['trsh']['trsh']:
match = re.search(r'maxcycle=(\d+)', item)
if match:
max_c = int(match.group(1))
break

if self.job_type in ['opt', 'conformers', 'optfreq', 'composite']:
keywords = ['ts', 'calcfc', 'noeigentest', f'maxcycles={max_c}'] if self.is_ts else ['calcfc']
keywords = ['ts', 'calcfc', 'noeigentest', f'maxcycle={max_c}'] if self.is_ts else ['calcfc']
if self.level.method in ['rocbs-qb3']:
# There are no analytical 2nd derivatives (FC) for this method.
keywords = ['ts', 'noeigentest', 'maxcycles=100'] if self.is_ts else []
keywords = ['ts', 'noeigentest', f'maxcycle={max_c}'] if self.is_ts else []
if self.fine:
if self.level.method_type in ['dft', 'composite']:
# Note that the Acc2E argument is not available in Gaussian03
input_dict['fine'] = f'integral=(grid=ultrafine, {integral_algorithm})'
# input_dict['trsh'] may have scf=(...) in it, so we need to add the tight and direct keywords to it
# input_dict['trsh'] may have scf=(...) in it, so we need to add the tight and direct keywords to it
scf_start = input_dict['trsh'].find('scf=(')
scf_end = input_dict['trsh'].find(')', scf_start)
scf_fine_content = 'tight,direct'
Expand All @@ -295,7 +302,7 @@ def write_input_file(self) -> None:
if self.is_ts:
keywords.extend(['tight', 'maxstep=5'])
else:
keywords.extend(['tight', 'maxstep=5'])
keywords.extend(['tight', 'maxstep=5', f'maxcycle={max_c}'])
input_dict['job_type_1'] = "opt" if self.level.method_type not in ['dft', 'composite', 'wavefunction']\
else f"opt=({', '.join(key for key in keywords)})"

Expand Down Expand Up @@ -390,11 +397,17 @@ def write_input_file(self) -> None:

#Fix SCF
# This may be redundant due to additional fixes in the above code
terms = ['scf=\((.*?)\)', 'scf=(\w+)']
terms = [r'scf=\((.*?)\)', r'scf=(\w+)']
input_dict, parameters = combine_parameters(input_dict, terms)
if parameters:
input_dict['trsh'] += f" scf=({','.join(parameters)})"

# Fix IRC
terms_irc = [r'irc=\((.*?)\)', r'irc=(\w+)']
input_dict, parameters_irc = combine_parameters(input_dict, terms_irc)
if parameters_irc:
input_dict['job_type_1'] = f"irc=({','.join(parameters_irc)}) {input_dict['job_type_1']}"

# Remove double spaces
input_dict['job_type_1'] = input_dict['job_type_1'].replace(' ', ' ')

Expand Down
196 changes: 178 additions & 18 deletions arc/job/adapters/gaussian_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,76 @@ def setUpClass(cls):
args=args
)

# Gaussian MaxOptCycles error - Part 1
# Intend to troubleshoot a MaxOptCycles error by adding opt=(maxcycle=200) to the input file
job_status = {'keywords': ['MaxOptCycles']}
ess_trsh_methods = ['']
output_errors, ess_trsh_methods, remove_checkfile, level_of_theory, software, job_type, fine, trsh_keyword, \
memory, shift, cpu_cores, couldnt_trsh = trsh.trsh_ess_job(label, level_of_theory, server, job_status,
job_type, software, fine, memory_gb,
num_heavy_atoms, cpu_cores, ess_trsh_methods)
args = {'keyword': {}, 'block': {}}
if trsh_keyword:
args['trsh'] = {'trsh': trsh_keyword}
cls.job_22 = GaussianAdapter(execution_type='local',
job_type='opt',
level=Level(method='wb97xd'),
fine=True,
ess_trsh_methods=ess_trsh_methods,
project='test',
project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'),
species=[spc_11],
testing=True,
args=args
)

# Gaussian MaxOptCycles error - Part 2
# Intend to troubleshoot a MaxOptCycles error by adding opt=(RFO) to the input file
job_status = {'keywords': ['MaxOptCycles']}
ess_trsh_methods = ['opt=(maxcycle=200)']
output_errors, ess_trsh_methods, remove_checkfile, level_of_theory, software, job_type, fine, trsh_keyword, \
memory, shift, cpu_cores, couldnt_trsh = trsh.trsh_ess_job(label, level_of_theory, server, job_status,
job_type, software, fine, memory_gb,
num_heavy_atoms, cpu_cores, ess_trsh_methods)
args = {'keyword': {}, 'block': {}}
if trsh_keyword:
args['trsh'] = {'trsh': trsh_keyword}
cls.job_23 = GaussianAdapter(execution_type='local',
job_type='opt',
level=Level(method='wb97xd'),
fine=True,
ess_trsh_methods=ess_trsh_methods,
project='test',
project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'),
species=[spc_11],
testing=True,
args=args
)

# Gaussian MaxOptCycles error - Part 3
# Intend to troubleshoot a MaxOptCycles error by adding opt=(GDIIS) and removing opt=(RFO) to the input file
job_status = {'keywords': ['MaxOptCycles']}
ess_trsh_methods = ['opt=(maxcycle=200)', 'opt=(RFO)']
output_errors, ess_trsh_methods, remove_checkfile, level_of_theory, software, job_type, fine, trsh_keyword, \
memory, shift, cpu_cores, couldnt_trsh = trsh.trsh_ess_job(label, level_of_theory, server, job_status,
job_type, software, fine, memory_gb,
num_heavy_atoms, cpu_cores, ess_trsh_methods)

args = {'keyword': {}, 'block': {}}
if trsh_keyword:
args['trsh'] = {'trsh': trsh_keyword}
cls.job_24 = GaussianAdapter(execution_type='local',
job_type='opt',
level=Level(method='wb97xd'),
fine=True,
ess_trsh_methods=ess_trsh_methods,
project='test',
project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'),
species=[spc_11],
testing=True,
args=args
)


def test_set_cpu_and_mem(self):
"""Test assigning number of cpu's and memory"""
Expand Down Expand Up @@ -625,7 +695,7 @@ def test_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P irc=(CalcAll, reverse, maxpoints=50, stepsize=7) wb97xd/def2tzvp IOp(2/9=2000)
#P irc=(CalcAll,maxpoints=50,reverse,stepsize=7) wb97xd/def2tzvp IOp(2/9=2000)
IRC
Expand Down Expand Up @@ -705,12 +775,21 @@ def test_gaussian_def2tzvp(self):

def test_trsh_write_input_file(self):
"""Test writing a trsh input file
1. Test with getting Acc2E14 as the trsh method and thus changing the input file integral algorithm, and is also 'fine' thus it will have direct and tight SCF (but not xqc)
2. Test with getting Acc2E14 as the trsh method but also checkfile=None in ess_trsh_methods, thus it will have both changes in the input file
3. Test with getting Acc2E14 as the trsh method but also checkfile=None in ess_trsh_methods and first SCF error thus it will have all three changes in the input file
4. Test with getting Acc2E14 as the trsh method but also checkfile=None in ess_trsh_methods and first and second SCF error and also the input file already has the integral algorithm change thus it will have all four changes in the input file
5. Test with getting Acc2E14 as the trsh method but also checkfile=None in ess_trsh_methods and first, second and third SCF error and also the input file already has the integral algorithm change and also the input file already has the scf algorithm change thus it will have all five changes in the input file
6. Test with all previous errors but now include an internal coordinate error thus it will have all six changes in the input file
10. Create an input file for a job with int=(Acc2E=14) included
11. Create an input file for a job with guess=mix included (removal of Checkfile via ess_trsh_methods)
12. Create an input file for a job with nosymm included, and also the first pass of SCF error troubleshooting
13. Create an input file for a job with NDamp=30 included, and also the previous pass of SCF error troubleshooting
14. Create an input file for a job with NoDIIS included, and also previous passes of SCF error troubleshooting
15. Create an input file for an opt job that has an internal coordinate error and so includes 'cartesian' in the input file and also includes all previous passes of SCF error troubleshooting
16. Create an input file for a job with all SCF troubleshooting methods included
17. Create an input file for a job with MaxOptCycles error and SCF error
18. Create an input file for a job with L502 error and InaccurateQuadrature
19. Create an input file for a job with L502 error but had already been troubleshooted with L502 error
20. Create an input file for a job with L502 error but had already been troubleshooted with L502 error and InaccurateQuadrature
21. Create an input file for a job with L502 error but had already been troubleshooted with L502 error and InaccurateQuadrature
22. Create an input file for a job with MaxOptCycles error - changes maxcycle to 200 from 100
23. Create an input file for a job with MaxOptCycles error - Add RFO to the input file
24. Create an input file for a job with MaxOptCycles error - Add GDIIS and remove RFO from the input file
"""
self.job_10.write_input_file()
with open(os.path.join(self.job_10.local_path, input_filenames[self.job_10.job_adapter]), 'r') as f:
Expand All @@ -719,7 +798,7 @@ def test_trsh_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P opt=(calcfc,maxstep=5,tight) uwb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=(direct,tight)
#P opt=(calcfc,maxcycle=100,maxstep=5,tight) uwb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=(direct,tight)
anion
Expand All @@ -737,7 +816,7 @@ def test_trsh_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P opt=(calcfc,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=(direct,tight)
#P opt=(calcfc,maxcycle=100,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=(direct,tight)
ethanol
Expand All @@ -763,7 +842,7 @@ def test_trsh_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P opt=(calcfc,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) nosymm scf=(direct,tight,xqc)
#P opt=(calcfc,maxcycle=100,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) nosymm scf=(direct,tight,xqc)
ethanol
Expand All @@ -789,7 +868,7 @@ def test_trsh_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P opt=(calcfc,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) nosymm scf=(NDamp=30,direct,tight,xqc)
#P opt=(calcfc,maxcycle=100,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) nosymm scf=(NDamp=30,direct,tight,xqc)
ethanol
Expand All @@ -815,7 +894,7 @@ def test_trsh_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P opt=(calcfc,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) nosymm scf=(NDamp=30,NoDIIS,direct,tight,xqc)
#P opt=(calcfc,maxcycle=100,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) nosymm scf=(NDamp=30,NoDIIS,direct,tight,xqc)
ethanol
Expand All @@ -841,7 +920,7 @@ def test_trsh_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P opt=(calcfc,cartesian,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) nosymm scf=(NDamp=30,NoDIIS,direct,tight,xqc)
#P opt=(calcfc,cartesian,maxcycle=100,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) nosymm scf=(NDamp=30,NoDIIS,direct,tight,xqc)
ethanol
Expand All @@ -868,7 +947,7 @@ def test_trsh_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P opt=(cartesian) integral=(grid=ultrafine, Acc2E=14) guess=INDO wb97xd IOp(2/9=2000) nosymm scf=(NDamp=30,NoDIIS,direct,tight,xqc)
#P opt=(cartesian) integral=(grid=ultrafine, Acc2E=14) guess=INDO wb97xd IOp(2/9=2000) nosymm scf=(Fermi,NDamp=30,NoDIIS,NoVarAcc,Noincfock,direct,tight,xqc)
ethanol
Expand Down Expand Up @@ -921,7 +1000,7 @@ def test_trsh_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P opt=(calcfc,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) int=grid=300590 scf=(direct,tight)
#P opt=(calcfc,maxcycle=100,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) int=grid=300590 scf=(direct,tight)
ethanol
Expand All @@ -947,7 +1026,7 @@ def test_trsh_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P opt=(calcfc,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) nosymm scf=(NDamp=30,NoDIIS,direct,tight,xqc)
#P opt=(calcfc,maxcycle=100,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) nosymm scf=(Fermi,NDamp=30,NoDIIS,NoVarAcc,Noincfock,direct,tight,xqc)
ethanol
Expand All @@ -973,7 +1052,7 @@ def test_trsh_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P opt=(calcfc,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=(NDamp=30,NoDIIS,NoVarAcc,direct,tight,xqc)
#P opt=(calcfc,maxcycle=100,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=(NDamp=30,NoDIIS,NoVarAcc,direct,tight,xqc)
ethanol
Expand All @@ -1000,7 +1079,7 @@ def test_trsh_write_input_file(self):
%mem=14336mb
%NProcShared=8
#P opt=(calcfc,maxstep=5,tight) guess=INDO wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) int=grid=300590 scf=(NDamp=30,NoDIIS,NoVarAcc,direct,tight,xqc)
#P opt=(calcfc,maxcycle=100,maxstep=5,tight) guess=INDO wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) int=grid=300590 scf=(NDamp=30,NoDIIS,NoVarAcc,direct,tight,xqc)
ethanol
Expand All @@ -1020,6 +1099,87 @@ def test_trsh_write_input_file(self):

self.assertEqual(content_21, job_21_expected_input_file)

self.job_22.write_input_file()
with open(os.path.join(self.job_22.local_path, input_filenames[self.job_22.job_adapter]), 'r') as f:
content_22 = f.read()
job_22_expected_input_file = """%chk=check.chk
%mem=14336mb
%NProcShared=8
#P opt=(calcfc,maxcycle=200,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=(direct,tight)
ethanol
0 1
C 1.16582100 -0.40435500 0.00000000
C 0.00000000 0.55180500 0.00000000
O -1.18946000 -0.21419400 0.00000000
H -1.94125800 0.37518500 0.00000000
H 2.10540200 0.14511600 0.00000000
H 1.13062400 -1.03878500 0.88303200
H 1.13062400 -1.03878500 -0.88303200
H 0.04768200 1.19305700 0.88359100
H 0.04768200 1.19305700 -0.88359100
"""

self.assertEqual(content_22, job_22_expected_input_file)

self.job_23.write_input_file()
with open(os.path.join(self.job_23.local_path, input_filenames[self.job_23.job_adapter]), 'r') as f:
content_23 = f.read()
job_23_expected_input_file = """%chk=check.chk
%mem=14336mb
%NProcShared=8
#P opt=(RFO,calcfc,maxcycle=200,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=(direct,tight)
ethanol
0 1
C 1.16582100 -0.40435500 0.00000000
C 0.00000000 0.55180500 0.00000000
O -1.18946000 -0.21419400 0.00000000
H -1.94125800 0.37518500 0.00000000
H 2.10540200 0.14511600 0.00000000
H 1.13062400 -1.03878500 0.88303200
H 1.13062400 -1.03878500 -0.88303200
H 0.04768200 1.19305700 0.88359100
H 0.04768200 1.19305700 -0.88359100
"""

self.assertEqual(content_23, job_23_expected_input_file)

self.job_24.write_input_file()
with open(os.path.join(self.job_24.local_path, input_filenames[self.job_24.job_adapter]), 'r') as f:
content_24 = f.read()
job_24_expected_input_file = """%chk=check.chk
%mem=14336mb
%NProcShared=8
#P opt=(GDIIS,calcfc,maxcycle=200,maxstep=5,tight) guess=mix wb97xd integral=(grid=ultrafine, Acc2E=14) IOp(2/9=2000) scf=(direct,tight)
ethanol
0 1
C 1.16582100 -0.40435500 0.00000000
C 0.00000000 0.55180500 0.00000000
O -1.18946000 -0.21419400 0.00000000
H -1.94125800 0.37518500 0.00000000
H 2.10540200 0.14511600 0.00000000
H 1.13062400 -1.03878500 0.88303200
H 1.13062400 -1.03878500 -0.88303200
H 0.04768200 1.19305700 0.88359100
H 0.04768200 1.19305700 -0.88359100
"""

self.assertEqual(content_24, job_24_expected_input_file)


@classmethod
def tearDownClass(cls):
Expand Down
Loading

0 comments on commit 5a82b3c

Please sign in to comment.