Exemplo n.º 1
0
        public HoppingPair Find(int left, int right)
        {
            HoppingPair retval = this.Find(x => x.Left == left && x.Right == right);

            if (retval == null)
            {
                HoppingPair p = this.Find(x => x.Right == left && x.Left == right);

                if (p == null)
                {
                    return(null);
                }

                // generate symmetric hopping if it doesn't exist.
                retval = new HoppingPair(left, right);

                for (int i = 0; i < p.Hoppings.Count; i++)
                {
                    HoppingValue v = new HoppingValue();
                    v.Value = p.Hoppings[i].Value;
                    v.R     = -p.Hoppings[i].R;

                    retval.Hoppings.Add(v);
                }

                this.Add(retval);
            }

            return(retval);
        }
Exemplo n.º 2
0
            void ReadHoppingsSection()
            {
                if (tb.hoppings != null)
                {
                    ThrowEx("Multiple hoppings sections found.");
                }

                if (LineType != LineType.NewSubSection)
                {
                    ThrowEx("Hoppings section must start with :..: delimited section.");
                }

                tb.hoppings = new HoppingPairList();

                while (!EOF && LineType != LineType.NewSection)
                {
                    string[] values = ReadSubSectionParameters();

                    int left  = int.Parse(values[0]) - 1;
                    int right = int.Parse(values[1]) - 1;

                    HoppingPair p = new HoppingPair(left, right);
                    tb.hoppings.Add(p);

                    //Output.WriteLine("Reading hoppings for {0}-{1}", left + 1, right + 1);

                    ReadNextLine();

                    while (LineType == LineType.Hopping || LineType == LineType.Numeric)
                    {
                        List <string> vals = new List <string>();
                        vals.AddRange(Line.Replace('\t', ' ').Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));

                        if (vals[0] == "T=")
                        {
                            vals.RemoveAt(0);
                        }
                        if (vals[3] == "hop=")
                        {
                            vals.RemoveAt(3);
                        }

                        double value = double.Parse(vals[vals.Count - 1]);

                        Vector3 loc = new Vector3(double.Parse(vals[0]), double.Parse(vals[1]), double.Parse(vals[2]));

                        HoppingValue v = new HoppingValue();
                        v.Value = value;
                        v.R     = loc;

                        p.Hoppings.Add(v);

                        ReadNextLine();
                    }

                    //Output.WriteLine("Count: {0}", p.Hoppings.Count);
                }
            }
