Skip to content

Commit

Permalink
Fix Atoms.cluster_from_file() in io.feff.inputs giving wrong numb…
Browse files Browse the repository at this point in the history
…er of atoms (#3426)

* Update test_sets.py

* add test file

* fix a bug in inputs.py

* fix AttributeError: 'list' object has no attribute 'startswith'

        for line in lines:
>           if line and not line.startswith("*"):

* gzip tests/files/ATOMS_test.inp

* improve test

---------

Signed-off-by: KaifengZheng <[email protected]>
Co-authored-by: Janosh Riebesell <[email protected]>
  • Loading branch information
kaifengZheng and janosh authored Nov 2, 2023
1 parent 6ce6d9b commit 8ce1cdd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pymatgen/io/feff/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,13 @@ def cluster_from_file(filename):
is the one at the origin.
"""
atoms_string = Atoms.atoms_string_from_file(filename)
lines = [line.split() for line in atoms_string.splitlines()[3:]]
lines = [line.split() for line in atoms_string.splitlines()[1:]]
coords = []
symbols = []
for line in lines:
if line:
coords.append([float(val) for val in line[:3]])
symbols.append(line[4])
for tokens in lines:
if tokens and not tokens[0].startswith("*"):
coords.append([float(val) for val in tokens[:3]])
symbols.append(tokens[4])
return Molecule(symbols, coords)

def get_lines(self) -> list[list[str | int]]:
Expand Down
Binary file added tests/files/Pt37_atoms.inp.gz
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/io/feff/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def test_cluster_from_file(self):
assert len(mol_1) == len(mol_2)
os.remove("ATOMS_test")

def test_atom_num(self):
filepath = f"{TEST_FILES_DIR}/Pt37_atoms.inp.gz"
atoms = Atoms.cluster_from_file(filepath)
assert len(atoms) == 37
assert atoms.formula == "Pt37"


class TestFeffTags(unittest.TestCase):
def test_init(self):
Expand Down

0 comments on commit 8ce1cdd

Please sign in to comment.