Code Monkey home page Code Monkey logo

Comments (1)

zerothi avatar zerothi commented on August 25, 2024

For orbital:

    def merge(self, other) -> Orbital:
        """ Merges two orbitals into one, with a preference of `self` """
        cls = self.__class__
        s = self.__getstate__()
        o = other.__getstate__()

        def inst_merge(typ, op):
            for k, v in s.items():
                if isinstance(v, typ):
                    s[k] = op(v, o[k])
        def key_merge(key, op):
            for k, v in s.items():
                if k == key:
                    s[k] = op(v, o[k])
        
        if isinstance(other, cls):
            inst_merge(float, max)
            # tag is defined for this orbital, no change
            key_merge("tag", lambda s, o: v if v else o)
            return cls(**s)

for atom

    def merge(self, other: Atom) -> Atom:
        """Merges two atoms into a single one, the calling atom will have precedence

        When merging there will be a couple of rules that will apply:

        1. When in doubt, the calling atom will have precedence.
        2. If the two atoms have the same `Z` value, they can be merged,
           otherwise, `self` will be returned *as-is*.
        3. The tag is only overwritten if not set.
        4. There is no way to decide which mass to choose. It will *always*
           take `self`.
        5. The orbitals requires explicit handling, the order will prefer
           `self`, but if there is more information in `other` those will
           be copied over.
        
        
        Parameters
        ----------
        other : Atom
            the other atom to merge into a single one
        """
        if self.Z != other.Z:
            return self
        mass = self.mass
        tag = self._tag or other._tag
        
        orbs = []
        for sorb in self:
            oorb = other[sorb.name()]
            if oorb is None:
                orbs.append(sorb)
                continue
            if isinstance(sorb, type(oorb)):
                # same type, now only check

from sisl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.