Minima Script Create Sweeping Inputs

from lxml import etree as ET
import os
fileobj=open("input.xml","r")
doc = ET.parse(fileobj) # Create repr del contenido

#Get instance of root element:
root = doc.getroot()

#Get list of elements named "atom":
atoms = doc.xpath('//atom')

#Loop over all "atom" elements and set a new "coord" attribute:

groundstate = doc.xpath('//groundstate')

print groundstate

for ngk in range(3, 21):
for rgkm in [6.00, 6.25, 6.50, 6.75, 7.00, 7.25, 7.50, 7.75, 8.00, 8.25, 8.50, 8.75, 9.00]:

if not os.path.exists("ngridk_"+str(ngk)+"-rgkmax_"+str(rgkm)): # If directories dir1, dir2, etc do not exist
os.makedirs("ngridk_"+str(ngk)+"-rgkmax_"+str(rgkm)) # Create directories dir1, dir2, etc
# Beware of this: in Python there are no braces {}. The elements in a given block (for example,
# the block 'if' above) are defined because they share the same indentation.

groundstate[0].set('ngridk',str(ngk)+" "+str(ngk)+" "+str(ngk))
# Give different values to the variable ngridk

groundstate[0].set('rgkmax',str(rgkm))

fileobj2=open("ngridk_"+str(ngk)+"-rgkmax_"+str(rgkm)+"/input.xml","w") #Write changes to input.xml

fileobj2.write(ET.tostring(root,
pretty_print=True,
xml_declaration=True,
encoding='UTF-8'))

fileobj2.close()

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License