Skip to content
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
2 changes: 2 additions & 0 deletions structuretoolkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
center_coordinates_in_unit_cell,
get_cell,
get_extended_positions,
get_number_species_atoms,
get_vertical_length,
get_wrapped_coordinates,
pymatgen_to_ase,
Expand All @@ -113,6 +114,7 @@
"get_mean_positions",
"get_neighborhood",
"get_neighbors",
"get_number_species_atoms",
"get_steinhardt_parameters",
"get_strain",
"get_symmetry",
Expand Down
2 changes: 2 additions & 0 deletions structuretoolkit/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
center_coordinates_in_unit_cell,
get_cell,
get_extended_positions,
get_number_species_atoms,
get_vertical_length,
get_wrapped_coordinates,
select_index,
Expand All @@ -22,6 +23,7 @@
"center_coordinates_in_unit_cell",
"get_cell",
"get_extended_positions",
"get_number_species_atoms",
"get_vertical_length",
"get_wrapped_coordinates",
"select_index",
Expand Down
14 changes: 14 additions & 0 deletions structuretoolkit/common/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
from scipy.sparse import coo_matrix


def get_number_species_atoms(structure: Atoms):
"""Returns a dictionary with the species in the structure and the corresponding count in the structure

Args:
structure

Returns:
dict: A dictionary with the species and the corresponding count

"""
elements_lst = structure.get_chemical_symbols()
return {species: elements_lst.count(species) for species in set(elements_lst)}


def get_extended_positions(
structure: Atoms,
width: float,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def test_get_cell(self):
stk.get_cell(np.arange(4))
with self.assertRaises(ValueError):
stk.get_cell(np.ones((4, 3)))

def test_get_number_species_atoms(self):
with self.subTest("Fe8"):
atoms = bulk("Fe").repeat(2)
self.assertEqual(stk.get_number_species_atoms(atoms), {'Fe': 8})
with self.subTest('Al2Fe8'):
atoms = bulk('Fe').repeat(2) + bulk('Al').repeat((2,1,1))
self.assertEqual(stk.get_number_species_atoms(atoms), {'Fe': 8, 'Al':2})


if __name__ == "__main__":
Expand Down
Loading