diff --git a/pymatgen/io/feff/inputs.py b/pymatgen/io/feff/inputs.py index d73a9341f91..5798a51acd1 100644 --- a/pymatgen/io/feff/inputs.py +++ b/pymatgen/io/feff/inputs.py @@ -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]]: diff --git a/tests/files/Pt37_atoms.inp.gz b/tests/files/Pt37_atoms.inp.gz new file mode 100644 index 00000000000..0ca9844e704 Binary files /dev/null and b/tests/files/Pt37_atoms.inp.gz differ diff --git a/tests/io/feff/test_inputs.py b/tests/io/feff/test_inputs.py index dfde53e380b..dc48d00ca51 100644 --- a/tests/io/feff/test_inputs.py +++ b/tests/io/feff/test_inputs.py @@ -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):