Beispiel #1
0
        public bool Equals(HoppingPairList a)
        {
            if (a.Count != Count)
            {
                Console.WriteLine("Failed count test.");
                return(false);
            }

            foreach (var pair in this)
            {
                HoppingPair other = a.Find(pair.Left, pair.Right);

                if (other == null)
                {
                    Console.WriteLine("Failed to find match.");
                    return(false);
                }
                if (pair.Equals(other) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        public HoppingPairList Clone()
        {
            HoppingPairList hops = new HoppingPairList();

            hops.AddRange(this.Select(x => x.Clone()));

            return(hops);
        }
Beispiel #3
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);
                }
            }