From c6bec674eb8b341eed4ffc8ecce2e69c03d2bc38 Mon Sep 17 00:00:00 2001 From: "Siu Wun \"Tony\" Cheung" Date: Thu, 16 Jan 2025 08:45:06 -0800 Subject: [PATCH] Merge release to ROMFPMD (#298) --- src/Control.cc | 72 ------ src/Control.h | 4 +- src/HDFrestart.cc | 15 ++ src/HDFrestart.h | 3 + src/Hamiltonian.cc | 7 +- src/MVPSolver.cc | 4 +- src/setup.cc | 17 +- tests/CMakeLists.txt | 12 + tests/FIRE/test.py | 6 +- tests/LBFGS/test.py | 8 +- tests/MD_D72/test.py | 6 +- tests/RestartEnergyAndForces/h2o.xyz | 6 + tests/RestartEnergyAndForces/mgmol.cfg | 33 +++ tests/RestartEnergyAndForces/restart.cfg | 32 +++ tests/RestartEnergyAndForces/test.py | 88 ++++++++ .../testRestartEnergyAndForces.cc | 206 ++++++++++++++++++ tests/ShortSighted/test.py | 6 +- 17 files changed, 440 insertions(+), 85 deletions(-) create mode 100644 tests/RestartEnergyAndForces/h2o.xyz create mode 100644 tests/RestartEnergyAndForces/mgmol.cfg create mode 100644 tests/RestartEnergyAndForces/restart.cfg create mode 100755 tests/RestartEnergyAndForces/test.py create mode 100644 tests/RestartEnergyAndForces/testRestartEnergyAndForces.cc diff --git a/src/Control.cc b/src/Control.cc index 3f8a11cc..83fe2093 100644 --- a/src/Control.cc +++ b/src/Control.cc @@ -1119,78 +1119,6 @@ void Control::printThermostatInfo(std::ostream& os) const } } -int Control::readOccupations(std::ifstream* tfile) -{ - int count = 0; - float nel = 0.; - do - { - float t1 = 0.; - int nst = 0; - if (mype_ == 0) - { -#ifdef DEBUG - (*MPIdata::sout) << " Occupations of states..." << std::endl; -#endif - (*tfile) >> nst; - if (nst <= 0) - { - (*MPIdata::sout) - << "Control::readOccupations: numst=" << numst << std::endl; - (*MPIdata::sout) << "Control::readOccupations: nst=" << nst - << ", count=" << count << std::endl; - (*MPIdata::sout) << "Control::readOccupations: Bad repeat " - "count for state occupations" - << std::endl; - return -1; - } - if ((count + nst) > numst) - { - (*MPIdata::sout) << "Control::readOccupations: Occupations " - "specified for too many states" - << std::endl; - return -1; - } - - (*tfile) >> t1; - if (t1 < 0.) - { - (*MPIdata::sout) - << "Control::readOccupations: occupation=" << t1 - << std::endl; - (*MPIdata::sout) << "Control::readOccupations: occupation " - "should be a positive number" - << std::endl; - return -1; - } - finishRead(*tfile); - } - int mpirc = MPI_Bcast(&nst, 1, MPI_INT, 0, comm_global_); - if (mpirc != MPI_SUCCESS) - { - (*MPIdata::sout) - << "MPI Bcast of occupation numbers failed!!!" << std::endl; - return -1; - } - mpirc = MPI_Bcast(&t1, 1, MPI_FLOAT, 0, comm_global_); - if (mpirc != MPI_SUCCESS) - { - (*MPIdata::sout) - << "MPI Bcast of occupation failed!!!" << std::endl; - return -1; - } - nel += nst * t1; - count += nst; - - } while (count < numst); - - nel_ = (int)nel; - - nempty_ = (2 * numst - (int)nel) / 2; - - return count; -} - void Control::setLocMode(const float radius, const float lx, const float ly, const float lz, const float mind_centers) { diff --git a/src/Control.h b/src/Control.h index 43da0be7..162a68cc 100644 --- a/src/Control.h +++ b/src/Control.h @@ -249,6 +249,7 @@ class Control const float total_spin, std::string run_directory = "."); void setDefaultValues(); + bool withSpin() { return with_spin_; } bool globalColoring() const { return (coloring_algo_ / 10 == 0); } @@ -270,6 +271,8 @@ class Control float getSpin() const { return total_spin_; } + void setNempty(const int nempty) { nempty_ = nempty; } + short getMGlevels() { return mg_levels_; } bool withPreconditioner() const { return (mg_levels_ >= 0); } @@ -301,7 +304,6 @@ class Control const float dtol, const short kim, const short itmax, const short lfil, const short maxfill, const short ilutype); void setSpreadRadius(); - int readOccupations(std::ifstream* tfile); bool checkTimeout() { return timeout_.check(); } bool occupationWidthIsZero() { return occ_width < 1.e-12; } diff --git a/src/HDFrestart.cc b/src/HDFrestart.cc index 08018d47..ef658955 100644 --- a/src/HDFrestart.cc +++ b/src/HDFrestart.cc @@ -2725,6 +2725,21 @@ void HDFrestart::gatherDataXdir(std::vector& data) } } +int HDFrestart::countFunctionObjects(std::string& name) const +{ + int count = 0; + int found = 0; + do + { + std::string datasetname(getDatasetName(name, count)); + // check if dataset exists... + found = checkDataExists(datasetname); + if (found) count++; + } while (found); // dataset exists + + return count; +} + template int HDFrestart::read_1func_hdf5(float*, const std::string&); template int HDFrestart::read_1func_hdf5(double*, const std::string&); diff --git a/src/HDFrestart.h b/src/HDFrestart.h index 7ffadff7..72c5c1f5 100644 --- a/src/HDFrestart.h +++ b/src/HDFrestart.h @@ -173,6 +173,7 @@ class HDFrestart return checkDataExistsLocal(datasetname.c_str()); } + // Returns zero (false), a positive (true) or a negative (failure) value. herr_t checkDataExistsLocal(const char* const datasetname) const { herr_t err_id = 0; @@ -282,6 +283,8 @@ class HDFrestart int getMDstepFromFile() const; int getFromFile(const std::string& attname) const; + int countFunctionObjects(std::string& name) const; + hid_t createPlist() { hid_t plist_id = H5P_DEFAULT; diff --git a/src/Hamiltonian.cc b/src/Hamiltonian.cc index ba0aa6c4..5a5d2a53 100644 --- a/src/Hamiltonian.cc +++ b/src/Hamiltonian.cc @@ -59,9 +59,9 @@ const T& Hamiltonian::applyLocal(T& phi, const bool force) if (onpe0) { (*MPIdata::sout) << "Hamiltonian::applyLocal(), new_index =" - << new_index << endl; + << new_index << std::endl; (*MPIdata::sout) << "Hamiltonian::applyLocal(), itindex_ =" - << itindex_ << endl; + << itindex_ << std::endl; } #endif if (force || new_index != itindex_) @@ -76,7 +76,8 @@ const T& Hamiltonian::applyLocal(T& phi, const bool force) if (onpe0) (*MPIdata::sout) << "Hamiltonian::hlphi up to date, itindex_=" << itindex_ - << endl; + << ", Potential index=" << pot_->getIterativeIndex() + << std::endl; #endif } return *hlphi_; diff --git a/src/MVPSolver.cc b/src/MVPSolver.cc index 6115f933..7ab9f665 100644 --- a/src/MVPSolver.cc +++ b/src/MVPSolver.cc @@ -143,7 +143,6 @@ void MVPSolver::buildTarget_MVP( proj_mat_work_->setHB2H(); proj_mat_work_->updateDM(orbitals_index); - target = proj_mat_work_->dm(); if (ct.verbose > 2) @@ -286,7 +285,7 @@ int MVPSolver::solve(OrbitalsType& orbitals) std::cout << "MVP --- Target energy..." << std::endl; proj_mat_work_->setDM(target, orbitals.getIterativeIndex()); proj_mat_work_->computeOccupationsFromDM(); - if (ct.verbose > 2) current_proj_mat->printOccupations(os_); + if (ct.verbose > 2) proj_mat_work_->printOccupations(os_); const double nel = proj_mat_work_->getNel(); if (onpe0 && ct.verbose > 1) os_ << "MVP --- Number of electrons at beta=1 : " << nel @@ -346,7 +345,6 @@ int MVPSolver::solve(OrbitalsType& orbitals) os_ << "Number of electrons for interpolated DM = " << pnel << std::endl; } - // if( onpe0 )os_<<"Rho..."<computeRho(orbitals, *work_); } diff --git a/src/setup.cc b/src/setup.cc index f022678c..9963bfc5 100644 --- a/src/setup.cc +++ b/src/setup.cc @@ -50,6 +50,7 @@ int MGmol::setupFromInput(const std::string filename) if (ct.isLocMode()) mymesh->subdivGridx(ct.getMGlevels()); const pb::PEenv& myPEenv = mymesh->peenv(); + if (ct.restart_info > 0) h5f_file_.reset( new HDFrestart(ct.restart_file, myPEenv, ct.restart_file_type)); @@ -58,8 +59,20 @@ int MGmol::setupFromInput(const std::string filename) if (status == -1) return -1; const short myspin = mmpi.myspin(); - const int nval = ions_->getNValenceElectrons(); - ct.setNumst(myspin, nval); + const int nel = ions_->getNValenceElectrons(); + // for the case of extended wavefunctions, we can determine the number + // of empty states from the number of wavefunctions in restart file + if (ct.restart_info > 2 && !ct.short_sighted) + { + std::string name = "Function"; + int count = h5f_file_->countFunctionObjects(name); + std::cout << "found " << count << " functions in restart file..." + << std::endl; + int nempty = ct.withSpin() ? count - nel : count - int(0.5 * nel); + ct.setNempty(nempty); + } + ct.setNumst(myspin, nel); + ct.setTolEnergy(); ct.setSpreadRadius(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 53793986..b29c1aad 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -256,6 +256,8 @@ add_executable(testWFEnergyAndForces ${CMAKE_SOURCE_DIR}/tests/WFEnergyAndForces/testWFEnergyAndForces.cc) add_executable(testDMandEnergyAndForces ${CMAKE_SOURCE_DIR}/tests/DMandEnergyAndForces/testDMandEnergyAndForces.cc) +add_executable(testRestartEnergyAndForces + ${CMAKE_SOURCE_DIR}/tests/RestartEnergyAndForces/testRestartEnergyAndForces.cc) if(${MAGMA_FOUND}) add_executable(testOpenmpOffload @@ -371,6 +373,15 @@ add_test(NAME testDMandEnergyAndForces ${CMAKE_CURRENT_SOURCE_DIR}/DMandEnergyAndForces/coords.in ${CMAKE_CURRENT_SOURCE_DIR}/DMandEnergyAndForces/lrs.in ${CMAKE_CURRENT_SOURCE_DIR}/../potentials) +add_test(NAME testRestartEnergyAndForces + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/RestartEnergyAndForces/test.py + ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} + ${CMAKE_CURRENT_BINARY_DIR}/../src/mgmol-opt + ${CMAKE_CURRENT_BINARY_DIR}/testRestartEnergyAndForces + ${CMAKE_CURRENT_SOURCE_DIR}/RestartEnergyAndForces/mgmol.cfg + ${CMAKE_CURRENT_SOURCE_DIR}/RestartEnergyAndForces/restart.cfg + ${CMAKE_CURRENT_SOURCE_DIR}/RestartEnergyAndForces/h2o.xyz + ${CMAKE_CURRENT_SOURCE_DIR}/../potentials) if(${MAGMA_FOUND}) add_test(NAME testOpenmpOffload @@ -567,6 +578,7 @@ target_link_libraries(testDirectionalReduce PRIVATE MPI::MPI_CXX) target_link_libraries(testEnergyAndForces PRIVATE mgmol_src) target_link_libraries(testWFEnergyAndForces PRIVATE mgmol_src) target_link_libraries(testDMandEnergyAndForces PRIVATE mgmol_src) +target_link_libraries(testRestartEnergyAndForces PRIVATE mgmol_src) target_link_libraries(testIons PRIVATE mgmol_src) target_link_libraries(testDensityMatrix PRIVATE ${HDF5_LIBRARIES}) diff --git a/tests/FIRE/test.py b/tests/FIRE/test.py index eaf380d9..6866e3ac 100755 --- a/tests/FIRE/test.py +++ b/tests/FIRE/test.py @@ -49,7 +49,11 @@ restart_file = subprocess.check_output(command,shell=True) restart_file=str(restart_file[:-1],'utf-8') print(restart_file) -os.symlink(restart_file, 'wave.out') +try: + os.symlink(restart_file, 'wave.out') +except FileExistsError: + os.remove('wave.out') + os.symlink(restart_file, 'wave.out') command = "{} {} -c {}".format(mpicmd,exe,inp2) print(command) diff --git a/tests/LBFGS/test.py b/tests/LBFGS/test.py index 2ff69c9a..324fd129 100755 --- a/tests/LBFGS/test.py +++ b/tests/LBFGS/test.py @@ -49,7 +49,12 @@ restart_file = subprocess.check_output(command,shell=True) restart_file=str(restart_file[:-1],'utf-8') print(restart_file) -os.symlink(restart_file, 'wave.out') + +try: + os.symlink(restart_file, 'wave.out') +except FileExistsError: + os.remove('wave.out') + os.symlink(restart_file, 'wave.out') command = "{} {} -c {} -i {} -l {}".format(mpicmd,exe,inp2,coords,lrs) print(command) @@ -75,6 +80,7 @@ os.remove('wave.out') if force>tol: + print("Force larger than tol {}".format(tol)) sys.exit(1) sys.exit(0) diff --git a/tests/MD_D72/test.py b/tests/MD_D72/test.py index a664b305..17b70de2 100755 --- a/tests/MD_D72/test.py +++ b/tests/MD_D72/test.py @@ -48,7 +48,11 @@ restart_file=str(restart_file[:-1],'utf-8') print(restart_file) -os.symlink(restart_file, 'wave.out') +try: + os.symlink(restart_file, 'wave.out') +except FileExistsError: + os.remove('wave.out') + os.symlink(restart_file, 'wave.out') command = "{} {} -c {} -i {}".format(mpicmd,exe,inp2,coords) output2 = subprocess.check_output(command,shell=True) diff --git a/tests/RestartEnergyAndForces/h2o.xyz b/tests/RestartEnergyAndForces/h2o.xyz new file mode 100644 index 00000000..cdc906f6 --- /dev/null +++ b/tests/RestartEnergyAndForces/h2o.xyz @@ -0,0 +1,6 @@ +3 +https://pubchem.ncbi.nlm.nih.gov/compound/Water +O 2.5369 -0.1550 0.0 +H 3.0739 0.1550 0.0 +H 2.0000 0.1550 0.0 + diff --git a/tests/RestartEnergyAndForces/mgmol.cfg b/tests/RestartEnergyAndForces/mgmol.cfg new file mode 100644 index 00000000..e590f810 --- /dev/null +++ b/tests/RestartEnergyAndForces/mgmol.cfg @@ -0,0 +1,33 @@ +verbosity=2 +xcFunctional=PBE +FDtype=4th +[Mesh] +nx=64 +ny=64 +nz=64 +[Domain] +ox=-3.4 +oy=-6.4 +oz=-6.4 +lx=12.8 +ly=12.8 +lz=12.8 +[Potentials] +pseudopotential=pseudo.O_ONCV_PBE_SG15 +pseudopotential=pseudo.H_ONCV_PBE_SG15 +[Run] +type=QUENCH +[Quench] +solver=PSD +max_steps=120 +atol=1.e-8 +[Orbitals] +initial_type=Random +initial_width=1.5 +nempty=2 +[Restart] +output_level=3 +output_filename=WF +[DensityMatrix] +solver=MVP +nb_inner_it=1 diff --git a/tests/RestartEnergyAndForces/restart.cfg b/tests/RestartEnergyAndForces/restart.cfg new file mode 100644 index 00000000..99bc77d8 --- /dev/null +++ b/tests/RestartEnergyAndForces/restart.cfg @@ -0,0 +1,32 @@ +verbosity=2 +xcFunctional=PBE +FDtype=4th +[Mesh] +nx=64 +ny=64 +nz=64 +[Domain] +ox=-3.4 +oy=-6.4 +oz=-6.4 +lx=12.8 +ly=12.8 +lz=12.8 +[Potentials] +pseudopotential=pseudo.O_ONCV_PBE_SG15 +pseudopotential=pseudo.H_ONCV_PBE_SG15 +[Run] +type=QUENCH +[Quench] +solver=PSD +max_steps=120 +atol=1.e-8 +[Orbitals] +initial_type=Random +initial_width=1.5 +[Restart] +input_level=3 +input_filename=WF +[DensityMatrix] +solver=MVP +nb_inner_it=20 diff --git a/tests/RestartEnergyAndForces/test.py b/tests/RestartEnergyAndForces/test.py new file mode 100755 index 00000000..349434e8 --- /dev/null +++ b/tests/RestartEnergyAndForces/test.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python +import sys +import os +import subprocess +import string + +print("Test RestartEnergyAndForces...") + +nargs=len(sys.argv) + +mpicmd = sys.argv[1]+" "+sys.argv[2]+" "+sys.argv[3] +for i in range(4,nargs-7): + mpicmd = mpicmd + " "+sys.argv[i] +print("MPI run command: {}".format(mpicmd)) + +mgmol_exe = sys.argv[nargs-6] +test_exe = sys.argv[nargs-5] +input1 = sys.argv[nargs-4] +input2 = sys.argv[nargs-3] +coords = sys.argv[nargs-2] +print("coordinates file: %s"%coords) + +#create links to potentials files +dst1 = 'pseudo.H_ONCV_PBE_SG15' +src1 = sys.argv[-1] + '/' + dst1 + +dst2 = 'pseudo.O_ONCV_PBE_SG15' +src2 = sys.argv[-1] + '/' + dst2 + +if not os.path.exists(dst1): + print("Create link to %s"%dst1) + os.symlink(src1, dst1) + +if not os.path.exists(dst2): + print("Create link to %s"%dst2) + os.symlink(src2, dst2) + +#run mgmol +command = "{} {} -c {} -i {}".format(mpicmd,mgmol_exe,input1,coords) +print("Run command: {}".format(command)) + +output = subprocess.check_output(command,shell=True) +lines=output.split(b'\n') + +#analyse output +ref_energy=1.e18 +for line in lines: + if line.count(b'%%'): + print(line) + words=line.split() + words=words[5].split(b',')[0] + energy = words.decode() + if line.count(b'achieved'): + ref_energy=energy + break + +#sys.exit(0) + +#run test +command = "{} {} -c {} -i {}".format(mpicmd,test_exe,input2,coords) +print("Run command: {}".format(command)) +output = subprocess.check_output(command,shell=True) +lines=output.split(b'\n') + +test_energy=1.e18 +for line in lines: + if line.count(b'%%'): + print(line) + words=line.split() + words=words[5].split(b',')[0] + energy = words.decode() + if line.count(b'Eks'): + print(line) + words=line.split() + print(words) + test_energy = words[2] + break + + +tol = 1.e-6 +diff=eval(test_energy)-eval(ref_energy) +print(diff) +if abs(diff)>tol: + print("Energies differ: {} vs {} !!!".format(ref_energy,test_energy)) + sys.exit(1) + +print("Test SUCCESSFUL!") +sys.exit(0) diff --git a/tests/RestartEnergyAndForces/testRestartEnergyAndForces.cc b/tests/RestartEnergyAndForces/testRestartEnergyAndForces.cc new file mode 100644 index 00000000..e323afbc --- /dev/null +++ b/tests/RestartEnergyAndForces/testRestartEnergyAndForces.cc @@ -0,0 +1,206 @@ +// Copyright (c) 2017, Lawrence Livermore National Security, LLC and +// UT-Battelle, LLC. +// Produced at the Lawrence Livermore National Laboratory and the Oak Ridge +// National Laboratory. +// LLNL-CODE-743438 +// All rights reserved. +// This file is part of MGmol. For details, see https://github.com/llnl/mgmol. +// Please also read this link https://github.com/llnl/mgmol/LICENSE + +#include "Control.h" +#include "ExtendedGridOrbitals.h" +#include "LocGridOrbitals.h" +#include "MGmol.h" +#include "MGmol_MPI.h" +#include "MPIdata.h" +#include "mgmol_run.h" + +#include +#include +#include +#include + +#include +namespace po = boost::program_options; + +int main(int argc, char** argv) +{ + int mpirc = MPI_Init(&argc, &argv); + if (mpirc != MPI_SUCCESS) + { + std::cerr << "MPI Initialization failed!!!" << std::endl; + MPI_Abort(MPI_COMM_WORLD, 0); + } + + MPI_Comm comm = MPI_COMM_WORLD; + + /* + * Initialize general things, like magma, openmp, IO, ... + */ + mgmol_init(comm); + + /* + * read runtime parameters + */ + std::string input_filename(""); + std::string lrs_filename; + std::string constraints_filename(""); + + float total_spin = 0.; + bool with_spin = false; + + po::variables_map vm; + + // read from PE0 only + if (MPIdata::onpe0) + { + read_config(argc, argv, vm, input_filename, lrs_filename, + constraints_filename, total_spin, with_spin); + } + + MGmol_MPI::setup(comm, std::cout, with_spin); + MGmol_MPI& mmpi = *(MGmol_MPI::instance()); + MPI_Comm global_comm = mmpi.commGlobal(); + + /* + * Setup control struct with run time parameters + */ + Control::setup(global_comm, with_spin, total_spin); + Control& ct = *(Control::instance()); + + ct.setOptions(vm); + + int ret = ct.checkOptions(); + if (ret < 0) return ret; + + mmpi.bcastGlobal(input_filename); + mmpi.bcastGlobal(lrs_filename); + + // Enter main scope + { + if (MPIdata::onpe0) + { + std::cout << "-------------------------" << std::endl; + std::cout << "Construct MGmol object..." << std::endl; + std::cout << "-------------------------" << std::endl; + } + + MGmolInterface* mgmol = new MGmol(global_comm, + *MPIdata::sout, input_filename, lrs_filename, constraints_filename); + + if (MPIdata::onpe0) + { + std::cout << "-------------------------" << std::endl; + std::cout << "MGmol setup..." << std::endl; + std::cout << "-------------------------" << std::endl; + } + mgmol->setup(); + + if (MPIdata::onpe0) + { + std::cout << "-------------------------" << std::endl; + std::cout << "Setup done..." << std::endl; + std::cout << "-------------------------" << std::endl; + } + + // here we just use the atomic positions read in and used + // to initialize MGmol + std::vector positions; + mgmol->getAtomicPositions(positions); + std::vector anumbers; + mgmol->getAtomicNumbers(anumbers); + if (MPIdata::onpe0) + { + std::cout << "Positions:" << std::endl; + std::vector::iterator ita = anumbers.begin(); + for (std::vector::iterator it = positions.begin(); + it != positions.end(); it += 3) + { + std::cout << *ita; + for (int i = 0; i < 3; i++) + std::cout << " " << *(it + i); + std::cout << std::endl; + ita++; + } + } + + Mesh* mymesh = Mesh::instance(); + const pb::Grid& mygrid = mymesh->grid(); + const pb::PEenv& myPEenv = mymesh->peenv(); + + HDFrestart h5file(ct.restart_file, myPEenv, ct.restart_file_type); + std::string name = "Function"; + int count = h5file.countFunctionObjects(name); + if (count != ct.numst) + { + std::cerr << "The number of functions in the restart file, " + << count << " is not equal to ct.numst, " << ct.numst + << std::endl; + MPI_Abort(mmpi.commSameSpin(), 0); + } + + std::shared_ptr projmatrices + = mgmol->getProjectedMatrices(); + + ExtendedGridOrbitals orbitals("new_orbitals", mygrid, mymesh->subdivx(), + ct.numst, ct.bcWF, projmatrices.get(), nullptr, nullptr, nullptr, + nullptr); + + // read numst_ wavefunction + int nread = orbitals.read_func_hdf5(h5file, name); + if (nread != ct.numst) + { + std::cerr << "The number of functions read from the restart file, " + << nread << " is not equal to ct.numst, " << ct.numst + << std::endl; + MPI_Abort(mmpi.commSameSpin(), 0); + } + + // set the iterative index to 1 to differentiate it from first instance + // in MGmol initial() function. This is not very clean and could be + // better designed, but works for now + orbitals.setIterativeIndex(1); + + // set initial DM with uniform occupations + projmatrices->setDMuniform(ct.getNelSpin(), 0); + projmatrices->printDM(std::cout); + + // + // evaluate energy and forces with wavefunctions just read + // + std::vector forces; + double eks = mgmol->evaluateDMandEnergyAndForces( + &orbitals, positions, anumbers, forces); + + // print out results + if (MPIdata::onpe0) + { + std::cout << "Eks : " << eks << std::endl; + std::cout << "Forces :" << std::endl; + for (std::vector::iterator it = forces.begin(); + it != forces.end(); it += 3) + { + for (int i = 0; i < 3; i++) + std::cout << " " << *(it + i); + std::cout << std::endl; + } + } + + delete mgmol; + + } // close main scope + + mgmol_finalize(); + + mpirc = MPI_Finalize(); + if (mpirc != MPI_SUCCESS) + { + std::cerr << "MPI Finalize failed!!!" << std::endl; + } + + time_t tt; + time(&tt); + if (onpe0) std::cout << " Run ended at " << ctime(&tt) << std::endl; + + return 0; +} diff --git a/tests/ShortSighted/test.py b/tests/ShortSighted/test.py index 9b731f4c..27da7f7d 100755 --- a/tests/ShortSighted/test.py +++ b/tests/ShortSighted/test.py @@ -48,7 +48,11 @@ restart_file=str(restart_file[:-1],'utf-8') print(restart_file) -os.symlink(restart_file, 'wave.out') +try: + os.symlink(restart_file, 'wave.out') +except FileExistsError: + os.remove('wave.out') + os.symlink(restart_file, 'wave.out') command = "{} {} -c {}".format(mpicmd,exe,inp2) output2 = subprocess.check_output(command,shell=True)