Skip to content

Commit

Permalink
Avoid inspect.getfullargspec to maintain compatibility with py2.7 (m…
Browse files Browse the repository at this point in the history
…aterialsproject#986)

* Use set_prop_cycle

* Import pymatgen.util.serialization

* Fix DeprecationWarning

* Add Hdr.to_string

* Minor changes

* Add is_ngqpt option to PhononWork class methods

* Better error message if disordered structure is passed to to_abivars

* Workaround for pandas issue 18021

* Fix typo

* Init build.version

* Minor changes

* Add Flow.get_task_cycles method

* Use universal_newlines in Popen if py3k

* Enforce in NscfTask same FFT mesh as in GSTask

* Add repr for DFPT tasks

* Begin removing deprecated functions

* update pseudos

* Use universal_newlines if py3k

* Add tests

* Add tests

* Add mpi_runner_options

* Count number of jobs in the queue without contacting the resource manager

* Add CyclesPlotter and new methods for RelaxationCycle, EOSFit.plot_ax + tests

* add methods and classes to __all__

* Just to trigger travis build

* This to check if travis gets stuck due to matplotlib

* Indent RST table in add_fix_kwargs decorator

* Remove logger.debug call

* Minor fix in NscfTask

* add class to __all__

* one more class in __all__

* remove introspection in dict methods

* Remove unused import
  • Loading branch information
gmatteo authored and shyuep committed Jan 6, 2018
1 parent 0d82915 commit bee0aed
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
38 changes: 28 additions & 10 deletions pymatgen/io/abinit/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import six
import abc
import logging
import inspect
import numpy as np

from monty.string import indent, is_string, list_strings
Expand All @@ -36,7 +35,9 @@
"ScfConvergenceWarning",
"NscfConvergenceWarning",
"RelaxConvergenceWarning",
"Correction"
"Correction",
"DilatmxError",
"DilatmxErrorHandler"
]


Expand Down Expand Up @@ -566,19 +567,20 @@ def handle_task_event(self, task, event):

@pmg_serialize
def as_dict(self):
#@Guido this introspection is nice but it's not safe
"""
Basic implementation of as_dict if __init__ has no arguments. Subclasses may need to overwrite.
"""

d = {}
if hasattr(self, "__init__"):
for c in inspect.getfullargspec(self.__init__).args:
if c != "self":
d[c] = self.__getattribute__(c)
return d

@classmethod
def from_dict(cls, d):
kwargs = {k: v for k, v in d.items()
if k in inspect.getfullargspec(cls.__init__).args}
return cls(**kwargs)
"""
Basic implementation of from_dict if __init__ has no arguments. Subclasses may need to overwrite.
"""

return cls()

@classmethod
def compare_inputs(cls, new_input, old_input):
Expand Down Expand Up @@ -721,6 +723,14 @@ class DilatmxErrorHandler(ErrorHandler):
def __init__(self, max_dilatmx=1.3):
self.max_dilatmx = max_dilatmx

@pmg_serialize
def as_dict(self):
return {'max_dilatmx': self.max_dilatmx}

@classmethod
def from_dict(cls, d):
return cls(max_dilatmx=d['max_dilatmx'])

def handle_task_event(self, task, event):
# Read the last structure dumped by ABINIT before aborting.
filepath = task.outdir.has_abiext("DILATMX_STRUCT.nc")
Expand Down Expand Up @@ -777,6 +787,14 @@ class TolSymErrorHandler(ErrorHandler):
def __init__(self, max_nfixes=3):
self.max_nfixes = max_nfixes

@pmg_serialize
def as_dict(self):
return {'max_nfixes': self.max_nfixes}

@classmethod
def from_dict(cls, d):
return cls(max_nfixes=d['max_nfixes'])

def handle_task_event(self, task, event):
# TODO: Add limit on the number of fixes one can do for the same error
# For example in this case, the scheduler will stop after 20 submissions
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/abinit/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,7 @@ def from_scf_input(cls, workdir, scf_input, ph_ngqpt, with_becs=True, manager=No
raise ValueError("ph_ngqpt %s should be a sub-mesh of scf_ngkpt %s" % (ph_ngqpt, scf_ngkpt))

# Get the q-points in the IBZ from Abinit
qpoints = scf_input.abiget_ibz(ngkpt=ph_ngqpt, shiftk=(0,0,0), kptopt=1).points
qpoints = scf_input.abiget_ibz(ngkpt=ph_ngqpt, shiftk=(0, 0, 0), kptopt=1).points

# Create a PhononWork for each q-point. Add DDK and E-field if q == Gamma and with_becs.
for qpt in qpoints:
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/abinit/qadapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ def optimize_params(self, qnodes=None):
This method is called in get_subs_dict. Return a dict with parameters to be added to qparams
Subclasses may provide a specialized version.
"""
logger.debug("optimize_params of baseclass --> no optimization available!!!")
#logger.debug("optimize_params of baseclass --> no optimization available!!!")
return {}

def get_subs_dict(self, qnodes=None):
Expand Down
10 changes: 7 additions & 3 deletions pymatgen/io/abinit/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3227,10 +3227,14 @@ def setup(self):
(in principle, it's possible to interpolate inside Abinit but tests revealed some numerical noise
Here we change the input file of the NSCF task to have the same FFT mesh.
"""
assert len(self.deps) == 1
dep = self.deps[0]
parent_task = dep.node
# TODO: This won't work if parent_node is a file
for dep in self.deps:
if "DEN" in dep.exts:
parent_task = dep.node
break
else:
raise RuntimeError("Cannot find parent node producing DEN file")

with parent_task.open_gsr() as gsr:
den_mesh = 3 * [None]
den_mesh[0] = gsr.reader.read_dimvalue("number_of_grid_points_vector1")
Expand Down
28 changes: 15 additions & 13 deletions pymatgen/util/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,19 +385,21 @@ def wrapper(*args, **kwargs):
return fig

# Add docstring to the decorated method.
s = "\n" + """\
keyword arguments controlling the display of the figure:
================ ====================================================
kwargs Meaning
================ ====================================================
title Title of the plot (Default: None).
show True to show the figure (default: True).
savefig 'abc.png' or 'abc.eps' to save the figure to a file.
size_kwargs Dictionary with options passed to fig.set_size_inches
example: size_kwargs=dict(w=3, h=4)
tight_layout True to call fig.tight_layout (default: False)
================ ===================================================="""
s = "\n\n" + """\
Keyword arguments controlling the display of the figure:
================ ====================================================
kwargs Meaning
================ ====================================================
title Title of the plot (Default: None).
show True to show the figure (default: True).
savefig "abc.png" or "abc.eps" to save the figure to a file.
size_kwargs Dictionary with options passed to fig.set_size_inches
e.g. size_kwargs=dict(w=3, h=4)
tight_layout True to call fig.tight_layout (default: False)
================ ====================================================
"""

if wrapper.__doc__ is not None:
# Add s at the end of the docstring.
Expand Down

0 comments on commit bee0aed

Please sign in to comment.