Skip to content

Commit

Permalink
Merge pull request #70 from SMTG-Bham/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
kavanase authored Mar 11, 2024
2 parents 286bf88 + 66e873a commit a6034d6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
tutorials/* linguist-documentation
docs/* linguist-documentation
10 changes: 5 additions & 5 deletions docs/ShakeNBreak_Example_Workflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@
]
},
{
"cell_type": "code",
"outputs": [],
"cell_type": "markdown",
"source": [
"# Install ShakeNBreak (if not already installed)\n",
"!pip install shakenbreak"
"```{tip}\n",
"You can run this notebook interactively through Google Colab or Binder using the launch buttons at the top of the docs tutorial page (click the Rocket ?? icon). If running on Colab, then you'll need to run `!pip install shakenbreak` in a cell to install the package, and `!git clone https://github.com/SMTG-Bham/shakenbreak` to download the example data (and update paths in the code cells accordingly).\n",
"```"
],
"metadata": {
"collapsed": false
},
"id": "b766bdc7fe8ff74e"
"id": "91fbd4d745464ba"
},
{
"cell_type": "code",
Expand Down
1 change: 1 addition & 0 deletions shakenbreak/distortions.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ def rattle(
(Default: 1)
active_atoms (:obj:`list`, optional):
List of which atomic indices should undergo Monte Carlo rattling.
If not set, rattles all atoms in the structure.
(Default: None)
nbr_cutoff (:obj:`float`):
The radial cutoff distance (in Angstroms) used to construct the
Expand Down
23 changes: 14 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ def test_snb_generate(self):
catch_exceptions=False,
)
print([str(warning.message) for warning in w]) # for debugging
assert not w
non_potcar_warnings = [warning for warning in w if "POTCAR" not in str(warning.message)]
assert not non_potcar_warnings # no warnings other than POTCAR warnings
self.assertEqual(result.exit_code, 0)
self.assertIn(
f"Auto site-matching identified {self.VASP_CDTE_DATA_DIR}/CdTe_V_Cd_POSCAR "
Expand Down Expand Up @@ -439,8 +440,9 @@ def test_snb_generate(self):
catch_exceptions=False,
)
print([str(warning.message) for warning in w]) # for debugging
assert len(w) == 1 # only overwriting structures warning
assert "has the same Unperturbed defect structure" in str(w[0].message)
non_potcar_warnings = [warning for warning in w if "POTCAR" not in str(warning.message)]
assert len(non_potcar_warnings) == 1 # only overwriting structures warning
assert "has the same Unperturbed defect structure" in str(non_potcar_warnings[0].message)
self.assertEqual(result.exit_code, 0)
self.assertIn(f"Defect: {defect_name}", result.output)
self.assertIn("Number of missing electrons in neutral state: 2", result.output)
Expand Down Expand Up @@ -489,8 +491,9 @@ def test_snb_generate(self):
catch_exceptions=False,
)
print([str(warning.message) for warning in w]) # for debugging
assert len(w) == 1 # only overwriting structures warning
assert "has the same Unperturbed defect structure" in str(w[0].message)
non_potcar_warnings = [warning for warning in w if "POTCAR" not in str(warning.message)]
assert len(non_potcar_warnings) == 1 # only overwriting structures warning
assert "has the same Unperturbed defect structure" in str(non_potcar_warnings[0].message)
self.assertEqual(result.exit_code, 0)
self.assertIn(f"Defect: {defect_name}", result.output)
self.assertIn("Number of missing electrons in neutral state: 2", result.output)
Expand Down Expand Up @@ -548,8 +551,9 @@ def test_snb_generate(self):
catch_exceptions=False,
)
print([str(warning.message) for warning in w]) # for debugging
assert len(w) == 1 # only overwriting structures warning
assert "has the same Unperturbed defect structure" in str(w[0].message)
non_potcar_warnings = [warning for warning in w if "POTCAR" not in str(warning.message)]
assert len(non_potcar_warnings) == 1 # only overwriting structures warning
assert "has the same Unperturbed defect structure" in str(non_potcar_warnings[0].message)
self.assertEqual(result.exit_code, 0)
self.assertIn(f"Defect: {defect_name}", result.output)
self.assertIn("Number of missing electrons in neutral state: 2", result.output)
Expand Down Expand Up @@ -603,8 +607,9 @@ def test_snb_generate(self):
catch_exceptions=False,
)
print([str(warning.message) for warning in w]) # for debugging
assert len(w) == 1 # only overwriting structures warning
assert "has the same Unperturbed defect structure" in str(w[0].message)
non_potcar_warnings = [warning for warning in w if "POTCAR" not in str(warning.message)]
assert len(non_potcar_warnings) == 1 # only overwriting structures warning
assert "has the same Unperturbed defect structure" in str(non_potcar_warnings[0].message)
self.assertEqual(result.exit_code, 0)
self.assertIn(f"Defect: {defect_name}", result.output)
self.assertIn("Number of missing electrons in neutral state: 2", result.output)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_energy_lowering_distortions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ase
import numpy as np
from monty.serialization import dumpfn, loadfn
from pymatgen.core.structure import Element, Structure
from pymatgen.core.structure import Structure
from pymatgen.io.ase import AseAtomsAdaptor

from shakenbreak import analysis, distortions, energy_lowering_distortions, io
Expand Down
5 changes: 3 additions & 2 deletions tests/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ def test_create_vasp_input(self):
for el_symbol in V_Cd_POSCAR.structure.symbol_set
}
else: # test POTCAR warning
print([str(warning.message) for warning in w])
assert (
len(w) == 2
) # general POTCAR warning and NELECT/NUPDOWN INCAR warning
Expand Down Expand Up @@ -3300,9 +3301,9 @@ def test_apply_distortions(self):
self.assertTrue("Bond_Distortion_-75.0%" in V_Cd_distortions_dict)

# test short interatomic distance distortions not omitted when Hydrogen knocking about
fake_hydrogen_V_Cd_dict = copy.copy(self.V_Cd_dict)
fake_hydrogen_V_Cd_dict = copy.deepcopy(self.V_Cd_dict) # deepcopy to avoid overwriting
fake_hydrogen_V_Cd_dict["charges"] = [0]
fake_hydrogen_bulk = copy.copy(self.cdte_doped_defect_dict["bulk"])
fake_hydrogen_bulk = copy.deepcopy(self.cdte_doped_defect_dict["bulk"])
fake_hydrogen_bulk["supercell"]["structure"][4].species = "H"
fake_hydrogen_bulk["supercell"]["structure"].add_oxidation_state_by_element(
{"Cd": +2, "Te": -2, "H": +1}
Expand Down
7 changes: 5 additions & 2 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import warnings
from collections import OrderedDict
from copy import deepcopy
from unittest.mock import patch
from unittest.mock import Mock, patch

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pytest
from monty.serialization import dumpfn, loadfn
from monty.serialization import loadfn

from shakenbreak import analysis, plotting
from test_energy_lowering_distortions import assert_not_called_with

Mock.assert_not_called_with = assert_not_called_with


def if_present_rm(path):
Expand Down
7 changes: 5 additions & 2 deletions tests/test_shakenbreak.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import shutil
import unittest
import warnings
from unittest.mock import call, patch
from unittest.mock import Mock, patch

import pytest
from monty.serialization import dumpfn, loadfn
from pymatgen.core.structure import Structure
from pymatgen.io.vasp.inputs import UnknownPotcarWarning

from shakenbreak import cli, energy_lowering_distortions, input, io, plotting
from shakenbreak import energy_lowering_distortions, input, io, plotting
from test_energy_lowering_distortions import assert_not_called_with

Mock.assert_not_called_with = assert_not_called_with

file_path = os.path.dirname(__file__)

Expand Down

0 comments on commit a6034d6

Please sign in to comment.