diff --git a/pymatgen/io/vasp/inputs.py b/pymatgen/io/vasp/inputs.py index 7f1aceab7b3..53d6016a55d 100644 --- a/pymatgen/io/vasp/inputs.py +++ b/pymatgen/io/vasp/inputs.py @@ -209,18 +209,18 @@ def __setattr__(self, name, value): super().__setattr__(name, value) @staticmethod - def from_file(filename, check_for_POTCAR=True, read_velocities=True) -> Poscar: + def from_file(filename, check_for_potcar=True, read_velocities=True, **kwargs) -> Poscar: """ Reads a Poscar from a file. The code will try its best to determine the elements in the POSCAR in the following order: - 1. If check_for_POTCAR is True, the code will try to check if a POTCAR + 1. If check_for_potcar is True, the code will try to check if a POTCAR is in the same directory as the POSCAR and use elements from that by default. (This is the VASP default sequence of priority). 2. If the input file is VASP5-like and contains element symbols in the - 6th line, the code will use that if check_for_POTCAR is False or there + 6th line, the code will use that if check_for_potcar is False or there is no POTCAR found. 3. Failing (2), the code will check if a symbol is provided at the end of each coordinate. @@ -233,7 +233,7 @@ def from_file(filename, check_for_POTCAR=True, read_velocities=True) -> Poscar: Args: filename (str): File name containing Poscar data. - check_for_POTCAR (bool): Whether to check if a POTCAR is present + check_for_potcar (bool): Whether to check if a POTCAR is present in the same directory as the POSCAR. Defaults to True. read_velocities (bool): Whether to read or not velocities if they are present in the POSCAR. Default is True. @@ -241,9 +241,13 @@ def from_file(filename, check_for_POTCAR=True, read_velocities=True) -> Poscar: Returns: Poscar object. """ + if "check_for_POTCAR" in kwargs: + warnings.warn("check_for_POTCAR is deprecated. Use check_for_potcar instead.", DeprecationWarning) + check_for_potcar = kwargs.pop("check_for_POTCAR") + dirname = os.path.dirname(os.path.abspath(filename)) names = None - if check_for_POTCAR and SETTINGS.get("PMG_POTCAR_CHECKS") is not False: + if check_for_potcar and SETTINGS.get("PMG_POTCAR_CHECKS") is not False: potcars = glob(f"{dirname}/*POTCAR*") if potcars: try: diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index 0b5c9ab6097..99130d87901 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -90,7 +90,7 @@ def test_init(self): def test_from_file(self): filepath = f"{TEST_FILES_DIR}/POSCAR.symbols_natoms_multilines" - poscar = Poscar.from_file(filepath, check_for_POTCAR=False, read_velocities=False) + poscar = Poscar.from_file(filepath, check_for_potcar=False, read_velocities=False) ordered_expected_elements = [ "Fe", "Cr", @@ -264,7 +264,7 @@ def test_str(self): def test_from_md_run(self): # Parsing from an MD type run with velocities and predictor corrector data - poscar = Poscar.from_file(f"{TEST_FILES_DIR}/CONTCAR.MD", check_for_POTCAR=False) + poscar = Poscar.from_file(f"{TEST_FILES_DIR}/CONTCAR.MD", check_for_potcar=False) assert np.sum(np.array(poscar.velocities)) == approx(0.0065417961324) assert poscar.predictor_corrector[0][0][0] == 0.33387820e00 assert poscar.predictor_corrector[0][1][1] == -0.10583589e-02 @@ -272,7 +272,7 @@ def test_from_md_run(self): def test_write_md_poscar(self): # Parsing from an MD type run with velocities and predictor corrector data # And writing a new POSCAR from the new structure - poscar = Poscar.from_file(f"{TEST_FILES_DIR}/CONTCAR.MD", check_for_POTCAR=False) + poscar = Poscar.from_file(f"{TEST_FILES_DIR}/CONTCAR.MD", check_for_potcar=False) path = Path("POSCAR.testing.md") poscar.write_file(path) @@ -286,7 +286,7 @@ def test_write_md_poscar(self): def test_setattr(self): filepath = f"{TEST_FILES_DIR}/POSCAR" - poscar = Poscar.from_file(filepath, check_for_POTCAR=False) + poscar = Poscar.from_file(filepath, check_for_potcar=False) with pytest.raises(ValueError, match="velocities array must be same length as the structure"): poscar.velocities = [[0, 0, 0]] poscar.selective_dynamics = np.array([[True, False, False]] * 24) @@ -1187,7 +1187,7 @@ def setUp(self): filepath = f"{TEST_FILES_DIR}/INCAR" incar = Incar.from_file(filepath) filepath = f"{TEST_FILES_DIR}/POSCAR" - poscar = Poscar.from_file(filepath, check_for_POTCAR=False) + poscar = Poscar.from_file(filepath, check_for_potcar=False) if "PMG_VASP_PSP_DIR" not in os.environ: os.environ["PMG_VASP_PSP_DIR"] = str(TEST_FILES_DIR) filepath = f"{TEST_FILES_DIR}/POTCAR"