|
60 | 60 |
|
61 | 61 | from pymatgen.util.typing import CompositionLike, SpeciesLike
|
62 | 62 |
|
63 |
| -FileFormats = Literal["cif", "poscar", "cssr", "json", "yaml", "yml", "xsf", "mcsqs", "res", ""] |
| 63 | +FileFormats = Literal["cif", "poscar", "cssr", "json", "yaml", "yml", "xsf", "mcsqs", "res", "pwmat", ""] |
64 | 64 |
|
65 | 65 |
|
66 | 66 | class Neighbor(Site):
|
@@ -2671,7 +2671,7 @@ def to(self, filename: str | Path = "", fmt: FileFormats = "", **kwargs) -> str:
|
2671 | 2671 | fmt (str): Format to output to. Defaults to JSON unless filename
|
2672 | 2672 | is provided. If fmt is specifies, it overrides whatever the
|
2673 | 2673 | filename is. Options include "cif", "poscar", "cssr", "json",
|
2674 |
| - "xsf", "mcsqs", "prismatic", "yaml", "yml", "fleur-inpgen". |
| 2674 | + "xsf", "mcsqs", "prismatic", "yaml", "yml", "fleur-inpgen", "pwmat". |
2675 | 2675 | Non-case sensitive.
|
2676 | 2676 | **kwargs: Kwargs passthru to relevant methods. E.g., This allows
|
2677 | 2677 | the passing of parameters like symprec to the
|
@@ -2752,6 +2752,10 @@ def to(self, filename: str | Path = "", fmt: FileFormats = "", **kwargs) -> str:
|
2752 | 2752 | with zopen(filename, mode="wt", encoding="utf8") as file:
|
2753 | 2753 | file.write(res_str)
|
2754 | 2754 | return res_str
|
| 2755 | + elif fmt == "pwmat" or fnmatch(filename.lower(), "*.pwmat") or fnmatch(filename.lower(), "*.config"): |
| 2756 | + from pymatgen.io.pwmat import AtomConfig |
| 2757 | + |
| 2758 | + writer = AtomConfig(self, **kwargs) |
2755 | 2759 | else:
|
2756 | 2760 | if fmt == "":
|
2757 | 2761 | raise ValueError(f"Format not specified and could not infer from {filename=}")
|
@@ -2832,6 +2836,10 @@ def from_str( # type: ignore[override]
|
2832 | 2836 | from pymatgen.io.res import ResIO
|
2833 | 2837 |
|
2834 | 2838 | struct = ResIO.structure_from_str(input_string, **kwargs)
|
| 2839 | + elif fmt == "pwmat": |
| 2840 | + from pymatgen.io.pwmat import AtomConfig |
| 2841 | + |
| 2842 | + struct = AtomConfig.from_str(input_string, **kwargs).structure |
2835 | 2843 | else:
|
2836 | 2844 | raise ValueError(f"Invalid {fmt=}, valid options are {get_args(FileFormats)}")
|
2837 | 2845 |
|
@@ -2910,8 +2918,12 @@ def from_file( # type: ignore[override]
|
2910 | 2918 | from pymatgen.io.res import ResIO
|
2911 | 2919 |
|
2912 | 2920 | struct = ResIO.structure_from_file(filename, **kwargs)
|
| 2921 | + elif fnmatch(fname.lower(), "*.config*") or fnmatch(fname.lower(), "*.pwmat*"): |
| 2922 | + from pymatgen.io.pwmat import AtomConfig |
| 2923 | + |
| 2924 | + struct = AtomConfig.from_file(filename, **kwargs).structure |
2913 | 2925 | else:
|
2914 |
| - raise ValueError("Unrecognized file extension!") |
| 2926 | + raise ValueError(f"Unrecognized extension in {filename=}") |
2915 | 2927 | if sort:
|
2916 | 2928 | struct = struct.get_sorted_structure()
|
2917 | 2929 | if merge_tol:
|
|
0 commit comments