Skip to content

Commit c8aff1f

Browse files
committed
Add special case for intensive properties with zero-electron components
1 parent 8f4628b commit c8aff1f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

atomdb/promolecule.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def nspin(self, p=1):
248248
def f(atom):
249249
return atom.nspin
250250

251-
return _intensive_property(self.atoms, self.coeffs, f, p=1)
251+
return _intensive_property_exclude_zero(self.atoms, self.coeffs, f, p=1)
252252

253253
def mult(self, p=1):
254254
r"""Compute the multiplicity of the promolecule.
@@ -787,6 +787,32 @@ def _intensive_property(atoms, coeffs, f, p=1):
787787
)
788788

789789

790+
def _intensive_property_exclude_zero(atoms, coeffs, f, p=1):
791+
r"""Helper function for computing intensive properties (excluding zero-electron proatoms).
792+
793+
Parameters
794+
----------
795+
atoms: list of Species
796+
Species instances.
797+
coeffs: np.ndarray((N,), dtype=float)
798+
Coefficients of each species.
799+
f: callable
800+
Property function.
801+
p: int, default=1 (linear mean)
802+
Type of mean used in the computation.
803+
804+
Returns
805+
-------
806+
prop: float
807+
Intensive property.
808+
"""
809+
# P-mean of each atom's property value
810+
return (
811+
sum(coeff * f(atom) ** p for atom, coeff in zip(atoms, coeffs) if atom.nelec != 0)
812+
/ sum(coeff for atom, coeff in zip(atoms, coeffs) if atom.nelec != 0) ** (1 / p)
813+
)
814+
815+
790816
def _radial_vector_outer_triu(radii):
791817
r"""Evaluate the outer products of a set of radial unit vectors.
792818

0 commit comments

Comments
 (0)