/* Copyright (C) 2008 Jiri Pittner or This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef _DRT_H_ #define _DRT_H_ #include #include "vec.h" #include "gelfand.h" struct abcrow; struct ABCdelta { int a; int b; int c; const bool operator==(const ABCdelta &rhs) const {return !memcmp(this,&rhs,sizeof(ABCdelta));}; }; extern ABCdelta abcdelta[4]; struct abcrow { orbindex a; orbindex b; orbindex c; orbindex error;//compiler would pad the space anyway, use this as a bool flag const abcrow operator+(const ABCdelta &d) const; const abcrow operator-(const ABCdelta &d) const; const ABCdelta operator-(const abcrow &rhs) const; const bool operator>(const abcrow &rhs) const { if(a!=rhs.a) return a>rhs.a; if(b!=rhs.b) return b>rhs.b; if(c!=rhs.c) return c>rhs.c; return 0; }//might be done more efficiently const bool operator==(const abcrow &rhs) const { return a==rhs.a && b==rhs.b && c==rhs.c; //do not care about error (efficiency?) }; }; extern istream& operator>>(istream &s, abcrow &x); extern ostream& operator<<(ostream &s, const abcrow &x); class shavittpath; class drt; class paldustab : public NRVec { public: paldustab(): NRVec() {}; paldustab(const int n): NRVec(n) {}; paldustab(const paldustab &rhs) : NRVec(rhs) {}; explicit paldustab(const gelfpat &g); //generate paldus table from a gelfand one explicit paldustab(const shavittpath &s, const drt &d); //indexing from 1 abcrow & operator[](const int i) {return v[i-1];}; const abcrow & operator[](const int i) const {return v[i-1];}; const int orbnum() const {return nn;} //just alias to size const int electrons() const {return 2*v[nn-1].a+v[nn-1].b;} const int spin2() const {return v[nn-1].b;} void weight(gelfweight &w) const; //calculate its weight }; extern istream& operator>>(istream &s, paldustab &x); extern ostream& operator<<(ostream &s, const paldustab &x); //note - we might use iterators or STL lists, but let's do it simply the C way here //the chaining might be tricky and dependent on the implementation of iterator anyway struct drtentry { abcrow abc; lexindex lexx; lexindex lexy[4]; struct drtentry * upchain[4]; struct drtentry * downchain[4]; struct drtentry *next; drtentry() {memset(this,0,sizeof(drtentry));};//guarantee zero pointers drtentry(const abcrow&rhs) {memset(this,0,sizeof(drtentry)); abc=rhs;}; }; extern drtentry *findabc(const abcrow&abc, drtentry *list); class drt //copy constructor and assingment might be implemented if needed, using reference counting { int norb; struct drtentry **list; public: drt(): norb(0), list(NULL) {}; drt(const abcrow &toprow); ~drt(); const int orbnum() const {return norb;} const int electrons() const {return 2*list[norb]->abc.a+list[norb]->abc.b;} const int spin2() const {return list[norb]->abc.b;} struct drtentry **getlist() const {return list;} const struct drtentry * operator[](const int i) const {return list[i];} const lexindex cisize() const {return list[norb]->lexx;}; }; extern ostream& operator<<(ostream &s, const drt &d); typedef unsigned char stepnumber; //actually 2 bits per step are sufficient, some packing might be possible class shavittpath : public NRVec //note: 0-th element is the highest level - to facilitate lexicographic comparison { public: shavittpath() : NRVec () {}; shavittpath(const int n) : NRVec (n) {}; shavittpath(const shavittpath &rhs) : NRVec(rhs) {}; explicit shavittpath(const paldustab &p); void weight(gelfweight &w, const bool reversed=false) const; //calculate its weight //operator== inherited, comparisons are in lexicographic gelfand order const bool operator>(const shavittpath &rhs) const {return memcmp(v,rhs.v,nn*sizeof(stepnumber)) <0;}; const bool operator<(const shavittpath &rhs) const {return memcmp(v,rhs.v,nn*sizeof(stepnumber)) >0;}; const lexindex index(const drt &d) const; const int orbnum() const {return nn;}; }; extern ostream& operator<<(ostream &o, const shavittpath &s); //generation of all paths in the shavitt graph extern lexindex shavitt_gener(const drt &d, void (*process)(const shavittpath &)); //calculation of matrix elements of E's in the drt-shavitt path representation extern unsigned int E_from_DRT(Ugenerators &E, const drt &drt, const bool inverselex=false); //conversion of a CI vector from the drt==gelfand basis to slater determinants class slaterbasis : public NRMat { public: slaterbasis() : NRMat() {}; slaterbasis(const int n, const int m) : NRMat(n,m) {}; const NRVec range() const; bool checkzero() const; }; extern int compareslaterdet(const int n, const spinorbindex *x, const spinorbindex *y); class slaterdet : public NRVec { public: slaterdet() : NRVec() {}; slaterdet(const int nelec) : NRVec(nelec) {}; slaterdet(const slaterdet &rhs) : NRVec(rhs) {}; slaterdet(const spinorbindex *x, const int nelec) : NRVec(x,nelec) {}; int compare(const slaterdet &rhs); bool operator>(const slaterdet &rhs) {return compareslaterdet(nn,v,rhs.v)>0;}; bool operator<(const slaterdet &rhs) {return compareslaterdet(nn,v,rhs.v)<0;}; const int electrons() const {return nn;}; void sort(); //get orbital numbers in ascending order and alpha followed by beta for double occupation lexindex find(const slaterbasis &slbasis, const int order, const NRVec *slrange=NULL) const; //assuming already sorted, is not checked! //if ranges of allowed orbital numbers at different positions are available, interpolation search can be done }; //compute mutual excitation of two slater determinants, optionally assume that //the orbital indices (spinorbital up to a sign) are sorted in an ascending order extern int slater_excitation(const int nelec, const spinorbindex *bra, const spinorbindex *ket, const bool assumesorted,const spinorbindex norb=0); inline int slater_excitation(const slaterdet &bra, const slaterdet &ket, const bool assumesorted, const spinorbindex norb=0) { if(bra.size()!=ket.size()) return -1; return slater_excitation(bra.size(),(const spinorbindex *)bra, (const spinorbindex *)ket, assumesorted,norb); } extern ostream & operator<<(ostream &s, const slaterdet&x); extern int spinfunctions(std::list &list, const shavittpath &p, const drt &d); //note - we might precalculate the # of safs and replace the list by array extern const NRMat alphabeta(const int nsingles,const int nalpha); //generate permutations of alpha and beta spins (beta = 1, alpha =0) extern NRVec slaterdets(const shavittpath &p, const int nelectrons, const int spin2); //single conversion coefficient (if performance is needed, something could be saved by doing whole batch of slaterdets at once) extern REAL slatercoef(const shavittpath &p, const drt &d, const slaterdet &s); //generate little dense matrix of transformations from safs to dets for a fixed weight extern const NRMat safs_slater(std::list &list, const drt &d, const NRVec &slaters); //some sorting helpers for slater det basis sort extern SPMatindex *slsort_permbase; extern slaterbasis *slsort_sldetbase; extern int slsort_nelectrons; extern int slsort_slbascmp(int i, int j); extern int slsort_slbascmp2(int i, int j); extern void slsort_slbasswap(int i, int j); //a Slater determinant expressed by its alpha and beta string struct slater_in_strings { lexindex string[2]; //numbers of the alpha and beta string of the determinant in the tables of distinct strings int sign; //parity (+1,-1) of bringing its spinorbitals to the order alpha string, beta string }; //some necessary traits of the non-scalar class to be able to use LA methods template<> class LA::LA_traits { public: static bool is_plaindata() {return true;}; static void copyonwrite(slater_in_strings& x) {}; typedef REAL normtype; //binary put and get of NRVec: the struct is three 4-byte integers static void multiput(size_t n, int fd, const slater_in_strings *x, bool dimensions=0) {LA_traits::multiput(3*n,fd,(const int *)x,dimensions);} static void multiget(size_t n, int fd, slater_in_strings *x, bool dimensions=0) {LA_traits::multiget(3*n,fd,(int *)x,dimensions);} }; //split a list of Slater determinants into tables of the distinct alpha (spin 0) and beta (spin 1) strings //strings[spin]: nstrings x nelec[spin], orbital numbers >0 in ascending order, rows sorted lexicographically //(for no electrons of a spin the table is empty and all determinants have the string number 0) //returns for each determinant the numbers of its strings and the sign extern NRVec slaterstrings(const slaterbasis &slaters, NRMat (&strings)[2]); //@@@implement generation of DRT with limited excitation level for an external (bottom) part //@@@implement loop algorithm for two-body coupling constants, in a form suitable for integral-driven Hamilonian build or direct CI //@@@implement the import of the columbus truncated-CI drt //to make it independent on our little fci //if the import includes the lexy values, the index() should automatically work also for a general truncated CI //posssibly they store explicitly only "internal" part of DRT, take this into account... //generate sparse matrix for the whole CI vector trafo and the basis of slater dets //will we correctly generate all lex. paths from an imported drt? hope yes! //rows are in Slater basis, columns in Gelfand (DRT) basis extern const SparseMat CItrafo(const int slatlistfile, const drt &d, const int sortdirection=0, const bool inverselex=false); #endif