50 for (
int cnt=0; cnt<
L; cnt++){
51 assert( OrbIrreps[cnt]>=0 );
52 assert( OrbIrreps[cnt]<nIrreps );
71 orb2irrep.reset(
new int[L]);
72 orb2indexSy.reset(
new int[L]);
73 int nIrreps = SymmInfo.getNumberOfIrreps();
74 irrep2num_orb.reset(
new int[nIrreps]);
76 memcpy(orb2irrep.get(), orig.
orb2irrep.get(),
sizeof(int)*L);
77 memcpy(orb2indexSy.get(), orig.
orb2indexSy.get(),
sizeof(int)*L);
78 memcpy(irrep2num_orb.get(), orig.
irrep2num_orb.get(),
sizeof(int)*nIrreps);
91 orb2irrep.reset(
new int[L]);
92 orb2indexSy.reset(
new int[L]);
93 int nIrreps = SymmInfo.getNumberOfIrreps();
94 irrep2num_orb.reset(
new int[nIrreps]);
96 memcpy(orb2irrep.get(), orig.
orb2irrep.get(),
sizeof(int)*L);
97 memcpy(orb2indexSy.get(), orig.
orb2indexSy.get(),
sizeof(int)*L);
98 memcpy(irrep2num_orb.get(), orig.
irrep2num_orb.get(),
sizeof(int)*nIrreps);
108 CreateAndFillFromPsi4dump( file_psi4text );
117 CreateAndFillFromH5( main_file, file_tmat, file_vmat );
119 CreateAndFillFromPsi4dump( main_file );
148 assert( orb2irrep[index1]==orb2irrep[index2] );
149 Tmat->set(orb2irrep[index1], orb2indexSy[index1], orb2indexSy[index2], val);
155 if (orb2irrep[index1]==orb2irrep[index2]){
156 return Tmat->get(orb2irrep[index1], orb2indexSy[index1], orb2indexSy[index2]);
166 Vmat->set(orb2irrep[index1], orb2irrep[index2], orb2irrep[index3], orb2irrep[index4], orb2indexSy[index1], orb2indexSy[index2], orb2indexSy[index3], orb2indexSy[index4], val);
173 Vmat->add(orb2irrep[index1], orb2irrep[index2], orb2irrep[index3], orb2irrep[index4], orb2indexSy[index1], orb2indexSy[index2], orb2indexSy[index3], orb2indexSy[index4], val);
180 return Vmat->get(orb2irrep[index1], orb2irrep[index2], orb2irrep[index3], orb2irrep[index4], orb2indexSy[index1], orb2indexSy[index2], orb2indexSy[index3], orb2indexSy[index4]);
189 Tmat->save(file_tmat);
190 Vmat->save(file_vmat);
193 hid_t file_id = H5Fcreate(file_parent.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
196 hid_t group_id = H5Gcreate(file_id,
"/Data", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
199 hsize_t dimarray = 1;
200 hid_t dataspace_id = H5Screate_simple(1, &dimarray, NULL);
201 hid_t dataset_id = H5Dcreate(group_id,
"L", H5T_STD_I32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
202 H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &L);
205 hsize_t dimarray2 = 1;
206 hid_t dataspace_id2 = H5Screate_simple(1, &dimarray2, NULL);
207 hid_t dataset_id2 = H5Dcreate(group_id,
"nGroup", H5T_STD_I32LE, dataspace_id2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
208 int nGroup = SymmInfo.getGroupNumber();
209 H5Dwrite(dataset_id2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nGroup);
212 hsize_t dimarray3 = L;
213 hid_t dataspace_id3 = H5Screate_simple(1, &dimarray3, NULL);
214 hid_t dataset_id3 = H5Dcreate(group_id,
"orb2irrep", H5T_STD_I32LE, dataspace_id3, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
215 H5Dwrite(dataset_id3, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, orb2irrep.get());
218 hsize_t dimarray4 = 1;
219 hid_t dataspace_id4 = H5Screate_simple(1, &dimarray4, NULL);
220 hid_t dataset_id4 = H5Dcreate(group_id,
"Econst", H5T_IEEE_F64LE, dataspace_id4, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
221 H5Dwrite(dataset_id4, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &Econst);
223 H5Dclose(dataset_id);
224 H5Sclose(dataspace_id);
225 H5Dclose(dataset_id2);
226 H5Sclose(dataspace_id2);
227 H5Dclose(dataset_id3);
228 H5Sclose(dataspace_id3);
229 H5Dclose(dataset_id4);
230 H5Sclose(dataspace_id4);
240 Tmat->read(file_tmat);
241 Vmat->read(file_vmat);
244 hid_t file_id = H5Fopen(file_parent.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
247 hid_t group_id = H5Gopen(file_id,
"/Data",H5P_DEFAULT);
250 hid_t dataset_id1 = H5Dopen(group_id,
"L", H5P_DEFAULT);
252 H5Dread(dataset_id1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &Lagain);
256 hid_t dataset_id2 = H5Dopen(group_id,
"nGroup", H5P_DEFAULT);
258 H5Dread(dataset_id2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nGroup);
259 assert( nGroup==SymmInfo.getGroupNumber() );
262 hid_t dataset_id3 = H5Dopen(group_id,
"orb2irrep", H5P_DEFAULT);
263 int * orb2irrepAgain =
new int[L];
264 H5Dread(dataset_id3, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, orb2irrepAgain);
265 for (
int cnt=0; cnt<L; cnt++){
266 assert( orb2irrep[cnt]==orb2irrepAgain[cnt] );
268 delete [] orb2irrepAgain;
271 hid_t dataset_id4 = H5Dopen(group_id,
"Econst", H5P_DEFAULT);
272 H5Dread(dataset_id4, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &Econst);
274 H5Dclose(dataset_id1);
275 H5Dclose(dataset_id2);
276 H5Dclose(dataset_id3);
277 H5Dclose(dataset_id4);
290 hid_t file_id = H5Fopen(file_parent.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
293 hid_t group_id = H5Gopen(file_id,
"/Data",H5P_DEFAULT);
296 hid_t dataset_id1 = H5Dopen(group_id,
"L", H5P_DEFAULT);
297 H5Dread(dataset_id1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &L);
300 hid_t dataset_id2 = H5Dopen(group_id,
"nGroup", H5P_DEFAULT);
302 H5Dread(dataset_id2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nGroup_LOADH5);
303 SymmInfo.setGroup( nGroup_LOADH5 );
306 hid_t dataset_id5 = H5Dopen(group_id,
"nelectrons", H5P_DEFAULT);
307 H5Dread(dataset_id5, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &Ne);
310 hid_t dataset_id3 = H5Dopen(group_id,
"orb2irrep", H5P_DEFAULT);
311 orb2irrep.reset(
new int[L]);
312 H5Dread(dataset_id3, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, orb2irrep.get());
314 H5Dclose(dataset_id1);
315 H5Dclose(dataset_id2);
316 H5Dclose(dataset_id3);
317 H5Dclose(dataset_id5);
323 orb2indexSy.reset(
new int[L]);
324 int nIrreps = SymmInfo.getNumberOfIrreps();
325 irrep2num_orb.reset(
new int[nIrreps]);
327 for (
int irrep = 0; irrep < nIrreps; irrep++){ irrep2num_orb[ irrep ] = 0; }
328 for (
int orb = 0; orb < L; orb++){
329 orb2indexSy[ orb ] = irrep2num_orb[ orb2irrep[ orb ] ];
330 irrep2num_orb[ orb2irrep[ orb ] ]++;
333 Tmat.reset(
new TwoIndex(SymmInfo.getGroupNumber(),irrep2num_orb.get()));
334 Vmat.reset(
new FourIndex(SymmInfo.getGroupNumber(),irrep2num_orb.get()));
336 read(file_parent, file_tmat, file_vmat);
346 ifstream inputfile(filename.c_str());
350 string start =
"**** Molecular Integrals For CheMPS Start Here";
352 getline(inputfile,line);
353 pos = line.find(start);
354 if (pos==0) stop =
true;
358 getline(inputfile,line);
359 pos = line.find(
"=");
360 part = line.substr(pos+2,line.size()-pos-3);
364 if (part.compare(SymmInfo.getGroupName(nGroup))==0) stop =
true;
367 SymmInfo.setGroup(nGroup);
371 getline(inputfile,line);
374 getline(inputfile,line);
375 pos = line.find(
"=");
376 part = line.substr(pos+2,line.size()-pos-3);
377 Econst = atof(part.c_str());
380 getline(inputfile,line);
381 pos = line.find(
"=");
382 part = line.substr(pos+2,line.size()-pos-3);
383 L = atoi(part.c_str());
386 getline(inputfile,line);
389 getline(inputfile,line);
391 orb2irrep.reset(
new int[L]);
392 orb2indexSy.reset(
new int[L]);
393 int nIrreps = SymmInfo.getNumberOfIrreps();
394 irrep2num_orb.reset(
new int[nIrreps]);
398 orb2irrep[pos] = atoi(line.substr(2*pos,1).c_str());
400 }
while (2*pos < (
int)line.size()-1);
402 for (
int cnt=0; cnt<nIrreps; cnt++) irrep2num_orb[cnt] = 0;
403 for (
int cnt=0; cnt<L; cnt++){
404 orb2indexSy[cnt] = irrep2num_orb[orb2irrep[cnt]];
405 irrep2num_orb[orb2irrep[cnt]]++;
407 Tmat.reset(
new TwoIndex(SymmInfo.getGroupNumber(),irrep2num_orb.get()));
408 Vmat.reset(
new FourIndex(SymmInfo.getGroupNumber(),irrep2num_orb.get()));
411 getline(inputfile,line);
412 getline(inputfile,line);
413 getline(inputfile,line);
416 getline(inputfile,line);
417 int pos2, index1, index2;
419 while( (line.substr(0,1)).compare(
"*")!=0 ){
422 pos2 = line.find(
" ",pos);
423 index1 = atoi(line.substr(pos,pos2-pos).c_str());
426 pos2 = line.find(
" ",pos);
427 index2 = atoi(line.substr(pos,pos2-pos).c_str());
429 value = atof(line.substr(pos2+1,line.size()-pos2-2).c_str());
431 setTmat(index1,index2,value);
433 getline(inputfile,line);
438 getline(inputfile,line);
440 while( (line.substr(0,1)).compare(
"*")!=0 ){
443 pos2 = line.find(
" ",pos);
444 index1 = atoi(line.substr(pos,pos2-pos).c_str());
447 pos2 = line.find(
" ",pos);
448 index2 = atoi(line.substr(pos,pos2-pos).c_str());
451 pos2 = line.find(
" ",pos);
452 index3 = atoi(line.substr(pos,pos2-pos).c_str());
455 pos2 = line.find(
" ",pos);
456 index4 = atoi(line.substr(pos,pos2-pos).c_str());
458 value = atof(line.substr(pos2+1,line.size()-pos2-2).c_str());
460 setVmat(index1, index3, index2, index4, value);
462 getline(inputfile,line);
474 cout <<
"Econst = " << Econst << endl;
479 for (
int i=0; i<L; i++){
480 test3 += getTmat(i,i);
481 for (
int j=0; j<L; j++){
482 test += getTmat(i,j);
483 if (i<=j) test2 += getTmat(i,j);
486 cout <<
"1-electron integrals: Trace : " << test3 << endl;
487 cout <<
"1-electron integrals: Sum over all elements : " << test << endl;
488 cout <<
"1-electron integrals: Sum over Tij with i<=j : " << test2 << endl;
493 for (
int i=0; i<L; i++){
494 test3 += getVmat(i,i,i,i);
495 for (
int j=0; j<L; j++){
496 for (
int k=0; k<L; k++){
497 for (
int l=0; l<L; l++){
498 test += getVmat(i,j,k,l);
499 if ((i<=j) && (j<=k) && (k<=l)) test2 += getVmat(i,j,k,l);
504 cout <<
"2-electron integrals: Trace : " << test3 << endl;
505 cout <<
"2-electron integrals: Sum over all elements : " << test << endl;
506 cout <<
"2-electron integrals: Sum over Vijkl with i<=j<=k<=l : " << test2 << endl;
519 hid_t file_id = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
522 hid_t group_id = H5Gcreate(file_id,
"/Data", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
525 hsize_t dimarray = 1;
526 hid_t dataspace_id = H5Screate_simple(1, &dimarray, NULL);
527 hid_t dataset_id = H5Dcreate(group_id,
"L", H5T_STD_I32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
528 H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &L);
531 hsize_t dimarray2 = 1;
532 hid_t dataspace_id2 = H5Screate_simple(1, &dimarray2, NULL);
533 hid_t dataset_id2 = H5Dcreate(group_id,
"nGroup", H5T_STD_I32LE, dataspace_id2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
534 int nGroup = SymmInfo.getGroupNumber();
535 H5Dwrite(dataset_id2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nGroup);
538 hsize_t dimarray3 = L;
539 hid_t dataspace_id3 = H5Screate_simple(1, &dimarray3, NULL);
540 hid_t dataset_id3 = H5Dcreate(group_id,
"orb2irrep", H5T_STD_I32LE, dataspace_id3, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
541 H5Dwrite(dataset_id3, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, orb2irrep.get());
544 hsize_t dimarray4 = 1;
545 hid_t dataspace_id4 = H5Screate_simple(1, &dimarray4, NULL);
546 hid_t dataset_id4 = H5Dcreate(group_id,
"Econst", H5T_IEEE_F64LE, dataspace_id4, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
547 H5Dwrite(dataset_id4, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &Econst);
549 hid_t dataspace_id5 = H5Screate(H5S_SCALAR);
550 hid_t dataset_id5 = H5Dcreate(group_id,
"nelectrons", H5T_STD_I32LE, dataspace_id5, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
551 H5Dwrite(dataset_id5, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &Ne);
553 H5Dclose(dataset_id);
554 H5Sclose(dataspace_id);
555 H5Dclose(dataset_id2);
556 H5Sclose(dataspace_id2);
557 H5Dclose(dataset_id3);
558 H5Sclose(dataspace_id3);
559 H5Dclose(dataset_id4);
560 H5Sclose(dataspace_id4);
561 H5Dclose(dataset_id5);
562 H5Sclose(dataspace_id5);
568 Tmat->save2(filename);
569 Vmat->save2(filename);
574 Tmat->read2(filename);
575 Vmat->read2(filename);
578 hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
581 hid_t group_id = H5Gopen(file_id,
"/Data",H5P_DEFAULT);
584 hid_t dataset_id1 = H5Dopen(group_id,
"L", H5P_DEFAULT);
586 H5Dread(dataset_id1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &Lagain);
590 hid_t dataset_id2 = H5Dopen(group_id,
"nGroup", H5P_DEFAULT);
592 H5Dread(dataset_id2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nGroup);
593 assert( nGroup==SymmInfo.getGroupNumber() );
595 hid_t dataset_id5 = H5Dopen(group_id,
"nelectrons", H5P_DEFAULT);
596 H5Dread(dataset_id5, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &Ne);
599 hid_t dataset_id3 = H5Dopen(group_id,
"orb2irrep", H5P_DEFAULT);
600 int * orb2irrepAgain =
new int[L];
601 H5Dread(dataset_id3, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, orb2irrepAgain);
602 for (
int cnt=0; cnt<L; cnt++){
603 assert( orb2irrep[cnt]==orb2irrepAgain[cnt] );
605 delete [] orb2irrepAgain;
608 hid_t dataset_id4 = H5Dopen(group_id,
"Econst", H5P_DEFAULT);
609 H5Dread(dataset_id4, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &Econst);
611 H5Dclose(dataset_id1);
612 H5Dclose(dataset_id2);
613 H5Dclose(dataset_id3);
614 H5Dclose(dataset_id4);
615 H5Dclose(dataset_id5);
634 hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
637 hid_t group_id = H5Gopen(file_id,
"/Data",H5P_DEFAULT);
641 hid_t dataset_id1 = H5Dopen(group_id,
"L", H5P_DEFAULT);
642 H5Dread(dataset_id1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &L);
645 hid_t dataset_id2 = H5Dopen(group_id,
"nGroup", H5P_DEFAULT);
647 H5Dread(dataset_id2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &nGroup_LOADH5);
650 hid_t dataset_id3 = H5Dopen(group_id,
"orb2irrep", H5P_DEFAULT);
651 std::unique_ptr<int []> orb2irrep(
new int[L]);
652 H5Dread(dataset_id3, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, orb2irrep.get());
654 H5Dclose(dataset_id1);
655 H5Dclose(dataset_id2);
656 H5Dclose(dataset_id3);
662 Hamiltonian my_obj(L, nGroup_LOADH5, orb2irrep.get());
664 my_obj.
read2(filename);
static Hamiltonian CreateFromH5(const string filename)
void reset()
set everything to zero
bool setGroup(const int nGroup)
Set the group.
std::unique_ptr< int[]> orb2indexSy
int getNumberOfIrreps() const
Get the number of irreps for the currently activated group.
void setTmat(const int index1, const int index2, const double val)
Set a Tmat element.
const bool HAMILTONIAN_debugPrint
int getOrbitalIrrep(const int nOrb) const
Get an orbital irrep number.
double getVmat(const int index1, const int index2, const int index3, const int index4) const
Get a Vmat element.
void debugcheck() const
Debug check certain elements and sums.
void setVmat(const int index1, const int index2, const int index3, const int index4, const double val)
Set a Vmat element.
void save(const string file_parent=HAMILTONIAN_ParentStorageName, const string file_tmat=HAMILTONIAN_TmatStorageName, const string file_vmat=HAMILTONIAN_VmatStorageName) const
Save the Hamiltonian.
void setEconst(const double val)
Set the constant energy.
int getGroupNumber() const
Get the group number.
std::unique_ptr< FourIndex > Vmat
void read(const string file_parent=HAMILTONIAN_ParentStorageName, const string file_tmat=HAMILTONIAN_TmatStorageName, const string file_vmat=HAMILTONIAN_VmatStorageName)
Load the Hamiltonian.
void save2(const string filename) const
double getTmat(const int index1, const int index2) const
Get a Tmat element.
std::unique_ptr< TwoIndex > Tmat
void CreateAndFillFromH5(const string file_parent, const string file_tmat, const string file_vmat)
void addToVmat(const int index1, const int index2, const int index3, const int index4, const double val)
Add to Vmat element.
void CreateAndFillFromPsi4dump(const string filename)
static int directProd(const int Irrep1, const int Irrep2)
Get the direct product of the irreps with numbers Irrep1 and Irrep2: a bitwise XOR for Psi4's convent...
Hamiltonian & operator=(const Hamiltonian &)
std::unique_ptr< int[]> orb2irrep
void read2(const string filename)
int getNGroup() const
Get the group number.
double getEconst() const
Get the constant energy.
Hamiltonian(const int Norbitals, const int nGroup, const int *OrbIrreps)
Constructor.
int getL() const
Get the number of orbitals.
std::unique_ptr< int[]> irrep2num_orb