Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpaceGroup.__repr__ #3122

Merged
merged 6 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ permissions:
jobs:
pytest:
# prevent this action from running on forks
if: github.repository == 'materialsproject/pymatgen'
if: ${{ !github.event.pull_request.head.repo.fork }}
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ci:
autoupdate_commit_msg: pre-commit autoupdate

repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.275
hooks:
- id: ruff
Expand Down
12 changes: 4 additions & 8 deletions pymatgen/analysis/elasticity/tests/test_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,7 @@ def test_energy_density(self):
[
[0.99774738, 0.11520994, -0],
[-0.11520994, 0.99774738, 0],
[
-0,
-0,
1,
],
[-0, -0, 1],
]
)
)
Expand Down Expand Up @@ -268,9 +264,9 @@ def tearDown(self):
warnings.simplefilter("default")

def test_init(self):
cijkl = Tensor.from_voigt(self.c2)
cijklmn = Tensor.from_voigt(self.c3)
exp = ElasticTensorExpansion([cijkl, cijklmn])
c_ijkl = Tensor.from_voigt(self.c2)
c_ijklmn = Tensor.from_voigt(self.c3)
exp = ElasticTensorExpansion([c_ijkl, c_ijklmn])
ElasticTensorExpansion.from_voigt([self.c2, self.c3])
assert exp.order == 3

Expand Down
4 changes: 0 additions & 4 deletions pymatgen/analysis/tests/test_surface_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import json
import os
import warnings

from pytest import approx
from sympy import Number, Symbol
Expand All @@ -25,9 +24,6 @@ def get_path(path_str):

class SlabEntryTest(PymatgenTest):
def setUp(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore")

with open(os.path.join(get_path(""), "ucell_entries.txt")) as ucell_entries:
ucell_entries = json.loads(ucell_entries.read())
self.ucell_entries = ucell_entries
Expand Down
26 changes: 12 additions & 14 deletions pymatgen/apps/borg/tests/test_hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@ def test_get_valid_paths(self):
assert len(self.drone.get_valid_paths(path)) > 0

def test_assimilate(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
entry = self.drone.assimilate(PymatgenTest.TEST_FILES_DIR)
for p in ["hubbards", "is_hubbard", "potcar_spec", "run_type"]:
assert p in entry.parameters
assert entry.data["efermi"] == approx(-6.62148548)
assert entry.composition.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)
entry = self.structure_drone.assimilate(PymatgenTest.TEST_FILES_DIR)
assert entry.composition.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)
assert isinstance(entry, ComputedStructureEntry)
assert entry.structure is not None
# assert len(entry.parameters["history"]) == 2
entry = self.drone.assimilate(PymatgenTest.TEST_FILES_DIR)
for p in ["hubbards", "is_hubbard", "potcar_spec", "run_type"]:
assert p in entry.parameters
assert entry.data["efermi"] == approx(-6.62148548)
assert entry.composition.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)
entry = self.structure_drone.assimilate(PymatgenTest.TEST_FILES_DIR)
assert entry.composition.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)
assert isinstance(entry, ComputedStructureEntry)
assert entry.structure is not None
# assert len(entry.parameters["history"]) == 2

def tearDown(self):
warnings.simplefilter("default")
Expand Down
4 changes: 1 addition & 3 deletions pymatgen/command_line/mcsqs_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ def _parse_sqs_path(path) -> Sqs:
corr_out = f"bestcorr{i + 1}.out"
with Popen(f"str2cif < {sqs_out} > {sqs_cif}", shell=True, cwd=path) as p:
p.communicate()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
sqs = Structure.from_file(path / sqs_out)
sqs = Structure.from_file(path / sqs_out)
with open(path / corr_out) as f:
lines = f.readlines()

Expand Down
107 changes: 52 additions & 55 deletions pymatgen/command_line/tests/test_enumlib_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import os
import unittest
import warnings
from shutil import which

import pytest
Expand All @@ -26,62 +25,60 @@ class EnumlibAdaptorTest(PymatgenTest):
_multiprocess_shared_ = True

def test_init(self):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
struct = self.get_structure("LiFePO4")
subtrans = SubstitutionTransformation({"Li": {"Li": 0.5}})
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 2)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 86
for s in structures:
assert s.composition.get_atomic_fraction(Element("Li")) == approx(0.5 / 6.5)
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 2, refine_structure=True)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 52
struct = self.get_structure("LiFePO4")
subtrans = SubstitutionTransformation({"Li": {"Li": 0.5}})
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 2)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 86
for s in structures:
assert s.composition.get_atomic_fraction(Element("Li")) == approx(0.5 / 6.5)
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 2, refine_structure=True)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 52

