Skip to content

Commit

Permalink
Merge pull request #338 from pyiron/atoms_order
Browse files Browse the repository at this point in the history
Consistent atoms order
  • Loading branch information
sudarsan-surendralal committed Sep 18, 2021
2 parents 3b7f9b6 + 45d6571 commit 97a1d0b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
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

0 comments on commit 97a1d0b

Please sign in to comment.