Skip to content

Commit

Permalink
Merge branch 'master' of github.com:materialsproject/pymatgen
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyue Ping Ong committed Oct 16, 2023
2 parents 37beac4 + 17e6ceb commit 65799c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 9 additions & 5 deletions pymatgen/io/vasp/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -233,17 +233,21 @@ 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.
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:
Expand Down
10 changes: 5 additions & 5 deletions tests/io/vasp/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -264,15 +264,15 @@ 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

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)
Expand All @@ -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)
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 65799c1

Please sign in to comment.