subtrans = SubstitutionTransformation({"Li": {"Li": 0.25}})
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 1, refine_structure=True)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 1
for s in structures:
assert s.composition.get_atomic_fraction(Element("Li")) == approx(0.25 / 6.25)

# Make sure it works for completely disordered structures.
struct = Structure([[10, 0, 0], [0, 10, 0], [0, 0, 10]], [{"Fe": 0.5}], [[0, 0, 0]])
adaptor = EnumlibAdaptor(struct, 1, 2)
adaptor.run()
assert len(adaptor.structures) == 3

# Make sure it works properly when symmetry is broken by ordered sites.
struct = self.get_structure("LiFePO4")
subtrans = SubstitutionTransformation({"Li": {"Li": 0.25}})
s = subtrans.apply_transformation(struct)
# REmove some ordered sites to break symmetry.
removetrans = RemoveSitesTransformation([4, 7])
s = removetrans.apply_transformation(s)
adaptor = EnumlibAdaptor(s, 1, 1, enum_precision_parameter=0.01)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 4

struct = Structure(
[[3, 0, 0], [0, 3, 0], [0, 0, 3]],
[{"Si": 0.5}] * 2,
[[0, 0, 0], [0.5, 0.5, 0.5]],
)
adaptor = EnumlibAdaptor(struct, 1, 3, enum_precision_parameter=0.01)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 10
subtrans = SubstitutionTransformation({"Li": {"Li": 0.25}})
adaptor = EnumlibAdaptor(subtrans.apply_transformation(struct), 1, 1, refine_structure=True)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 1
for s in structures:
assert s.composition.get_atomic_fraction(Element("Li")) == approx(0.25 / 6.25)

struct = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "EnumerateTest.json"))
adaptor = EnumlibAdaptor(struct, 1, 1)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 2
# Make sure it works for completely disordered structures.
struct = Structure([[10, 0, 0], [0, 10, 0], [0, 0, 10]], [{"Fe": 0.5}], [[0, 0, 0]])
adaptor = EnumlibAdaptor(struct, 1, 2)
adaptor.run()
assert len(adaptor.structures) == 3

# Make sure it works properly when symmetry is broken by ordered sites.
struct = self.get_structure("LiFePO4")
subtrans = SubstitutionTransformation({"Li": {"Li": 0.25}})
s = subtrans.apply_transformation(struct)
# REmove some ordered sites to break symmetry.
removetrans = RemoveSitesTransformation([4, 7])
s = removetrans.apply_transformation(s)
adaptor = EnumlibAdaptor(s, 1, 1, enum_precision_parameter=0.01)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 4

struct = Structure(
[[3, 0, 0], [0, 3, 0], [0, 0, 3]],
[{"Si": 0.5}] * 2,
[[0, 0, 0], [0.5, 0.5, 0.5]],
)
adaptor = EnumlibAdaptor(struct, 1, 3, enum_precision_parameter=0.01)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 10

struct = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "EnumerateTest.json"))
adaptor = EnumlibAdaptor(struct, 1, 1)
adaptor.run()
structures = adaptor.structures
assert len(structures) == 2

def test_rounding_errors(self):
# It used to be that a rounding issue would result in this structure
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,8 +1013,8 @@ def from_spacegroup(
from pymatgen.symmetry.groups import SpaceGroup

try:
i = int(sg)
spg = SpaceGroup.from_int_number(i)
num = int(sg)
spg = SpaceGroup.from_int_number(num)
except ValueError:
spg = SpaceGroup(sg) # type: ignore

Expand All @@ -1038,12 +1038,12 @@ def from_spacegroup(
all_sp: list[str | Element | Species | DummySpecies | Composition] = []
all_coords: list[list[float]] = []
all_site_properties: dict[str, list] = collections.defaultdict(list)
for i, (sp, c) in enumerate(zip(species, frac_coords)):
for idx, (sp, c) in enumerate(zip(species, frac_coords)):
cc = spg.get_orbit(c, tol=tol)
all_sp.extend([sp] * len(cc))
all_coords.extend(cc) # type: ignore
for k, v in props.items():
all_site_properties[k].extend([v[i]] * len(cc))
all_site_properties[k].extend([v[idx]] * len(cc))

return cls(latt, all_sp, all_coords, site_properties=all_site_properties)

Expand Down
Loading