8 Class to read a WinNet template file.
13 Initialize the template class.
20 Read the data from the template file and store it in a dictionary.
26 with open(self.
path,
'r')
as f:
28 for line
in self.
data:
29 if line.strip().startswith(
'#'):
35 key = line.split(
"=")[0].strip()
36 value = line.split(
"=")[1].strip().replace(
'"',
'').replace(
"'",
"")
42 Get the entries of the template file.
46 if not hasattr(self,
'_template__entries'):
53 Get the value of a specific key.
55 if not hasattr(self,
'_template__entries'):
61 Set the value of a specific key.
63 if not hasattr(self,
'_template__entries'):
70 Save the template file.
72 with open(path,
'w')
as f:
73 for key, value
in self.
entries.items():
74 if winnet_path
is None:
75 f.write(f
"{key} = {value}\n")
77 entry = str(value).replace(
"@WINNET@",winnet_path)
78 f.write(f
"{key} = {entry}\n")
81 if __name__ ==
'__main__':
83 path =
'/home/mreichert/data/Networks/comparison_winNet/WinNet-dev/par/NSE_comp.par'
85 print(t[
"isotopes_file"])
86 t.save_template(
'test.par', winnet_path=
'../../runs/winnet')