Here is a simple working example of connect function that helps to define hoppings.

    def crit(site1,site2):
        x,y,z =site1.pos-site2.pos
        if abs(z)==1 and y==0 and x==0:
            return True
        else:
            return False

    def connect(sys,crit):
        result=[]
        for site1 in sys.sites():
            for site2 in sys.sites():
                if crit(site1,site2):
                    result.append((site1,site2))
        return iter(result)

#example usage
    lead[connect(lead,crit)] = tz

It could be improved by reducing iterating only over i<j sites, but I do not know of simple way to code that.

Best wishes,
Sergey

On 10/07/15 16:25, Christoph Groth wrote:
Sergey wrote:

Yes, such function would be definitely useful. Sometimes, it is useful to play with some reasonable, but a bit ad-hoc hoppings. I propose that that the function "connect" must take a function name "crit" as an input parameter. Where "crit" is a function taking two sites as parameters, e.g.

crit(A,B):
    if norm(A-B) < 2   and  0<np.abs(A.pos[3] - B.pos[3])<1:
          return true
    else:
          return false

It could be nice to have an efficient realization of "connect" . Is there a way to do it faster than N^2 ?

I believe that it can be made something like O(N log N) by using an appropriate data structure, perhaps a k-d tree.

But it's clearly O(N^2) if crit is to be called for all pairs of sites. How about, instead of crit, having a function that returns all hoppings within some maximum distance. If you want to use crit, you can do something like this:

sys[ (hop for hop in connect(A, B) if crit(hop)) ] = value

Wouldn't that be the same as your suggestion, only more generic?

Christoph

Reply via email to