Skip to content

Commit

Permalink
MD stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Oct 18, 2023
1 parent 4a72dd5 commit c395dad
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 163 deletions.
5 changes: 5 additions & 0 deletions abipy/dynamics/cpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def df(self) -> pd.DataFrame:
df = pd.read_csv(self.filepath, delim_whitespace=True, skiprows=1, names=names)
return df

@lazy_property
def times(self):
"""Array with times in ps units."""
return evp.df["tps(ps)"].values

def to_string(self, verbose=0) -> str:
"""String representation with verbosity level verbose."""
lines = []; app = lines.append
Expand Down
350 changes: 197 additions & 153 deletions abipy/dynamics/msqd.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions abipy/electrons/ebands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,7 @@ def plot_ejdosvc(self, vrange, crange, method="gaussian", step=0.1, width=0.2, c
method: String defining the method.
step: Energy step (eV) of the linear mesh.
width: Standard deviation (eV) of the gaussian.
colormap: Have a look at the colormaps here and decide which one you like:
colormap: Color map. Have a look at the colormaps here and decide which one you like:
http://matplotlib.sourceforge.net/examples/pylab_examples/show_colormaps.html
cumulative: True for cumulative plots (default).
ax: |matplotlib-Axes| or None if a new figure should be created.
Expand Down Expand Up @@ -2449,7 +2449,7 @@ def plot_scatter3d(self, band, spin=0, e0="fermie", colormap="jet", ax=None, **k
- ``fermie``: shift all eigenvalues to have zero energy at the Fermi energy (``self.fermie``).
- Number e.g ``e0 = 0.5``: shift all eigenvalues to have zero energy at 0.5 eV
- None: Don't shift energies, equivalent to ``e0 = 0``.
colormap: Have a look at the colormaps here and decide which one you like:
colormap: Color map. Have a look at the colormaps here and decide which one you like:
<http://matplotlib.sourceforge.net/examples/pylab_examples/show_colormaps.html>
ax: matplotlib :class:`Axes3D` or None if a new figure should be created.
"""
Expand Down
16 changes: 11 additions & 5 deletions abipy/ml/aseml.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from ase.md.velocitydistribution import (MaxwellBoltzmannDistribution, Stationary, ZeroRotation)
from abipy.core import Structure
from abipy.tools.iotools import workdir_with_prefix, PythonScript, yaml_safe_load_path
from abipy.tools.typing import Figure
from abipy.tools.printing import print_dataframe
from abipy.tools.serialization import HasPickleIO
from abipy.abio.enums import StrEnum, EnumMixin
Expand Down Expand Up @@ -1172,6 +1173,7 @@ def install_nn_names(nn_names="all", update=False, verbose=0) -> None:
def pip_install(nn_name) -> int:
from subprocess import call
cmd = f"python -m pip install {nn_name}"
#print("About to execute", cmd)
try:
retcode = call(cmd, shell=True)
if retcode < 0:
Expand All @@ -1187,18 +1189,23 @@ def pip_install(nn_name) -> int:
"alignn",
]

nn_names = CalcBuilder.ALL_NN_TYPES if nn_names == "all" else list_strings(nn_names)
nn_names == list_strings(nn_names)
if "all" in nn_names: nn_names = CalcBuilder.ALL_NN_TYPES
installed, versions = get_installed_nn_names(verbose=verbose, printout=False)

for name in nn_names:
#print(f"About to install nn_name={name}")
if name in black_list:
print("Cannot install {name} with pip!")
continue
if name in installed:
if not update:
print("{name} is already installed!. Use update to update the package")
continue
print("Upgradig {name}")
print("Upgrading: {name}")
if name not in CalcBuilder.ALL_NN_TYPES:
print(f"Ignoring unknown {name=}")
continue

pip_install(name)

Expand Down Expand Up @@ -1763,7 +1770,6 @@ def restart_md(traj_filepath, atoms, verbose) -> tuple[bool, int]:


from abipy.core.mixins import TextFile, NotebookWriter
#class AseMdLog(TextFile, NotebookWriter):
class AseMdLog(TextFile):
"""
Postprocessing tool for the log file produced by ASE MD.
Expand All @@ -1782,6 +1788,7 @@ def df(self) -> pd.DataFrame:
# Here we implement the logic required to take into account a possible restart.
begin_restart = False
d = {}
add_time = 0.0
with open(self.filepath, mode="rt") as fh:
for i, line in enumerate(fh):
if i == 0:
Expand All @@ -1795,7 +1802,6 @@ def df(self) -> pd.DataFrame:
begin_restart = True
continue

add_time = 0.0
if begin_restart:
# First iteration after restart. Set add_time and kkip it.
begin_restart = False
Expand Down Expand Up @@ -1901,7 +1907,7 @@ def run(self) -> None:
loginterval=self.loginterval,
ensemble =self.ensemble,
nn_name =self.nn_name,
workdir =self.workdir,
workdir =str(self.workdir),
verbose =self.verbose,
)
self.write_json("md.json", md_dict, info="JSON file with ASE MD parameters")
Expand Down
2 changes: 1 addition & 1 deletion abipy/scripts/abiml.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def show(ctx, verbose):
@click.option('-v', '--verbose', count=True, help="Verbosity level")
def install(ctx, nn_names, update, verbose):
"""
Install NN potentials in the environment using pip
Install NN potentials in the environment using pip.
"""
aseml.install_nn_names(nn_names=nn_names, update=update, verbose=verbose)
installed, versions = aseml.get_installed_nn_names(verbose=verbose, printout=True)
Expand Down
2 changes: 1 addition & 1 deletion abipy/scripts/abips.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def abips_install(options) -> int:
return 0

print("The following pseudopotential repositories will be installed:")
print(tabulate_repos(repos, verbose=options.verbose))
print(tabulate_repos(repos, verbose=options.verbose), "\n")
#if not options.yes and cli.user_wants_to_abort(): return 2

for repo in repos:
Expand Down
31 changes: 30 additions & 1 deletion abipy/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,41 @@ def set_ax_xylabels(ax, xlabel: str, ylabel: str, exchange_xy: bool = False) ->
ax.set_ylabel(ylabel)


def set_logscale(ax_or_axlist, xy_log) -> None:
"""
Activate logscale
Args:
ax_or_axlist: Axes or list of axes.
xy_log:
None or empty string -> Use linear scale.
x -> Use log scale on x-axis
xy -> Use log scale on x- and y-axis
x:semilog -> Use semilog scale on x-axis.
"""
if not xy_log: return

# Parse xy_log string.
xy, log_type = xy_log, "log"
if ":" in xy_log:
xy, log_type = xy_log.split(":")

ax_list = [ax_or_axlist] if not duck.is_listlike(ax_or_axlist) else ax_or_axlist

for ix, ax in enumerate(ax_list):
if "x" in xy:
ax.set_xscale(log_type)
if "y" in xy:
ax.set_yscale(log_type)


def set_ticks_fontsize(ax_or_axlist, fontsize: int, xy_string="xy") -> None:
"""
Set tick properties for one axis or a list of axis.
Args:
xy_string: "x" to share x-axis, "xy" for both
ax_or_axlist: Axes or list of axes.
xy_string: "x" to share x-axis, "xy" for both.
"""
ax_list = [ax_or_axlist] if not duck.is_listlike(ax_or_axlist) else ax_or_axlist

Expand Down

0 comments on commit c395dad

Please sign in to comment.