Skip to content

Commit

Permalink
Using lazy string formatting in debug statements.
Browse files Browse the repository at this point in the history
Doing it this way, the string formatting is not evaluated if you aren't 
actually going to log the debug statements (usually the case, as we normally
don't run in verbose mode). Should be marginally quicker.
  • Loading branch information
rwest committed Jun 5, 2021
1 parent 5374c6d commit 08c6343
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions rmgpy/molecule/resonance.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,23 @@ def _generate_resonance_structures(mol_list, method_list, keep_isomorphic=False,
for mol in mol_list[1:]:
if mol.get_net_charge() != input_charge:
mol_list.remove(mol)
logging.debug('Resonance generation created a molecule {0} with a net charge of {1}\n'
'which does not match the input mol charge of {2}'
'Removing {0} from resonance structures'.format(mol.smiles,mol.get_net_charge(),input_charge))
logging.debug('Resonance generation created a molecule %s with a net charge of %d '
'which does not match the input mol charge of %d.\n'
'Removing it from resonance structures',mol.smiles,mol.get_net_charge(),input_charge)
if mol.contains_surface_site():
for x in [atom for atom in mol.atoms if atom.is_surface_site()]:
if x.radical_electrons != 0:
mol_list.remove(mol)
logging.debug('Resonance generation created a molecule {0} with {1} radicals on {2}\n'
'Removing {0} from resonance structures'.format(mol.smiles,x.radical_electrons,x.symbol))
logging.debug('Resonance generation created a molecule %s with %d radicals on %s.\n'
'Removing it from resonance structures',mol.smiles,x.radical_electrons,x.symbol)
elif x.lone_pairs != 0:
mol_list.remove(mol)
logging.debug('Resonance generation created a molecule {0} with {1} lone pairs on {2}\n'
'Removing {0} from resonance structures'.format(mol.smiles,x.lone_pairs,x.symbol))
logging.debug('Resonance generation created a molecule %s with %d lone pairs on %s.\n'
'Removing it from resonance structures',mol.smiles,x.lone_pairs,x.symbol)
elif x.charge != 0:
mol_list.remove(mol)
logging.debug('Resonance generation created a molecule {0} with a charge of {1} on {2}\n'
'Removing {0} from resonance structures'.format(mol.smiles,x.charge,x.symbol))
logging.debug('Resonance generation created a molecule %s with a charge of %d on %s.\n'
'Removing it from resonance structures',mol.smiles,x.charge,x.symbol)

return mol_list

Expand Down

0 comments on commit 08c6343

Please sign in to comment.