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

ipi: remove normalize_coord #3257

Merged
merged 4 commits into from
Feb 11, 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
5 changes: 3 additions & 2 deletions doc/install/install-from-c-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tar xzf libdeepmd_c.tar.gz

The library is built in Linux (GLIBC 2.17) with CUDA 12.2 (`libdeepmd_c.tar.gz`) or 11.8 (`libdeepmd_c_cu11.tar.gz`). It's noted that this package does not contain CUDA Toolkit and cuDNN, so one needs to download them from the NVIDIA website.

## Use Pre-compiled C Library to build the LAMMPS plugin and GROMACS patch
## Use Pre-compiled C Library to build the LAMMPS plugin, i-PI driver, and GROMACS patch

When one [installs DeePMD-kit's C++ interface](./install-from-source.md#install-deepmd-kits-c-interface), one can use the CMake argument `DEEPMD_C_ROOT` to the path `libdeepmd_c`.

Expand All @@ -27,4 +27,5 @@ make -j8
make install
```

Then one can follow the manual [Install LAMMPS](./install-lammps.md) and/or [Install GROMACS](./install-gromacs.md).
Then the i-PI driver `dp_ipi` will be built and installed.
One can also follow the manual [Install LAMMPS](./install-lammps.md) and/or [Install GROMACS](./install-gromacs.md).
5 changes: 1 addition & 4 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,7 @@ if(BUILD_CPP_IF)
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8)
# add_subdirectory (md/)
if(ENABLE_IPI
OR NOT BUILD_PY_IF
AND NOT DEEPMD_C_ROOT)
# ipi has a dependency on libdeepmd
if(ENABLE_IPI OR NOT BUILD_PY_IF)
add_subdirectory(ipi/)
endif()
if(NOT BUILD_PY_IF)
Expand Down
2 changes: 1 addition & 1 deletion source/ipi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ add_executable(${ipiname} ${DRIVER_SOURCE_FILES})
# link: libdeepmd_cc
if(DP_USING_C_API)
# SimulationRegion.h
target_link_libraries(${ipiname} PRIVATE ${LIB_DEEPMD_C} ${LIB_DEEPMD})
target_link_libraries(${ipiname} PRIVATE ${LIB_DEEPMD_C})
target_precompile_headers(${ipiname} PRIVATE [["deepmd.hpp"]])
remove_definitions(-D_GLIBCXX_USE_CXX11_ABI=${OP_CXX_ABI})
else()
Expand Down
23 changes: 0 additions & 23 deletions source/ipi/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace deepmd_compat = deepmd;
#include "deepmd.hpp"
namespace deepmd_compat = deepmd::hpp;
#endif
#include "SimulationRegion.h"
#include "XyzFileManager.h"
#include "json.hpp"
#include "sockets.h"
Expand Down Expand Up @@ -49,25 +48,6 @@ char *trimwhitespace(char *str) {
return str;
}

void normalize_coord(std::vector<double> &coord,
const SimulationRegion<double> &region) {
int natoms = coord.size() / 3;

for (int ii = 0; ii < natoms; ++ii) {
double inter[3];
region.phys2Inter(inter, &coord[3 * ii]);
for (int dd = 0; dd < 3; ++dd) {
inter[dd] -= int(floor(inter[dd]));
if (inter[dd] < 0) {
inter[dd] += 1.;
} else if (inter[dd] >= 1) {
inter[dd] -= 1.;
}
}
region.inter2Phys(&coord[3 * ii], inter);
}
}

int main(int argc, char *argv[]) {
if (argc == 1) {
std::cerr << "usage " << std::endl;
Expand Down Expand Up @@ -122,7 +102,6 @@ int main(int argc, char *argv[]) {
std::vector<double> dcoord_tmp;
std::vector<int> dtype = cvt.get_type();
std::vector<double> dbox(9, 0);
SimulationRegion<double> region;
double *msg_buff = NULL;
double ener;
double virial[9];
Expand Down Expand Up @@ -179,7 +158,6 @@ int main(int argc, char *argv[]) {
for (int dd = 0; dd < 9; ++dd) {
dbox[dd] = cell_h[(dd % 3) * 3 + (dd / 3)] * cvt_len;
}
region.reinitBox(&dbox[0]);

// get number of atoms
readbuffer_(&socket, (char *)(&cbuf), sizeof(int32_t));
Expand All @@ -203,7 +181,6 @@ int main(int argc, char *argv[]) {
dcoord_tmp[ii] = msg_buff[ii] * cvt_len;
}
cvt.forward(dcoord, dcoord_tmp, 3);
normalize_coord(dcoord, region);

// nnp over writes ener, force and virial
nnp_inter.compute(dener, dforce_tmp, dvirial, dcoord, dtype, dbox);
Expand Down
40 changes: 35 additions & 5 deletions source/ipi/tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def write_input(self, atoms, **kwargs):
atoms.write(self.xyz_file, format="xyz")


class TestDeepPotALargeBoxNoPBC(unittest.TestCase):
class TestDPIPI(unittest.TestCase):
# copy from test_deeppot_a.py
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -193,8 +193,8 @@ def test_ase_unix(self):
cell=self.box.reshape((3, 3)),
calculator=calc,
)
ee = water.get_potential_energy()
ff = water.get_forces()
ee = water.get_potential_energy()
ff = water.get_forces()
nframes = 1
np.testing.assert_almost_equal(
ff.ravel(), self.expected_f.ravel(), default_places
Expand All @@ -213,8 +213,38 @@ def test_ase_nounix(self):
cell=self.box.reshape((3, 3)),
calculator=calc,
)
ee = water.get_potential_energy()
ff = water.get_forces()
ee = water.get_potential_energy()
ff = water.get_forces()
nframes = 1
np.testing.assert_almost_equal(
ff.ravel(), self.expected_f.ravel(), default_places
)
expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis=1)
np.testing.assert_almost_equal(ee.ravel(), expected_se.ravel(), default_places)

def test_normalize_coords(self):
# coordinate nomarlization should happen inside the interface
cell = self.box.reshape((3, 3))
coord = self.coords.reshape((-1, 3))
# random unwrap coords
coord[0] += np.array([3, 0, 0]) @ cell
coord[1] += np.array([0, -3, 0]) @ cell
coord[2] += np.array([0, 0, 3]) @ cell
coord[3] += np.array([-3, 0, 0]) @ cell
coord[4] += np.array([0, 3, 0]) @ cell
coord[5] += np.array([0, 0, -3]) @ cell
with SocketIOCalculator(
DPiPICalculator(self.model_file, use_unix=False),
log=sys.stdout,
) as calc:
water = Atoms(
"OHHOHH",
positions=coord,
cell=cell,
calculator=calc,
)
ee = water.get_potential_energy()
ff = water.get_forces()
nframes = 1
np.testing.assert_almost_equal(
ff.ravel(), self.expected_f.ravel(), default_places
Expand Down