Exemplo n.º 3
0
        public bool Contains(HoppingValue val)
        {
            foreach (HoppingValue a in Hoppings)
            {
                if (a.Value != val.Value)
                {
                    continue;
                }
                if ((a.R - val.R).Magnitude > 1e-6)
                {
                    continue;
                }

                //Console.WriteLine("hop: {0} {1} {2} {3}",
                //                  a.Value, a.BravaisVector,
                //                  val.Value, val.BravaisVector);
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public Matrix CalcHamiltonian(Vector3 kpt)
        {
            Matrix m = new Matrix(Orbitals.Count, Orbitals.Count);

            kpt *= 2 * Math.PI;

            for (int i = 0; i < Orbitals.Count; i++)
            {
                for (int j = 0; j < Orbitals.Count; j++)
                {
                    HoppingPair p = Hoppings.FindOrThrow(i, j);

                    Complex val = new Complex();

                    for (int k = 0; k < p.Hoppings.Count; k++)
                    {
                        HoppingValue hop = p.Hoppings[k];
                        Vector3      R   = hop.R;

                        Complex newval = hop.Value *
                                         Complex.Exp(new Complex(0, kpt.DotProduct(R)));

                        val += newval;
                    }

                    m[i, j] = val;
                }
            }

            if (m.IsHermitian == false)
            {
                throw new Exception("Hamiltonian at k = " + kpt.ToString() + " is not Hermitian.");
            }

            return(m);
        }
Exemplo n.º 5
0
            void ApplySymmetries()
            {
                List <Matrix> validSyms = new List <Matrix>();
                Matrix        reduce    = new Matrix(3, 3);

                reduce.SetRows(tb.lattice.G1, tb.lattice.G2, tb.lattice.G3);
                int symIndex = 0;

                using (StreamWriter s = new StreamWriter("syms"))
                {
                    foreach (var sym in GetPossibleSymmetries())
                    {
                        symIndex++;
                        s.WriteLine();
                        s.WriteLine("Applying symmetry " + symIndex.ToString() + ":");
                        s.WriteLine(sym);

                        Matrix lat = new Matrix(3, 3);
                        lat.SetColumns(sym * tb.lattice.A1, sym * tb.lattice.A2, sym * tb.lattice.A3);

                        lat = reduce * lat;

                        s.WriteLine("Lattice vector test...");
                        if (CheckLatticeSymmetry(lat) == false)
                        {
                            goto fail;
                        }

                        Dictionary <int, int> sitemap = new Dictionary <int, int>();

                        s.WriteLine("Generating site map...");

                        for (int i = 0; i < tb.sites.Count; i++)
                        {
                            var     site = tb.sites[i];
                            Vector3 loc  = sym * site.Location;

                            int index = tb.Orbitals.FindIndex(tb.lattice, loc);

                            if (index == -1)
                            {
                                s.WriteLine("Failed to map site " + i.ToString());
                                goto fail;
                            }

                            sitemap[i] = index;
                            s.WriteLine("  " + i.ToString() + " => " + index.ToString());
                        }

                        HoppingPairList newHops = new HoppingPairList();

                        // rotate hoppings
                        for (int i = 0; i < tb.hoppings.Count; i++)
                        {
                            var pair = tb.hoppings[i];

                            int newleft  = sitemap[pair.Left];
                            int newright = sitemap[pair.Right];

                            HoppingPair newPair = new HoppingPair(newleft, newright);
                            newHops.Add(newPair);

                            foreach (var hop in pair.Hoppings)
                            {
                                HoppingValue v = new HoppingValue();
                                v.Value = hop.Value;
                                v.R     = sym * hop.R;

                                newPair.Hoppings.Add(v);
                            }
                        }

                        s.WriteLine("Performing hopping test...");
                        if (newHops.Equals(tb.hoppings) == false)
                        {
                            goto fail;
                        }

                        s.WriteLine("Success.");
                        validSyms.Add(sym);
                        continue;

fail:
                        s.WriteLine("Failed.");
                    }

                    // now apply symmetries to reduce k-points in kmesh
                    int initialKptCount = tb.kmesh.Kpts.Count;

                    System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                    watch.Start();

                    foreach (var sym in validSyms)
                    {
                        for (int i = 0; i < tb.kmesh.Kpts.Count; i++)
                        {
                            KPoint  kpt   = tb.kmesh.Kpts[i];
                            Vector3 trans = kpt.Value;

                            /*
                             * for (int j = 0; j < 3; j++)
                             * {
                             *      trans = sym * trans;
                             *
                             *      int index = kmesh.IndexOf(trans, i+1);
                             *
                             *      if (index == -1)
                             *              continue;
                             *
                             *      kmesh.Kpts.RemoveAt(index);
                             *      kpt.Weight ++;
                             *
                             * }
                             */
                        }
                    }
                    watch.Stop();

                    string fmt = string.Format("{0} total kpts, {1} irreducible kpts.  Applying symmetries took {2} seconds.",
                                               initialKptCount, tb.kmesh.Kpts.Count, watch.ElapsedMilliseconds / 1000);

                    Output.WriteLine(fmt);
                    s.WriteLine(fmt);
                }
            }
Exemplo n.º 6
0
 public bool Equals(HoppingValue v)
 {
     return(Math.Abs(Value - v.Value) < 1e-6 &&
            (R - v.R).Magnitude < 1e-6);
 }