Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent atoms order #338

Merged
merged 6 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyiron_atomistics/atomistics/structure/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def __init__(
if el_object_list is None:
el_object_list = [self.convert_element(el) for el in element_list]

self.set_species(list(set(el_object_list)))
# species_to_index_dict = {el: i for i, el in enumerate(self.species)}
# Create a list from a set but always preserve order
self.set_species(list(dict.fromkeys(el_object_list)))
el_index_lst = [self._species_to_index_dict[el] for el in el_object_list]

elif indices is not None:
Expand Down
11 changes: 11 additions & 0 deletions tests/static/vasp_test_files/poscar_samples/POSCAR_diff_species
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
POSCAR file written by Ovito Basic 3.0.0
1.00000000000000
12.4524250200999997 0.0000000000000000 0.0000157408058710
-3.1131062549999999 5.3920451819000004 -0.0000039352014677
0.0000530996979940 0.0000000000000000 40.4697188976000035
Ca Mg Al
1 1 1
Cartesian
6.2262054545 8.8300000128e-06 1.9039669849
0.3113441054 0.5391959194 18.3309003343
3.1131124744 5.3920363513 12.0213927741
11 changes: 11 additions & 0 deletions tests/vasp/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ def test_atoms_from_string(self):
self.assertRaises(AssertionError, atoms_from_string, string=lines)
else:
atoms = atoms_from_string(string=lines)
if "diff_species" in poscar_file:
for _ in range(10):
atoms = atoms_from_string(string=lines)
self.assertEqual(atoms.indices.tolist(), [0, 1, 2])
self.assertEqual(" ".join(atoms.get_chemical_symbols()), " ".join(["Ca", "Mg", "Al"]))
self.assertTrue(np.allclose(atoms.positions[atoms.select_index("Ca")],
np.array([6.2262054545, 8.8300000128e-06, 1.9039669849])))
self.assertTrue(np.allclose(atoms.positions[atoms.select_index("Mg")],
np.array([0.3113441054, 0.5391959194, 18.3309003343])))
self.assertTrue(np.allclose(atoms.positions[atoms.select_index("Al")],
np.array([3.1131124744, 5.3920363513, 12.0213927741])))
self.assertIsInstance(atoms, Atoms)

def test_read_atoms(self):
Expand Down