Skip to content

Commit

Permalink
Reduce clutter in restart dict (#751)
Browse files Browse the repository at this point in the history
Don't save default values of `ARC`, `ARCSpecies`, and `ARCReaction`
objects as dictionaries
Tests modified accordingly
  • Loading branch information
alongd authored Jul 2, 2024
2 parents 34ef50d + 728aeea commit 047f656
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 162 deletions.
58 changes: 35 additions & 23 deletions arc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,16 @@ def as_dict(self) -> dict:
if self.adaptive_levels is not None:
restart_dict['adaptive_levels'] = {atom_range: {job_type: level.as_dict() for job_type, level in levels_dict}
for atom_range, levels_dict in self.adaptive_levels.items()}
restart_dict['allow_nonisomorphic_2d'] = self.allow_nonisomorphic_2d
if self.allow_nonisomorphic_2d:
restart_dict['allow_nonisomorphic_2d'] = self.allow_nonisomorphic_2d
if self.arkane_level_of_theory is not None:
restart_dict['arkane_level_of_theory'] = self.arkane_level_of_theory.as_dict() \
if isinstance(self.arkane_level_of_theory, Level) else self.arkane_level_of_theory
if self.bac_type != 'p':
restart_dict['bac_type'] = self.bac_type
if self.bath_gas is not None:
restart_dict['bath_gas'] = self.bath_gas
if self.calc_freq_factor:
if not self.calc_freq_factor:
restart_dict['calc_freq_factor'] = self.calc_freq_factor
if not self.compare_to_rmg:
restart_dict['compare_to_rmg'] = self.compare_to_rmg
Expand All @@ -487,62 +488,73 @@ def as_dict(self) -> dict:
restart_dict['compute_rates'] = self.compute_rates
if not self.compute_thermo:
restart_dict['compute_thermo'] = self.compute_thermo
if not self.compute_transport:
if self.compute_transport:
restart_dict['compute_transport'] = self.compute_transport
if self.conformer_level is not None:
if self.conformer_level is not None and str(self.conformer_level).split()[0] != default_levels_of_theory['conformer']:
restart_dict['conformer_level'] = self.conformer_level.as_dict()
if self.dont_gen_confs:
restart_dict['dont_gen_confs'] = self.dont_gen_confs
if self.ts_adapters:
if self.ts_adapters is not None:
restart_dict['ts_adapters'] = self.ts_adapters
restart_dict['e_confs'] = self.e_confs
if self.e_confs != 5.0:
restart_dict['e_confs'] = self.e_confs
restart_dict['ess_settings'] = self.ess_settings
if self.freq_level is not None:
if self.freq_level is not None and str(self.freq_level).split()[0] != default_levels_of_theory['freq']:
restart_dict['freq_level'] = self.freq_level.as_dict() \
if not isinstance(self.freq_level, (dict, str)) else self.freq_level
if self.freq_scale_factor is not None:
restart_dict['freq_scale_factor'] = self.freq_scale_factor
if self.irc_level is not None:
if self.irc_level is not None and str(self.irc_level).split()[0] != default_levels_of_theory['irc']:
restart_dict['irc_level'] = self.irc_level.as_dict() \
if not isinstance(self.irc_level, (dict, str)) else self.irc_level
if self.keep_checks:
restart_dict['keep_checks'] = self.keep_checks
restart_dict['kinetics_adapter'] = self.kinetics_adapter
if self.kinetics_adapter != 'arkane':
restart_dict['kinetics_adapter'] = self.kinetics_adapter
restart_dict['job_memory'] = self.memory
restart_dict['job_types'] = self.job_types
if self.level_of_theory:
restart_dict['level_of_theory'] = self.level_of_theory
restart_dict['max_job_time'] = self.max_job_time
restart_dict['n_confs'] = self.n_confs
if self.opt_level is not None:
if self.n_confs != 10:
restart_dict['n_confs'] = self.n_confs
if self.opt_level is not None and str(self.opt_level).split()[0] != default_levels_of_theory['opt']:
restart_dict['opt_level'] = self.opt_level.as_dict() \
if not isinstance(self.opt_level, (dict, str)) else self.opt_level
if self.orbitals_level is not None:
if self.orbitals_level is not None and str(self.orbitals_level).split()[0] != default_levels_of_theory['orbitals']:
restart_dict['orbitals_level'] = self.orbitals_level.as_dict() \
if not isinstance(self.orbitals_level, (dict, str)) else self.orbitals_level
restart_dict['output'] = self.output
restart_dict['output_multi_spc'] = self.output_multi_spc if self.output_multi_spc else dict()
if self.output:
restart_dict['output'] = self.output
if self.output_multi_spc:
restart_dict['output_multi_spc'] = self.output_multi_spc if self.output_multi_spc else dict()
restart_dict['project'] = self.project
restart_dict['reactions'] = [rxn.as_dict() for rxn in self.reactions]
restart_dict['running_jobs'] = self.running_jobs
if self.scan_level is not None:
if len(self.reactions):
restart_dict['reactions'] = [rxn.as_dict() for rxn in self.reactions]
if self.running_jobs:
restart_dict['running_jobs'] = self.running_jobs
if self.scan_level is not None and str(self.scan_level).split()[0] != default_levels_of_theory['scan']:
restart_dict['scan_level'] = self.scan_level.as_dict() \
if not isinstance(self.scan_level, (dict, str)) else self.scan_level
if self.sp_level is not None:
if self.sp_level is not None and str(self.sp_level).split()[0] != default_levels_of_theory['sp']:
restart_dict['sp_level'] = self.sp_level.as_dict() \
if not isinstance(self.sp_level, (dict, str)) else self.sp_level
restart_dict['species'] = [spc.as_dict() for spc in self.species]
if self.specific_job_type:
restart_dict['specific_job_type'] = self.specific_job_type
restart_dict['T_min'] = self.T_min
restart_dict['T_max'] = self.T_max
restart_dict['T_count'] = self.T_count
restart_dict['thermo_adapter'] = self.thermo_adapter
if self.T_min is not None:
restart_dict['T_min'] = self.T_min
if self.T_max is not None:
restart_dict['T_max'] = self.T_max
if self.T_count != 50:
restart_dict['T_count'] = self.T_count
if self.thermo_adapter != 'arkane':
restart_dict['thermo_adapter'] = self.thermo_adapter
if not self.three_params:
restart_dict['three_params'] = self.three_params
if not self.trsh_ess_jobs:
restart_dict['trsh_ess_jobs'] = self.trsh_ess_jobs
if self.ts_guess_level is not None:
if self.ts_guess_level is not None and str(self.ts_guess_level).split()[0] != default_levels_of_theory['ts_guesses']:
restart_dict['ts_guess_level'] = self.ts_guess_level.as_dict() \
if not isinstance(self.ts_guess_level, (dict, str)) else self.ts_guess_level
if self.verbose != logging.INFO:
Expand Down
24 changes: 2 additions & 22 deletions arc/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,15 @@ def test_as_dict(self):
self.assertIn("'C-C': 1", long_thermo_description)
self.assertIn("'C-H': 6", long_thermo_description)
# mol.atoms are not tested since all id's (including connectivity) changes depending on how the test is run.
expected_dict = {'T_count': 50,
'T_max': None,
'T_min': None,
'allow_nonisomorphic_2d': False,
'arkane_level_of_theory': {'basis': 'cc-pvdz-f12',
expected_dict = {'arkane_level_of_theory': {'basis': 'cc-pvdz-f12',
'method': 'ccsd(t)-f12',
'method_type': 'wavefunction',
'software': 'molpro'},
'calc_freq_factor': True,
'compute_transport': False,
'conformer_level': {'basis': 'def2svp',
'compatible_ess': ['gaussian', 'terachem'],
'method': 'wb97xd',
'method_type': 'dft',
'software': 'gaussian'},
'e_confs': 5.0,
'ess_settings': {'cfour': ['local'],
'gaussian': ['local', 'server2'],
'gcn': ['local'],
Expand Down Expand Up @@ -129,29 +122,18 @@ def test_as_dict(self):
'orbitals': False,
'rotors': False,
'sp': True},
'kinetics_adapter': 'arkane',
'max_job_time': 120,
'n_confs': 10,
'opt_level': {'basis': '6-311+g(3df,2p)',
'method': 'b3lyp',
'method_type': 'dft',
'software': 'gaussian'},
'output': {},
'output_multi_spc': {},
'project': 'arc_test',
'reactions': [],
'running_jobs': {},
'sp_level': {'basis': 'cc-pvdz-f12',
'method': 'ccsd(t)-f12',
'method_type': 'wavefunction',
'software': 'molpro'},
'species': [{'arkane_file': None,
'bond_corrections': {'C-C': 1, 'C-H': 6},
'charge': 0,
'species': [{'bond_corrections': {'C-C': 1, 'C-H': 6},
'compute_thermo': False,
'consider_all_diastereomers': True,
'force_field': 'MMFF94s',
'is_ts': False,
'label': 'spc1',
'long_thermo_description': long_thermo_description,
'mol': {'atom_order': restart_dict['species'][0]['mol']['atom_order'],
Expand All @@ -160,7 +142,6 @@ def test_as_dict(self):
'props': {}},
'multiplicity': 1,
'number_of_rotors': 0}],
'thermo_adapter': 'arkane',
'three_params': False,
'ts_adapters': ['heuristics', 'AutoTST', 'GCN', 'xtb_gsm']}
# import pprint # left intentionally for debugging
Expand All @@ -174,7 +155,6 @@ def test_from_dict(self):
'freq_level': 'wb97x-d3/6-311+g(d,p)',
'freq_scale_factor': 0.96,
'opt_level': 'wb97x-d3/6-311+g(d,p)',
'output': {},
'project': 'testing_from_dict',
'reactions': [],
'scan_level': '',
Expand Down
9 changes: 6 additions & 3 deletions arc/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ def as_dict(self,
"""
reaction_dict = dict()
reaction_dict['label'] = self.label
reaction_dict['index'] = self.index
if self.index is not None:
reaction_dict['index'] = self.index
reaction_dict['multiplicity'] = self.multiplicity
reaction_dict['charge'] = self.charge
if self.charge != 0:
reaction_dict['charge'] = self.charge
reaction_dict['reactants'] = self.reactants
reaction_dict['products'] = self.products
reaction_dict['r_species'] = [spc.as_dict(reset_atom_ids=reset_atom_ids) for spc in self.r_species]
Expand All @@ -256,7 +258,8 @@ def as_dict(self,
if len(self.ts_xyz_guess):
reaction_dict['ts_xyz_guess'] = self.ts_xyz_guess
reaction_dict['label'] = self.label
reaction_dict['ts_label'] = self.ts_label
if self.ts_label is not None:
reaction_dict['ts_label'] = self.ts_label
return reaction_dict

def from_dict(self,
Expand Down
Loading

0 comments on commit 047f656

Please sign in to comment.