Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingsbury committed Mar 10, 2023
2 parents c4ac3aa + 2689557 commit 6b83007
Show file tree
Hide file tree
Showing 89 changed files with 985 additions and 918 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ci:

repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.253
rev: v0.0.254
hooks:
- id: ruff
args: [--fix, --ignore, 'D,SIM']
Expand Down Expand Up @@ -38,7 +38,7 @@ repos:
additional_dependencies: [tomli] # needed to read pyproject.toml below py3.11

- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.12.4
rev: v0.12.5
hooks:
- id: cython-lint
args: [--no-pycodestyle]
Expand Down
7 changes: 3 additions & 4 deletions dev_scripts/regen_libxcfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ def parse_libxc_docs(path):

def parse_section(section):
d = {}
for l in section:
key, value = l.split(":")
key = key.strip()
d[key] = value.strip()
for line in section:
key, value = line.split(":")
d[key.strip()] = value.strip()

return int(d["Number"]), d

Expand Down
6 changes: 6 additions & 0 deletions docs_rst/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Optional libraries that are required if you need certain features.
5. networkx: For graph analysis associated with critic2 topological analysis
of electron charge densities, pygraphviz is also required for visualization.
6. pytest - For unittesting. Not optional for developers.
7. numba: Optionally can be installed for faster evaluation of certain
functionality, such as the SubstrateAnalyzer. It incurrs an initial
slowdown the first time the relevant function is called, as it is
compiled, for dramatically faster subsequent evaluations. Note that
numba places additional constraints on the versions of numpy and
Python that may be used.

Optional non-Python programs
----------------------------
Expand Down
9 changes: 2 additions & 7 deletions docs_rst/team.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Lead Maintainers
:alt: ORCID profile for 0000-0001-5726-2587

| **Matthew Horton** |mkhorton| |0000-0001-7777-8871|
| Materials Project Staff, Persson Group Member
| Lawrence Berkeley National Laboratory
| Senior Research Software Engineer
| Microsoft Research
.. |mkhorton| image:: https://cdnjs.cloudflare.com/ajax/libs/octicons/8.5.0/svg/mark-github.svg
:target: https://github.com/mkhorton
Expand All @@ -58,11 +58,6 @@ Lead Maintainers
:height: 16
:alt: ORCID profile for 0000-0001-7777-8871

Pull Request Review
-------------------

Additional support for reviewing pull requests from:

| **Janosh Riebesell** |janosh|
| University of Cambridge
.. |janosh| image:: https://cdnjs.cloudflare.com/ajax/libs/octicons/8.5.0/svg/mark-github.svg
Expand Down
12 changes: 6 additions & 6 deletions pymatgen/alchemy/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def undo_last_change(self) -> None:
raise IndexError("Can't undo. Latest history has no input_structure")
h = self.history.pop()
self._undone.append((h, self.final_structure))
s = h["input_structure"]
if isinstance(s, dict):
s = Structure.from_dict(s)
self.final_structure = s
struct = h["input_structure"]
if isinstance(struct, dict):
struct = Structure.from_dict(struct)
self.final_structure = struct

