diff --git a/t3/logger.py b/t3/logger.py index 97e8c294..7c75eda6 100644 --- a/t3/logger.py +++ b/t3/logger.py @@ -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 @@ -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']) @@ -201,10 +202,15 @@ 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. @@ -212,7 +218,11 @@ def log_reactions_to_calculate(self, 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']) @@ -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]): """ diff --git a/t3/main.py b/t3/main.py index ff2341df..c68e0f18 100755 --- a/t3/main.py +++ b/t3/main.py @@ -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'), @@ -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}) return additional_calcs_required def determine_species_based_on_sa(self) -> List[int]: