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

Hide warning when loading a cif file through pymatgen #223

Merged
merged 1 commit into from
Dec 12, 2023
Merged
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
14 changes: 8 additions & 6 deletions src/gemdat/io.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""This module contains functions to read and write data."""
from __future__ import annotations

import warnings
from importlib.resources import files
from pathlib import Path

from pymatgen.core import Structure
from pymatgen.io import cif
from pymatgen.io.cif import CifWriter

DATA = Path(files('gemdat') / 'data') # type: ignore

Expand All @@ -31,8 +30,8 @@ def write_cif(structure: Structure, filename: Path | str):
filename : Path | str
Filename to write to
"""
cif_path = Path(filename).with_suffix('.cif')
CifWriter(structure).write_file(cif_path)
filename = Path(filename).with_suffix('.cif')
structure.to_file(filename)


def read_cif(filename: Path | str) -> Structure:
Expand All @@ -49,8 +48,11 @@ def read_cif(filename: Path | str) -> Structure:
structure : pymatgen.core.structure.Structure
Output structure
"""
cifdata = cif.CifParser(filename)
structure = cifdata.get_structures(primitive=False)[0]
with warnings.catch_warnings():
# Hide warning from https://github.com/materialsproject/pymatgen/pull/3419
warnings.simplefilter('ignore')
structure = Structure.from_file(filename, primitive=False)

return structure


Expand Down