Source code for schrodinger.application.matsci.qeschema.utils
"""
Convert from XML input to Fortran input.
"""
from schrodinger.application.matsci.qeschema import qeschema
import os
import xml.etree.ElementTree as Etree
NORUN_WARNING = """! === WARNING ===
! This file is not used by periodic_dft_driver.py or <jobname>.sh
! If you want to run this file, use runner.py
! ======
"""
[docs]def xml2in(input_fn, warning=False):
tree = Etree.parse(input_fn)
root = tree.getroot()
element_name = root.tag.split('}')[-1]
if element_name == 'espresso':
xml_document = qeschema.PwDocument()
elif element_name == 'nebRun':
xml_document = qeschema.NebDocument()
elif element_name == 'espressoph':
xml_document = qeschema.PhononDocument()
elif element_name == 'tddfpt':
xml_document = qeschema.TdDocument()
elif element_name == 'spectrumDoc':
xml_document = qeschema.TdSpectrumDocument()
else:
raise ValueError("Could not find correct XML in %s, exiting...\n" %
input_fn)
root = None
tree = None
xml_document.read(input_fn)
qe_in = xml_document.get_fortran_input()
input_fn_name, input_fn_ext = os.path.splitext(input_fn)
outfile = input_fn_name + '.in'
with open(outfile, mode='w') as f:
if warning:
f.write(NORUN_WARNING)
f.write(qe_in)
return outfile