def redo_next_change(self) -> None:
"""
Expand Down Expand Up @@ -347,8 +347,8 @@ def from_dict(cls, d) -> TransformedStructure:
"""
Creates a TransformedStructure from a dict.
"""
s = Structure.from_dict(d)
return cls(s, history=d["history"], other_parameters=d.get("other_parameters", None))
struct = Structure.from_dict(d)
return cls(struct, history=d["history"], other_parameters=d.get("other_parameters", None))

def to_snl(self, authors, **kwargs) -> StructureNL:
"""
Expand Down
27 changes: 9 additions & 18 deletions pymatgen/alchemy/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,29 @@ class ContainsSpecieFilterTest(PymatgenTest):
def test_filtering(self):
coords = [[0, 0, 0], [0.75, 0.75, 0.75], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25]]
lattice = Lattice([[3.0, 0.0, 0.0], [1.0, 3.0, 0.00], [0.00, -2.0, 3.0]])
s = Structure(
lattice,
[
{"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
{"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
{"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
{"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25},
],
coords,
)
struct = Structure(lattice, [{"Si4+": 0.5, "O2-": 0.25, "P5+": 0.25}] * 4, coords)

species1 = [Species("Si", 5), Species("Mg", 2)]
f1 = ContainsSpecieFilter(species1, strict_compare=True, AND=False)
assert not f1.test(s), "Incorrect filter"
assert not f1.test(struct), "Incorrect filter"
f2 = ContainsSpecieFilter(species1, strict_compare=False, AND=False)
assert f2.test(s), "Incorrect filter"
assert f2.test(struct), "Incorrect filter"
species2 = [Species("Si", 4), Species("Mg", 2)]
f3 = ContainsSpecieFilter(species2, strict_compare=True, AND=False)
assert f3.test(s), "Incorrect filter"
assert f3.test(struct), "Incorrect filter"
f4 = ContainsSpecieFilter(species2, strict_compare=False, AND=False)
assert f4.test(s), "Incorrect filter"
assert f4.test(struct), "Incorrect filter"

species3 = [Species("Si", 5), Species("O", -2)]
f5 = ContainsSpecieFilter(species3, strict_compare=True, AND=True)
assert not f5.test(s), "Incorrect filter"
assert not f5.test(struct), "Incorrect filter"
f6 = ContainsSpecieFilter(species3, strict_compare=False, AND=True)
assert f6.test(s), "Incorrect filter"
assert f6.test(struct), "Incorrect filter"
species4 = [Species("Si", 4), Species("Mg", 2)]
f7 = ContainsSpecieFilter(species4, strict_compare=True, AND=True)
assert not f7.test(s), "Incorrect filter"
assert not f7.test(struct), "Incorrect filter"
f8 = ContainsSpecieFilter(species4, strict_compare=False, AND=True)
assert not f8.test(s), "Incorrect filter"
assert not f8.test(struct), "Incorrect filter"

def test_to_from_dict(self):
species1 = ["Si5+", "Mg2+"]
Expand Down
14 changes: 7 additions & 7 deletions pymatgen/analysis/bond_valence.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,14 @@ def get_oxi_state_decorated_structure(self, structure):
Raises:
ValueError if the valences cannot be determined.
"""
s = structure.copy()
if s.is_ordered:
valences = self.get_valences(s)
s.add_oxidation_state_by_site(valences)
struct = structure.copy()
if struct.is_ordered:
valences = self.get_valences(struct)
struct.add_oxidation_state_by_site(valences)
else:
valences = self.get_valences(s)
s = add_oxidation_state_by_site_fraction(s, valences)
return s
valences = self.get_valences(struct)
struct = add_oxidation_state_by_site_fraction(struct, valences)
return struct


def get_z_ordered_elmap(comp):
Expand Down
16 changes: 8 additions & 8 deletions pymatgen/analysis/chemenv/utils/math_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ def _cartesian_product(lists):
return reduce(_append_es2sequences, lists, [])


def prime_factors(n):
def prime_factors(n: int) -> list[int]:
"""Lists prime factors of a given natural integer, from greatest to smallest
:param n: Natural integer
:rtype : list of all prime factors of the given natural n
"""
i = 2
while i <= sqrt(n):
if n % i == 0:
l = prime_factors(n / i)
l.append(i)
return l
i += 1
idx = 2
while idx <= sqrt(n):
if n % idx == 0:
lst = prime_factors(n // idx)
lst.append(idx)
return lst
idx += 1
return [n] # n is prime


Expand Down
22 changes: 11 additions & 11 deletions pymatgen/analysis/diffraction/tests/test_xrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def test_type_wavelength(self):
XRDCalculator(wavelength)

def test_get_pattern(self):
s = self.get_structure("CsCl")
struct = self.get_structure("CsCl")
c = XRDCalculator()
xrd = c.get_pattern(s, two_theta_range=(0, 90))
xrd = c.get_pattern(struct, two_theta_range=(0, 90))
assert xrd.to_json() # Test MSONAble property
# Check the first two peaks
assert xrd.x[0] == pytest.approx(21.107738329639844)
Expand All @@ -46,20 +46,20 @@ def test_get_pattern(self):
assert xrd.hkls[1] == [{"hkl": (1, 1, 0), "multiplicity": 12}]
assert xrd.d_hkls[1] == pytest.approx(2.976212442014178)

s = self.get_structure("LiFePO4")
xrd = c.get_pattern(s, two_theta_range=(0, 90))
struct = self.get_structure("LiFePO4")
xrd = c.get_pattern(struct, two_theta_range=(0, 90))
assert xrd.x[1] == pytest.approx(17.03504233621785)
assert xrd.y[1] == pytest.approx(50.400928948337075)

s = self.get_structure("Li10GeP2S12")
xrd = c.get_pattern(s, two_theta_range=(0, 90))
struct = self.get_structure("Li10GeP2S12")
xrd = c.get_pattern(struct, two_theta_range=(0, 90))
assert xrd.x[1] == pytest.approx(14.058274883353876)
assert xrd.y[1] == pytest.approx(4.4111123641667671)

# Test a hexagonal structure.
s = self.get_structure("Graphite")
struct = self.get_structure("Graphite")

xrd = c.get_pattern(s, two_theta_range=(0, 90))
xrd = c.get_pattern(struct, two_theta_range=(0, 90))
assert xrd.x[0] == pytest.approx(26.21057350859598)
assert xrd.y[0] == pytest.approx(100)
assert len(xrd.hkls[0][0]["hkl"]) == pytest.approx(4)
Expand All @@ -75,13 +75,13 @@ def test_get_pattern(self):
[0.75, 0.75, 0.324],
]
sp = ["Si", "Si", "Ru", "Ru", "Pr", "Pr"]
s = Structure(Lattice.tetragonal(4.192, 6.88), sp, coords)
xrd = c.get_pattern(s)
struct = Structure(Lattice.tetragonal(4.192, 6.88), sp, coords)
xrd = c.get_pattern(struct)
assert xrd.x[0] == pytest.approx(12.86727341476735)
assert xrd.y[0] == pytest.approx(31.448239816769796)
assert xrd.d_hkls[0] == pytest.approx(6.88)
assert len(xrd) == 42
xrd = c.get_pattern(s, two_theta_range=[0, 60])
xrd = c.get_pattern(struct, two_theta_range=[0, 60])
assert len(xrd) == 18

# Test with and without Debye-Waller factor
Expand Down
10 changes: 5 additions & 5 deletions pymatgen/analysis/dimensionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,13 @@ def get_dimensionality_gorai(
bonds = get_max_bond_lengths(structure, el_radius_updates)

num_surfaces = 0
for h in range(max_hkl):
for k in range(max_hkl):
for l in range(max_hkl):
if max([h, k, l]) > 0 and num_surfaces < 2:
for hh in range(max_hkl):
for kk in range(max_hkl):
for ll in range(max_hkl):
if max([hh, kk, ll]) > 0 and num_surfaces < 2:
sg = SlabGenerator(
structure,
(h, k, l),
(hh, kk, ll),
min_slab_size=min_slab_size,
min_vacuum_size=min_vacuum_size,
)
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/ferroelectricity/polarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def get_lattice_quanta(self, convert_to_muC_per_cm2=True, all_in_polar=True):
lattice = lattices[-1]
lattices[i] = Lattice.from_parameters(*(np.array(lattice.lengths) * units.ravel()[-1]), *lattice.angles)

quanta = np.array([np.array(l.lengths) for l in lattices])
quanta = np.array([np.array(latt.lengths) for latt in lattices])

return quanta

Expand Down
Loading

0 comments on commit 6b83007

Please sign in to comment.