Skip to content

Commit

Permalink
Fix concentrations in nanoparticle generation
Browse files Browse the repository at this point in the history
  • Loading branch information
sivonxay committed Oct 4, 2023
1 parent 7046c74 commit 7f8a428
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/NanoParticleTools/inputs/nanoparticle.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,15 @@ def __init__(self,
'The result will be zero intensity for everything')

if prune_hosts:
for dopants_dict, constraint in zip(conc_by_layer_and_species,
constraints):
replaced_els = []
for dopants_dict in conc_by_layer_and_species:
replaced_els.extend(list(dopants_dict.keys()))
replaced_els = list(set(replaced_els))
for constraint in constraints:
_sites = [
site for site in constraint.get_host_structure().sites
if site.species_string in dopants_dict.keys()
if site.species_string in replaced_els
]

if len(_sites) == 0:
# Need at least one site for a valid pymatgen structure.
# Just keep the first site from the host structure
_sites = [constraint.get_host_structure().sites[0]]

constraint.host_structure = Structure.from_sites(_sites)

self._sites = None
Expand Down
5 changes: 4 additions & 1 deletion tests/inputs/test_nanoparticle.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def test_nanoparticle_with_empty():
prune_hosts=True)
dnp.generate()
assert len(dnp.dopant_sites) == 18015
assert len(dnp.sites) == 39579
assert len(dnp.sites) == 59790
assert dnp.dopant_concentrations()['Yb'] == 0.24609466465964208
assert dnp.dopant_concentrations()['Er'] == 0.011975246696772036
assert dnp.dopant_concentrations()['Nd'] == 0.04323465462451915


def test_empty_nanoparticle():
Expand Down

0 comments on commit 7f8a428

Please sign in to comment.