Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report SA results per iteration #138

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions t3/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def log_footer(self):

def log_species_to_calculate(self,
species_keys: List[int],
species_dict: Dict[int, dict]):
species_dict: Dict[int, dict]) -> Dict:
"""
Report the species to be calculated in the next iteration.
The 'QM label' is used for reporting, it is principally the
Expand All @@ -178,9 +178,10 @@ def log_species_to_calculate(self,
species_keys (List[int]): Entries are T3 species indices.
species_dict (dict): The T3 species dictionary.

Todo:
Log the reasons one by one with line breaks and enumerate
Returns:
Dict: SA content for the YAML file.
"""
yml_content = dict()
if len(species_keys):
self.info('\n\nSpecies to calculate thermodynamic data for:')
max_label_length = max([len(spc_dict['QM label'])
Expand All @@ -201,18 +202,27 @@ def log_species_to_calculate(self,
for j, reason in enumerate(spc_dict['reasons']):
if j:
self.info(f"{' ' * (max_label_length + max_smiles_length + 4)}{j + 1}. {spc_dict['reasons'][j]}")
yml_content[key] = {'SMILES': smiles,
'QM label': spc_dict['QM label'],
'reasons': spc_dict['reasons'],
}
return yml_content

def log_reactions_to_calculate(self,
reaction_keys: List[int],
reaction_dict: Dict[int, dict]):
reaction_dict: Dict[int, dict]) -> Dict:
"""
Report reaction rate coefficients to be calculated in the next iteration.
The reaction 'QM label' is used for reporting.

Args:
reaction_keys (List[int]): Entries are T3 reaction indices.
reaction_dict (dict): The T3 reaction dictionary.

Returns:
Dict: SA content for the YAML file.
"""
yml_content = dict()
if len(reaction_keys):
self.info('\n\nReactions to calculate high-pressure limit rate coefficients for:')
max_label_length = max([len(rxn_dict['QM label'])
Expand All @@ -228,10 +238,16 @@ def log_reactions_to_calculate(self,
space1 = ' ' * (max_label_length - len(rxn_dict['QM label']) + 1)
self.info(f"\n{rxn_dict['QM label']}{space1} {rxn_dict['reasons']}")
self.info(f"{rxn_dict['SMILES label']}\n")
yml_content[key] = {'SMILES label': rxn_dict['SMILES label'],
'QM label': rxn_dict['QM label'],
'reasons': rxn_dict['reasons'],
}
if hasattr(rxn_dict['object'], 'family') and rxn_dict['object'].family is not None:
label = rxn_dict['object'].family if isinstance(rxn_dict['object'].family, str) \
else rxn_dict['object'].family.label
self.info(f'RMG family: {label}\n')
yml_content[key]['RMG family'] = label
return yml_content

def log_species_summary(self, species_dict: Dict[int, dict]):
"""
Expand Down
8 changes: 4 additions & 4 deletions t3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ def set_paths(self,
'chem annotated': os.path.join(iteration_path, 'RMG', 'chemkin', 'chem_annotated.inp'),
'species dict': os.path.join(iteration_path, 'RMG', 'chemkin', 'species_dictionary.txt'),
'SA': os.path.join(iteration_path, 'SA'),
'SA yaml': os.path.join(iteration_path, 'SA', 'SA.yml'),
'SA solver': os.path.join(iteration_path, 'SA', 'solver'),
'SA input': os.path.join(iteration_path, 'SA', 'input.py'),
'PDep SA': os.path.join(iteration_path, 'PDep_SA'),
Expand Down Expand Up @@ -729,10 +730,9 @@ def determine_species_and_reactions_to_calculate(self) -> bool:
or any(spc['converged'] is None for spc in self.species.values())

self.logger.info(f'Additional calculations required: {additional_calcs_required}\n')
if len(species_keys):
self.logger.log_species_to_calculate(species_keys, self.species)
if len(reaction_keys):
self.logger.log_reactions_to_calculate(reaction_keys, self.reactions)
spc_yml = self.logger.log_species_to_calculate(species_keys, self.species) if len(species_keys) else dict()
rxn_yml = self.logger.log_reactions_to_calculate(reaction_keys, self.reactions) if len(reaction_keys) else dict()
save_yaml_file(path=self.paths['SA yaml'], content={'Species': spc_yml, 'Reactions': rxn_yml})
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
return additional_calcs_required

def determine_species_based_on_sa(self) -> List[int]:
Expand Down
Loading