Skip to content

Commit

Permalink
add a normalizer function for the AtomCenteredFunction to handle comb…
Browse files Browse the repository at this point in the history
…ined orbital types
  • Loading branch information
EBB2675 committed Nov 28, 2024
1 parent 9ef13ea commit 80c8b64
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions src/nomad_simulations/schema_packages/basis_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class AtomCenteredFunction(ArchiveSection):
Specifies a single function (term) in an atom-centered basis set.
"""

basis_type = Quantity(
harmonic_type = Quantity(
type=MEnum(
'spherical',
'cartesian',
Expand All @@ -202,7 +202,9 @@ class AtomCenteredFunction(ArchiveSection):
)

function_type = Quantity(
type=MEnum('s', 'p', 'd', 'f', 'g', 'h', 'i', 'j', 'k', 'l'),
type=MEnum('s', 'p', 'd', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'sp', 'spd', 'spdf',
),
description="""
L=a+b+c
The angular momentum of GTO to be added.
Expand All @@ -227,7 +229,7 @@ class AtomCenteredFunction(ArchiveSection):

contraction_coefficients = Quantity(
type=np.float32,
shape=['n_primitive'],
shape=['*'], # Flexible shape to handle combined types (e.g. SP, SPD..)
description="""
List of contraction coefficients corresponding to the exponents.
""",
Expand All @@ -241,20 +243,51 @@ class AtomCenteredFunction(ArchiveSection):
)

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
"""
Validates the input data
and resolves combined types like SP, SPD, SPDF, etc.
Raises ValueError: If the data is inconsistent (e.g., mismatch in exponents and coefficients).
"""
super().normalize(archive, logger)

# Validation: Check that n_primitive matches the lengths of exponents and contraction coefficients
# Validate number of primitives
if self.n_primitive is not None:
if self.exponents is not None and len(self.exponents) != self.n_primitive:
raise ValueError(
f'Mismatch in number of exponents: expected {self.n_primitive}, found {len(self.exponents)}.'
f"Mismatch in number of exponents: expected {self.n_primitive}, "
f"found {len(self.exponents)}."
)
if (
self.contraction_coefficients is not None
and len(self.contraction_coefficients) != self.n_primitive
):

# Resolve combined types
if self.function_type and len(self.function_type) > 1:
num_types = len(self.function_type) # For SP: 2, SPD: 3, etc.
if self.contraction_coefficients is not None:
expected_coeffs = num_types * self.n_primitive
if len(self.contraction_coefficients) != expected_coeffs:
raise ValueError(
f"Mismatch in contraction coefficients for {self.function_type} type: "
f"expected {expected_coeffs}, found {len(self.contraction_coefficients)}."
)

# Split coefficients into separate lists for each type
self.coefficient_sets = {
t: self.contraction_coefficients[i::num_types]
for i, t in enumerate(self.function_type)
}

# Debug: Log split coefficients
for t, coeffs in self.coefficient_sets.items():
logger.info(f"{t}-type coefficients: {coeffs}")
else:
logger.warning(f"No contraction coefficients provided for {self.function_type} type.")

# For single types, ensure coefficients match primitives
elif self.contraction_coefficients is not None:
if len(self.contraction_coefficients) != self.n_primitive:
raise ValueError(
f'Mismatch in number of contraction coefficients: expected {self.n_primitive}, found {len(self.contraction_coefficients)}.'
f"Mismatch in contraction coefficients: expected {self.n_primitive}, "
f"found {len(self.contraction_coefficients)}."
)


Expand Down Expand Up @@ -295,6 +328,11 @@ class AtomCenteredBasisSet(BasisSetComponent):
""",
)

total_number_of_basis_functions = Quantity(
type=np.int32,
description="",
)

functional_composition = SubSection(
sub_section=AtomCenteredFunction.m_def, repeats=True
)
Expand Down

1 comment on commit 80c8b64

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py15287%39–41
   atoms_state.py19012932%13–15, 159–179, 197–232, 245–276, 279–297, 344–355, 358–372, 491–506, 518–526, 529–550, 608–615, 627–634, 637–643
   basis_set.py26717036%8–9, 78–79, 115–119, 122–133, 162–165, 168–169, 172–185, 252–288, 341, 395, 401–402, 406–410, 421–425, 429–433, 437–458, 466, 501–512, 516–528, 548–549, 584–597, 601, 606–607, 644–652, 661, 693–720, 726–731, 734–749, 778–829
   general.py894253%4–7, 51–54, 121, 185, 214–216, 228–286, 289–311
   model_method.py26915443%10–12, 73, 92, 125, 171–174, 177–184, 276–277, 297, 318–339, 355–381, 384–401, 493, 516–559, 562–587, 637–645, 704–706, 732–753, 756–762, 780, 791, 833–840, 878, 897, 977, 1034, 1109, 1223
   model_system.py34822037%45–51, 207–215, 219–225, 234–236, 243, 246, 250, 254, 258, 261, 264, 273–282, 286–291, 374–377, 381, 385, 389, 393, 397, 401, 404, 449–455, 466–475, 489–520, 531–548, 551–554, 685–712, 730–812, 815–831, 897–901, 904–925, 1131–1169, 1172–1211
   numerical_settings.py27820128%12–14, 36, 131–134, 204–210, 238–254, 276–347, 437–457, 473–488, 507–529, 532–559, 624–645, 657–673, 695–725, 743–805, 808–829, 855–857, 872–890, 893–898, 952, 974
   outputs.py1206843%9–10, 153–159, 169–173, 183–187, 190–198, 241–259, 276–309, 312–329, 362, 381
   physical_property.py1024952%20–22, 46–62, 200–202, 223, 235–238, 251, 258, 265–291, 301–303, 306–309, 331–333
   variables.py862176%8–10, 63–70, 73–76, 98, 121, 145, 167, 189, 211, 233, 256, 272–273, 276
src/nomad_simulations/schema_packages/properties
   band_gap.py513237%8–10, 79–92, 104–126, 129–144
   band_structure.py1237638%9–11, 53–55, 58, 131–132, 144–159, 174–199, 209–218, 232–265, 274–286, 289–308, 321–322, 325, 372–373, 378
   energies.py421857%7–9, 36, 57, 77–79, 82, 99–100, 103, 115–116, 119, 130–131, 134
   fermi_surface.py17759%7–9, 34–37, 40
   forces.py22864%7–9, 36, 56, 75–76, 79
   greens_function.py995247%7–9, 135–137, 149–179, 182–189, 210–211, 214, 235–236, 239, 260–261, 264, 349–355, 365–367, 376–384, 387–403
   hopping_matrix.py291162%7–9, 50–53, 58, 88–91, 94
   permittivity.py483233%7–9, 53–56, 59–62, 71–94, 97–105
   spectral_profile.py26021517%9–11, 39–40, 49–51, 54–60, 80, 94–106, 109–112, 176–177, 199–300, 313–345, 356–368, 382–400, 415–463, 466–502, 521–523, 526, 555–557, 568–593, 598–604
   thermodynamics.py752764%7–9, 35, 56, 72, 81, 90, 101, 110, 137, 147, 157, 172–174, 177, 193, 213–215, 218, 234, 254–256, 259
src/nomad_simulations/schema_packages/utils
   utils.py795629%8–11, 48–58, 65–74, 78–84, 87–92, 96, 100, 117–122, 139–145, 154–156, 165–170
TOTAL2635159440% 

Tests Skipped Failures Errors Time
1 0 💤 0 ❌ 1 🔥 1.296s ⏱️

Please sign in to comment.