Skip to content

Commit

Permalink
a placeholder for MO and LCAO
Browse files Browse the repository at this point in the history
  • Loading branch information
EBB2675 committed Dec 11, 2024
1 parent c9d6118 commit 816c7ba
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 22 deletions.
171 changes: 171 additions & 0 deletions src/nomad_simulations/schema_packages/model_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,164 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)


class MolecularOrbital(ArchiveSection):
"""
A section representing a single molecular orbital.
"""

energy = Quantity(
type=np.float64,
# unit='electron_volt',
description='Energy of the molecular orbital.',
)

occupation = Quantity(
type=np.float64, description='Occupation number of the molecular orbital.'
)

symmetry_label = Quantity(
type=str, description='Symmetry label of the molecular orbital.'
)

reference_orbital = SubSection(
sub_section=OrbitalsState.m_def,
description='Reference to the underlying atomic orbital state.',
)


class LCAO(ArchiveSection):
"""
A base class for molecular orbital schemes used in quantum chemistry calculations.
Supports unrestricted (UHF, UKS), restricted (RHF, RKS), and restricted open-shell (ROHF, ROKS) schemes.
"""

reference_type = Quantity(
type=MEnum('RHF', 'ROHF', 'UHF', 'RKS', 'ROKS', 'UKS'),
description="""
Specifies the type of reference wavefunction:
- RHF: Restricted Hartree-Fock
- ROHF: Restricted Open-Shell Hartree-Fock
- UHF: Unrestricted Hartree-Fock
- RKS: Restricted Kohn-Sham
- ROKS: Restricted Open-Shell Kohn-Sham
- UKS: Unrestricted Kohn-Sham
""",
a_eln=ELNAnnotation(component='EnumEditQuantity'),
)

orbital_set = Quantity(
type=MEnum('canonical', 'natural', 'localized'),
description="""
Specifies the type of orbitals used in the molecular orbital scheme:
- canonical: Default canonical molecular orbitals.
- natural: Natural orbitals obtained from the density matrix.
- localized: Localized orbitals such as Boys or Foster-Boys localization.
TODO: this will be later connected to many other things.
""",
a_eln=ELNAnnotation(component='EnumEditQuantity'),
)

n_alpha_electrons = Quantity(
type=np.int32,
description="""
Number of alpha electrons (spin up) in the molecular system.
""",
)

n_beta_electrons = Quantity(
type=np.int32,
description="""
Number of beta electrons (spin down) in the molecular system.
""",
)

n_molecular_orbitals = Quantity(
type=np.int32,
description="""
Total number of molecular orbitals in the system.
""",
)

molecular_orbitals = SubSection(
sub_section=MolecularOrbital.m_def,
repeats=True,
description="""
Detailed information about each molecular orbital,
including energy, occupation, and symmetry label.
""",
)

total_spin = Quantity(
type=np.float64,
description="""
Total spin of the system defined as S = (n_alpha_electrons - n_beta_electrons) / 2.
Connect to the model system.
""",
)

spin_multiplicity = Quantity(
type=np.int32,
description="""
Spin multiplicity of the system defined as 2S + 1.
""",
)

def resolve_spin_properties(self, logger: 'BoundLogger') -> None:
"""
Resolves the total spin and spin multiplicity of the system based on alpha and beta electrons.
"""
if self.n_alpha_electrons is not None and self.n_beta_electrons is not None:
self.total_spin = (self.n_alpha_electrons - self.n_beta_electrons) / 2
self.spin_multiplicity = int(2 * self.total_spin + 1)

def validate_scheme(self, logger: 'BoundLogger') -> bool:
"""
Validates the consistency of the molecular orbital scheme.
Returns:
(bool): True if the scheme is consistent, False otherwise.
"""
if self.reference_type in ['RHF', 'RKS']:
if self.n_alpha_electrons != self.n_beta_electrons:
logger.error(
f'For {self.reference_type}, the number of alpha and beta electrons must be equal.'
)
return False
if self.reference_type in ['ROHF', 'ROKS']:
if abs(self.n_alpha_electrons - self.n_beta_electrons) != 1:
logger.error(
f'For {self.reference_type}, there must be exactly one unpaired electron.'
)
return False
return True

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)

# Resolve spin properties
self.resolve_spin_properties(logger)

# Validate the molecular orbital scheme
if not self.validate_scheme(logger):
logger.error('Invalid molecular orbital scheme.')

# Resolve the number of molecular orbitals
if self.n_molecular_orbitals is None and self.molecular_orbitals:
self.n_molecular_orbitals = len(self.molecular_orbitals)

# Validate molecular orbital occupation
total_occupation = sum(
orbital.occupation
for orbital in self.molecular_orbitals
if orbital.occupation is not None
)
expected_occupation = self.n_alpha_electrons + self.n_beta_electrons
if total_occupation != expected_occupation:
logger.warning(
f'The total occupation ({total_occupation}) does not match the expected value ({expected_occupation}).'
)


