Skip to content

Commit

Permalink
Revert "Merge branch 'master' into fix-stru-prop-check"
Browse files Browse the repository at this point in the history
This reverts commit e6fc3e6, reversing
changes made to 091c911.
  • Loading branch information
DanielYang59 committed Dec 11, 2024
1 parent e6fc3e6 commit 5b06c2a
Show file tree
Hide file tree
Showing 97 changed files with 523 additions and 1,030 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,36 @@ jobs:
- name: Check out repo
uses: actions/checkout@v4

- name: Create mamba environment
- name: Set up micromamba
uses: mamba-org/setup-micromamba@main
with:
environment-name: pmg
create-args: >-
python=${{ matrix.config.python }}

- name: Create mamba environment
run: |
micromamba create -n pmg python=${{ matrix.config.python }} --yes
- name: Install ubuntu-only conda dependencies
if: matrix.config.os == 'ubuntu-latest'
run: |
micromamba install -n pmg -c conda-forge bader enumlib \
openff-toolkit packmol pygraphviz tblite --yes
- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Install pymatgen and dependencies via uv
run: |
micromamba activate pmg
pip install uv
# TODO1 (use uv over pip) uv install torch is flaky, track #3826
# TODO2 (pin torch version): DGL library (matgl) doesn't support torch > 2.2.1,
# see: https://discuss.dgl.ai/t/filenotfounderror-cannot-find-dgl-c-graphbolt-library/4302
pip install torch==2.2.1
# Install from wheels to test the content
uv build --wheel --no-build-logs
WHEEL_FILE=$(ls dist/pymatgen*.whl)
uv pip install $WHEEL_FILE[${{matrix.config.extras}}] --resolution=${{matrix.config.resolution}}
uv pip install build
python -m build --wheel
uv pip install dist/*.whl
uv pip install pymatgen[${{ matrix.config.extras }}] --resolution=${{ matrix.config.resolution }}
- name: Install optional Ubuntu dependencies
if: matrix.config.os == 'ubuntu-latest'
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
rev: v0.7.2
hooks:
- id: ruff
args: [--fix, --unsafe-fixes]
Expand Down Expand Up @@ -36,7 +36,7 @@ repos:
exclude: src/pymatgen/analysis/aflow_prototypes.json

- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.16.6
rev: v0.16.2
hooks:
- id: cython-lint
args: [--no-pycodestyle]
Expand All @@ -48,7 +48,7 @@ repos:
- id: blacken-docs

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.43.0
rev: v0.42.0
hooks:
- id: markdownlint
# MD013: line too long
Expand All @@ -59,12 +59,12 @@ repos:
args: [--disable, MD013, MD024, MD025, MD033, MD041, "--"]

- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
rev: 0.8.0
hooks:
- id: nbstripout
args: [--drop-empty-cells, --keep-output]

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.389
rev: v1.1.387
hooks:
- id: pyright
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Pymatgen (Python Materials Genomics) is a robust, open-source Python
library for materials analysis. These are some of the main features:

1. Highly flexible classes for the representation of `Element`, `Site`, `Molecule` and `Structure` objects.
2. Extensive input/output support, including support for [VASP](https://www.vasp.at/), [ABINIT](https://abinit.github.io/abinit_web/), [CIF](https://wikipedia.org/wiki/Crystallographic_Information_File), [Gaussian](https://gaussian.com), [XYZ](https://wikipedia.org/wiki/XYZ_file_format), and many other file formats.
2. Extensive input/output support, including support for [VASP](https://cms.mpi.univie.ac.at/vasp), [ABINIT](https://abinit.org), [CIF](https://wikipedia.org/wiki/Crystallographic_Information_File), [Gaussian](https://gaussian.com), [XYZ](https://wikipedia.org/wiki/XYZ_file_format), and many other file formats.
3. Powerful analysis tools, including generation of phase diagrams, Pourbaix diagrams, diffusion analyses, reactions, etc.
4. Electronic structure analyses, such as density of states and band structure.
5. Integration with the [Materials Project] REST API.
Expand Down
2 changes: 1 addition & 1 deletion dev_scripts/potcar_scrambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def generate_fake_potcar_libraries() -> None:
zpath(f"{func_dir}/{psp_name}/POTCAR"),
]
if not any(map(os.path.isfile, paths_to_try)):
warnings.warn(f"Could not find {psp_name} in {paths_to_try}", stacklevel=2)
warnings.warn(f"Could not find {psp_name} in {paths_to_try}")
for potcar_path in paths_to_try:
if os.path.isfile(potcar_path):
os.makedirs(rebase_dir, exist_ok=True)
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ Issues = "https://github.com/materialsproject/pymatgen/issues"
Pypi = "https://pypi.org/project/pymatgen"

[project.optional-dependencies]
abinit = ["netcdf4>=1.7.2"]
# PR4128: netcdf4 1.7.[0/1] yanked, 1.7.1.post[1/2]/1.7.2 cause CI error
abinit = ["netcdf4>=1.6.5,!=1.7.1.post1,!=1.7.1.post2,!=1.7.2"]
ase = ["ase>=3.23.0"]
ci = ["pytest-cov>=4", "pytest-split>=0.8", "pytest>=8"]
docs = ["invoke", "sphinx", "sphinx_markdown_builder", "sphinx_rtd_theme"]
Expand Down Expand Up @@ -192,6 +193,7 @@ ignore = [

# Single rules
"B023", # Function definition does not bind loop variable
"B028", # No explicit stacklevel keyword argument found
"B904", # Within an except clause, raise exceptions with ...
"C408", # unnecessary-collection-call
"D105", # Missing docstring in magic method
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/alchemy/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def to_snl(self, authors: list[str], **kwargs) -> StructureNL:
StructureNL: The generated StructureNL object.
"""
if self.other_parameters:
warn("Data in TransformedStructure.other_parameters discarded during type conversion to SNL", stacklevel=2)
warn("Data in TransformedStructure.other_parameters discarded during type conversion to SNL")
history = []
for hist in self.history:
snl_metadata = hist.pop("_snl", {})
Expand Down
10 changes: 4 additions & 6 deletions src/pymatgen/analysis/bond_dissociation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def __init__(
if multibreak:
warnings.warn(
"Breaking pairs of ring bonds. WARNING: Structure changes much more likely, meaning dissociation values"
" are less reliable! This is a bad idea!",
stacklevel=2,
" are less reliable! This is a bad idea!"
)
self.bond_pairs = []
for ii, bond in enumerate(self.ring_bonds, start=1):
Expand Down Expand Up @@ -165,8 +164,7 @@ def fragment_and_process(self, bonds):
warnings.warn(
f"Missing ring opening fragment resulting from the breakage of {specie[bonds[0][0]]} "
f"{specie[bonds[0][1]]} bond {bonds[0][0]} {bonds[0][1]} which would yield a "
f"molecule with this SMILES string: {smiles}",
stacklevel=2,
f"molecule with this SMILES string: {smiles}"
)
elif len(good_entries) == 1:
# If we have only one good entry, format it and add it to the list that will eventually return
Expand Down Expand Up @@ -214,14 +212,14 @@ def fragment_and_process(self, bonds):
smiles = pb_mol.write("smi").split()[0]
for charge in self.expected_charges:
if charge not in frag1_charges_found:
warnings.warn(f"Missing {charge=} for fragment {smiles}", stacklevel=2)
warnings.warn(f"Missing {charge=} for fragment {smiles}")
if len(frag2_charges_found) < len(self.expected_charges):
bb = BabelMolAdaptor(fragments[1].molecule)
pb_mol = bb.pybel_mol
smiles = pb_mol.write("smi").split()[0]
for charge in self.expected_charges:
if charge not in frag2_charges_found:
warnings.warn(f"Missing {charge=} for fragment {smiles}", stacklevel=2)
warnings.warn(f"Missing {charge=} for fragment {smiles}")
# Now we attempt to pair fragments with the right total charge, starting with only fragments with no
# structural change:
for frag1 in frag1_entries[0]: # 0 -> no structural change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ def points_wcs_csc(self, permutation=None):
"""
if permutation is None:
return self._points_wcs_csc
return np.concatenate(
(self._points_wcs_csc[:1], self._points_wocs_csc.take(np.array(permutation, dtype=np.intp), axis=0))
)
return np.concatenate((self._points_wcs_csc[:1], self._points_wocs_csc.take(permutation, axis=0)))

def points_wocs_csc(self, permutation=None):
"""
Expand All @@ -229,7 +227,7 @@ def points_wocs_csc(self, permutation=None):
"""
if permutation is None:
return self._points_wocs_csc
return self._points_wocs_csc.take(np.array(permutation, dtype=np.intp), axis=0)
return self._points_wocs_csc.take(permutation, axis=0)

def points_wcs_ctwcc(self, permutation=None):
"""
Expand All @@ -241,7 +239,7 @@ def points_wcs_ctwcc(self, permutation=None):
return np.concatenate(
(
self._points_wcs_ctwcc[:1],
self._points_wocs_ctwcc.take(np.array(permutation, dtype=np.intp), axis=0),
self._points_wocs_ctwcc.take(permutation, axis=0),
)
)

Expand All @@ -252,7 +250,7 @@ def points_wocs_ctwcc(self, permutation=None):
"""
if permutation is None:
return self._points_wocs_ctwcc
return self._points_wocs_ctwcc.take(np.array(permutation, dtype=np.intp), axis=0)
return self._points_wocs_ctwcc.take(permutation, axis=0)

def points_wcs_ctwocc(self, permutation=None):
"""
Expand All @@ -264,7 +262,7 @@ def points_wcs_ctwocc(self, permutation=None):
return np.concatenate(
(
self._points_wcs_ctwocc[:1],
self._points_wocs_ctwocc.take(np.array(permutation, dtype=np.intp), axis=0),
self._points_wocs_ctwocc.take(permutation, axis=0),
)
)

Expand All @@ -275,7 +273,7 @@ def points_wocs_ctwocc(self, permutation=None):
"""
if permutation is None:
return self._points_wocs_ctwocc
return self._points_wocs_ctwocc.take(np.array(permutation, dtype=np.intp), axis=0)
return self._points_wocs_ctwocc.take(permutation, axis=0)

@property
def cn(self):
Expand Down Expand Up @@ -1978,7 +1976,6 @@ def _cg_csm_separation_plane_optim2(
stop_search = False
# TODO: do not do that several times ... also keep in memory
if sepplane.ordered_plane:
separation_indices = [arr.astype(np.intp) for arr in separation_indices]
inp = self.local_geometry.coords.take(separation_indices[1], axis=0)
if sepplane.ordered_point_groups[0]:
pp_s0 = self.local_geometry.coords.take(separation_indices[0], axis=0)
Expand Down Expand Up @@ -2054,7 +2051,10 @@ def coordination_geometry_symmetry_measures_fallback_random(
The symmetry measures for the given coordination geometry for each permutation investigated.
"""
if "NRANDOM" in kwargs:
warnings.warn("NRANDOM is deprecated, use n_random instead", category=DeprecationWarning, stacklevel=2)
warnings.warn(
"NRANDOM is deprecated, use n_random instead",
category=DeprecationWarning,
)
n_random = kwargs.pop("NRANDOM")
permutations_symmetry_measures = [None] * n_random
permutations = []
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/analysis/chempot_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def _get_3d_plot(
if formulas_to_draw:
for formula in formulas_to_draw:
if formula not in domain_simplexes:
warnings.warn(f"Specified formula to draw, {formula}, not found!", stacklevel=2)
warnings.warn(f"Specified formula to draw, {formula}, not found!")

if draw_formula_lines:
data.extend(self._get_3d_formula_lines(draw_domains, formula_colors))
Expand Down
11 changes: 4 additions & 7 deletions src/pymatgen/analysis/elasticity/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __new__(cls, input_array, check_rank=None, tol: float = 1e-4) -> Self:
if obj.rank % 2 != 0:
raise ValueError("ElasticTensor must have even rank")
if not obj.is_voigt_symmetric(tol):
warnings.warn("Input elastic tensor does not satisfy standard Voigt symmetries", stacklevel=2)
warnings.warn("Input elastic tensor does not satisfy standard Voigt symmetries")
return obj.view(cls)

@property
Expand Down Expand Up @@ -476,8 +476,7 @@ def from_pseudoinverse(cls, strains, stresses) -> Self:
# convert the stress/strain to Nx6 arrays of voigt notation
warnings.warn(
"Pseudo-inverse fitting of Strain/Stress lists may yield "
"questionable results from vasp data, use with caution.",
stacklevel=2,
"questionable results from vasp data, use with caution."
)
stresses = np.array([Stress(stress).voigt for stress in stresses])
with warnings.catch_warnings():
Expand Down Expand Up @@ -506,9 +505,7 @@ def from_independent_strains(cls, strains, stresses, eq_stress=None, vasp=False,
if not set(strain_states) <= set(ss_dict):
raise ValueError(f"Missing independent strain states: {set(strain_states) - set(ss_dict)}")
if len(set(ss_dict) - set(strain_states)) > 0:
warnings.warn(
"Extra strain states in strain-stress pairs are neglected in independent strain fitting", stacklevel=2
)
warnings.warn("Extra strain states in strain-stress pairs are neglected in independent strain fitting")
c_ij = np.zeros((6, 6))
for ii in range(6):
strains = ss_dict[strain_states[ii]]["strains"]
Expand Down Expand Up @@ -919,7 +916,7 @@ def find_eq_stress(strains, stresses, tol: float = 1e-10):
)
eq_stress = eq_stress[0]
else:
warnings.warn("No eq state found, returning zero voigt stress", stacklevel=2)
warnings.warn("No eq state found, returning zero voigt stress")
eq_stress = Stress(np.zeros((3, 3)))
return eq_stress

Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/analysis/ewald.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def get_site_energy(self, site_index):
self._initialized = True

if self._charged:
warn("Per atom energies for charged structures not supported in EwaldSummation", stacklevel=2)
warn("Per atom energies for charged structures not supported in EwaldSummation")
return np.sum(self._recip[:, site_index]) + np.sum(self._real[:, site_index]) + self._point[site_index]

def _calc_ewald_terms(self):
Expand Down
1 change: 0 additions & 1 deletion src/pymatgen/analysis/gb/grain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
"Grain boundary analysis has been moved to pymatgen.core.interface."
"This stub is retained for backwards compatibility and will be removed Dec 31 2024.",
DeprecationWarning,
stacklevel=2,
)
11 changes: 4 additions & 7 deletions src/pymatgen/analysis/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def add_edge(
# edges if appropriate
if to_jimage is None:
# assume we want the closest site
warnings.warn("Please specify to_jimage to be unambiguous, trying to automatically detect.", stacklevel=2)
warnings.warn("Please specify to_jimage to be unambiguous, trying to automatically detect.")
dist, to_jimage = self.structure[from_index].distance_and_image(self.structure[to_index])
if dist == 0:
# this will happen when from_index == to_index,
Expand Down Expand Up @@ -417,7 +417,7 @@ def add_edge(
# this is a convention to avoid duplicate hops
if to_index == from_index:
if to_jimage == (0, 0, 0):
warnings.warn("Tried to create a bond to itself, this doesn't make sense so was ignored.", stacklevel=2)
warnings.warn("Tried to create a bond to itself, this doesn't make sense so was ignored.")
return

# ensure that the first non-zero jimage index is positive
Expand All @@ -439,8 +439,7 @@ def add_edge(
if warn_duplicates:
warnings.warn(
"Trying to add an edge that already exists from "
f"site {from_index} to site {to_index} in {to_jimage}.",
stacklevel=2,
f"site {from_index} to site {to_index} in {to_jimage}."
)
return

Expand Down Expand Up @@ -1827,9 +1826,7 @@ def add_edge(
# between two sites
existing_edge_data = self.graph.get_edge_data(from_index, to_index)
if existing_edge_data and warn_duplicates:
warnings.warn(
f"Trying to add an edge that already exists from site {from_index} to site {to_index}.", stacklevel=2
)
warnings.warn(f"Trying to add an edge that already exists from site {from_index} to site {to_index}.")
return

# generic container for additional edge properties,
Expand Down
11 changes: 4 additions & 7 deletions src/pymatgen/analysis/interface_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,8 @@ def _get_entry_energy(pd: PhaseDiagram, composition: Composition):

if not candidate:
warnings.warn(
f"The reactant {composition.reduced_formula} has no matching entry "
"with negative formation energy, instead convex hull energy for "
"this composition will be used for reaction energy calculation.",
stacklevel=2,
f"The reactant {composition.reduced_formula} has no matching entry with negative formation"
" energy, instead convex hull energy for this composition will be used for reaction energy calculation."
)
return pd.get_hull_energy(composition)
min_entry_energy = min(candidate)
Expand Down Expand Up @@ -547,9 +545,8 @@ def get_chempot_correction(cls, element: str, temp: float, pres: float): # code
The correction of chemical potential in eV/atom of the gas
phase at given temperature and pressure.
"""
valid_elements = {"O", "N", "Cl", "F", "H"}
if element not in valid_elements:
warnings.warn(f"{element=} not one of valid options: {valid_elements}", stacklevel=2)
if element not in ["O", "N", "Cl", "F", "H"]:
warnings.warn(f"{element=} not one of valid options: ['O', 'N', 'Cl', 'F', 'H']")
return 0

std_temp = 298.15
Expand Down
6 changes: 2 additions & 4 deletions src/pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4025,8 +4025,7 @@ def get_nn_data(self, structure: Structure, n: int, length=None):
warnings.warn(
"CrystalNN: cannot locate an appropriate radius, "
"covalent or atomic radii will be used, this can lead "
"to non-optimal results.",
stacklevel=2,
"to non-optimal results."
)
diameter = _get_default_radius(structure[n]) + _get_default_radius(entry["site"])

Expand Down Expand Up @@ -4232,8 +4231,7 @@ def _get_radius(site):
else:
warnings.warn(
"No oxidation states specified on sites! For better results, set "
"the site oxidation states in the structure.",
stacklevel=2,
"the site oxidation states in the structure."
)
return 0

Expand Down
Loading

0 comments on commit 5b06c2a

Please sign in to comment.