1"""! Module of parsers for PSCF output file formats. """
207 with open(filename)
as f:
222 if line.startswith(
'fHelmholtz'):
225 raise Exception(
'Not valid Thermo file. No fHelmholtz found.')
226 line = file.readline()
227 if line.startswith(
'pressure'):
228 self.
pressure = float(line.split()[-1])
230 raise Exception(
'Not valid Thermo file. No pressure found.')
234 hasPolymersBlock =
False
238 if line.startswith(
'fIdeal'):
239 while line.strip() !=
'':
242 self.
fIdeal = float(l[-1])
244 self.
fInter = float(l[-1])
246 self.
fExt = float(l[-1])
247 line = file.readline()
251 elif line.lower().startswith(
'polymers:'):
254 line = file.readline()
255 while line.strip() !=
'':
258 line = file.readline()
260 hasPolymersBlock =
True
263 elif line.lower().startswith(
'solvents:'):
265 line = file.readline()
266 line = file.readline()
267 while line.strip() !=
'':
270 line = file.readline()
274 elif line.startswith(
'cellParams:'):
276 line = file.readline()
277 while line.strip() !=
'':
280 line = file.readline()
284 elif line.startswith(
'f (homo)'):
288 while line.strip() !=
'':
289 self.
homogeneous[line[:11].strip()] = float(line[12:31])
290 line = file.readline()
293 if line.lower().startswith(
'species:'):
294 line = file.readline()
295 speciesParams = line.split()
296 line = file.readline()
297 while line.strip() !=
'':
301 prm = speciesParams[i]
306 line = file.readline()
310 elif line.lower().startswith(
'stress:'):
312 line = file.readline()
313 while line.strip() !=
'':
315 self.
stress.append(float(l[1]))
316 line = file.readline()
320 elif line.lower().startswith(
'environment-modified stress:'):
322 line = file.readline()
323 while line.strip() !=
'':
326 line = file.readline()
329 if not hasPolymersBlock:
330 raise Exception(
'Not valid Thermo file. No polymers block found.')
341 line = file.readline()
343 line = file.readline()
356 with open(filename,
'w')
as f:
365 v = f
'{self.fHelmholtz:.11e}'
368 v = f
'{self.pressure:.11e}'
375 v = f
'{self.fIdeal:.11e}'
379 v = f
'{self.fInter:.11e}'
381 if self.
fExt !=
None:
383 v = f
'{self.fExt:.11e}'
390 p = f
'{self.polymers[i].phi:.11e}'
391 m = f
'{self.polymers[i].mu:.11e}'
392 s += f
'{i:>5}{p:>20}{m:>20}\n'
399 p = f
'{self.solvents[i].phi:.11e}'
400 m = f
'{self.solvents[i].mu:.11e}'
401 s += f
'{i:>5}{p:>20}{m:>20}\n'
407 v = f
'{self.cellParams[i]:.11e}'
408 s += f
'{i:>5}{v:>20}\n'
414 s += f
'{key:<10} = {val:18.11e}'
415 if key ==
"V(tot)/v":
417 elif key.lower() == key:
418 s +=
" [per monomer volume]\n"
426 s +=
' i mu phi(homo) deltaV\n'
429 s += f
'{sp["mu"]:>20.11e}'
430 s += f
'{sp["phi(homo)"]:>20.11e}'
431 s += f
'{sp["deltaV"]:>20.11e}\n'
436 for i
in range(len(self.
stress)):
437 v = f
'{self.stress[i]:.11e}'
438 s += f
'{i:>5}{v:>20}\n'
442 s +=
'environment-modified stress:\n'
444 v = f
'{self.environmentStress[i]:.11e}'
445 s += f
'{i:>5}{v:>20}\n'
465 self.
phi = float(l[1])
466 self.
mu = float(l[2])
468 self.
phi = float(l[0])
469 self.
mu = float(l[1])
546 with open(filename)
as f:
547 firstline = f.readline()
548 fl = firstline.split()
549 if fl[0] !=
'System{':
550 raise Exception(
'Not valid State file')
576 with open(filename,
"w")
as f:
635 filename = prefix + str(num) +
'.stt'
636 while os.path.isfile(filename) ==
True:
640 filename = prefix + str(num) +
'.stt'
718 for i
in range(0, len(self.
sweep)):
723 for j
in range(0, n):
725 string =
'a.' + vars[j]
728 except RecursionError:
729 raise Exception(
'Wrong command or values do not exist')
772 for i
in range(0, len(self.
sweep)):
774 for j
in range(0, n):
776 string =
'a.' + vars[j]
779 except RecursionError:
780 raise Exception(
'Wrong command or values do not exist')
786 for i
in range(0, n):
787 index = vars[i].rfind(
'.')
788 name = vars[i][index+1:]
789 nameList.append(name)
793 for i
in range(0, len(summary)):
795 for j
in range(0, len(summary[0])):
796 valType[i].append(type(summary[i][j]))
798 for i
in range(0, len(summary)):
799 for j
in range(0, len(summary[0])):
800 length = len(str(summary[i][j]))
801 if (valType[i][j] == str)
and (length > nl[j]):
803 if (valType[i][j] == float)
and (13 > nl[j]):
805 if (valType[i][j] == int)
and (length > nl[j]):
810 for i
in range(0, len(nameList)):
811 stringFormat =
'{:>' + str(nl[i]) +
's}'
812 if i != len(nameList)-1:
813 summaryString += stringFormat.format(nameList[i]) +
' '
815 summaryString += stringFormat.format(nameList[i]) +
'\n '
817 for i
in range(0, len(summary)):
818 for j
in range(0, len(summary[0])):
819 if valType[i][j] == int:
820 stringFormat =
'{:>' + str(nl[j]) +
'}'
821 summaryString += stringFormat.format(summary[i][j])
822 if valType[i][j] == float:
823 stringFormat =
'{:.7e}'
824 val = stringFormat.format(summary[i][j])
826 if valType[i][j] == str:
827 stringFormat =
'{:>' + str(nl[j]) +
's}'
828 summaryString += stringFormat.format(summary[i][j])
829 if j == len(summary[0])-1:
830 summaryString +=
'\n '
842 return self.
sweep[key]
848 return len(self.
sweep)
Container for phi and mu for a single species in a Thermo object.
__init__(self, l)
Constructor.
Container for data in state files produced by a sweep.
__str__(self)
Return string representation of this object in state file format.
write(self, filename)
Write the contents of this object to file in state file format.
__init__(self, filename)
Constructor.
Container for data in state files produced by a PSCF sweep.
__init__(self, prefix)
Constructor.
__getitem__(self, key)
Get a specific State object, specified by integer index.
summaryString(self, vars)
Return a summary report as a formatted string suitable for printing.
__len__(self)
Get the number of states in a sweep.
summary(self, vars, index=False)
Make a summary report containing values for selected variables.
Parser and container for PSCF thermo file blocks.
__init__(self, filename=None)
Constructor.
write(self, filename)
Write the contents of this object in thermo file format to a file.
__str__(self)
Return a string representation of this object in thermo file format.
read(self, file)
Read the passed-in open-file.
skipEmptyLine(self, file)
Skip empty lines in the file.
Container for data of a Composite in a param file.
Module for parsing param files.