Skip to content
Snippets Groups Projects
Commit f3e8f856 authored by mkirsz's avatar mkirsz
Browse files

Update for multi cutoff and descriptors

parent 205fed3b
No related branches found
No related tags found
1 merge request!11Develop
Pipeline #49537 passed
......@@ -112,6 +112,7 @@ FetchContent_Declare(
FetchContent_MakeAvailable(Tadah.MD)
add_library(tadah.lammps STATIC lammps_tadah.cpp)
target_include_directories(tadah.lammps PRIVATE .)
target_link_libraries(tadah.lammps PUBLIC tadah.md)
target_link_libraries(tadah.lammps PUBLIC tadah.core)
......
......@@ -13,4 +13,4 @@ models_src=$(dir)/_deps/tadah.models-src/include
md_src=$(dir)/_deps/tadah.md-src/include
cmrc_src=$(dir)/_cmrc/include
tadah_inc=-I$(core_src) -I$(models_src) -I$(md_src) -I$(toml_src) -I$(cmrc_src)
\ No newline at end of file
tadah_inc=-I$(core_src) -I$(models_src) -I$(md_src) -I$(toml_src) -I$(cmrc_src) -I../../lib/$(lib)
This diff is collapsed.
......@@ -11,6 +11,11 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/*----------------------------------------------------------------------*/
/* Contributing author: Marcin Kirsz | marcin.kirsz@ed.ac.uk */
/* The University of Edinburgh | https://git.ecdf.ed.ac.uk/tadah */
/*----------------------------------------------------------------------*/
#ifdef PAIR_CLASS
// clang-format off
PairStyle(tadah,PairTadah)
......@@ -21,7 +26,7 @@ PairStyle(tadah,PairTadah)
#define LMP_PAIR_TADAH_H
#include "pair.h"
#include "../../lib/tadah.lammps/lammps_tadah.h"
#include <lammps_tadah.h>
namespace LAMMPS_NS {
......@@ -38,7 +43,7 @@ namespace LAMMPS_NS {
void compute_dimers(int eflag, int vflag);
std::vector<std::pair<int,int>> midx;
TADAH::LammpsTadah lt;
TADAH::LammpsTadah *lt=nullptr;
int nmax=0;
void allocate();
......
#include "lammps_tadah.h"
#include <lammps_tadah.h>
#include <tadah/core/periodic_table.h>
using namespace TADAH;
// // Const Assignment operator
// LammpsTadah &LammpsTadah::operator=(const LammpsTadah& lt)
// {
// c=lt.c;
// norm=lt.norm;
// bias=lt.bias;
// dsize=lt.dsize;
// cutoff_max_sq=lt.cutoff_max_sq;
// cutoff_max=lt.cutoff_max;
// linear=lt.linear;
// dimer=lt.dimer;
// dimer_r=lt.dimer_r;
// dimer_bond_bool=lt.dimer_bond_bool;
// init2b=lt.init2b;
// initmb=lt.initmb;
// watom=lt.watom;
// S=lt.S;
// // We need deep copy for fb and model.
// // For now we just init them the same way
// // as constructor does
// fb = CONFIG::factory<Function_Base,Config&>(
// c.get<std::string>("MODEL",1),c);
// model = CONFIG::factory<M_MD_Base,Function_Base&,Config&>(
// c.get<std::string>("MODEL",0),*fb,c);
// aeds=lt.aeds;
// rhos=lt.rhos;
// return *this;
// }
LammpsTadah &LammpsTadah::operator=(LammpsTadah& lt)
{
std::swap(c,lt.c);
std::swap(norm , lt.norm);
std::swap(bias,lt.bias);
std::swap(dsize,lt.dsize);
std::swap(cutoff_max_sq,lt.cutoff_max_sq);
std::swap(cutoff_max,lt.cutoff_max);
std::swap(linear,lt.linear);
std::swap(dimer,lt.dimer);
std::swap(dimer_r,lt.dimer_r);
std::swap(dimer_bond_bool,lt.dimer_bond_bool);
std::swap(init2b,lt.init2b);
std::swap(initmb,lt.initmb);
std::swap(watom,lt.watom);
S=lt.S;
std::swap(fb,lt.fb);
std::swap(model,lt.model);
aeds=lt.aeds;
rhos=lt.rhos;
return *this;
}
LammpsTadah::LammpsTadah():
fb(nullptr),
model(nullptr)
{}
LammpsTadah::LammpsTadah(int narg, char **arg):
c(arg[2]),
norm(c.get<bool>("NORM") && !(c("MODEL")[1]=="BF_Linear" || c("MODEL")[1]=="Kern_Linear")),
//bias(c.get<bool>("BIAS")),
cutoff_max_sq(pow(c.get<double>("RCUTMAX"),2)),
cutoff_max(c.get<double>("RCUTMAX")),
linear(c("MODEL")[1]=="BF_Linear" || c("MODEL")[1]=="Kern_Linear"),
......@@ -70,26 +15,23 @@ LammpsTadah::LammpsTadah(int narg, char **arg):
init2b(c.get<bool>("INIT2B")),
initmb(c.get<bool>("INITMB")),
S(c),
fb(nullptr),
model(nullptr)
fb(CONFIG::factory<Function_Base,Config&>(
c.get<std::string>("MODEL",1),c)),
model(CONFIG::factory<M_MD_Base,Function_Base&,Config&>(
c.get<std::string>("MODEL",0),*fb,c))
{
// check does pot file exists
std::ifstream f(arg[2]);
if(!f.good())
throw std::runtime_error("Pot file does not exists.\n");
// Map LAMMPS atom types to weight factors
// e.g. pair_coaeff * * pot.tadah Ti Nb NULL
watom.resize(narg-3); // this includes NULL values
// watom.resize(narg-3); // this includes NULL values
Z.resize(narg-3); // this includes NULL values
// which want be set
for (int i=3; i<narg; ++i) {
std::string symbol=arg[i];
if (symbol=="NULL") continue;
size_t j=0;
for (j=0; j<c.size("ATOMS"); ++j) {
if (c.get<std::string>("ATOMS", j)==symbol) {
watom[i-3] = c.get<double>("WATOMS",j);
Z[i-3] = PeriodicTable::find_by_symbol(symbol).Z;
break;
}
}
......@@ -97,11 +39,6 @@ LammpsTadah::LammpsTadah(int narg, char **arg):
throw std::runtime_error("Symbol not in potential file: "+symbol);
}
fb = CONFIG::factory<Function_Base,Config&>(
c.get<std::string>("MODEL",1),c);
model = CONFIG::factory<M_MD_Base,Function_Base&,Config&>(
c.get<std::string>("MODEL",0),*fb,c);
// bias affects position of fidx for descriptors
if (c.get<bool>("BIAS"))
bias++;
......@@ -121,6 +58,7 @@ LammpsTadah::LammpsTadah(int narg, char **arg):
c.add("SIZEMB",S.dmb->size());
dsize+=S.dmb->size();
S.dmb->set_fidx(bias+S.d2b->size());
rsize = S.dmb->rhoi_size()+ S.dmb->rhoip_size();
}
else {
c.add("SIZEMB",0);
......
......@@ -14,59 +14,50 @@
#include <iostream>
#include <string>
/**
* LAMMPS INTERFACE
*/
namespace TADAH {
class LammpsTadah {
public:
Config c;
bool norm;
size_t bias=0;
size_t dsize=0;
double cutoff_max_sq;
double cutoff_max;
bool linear;
bool dimer;
double dimer_r;
bool dimer_bond_bool;
bool init2b;
bool initmb;
std::vector<double> watom;
DC_Selector S;
Function_Base *fb=nullptr;
M_MD_Base *model=nullptr;
aeds_type2 aeds;
rhos_type rhos;
// Const Assignment operator
//LammpsTadah& operator=(const LammpsTadah& lt);
// Assignment operator
LammpsTadah& operator=(LammpsTadah& lt);
// Constructor:
LammpsTadah();
LammpsTadah(int narg, char **arg);
~LammpsTadah();
int pack_reverse_linear(int n, int first, double *buf);
void unpack_reverse_linear(int n, int *list, double *buf);
// Pack the derivative of the embedding func
int pack_forward_linear(int n, int *list, double *buf);
// Unpack the derivative of the embedding func
void unpack_forward_linear(int n, int first, double *buf);
// NONLINEAR
int pack_reverse_nonlinear(int n, int first, double *buf);
void unpack_reverse_nonlinear(int n, int *list, double *buf);
int pack_forward_nonlinear(int n, int *list, double *buf);
void unpack_forward_nonlinear(int n, int first, double *buf);
};
class LammpsTadah {
public:
Config c;
bool norm;
size_t bias=0;
size_t dsize=0; // descriptor dim inc bias
size_t rsize=0; // rho dim inc derivative
double cutoff_max_sq;
double cutoff_max;
bool linear;
bool dimer;
double dimer_r;
bool dimer_bond_bool;
bool init2b;
bool initmb;
std::vector<int> Z;
DC_Selector S;
Function_Base *fb=nullptr;
M_MD_Base *model=nullptr;
aeds_type2 aeds;
rhos_type rhos;
LammpsTadah(int narg, char **arg);
~LammpsTadah();
LammpsTadah(const LammpsTadah&) = delete;
LammpsTadah& operator=(const LammpsTadah&) = delete;
int pack_reverse_linear(int n, int first, double *buf);
void unpack_reverse_linear(int n, int *list, double *buf);
// Pack the derivative of the embedding func
int pack_forward_linear(int n, int *list, double *buf);
// Unpack the derivative of the embedding func
void unpack_forward_linear(int n, int first, double *buf);
// NONLINEAR
int pack_reverse_nonlinear(int n, int first, double *buf);
void unpack_reverse_nonlinear(int n, int *list, double *buf);
int pack_forward_nonlinear(int n, int *list, double *buf);
void unpack_forward_nonlinear(int n, int first, double *buf);
};
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment