Skip to content

Commit

Permalink
Promolecule: add default multiplicities for non-int charge (#82) (#84)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored May 3, 2024
1 parent fed9fbc commit 581c50b
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions atomdb/promolecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,12 @@ def make_promolecule(

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

# Construct linear combination of species
promol = Promolecule()
Expand Down Expand Up @@ -615,6 +619,41 @@ def make_promolecule(
"of other species",
stacklevel=1,
)
# Non-integer charge, default multiplicity
if mult is None:
# get floor and ceiling charges
f_charge, c_charge = int(np.floor(charge)), int(np.ceil(charge))
fmult, cmult = MULTIPLICITIES[(atnum, f_charge)], MULTIPLICITIES[(atnum, c_charge)]
# get coefficients for linear combination
f_coeff = np.ceil(charge) - charge
c_coeff = charge - np.floor(charge)
# get corresponding species
try:
specie_f = load(
atom,
f_charge,
fmult,
dataset=dataset,
datapath=datapath,
remotepath=remotepath,
)
specie_c = load(
atom,
c_charge,
cmult,
dataset=dataset,
datapath=datapath,
remotepath=remotepath,
)
promol._extend((specie_f, specie_c), (coord, coord), (f_coeff, c_coeff))
continue
except FileNotFoundError:
warn(
"Unable to load species corresponding to `charge, mult`; "
"generating species via linear combination "
"of other species",
stacklevel=1,
)

# Non-integer charge and multiplicity
#
Expand Down

0 comments on commit 581c50b

Please sign in to comment.