public HoppingPair Clone() { HoppingPair p = new HoppingPair(left, right); p.hoppings.AddRange(hoppings.Select(x => x.Clone())); return(p); }
public bool Equals(HoppingPair a) { if (a == null) { return(false); } if (a.Left != Left || a.Right != Right) { return(false); } if (hoppings.Count != a.hoppings.Count) { Console.WriteLine("Wrong number of hoppings."); return(false); } foreach (HoppingValue v in Hoppings) { if (a.Contains(v) == false) { return(false); } } return(true); }
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); } }
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); }
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); } }