Skip to content

Commit

Permalink
Skip problematic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Sep 7, 2023
1 parent 1d5687f commit b555151
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 125 deletions.
1 change: 1 addition & 0 deletions abipy/abio/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding: utf-8
"""Test for output files"""
import os
import pytest
import abipy.data as abidata

from abipy import abilab
Expand Down
11 changes: 2 additions & 9 deletions abipy/core/tests/test_restapi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for core.restapi module"""
import contextlib
import pytest
import abipy.data as abidata

from abipy import abilab
Expand All @@ -10,18 +11,10 @@
class TestMpRestApi(AbipyTest):
"""Test interfaces with the Materials Project REST API."""

@pytest.mark.skip(reason="Interface with MP rester is broken")
def test_mprester(self):
"""Testing MP Rest API wrappers."""

#with restapi.get_mprester() as rest:
# #pdr = rest.get_phasediagram_results("Li-Fe-O".split("-"))
# pdr = rest.get_phasediagram_results("Ga-Ge-As".split("-")) # This one is faster.
# repr(pdr); str(pdr)
# pdr.print_dataframes(verbose=2)
# if self.has_matplotlib():
# plotter = pdr.plot(show_unstable=True, show=False)
# assert hasattr(plotter, "show")

# Test mp_search
mp = abilab.mp_search("MgB2")
repr(mp); str(mp)
Expand Down
116 changes: 6 additions & 110 deletions abipy/ml/aseml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ class MyAlignnCalculator(_MyMlCalculator, AlignnAtomwiseCalculator):
raise ValueError(f"Invalid {self.nn_type=}")


class _MlBase:
class MlBase:
"""
Base class for all Ml subclasses providing helper methods to
perform typical tasks such as writing files in the workdir
Expand Down Expand Up @@ -1411,7 +1411,7 @@ def _finalize(self) -> None:
print("\nResults available in directory:", self.workdir)


class MlRelaxer(_MlBase):
class MlRelaxer(MlBase):
"""
Relax structure with ASE and ML-potential.
"""
Expand Down Expand Up @@ -1625,7 +1625,7 @@ def run(self):
return relax


class MlMd(_MlBase):
class MlMd(MlBase):
"""Perform MD calculations with ASE and ML potential."""

def __init__(self, atoms: Atoms, temperature, timestep, steps, loginterval,
Expand Down Expand Up @@ -1728,7 +1728,7 @@ def run(self) -> None:
# label=f"xdatcar with relaxation generated by {self.__class__.__name__}")


class _MlNebBase(_MlBase):
class _MlNebBase(MlBase):
"""
Base class for Neb calculations
"""
Expand Down Expand Up @@ -2117,7 +2117,7 @@ def make_ase_neb(initial: Atoms, final: Atoms, nimages: int,
return neb


class MlOrderer(_MlBase):
class MlOrderer(MlBase):
"""
Order a disordered structure using pymatgen and ML potential.
"""
Expand Down Expand Up @@ -2582,7 +2582,7 @@ def traj_to_qepos(traj_filepath: str, pos_filepath: str) -> None:



class MlAsePhonons(_MlBase):
class MlAsePhonons(MlBase):
"""
Compute phonons with ASE and ML potential.
"""
Expand Down Expand Up @@ -2705,107 +2705,3 @@ def run(self) -> None:
self.savefig("phonons.png", fig, info=title)

self._finalize()


class MlPhononsWithDDB(_MlBase):
"""
Compute phonons with phonopy and a set of ML potentials starting from a DDB file.
"""

def __init__(self, ddb_filepath: str, supercell, qmesh, asr, nqpath,
relax_mode, fmax, pressure, steps, optimizer, nn_name,
verbose, workdir, prefix=None):
"""
Args:
ddb_filepath: DDB filename.
supercell: tuple with supercell dimension.
qmesh: q-mesh for phonon-DOS
asr: Enforce acoustic sum-rule.
nqpath: Number of q-point along the q-path.
relax_mode: "ions" to relax ions only, "cell" for ions + cell, "no" for no relaxation.
fmax: tolerance for relaxation convergence. Here fmax is a sum of force and stress forces.
verbose: whether to print stdout.
optimizer: name of the ASE optimizer to use for relaxation.
nn_name: String defining the NN potential. See also CalcBuilder.
verbose: Verbosity level.
workdir:
prefix:
"""
super().__init__(workdir, prefix)
from abipy.dfpt.ddb import DdbFile
self.ddb = DdbFile(ddb_file)
self.initial_atoms = get_atoms(ddb.structure)
self.supercell = supercell
self.qmesh = qmesh
self.asr = asr
self.nqpath = nqpath
self.relax_mode = relax_mode
RX_MODE.validate(self.relax_mode)
self.fmax = fmax
self.pressure = pressure
self.steps = steps
self.optimizer = optimizer
self.nn_name = nn_name
self.verbose = verbose

def to_string(self, verbose=0):
"""String representation with verbosity level `verbose`."""
s = f"""\
{self.__class__.__name__} parameters:
ddb_path = {self.ddb.filepath}
supercell = {self.supercell}
qmesh = {self.qmesh}
asr = {self.asr}
nqpath = {self.nqpath}
relax_mode = {self.relax_mode}
fmax = {self.fmax}
steps = {self.steps}
optimizer = {self.optimizer}
pressure = {self.pressure}
nn_names = {self.nn_names}
workdir = {self.workdir}
verbose = {self.verbose}
=== ATOMS ===
{self.initial_atoms}
"""
return s

def run(self) -> None:
"""Run MlPhononsWithDDB."""
workdir = self.workdir

atoms = self.initial_atoms.copy()
calculator = CalcBuilder(self.nn_name).get_calculator()
atoms.calc = calculator

if self.relax != RX_MODE.no:
print(f"Relaxing DDB atoms with relax mode: {self.relax_mode}.")
relax_kws = dict(optimizer=self.optimizer,
relax_mode=self.relax_mode,
fmax=self.fmax,
pressure=self.pressure,
steps=self.steps,
traj_path=self.get_path("relax.traj", "ASE relax trajectory"),
verbose=self.verbose,
)

relax = relax_atoms(atoms, **relax_kws)
r0, r1 = AseResults.from_traj_inds(relax.traj, 0, -1)
df = dataframe_from_results_list(["DDB_initial", "DDB_relaxed"], [r0, r1])
print(df, end=2*"\n")

# Call phonopy to compute phonons with finite difference and ML potential.
# Include non-analytical term if dipoles are available in the DDB file.
if self.dbb.has_lo_to_data:
print("Activating dipolar term in phonopy calculation using BECS and Zeff taken from DDB.")

# Call anaddb to compute ab-initio phonon frequencies from the DDB.
#self.ddb.anaget_phmodes_at_qpoints(
# qpoints=None, asr=2, chneut=1, dipdip=1, dipquad=1, quadquad=1,
# ifcflag=0, ngqpt=None, workdir=None, mpi_procs=1, manager=None, verbose=0,
# lo_to_splitting=False,
# spell_check=True, directions=None, anaddb_kwargs=None, return_input=False)
Loading

0 comments on commit b555151

Please sign in to comment.