1"""! Module for parsing field files. """
116 with open(filename)
as f:
130 line = openFile.readline()
138 raise Exception(
'Not valid field file.')
140 if self.
type !=
'fd1d':
142 while lineCount <= 15:
143 line = openFile.readline()
148 if name ==
'N_basis' or name ==
"N_star":
151 if name ==
'mesh' or name ==
'ngrid' or name ==
'cell_param':
153 for i
in range(0, len(l)):
159 line = openFile.readline()
162 line = openFile.readline()
167 for i
in range(0, len(l)):
170 line = openFile.readline()
174 if self.
type !=
'basis' and self.
type !=
'fd1d':
175 if type(self.
data[0][0])
is int:
188 for x, y
in self.
header.items():
189 if self.
type ==
'fd1d':
190 o = f
'{x:<7}' + str(y) +
'\n'
193 o = x +
' ' + str(y[0]) +
' ' + str(y[1]) +
'\n'
196 if x ==
'cell_param':
201 for i
in range(1, len(y)):
206 elif x ==
'mesh' or x ==
'ngrid':
210 for i
in range(1, len(y)):
215 o += f
'{str(y):>20s}' +
'\n'
219 for i
in range(0, len(self.
data)):
221 for j
in range(0, len(self.
data[0])):
222 if self.
type ==
'fd1d':
224 row += f
'{self.data[i][j]:>6}'
226 val = f
'{self.data[i][j]:.11e}'
229 if self.
type ==
'basis':
230 if j < self.
header[
'N_monomer']:
231 val = f
'{self.data[i][j]:.10e}'
234 if j == self.
header[
'N_monomer']:
236 row += f
'{self.data[i][j]:>5}'
238 if self.
type ==
'rgrid':
239 val = f
'{self.data[i][j]:.15e}'
242 if self.
type ==
'kgrid':
244 row += f
'{self.data[i][j]:>6}'
246 val = f
'{self.data[i][j]:.12e}'
266 with open(filename,
'w')
as f:
290 if isinstance(element, list):
291 if not (len(element) == len(self.
data)):
292 raise Exception(
'Incorrect dimension for parameter element')
293 for i
in range(0, len(self.
data)):
294 self.
data[i].insert(index, element[i])
296 for i
in range(0, len(self.
data)):
297 self.
data[i].insert(index, element)
309 for i
in range(0, len(self.
data)):
310 self.
data[i].pop(index)
352 for i
in range(0, len(self.
data)):
353 if not (nc == len(self.
data[i])):
354 raise Exception(
'Incorrect length for permutation order')
356 for j
in range(0,len(order)):
357 d.append(self.
data[i][order[j]])
375 if (v.isdigit() ==
True)
or (v[0] ==
'-' and v[1:].isdigit() ==
True):
Container for data in a PSCF field file.
addColumn(self, index, element)
Add a new column to the data list.
read(self, openFile)
Read and parse the passed-in file.
write(self, filename)
Write out field to a file.
deleteColumn(self, index)
Delete an existing column from the data list.
__str__(self)
Return string representation of this Field.
reorder(self, order)
Reorder the data list.
__init__(self, filename)
Constructor.
getValue(v)
Distinguish the correct type of the value from a string.