Using the logger to control output and logging information#
In this example, we’ll use scm.reactmap.logger to adjust the level of information that is printed to stdout and logged to the text file RM_Log.txt. These options can be adjusted using a set of three logger attributes:
logger.write_log = True/False– Whether to write the log file (default False)logger.print_level = 'info'/'status'/'warning'/'error'/'critical'/'none'– Which level of information to write to stdout (in decreasing order by amount of information)logger.log_level = 'info'/'status'/'warning'/'error'/'critical'/'none'– Which level of information to write to the log file (in decreasing order by amount of information)
import scm.reactmap as rm
# turn off logging
rm.logger.write_log = False
reactant = rm.Molecule(atoms=['H','O','O','H'], bonds=[(0,1),(1,2),(2,3)])
product = rm.Molecule(atoms=['H','O','O','H'], bonds=[(0,1),(2,3)])
reaction1 = rm.Reaction(reactant = reactant, product = product, name = "homolytic cleavage")
# print nothing
print("print_level = 'none'")
rm.logger.print_level = 'none'
rm.Map(reaction1)
# print status
print("print_level = 'status'")
rm.logger.print_level = 'status'
rm.Map(reaction1)
# print everything
print("print_level = 'info'")
rm.logger.print_level = 'info'
rm.Map(reaction1)
# now we make an error -- we provide a reaction that cannot be mapped
# this is due to an imbalance of atoms between reactant and product
print("making error, print_level = 'none'")
rm.logger.print_level = 'none'
reactant = rm.Molecule(atoms=['H','O','O','H','F'], bonds=[(0,1),(1,2),(2,3)])
product = rm.Molecule(atoms=['H','O','O','H'], bonds=[(0,1),(2,3)])
reaction2 = rm.Reaction(reactant = reactant, product = product, name = "homolytic cleavage error")
rm.Map(reaction2)
print("making error, print_level = 'error'")
rm.logger.print_level = 'error'
rm.Map(reaction2)
# now let's write a log
print("now, writing the log")
rm.logger.write_log = True
rm.logger.log_level = 'info'
rm.Map(reaction1)
The output below shows the printed messages for each print level.
print_level = 'none'
print_level = 'status'
Starting calculation on homolytic cleavage.
Details of homolytic cleavage:
Number of atoms: 4,
Types of atoms: O H,
Number of reactant bonds: 3,
Number of product bonds: 2,
Timer has been reset.
STATUS : 0.000s : Trying Heuristics.
STATUS : 0.000s : Heuristics successfully solved the model and found a value of 1.
Mapping finished of homolytic cleavage.
Found a minimal map cost of 1 in 0.000 seconds
print_level = 'info'
INFO : 0.001s : No settings supplied. Continuing with standard settings
Starting calculation on homolytic cleavage.
Details of homolytic cleavage:
Number of atoms: 4,
Types of atoms: O H,
Number of reactant bonds: 3,
Number of product bonds: 2,
Timer has been reset.
INFO : 0.000s : Checking settings for problem.
INFO : 0.000s : Preprocessing problem.
STATUS : 0.000s : Trying Heuristics.
STATUS : 0.000s : Heuristics successfully solved the model and found a value of 1.
INFO : 0.000s : Postprocessing problem.
Mapping finished of homolytic cleavage.
Found a minimal map cost of 1 in 0.000 seconds
making error, print_level = 'none'
making error, print_level = 'error'
ERROR : 0.001s : problem homolytic cleavage error is not valid for reaction mapping. Skipping problem
now, writing the log
Additionally, the following log file RM_Log.txt is produced:
INFO : 0.001s : No settings supplied. Continuing with standard settings
Starting calculation on homolytic cleavage.
Details of homolytic cleavage:
Number of atoms: 4,
Types of atoms: O H,
Number of reactant bonds: 3,
Number of product bonds: 2,
Timer has been reset.
INFO : 0.000s : Checking settings for problem.
INFO : 0.000s : Preprocessing problem.
STATUS : 0.000s : Trying Heuristics.
STATUS : 0.000s : Heuristics successfully solved the model and found a value of 1.
INFO : 0.000s : Postprocessing problem.
Mapping finished of homolytic cleavage.
Found a minimal map cost of 1 in 0.000 seconds