Skip to content

Commit bdefc71

Browse files
authored
Merge pull request #76 from ZimmermanGroup/srijita
Added function to read 4c-2e integrals from file
2 parents 6d28634 + 337034f commit bdefc71

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/libio/read.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,62 @@ bool read_integrals(string dirname, int N, int Naux, double* S, double* T, doubl
18081808
return 1;
18091809
}
18101810

1811+
bool read_MOI_from_file(int Mm, int M3, double** MOI, string filename, int prl)
1812+
{
1813+
// Read 4-center 2-electron molecular orbital integrals (MOI) from a text file.
1814+
// Each row of the file corresponds to one orbital index combination, with M3 columns per row.
1815+
// Expected format is Mm rows and M3 columns
1816+
// Parameters:
1817+
// Mm - expected number of rows in the file (number of basis functions)
1818+
// M3 - expected number of columns per row
1819+
// MOI - output 2D array [Mm][M3] to populate with integral values
1820+
// filename - path to the MOI text file
1821+
// prl - print level for diagnostic output (higher = more verbose)
1822+
//
1823+
// Returns true on success, false if the file cannot be opened.
1824+
printf(" attempting file read: %s \n", filename.c_str());
1825+
1826+
ifstream infile;
1827+
infile.open(filename.c_str());
1828+
if (!infile)
1829+
{
1830+
printf(" couldn't open file \n");
1831+
return false;
1832+
}
1833+
1834+
string line;
1835+
1836+
// Skip the header line
1837+
(bool)getline(infile, line);
1838+
int wi = 0; // row counter for MOI
1839+
while (!infile.eof())
1840+
{
1841+
(bool)getline(infile, line);
1842+
vector<string> tok_line = split1(line, ' ');
1843+
if (tok_line.size() > 0)
1844+
{
1845+
// Validate that each row has at least M3 columns
1846+
if (tok_line.size() < M3) {
1847+
printf(" ERROR: file size wrong in MOI (%2i vs %2i) \n", tok_line.size(), M3);
1848+
exit(1);
1849+
}
1850+
// Parse M3 floating-point values into the current MOI row
1851+
for (int m = 0; m < M3; m++)
1852+
MOI[wi][m] = atof(tok_line[m].c_str());
1853+
wi++;
1854+
}
1855+
}
1856+
1857+
// Verify that the expected number of rows were read
1858+
if (wi == Mm) {
1859+
if (prl > 1) printf(" found all lines of MOI \n");
1860+
}
1861+
else printf(" MOI missing lines \n");
1862+
1863+
infile.close();
1864+
return true;
1865+
}
1866+
18111867
double nuclear_repulsion(int natoms, int* atno, double* coords)
18121868
{
18131869
double Enn = 0;

0 commit comments

Comments
 (0)