Skip to content

Commit 2ddd621

Browse files
msricherpre-commit-ci[bot]marco-2023
authored
Promolecule: add default multiplicities for non-int charge (#82) (#84)
* Promolecule: add default multiplicities for non-int charge * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add fix to make_promolecule Added support for making promolecules with fractional charges and no default multiplicities. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Marco Martínez González <[email protected]>
1 parent 7a41f80 commit 2ddd621

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

atomdb/promolecule.py

+41-2
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,12 @@ def make_promolecule(
584584

585585
# Handle default multiplicity parameters
586586
if mults is None:
587-
# Force non-int charge to be integer here; will be overwritten below.
588-
mults = [MULTIPLICITIES[(atnum, charge)] for (atnum, charge) in zip(atnums, charges)]
587+
# if all charges are integers, get corresponding multiplicities
588+
if all(isinstance(charge, Integral) for charge in charges):
589+
mults = [MULTIPLICITIES[(atnum, charge)] for (atnum, charge) in zip(atnums, charges)]
590+
else:
591+
# set each multiplicity to None
592+
mults = [None for _ in atnums]
589593

590594
# Construct linear combination of species
591595
promol = Promolecule()
@@ -615,6 +619,41 @@ def make_promolecule(
615619
"of other species",
616620
stacklevel=1,
617621
)
622+
# Non-integer charge, default multiplicity
623+
if mult is None:
624+
# get floor and ceiling charges
625+
f_charge, c_charge = int(np.floor(charge)), int(np.ceil(charge))
626+
fmult, cmult = MULTIPLICITIES[(atnum, f_charge)], MULTIPLICITIES[(atnum, c_charge)]
627+
# get coefficients for linear combination
628+
f_coeff = np.ceil(charge) - charge
629+
c_coeff = charge - np.floor(charge)
630+
# get corresponding species
631+
try:
632+
specie_f = load(
633+
atom,
634+
f_charge,
635+
fmult,
636+
dataset=dataset,
637+
datapath=datapath,
638+
remotepath=remotepath,
639+
)
640+
specie_c = load(
641+
atom,
642+
c_charge,
643+
cmult,
644+
dataset=dataset,
645+
datapath=datapath,
646+
remotepath=remotepath,
647+
)
648+
promol._extend((specie_f, specie_c), (coord, coord), (f_coeff, c_coeff))
649+
continue
650+
except FileNotFoundError:
651+
warn(
652+
"Unable to load species corresponding to `charge, mult`; "
653+
"generating species via linear combination "
654+
"of other species",
655+
stacklevel=1,
656+
)
618657

619658
# Non-integer charge and multiplicity
620659
#

0 commit comments

Comments
 (0)