void Wf_return::setVals(Array2 <dcomplex> & vals , Array1 <doublevar> & p) { // here we extract amplitude and phase, and their gradients and laplacians, // from the complex value and its gradient and derivative is_complex=1; cvals=vals; int ntype=vals.GetDim(1); int nwf=vals.GetDim(0); for (int w=0; w< nwf; w++) { amp(w,0)=vals(w,0).real(); phase(w,0)=p(w); doublevar sum_ii=0; doublevar sum_ri=0; if (ntype>=4) { for (int i=1; i<4; i++) { amp(w,i)=vals(w,i).real(); phase(w,i)=vals(w,i).imag(); sum_ii+=phase(w,i)*phase(w,i); sum_ri+=amp(w,i)*phase(w,i); } } if (ntype>=5) { amp(w,4)=vals(w,4).real()+sum_ii; phase(w,4)=vals(w,4).imag()-2*sum_ri; } } }
bool compareArraysNeg( const Array1 &a1, const std::string &a1_name, const Array2 &a2, const std::string &a2_name, FancyOStream &out ) { bool success = true; out << "Comparing " << a1_name << " == -(" << a2_name << ") ... "; const int n = a1.size(); // Compare sizes if (as<int>(a2.size()) != n) { out << "\nError, "<<a1_name<<".size() = "<<a1.size()<<" == " << a2_name<<".size() = "<<a2.size()<<" : failed!\n"; return false; } // Compare elements for( int i = 0; i < n; ++i ) { const bool result = ( a1[i] == -a2[i] ); // Tests C::operator[](i) const if (!result) { out << "\nError, "<<a1_name<<"["<<i<<"] = "<<a1[i]<<" == -(" << a2_name<<"["<<i<<"]) = -("<<a2[i]<<"): failed!\n"; success = false; } } if (success) { out << "passed\n"; } return success; }
int main(int argc, char **argv) { Triolet_init(&argc, &argv); List<TriInput> arr = make_inputs(); Array2<Float> result = f(arr); // Check output int y, x; bool ok = true; for (y = 0; y < 2; y++) { for (x = 0; x < 3; x++) { float result_val = (Float)result.at(y, x); if (result_val != outputs[y][x]) ok = false; } } if (ok) { fputs("ok", stdout); return 0; } else { // Result does not match; print all outputs for (y = 0; y < 2; y++) { for (x = 0; x < 3; x++) { printf("%6f\t%6f\n", outputs[y][x], (float)(Float)result.at(y, x)); } } return 1; } }
void recenter(Array2 <doublevar> & pos, Array1 <doublevar> & mass) { int natoms=pos.GetDim(0); assert(pos.GetDim(0)==mass.GetDim(0)); assert(pos.GetDim(1)==3); Array1 <doublevar> center(3,0.0); //center of mass doublevar tot=0.0; for(int at=0; at< natoms; at++) { for(int d=0; d< 3; d++) { center(d)+=mass(at)*pos(at,d); } tot+=mass(at); } for(int d=0; d< 3; d++) { center(d)/=tot; } for(int at=0; at< natoms; at++) { for(int d=0; d< 3; d++) { pos(at,d)-=center(d); } } }
void copy_array (Array1& source, Array2& dest) { assert(std::equal(source.shape(),source.shape()+source.num_dimensions(), dest.shape())); // Dispatch to the proper function typedef typename Array1::element element_type; copy_dispatch<element_type>:: copy_array(source.begin(),source.end(),dest.begin()); }
inline void output_array(Array2 <doublevar> & arr) { for(int i=0; i< arr.GetDim(0); i++) { for(int j=0; j < arr.GetDim(1); j++) { cout << arr(i,j) << " "; } cout << endl; } }
void Wf_return::setVals(Array2 <log_value<doublevar> > & v ) { is_complex=0; int nfunc=v.GetDim(0); int nst=v.GetDim(1); Resize(nfunc,nst); for(int f=0; f< nfunc; f++) { amp(f,0)=v(f,0).logval; phase(f,0)=v(f,0).sign<0?pi:0.0; for(int s=1; s< nst; s++) { amp(f,s)=v(f,s).val(); phase(f,s)=0.0; } } }
/* Return the molecule orbital values */ void Average_ekt::calc_mos(Sample_point * sample, int e, Array2 <dcomplex> & movals) { if(complex_orbitals) { movals.Resize(nmo,1); cmomat->updateVal(sample,e,0,movals); } else { Array2 <doublevar> movals_d(nmo,1); momat->updateVal(sample,e,0,movals_d); movals.Resize(nmo,1); for(int i=0; i< nmo; i++) { movals(i,0)=movals_d(i,0); } } }
/* Calculate the values, gradient and laplacians of molecule orbitals, returned as: [val, grad, lap] */ void Average_ekt::calc_mosLap(Sample_point * sample, int e, Array2 <dcomplex> & molaps) { if(complex_orbitals) { molaps.Resize(nmo,5); cmomat->updateLap(sample, e, 0, molaps); } else { Array2 <doublevar> molaps_d(nmo,5); momat->updateLap(sample,e,0,molaps_d); molaps.Resize(nmo,5); for(int i=0; i< nmo; i++) { for (int d=0; d<5; d++) molaps(i,d)=molaps_d(i,d); } } }
// Extracts the inverted covariance matrix for a given branch from the full covariance matrix. void branch_inverted_covariance_matrix(Model &Mod, Array2 &Covfull, long b, Array2 &Covbri) { long i,j; ublas::matrix<double> CC(Mod.df, Mod.df); ublas::matrix<double> II(Mod.df, Mod.df); for(i=0; i < Mod.df; i++) { for(j=0; j< Mod.df; j++) { CC(i,j) = Covfull[Mod.df*b + i][Mod.df*b + j]; } } bool res = matrix_inverse(CC, II); if (!res) { throw std::out_of_range( "Could not invert the Covariance matrix." ); } Covbri.resize(Mod.df); for(i=0; i < Mod.df; i++) { Covbri[i].resize(Mod.df); for(j=0; j< Mod.df; j++) { Covbri[i][j] = II(i,j); } } }
// Computes the full covariance matrix for the MLE, using observed Fisher info. void full_MLE_observed_covariance_matrix(Tree &T, Model &Mod, Parameters &Par, Counts &data, Array2 &Cov) { long i, j; long npars = Mod.df*T.nedges + Mod.rdf; ublas::matrix<double> CC(npars, npars); ublas::matrix<double> II(npars, npars); Array2 I; Observed_Fisher_information(T, Mod, Par, data, I); // Need to convert from Matrix to ublas::matrix<double> for(i=0; i < npars; i++) { for(j=0; j < npars; j++) { II(i, j) = I[i][j]; } } bool res = matrix_inverse(II, CC); if (!res) { throw std::out_of_range("Could not invert the Fisher information matrix."); } Cov.resize(npars); for(i=0; i < npars; i++) { Cov[i].resize(npars); for(j=0; j < npars; j++) { Cov[i][j] = CC(i,j); } } }
void MO_matrix_blas::writeorb(ostream & os, Array2 <doublevar> & rotation, Array1 <int> &moList) { int nmo_write=moList.GetDim(0); assert(rotation.GetDim(0)==nmo_write); assert(rotation.GetDim(1)==nmo_write); os.precision(15); int counter=0; for(int m=0; m < nmo_write; m++) { int mo=moList(m); for(int ion=0; ion<centers.size(); ion++) { int f=0; for(int n=0; n< centers.nbasis(ion); n++) { int fnum=centers.basis(ion,n); int imax=basis(fnum)->nfunc(); for(int i=0; i<imax; i++) { os << mo+1 << " " << f+1 << " " << ion+1 << " " << counter+1 << endl; f++; //keep a total of functions on center counter++; } //i } //n } //ion } os << "COEFFICIENTS\n"; ifstream orbin(orbfile.c_str()); rotate_orb(orbin, os, rotation, moList, totbasis); orbin.close(); }
void Cutoff_cusp::calcLap( const Array1 <doublevar> & r, Array2 <doublevar> & symvals, const int startfill ) { assert(r.GetDim(0) >=5); assert(symvals.GetDim(0) >= 1+startfill); assert(symvals.GetDim(1) >= 5); if(r(0) < rcut) { doublevar zz=r(0)*rcutinv; doublevar zz2=zz*zz; doublevar pp=zz-zz2+zz*zz2/3; doublevar pade=1./(1+gamma*pp); symvals(startfill,0)=cusp*rcut*(pp*pade-pade0); doublevar pade2=pade*pade; doublevar ppd=1.-2.*zz+zz2; doublevar ppdd=-2.+2.*zz; doublevar dadr=ppd*pade2/r(0); doublevar dadr2=ppdd*pade2*rcutinv -2.*gamma*ppd*ppd*pade2*pade*rcutinv +2.*dadr; for(int i=1; i< 4; i++) { symvals(startfill, i)=cusp*dadr*r(i+1); } symvals(startfill, 4)=cusp*dadr2; } else { for(int i=0; i< 5; i++) symvals(startfill, i)=0; } }
//---------------------------------------------------------------------- //Keeping this separate from calcLoc for efficiency reasons.. //It's most likely faster to add to a double than fill matrices.. //We also don't need to calculate the ion-ion interaction for this void Molecular_system::separatedLocal(Sample_point * sample,Array1 <doublevar> & onebody, Array2 <doublevar> & twobody) { int nions=sample->ionSize(); int nelectrons=sample->electronSize(); onebody.Resize(nelectrons); twobody.Resize(nelectrons,nelectrons); onebody=0.0; twobody=0.0; Array1 <doublevar> R(5); sample->updateEIDist(); sample->updateEEDist(); for(int e=0; e< nelectrons; e++) { for(int i=0; i < nions; i++) { sample->getEIDist(e,i, R); onebody(e)-=sample->getIonCharge(i)/R(0); } } Array1 <doublevar> R2(5); for(int i=0; i< nelectrons; i++) { for(int j=i+1; j<nelectrons; j++) { sample->getEEDist(i,j,R2); twobody(i,j)+= 1/R2(0); } } Array1 <doublevar> pos(3); for(int e=0; e< nelectrons; e++) { sample->getElectronPos(e,pos); for(int d=0; d< 3; d++) onebody(e)-=electric_field(d)*pos(d); } }
int Molecular_system::getBounds(Array2 <doublevar> & latticevec,Array1<doublevar> & origin) { cout << "getBounds()" << endl; latticevec.Resize(3,3); latticevec=0.0; Array1 <doublevar> minmax(6); for(int d=0; d< 3; d++) { minmax(2*d)=minmax(2*d+1)=0.0; } int nions=nIons(); Array1 <doublevar> ionpos(3); for(int i=0; i< nions; i++) { getIonPos(i,ionpos); for(int d=0; d< 3; d++) { if(ionpos(d) < minmax(2*d)) minmax(2*d) = ionpos(d); if(ionpos(d) > minmax(2*d+1)) minmax(2*d+1)=ionpos(d); } } for(int d=0; d< 3; d++) { // minmax(2*d)-=4.0; //minmax(2*d+1)+=4.0; origin(d)=minmax(2*d)-4.0; latticevec(d,d)=minmax(2*d+1)-origin(d)+4.0; } cout << "getBounds done" << endl; return 1; }
void Wf_return::setVals(Array2 <doublevar> & vals, Array1 <doublevar> & sign) { is_complex=0; for(int w=0; w< vals.GetDim(0); w++) { for(int i=0; i< vals.GetDim(1); i++) { cvals(w,i)=vals(w,i); } } amp=vals; phase=0; for(int w=0; w< sign.GetDim(0); w++) { phase(w,0)=.5*pi*(1-sign(w)); } }
void GeneralizedEigenSystemSolverRealGeneralMatrices(Array2 < doublevar > & Ain, Array1 <dcomplex> & W, Array2 <doublevar> & VL, Array2 <doublevar> & VR) { #ifdef USE_LAPACK //if LAPACK int N=Ain.dim[0]; Array2 <doublevar> A_temp=Ain; //,VL(N,N),VR(N,N); Array1 <doublevar> WORK,RWORK(2*N),WI(N),WR(N); WI.Resize(N); VL.Resize(N,N); VR.Resize(N,N); int info; int NB=64; int NMAX=N; int lda=NMAX; int ldb=NMAX; int LWORK=5*NMAX; WORK.Resize(LWORK); info= dgeev('V','V',N,A_temp.v, lda,WR.v,WI.v,VL.v,lda,VR.v,lda,WORK.v,LWORK); if(info>0) error("Internal error in the LAPACK routine dgeev",info); if(info<0) error("Problem with the input parameter of LAPACK routine dgeev in position ",-info); W.Resize(N); for(int i=0; i< N; i++) { W(i)=dcomplex(WR(i),WI(i)); } // for (int i=0; i<N; i++) // evals(i)=W[N-1-i]; // for (int i=0; i<N; i++) { // for (int j=0; j<N; j++) { // evecs(j,i)=A_temp(N-1-i,j); // } // } //END OF LAPACK #else //IF NO LAPACK error("need LAPACK for eigensystem solver for general matrices"); #endif //END OF NO LAPACK }
doublevar Wannier_method::eval_tstep(Array3 <dcomplex> & eikr, Array2 <doublevar> & Rgen, Array2 <doublevar> & Rgen_save, Array2 <doublevar> & deriv, doublevar tstep, Array2 <doublevar> & R) { int norb=Rgen.GetDim(0); for(int ii=0; ii< norb; ii++) { for(int jj=ii+1; jj < norb; jj++) { Rgen(ii,jj)=Rgen_save(ii,jj)-tstep*deriv(ii,jj); } } return evaluate_local(eikr,Rgen,R); }
// Extracts the covariance matrix for a given branch from the full covariance matrix. void branch_covariance_matrix(Model &Mod, Array2 &Covfull, long b, Array2 &Covbr) { long i,j; Covbr.resize(Mod.df); for(i=0; i < Mod.df; i++) { Covbr[i].resize(Mod.df); for(j=0; j< Mod.df; j++) { Covbr[i][j] = Covfull[Mod.df*b + i][Mod.df*b + j]; } } }
void Minimization_function::init_overlap_ma_R(Array2<doublevar> &overlap_ma_R){ assert(overlap_ma_R.GetDim(0)==overlap_ma_R.GetDim(1)); _overlap_ma_R.Resize(overlap_ma_R.GetDim(0),overlap_ma_R.GetDim(0)); for(int k=0;k<overlap_ma_R.GetDim(0);k++) for(int l=0;l<=k;l++) _overlap_ma_R(l,k)=_overlap_ma_R(k,l)=overlap_ma_R(k,l); }
void MO_matrix_standard::updateLap( Sample_point * sample, int e, int listnum, Array2 <doublevar> & newvals //!< The return: in form (MO, [val, grad, lap]) ){ Array2 <doublevar> basisvals(totbasis, 5); int centermax=centers.size(); centers.updateDistance(e, sample); Basis_function * tempbasis; Array1 <doublevar> R(5); int currfunc=0; newvals=0; //cout << "centermax " << centermax << endl; for(int ion=0; ion < centermax; ion++) { centers.getDistance(e, ion, R); //cout << "nbasis " << centers.nbasis(ion) << endl; for(int n=0; n< centers.nbasis(ion); n++) { tempbasis=basis(centers.basis(ion,n)); tempbasis->calcLap(R, basisvals, currfunc); currfunc+=tempbasis->nfunc(); } } doublevar c; int nmo_list=moLists(listnum).GetDim(0); int valscale=newvals.GetDim(1); int basisscale=basisvals.GetDim(1); int mocoeffscale=moCoeff.GetDim(1); for(int m=0; m < nmo_list; m++) { int mo=moLists(listnum)(m); int effmo=mo*mocoeffscale; int effm=m*valscale; int efff; for(int f=0; f< totbasis; f++) { //c=moCoeff(mo,f); //cout << " c " << c << endl; c=moCoeff.v[effmo+f]; //cout << "c2 " << c << endl; efff=f*basisscale; for(int d=0; d< 5; d++) { //cout << "basisvals " << basisvals(f,d) << endl; //cout << "basisvals2 " << basisvals.v[efff+d] << endl; // //newvals(m,d)+=c*basisvals(f,d); //newvals.v[effm+d]+=c*basisvals(f,d); newvals.v[effm+d]+=c*basisvals.v[efff+d]; } } } }
void MO_matrix_standard::writeorb(ostream & os, Array2 <doublevar> & rotation, Array1 <int> &moList) { int nmo_write=moList.GetDim(0); assert(rotation.GetDim(0)==nmo_write); assert(rotation.GetDim(1)==nmo_write); cout << "nmo_write " << nmo_write << endl; int counter=0; for(int m=0; m < nmo_write; m++) { int mo=moList(m); for(int ion=0; ion<centers.size(); ion++) { int f=0; for(int n=0; n< centers.nbasis(ion); n++) { int fnum=centers.basis(ion,n); int imax=basis(fnum)->nfunc(); for(int i=0; i<imax; i++) { os << mo+1 << " " << f+1 << " " << ion+1 << " " << counter+1 << endl; f++; //keep a total of functions on center counter++; } //i } //n } //ion } os << "COEFFICIENTS\n"; Array2 <doublevar> rotated_mo(nmo_write, totbasis); rotated_mo=0; for(int m=0; m< nmo_write; m++) { for(int m2=0; m2 < nmo_write; m2++) { for(int f=0; f< totbasis; f++) { rotated_mo(m, f)+=rotation(m,m2)*moCoeff(m2,f); } } } int counter2=1; for(int m=0; m < nmo_write; m++) { for(int f=0; f< totbasis; f++) { os << rotated_mo(m, f) << " "; if(counter2 % 5 ==0) os << endl; } } }
bool Teuchos::compareFloatingArrays( const Array1 &a1, const std::string &a1_name, const Array2 &a2, const std::string &a2_name, const ScalarMag &tol, Teuchos::FancyOStream &out ) { using Teuchos::as; bool success = true; out << "Comparing " << a1_name << " == " << a2_name << " ... "; const int n = a1.size(); // Compare sizes if (as<int>(a2.size()) != n) { out << "\nError, "<<a1_name<<".size() = "<<a1.size()<<" == " << a2_name<<".size() = "<<a2.size()<<" : failed!\n"; return false; } // Compare elements for( int i = 0; i < n; ++i ) { const ScalarMag err = relErr( a1[i], a2[i] ); if ( err > tol ) { out <<"\nError, relErr("<<a1_name<<"["<<i<<"]," <<a2_name<<"["<<i<<"]) = relErr("<<a1[i]<<","<<a2[i]<<") = " <<err<<" <= tol = "<<tol<<": failed!\n"; success = false; } } if (success) { out << "passed\n"; } return success; }
//---------------------------------------------------------------------- void Wf_return::setVals(Array2 <log_value<dcomplex> > & v ) { is_complex=1; int nfunc=v.GetDim(0); int nst=v.GetDim(1); Resize(nfunc,nst); for(int f=0; f< nfunc; f++) { amp(f,0)=v(f,0).logval.real(); phase(f,0)=v(f,0).logval.imag(); for(int s=1; s< nst; s++) { amp(f,s)=v(f,s).val().real(); phase(f,s)=v(f,s).val().imag(); } if(nst > 4) { doublevar sum_ii=0,sum_ri=0; for(int s=1; s< 4; s++) { sum_ii+=phase(f,s)*phase(f,s); sum_ri+=amp(f,s)*phase(f,s); } phase(f,4)-=2*sum_ri; amp(f,4)+=sum_ii; } } }
//---------------------------------------------------------------------- // // // doublevar Wannier_method::evaluate_local(const Array3 <dcomplex> & eikr, Array2 <doublevar> & Rgen, Array2 <doublevar> & R) { int norb=Rgen.GetDim(0); Array2 <doublevar> gvec(3,3); sys->getPrimRecipLattice(gvec); Array1 <doublevar> gnorm(3); gnorm=0; for(int d=0; d < 3; d++) { for(int d1=0; d1 < 3; d1++) { gnorm(d)+=gvec(d,d1)*gvec(d,d1); } gnorm(d)=sqrt(gnorm(d)); } Array2 <dcomplex> tmp(norb,norb),tmp2(norb,norb); make_rotation_matrix(Rgen,R); doublevar func=0; for(int d=0; d< 3; d++) { tmp=0.0; for(int i=0; i< norb; i++) { for(int j=0; j< norb; j++) { for(int k=0; k< norb; k++) { tmp(i,k)+=eikr(d,i,j)*R(k,j); } } } tmp2=0; for(int i=0; i< norb; i++) { for(int j=0; j< norb; j++) { for(int k=0; k< norb; k++) { tmp2(i,k)+=R(i,j)*tmp(j,k); } } } //cout << "========for d=" << d << endl; for(int i=0; i< norb; i++) { doublevar f= -log(norm(tmp2(i,i)))/(gnorm(d)*gnorm(d)); func+=f; // cout << setw(9) << f; } } //cout << endl; return func/(3*norb); }
void fill_pcond1(Tree &T, Model &Mod, StateList &sl, Parameters &Par, Array2 &pcond1) { long i,j,l,u,v; long k,e,a,b; double p; long npars = T.nedges*Mod.np + Mod.rdf + 1; // Initializations pcond1.resize(T.nstleaves); for (i=0; i < T.nstleaves; i++) { pcond1[i].resize(npars); for(k=0; k < npars; k++) { pcond1[i][k] = 0; } } // Loop over all states for (i=0; i < T.nstleaves; i++) { for(j=0; j < T.nsthidden; j++) { // Loop over edges for(e=0; e < T.nedges; e++) { // Compute cond1 probabilities p = Par.r[rootstate(sl.h[j])]; for(l=0; l < T.nedges; l++) { if (l == e) continue; edgestate(T, l, sl.h[j], sl.l[i], u, v); p = p*Par.tm[l][u][v]; } edgestate(T, e, sl.h[j], sl.l[i], a, b); k = erc2param(Mod, e, a, b); pcond1[i][k] = pcond1[i][k] + p; } // Take care of root parameters in pcond1 p = 1; for(l=0; l < T.nedges; l++) { edgestate(T, l, sl.h[j], sl.l[i], u, v); p = p*Par.tm[l][u][v]; } k = root2param(T, Mod, rootstate(sl.h[j])); pcond1[i][k] = pcond1[i][k] + p; } } }
void Properties_final_average::twoPointForces(Array2 <doublevar> & forces ) { int nwf=avg.GetDim(1); int naux=aux_energy.GetDim(0); if(naux%2!=0) error("there can't be two-point forces, since" " there's an odd number of differences"); forces.Resize(naux/2, 2); for(int i=0; i < naux; i+=2) { assert(aux_size(i)==aux_size(i+1)); forces(i/2,0)=(aux_diff(i,0)-aux_diff(i+1,0))/(aux_size(i)*2); forces(i/2,1)=sqrt( (aux_differr(i,0)+aux_differr(i+1,0))/4)/aux_size(i); } }
void Rgaussian_function::calcLap( const Array1 <doublevar> & r, Array2 <doublevar> & symvals, const int startfill){ assert(symvals.GetDim(0) >= nmax+startfill); assert(r.GetDim(0) >= 5); doublevar exponent; //cout << "v_l for l=" << l << " atom=" << at << endl; int index=startfill; for(int i=0; i< nmax; i++) { doublevar v_l=0, dv_l=0, d2v_l=0; for(int j=0; j< numExpansion(i); j++) { exponent=gaussexp(i, j)*r(1); exponent=min(exponent,(doublevar) 60.0); exponent=exp(-exponent); doublevar n=radiusexp(i,j); v_l+= gausscoeff(i, j) *pow(r(0),n ) *exponent; dv_l+=gausscoeff(i,j)*exponent*pow(r(0), n-1)*( n -2*r(1)*gaussexp(i,j)); //note that the laplacian is untested.. d2v_l+=gausscoeff(i,j)*pow(r(0), n-2)*( n*(n-1)-2*gaussexp(i,j)*n*r(1) -2*(n+1)*gaussexp(i,j)*r(1) +4*gaussexp(i,j)*gaussexp(i,j) *r(1)*r(1))*exponent; } dv_l/=r(0); symvals(index,0) = v_l; symvals(index,1) = dv_l*r(2); symvals(index,2) = dv_l*r(3); symvals(index,3) = dv_l*r(4); symvals(index,4) = d2v_l+2*dv_l; index++; } }
//---------------------------------------------------------------------- // // //Note this needs to be changed for non-zero k-points! doublevar Average_ekt::gen_sample(int nstep, doublevar tstep, int e, Array2 <dcomplex> & movals, Sample_point * sample) { int ndim=3; Array1 <doublevar> r(ndim),rold(ndim); Array2 <dcomplex> movals_old(nmo,1); movals.Resize(nmo,1); sample->getElectronPos(e,rold); calc_mos(sample,e,movals_old); doublevar acc=0; for(int step=0; step < nstep; step++) { for(int d=0; d< ndim; d++) { r(d)=rold(d)+sqrt(tstep)*rng.gasdev(); } sample->setElectronPos(e,r); calc_mos(sample,e,movals); doublevar sum_old=0,sum=0; for(int mo=0; mo < nmo; mo++) { sum_old+=norm(movals_old(mo,0)); sum+=norm(movals(mo,0)); } if(rng.ulec() < sum/sum_old) { movals_old=movals; rold=r; acc++; } } //cout << "acceptance " << acc/nstep << endl; movals=movals_old; sample->setElectronPos(e,rold); doublevar sum=0; for(int mo=0; mo < nmo; mo++) { sum+=norm(movals(mo,0)); } return sum; }
/*! Uses flat file of form: ncenters Label x y z Label x y z ... */ void read_centerpos(string & filename, Array2 <doublevar> & position, vector <string> & labels) { int ncenters; ifstream centin(filename.c_str()); if(!centin) error("Couldn't open ", filename); centin >> ncenters; labels.clear(); position.Resize(ncenters,3); string labeltemp; for(int i=0; i< ncenters; i++) { centin >> labeltemp; labels.push_back(labeltemp); for(int d=0; d< 3; d++) { centin >> position(i,d); } } centin.close(); }