/doc/ase/thermochemistry/thermochemistry.py

https://gitlab.com/vote539/ase · Python · 31 lines · 21 code · 5 blank · 5 comment · 5 complexity · 5118901e796efbefd5642bd827c80582 MD5 · raw file

  1. # creates: nitrogen.txt
  2. import os
  3. import sys
  4. from StringIO import StringIO
  5. def output_to_string(pythonfile):
  6. """Returns the stdout of executing the code in pythonfile
  7. as a string."""
  8. buffer = StringIO()
  9. sys.stdout = buffer
  10. execfile(pythonfile)
  11. sys.stdout = sys.__stdout__
  12. return buffer.getvalue()
  13. # Only save the parts relevant to thermochemistry
  14. nitrogen = output_to_string('nitrogen.py')
  15. nitrogen = nitrogen[nitrogen.find('Enthalpy'):]
  16. with open('nitrogen.txt', 'w') as f:
  17. f.write(nitrogen)
  18. gold = output_to_string('gold.py')
  19. gold = gold[gold.find('Internal'):]
  20. with open('gold.txt', 'w') as f:
  21. f.write(gold)
  22. # Clean up.
  23. vibfiles = [file for file in os.listdir(os.getcwd()) if
  24. file.startswith('vib.') or file.startswith('phonon.')]
  25. for file in vibfiles:
  26. os.remove(file)