Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes #90

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 91 additions & 3 deletions src/basis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1770,9 +1770,17 @@ arma::ivec BasisSet::get_m_values() const {
arma::ivec BasisSet::unique_m_values() const {
// Find unique m values
arma::ivec mval(get_m_values());
arma::uvec muni_idx(arma::find_unique(mval));
arma::ivec muni(mval(muni_idx));
return arma::sort(muni);
arma::sword mmin=0;
arma::sword mmax=arma::max(arma::abs(mval));

std::vector<arma::sword> mvals;
mvals.push_back(0);
for(int am=1;am<=mmax;am++) {
mvals.push_back(-am);
mvals.push_back(am);
}

return arma::conv_to<arma::ivec>::from(mvals);
}

std::map<int, arma::uword> BasisSet::unique_m_map() const {
Expand Down Expand Up @@ -4214,3 +4222,83 @@ arma::ivec m_classify(const arma::mat & C, const arma::ivec & mv) {

return oclass;
}

std::vector< std::vector<size_t> > BasisSet::find_identical_nuclei() const {
// Index list
std::vector< std::vector<size_t> > ret;

// Loop over nuclei
for(size_t i=0;i<get_Nnuc();i++) {
// Check that nucleus isn't BSSE
nucleus_t nuc=get_nucleus(i);
if(nuc.bsse)
continue;

// Get the shells on the nucleus
std::vector<GaussianShell> shi=get_funcs(i);

// Check if there something already on the list
bool found=false;
for(size_t j=0;j<ret.size();j++) {
std::vector<GaussianShell> shj=get_funcs(ret[j][0]);

// Check nuclear type
if(get_symbol(i).compare(get_symbol(ret[j][0]))!=0)
continue;
// Check charge status
if(get_nucleus(i).Q != get_nucleus(ret[j][0]).Q)
continue;

// Do comparison
if(shi.size()!=shj.size())
continue;
else {

bool same=true;
for(size_t ii=0;ii<shi.size();ii++) {
// Check angular momentum
if(shi[ii].get_am()!=shj[ii].get_am()) {
same=false;
break;
}

// and exponents
std::vector<contr_t> lhc=shi[ii].get_contr();
std::vector<contr_t> rhc=shj[ii].get_contr();

if(lhc.size() != rhc.size()) {
same=false;
break;
}
for(size_t ic=0;ic<lhc.size();ic++) {
if(!(lhc[ic]==rhc[ic])) {
same=false;
break;
}
}

if(!same)
break;
}

if(same) {
// Found identical atom.
found=true;

// Add it to the list.
ret[j].push_back(i);
}
}
}

if(!found) {
// Didn't find the atom, add it to the list.
std::vector<size_t> tmp;
tmp.push_back(i);

ret.push_back(tmp);
}
}

return ret;
}
2 changes: 2 additions & 0 deletions src/basis.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ class BasisSet {

/// Find "identical" shells in basis set.
std::vector< std::vector<size_t> > find_identical_shells() const;
/// Find "identical" nuclei
std::vector< std::vector<size_t> > find_identical_nuclei() const;
};

/// Compute three-center overlap integral
Expand Down
8 changes: 8 additions & 0 deletions src/density_fitting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,10 @@ arma::mat DensityFit::calcK(const arma::mat & Corig, const std::vector<double> &
return K;
}

arma::mat DensityFit::calcK(const arma::mat & Corig, const arma::vec & occo, size_t fitmem) const {
return calcK(Corig, arma::conv_to<std::vector<double>>::from(occo), fitmem);
}

arma::cx_mat DensityFit::calcK(const arma::cx_mat & Corig, const std::vector<double> & occo, size_t fitmem) const {
if(Corig.n_rows != Nbf) {
std::ostringstream oss;
Expand Down Expand Up @@ -1136,6 +1140,10 @@ arma::cx_mat DensityFit::calcK(const arma::cx_mat & Corig, const std::vector<dou
return K;
}

arma::cx_mat DensityFit::calcK(const arma::cx_mat & Corig, const arma::vec & occo, size_t fitmem) const {
return calcK(Corig, arma::conv_to<std::vector<double>>::from(occo), fitmem);
}

size_t DensityFit::get_Norb() const {
return Nbf;
}
Expand Down
5 changes: 5 additions & 0 deletions src/density_fitting.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ class DensityFit {
/// Get exchange matrix from orbitals with occupation numbers occs
arma::cx_mat calcK(const arma::cx_mat & C, const std::vector<double> & occs, size_t fitmem) const;

/// Get exchange matrix from orbitals with occupation numbers occs
arma::mat calcK(const arma::mat & C, const arma::vec & occs, size_t fitmem) const;
/// Get exchange matrix from orbitals with occupation numbers occs
arma::cx_mat calcK(const arma::cx_mat & C, const arma::vec & occs, size_t fitmem) const;

/// Get the number of orbital functions
size_t get_Norb() const;
/// Get the number of auxiliary functions
Expand Down
8 changes: 8 additions & 0 deletions src/erichol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,10 @@ arma::mat ERIchol::calcK(const arma::mat & C, const std::vector<double> & occs)
return K;
}

arma::mat ERIchol::calcK(const arma::mat & C, const arma::vec & occs) const {
return calcK(C, arma::conv_to<std::vector<double>>::from(occs));
}

arma::cx_mat ERIchol::calcK(const arma::cx_mat & C, const std::vector<double> & occs) const {
arma::cx_mat K(C.n_rows,C.n_rows);
K.zeros();
Expand All @@ -788,6 +792,10 @@ arma::cx_mat ERIchol::calcK(const arma::cx_mat & C, const std::vector<double> &
return K;
}

arma::cx_mat ERIchol::calcK(const arma::cx_mat & C, const arma::vec & occs) const {
return calcK(C, arma::conv_to<std::vector<double>>::from(occs));
}

void ERIchol::B_matrix(arma::mat & Br) const {
Br.zeros(Nbf*Nbf,B.n_cols);
for(size_t P=0;P<B.n_cols;P++)
Expand Down
4 changes: 4 additions & 0 deletions src/erichol.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ class ERIchol {
arma::mat calcK(const arma::vec & C) const;
/// Form exchange matrix
arma::mat calcK(const arma::mat & C, const std::vector<double> & occs) const;
/// Form exchange matrix
arma::mat calcK(const arma::mat & C, const arma::vec & occs) const;

/// Form exchange matrix
arma::cx_mat calcK(const arma::cx_vec & C) const;
/// Form exchange matrix
arma::cx_mat calcK(const arma::cx_mat & C, const std::vector<double> & occs) const;
/// Form exchange matrix
arma::cx_mat calcK(const arma::cx_mat & C, const arma::vec & occs) const;

/// Get full B matrix
void B_matrix(arma::mat & B) const;
Expand Down
81 changes: 1 addition & 80 deletions src/guess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ arma::mat atomic_guess_wrk(const BasisSet & basis, atomic_guess_t type, double K
// the way that the basis sets coincide.

// Get list of identical nuclei
std::vector< std::vector<size_t> > idnuc=identical_nuclei(basis);
std::vector< std::vector<size_t> > idnuc=basis.find_identical_nuclei();

// Amount of basis functions is
size_t Nbf=basis.get_Nbf();
Expand Down Expand Up @@ -422,85 +422,6 @@ arma::mat minimal_basis_projection(const BasisSet & basis) {
return atomic_guess_wrk(basis,FORM_MINBAS,0.0);
}

std::vector< std::vector<size_t> > identical_nuclei(const BasisSet & basis) {
// Returned list
std::vector< std::vector<size_t> > ret;

// Loop over nuclei
for(size_t i=0;i<basis.get_Nnuc();i++) {
// Check that nucleus isn't BSSE
nucleus_t nuc=basis.get_nucleus(i);
if(nuc.bsse)
continue;

// Get the shells on the nucleus
std::vector<GaussianShell> shi=basis.get_funcs(i);

// Check if there something already on the list
bool found=false;
for(size_t j=0;j<ret.size();j++) {
std::vector<GaussianShell> shj=basis.get_funcs(ret[j][0]);

// Check nuclear type
if(basis.get_symbol(i).compare(basis.get_symbol(ret[j][0]))!=0)
continue;
// Check charge status
if(basis.get_nucleus(i).Q != basis.get_nucleus(ret[j][0]).Q)
continue;

// Do comparison
if(shi.size()!=shj.size())
continue;
else {

bool same=true;
for(size_t ii=0;ii<shi.size();ii++) {
// Check angular momentum
if(shi[ii].get_am()!=shj[ii].get_am()) {
same=false;
break;
}

// and exponents
std::vector<contr_t> lhc=shi[ii].get_contr();
std::vector<contr_t> rhc=shj[ii].get_contr();

if(lhc.size() != rhc.size()) {
same=false;
break;
}
for(size_t ic=0;ic<lhc.size();ic++) {
if(!(lhc[ic]==rhc[ic])) {
same=false;
break;
}
}

if(!same)
break;
}

if(same) {
// Found identical atom.
found=true;

// Add it to the list.
ret[j].push_back(i);
}
}
}

if(!found) {
// Didn't find the atom, add it to the list.
std::vector<size_t> tmp;
tmp.push_back(i);

ret.push_back(tmp);
}
}

return ret;
}


bool operator<(const el_conf_t & lhs, const el_conf_t & rhs) {
Expand Down
3 changes: 0 additions & 3 deletions src/guess.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ arma::mat minimal_basis_projection(const BasisSet & basis);
*/
void atomic_guess(const BasisSet & basis, size_t inuc, const std::string & method, std::vector<size_t> & shellidx, BasisSet & atbas, arma::vec & atE, arma::mat & atC, arma::mat & atP, arma::mat & atF, int Q);

/// Determine list of identical nuclei, determined by nucleus and basis set
std::vector< std::vector<size_t> > identical_nuclei(const BasisSet & basis);

/// Electronic configuration
typedef struct {
/// Primary quantum number
Expand Down
2 changes: 1 addition & 1 deletion src/hirshfeld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void Hirshfeld::compute(const BasisSet & basis, std::string method) {
atoms.resize(basis.get_Nnuc());

// Get list of identical nuclei
std::vector< std::vector<size_t> > idnuc=identical_nuclei(basis);
std::vector< std::vector<size_t> > idnuc=basis.find_identical_nuclei();

// Loop over list of identical nuclei
for(size_t i=0;i<idnuc.size();i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/hirshfeldi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void HirshfeldI::compute(const BasisSet & basis, const arma::mat & P, std::strin
atQ.resize(basis.get_Nnuc());

// Get list of identical nuclei
std::vector< std::vector<size_t> > idnuc=identical_nuclei(basis);
std::vector< std::vector<size_t> > idnuc=basis.find_identical_nuclei();

Timer t;
if(verbose)
Expand Down
Loading