From 7f8a42800996e71af3e3d7d83a6f55d61a760102 Mon Sep 17 00:00:00 2001 From: Eric Sivonxay Date: Tue, 3 Oct 2023 17:24:47 -0700 Subject: [PATCH] Fix concentrations in nanoparticle generation --- src/NanoParticleTools/inputs/nanoparticle.py | 15 ++++++--------- tests/inputs/test_nanoparticle.py | 5 ++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/NanoParticleTools/inputs/nanoparticle.py b/src/NanoParticleTools/inputs/nanoparticle.py index f5dbdc3..faf2ad6 100644 --- a/src/NanoParticleTools/inputs/nanoparticle.py +++ b/src/NanoParticleTools/inputs/nanoparticle.py @@ -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 diff --git a/tests/inputs/test_nanoparticle.py b/tests/inputs/test_nanoparticle.py index d79a0a1..d665064 100644 --- a/tests/inputs/test_nanoparticle.py +++ b/tests/inputs/test_nanoparticle.py @@ -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():