• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

adc-connect / adcc / 21177357553

20 Jan 2026 03:33PM UTC coverage: 74.598% (+0.3%) from 74.293%
21177357553

Pull #200

github

web-flow
Merge 3c14af03c into 9ff4abd52
Pull Request #200: Generalize OneParticleOperator to NParticleOperator and separate operators from densities

1270 of 2000 branches covered (63.5%)

Branch coverage included in aggregate %.

555 of 621 new or added lines in 22 files covered. (89.37%)

3 existing lines in 1 file now uncovered.

7787 of 10141 relevant lines covered (76.79%)

168782.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/adcc/OneParticleOperator.py
1
#!/usr/bin/env python3
2
## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
3
## ---------------------------------------------------------------------
4
##
5
## Copyright (C) 2019 by the adcc authors
6
##
7
## This file is part of adcc.
8
##
9
## adcc is free software: you can redistribute it and/or modify
10
## it under the terms of the GNU General Public License as published
11
## by the Free Software Foundation, either version 3 of the License, or
12
## (at your option) any later version.
13
##
14
## adcc is distributed in the hope that it will be useful,
15
## but WITHOUT ANY WARRANTY; without even the implied warranty of
16
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
## GNU General Public License for more details.
18
##
19
## You should have received a copy of the GNU General Public License
20
## along with adcc. If not, see <http://www.gnu.org/licenses/>.
21
##
22
## ---------------------------------------------------------------------
23
import libadcc
2✔
24

25
from .NParticleOperator import NParticleOperator, OperatorSymmetry
2✔
26
from .functions import einsum
2✔
27
from .MoSpaces import split_spaces
2✔
28

29

30
class OneParticleOperator(NParticleOperator):
2✔
31
    def __init__(self, spaces, symmetry=OperatorSymmetry.HERMITIAN):
2✔
32
        """
33
        Construct an OneParticleOperator object. All blocks are initialised
34
        as zero blocks.
35

36
        Parameters
37
        ----------
38
        spaces : adcc.MoSpaces or adcc.ReferenceState or adcc.LazyMp
39
            MoSpaces object
40

41
        symmetry : OperatorSymmetry, optional
42
        """
43
        super().__init__(spaces, n_particle_op=1, symmetry=symmetry)
2✔
44

45
    def _construct_empty(self):
2✔
46
        """
47
        Create an empty instance of an OneParticleOperator
48
        """
NEW
49
        return self.__class__(
×
50
            self.mospaces,
51
            symmetry=self.symmetry,
52
        )
53

54
    def _transform_to_ao(self, refstate):
2✔
55
        if not len(self.blocks_nonzero):
2✔
56
            raise ValueError("At least one non-zero block is needed to "
2✔
57
                             "transform the OneParticleOperator.")
58
        if isinstance(refstate, libadcc.ReferenceState):
2!
59

60
            coeff_map = {}
2✔
61
            for sp in self.orbital_subspaces:
2✔
62
                coeff_map[sp + "_a"] = refstate.orbital_coefficients_alpha(sp + "b")
2✔
63
                coeff_map[sp + "_b"] = refstate.orbital_coefficients_beta(sp + "b")
2✔
64
            ovlp = refstate.operators.overlap_ao
2✔
65
        else:
NEW
66
            raise TypeError("refstate needs to be an libadcc.ReferenceState.")
×
67

68
        dm_bb_a = 0
2✔
69
        dm_bb_b = 0
2✔
70

71
        for block in self.blocks_nonzero:
2✔
72
            # only canonical blocks
73
            s1, s2 = split_spaces(block)
2✔
74
            # (anti-)hermitian operators: scale off-diagonal block of operator
75
            # by 2 because only one of the blocks is actually present
76
            pref = self.canonical_factors[block]
2✔
77

78
            dm_bb_a += pref * einsum("lm,im,ij,jv,vs->ls",
2✔
79
                                     ovlp, coeff_map[f"{s1}_a"],
80
                                     self.block(block), coeff_map[f"{s2}_a"], ovlp)
81
            dm_bb_b += pref * einsum("lm,im,ij,jv,vs->ls",
2✔
82
                                     ovlp, coeff_map[f"{s1}_b"],
83
                                     self.block(block), coeff_map[f"{s2}_b"], ovlp)
84
        if self.symmetry == OperatorSymmetry.HERMITIAN:
2✔
85
            dm_bb_a = dm_bb_a.symmetrise()
2✔
86
            dm_bb_b = dm_bb_b.symmetrise()
2✔
87
        elif self.symmetry == OperatorSymmetry.ANTIHERMITIAN:
2✔
88
            dm_bb_a = dm_bb_a.antisymmetrise()
2✔
89
            dm_bb_b = dm_bb_b.antisymmetrise()
2✔
90
        return (dm_bb_a.evaluate(), dm_bb_b.evaluate())
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc