mirror of https://github.com/abinit/abipy.git
AbinitOutput.__str__ now prints dataframe with dims
This commit is contained in:
parent
bb5db1fa2d
commit
39efefa89d
|
@ -220,6 +220,10 @@ def abiopen(filepath):
|
|||
if outnum.match(filepath) or abonum.match(filepath):
|
||||
return AbinitOutputFile.from_file(filepath)
|
||||
|
||||
if os.path.basename(filepath) == "log":
|
||||
# Assume Abinit log file.
|
||||
return AbinitLogFile.from_file(filepath)
|
||||
|
||||
cls = abifile_subclass_from_filename(filepath)
|
||||
return cls.from_file(filepath)
|
||||
|
||||
|
|
|
@ -5,9 +5,11 @@ from __future__ import print_function, division, unicode_literals, absolute_impo
|
|||
|
||||
import os
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from collections import OrderedDict
|
||||
from monty.string import is_string
|
||||
from six.moves import cStringIO
|
||||
from monty.string import is_string, marquee
|
||||
from monty.functools import lazy_property
|
||||
from monty.termcolor import cprint
|
||||
from pymatgen.core.units import bohr_to_ang
|
||||
|
@ -477,6 +479,26 @@ class AbinitOutputFile(AbinitTextFile, NotebookWriter):
|
|||
app("Atomic coordinates:")
|
||||
app(str(df.coords))
|
||||
|
||||
# Print dataframe with dimensions.
|
||||
dims_dataset, spginfo_dataset = self.get_dims_spginfo_dataset(verbose=verbose)
|
||||
rows = []
|
||||
for dtind, dims in dims_dataset.items():
|
||||
d = OrderedDict()
|
||||
d["dataset"] = dtind
|
||||
d.update(dims)
|
||||
d.update(spginfo_dataset[dtind])
|
||||
rows.append(d)
|
||||
|
||||
from abipy.tools.printing import print_dataframe
|
||||
df = pd.DataFrame(rows, columns=list(rows[0].keys()) if rows else None)
|
||||
df = df.set_index('dataset')
|
||||
strio = cStringIO()
|
||||
print_dataframe(df, file=strio)
|
||||
strio.seek(0)
|
||||
app("")
|
||||
app(marquee("Dimensions of calculation", mark="="))
|
||||
app("".join(strio))
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
def get_dims_spginfo_dataset(self, verbose=0):
|
||||
|
@ -550,7 +572,7 @@ class AbinitOutputFile(AbinitTextFile, NotebookWriter):
|
|||
with open(self.filepath, "rt") as fh:
|
||||
for line in fh:
|
||||
line = line.strip()
|
||||
if verbose: print("inblock:", inblock, " at line:", line)
|
||||
if verbose > 1: print("inblock:", inblock, " at line:", line)
|
||||
|
||||
if line.startswith(magic_exit):
|
||||
break
|
||||
|
@ -592,7 +614,7 @@ class AbinitOutputFile(AbinitTextFile, NotebookWriter):
|
|||
else:
|
||||
if line and line[0] == "-": line = line[1:]
|
||||
tokens = grouper(2, line.replace("=", "").split())
|
||||
if verbose: print("tokens:", tokens)
|
||||
if verbose > 1: print("tokens:", tokens)
|
||||
dims.update([(t[0], int(t[1])) for t in tokens])
|
||||
|
||||
return dims_dataset, spginfo_dataset
|
||||
|
@ -859,7 +881,6 @@ class AboRobot(Robot):
|
|||
rows.append(dims)
|
||||
my_index.append(abo.relpath if index is None else index[i])
|
||||
|
||||
import pandas as pd
|
||||
return pd.DataFrame(rows, index=my_index, columns=list(rows[0].keys()))
|
||||
|
||||
def get_dataframe(self, with_geo=True, with_dims=True, abspath=False, funcs=None):
|
||||
|
@ -893,7 +914,6 @@ class AboRobot(Robot):
|
|||
if funcs is not None: d.update(self._exec_funcs(funcs, abo))
|
||||
rows.append(d)
|
||||
|
||||
import pandas as pd
|
||||
row_names = row_names if not abspath else self._to_relpaths(row_names)
|
||||
return pd.DataFrame(rows, index=row_names, columns=list(rows[0].keys()))
|
||||
|
||||
|
@ -909,7 +929,6 @@ class AboRobot(Robot):
|
|||
("overall_cputime", "proc0_cputime", "overall_walltime", "proc0_walltime")])
|
||||
rows.append(d)
|
||||
|
||||
import pandas as pd
|
||||
return pd.DataFrame(rows, index=row_names, columns=list(rows[0].keys()))
|
||||
|
||||
# TODO
|
||||
|
|
Loading…
Reference in New Issue