class GTOIntegralDecomposition(BaseModelMethod):
"""
A general class for integral decomposition techniques for Coulomb and exchange integrals.
Expand Down Expand Up @@ -1253,6 +1411,19 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)


class HartreeFock(ModelMethodElectronic):
"""
A base section for Hartree Fock ansatz.
"""

reference_determinant = Quantity(
type=MEnum('UHF', 'RHF', 'ROHF', 'UKS', 'RKS', 'ROKS'),
description="""
the type of reference determinant.
""",
)


class PerturbationMethod(ModelMethodElectronic):
type = Quantity(
type=MEnum('MP', 'RS', 'BW'),
Expand Down
22 changes: 0 additions & 22 deletions src/nomad_simulations/schema_packages/numerical_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,25 +980,3 @@ class OrbitalLocalization(SelfConsistency):

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)


class GTOIntegralDecomposition(NumericalSettings):
"""
A general class for integral decomposition techniques for Coulomb and exchange integrals.
Examples:
Resolution of identity (RI-approximation):
RI
RIJK
....
Chain-of-spheres (COSX) algorithm for exchange: doi:10.1016/j.chemphys.2008.10.036
"""

approximation_type = Quantity(
type=str,
description="""
RIJ, RIK, RIJK,
""",
)

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)

2 comments on commit 816c7ba

@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.py1902189%13–15, 201–204, 228, 283–284, 352–353, 355, 537, 549–550, 611–615, 630–634, 641
   basis_set.py2674085%8–9, 122–133, 172–185, 275–302, 536–540, 562–563, 607–610, 729, 760, 762
   general.py89891%4–7, 121, 185, 295–296, 306
   model_method.py32110169%10–12, 171–174, 177–184, 276–277, 297, 318–339, 355–381, 384–401, 587, 780, 791, 833–840, 878, 897, 977, 1034, 1109, 1223, 1332–1334, 1343–1355, 1358–1379, 1411
   model_system.py3503789%45–51, 235, 254, 258, 261, 264, 290, 376–377, 454–455, 472–473, 686–689, 736–743, 917–918, 1155–1159, 1165–1166, 1174–1175, 1180, 1203
   numerical_settings.py2806776%12–14, 204–210, 280, 282–283, 286–289, 293–294, 301–304, 313–316, 320–323, 325–328, 333–336, 342–345, 532–559, 634, 669–672, 696, 699, 744, 746–749, 753, 757, 804, 808–829, 884–885, 952, 982
   outputs.py1201092%9–10, 252–255, 295–298, 323, 325, 362, 381
   physical_property.py102793%20–22, 202, 331–333
   variables.py861286%8–10, 98, 121, 145, 167, 189, 211, 233, 256, 276
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%8–10, 135–136
   band_structure.py1232580%9–11, 232–265, 278, 285, 321–322, 325, 372–373, 378
   energies.py42979%7–9, 36, 57, 82, 103, 119, 134
   fermi_surface.py17476%7–9, 40
   forces.py22673%7–9, 36, 56, 79
   greens_function.py991387%7–9, 210–211, 214, 235–236, 239, 260–261, 264, 400
   hopping_matrix.py29583%7–9, 58, 94
   permittivity.py48883%7–9, 97–105
   spectral_profile.py26012851%9–11, 57–60, 95–98, 199–300, 356–368, 393–396, 416, 421–424, 466–502, 526, 573–576, 592–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.py791680%8–11, 65–74, 83–84, 89, 92, 169–170
TOTAL269155579% 

Tests Skipped Failures Errors Time
423 0 💤 0 ❌ 0 🔥 6.719s ⏱️

@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.py1902189%13–15, 201–204, 228, 283–284, 352–353, 355, 537, 549–550, 611–615, 630–634, 641
   basis_set.py2674085%8–9, 122–133, 172–185, 275–302, 536–540, 562–563, 607–610, 729, 760, 762
   general.py89891%4–7, 121, 185, 295–296, 306
   model_method.py32110169%10–12, 171–174, 177–184, 276–277, 297, 318–339, 355–381, 384–401, 587, 780, 791, 833–840, 878, 897, 977, 1034, 1109, 1223, 1332–1334, 1343–1355, 1358–1379, 1411
   model_system.py3503789%45–51, 235, 254, 258, 261, 264, 290, 376–377, 454–455, 472–473, 686–689, 736–743, 917–918, 1155–1159, 1165–1166, 1174–1175, 1180, 1203
   numerical_settings.py2806776%12–14, 204–210, 280, 282–283, 286–289, 293–294, 301–304, 313–316, 320–323, 325–328, 333–336, 342–345, 532–559, 634, 669–672, 696, 699, 744, 746–749, 753, 757, 804, 808–829, 884–885, 952, 982
   outputs.py1201092%9–10, 252–255, 295–298, 323, 325, 362, 381
   physical_property.py102793%20–22, 202, 331–333
   variables.py861286%8–10, 98, 121, 145, 167, 189, 211, 233, 256, 276
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%8–10, 135–136
   band_structure.py1232580%9–11, 232–265, 278, 285, 321–322, 325, 372–373, 378
   energies.py42979%7–9, 36, 57, 82, 103, 119, 134
   fermi_surface.py17476%7–9, 40
   forces.py22673%7–9, 36, 56, 79
   greens_function.py991387%7–9, 210–211, 214, 235–236, 239, 260–261, 264, 400
   hopping_matrix.py29583%7–9, 58, 94
   permittivity.py48883%7–9, 97–105
   spectral_profile.py26012851%9–11, 57–60, 95–98, 199–300, 356–368, 393–396, 416, 421–424, 466–502, 526, 573–576, 592–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.py791680%8–11, 65–74, 83–84, 89, 92, 169–170
TOTAL269155579% 

Tests Skipped Failures Errors Time
423 0 💤 0 ❌ 0 🔥 7.191s ⏱️

Please sign in to comment.