Skip to content

Commit

Permalink
Set default fmax for everythng to 0.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyue Ping Ong committed Aug 11, 2023
1 parent 7003477 commit 10da158
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 210 deletions.
382 changes: 198 additions & 184 deletions examples/Calculating MLIP properties.ipynb

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions matcalc/elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ def __init__(
calculator: Calculator,
norm_strains: float = 0.01,
shear_strains: float = 0.01,
relax_structure: bool = True,
fmax: float = 0.1,
relax_structure: bool = True,
):
"""
Args:
calculator: ASE Calculator to use.
fmax: maximum force in the relaxed structure (if relax_structure).
norm_strains: strain value to apply to each normal mode.
shear_strains: strain value to apply to each shear mode.
relax_structure: whether to relax the provided structure with the given calculator.
fmax: maximum force in the relaxed structure (if relax_structure).
"""
self.calculator = calculator
self.norm_strains = norm_strains
Expand Down
12 changes: 7 additions & 5 deletions matcalc/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@ class EOSCalc(PropCalc):
def __init__(
self,
calculator: Calculator,
relax_structure: bool = True,
fmax: float = 0.01,
steps: int = 500,
max_abs_strain: float = 0.1,
n_points: int = 11,
fmax: float = 0.1,
relax_structure: bool = True,
):
"""
Args:
calculator: ASE Calculator to use.
relax_structure: Whether to first relax the structure. Set to False if structures provided are pre-relaxed
with the same calculator.
fmax (float): Max force for relaxation (of structure as well as atoms).
steps (int): Max number of steps for relaxation.
max_abs_strain (float): The maximum absolute strain applied to the structure. Defaults to 0.1, i.e.,
10% strain.
n_points (int): Number of points in which to compute the EOS. Defaults to 11.
fmax (float): Max force for relaxation (of structure as well as atoms).
relax_structure: Whether to first relax the structure. Set to False if structures provided are pre-relaxed
with the same calculator.
"""
self.calculator = calculator
self.relax_structure = relax_structure
Expand Down
12 changes: 7 additions & 5 deletions matcalc/phonon.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,25 @@ def __init__(
calculator: Calculator,
atom_disp=0.015,
supercell_matrix=((2, 0, 0), (0, 2, 0), (0, 0, 2)),
fmax=0.01,
relax_structure=True,
t_step=10,
t_max=1000,
t_min=0,
fmax=0.1,
relax_structure=True,
):
"""
Args:
calculator: ASE Calculator to use.
fmax: Max forces. This criterion is more stringent than for simple relaxation.
atom_disp: Atomic displacement
supercell_matrix: Supercell matrix to use. Defaults to 2x2x2 supercell.
fmax: Max forces. This criterion is more stringent than for simple relaxation.
relax_structure: Whether to first relax the structure. Set to False if structures provided are pre-relaxed
with the same calculator.
t_step: Temperature step.
t_max: Max temperature.
t_min: Min temperature.
relax_structure: Whether to first relax the structure. Set to False if structures provided are pre-relaxed
with the same calculator.
"""
self.calculator = calculator
self.atom_disp = atom_disp
Expand Down
6 changes: 3 additions & 3 deletions matcalc/relaxation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ def __init__(
self,
calculator: Calculator,
optimizer: Optimizer | str = "FIRE",
fmax: float = 0.1,
steps: int = 500,
traj_file: str | None = None,
interval=1,
fmax: float = 0.1,
relax_cell=True,
):
"""
Args:
calculator: ASE Calculator to use.
optimizer (str or ase Optimizer): the optimization algorithm.
Defaults to "FIRE"
fmax (float): Total force tolerance for relaxation convergence. fmax is a sum of force and stress forces.
steps (int): Max number of steps for relaxation.
traj_file (str): The trajectory file for saving
interval (int): The step interval for saving the trajectories.
relax_cell (bool): Whether to relax the cell.
fmax (float): Total force tolerance for relaxation convergence. fmax is a sum of force and stress forces.
relax_cell (bool): Whether to relax the cell (or just atoms).
"""
self.calculator = calculator
self.optimizer: Optimizer = OPTIMIZERS[optimizer] if isinstance(optimizer, str) else optimizer
Expand Down
10 changes: 5 additions & 5 deletions tests/test_elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
def test_ElasticCalc(LiFePO4, M3GNetUPCalc):
"""Tests for ElasticCalc class"""
calculator = M3GNetUPCalc
ecalc = ElasticityCalc(calculator, norm_strains=0.02, shear_strains=0.04, fmax=0.01)
ecalc = ElasticityCalc(calculator, norm_strains=0.02, shear_strains=0.04, fmax=0.1)

# Test LiFePO4 with relaxation
results = ecalc.calc(LiFePO4)
assert results["elastic_tensor"].shape == (3, 3, 3, 3)
assert results["elastic_tensor"][0][1][1][0] == pytest.approx(0.6441543434291928, rel=0.0001)
assert results["bulk_modulus_vrh"] == pytest.approx(1.109278785217532, rel=0.0001)
assert results["shear_modulus_vrh"] == pytest.approx(0.5946891263210372, rel=0.0001)
assert results["youngs_modulus"] == pytest.approx(1513587180.4865916, rel=0.0001)
assert results["elastic_tensor"][0][1][1][0] == pytest.approx(0.646330702693376, rel=0.1)
assert results["bulk_modulus_vrh"] == pytest.approx(1.109278785217532, rel=0.1)
assert results["shear_modulus_vrh"] == pytest.approx(0.5946891263210372, rel=0.1)
assert results["youngs_modulus"] == pytest.approx(1513587180.4865916, rel=0.1)
4 changes: 2 additions & 2 deletions tests/test_eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def test_PhononCalc(Li2O, LiFePO4, M3GNetUPCalc):
"""Tests for PhononCalc class"""
calculator = M3GNetUPCalc
# Note that the fmax is probably too high. This is for testing purposes only.
pcalc = EOSCalc(calculator, fmax=0.01)
pcalc = EOSCalc(calculator, fmax=0.1)
results = pcalc.calc(Li2O)

assert results["bulk_modulus"] == pytest.approx(69.86879801931632, rel=0.1)

results = list(pcalc.calc_many([Li2O, LiFePO4]))
assert len(results) == 2
assert results[1]["bulk_modulus"] == pytest.approx(53.791519828150925, rel=0.1)
assert results[1]["bulk_modulus"] == pytest.approx(60.083102790525366, rel=0.1)
8 changes: 4 additions & 4 deletions tests/test_phonon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def test_PhononCalc(Li2O, LiFePO4, M3GNetUPCalc):

# Test values at 100 K
ind = results["temperatures"].tolist().index(300)
assert results["heat_capacity"][ind] == pytest.approx(59.918928933451305, abs=0.01)
assert results["entropy"][ind] == pytest.approx(51.9081928335805, abs=0.01)
assert results["free_energy"][ind] == pytest.approx(11.892105644441045, abs=0.01)
assert results["heat_capacity"][ind] == pytest.approx(59.91894069664282, rel=0.1)
assert results["entropy"][ind] == pytest.approx(51.9081928335805, rel=0.1)
assert results["free_energy"][ind] == pytest.approx(11.892105644441045, rel=0.1)

results = list(pcalc.calc_many([Li2O, LiFePO4]))
assert len(results) == 2
assert results[-1]["heat_capacity"][ind] == pytest.approx(550.6419940551511, abs=0.01)
assert results[-1]["heat_capacity"][ind] == pytest.approx(550.6419940551511, rel=0.1)

0 comments on commit 10da158

Please sign in to comment.