Skip to content

Commit

Permalink
support multiple frames DeepPot in C/hpp API (#2309)
Browse files Browse the repository at this point in the history
* Add DeepPot C API v2 to support multiple frames. Also, preserve the
arguments for fparam and aparam for future use (planned in #2236). V1 is
kept for API and ABI compatibility.
* Support multiple frames for DeepPot hpp API. The API compatibility is
kept. Add tests for new situation.

---------

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
  • Loading branch information
njzjz authored Feb 13, 2023
1 parent d16231f commit a98b368
Show file tree
Hide file tree
Showing 5 changed files with 1,168 additions and 79 deletions.
166 changes: 166 additions & 0 deletions source/api_c/include/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extern DP_DeepPot* DP_NewDeepPotWithParam(const char* c_model,

/**
* @brief Evaluate the energy, force and virial by using a DP. (double version)
* @attention The number of frames is assumed to be 1.
* @param[in] dp The DP to use.
* @param[in] natoms The number of atoms.
* @param[in] coord The coordinates of atoms. The array should be of size natoms
Expand Down Expand Up @@ -77,6 +78,7 @@ extern void DP_DeepPotCompute(DP_DeepPot* dp,

/**
* @brief Evaluate the energy, force and virial by using a DP. (float version)
* @attention The number of frames is assumed to be 1.
* @param[in] dp The DP to use.
* @param[in] natoms The number of atoms.
* @param[in] coord The coordinates of atoms. The array should be of size natoms
Expand Down Expand Up @@ -108,6 +110,7 @@ extern void DP_DeepPotComputef(DP_DeepPot* dp,
/**
* @brief Evaluate the energy, force and virial by using a DP with the neighbor
*list. (double version)
* @attention The number of frames is assumed to be 1.
* @param[in] dp The DP to use.
* @param[in] natoms The number of atoms.
* @param[in] coord The coordinates of atoms. The array should be of size natoms
Expand Down Expand Up @@ -145,6 +148,7 @@ extern void DP_DeepPotComputeNList(DP_DeepPot* dp,
/**
* @brief Evaluate the energy, force and virial by using a DP with the neighbor
*list. (float version)
* @attention The number of frames is assumed to be 1.
* @param[in] dp The DP to use.
* @param[in] natoms The number of atoms.
* @param[in] coord The coordinates of atoms. The array should be of size natoms
Expand Down Expand Up @@ -179,6 +183,168 @@ extern void DP_DeepPotComputeNListf(DP_DeepPot* dp,
float* atomic_energy,
float* atomic_virial);

/**
* @brief Evaluate the energy, force and virial by using a DP. (double version)
* @version 2
* @param[in] dp The DP to use.
* @param[in] nframes The number of frames.
* @param[in] natoms The number of atoms.
* @param[in] coord The coordinates of atoms. The array should be of size natoms
*x 3.
* @param[in] atype The atom types. The array should contain natoms ints.
* @param[in] box The cell of the region. The array should be of size 9. Pass
*NULL if pbc is not used.
* @param[in] fparam The frame parameters. (not work at this time)
* @param[in] aparam The atom parameters. (not work at this time)
* @param[out] energy Output energy.
* @param[out] force Output force. The array should be of size natoms x 3.
* @param[out] virial Output virial. The array should be of size 9.
* @param[out] atomic_energy Output atomic energy. The array should be of size
*natoms.
* @param[out] atomic_virial Output atomic virial. The array should be of size
*natoms x 9.
* @warning The output arrays should be allocated before calling this function.
*Pass NULL if not required.
**/
extern void DP_DeepPotCompute2(DP_DeepPot* dp,
const int nframes,
const int natom,
const double* coord,
const int* atype,
const double* cell,
const double* fparam,
const double* aparam,
double* energy,
double* force,
double* virial,
double* atomic_energy,
double* atomic_virial);

/**
* @brief Evaluate the energy, force and virial by using a DP. (float version)
* @version 2
* @param[in] dp The DP to use.
* @param[in] nframes The number of frames.
* @param[in] natoms The number of atoms.
* @param[in] coord The coordinates of atoms. The array should be of size natoms
*x 3.
* @param[in] atype The atom types. The array should contain natoms ints.
* @param[in] box The cell of the region. The array should be of size 9. Pass
*NULL if pbc is not used.
* @param[in] fparam The frame parameters. (not work at this time)
* @param[in] aparam The atom parameters. (not work at this time)
* @param[out] energy Output energy.
* @param[out] force Output force. The array should be of size natoms x 3.
* @param[out] virial Output virial. The array should be of size 9.
* @param[out] atomic_energy Output atomic energy. The array should be of size
*natoms.
* @param[out] atomic_virial Output atomic virial. The array should be of size
*natoms x 9.
* @warning The output arrays should be allocated before calling this function.
*Pass NULL if not required.
**/
extern void DP_DeepPotComputef2(DP_DeepPot* dp,
const int nframes,
const int natom,
const float* coord,
const int* atype,
const float* cell,
const float* fparam,
const float* aparam,
double* energy,
float* force,
float* virial,
float* atomic_energy,
float* atomic_virial);

/**
* @brief Evaluate the energy, force and virial by using a DP with the neighbor
*list. (double version)
* @version 2
* @param[in] dp The DP to use.
* @param[in] nframes The number of frames.
* @param[in] natoms The number of atoms.
* @param[in] coord The coordinates of atoms. The array should be of size natoms
*x 3.
* @param[in] atype The atom types. The array should contain natoms ints.
* @param[in] box The cell of the region. The array should be of size 9. Pass
*NULL if pbc is not used.
* @param[in] nghost The number of ghost atoms.
* @param[in] nlist The neighbor list.
* @param[in] ago Update the internal neighbour list if ago is 0.
* @param[in] fparam The frame parameters. (not work at this time)
* @param[in] aparam The atom parameters. (not work at this time)
* @param[out] energy Output energy.
* @param[out] force Output force. The array should be of size natoms x 3.
* @param[out] virial Output virial. The array should be of size 9.
* @param[out] atomic_energy Output atomic energy. The array should be of size
*natoms.
* @param[out] atomic_virial Output atomic virial. The array should be of size
*natoms x 9.
* @warning The output arrays should be allocated before calling this function.
*Pass NULL if not required.
**/
extern void DP_DeepPotComputeNList2(DP_DeepPot* dp,
const int nframes,
const int natom,
const double* coord,
const int* atype,
const double* cell,
const int nghost,
const DP_Nlist* nlist,
const int ago,
const double* fparam,
const double* aparam,
double* energy,
double* force,
double* virial,
double* atomic_energy,
double* atomic_virial);

/**
* @brief Evaluate the energy, force and virial by using a DP with the neighbor
*list. (float version)
* @version 2
* @param[in] dp The DP to use.
* @param[in] nframes The number of frames.
* @param[in] natoms The number of atoms.
* @param[in] coord The coordinates of atoms. The array should be of size natoms
*x 3.
* @param[in] atype The atom types. The array should contain natoms ints.
* @param[in] box The cell of the region. The array should be of size 9. Pass
*NULL if pbc is not used.
* @param[in] nghost The number of ghost atoms.
* @param[in] nlist The neighbor list.
* @param[in] ago Update the internal neighbour list if ago is 0.
* @param[in] fparam The frame parameters. (not work at this time)
* @param[in] aparam The atom parameters. (not work at this time)
* @param[out] energy Output energy.
* @param[out] force Output force. The array should be of size natoms x 3.
* @param[out] virial Output virial. The array should be of size 9.
* @param[out] atomic_energy Output atomic energy. The array should be of size
*natoms.
* @param[out] atomic_virial Output atomic virial. The array should be of size
*natoms x 9.
* @warning The output arrays should be allocated before calling this function.
*Pass NULL if not required.
**/
extern void DP_DeepPotComputeNListf2(DP_DeepPot* dp,
const int nframes,
const int natom,
const float* coord,
const int* atype,
const float* cell,
const int nghost,
const DP_Nlist* nlist,
const int ago,
const float* fparam,
const float* aparam,
double* energy,
float* force,
float* virial,
float* atomic_energy,
float* atomic_virial);

/**
* @brief The deep potential model deviation.
**/
Expand Down
Loading

0 comments on commit a98b368

Please sign in to comment.