diff --git a/include/tadah/mlip/analytics/analytics.h b/include/tadah/mlip/analytics/analytics.h index 7dd101694959a1e0c4036d525bf8c8820dfc4ef9..3a202536ca3e46964dc0e4846c2287686a596852 100644 --- a/include/tadah/mlip/analytics/analytics.h +++ b/include/tadah/mlip/analytics/analytics.h @@ -3,6 +3,8 @@ #include <tadah/mlip/structure_db.h> #include <tadah/core/core_types.h> +namespace tadah { +namespace mlip { /** Class for analysing and comparing datasets @@ -17,40 +19,42 @@ class Analytics { Analytics(const StructureDB &st, const StructureDB &stp); /** Return Energy/atom Mean Absolute Error for each DBFILE. */ - t_type calc_e_mae() const; + tadah::core::t_type calc_e_mae() const; /** Return Force Mean Absolute Error for each DBFILE. */ - t_type calc_f_mae() const; + tadah::core::t_type calc_f_mae() const; /** Return Stress Mean Absolute Error for each DBFILE. * * Calculated using 6 independed components. */ - t_type calc_s_mae() const; + tadah::core::t_type calc_s_mae() const; /** Return Energy/atom Relative Root Mean Square Error for each DBFILE. */ - t_type calc_e_rrmse() const; + tadah::core::t_type calc_e_rrmse() const; /** Return Energy/atom Root Mean Square Error for each DBFILE. */ - t_type calc_e_rmse() const; + tadah::core::t_type calc_e_rmse() const; /** Return Force Root Mean Square Error for each DBFILE. */ - t_type calc_f_rmse() const; + tadah::core::t_type calc_f_rmse() const; /** Return Stress Root Mean Square Error for each DBFILE. * * Calculated using 6 independed components. */ - t_type calc_s_rmse() const; + tadah::core::t_type calc_s_rmse() const; /** Return Energy/atom coefficient of determination for each DBFILE. */ - t_type calc_e_r_sq() const; + tadah::core::t_type calc_e_r_sq() const; /** Return Force coefficient of determination for each DBFILE. */ - t_type calc_f_r_sq() const; + tadah::core::t_type calc_f_r_sq() const; /** Return Stress coefficient of determination for each DBFILE. */ - t_type calc_s_r_sq() const; + tadah::core::t_type calc_s_r_sq() const; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/analytics/statistics.h b/include/tadah/mlip/analytics/statistics.h index 4bd75bfc92cbccaf9b224c0666da0a62228544f4..047c97520f25c9429723d4d50780752262475fb5 100644 --- a/include/tadah/mlip/analytics/statistics.h +++ b/include/tadah/mlip/analytics/statistics.h @@ -2,10 +2,12 @@ #define STATISTICS_H #include <tadah/core/core_types.h> +namespace tadah { +namespace mlip { /** Some basis statistical tools */ class Statistics { - using vec = aed_type; + using vec = tadah::core::aed_type; public: /** Residual sum of squares. */ static double res_sum_sq(const vec &obs, const vec &pred); @@ -23,4 +25,6 @@ class Statistics { static double mean(const vec &v); }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/atom.h b/include/tadah/mlip/atom.h index 385eef7bb7739dff3cba5e03461150d4728d9e67..b87160977f1622d98ed3171094fc71b27c862ffe 100644 --- a/include/tadah/mlip/atom.h +++ b/include/tadah/mlip/atom.h @@ -6,6 +6,8 @@ #include <string> #include <iostream> +namespace tadah { +namespace mlip { /** * Container to represent atom properties @@ -18,7 +20,7 @@ * # set atom symbol * atom.symbol="Ti" * - * # set atom name, atomic number... see Element class for attributes + * # set atom name, atomic number... see tadah::core::Element class for attributes * * # set atom position to (1.1, 2.2, 3.3) * atom.position(0) = 1.1; @@ -34,7 +36,7 @@ * * # Use constructor to fully initialise this object * # with the position and force as in the example above - * Element element = PeriodicTable().find_by_symbol("Ti"); + * tadah::core::Element element = tadah::core::PeriodicTable().find_by_symbol("Ti"); * Atom atom(element, 1.1, 2.2, 3.3, 0.1, -0.2, 0.3); * * Usage example: @@ -47,7 +49,7 @@ * * @see Structure */ -struct Atom: public Element { +struct Atom: public tadah::core::Element { /** * Create an empty atom object. All class attributes are left uninitialised. */ @@ -55,29 +57,29 @@ struct Atom: public Element { /** This constructor fully initialise this object * - * @param[in] element Chemical Element + * @param[in] element Chemical tadah::core::Element * @param[in] px,py,pz Atomic coordinates * @param[in] fx,fy,fz Force acting on the atom * */ - Atom(const Element &element, + Atom(const tadah::core::Element &element, const double px, const double py, const double pz, const double fx, const double fy, const double fz); /** This constructor fully initialise this object with zero force * - * @param[in] element Chemical Element + * @param[in] element Chemical tadah::core::Element * @param[in] px,py,pz Atomic coordinates * */ - Atom(const Element &element, + Atom(const tadah::core::Element &element, const double px, const double py, const double pz); /** Hold position of the atom. */ - Vec3d position; + tadah::core::Vec3d position; /** Hold force on the atom. */ - Vec3d force; + tadah::core::Vec3d force; /** Print object summary to the stream */ friend std::ostream& operator<<(std::ostream& os, const Atom& atom); @@ -95,4 +97,6 @@ struct Atom: public Element { bool is_the_same(const Atom &, double thr=1e-6) const; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/data_providers/aflow_data_provider.h b/include/tadah/mlip/data_providers/aflow_data_provider.h index 31b0064228bd96e3a98106ac2a131570221c740c..ecb67ba23eec2f29960a9004c093f9ef6eb306cc 100644 --- a/include/tadah/mlip/data_providers/aflow_data_provider.h +++ b/include/tadah/mlip/data_providers/aflow_data_provider.h @@ -3,6 +3,8 @@ #include <tadah/mlip/data_providers/imaterials_data_provider.h> #include <string> +namespace tadah { +namespace mlip { /** * @brief Provides raw JSON data from AFLOW by an AUID query. @@ -53,5 +55,7 @@ private: RawResponse fetchAndParseAflowByAuid(const std::string &auid); }; +} // namespace mlip +} // namespace tadah #endif // TADAH_MLIP_DATA_PROVIDERS_AFLOW_DATA_PROVIDER_H diff --git a/include/tadah/mlip/data_providers/cod_data_provider.h b/include/tadah/mlip/data_providers/cod_data_provider.h index 8e5df0654c6759877aa2196191ad58c884bd0a2c..1511bc7699e0b55dd83922a4c3f6d424dde96867 100644 --- a/include/tadah/mlip/data_providers/cod_data_provider.h +++ b/include/tadah/mlip/data_providers/cod_data_provider.h @@ -3,6 +3,8 @@ #include <tadah/mlip/data_providers/imaterials_data_provider.h> #include <string> +namespace tadah { +namespace mlip { /** * @brief Provides raw CIF data from the Crystallography Open Database (COD) @@ -58,5 +60,7 @@ private: RawResponse fetchFromURL(const std::string &url); }; +} // namespace mlip +} // namespace tadah #endif // TADAH_MLIP_DATA_PROVIDERS_COD_DATA_PROVIDER_H diff --git a/include/tadah/mlip/data_providers/imaterials_data_provider.h b/include/tadah/mlip/data_providers/imaterials_data_provider.h index 20884d2f9ed224774eaa1b009dbcefe524f558f4..20e9c2e8f64b6e34ebf91dab298dea65d4c83d17 100644 --- a/include/tadah/mlip/data_providers/imaterials_data_provider.h +++ b/include/tadah/mlip/data_providers/imaterials_data_provider.h @@ -2,6 +2,8 @@ #define TADAH_MLIP_DATA_PROVIDERS_IMATERIALS_DATA_PROVIDER_H #include <string> +namespace tadah { +namespace mlip { /** * @brief Encapsulates the raw result of an HTTP request to a materials-database service. @@ -68,5 +70,7 @@ public: // Additional placeholders can be added for asynchronous operations (6.5). }; +} // namespace mlip +} // namespace tadah #endif // TADAH_MLIP_DATA_PROVIDERS_IMATERIALS_DATA_PROVIDER_H diff --git a/include/tadah/mlip/data_providers/materials_project_data_provider.h b/include/tadah/mlip/data_providers/materials_project_data_provider.h index 47f2e0c7fb3bbf87f58e5834cc26aeda013011a5..d24c22b37be360dd50764434e018bcba877247a2 100644 --- a/include/tadah/mlip/data_providers/materials_project_data_provider.h +++ b/include/tadah/mlip/data_providers/materials_project_data_provider.h @@ -3,6 +3,8 @@ #include <tadah/mlip/data_providers/imaterials_data_provider.h> #include <string> +namespace tadah { +namespace mlip { /** * @brief Retrieves raw JSON from the Materials Project API (v2 / v3). @@ -45,5 +47,7 @@ private: RawResponse httpGet(const std::string &url); }; +} // namespace mlip +} // namespace tadah #endif // TADAH_MLIP_DATA_PROVIDERS_MATERIALS_PROJECT_DATA_PROVIDER_H diff --git a/include/tadah/mlip/data_providers/nomad_data_provider.h b/include/tadah/mlip/data_providers/nomad_data_provider.h index 0d3bf513d04af62f79951de0554e53f4114d02f2..d895dda7ed91b2d29c944a2c3ed7b8a52a9e64fc 100644 --- a/include/tadah/mlip/data_providers/nomad_data_provider.h +++ b/include/tadah/mlip/data_providers/nomad_data_provider.h @@ -3,6 +3,8 @@ #include <tadah/mlip/data_providers/imaterials_data_provider.h> #include <string> +namespace tadah { +namespace mlip { /** * @brief Provides raw data from NOMAD by making HTTP POST requests to: @@ -60,5 +62,7 @@ private: RawResponse httpPost(const std::string &url, const std::string &jsonBody); }; +} // namespace mlip +} // namespace tadah #endif // TADAH_MLIP_DATA_PROVIDERS_NOMAD_DATA_PROVIDER_H diff --git a/include/tadah/mlip/dataset_readers/castep_castep_reader.h b/include/tadah/mlip/dataset_readers/castep_castep_reader.h index 794a1144c29a4ed44c7c5abf65a88e26dc90f68c..8363cb6126f5b6eb03d1f5479ebab2ff343c75c9 100644 --- a/include/tadah/mlip/dataset_readers/castep_castep_reader.h +++ b/include/tadah/mlip/dataset_readers/castep_castep_reader.h @@ -10,6 +10,8 @@ #include <sstream> #include <vector> #include <stdexcept> +namespace tadah { +namespace mlip { /** * @class CastepCastepReader * @brief A class for reading and parsing CASTEP .castep files. @@ -85,6 +87,8 @@ protected: }; +} // namespace mlip +} // namespace tadah #endif // CASTEP_CASTEP_READER_H diff --git a/include/tadah/mlip/dataset_readers/castep_geom_reader.h b/include/tadah/mlip/dataset_readers/castep_geom_reader.h index f44dc7231d6e6abad416b5f22ea01ab3893d94c4..32a3186be102d0dfcb5dba7b31f73a93275f5140 100644 --- a/include/tadah/mlip/dataset_readers/castep_geom_reader.h +++ b/include/tadah/mlip/dataset_readers/castep_geom_reader.h @@ -10,6 +10,8 @@ #include <sstream> #include <vector> #include <stdexcept> +namespace tadah { +namespace mlip { /** * @class CastepGeomReader @@ -62,5 +64,7 @@ private: }; +} // namespace mlip +} // namespace tadah #endif // CASTEP_GEOM_READER_H diff --git a/include/tadah/mlip/dataset_readers/castep_md_reader.h b/include/tadah/mlip/dataset_readers/castep_md_reader.h index 8ef93cff2537900fe1d137b8bc354d7cdc315a6f..7888ba12210b89f2b6e84505b9aa687da6308e05 100644 --- a/include/tadah/mlip/dataset_readers/castep_md_reader.h +++ b/include/tadah/mlip/dataset_readers/castep_md_reader.h @@ -10,6 +10,8 @@ #include <sstream> #include <vector> #include <stdexcept> +namespace tadah { +namespace mlip { /** * @class CastepMDReader @@ -114,5 +116,7 @@ private: }; +} // namespace mlip +} // namespace tadah #endif // CASTEP_MD_READER_H diff --git a/include/tadah/mlip/dataset_readers/dataset_reader.h b/include/tadah/mlip/dataset_readers/dataset_reader.h index a83ab7e012fdfd8d4a1ef77edad4ad0b6d9ae529..50e83847f01223d16d824fa4f2cdf2cbf29ec447 100644 --- a/include/tadah/mlip/dataset_readers/dataset_reader.h +++ b/include/tadah/mlip/dataset_readers/dataset_reader.h @@ -4,6 +4,8 @@ #include <tadah/mlip/structure_db.h> #include <string> #include <vector> +namespace tadah { +namespace mlip { /** * @class DatasetReader @@ -83,4 +85,6 @@ private: virtual std::string get_first_label(std::string &); virtual std::string get_label(std::string &); }; +} // namespace mlip +} // namespace tadah #endif // DATASET_READER_H diff --git a/include/tadah/mlip/dataset_readers/dataset_reader_selector.h b/include/tadah/mlip/dataset_readers/dataset_reader_selector.h index a09803ecc532770a28e191be52666ad02897b69a..17a2c2bba0459bf7ff61436bdcfdcf2b35b72aeb 100644 --- a/include/tadah/mlip/dataset_readers/dataset_reader_selector.h +++ b/include/tadah/mlip/dataset_readers/dataset_reader_selector.h @@ -5,6 +5,8 @@ #include <tadah/mlip/dataset_readers/dataset_reader.h> #include <string> #include <memory> +namespace tadah { +namespace mlip { /** * @class DatasetReaderSelector @@ -31,4 +33,6 @@ public: }; +} // namespace mlip +} // namespace tadah #endif // DATASET_READER_SELECTOR_H diff --git a/include/tadah/mlip/dataset_readers/vasp_outcar_reader.h b/include/tadah/mlip/dataset_readers/vasp_outcar_reader.h index 34c861a26cc041f7331a3e2bcbea0211a2150ff8..e9899d6fcc87272e9fa087ee346ebca05b205534 100644 --- a/include/tadah/mlip/dataset_readers/vasp_outcar_reader.h +++ b/include/tadah/mlip/dataset_readers/vasp_outcar_reader.h @@ -4,6 +4,8 @@ #include <tadah/mlip/structure_db.h> #include <tadah/mlip/dataset_readers/dataset_reader.h> #include <string> +namespace tadah { +namespace mlip { /** * @class VaspOutcarReader @@ -77,4 +79,6 @@ private: double s_conv = 6.241509074e-4; // kbar -> eV/A^3 }; +} // namespace mlip +} // namespace tadah #endif // VASP_OUTCAR_READER_H diff --git a/include/tadah/mlip/dataset_readers/vasp_vasprun_reader.h b/include/tadah/mlip/dataset_readers/vasp_vasprun_reader.h index b43e279f822909b7a0660d0c5d1274824f863384..855ffe0cda25eb8944199ef317f3431a157a24e3 100644 --- a/include/tadah/mlip/dataset_readers/vasp_vasprun_reader.h +++ b/include/tadah/mlip/dataset_readers/vasp_vasprun_reader.h @@ -8,6 +8,8 @@ #include <string> #include <vector> #include <iostream> +namespace tadah { +namespace mlip { namespace rx = rapidxml; @@ -163,4 +165,6 @@ private: double s_conv = 6.241509074e-4; // kbar -> eV/A^3 }; +} // namespace mlip +} // namespace tadah #endif // VASP_VASPRUN_READER_H diff --git a/include/tadah/mlip/descriptors_calc.h b/include/tadah/mlip/descriptors_calc.h index 14d1c4be9194f599cac14a0e27de32b9b63a8e1a..ef8df5c5681367a833f05073170e4f8b23d25a90 100644 --- a/include/tadah/mlip/descriptors_calc.h +++ b/include/tadah/mlip/descriptors_calc.h @@ -12,13 +12,15 @@ #include <tadah/models/descriptors/dm/dm_base.h> #include <tadah/models/cutoffs.h> +namespace tadah { +namespace mlip { /** \brief Descriptors calculator * * This object does not store any data. * * Usage example: * \code{.cpp} - * # Build calculator using Config object. + * # Build calculator using tadah::core::Config object. * DescriptorsCalc<D2_LJ, D3_Dummy, DM_Dummy> dc(config); * * # Calculate all descriptors in a Structure st @@ -29,7 +31,7 @@ * \endcode * * This object sets the following \ref INTERNAL_KEYS - * to the provided Config object: + * to the provided tadah::core::Config object: * * \ref SIZE2B,\ref SIZE3B,\ref SIZEMB,\ref DSIZE * @@ -49,7 +51,7 @@ template <typename D2=D2_Base&, typename D3=D3_Base&, typename DM=DM_Base&, type class DescriptorsCalc: public DC_Base { public: - Config &config; + tadah::core::Config &config; /** Constructor to fully initialise this object. * * REQUIRED CONFIG KEYS: @@ -57,7 +59,7 @@ class DescriptorsCalc: public DC_Base { * at least one of: \ref RCUT2B, \ref RCUT3B,\ref RCUTMB * */ - DescriptorsCalc(Config &c); + DescriptorsCalc(tadah::core::Config &c); /** This constructor is equivalent to the main constructor above. * @@ -72,7 +74,7 @@ class DescriptorsCalc: public DC_Base { * * Usage example: * \code{.cpp} - * # Build calculator using Config object. + * # Build calculator using tadah::core::Config object. * D2_Base *d2 = new D2_LJ(config); * D2_Base *d3 = new D3_Dummy(config); * D2_Base *dm = new DM_Dummy(config); @@ -97,7 +99,7 @@ class DescriptorsCalc: public DC_Base { * */ template <typename T1, typename T2, typename T3,typename T4, typename T5, typename T6> - DescriptorsCalc(Config &c, T1 &d2, T2 &d3, T3 &dm, T4 &c2, T5 &c3, T6 &cm); + DescriptorsCalc(tadah::core::Config &c, T1 &d2, T2 &d3, T3 &dm, T4 &c2, T5 &c3, T6 &cm); /** Calculate all descriptors in a Structure st */ StDescriptors calc(const Structure &st); @@ -116,12 +118,14 @@ class DescriptorsCalc: public DC_Base { DM dm; private: template <typename T1, typename T2, typename T3> - DescriptorsCalc(Config &c,T1 &t1,T2 &t2,T3 &t3); + DescriptorsCalc(tadah::core::Config &c,T1 &t1,T2 &t2,T3 &t3); void calc(const Structure &st, StDescriptors &std); void calc_dimer(const Structure &st, StDescriptors &std); void common_constructor(); }; +} // namespace mlip +} // namespace tadah #include "descriptors_calc.hpp" #endif diff --git a/include/tadah/mlip/descriptors_calc.hpp b/include/tadah/mlip/descriptors_calc.hpp index b5bc9b1e16a82cf2d6cf2e0822f3a9ba0a453795..4f32e0e989cd372a09ab20b98a83e96a4b681547 100644 --- a/include/tadah/mlip/descriptors_calc.hpp +++ b/include/tadah/mlip/descriptors_calc.hpp @@ -6,10 +6,12 @@ #include <tadah/core/periodic_table.h> #include <cstdio> +namespace tadah { +namespace mlip { template <typename D2, typename D3, typename DM, typename C2, typename C3, typename CM> template <typename T1, typename T2, typename T3> -DescriptorsCalc<D2,D3,DM,C2,C3,CM>::DescriptorsCalc(Config &c, T1 &t1, T2 &t2, T3 &t3): +DescriptorsCalc<D2,D3,DM,C2,C3,CM>::DescriptorsCalc(tadah::core::Config &c, T1 &t1, T2 &t2, T3 &t3): config(c), d2(t1), d3(t2), @@ -30,7 +32,7 @@ DescriptorsCalc<D2,D3,DM,C2,C3,CM>::DescriptorsCalc(Config &c, T1 &t1, T2 &t2, T } } template <typename D2, typename D3, typename DM, typename C2, typename C3, typename CM> -DescriptorsCalc<D2,D3,DM,C2,C3,CM>::DescriptorsCalc(Config &c): +DescriptorsCalc<D2,D3,DM,C2,C3,CM>::DescriptorsCalc(tadah::core::Config &c): DescriptorsCalc(c,c,c,c) { if (c.get<bool>("INIT2B")) { @@ -76,7 +78,7 @@ DescriptorsCalc<D2,D3,DM,C2,C3,CM>::DescriptorsCalc(Config &c): template <typename D2, typename D3, typename DM, typename C2, typename C3, typename CM> template <typename T1, typename T2, typename T3,typename T4, typename T5, typename T6> -DescriptorsCalc<D2,D3,DM,C2,C3,CM>::DescriptorsCalc(Config &c, T1 &d2, T2 &d3, T3 &dm, T4 &c2, T5 &c3, T6 &cm): +DescriptorsCalc<D2,D3,DM,C2,C3,CM>::DescriptorsCalc(tadah::core::Config &c, T1 &d2, T2 &d3, T3 &dm, T4 &c2, T5 &c3, T6 &cm): config(c), c2(c2), c3(c3), @@ -160,18 +162,18 @@ void DescriptorsCalc<D2,D3,DM,C2,C3,CM>::common_constructor() { template <typename D2, typename D3, typename DM, typename C2, typename C3, typename CM> void DescriptorsCalc<D2,D3,DM,C2,C3,CM>::calc_rho(const Structure &st, StDescriptors &st_d) { double rcut_mb_sq = pow(config.get<double>("RCUTMBMAX"),2); - rhos_type &rhos = st_d.rhos; + tadah::core::tadah::core::rhos_type &rhos = st_d.rhos; size_t s = dm.rhoi_size()+dm.rhoip_size(); rhos.resize(s,st.natoms()); rhos.set_zero(); - Vec3d delij; + tadah::core::Vec3d delij; for (size_t i=0; i<st.natoms(); ++i) { const Atom &a1 = st(i); int Zi = a1.Z; for (size_t jj=0; jj<st.nn_size(i); ++jj) { - const Vec3d &a2pos = st.nn_pos(i,jj); + const tadah::core::Vec3d &a2pos = st.nn_pos(i,jj); //delij = a1.position - a2pos; delij[0] = a1.position[0] - a2pos[0]; delij[1] = a1.position[1] - a2pos[1]; @@ -219,7 +221,7 @@ void DescriptorsCalc<D2,D3,DM,C2,C3,CM>::calc(const Structure &st, StDescriptors // zero all aeds and set bias for (size_t i=0; i<st.natoms(); ++i) { - aed_type &aed = st_d.get_aed(i); + tadah::core::aed_type &aed = st_d.get_aed(i); aed.set_zero(); aed(0)=static_cast<double>(bias); // set bias } @@ -229,8 +231,8 @@ void DescriptorsCalc<D2,D3,DM,C2,C3,CM>::calc(const Structure &st, StDescriptors // can be calculated if (initmb) { for (size_t i=0; i<st.natoms(); ++i) { - aed_type &aed = st_d.get_aed(i); - rho_type& rhoi = st_d.get_rho(i); + tadah::core::aed_type &aed = st_d.get_aed(i); + tadah::core::rho_type& rhoi = st_d.get_rho(i); dm.calc_aed(rhoi,aed); } } @@ -238,14 +240,14 @@ void DescriptorsCalc<D2,D3,DM,C2,C3,CM>::calc(const Structure &st, StDescriptors bool use_force = config.get<bool>("FORCE"); bool use_stress = config.get<bool>("STRESS"); - Vec3d delij; + tadah::core::Vec3d delij; for (size_t i=0; i<st.natoms(); ++i) { const Atom &a1 = st(i); - aed_type &aed = st_d.get_aed(i); + tadah::core::aed_type &aed = st_d.get_aed(i); int Zi = a1.Z; for (size_t jj=0; jj<st.nn_size(i); ++jj) { - const Vec3d &a2pos = st.nn_pos(i,jj); + const tadah::core::Vec3d &a2pos = st.nn_pos(i,jj); delij[0] = a1.position[0] - a2pos[0]; delij[1] = a1.position[1] - a2pos[1]; @@ -261,7 +263,7 @@ void DescriptorsCalc<D2,D3,DM,C2,C3,CM>::calc(const Structure &st, StDescriptors // CALCULATE TWO-BODY TERM if (use_force || use_stress) { - fd_type &fd_ij = st_d.fd[i][jj]; + tadah::core::fd_type &fd_ij = st_d.fd[i][jj]; if (rij_sq <= rcut_2b_sq && init2b) { d2.calc_all(Zi,Zj,rij,rij_sq,aed,fd_ij,0.5); // Two-body descriptor calculates x-direction only - fd_ij(n,0) @@ -276,7 +278,7 @@ void DescriptorsCalc<D2,D3,DM,C2,C3,CM>::calc(const Structure &st, StDescriptors } // CALCULATE MANY-BODY TERM if (rij_sq <= rcut_mb_sq && initmb) { - rho_type& rhoi = st_d.get_rho(i); + tadah::core::rho_type& rhoi = st_d.get_rho(i); dm.calc_dXijdri(Zi,Zj,rij,rij_sq,delij,rhoi,fd_ij); } } @@ -361,7 +363,7 @@ void DescriptorsCalc<D2,D3,DM,C2,C3,CM>::calc_dimer(const Structure &st, StDescr // zero all aeds+rho and set bias for (size_t i=0; i<4; ++i) { - aed_type &aed = st_d.get_aed(i); + tadah::core::aed_type &aed = st_d.get_aed(i); aed.set_zero(); aed(0)=static_cast<double>(bias); // set bias } @@ -371,10 +373,10 @@ void DescriptorsCalc<D2,D3,DM,C2,C3,CM>::calc_dimer(const Structure &st, StDescr st_d.rhos.set_zero(); } - Vec3d xicom = 0.5*(atoms[0].position + atoms[1].position); - Vec3d xjcom = 0.5*(atoms[2].position + atoms[3].position); + tadah::core::Vec3d xicom = 0.5*(atoms[0].position + atoms[1].position); + tadah::core::Vec3d xjcom = 0.5*(atoms[2].position + atoms[3].position); - Vec3d del_com = xicom-xjcom;; + tadah::core::Vec3d del_com = xicom-xjcom;; double r_com_sq = del_com * del_com; if (r_com_sq > rcut_com_sq) { return; @@ -406,8 +408,8 @@ void DescriptorsCalc<D2,D3,DM,C2,C3,CM>::calc_dimer(const Structure &st, StDescr // calculate many-body aed if (initmb) { for (size_t i=0; i<4; ++i) { - aed_type &aed = st_d.get_aed(i); - rho_type& rhoi = st_d.get_rho(i); + tadah::core::aed_type &aed = st_d.get_aed(i); + tadah::core::rho_type& rhoi = st_d.get_rho(i); dm.calc_aed(rhoi,aed); } } @@ -445,4 +447,6 @@ StDescriptorsDB DescriptorsCalc<D2,D3,DM,C2,C3,CM>::calc(const StructureDB &stdb calc(stdb(i),st_desc_db(i)); return st_desc_db; } +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/descriptors_calc_base.h b/include/tadah/mlip/descriptors_calc_base.h index a56c26f328d261161e21688d844aad0e68c90ddf..a8910a8f20e8780d32dce28b5935d28e68fb265f 100644 --- a/include/tadah/mlip/descriptors_calc_base.h +++ b/include/tadah/mlip/descriptors_calc_base.h @@ -5,6 +5,8 @@ #include <tadah/mlip/structure_db.h> #include <tadah/mlip/st_descriptors.h> #include <tadah/mlip/st_descriptors_db.h> +namespace tadah { +namespace mlip { class DC_Base { public: @@ -12,4 +14,6 @@ class DC_Base { virtual StDescriptors calc(const Structure &) { return StDescriptors(); }; virtual StDescriptorsDB calc(const StructureDB &) {return StDescriptorsDB();}; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/design_matrix.h b/include/tadah/mlip/design_matrix/design_matrix.h index f4a2e71b851b6c8977547d2618437151aef45f7c..f88648223a8406714f9ec2814e0be0b3d4b21402 100644 --- a/include/tadah/mlip/design_matrix/design_matrix.h +++ b/include/tadah/mlip/design_matrix/design_matrix.h @@ -12,11 +12,13 @@ #include <tadah/mlip/memory/DesignMatrixWorkspace.h> #include <stdexcept> +namespace tadah { +namespace mlip { class DesignMatrixBase { public: - static int phi_rows_num(Config &c, int nstruct_tot, int natoms_tot) { + static int phi_rows_num(tadah::core::Config &c, int nstruct_tot, int natoms_tot) { bool force = c.get<bool>("FORCE"); bool stress = c.get<bool>("STRESS"); int rows = nstruct_tot; @@ -27,7 +29,7 @@ public: }; -/** Design Matrix \f$ \Phi \f$ and the corresponding target vector \f$ \mathrm{T} \f$ +/** Design tadah::core::Matrix \f$ \Phi \f$ and the corresponding target vector \f$ \mathrm{T} \f$ * * An aggregation matrix composed of \phi_i matrices * @@ -81,17 +83,17 @@ public: /** \brief This constructor fully initialise this object * - * This class is used to build a Design Matrix. + * This class is used to build a Design tadah::core::Matrix. * * Usage example: * \code{.cpp} - * Config config("Config"); + * tadah::core::Config config("tadah::core::Config"); * BF_Linear bf(config); * DesignMatrix<LinearKernel> desmat(bf, config); * * \endcode */ - DesignMatrix(F &f, Config &c, tadah::mlip::memory::IMLIPWorkspaceManager& workspaceManager) + DesignMatrix(F &f, tadah::core::Config &c, tadah::mlip::memory::IMLIPWorkspaceManager& workspaceManager) : f(f), workspaceManager_(&workspaceManager), ownWorkspaceManager(false), @@ -112,7 +114,7 @@ public: } // Constructor without workspaceManager_ parameter (delegating constructor) - DesignMatrix(F &f, Config &c) + DesignMatrix(F &f, tadah::core::Config &c) : DesignMatrix(f, c, *new tadah::mlip::memory::MLIPWorkspaceManager()) { ownWorkspaceManager = true; // Set ownership flag @@ -252,15 +254,15 @@ public: } } - phi_type &getPhi() { return ws->Phi; } - t_type &getT() { return ws->T; } - t_type &getTlabels() { return ws->Tlabels; } + tadah::core::phi_type &getPhi() { return ws->Phi; } + tadah::core::t_type &getT() { return ws->T; } + tadah::core::t_type &getTlabels() { return ws->Tlabels; } bool hasCopy() { return w_copy_; } private: tadah::mlip::memory::IMLIPWorkspaceManager* workspaceManager_ = nullptr; bool ownWorkspaceManager = false; - Config & config; + tadah::core::Config & config; size_t rows = 0; size_t cols = 0; bool force; @@ -291,8 +293,8 @@ private: } void compute_stdevs(const StructureDB &stdb) { - t_type evec(stdb.size()); - Matrix svec(stdb.size(),6); + tadah::core::t_type evec(stdb.size()); + tadah::core::Matrix svec(stdb.size(),6); size_t num_forces=0; for (size_t s=0; s<stdb.size(); ++s) { evec(s) = stdb(s).energy/stdb(s).natoms(); @@ -319,7 +321,7 @@ private: if (force) { size_t j=0; - t_type fvec(num_forces); + tadah::core::t_type fvec(num_forces); for (size_t s=0; s<stdb.size(); ++s) { for (const Atom &a : stdb(s).atoms) { fvec(j++) = a.force(0); @@ -386,4 +388,6 @@ private: } } }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_all.h b/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_all.h index 48179cf65d71ab9692485bdc246206e5417910b1..0cc99f547747d3a9d451d1a6761b1d7bdee66765 100644 --- a/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_all.h +++ b/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_all.h @@ -1,2 +1,6 @@ #include <tadah/mlip/design_matrix/functions/basis_functions/dm_bf_linear.h> #include <tadah/mlip/design_matrix/functions/basis_functions/dm_bf_polynomial2.h> +namespace tadah { +namespace mlip { +} // namespace mlip +} // namespace tadah diff --git a/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_base.h b/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_base.h index 7385b9cd3883e30876c8c5e4155c82abdbb1999d..56d0ef73d12eb7abd84e5e29185d71a6fd00102b 100644 --- a/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_base.h +++ b/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_base.h @@ -8,18 +8,22 @@ #include <tadah/models/functions/basis_functions/bf_base.h> #include <iostream> +namespace tadah { +namespace mlip { struct DM_BF_Base: public DM_Function_Base, public virtual BF_Base { DM_BF_Base(); - DM_BF_Base(const Config &c); + DM_BF_Base(const tadah::core::Config &c); virtual ~DM_BF_Base(); - // virtual size_t get_phi_cols(const Config &config)=0; - // virtual void calc_phi_energy_row(phi_type &Phi, size_t &row, + // virtual size_t get_phi_cols(const tadah::core::Config &config)=0; + // virtual void calc_phi_energy_row(tadah::core::phi_type &Phi, size_t &row, // const Structure &st, const StDescriptors &st_d)=0; - // virtual void calc_phi_force_rows(phi_type &Phi, size_t &row, + // virtual void calc_phi_force_rows(tadah::core::phi_type &Phi, size_t &row, // const Structure &st, const StDescriptors &st_d)=0; - // virtual void calc_phi_stress_rows(phi_type &Phi, size_t &row, + // virtual void calc_phi_stress_rows(tadah::core::phi_type &Phi, size_t &row, // const Structure &st, const StDescriptors &st_d)=0; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_linear.h b/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_linear.h index 43c483444630751fcb7b656dc38231088e415b90..63cdeea291a943d724fed183a3ec02c4c7b237da 100644 --- a/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_linear.h +++ b/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_linear.h @@ -3,17 +3,21 @@ #include <tadah/mlip/design_matrix/functions/basis_functions/dm_bf_base.h> #include <tadah/models/functions/basis_functions/bf_linear.h> +namespace tadah { +namespace mlip { struct DM_BF_Linear: public DM_BF_Base, public BF_Linear { DM_BF_Linear(); - DM_BF_Linear(const Config &c); - size_t get_phi_cols(const Config &config) override; - void calc_phi_energy_row(phi_type &Phi, size_t &row, + DM_BF_Linear(const tadah::core::Config &c); + size_t get_phi_cols(const tadah::core::Config &config) override; + void calc_phi_energy_row(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; - void calc_phi_force_rows(phi_type &Phi, size_t &row, + void calc_phi_force_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; - void calc_phi_stress_rows(phi_type &Phi, size_t &row, + void calc_phi_stress_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_polynomial2.h b/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_polynomial2.h index 19bca293ad1c5fde956ab06bb353ab1b5e87e07c..510dcfdeb57d3de61d2861a0f20d72393d9ffa9d 100644 --- a/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_polynomial2.h +++ b/include/tadah/mlip/design_matrix/functions/basis_functions/dm_bf_polynomial2.h @@ -3,17 +3,21 @@ #include <tadah/mlip/design_matrix/functions/basis_functions/dm_bf_base.h> #include <tadah/models/functions/basis_functions/bf_polynomial2.h> +namespace tadah { +namespace mlip { struct DM_BF_Polynomial2: public DM_BF_Base, public BF_Polynomial2 { DM_BF_Polynomial2(); - DM_BF_Polynomial2(const Config &c); - size_t get_phi_cols(const Config &config) override; - void calc_phi_energy_row(phi_type &Phi, size_t &row, + DM_BF_Polynomial2(const tadah::core::Config &c); + size_t get_phi_cols(const tadah::core::Config &config) override; + void calc_phi_energy_row(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; - void calc_phi_force_rows(phi_type &Phi, size_t &row, + void calc_phi_force_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; - void calc_phi_stress_rows(phi_type &Phi, size_t &row, + void calc_phi_stress_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/functions/dm_f_all.h b/include/tadah/mlip/design_matrix/functions/dm_f_all.h index 56c4baed80353ca9d691d8a94594b605a46f8143..28684d65f0b57b4bb86e732a1c36358cf302bf56 100644 --- a/include/tadah/mlip/design_matrix/functions/dm_f_all.h +++ b/include/tadah/mlip/design_matrix/functions/dm_f_all.h @@ -1,2 +1,6 @@ #include <tadah/mlip/design_matrix/functions/basis_functions/dm_bf_all.h> #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_all.h> +namespace tadah { +namespace mlip { +} // namespace mlip +} // namespace tadah diff --git a/include/tadah/mlip/design_matrix/functions/dm_function_base.h b/include/tadah/mlip/design_matrix/functions/dm_function_base.h index fdbdee273c94b6276409914ccb14c432e7ff3d7a..49b25814aa8a225da7a823da1486b275f87652eb 100644 --- a/include/tadah/mlip/design_matrix/functions/dm_function_base.h +++ b/include/tadah/mlip/design_matrix/functions/dm_function_base.h @@ -12,23 +12,27 @@ #include <iostream> #include <limits> #include <vector> +namespace tadah { +namespace mlip { /** Base class for Kernels and Basis Functions */ struct DM_Function_Base: public virtual Function_Base { - // Derived classes must implement Derived() and Derived(Config) + // Derived classes must implement Derived() and Derived(tadah::core::Config) DM_Function_Base(); - DM_Function_Base(const Config &c); + DM_Function_Base(const tadah::core::Config &c); virtual ~DM_Function_Base(); - virtual size_t get_phi_cols(const Config &)=0; - virtual void calc_phi_energy_row(phi_type &, size_t &, + virtual size_t get_phi_cols(const tadah::core::Config &)=0; + virtual void calc_phi_energy_row(tadah::core::phi_type &, size_t &, const Structure &, const StDescriptors &)=0; - virtual void calc_phi_force_rows(phi_type &, size_t &, + virtual void calc_phi_force_rows(tadah::core::phi_type &, size_t &, const Structure &, const StDescriptors &)=0; - virtual void calc_phi_stress_rows(phi_type &, size_t &, + virtual void calc_phi_stress_rows(tadah::core::phi_type &, size_t &, const Structure &, const StDescriptors &)=0; }; //template<> inline CONFIG::Registry<DM_Function_Base>::Map CONFIG::Registry<DM_Function_Base>::registry{}; -//template<> inline CONFIG::Registry<DM_Function_Base,Config&>::Map CONFIG::Registry<DM_Function_Base,Config&>::registry{}; +//template<> inline CONFIG::Registry<DM_Function_Base,tadah::core::Config&>::Map CONFIG::Registry<DM_Function_Base,tadah::core::Config&>::registry{}; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_all.h b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_all.h index b53a2f63d862fecb09f6410c744ee549d13c5784..aa9607961801fd88e114616c1582ff77985412d8 100644 --- a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_all.h +++ b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_all.h @@ -5,3 +5,5 @@ #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_polynomial.h> #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_sigmoid.h> #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_quadratic.h> +namespace tadah { +namespace mlip { diff --git a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h index 52802523265cf2b88b6c8c63bec0973b321519d4..4f73e759a2adbb369943dd1b267d83fc3d7c3d06 100644 --- a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h +++ b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h @@ -9,6 +9,8 @@ #include <tadah/models/functions/kernels/kern_base.h> #include <iostream> +namespace tadah { +namespace mlip { /** \brief Abstract class to be used as a base for all kernels. * @@ -21,12 +23,14 @@ class DM_Kern_Base: public DM_Function_Base, public virtual Kern_Base { public: DM_Kern_Base(); - DM_Kern_Base(const Config&c); + DM_Kern_Base(const tadah::core::Config&c); virtual ~DM_Kern_Base(); - virtual size_t get_phi_cols(const Config &config) override; - virtual void calc_phi_energy_row(phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; - virtual void calc_phi_force_rows(phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; - virtual void calc_phi_stress_rows(phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; + virtual size_t get_phi_cols(const tadah::core::Config &config) override; + virtual void calc_phi_energy_row(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; + virtual void calc_phi_force_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; + virtual void calc_phi_stress_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_linear.h b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_linear.h index 3b35036e2d99683f3c74eab2f7bfeb89aa8f9da9..e54041ff0b312877ba254a80bfbb1227565b957d 100644 --- a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_linear.h +++ b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_linear.h @@ -3,6 +3,8 @@ #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h> #include <tadah/models/functions/kernels/kern_linear.h> +namespace tadah { +namespace mlip { /** * Linear kernel also knows as dot product kernel * @@ -17,14 +19,16 @@ class DM_Kern_Linear : public DM_Kern_Base, public Kern_Linear { public: DM_Kern_Linear (); - DM_Kern_Linear (const Config &c); + DM_Kern_Linear (const tadah::core::Config &c); - size_t get_phi_cols(const Config &config) override; - void calc_phi_energy_row(phi_type &Phi, size_t &row, + size_t get_phi_cols(const tadah::core::Config &config) override; + void calc_phi_energy_row(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; - void calc_phi_force_rows(phi_type &Phi, size_t &row, + void calc_phi_force_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; - void calc_phi_stress_rows(phi_type &Phi, size_t &row, + void calc_phi_stress_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) override; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_lq.h b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_lq.h index f0b44451955e6c2e1f7f592397d318d2599fa31b..0ad81aadc5b68c0ba2cfbea14dee795d96a07bce 100644 --- a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_lq.h +++ b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_lq.h @@ -3,10 +3,14 @@ #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h> #include <tadah/models/functions/kernels/kern_lq.h> +namespace tadah { +namespace mlip { class DM_Kern_LQ : public DM_Kern_Base, public Kern_LQ { public: DM_Kern_LQ(); - DM_Kern_LQ(const Config &c); + DM_Kern_LQ(const tadah::core::Config &c); }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_polynomial.h b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_polynomial.h index 5094370338d006531c85b4450a81878d7fcb6653..13c78e6edc1eca5de8dddd9507b2a272921bfba4 100644 --- a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_polynomial.h +++ b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_polynomial.h @@ -3,10 +3,14 @@ #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h> #include <tadah/models/functions/kernels/kern_polynomial.h> +namespace tadah { +namespace mlip { class DM_Kern_Polynomial : public DM_Kern_Base, public Kern_Polynomial { public: DM_Kern_Polynomial(); - DM_Kern_Polynomial(const Config &c); + DM_Kern_Polynomial(const tadah::core::Config &c); }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_quadratic.h b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_quadratic.h index ecb85350cdc42c698547432ae1965124bd6fcde5..de31022b613b7dcc18cd04b0caa69e642128d326 100644 --- a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_quadratic.h +++ b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_quadratic.h @@ -3,10 +3,14 @@ #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h> #include <tadah/models/functions/kernels/kern_quadratic.h> +namespace tadah { +namespace mlip { class DM_Kern_Quadratic : public DM_Kern_Base, public Kern_Quadratic { public: DM_Kern_Quadratic(); - DM_Kern_Quadratic(const Config &c); + DM_Kern_Quadratic(const tadah::core::Config &c); }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_rbf.h b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_rbf.h index 7e1251afe93a266366024cf5d22a43869287d84a..5d349e747b940662948cd176a3109d338794cf9f 100644 --- a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_rbf.h +++ b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_rbf.h @@ -3,10 +3,14 @@ #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h> #include <tadah/models/functions/kernels/kern_rbf.h> +namespace tadah { +namespace mlip { class DM_Kern_RBF : public DM_Kern_Base, public Kern_RBF { public: DM_Kern_RBF(); - DM_Kern_RBF(const Config &c); + DM_Kern_RBF(const tadah::core::Config &c); }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_sigmoid.h b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_sigmoid.h index c62a50ef586e4dd76390d5d710deec129c679d46..bf3cc1aea1620a100dc749f394cccd1bfc7e97b9 100644 --- a/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_sigmoid.h +++ b/include/tadah/mlip/design_matrix/functions/kernels/dm_kern_sigmoid.h @@ -3,10 +3,14 @@ #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h> #include <tadah/models/functions/kernels/kern_sigmoid.h> +namespace tadah { +namespace mlip { class DM_Kern_Sigmoid : public DM_Kern_Base, public Kern_Sigmoid { public: DM_Kern_Sigmoid(); - DM_Kern_Sigmoid(const Config &c); + DM_Kern_Sigmoid(const tadah::core::Config &c); }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/key_storage/environment_key_storage.h b/include/tadah/mlip/key_storage/environment_key_storage.h index 258e13beb4358a2cf92d765d47cb2bc99e615dee..1b242cefbf7e66a16cb22e22867f65281faa2b3a 100644 --- a/include/tadah/mlip/key_storage/environment_key_storage.h +++ b/include/tadah/mlip/key_storage/environment_key_storage.h @@ -13,6 +13,8 @@ #include <tadah/mlip/key_storage/ikey_storage.h> #include <string> +namespace tadah { +namespace mlip { /** * @class EnvironmentKeyStorage @@ -40,4 +42,6 @@ public: const std::string &keyValue) override; }; +} // namespace mlip +} // namespace tadah #endif // ENVIRONMENTKEYSTORAGE_H diff --git a/include/tadah/mlip/key_storage/fallback_key_storage.h b/include/tadah/mlip/key_storage/fallback_key_storage.h index 45e94fcc239a724590130fb81597ea5e91ac9167..9e8e7012587d74fbb1c461b348f02dfa40caf013 100644 --- a/include/tadah/mlip/key_storage/fallback_key_storage.h +++ b/include/tadah/mlip/key_storage/fallback_key_storage.h @@ -10,6 +10,8 @@ #include <tadah/mlip/key_storage/ikey_storage.h> #include <vector> #include <memory> +namespace tadah { +namespace mlip { /** * @class FallbackKeyStorage @@ -47,5 +49,7 @@ private: std::vector<std::unique_ptr<IKeyStorage>> m_storages; }; +} // namespace mlip +} // namespace tadah #endif // FALLBACKKEYSTORAGE_H diff --git a/include/tadah/mlip/key_storage/ikey_storage.h b/include/tadah/mlip/key_storage/ikey_storage.h index 0ce8276c2a4400573883a604a77f86ed884846db..b3ac9dcd0b1094a5426c8a3064b77f62b9f93ef8 100644 --- a/include/tadah/mlip/key_storage/ikey_storage.h +++ b/include/tadah/mlip/key_storage/ikey_storage.h @@ -7,6 +7,8 @@ #define IKEYSTORAGE_H #include <string> +namespace tadah { +namespace mlip { /** * @class IKeyStorage @@ -35,4 +37,6 @@ public: virtual bool storeKey(const std::string& keyName, const std::string& keyValue) = 0; }; +} // namespace mlip +} // namespace tadah #endif // IKEYSTORAGE_H diff --git a/include/tadah/mlip/key_storage/key_manager.h b/include/tadah/mlip/key_storage/key_manager.h index be98eccf6493d382bd94fcc4b0c4fce92d37cee6..6587bf6a9074359c20d00190120634a6839eb565 100644 --- a/include/tadah/mlip/key_storage/key_manager.h +++ b/include/tadah/mlip/key_storage/key_manager.h @@ -8,6 +8,8 @@ #define KEYMANAGER_H #include <string> +namespace tadah { +namespace mlip { /** * @enum ServiceType @@ -82,4 +84,6 @@ private: */ static void showShellExportInstructions(const std::string& keyName, const std::string& keyValue); }; +} // namespace mlip +} // namespace tadah #endif // KEYMANAGER_H diff --git a/include/tadah/mlip/key_storage/key_storage_factory.h b/include/tadah/mlip/key_storage/key_storage_factory.h index f1572bcdbbea4eff6af84ed7d6d5d60b6d7d95c0..4287322bf5a6597c4c0771a1b2d7af60949e28f7 100644 --- a/include/tadah/mlip/key_storage/key_storage_factory.h +++ b/include/tadah/mlip/key_storage/key_storage_factory.h @@ -9,6 +9,8 @@ #include <memory> #include <string> #include <tadah/mlip/key_storage/ikey_storage.h> +namespace tadah { +namespace mlip { /** * @class KeyStorageFactory @@ -36,5 +38,7 @@ public: static std::unique_ptr<IKeyStorage> createEnvironmentOnly(); }; +} // namespace mlip +} // namespace tadah #endif // KEYSTORAGEFACTORY_H diff --git a/include/tadah/mlip/key_storage/plain_text_key_storage.h b/include/tadah/mlip/key_storage/plain_text_key_storage.h index c71a43eb88fa1c7aae5722fc4feafdfb7e9fe30c..0c33ff474eaae17e89f948d000df9a84d987a1b0 100644 --- a/include/tadah/mlip/key_storage/plain_text_key_storage.h +++ b/include/tadah/mlip/key_storage/plain_text_key_storage.h @@ -8,6 +8,8 @@ #include <tadah/mlip/key_storage/ikey_storage.h> #include <vector> +namespace tadah { +namespace mlip { /** * @class PlainTextKeyStorage @@ -56,5 +58,7 @@ private: bool writeAllKeys(const std::vector<std::pair<std::string, std::string>>& kvPairs); }; +} // namespace mlip +} // namespace tadah #endif // PLAINTEXTKEYSTORAGE_H diff --git a/include/tadah/mlip/memory/DesignMatrixWorkspace.h b/include/tadah/mlip/memory/DesignMatrixWorkspace.h index 03b996dec04d12cf6d7c43b609a71e2fa85dca51..3d44ff9214cab4210dabc920bb3b18bfd678c87c 100644 --- a/include/tadah/mlip/memory/DesignMatrixWorkspace.h +++ b/include/tadah/mlip/memory/DesignMatrixWorkspace.h @@ -47,10 +47,10 @@ public: */ bool isSufficient(size_t m_, size_t n_) const; - phi_type Phi, Phi_cpy; // Design matrix and space for its copy - t_type T, T_cpy; // Target vector and space for its copy - t_type Tlabels; // 0-Energy, 1-Force, 2-Stress // TODO should be array of int not double - t_type wfactors; // Weighting factors for Phi + tadah::core::phi_type Phi, Phi_cpy; // Design matrix and space for its copy + tadah::core::t_type T, T_cpy; // Target vector and space for its copy + tadah::core::t_type Tlabels; // 0-Energy, 1-Force, 2-Stress // TODO should be array of int not double + tadah::core::t_type wfactors; // Weighting factors for Phi private: // Disable copying diff --git a/include/tadah/mlip/models/basis.h b/include/tadah/mlip/models/basis.h index f00caf0953e911cc133987bca99070a44e24334e..852cd44fe41cbcaaeda1bfcdf747e35ae1b31462 100644 --- a/include/tadah/mlip/models/basis.h +++ b/include/tadah/mlip/models/basis.h @@ -10,22 +10,24 @@ #include <numeric> #include <stdexcept> #include <vector> +namespace tadah { +namespace mlip { template <typename K> class Basis { private: - Config &config; + tadah::core::Config &config; int verbose; public: - Matrix b; - t_type T; // Vectors corresponding to basis vectors - Basis(Config &c): + tadah::core::Matrix b; + tadah::core::t_type T; // Vectors corresponding to basis vectors + Basis(tadah::core::Config &c): config(c), verbose(c.get<int>("VERBOSE")) {} - void set_basis(Matrix &b_) { + void set_basis(tadah::core::Matrix &b_) { b=b_; } void build_random_basis(size_t s, StDescriptorsDB &st_desc_db) { @@ -56,7 +58,7 @@ larger than the amount of available AEDs\n"); for (size_t i=1; i<s; ++i) { size_t st = std::get<0>(indices[i]); size_t a = std::get<1>(indices[i]); - const aed_type &aed = st_desc_db(st).get_aed(a); + const tadah::core::aed_type &aed = st_desc_db(st).get_aed(a); for (size_t j=0; j<aed.size(); ++j) { b(j,i)=aed[j]; } @@ -97,7 +99,7 @@ larger than the amount of available AEDs\n"); const size_t st = indices[i]; T(i)=stdb(st).energy/st_desc_db(st).naed(); for( size_t a=0; a<st_desc_db(st).naed(); a++ ) { - const aed_type &aed = st_desc_db(st).get_aed(a); + const tadah::core::aed_type &aed = st_desc_db(st).get_aed(a); for (size_t j=0; j<aed.size(); ++j) { b(j,i)+=aed[j]/st_desc_db(st).naed(); } @@ -105,4 +107,6 @@ larger than the amount of available AEDs\n"); } } }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/models/m_all.h b/include/tadah/mlip/models/m_all.h index d155789207e9ecc83fe25187a50bd95dd15d526b..2a2a34484411c2790c28ef426e7b9fcd86463a65 100644 --- a/include/tadah/mlip/models/m_all.h +++ b/include/tadah/mlip/models/m_all.h @@ -1,3 +1,5 @@ //#include "m_tadah_base.h" #include <tadah/mlip/models/m_blr.h> #include <tadah/mlip/models/m_krr.h> +namespace tadah { +namespace mlip { diff --git a/include/tadah/mlip/models/m_blr.h b/include/tadah/mlip/models/m_blr.h index c72ea351fec29957c88c9049baf9d14e1a819eac..b02aabeb0ba4d3ad15e372d9c927f311db351c10 100644 --- a/include/tadah/mlip/models/m_blr.h +++ b/include/tadah/mlip/models/m_blr.h @@ -14,6 +14,8 @@ #include <stdexcept> #include <type_traits> #include <iostream> +namespace tadah { +namespace mlip { /** * @class M_BLR @@ -51,13 +53,13 @@ public: * * **Example**: * \code{.cpp} - * Config config("Config"); + * tadah::core::Config config("tadah::core::Config"); * M_BLR<BF_Linear> blr(config); * \endcode * * @param c Configuration object. */ - M_BLR(Config &c): + M_BLR(tadah::core::Config &c): M_BLR_Train<BF>(c), desmat(M_BLR_Train<BF>::bf,c) { @@ -70,29 +72,29 @@ public: * @param bf Basis function. * @param c Configuration object. */ - M_BLR(BF &bf, Config &c): + M_BLR(BF &bf, tadah::core::Config &c): M_BLR_Train<BF>(bf,c), desmat(bf,c) { norm = Normaliser(c); } - M_BLR(BF &bf, Config &c, tadah::mlip::memory::IMLIPWorkspaceManager& workspaceManager): + M_BLR(BF &bf, tadah::core::Config &c, tadah::mlip::memory::IMLIPWorkspaceManager& workspaceManager): M_BLR_Train<BF>(bf,c,workspaceManager), desmat(bf,c,workspaceManager) { norm = Normaliser(c); } - double epredict(const aed_type &aed) const{ + double epredict(const tadah::core::aed_type &aed) const{ return bf.epredict(weights,aed); }; - double fpredict(const fd_type &fdij, const aed_type &aedi, const size_t k) const{ + double fpredict(const tadah::core::fd_type &fdij, const tadah::core::aed_type &aedi, const size_t k) const{ return bf.fpredict(weights,fdij,aedi,k); } - force_type fpredict(const fd_type &fdij, const aed_type &aedi) const{ + tadah::core::force_type fpredict(const tadah::core::fd_type &fdij, const tadah::core::aed_type &aedi) const{ return bf.fpredict(weights,fdij,aedi); } @@ -137,18 +139,18 @@ public: train(desmat); } - Structure predict(const Config &c, StDescriptors &std, const Structure &st) { + Structure predict(const tadah::core::Config &c, StDescriptors &std, const Structure &st) { if(config.template get<bool>("NORM") && !std.normalised && bf.get_label()!="BF_Linear") norm.normalise(std); return M_Tadah_Base::predict(c,std,st); } - StructureDB predict(Config &c, const StructureDB &stdb, DC_Base &dc) { + StructureDB predict(tadah::core::Config &c, const StructureDB &stdb, DC_Base &dc) { return M_Tadah_Base::predict(c,stdb,dc); } - Config get_param_file() { - Config c = config; + tadah::core::Config get_param_file() { + tadah::core::Config c = config; //c.remove("ALPHA"); //c.remove("BETA"); c.remove("DBFILE"); @@ -176,8 +178,8 @@ public: c.clear_internal_keys(); return c; } - StructureDB predict(Config config_pred, StructureDB &stdb, DC_Base &dc, - aed_type &predicted_error) { + StructureDB predict(tadah::core::Config config_pred, StructureDB &stdb, DC_Base &dc, + tadah::core::aed_type &predicted_error) { LinearRegressor::read_sigma(config_pred,Sigma); DesignMatrix<BF> dm(bf,config_pred); @@ -189,7 +191,7 @@ public: double pmean = sqrt(predicted_error.mean()); // compute energy, forces and stresses - aed_type Tpred = T_dgemv(dm.getPhi(), weights); + tadah::core::aed_type Tpred = T_dgemv(dm.getPhi(), weights); // Construct StructureDB object with predicted values StructureDB stdb_; @@ -225,10 +227,10 @@ public: if(!trained) throw std::runtime_error("This object is not trained!\n\ Hint: check different predict() methods."); - phi_type &Phi = desmat.getPhi(); + tadah::core::phi_type &Phi = desmat.getPhi(); // compute energy, forces and stresses - aed_type Tpred = T_dgemv(Phi, weights); + tadah::core::aed_type Tpred = T_dgemv(Phi, weights); // double eweightglob=config.template get<double>("EWEIGHT"); // double fweightglob=config.template get<double>("FWEIGHT"); @@ -270,12 +272,12 @@ private: // normalise weights such that when predict is called // we can supply it with a non-normalised descriptor - t_type convert_to_nweights(const t_type &weights) const { + tadah::core::t_type convert_to_nweights(const tadah::core::t_type &weights) const { if(bf.get_label()!="BF_Linear") { throw std::runtime_error("Cannot convert weights to nweights for\n\ non linear basis function\n"); } - t_type nw(weights.rows()); + tadah::core::t_type nw(weights.rows()); nw(0) = weights(0); for (size_t i=1; i<weights.size(); ++i) { @@ -290,13 +292,13 @@ non linear basis function\n"); return nw; } // The opposite of convert_to_nweights() - t_type convert_to_weights(const t_type &nw) const { + tadah::core::t_type convert_to_weights(const tadah::core::t_type &nw) const { if(bf.get_label()!="BF_Linear") { throw std::runtime_error("Cannot convert nweights to weights for\n\ non linear basis function\n"); } // convert normalised weights back to "normal" - t_type w(nw.rows()); + tadah::core::t_type w(nw.rows()); w(0) = nw(0); for (size_t i=1; i<nw.size(); ++i) { if (norm.std_dev[i] > std::numeric_limits<double>::min()) @@ -315,10 +317,10 @@ non linear basis function\n"); // the train method destroys the Phi matrix // In consequence, we cannot use it for quick prediction // The simple solution, for now, is to make a copy of the Phi matrix - //phi_type &Phi = desmat.Phi; - phi_type Phi = desmat.getPhi(); - t_type T = desmat.getT(); - //t_type &T = desmat.T; + //tadah::core::phi_type &Phi = desmat.Phi; + tadah::core::phi_type Phi = desmat.getPhi(); + tadah::core::t_type T = desmat.getT(); + //tadah::core::t_type &T = desmat.T; M_BLR_Train<BF>::train(Phi,T); if (config.template get<bool>("NORM") && @@ -335,4 +337,6 @@ non linear basis function\n"); using M_BLR_Train<BF>::weights; using M_BLR_Train<BF>::Sigma; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/models/m_krr.h b/include/tadah/mlip/models/m_krr.h index bbe9f7cba6cc2441a0cadf4340ccb171a1b1ada8..d022e6804d775846876f05b6871cc870926d020c 100644 --- a/include/tadah/mlip/models/m_krr.h +++ b/include/tadah/mlip/models/m_krr.h @@ -15,6 +15,8 @@ #include <stdexcept> #include <type_traits> #include <iostream> +namespace tadah { +namespace mlip { /** * @class M_KRR @@ -52,13 +54,13 @@ public: * * **Example**: * \code{.cpp} - * Config config("Config"); + * tadah::core::Config config("tadah::core::Config"); * M_KRR<Kern_Linear> krr(config); * \endcode * * @param c Configuration object. */ - M_KRR(Config &c): + M_KRR(tadah::core::Config &c): M_KRR_Train<K>(c), basis(c), desmat(kernel,c) @@ -72,7 +74,7 @@ public: * @param kernel Kernel function. * @param c Configuration object. */ - M_KRR(K &kernel, Config &c): + M_KRR(K &kernel, tadah::core::Config &c): M_KRR_Train<K>(kernel,c), basis(c), desmat(kernel,c) @@ -80,22 +82,22 @@ public: norm = Normaliser(c); } - M_KRR(K &kernel, Config &c, tadah::mlip::memory::IMLIPWorkspaceManager& workspaceManager): + M_KRR(K &kernel, tadah::core::Config &c, tadah::mlip::memory::IMLIPWorkspaceManager& workspaceManager): M_KRR_Train<K>(kernel,c,workspaceManager), basis(c), desmat(kernel,c) { norm = Normaliser(c); } - double epredict(const aed_type &aed) const { + double epredict(const tadah::core::aed_type &aed) const { return kernel.epredict(weights,aed); }; - double fpredict(const fd_type &fdij, const aed_type &aedi, const size_t k) const { + double fpredict(const tadah::core::fd_type &fdij, const tadah::core::aed_type &aedi, const size_t k) const { return kernel.fpredict(weights,fdij,aedi,k); } - force_type fpredict(const fd_type &fdij, const aed_type &aedi) const { + tadah::core::force_type fpredict(const tadah::core::fd_type &fdij, const tadah::core::aed_type &aedi) const { return kernel.fpredict(weights,fdij,aedi); } @@ -191,18 +193,18 @@ public: M_KRR_Train<K>::train2(basis.b, basis.T); } - Structure predict(const Config &c, StDescriptors &std, const Structure &st) { + Structure predict(const tadah::core::Config &c, StDescriptors &std, const Structure &st) { if(config.template get<bool>("NORM") && !std.normalised && kernel.get_label()!="Kern_Linear") norm.normalise(std); return M_Tadah_Base::predict(c,std,st); } - StructureDB predict(Config &c, const StructureDB &stdb, DC_Base &dc) { + StructureDB predict(tadah::core::Config &c, const StructureDB &stdb, DC_Base &dc) { return M_Tadah_Base::predict(c,stdb,dc); } - Config get_param_file() { - Config c = config; + tadah::core::Config get_param_file() { + tadah::core::Config c = config; c.remove("ALPHA"); c.remove("BETA"); c.remove("DBFILE"); @@ -246,8 +248,8 @@ public: c.clear_internal_keys(); return c; } - StructureDB predict(Config config_pred, StructureDB &stdb, DC_Base &dc, - aed_type &predicted_error) { + StructureDB predict(tadah::core::Config config_pred, StructureDB &stdb, DC_Base &dc, + tadah::core::aed_type &predicted_error) { LinearRegressor::read_sigma(config_pred,Sigma); DesignMatrix<K> dm(kernel,config_pred); @@ -260,7 +262,7 @@ public: double pmean = sqrt(predicted_error.mean()); // compute energy, forces and stresses - aed_type Tpred = T_dgemv(dm.getPhi(), weights); + tadah::core::aed_type Tpred = T_dgemv(dm.getPhi(), weights); // Construct StructureDB object with predicted values StructureDB stdb_; @@ -296,10 +298,10 @@ public: if(!trained) throw std::runtime_error("This object is not trained!\n\ Hint: check different predict() methods."); - phi_type &Phi = desmat.getPhi(); + tadah::core::phi_type &Phi = desmat.getPhi(); // compute energy, forces and stresses - aed_type Tpred = T_dgemv(Phi, weights); + tadah::core::aed_type Tpred = T_dgemv(Phi, weights); // double eweightglob=config.template get<double>("EWEIGHT"); // double fweightglob=config.template get<double>("FWEIGHT"); @@ -340,12 +342,12 @@ private: Basis<K> basis; DesignMatrix<K> desmat; - t_type convert_to_nweights(const t_type &weights) const { + tadah::core::t_type convert_to_nweights(const tadah::core::t_type &weights) const { if(kernel.get_label()!="Kern_Linear") { throw std::runtime_error("Cannot convert weights to nweights for\n\ non linear kernel\n"); } - t_type kw(weights.rows()); + tadah::core::t_type kw(weights.rows()); if(config.template get<bool>("NORM") && kernel.get_label()=="Kern_Linear") { // normalise weights such that when predict is called // we can supply it with a non-normalised descriptor @@ -365,13 +367,13 @@ non linear kernel\n"); return kw; } // The opposite of convert_to_nweights() - t_type convert_to_weights(const t_type &kw) const { + tadah::core::t_type convert_to_weights(const tadah::core::t_type &kw) const { if(kernel.get_label()!="Kern_Linear") { throw std::runtime_error("Cannot convert nweights to weights for\n\ non linear kernel\n"); } // convert normalised weights back to "normal" - t_type w(kw.rows()); + tadah::core::t_type w(kw.rows()); w(0) = kw(0); for (size_t i=1; i<kw.size(); ++i) { if (norm.std_dev[i] > std::numeric_limits<double>::min()) @@ -387,8 +389,8 @@ non linear kernel\n"); template <typename D> void train(D &desmat) { // TODO see comments in M_BLR - phi_type Phi = desmat.getPhi(); - t_type T = desmat.getT(); + tadah::core::phi_type Phi = desmat.getPhi(); + tadah::core::t_type T = desmat.getT(); M_KRR_Train<K>::train(Phi,T); if (config.template get<bool>("NORM") && @@ -408,4 +410,6 @@ non linear kernel\n"); using M_KRR_Train<K>::kernel; using M_KRR_Train<K>::ekm; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/models/m_tadah_base.h b/include/tadah/mlip/models/m_tadah_base.h index 3285cf0bf5572a1551c60ffaa0d78e74a66b2304..3c2b8840edbbb04714c05a489d235a56b5716d84 100644 --- a/include/tadah/mlip/models/m_tadah_base.h +++ b/include/tadah/mlip/models/m_tadah_base.h @@ -10,6 +10,8 @@ #include <tadah/core/core_types.h> #include <tadah/models/m_core.h> #include <tadah/models/m_predict.h> +namespace tadah { +namespace mlip { /** This interface provides functionality required from all models. */ @@ -30,52 +32,52 @@ public: double epredict(const StDescriptors &std); ///** \brief Predict force between a pair of atoms in a k-direction. */ - //virtual double fpredict(const fd_type &fdij, const aed_type &aedi, size_t k)=0; + //virtual double fpredict(const tadah::core::fd_type &fdij, const tadah::core::aed_type &aedi, size_t k)=0; ///** \brief Predict force between a pair of atoms. */ - //virtual force_type fpredict(const fd_type &fdij, - // const aed_type &aedi)=0; + //virtual tadah::core::force_type fpredict(const tadah::core::fd_type &fdij, + // const tadah::core::aed_type &aedi)=0; /** \brief Predict total force on an atom a. */ - virtual void fpredict(const size_t a, force_type &v, + virtual void fpredict(const size_t a, tadah::core::force_type &v, const StDescriptors &std, const Structure &st); /** \brief Predict total force on an atom a. */ - virtual force_type fpredict(const size_t a, const StDescriptors &std, + virtual tadah::core::force_type fpredict(const size_t a, const StDescriptors &std, const Structure &st); /** \brief Predict energy, forces and stresses for the Structure st. */ - virtual Structure predict(const Config &c, + virtual Structure predict(const tadah::core::Config &c, /*not const*/ StDescriptors &std, const Structure &st); /** \brief Predict energy, forces and stresses for a set of Structures. * * Use precalculated descriptors. */ - virtual StructureDB predict(const Config &c, + virtual StructureDB predict(const tadah::core::Config &c, /*not const*/ StDescriptorsDB &st_desc_db, const StructureDB &stdb); /** \brief Predict energy, forces and stresses for a set of Structures. */ - virtual StructureDB predict(Config &c, const StructureDB &stdb, DC_Base &dc); + virtual StructureDB predict(tadah::core::Config &c, const StructureDB &stdb, DC_Base &dc); /** \brief Predict virial stresses in a Structure st. */ - virtual stress_type spredict(const StDescriptors &std, const Structure &st); + virtual tadah::core::stress_type spredict(const StDescriptors &std, const Structure &st); /** \brief Predict virial stresses in all Structures. */ - virtual stress_type spredict(const size_t a, const StDescriptors &std, + virtual tadah::core::stress_type spredict(const size_t a, const StDescriptors &std, const Structure &st); /** \brief Predict both virial stresses and forces for a Structure */ virtual void stress_force_predict(const StDescriptors &std, Structure &st); /** \brief Predict virial stress for atom a in a Structure st. */ - virtual void spredict(const size_t a, stress_type &s, + virtual void spredict(const size_t a, tadah::core::stress_type &s, const StDescriptors &std, const Structure &st); /** Return potential file. */ - virtual Config get_param_file()=0; + virtual tadah::core::Config get_param_file()=0; // TRAINING @@ -96,11 +98,13 @@ public: */ virtual void train(StDescriptorsDB &, const StructureDB &) {}; - virtual StructureDB predict(Config config_pred, StructureDB &stdb, DC_Base &dc, - aed_type &predicted_error)=0; + virtual StructureDB predict(tadah::core::Config config_pred, StructureDB &stdb, DC_Base &dc, + tadah::core::aed_type &predicted_error)=0; virtual StructureDB predict(StructureDB &stdb)=0; }; -//template<> inline Registry<M_Tadah_Base,DM_Function_Base&,Config&>::Map Registry<M_Tadah_Base,DM_Function_Base&,Config&>::registry{}; +//template<> inline Registry<M_Tadah_Base,DM_Function_Base&,tadah::core::Config&>::Map Registry<M_Tadah_Base,DM_Function_Base&,tadah::core::Config&>::registry{}; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/nn_finder.h b/include/tadah/mlip/nn_finder.h index 2593334383f35c22037303bbf6784879bdd6e1b3..f91819c77ef29c842dac1a902e27dd7bef69246e 100644 --- a/include/tadah/mlip/nn_finder.h +++ b/include/tadah/mlip/nn_finder.h @@ -5,6 +5,8 @@ #include <tadah/core/lapack.h> #include <tadah/mlip/structure.h> #include <tadah/mlip/structure_db.h> +namespace tadah { +namespace mlip { /** * @class NNFinder @@ -143,7 +145,7 @@ public: /** * Construct with cutoff from config("RCUTMAX"). */ - NNFinder(Config &config); + NNFinder(tadah::core::Config &config); /** * Build nearest neighbors for all atoms in one Structure. @@ -157,6 +159,8 @@ public: void calc(StructureDB &stdb); }; +} // namespace mlip +} // namespace tadah #endif // NN_FINDER_H diff --git a/include/tadah/mlip/normaliser.h b/include/tadah/mlip/normaliser.h index 72e8be17b58cba85a1761360313df9da5fc454b4..508893521466efe783593c15bed8de4a1a3a54ec 100644 --- a/include/tadah/mlip/normaliser.h +++ b/include/tadah/mlip/normaliser.h @@ -8,6 +8,8 @@ #include <limits> #include <stdexcept> +namespace tadah { +namespace mlip { class Normaliser: public Normaliser_Core { public: @@ -16,10 +18,10 @@ class Normaliser: public Normaliser_Core { Normaliser (): Normaliser_Core() {}; - Normaliser (Config &c): + Normaliser (tadah::core::Config &c): Normaliser_Core(c) {}; - Normaliser(Config &c,StDescriptorsDB &st_desc_db): + Normaliser(tadah::core::Config &c,StDescriptorsDB &st_desc_db): Normaliser_Core(c) { learn(st_desc_db); @@ -36,13 +38,13 @@ class Normaliser: public Normaliser_Core { // prep containers size_t dim = st_desc_db(0).dim(); - mean = v_type(dim); - std_dev = v_type(dim); + mean = tadah::core::v_type(dim); + std_dev = tadah::core::v_type(dim); //std::cout << "COLS NORM: " << nn << std::endl; // compute mean and st_dev for (size_t d=0; d<dim; ++d) { - t_type v(n); + tadah::core::t_type v(n); size_t b=0; for (size_t s=0; s<st_desc_db.size(); ++s) { //for (const auto &aed:st_desc_db(s).aed) { @@ -95,4 +97,6 @@ class Normaliser: public Normaliser_Core { } }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/output/output.h b/include/tadah/mlip/output/output.h index e583c9229e3725899d6696ffddb0065dfea92332..a8036ab0b9d2166792e0280721708968097b888b 100644 --- a/include/tadah/mlip/output/output.h +++ b/include/tadah/mlip/output/output.h @@ -10,10 +10,12 @@ #include <iostream> #include <iomanip> #include <string> +namespace tadah { +namespace mlip { class Output { private: - Config &pot_config; + tadah::core::Config &pot_config; bool pred_err_bool; //size_t sigfig; //size_t nw; @@ -22,11 +24,11 @@ class Output { size_t emptyspace=5; size_t nw=emptyspace+fmtw; // width of numeric column public: - Output (Config &c, bool peb): + Output (tadah::core::Config &c, bool peb): pot_config(c), pred_err_bool(peb) {} - void print_train_unc(t_type &weights, t_type &unc) { + void print_train_unc(tadah::core::t_type &weights, tadah::core::t_type &unc) { std::string index_str="Index"; size_t iwe=(size_t)unc.size() > max_number(index_str.size()) ? @@ -45,7 +47,7 @@ class Output { out_unc.close(); } - void print_predict_all(StructureDB &stdb, StructureDB &stpred, aed_type & predicted_error) { + void print_predict_all(StructureDB &stdb, StructureDB &stpred, tadah::core::aed_type & predicted_error) { std::ofstream out_error("error.pred"); std::ofstream out_energy("energy.pred"); std::ofstream out_force("forces.pred"); @@ -143,8 +145,8 @@ class Output { if (newline) out_force << std::endl << std::endl; for (size_t a=0; a<stdb(i).natoms(); ++a) { - Vec3d &f = stdb(i).atoms[a].force; - Vec3d &fp = stpred(i).atoms[a].force; + tadah::core::Vec3d &f = stdb(i).atoms[a].force; + tadah::core::Vec3d &fp = stpred(i).atoms[a].force; for (size_t k=0; k<3; ++k) { out_force << std::setw(iwf) << fidx++ << std::setw(nw) << f[k] << std::setw(nw) << fp[k]; @@ -163,8 +165,8 @@ class Output { double max_serr=0.0; if (newline) out_stress << std::endl << std::endl; - stress_type &s = stdb(i).stress; - stress_type &sp = stpred(i).stress; + tadah::core::stress_type &s = stdb(i).stress; + tadah::core::stress_type &sp = stpred(i).stress; for (size_t x=0; x<3; ++x) { for (size_t y=x; y<3; ++y) { out_stress << std::setw(iws) << sidx++ << std::setw(nw) << s(x,y) @@ -198,4 +200,6 @@ class Output { } }; +} // namespace mlip +} // namespace tadah #endif // !OUTPUT_H diff --git a/include/tadah/mlip/st_descriptors.h b/include/tadah/mlip/st_descriptors.h index f5cf2ad234a067afafb78c18c02427cfe3e0cee9..878b7234f0c3d6bd2bf722789e3e53aa907eff46 100644 --- a/include/tadah/mlip/st_descriptors.h +++ b/include/tadah/mlip/st_descriptors.h @@ -6,6 +6,8 @@ #include <tadah/core/core_types.h> #include <vector> +namespace tadah { +namespace mlip { /** \brief Container for a structure descriptors. @@ -18,11 +20,11 @@ * To fully initialise this object it needs to know: * - number of atoms in a structure (from Structure) * - number of nn for every atom (from Structure) - * - dimension of the descriptor vector (Config) - * - whether force and stress is being calculated (from Config) + * - dimension of the descriptor vector (tadah::core::Config) + * - whether force and stress is being calculated (from tadah::core::Config) * * \note - * Required Config keys: + * Required tadah::core::Config keys: * \ref FORCE \ref STRESS. * \ref INTERNAL_KEY \ref DSIZE. * @@ -33,9 +35,9 @@ struct StDescriptors { * * Requires: * - Structure st to have NN calculated - * - Config c to contain keys: \ref DSIZE, \ref FORCE, \ref STRESS + * - tadah::core::Config c to contain keys: \ref DSIZE, \ref FORCE, \ref STRESS */ - StDescriptors(const Structure &s, const Config &c); + StDescriptors(const Structure &s, const tadah::core::Config &c); /** Default constructor. Object is left uninitialised */ StDescriptors(); @@ -48,14 +50,14 @@ struct StDescriptors { * Dimensions: * [number of atoms, descriptor size] */ - aeds_type2 aeds; + tadah::core::aeds_type2 aeds; /** FD for all atoms * * Dimensions: * [number of atoms, number of atom NN, descriptor size, 3] */ - std::vector<std::vector<fd_type>> fd; + std::vector<std::vector<tadah::core::fd_type>> fd; /** SD for a Structure * @@ -67,14 +69,16 @@ struct StDescriptors { /** True if descriptors are normalised */ bool normalised=false; - rhos_type rhos; + tadah::core::rhos_type rhos; - aed_type & get_aed(const size_t i); - const aed_type &get_aed(const size_t i) const; - rho_type& get_rho(const size_t i); + tadah::core::aed_type & get_aed(const size_t i); + const tadah::core::aed_type &get_aed(const size_t i) const; + tadah::core::rho_type& get_rho(const size_t i); size_t naed() const; size_t dim() const; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/st_descriptors_db.h b/include/tadah/mlip/st_descriptors_db.h index 6272db8c0b1dab60451dae98beaa6ec42c9d85a6..bb0349d5963caf8f10dff981a28c8c3503c0994f 100644 --- a/include/tadah/mlip/st_descriptors_db.h +++ b/include/tadah/mlip/st_descriptors_db.h @@ -4,12 +4,14 @@ #include <tadah/core/config.h> #include <tadah/mlip/st_descriptors.h> #include <tadah/mlip/structure_db.h> +namespace tadah { +namespace mlip { /** \brief Container for StDescriptors. * * \note - * Required Config keys: + * Required tadah::core::Config keys: * \ref FORCE \ref STRESS * \ref INTERNAL_KEY \ref DSIZE. * @@ -22,10 +24,10 @@ struct StDescriptorsDB { * * Requires: * - StructureDB st to have all nearest neighbours calculated - * - Config to contain keys: \ref FORCE, \ref STRESS + * - tadah::core::Config to contain keys: \ref FORCE, \ref STRESS * and \ref INTERNAL_KEY \ref DSIZE */ - StDescriptorsDB(const StructureDB &stdb, Config &config); + StDescriptorsDB(const StructureDB &stdb, tadah::core::Config &config); /** Return reference to the n-th StDescriptors * stored by this object @@ -45,4 +47,6 @@ struct StDescriptorsDB { std::vector<StDescriptors>::const_iterator end() const; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/structure.h b/include/tadah/mlip/structure.h index 9481314d7a01e33dbd7e1db0b227bed5fb0c5920..81d30af26f182c51334a35cf807b19cb66450226 100644 --- a/include/tadah/mlip/structure.h +++ b/include/tadah/mlip/structure.h @@ -11,6 +11,8 @@ #include <iomanip> #include <vector> #include <set> +namespace tadah { +namespace mlip { /** * Container for a collection of Atom(s). @@ -54,10 +56,10 @@ struct Structure { double energy; /** Lattice vectors. */ - Matrix3d cell; + tadah::core::Matrix3d cell; /** Virial stress tensor. */ - stress_type stress; + tadah::core::stress_type stress; /** Container for atoms which belong to this structure */ std::vector<Atom> atoms; @@ -88,7 +90,7 @@ struct Structure { * Note that there might be more than one periodic image in each direction. * This depends on the box size and the cutoff distance used. */ - std::vector<std::vector<Vec3d>> near_neigh_shift; + std::vector<std::vector<tadah::core::Vec3d>> near_neigh_shift; /** List of global indices for nearest neighbours for every atom */ std::vector<std::vector<size_t>> near_neigh_idx; @@ -166,9 +168,9 @@ struct Structure { * near_neigh_idx[i][n] -> global index of neighbor * near_neigh_shift[i][n] -> integer triple (n1, n2, n3) OR real shift * - * Returns by value (Vec3d) so we don't reference a temporary. + * Returns by value (tadah::core::Vec3d) so we don't reference a temporary. */ - Vec3d nn_pos(const size_t i, const size_t n) const; + tadah::core::Vec3d nn_pos(const size_t i, const size_t n) const; /** @return a number of nearest neighbours of the i-th Atom. */ size_t nn_size(const size_t i) const; @@ -314,7 +316,7 @@ struct Structure { void dump_to_file(const std::string& filepath, size_t prec=12) const; /** List of chemical elements in this structure. */ - std::set<Element> get_unique_elements() const; + std::set<tadah::core::Element> get_unique_elements() const; private: const static size_t w=13; // controls output width @@ -322,4 +324,6 @@ struct Structure { }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/structure_db.h b/include/tadah/mlip/structure_db.h index b96eac0683a11ac4bb827ff91784c21874effaa5..48c972777c22abccb2e9f41c5923ccefa34559b7 100644 --- a/include/tadah/mlip/structure_db.h +++ b/include/tadah/mlip/structure_db.h @@ -12,6 +12,8 @@ #include <vector> #include <set> +namespace tadah { +namespace mlip { /** * Container for a collection of Structure(s). * @@ -51,7 +53,7 @@ struct StructureDB { * \note * Required Config key: \ref DBFILE */ - StructureDB(Config &config); + StructureDB(tadah::core::Config &config); /** Add structures listed in the config file * @@ -59,7 +61,7 @@ struct StructureDB { * Required Config key: \ref DBFILE * */ - void add(Config &config); + void add(tadah::core::Config &config); /** Add all structures from a file */ void add(const std::string fn); @@ -140,16 +142,16 @@ struct StructureDB { size_t calc_natoms(size_t n) const; /** Return unique elements for all Structures. */ - std::set<Element> get_unique_elements() const; + std::set<tadah::core::Element> get_unique_elements() const; /** Find unique elements in provided Config file */ - static std::set<Element> find_unique_elements(const Config &c); + static std::set<tadah::core::Element> find_unique_elements(const tadah::core::Config &c); /** Find unique elements in provided file */ - static std::set<Element> find_unique_elements(const std::string &fn); + static std::set<tadah::core::Element> find_unique_elements(const std::string &fn); /** Count number of structures and atoms in all datasets from the Config file. */ - static std::pair<int,int> count(const Config &c); + static std::pair<int,int> count(const tadah::core::Config &c); /** Count number of structures and atoms in a single dataset. */ static std::pair<int,int> count(const std::string fn); @@ -157,10 +159,10 @@ struct StructureDB { void clear_nn(); /** Check consistency of the ATOMS key. */ - static void check_atoms_key(Config &config, std::set<Element> &unique_elements); + static void check_atoms_key(tadah::core::Config &config, std::set<tadah::core::Element> &unique_elements); /** Check consistency of the WATOMS key. Add if missing*/ - static void check_watoms_key(Config &config, std::set<Element> &unique_elements); + static void check_watoms_key(tadah::core::Config &config, std::set<tadah::core::Element> &unique_elements); // Methods to enable range-based for loop std::vector<Structure>::iterator begin(); @@ -180,4 +182,6 @@ private: bool isBlankLine(const std::string& line) const; }; +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/structure_properties.h b/include/tadah/mlip/structure_properties.h index 1af97602eff13d8b5ac8f3e85c56ac687971f7db..15d662e438ed90c89a4e20f81b39ba550a7080fb 100644 --- a/include/tadah/mlip/structure_properties.h +++ b/include/tadah/mlip/structure_properties.h @@ -2,6 +2,8 @@ #define STRUCTURE_PROPERTIES_H #include <tadah/mlip/structure.h> +namespace tadah { +namespace mlip { /** * @class StructureProperties @@ -26,7 +28,7 @@ public: * @brief Computes the density of the Structure in g/cm^3. * * Procedure: - * - Accumulate atomic mass from PeriodicTable::get_mass(atom.Z) in amu. + * - Accumulate atomic mass from tadah::core::PeriodicTable::get_mass(atom.Z) in amu. * - Convert volume from Å^3 to cm^3 (1 Å^3 = 1e-24 cm^3). * - Multiply total mass (amu) by 1.66053906660e-24 g/amu. * - Divide by volume in cm^3 => density. @@ -40,14 +42,16 @@ public: * Sums (mass_i * position_i) for each atom, divides by total mass. * If no atoms exist, returns (0,0,0). */ - static Vec3d getCentreOfMass(const Structure &st); + static tadah::core::Vec3d getCentreOfMass(const Structure &st); /** * @brief Computes the *geometric center* (centroid) of all atoms. * * If no atoms exist, returns (0,0,0). */ - static Vec3d getGeometricCenter(const Structure &st); + static tadah::core::Vec3d getGeometricCenter(const Structure &st); }; +} // namespace mlip +} // namespace tadah #endif // STRUCTURE_PROPERTIES_H diff --git a/include/tadah/mlip/structure_readers/aflow_reader.h b/include/tadah/mlip/structure_readers/aflow_reader.h index d302668887be4bc88ca5433ce275f7b24f349669..a456c45f4f66dba9956dbeac45036cd93e1d3ec2 100644 --- a/include/tadah/mlip/structure_readers/aflow_reader.h +++ b/include/tadah/mlip/structure_readers/aflow_reader.h @@ -8,6 +8,8 @@ #include <tadah/mlip/data_providers/aflow_data_provider.h> #include <tadah/mlip/structure_readers/istructure_reader.h> #include <tadah/mlip/structure.h> +namespace tadah { +namespace mlip { /** * @class AflowReader @@ -50,4 +52,6 @@ private: double (&cell)[3][3]); }; +} // namespace mlip +} // namespace tadah #endif // AFLOW_READER_H diff --git a/include/tadah/mlip/structure_readers/castep_cell_reader.h b/include/tadah/mlip/structure_readers/castep_cell_reader.h index 1cbeec0c537b996b7c823429493b6c445cb9181f..daa847a5ac9545bab8ff948e5033e2bc571fe445 100644 --- a/include/tadah/mlip/structure_readers/castep_cell_reader.h +++ b/include/tadah/mlip/structure_readers/castep_cell_reader.h @@ -4,6 +4,8 @@ #include <string> #include <tadah/mlip/structure.h> #include <tadah/mlip/structure_readers/istructure_reader.h> +namespace tadah { +namespace mlip { /** * @brief Reads crystallographic and atomic data from a CASTEP .cell file. @@ -66,9 +68,11 @@ private: double &cz); /** - * @brief Helper for mapping string species (e.g., "Si", "O") to Element enum. + * @brief Helper for mapping string species (e.g., "Si", "O") to tadah::core::Element enum. */ - Element parseSpecies(const std::string &sym); + tadah::core::Element parseSpecies(const std::string &sym); }; +} // namespace mlip +} // namespace tadah #endif // CASTEP_CELL_READER_H diff --git a/include/tadah/mlip/structure_readers/cif_reader.h b/include/tadah/mlip/structure_readers/cif_reader.h index f3c524510334102fda3331a0e29257c9e2a829b8..ed15419879c819994d3dbf47b10d4ba152b5e536 100644 --- a/include/tadah/mlip/structure_readers/cif_reader.h +++ b/include/tadah/mlip/structure_readers/cif_reader.h @@ -4,6 +4,8 @@ #include <tadah/mlip/structure_readers/istructure_reader.h> #include <tadah/mlip/structure.h> #include <string> +namespace tadah { +namespace mlip { /** * @brief Reads Structure data from a CIF file using older Gemmi APIs. @@ -47,5 +49,7 @@ private: static double deg2rad(double deg); }; +} // namespace mlip +} // namespace tadah #endif // CIF_READER_H diff --git a/include/tadah/mlip/structure_readers/cod_reader.h b/include/tadah/mlip/structure_readers/cod_reader.h index 5d8d5ce42021608ad43f6eb488a3898c7610fd93..ce09f5ffd2d9fc1fe7bc4c919a68c8c2e4b5c3e6 100644 --- a/include/tadah/mlip/structure_readers/cod_reader.h +++ b/include/tadah/mlip/structure_readers/cod_reader.h @@ -9,6 +9,8 @@ #include <tadah/mlip/structure_readers/istructure_reader.h> #include <tadah/mlip/structure_readers/cif_reader.h> #include <tadah/mlip/structure.h> +namespace tadah { +namespace mlip { /** * @brief Reads a CIF file from the Crystallography Open Database (COD) @@ -70,5 +72,7 @@ private: std::unique_ptr<IMaterialsDataProvider> m_dataProvider; }; +} // namespace mlip +} // namespace tadah #endif // COD_READER_H diff --git a/include/tadah/mlip/structure_readers/istructure_reader.h b/include/tadah/mlip/structure_readers/istructure_reader.h index a9f0c5cdb9fe86d2c0e69897ba6391191062fe4a..e47761600c154ec29b5c1583f8a068faa1efc536 100644 --- a/include/tadah/mlip/structure_readers/istructure_reader.h +++ b/include/tadah/mlip/structure_readers/istructure_reader.h @@ -3,6 +3,8 @@ #include <string> #include <tadah/mlip/structure.h> +namespace tadah { +namespace mlip { /** * @brief Abstract base class for reading a Structure from a file or remote source. @@ -33,4 +35,6 @@ public: virtual Structure getStructure() const = 0; }; +} // namespace mlip +} // namespace tadah #endif // TADAH_MLIP_STRUCTURE_READERS_ISTRUCTURE_READER_H diff --git a/include/tadah/mlip/structure_readers/materials_project_reader.h b/include/tadah/mlip/structure_readers/materials_project_reader.h index 716cdc7f70a49f161ed09edc40a38830f09bd8be..3faf46f5e8576887c2fe207ca37ec86df23a195c 100644 --- a/include/tadah/mlip/structure_readers/materials_project_reader.h +++ b/include/tadah/mlip/structure_readers/materials_project_reader.h @@ -8,6 +8,8 @@ #include <tadah/mlip/data_providers/materials_project_data_provider.h> #include <tadah/mlip/structure_readers/istructure_reader.h> #include <tadah/mlip/structure.h> +namespace tadah { +namespace mlip { /** * @brief Reads a Structure from the Materials Project via REST API. @@ -52,4 +54,6 @@ private: void parseMpJson(const std::string &jsonContent); }; +} // namespace mlip +} // namespace tadah #endif // MATERIALS_PROJECT_READER_H diff --git a/include/tadah/mlip/structure_readers/nomad_reader.h b/include/tadah/mlip/structure_readers/nomad_reader.h index 62c0807c2667a5895e904c52e8c37a9417c9b8a6..e4c9b9f0745ad54b6f0be4b1dfa602afce341247 100644 --- a/include/tadah/mlip/structure_readers/nomad_reader.h +++ b/include/tadah/mlip/structure_readers/nomad_reader.h @@ -8,6 +8,8 @@ #include <tadah/mlip/data_providers/nomad_data_provider.h> #include <tadah/mlip/structure_readers/istructure_reader.h> #include <tadah/mlip/structure.h> +namespace tadah { +namespace mlip { /** * @class NomadReader @@ -60,5 +62,7 @@ private: double (&cell)[3][3]); }; +} // namespace mlip +} // namespace tadah #endif // NOMAD_READER_H diff --git a/include/tadah/mlip/structure_readers/structure_reader_selector.h b/include/tadah/mlip/structure_readers/structure_reader_selector.h index 35ee06269deba46c2983efd1431285ddfff3175f..1a96b7a486ce44aea1a880a4f86d6a569665051d 100644 --- a/include/tadah/mlip/structure_readers/structure_reader_selector.h +++ b/include/tadah/mlip/structure_readers/structure_reader_selector.h @@ -4,6 +4,8 @@ #include <memory> #include <string> #include <tadah/mlip/structure_readers/istructure_reader.h> +namespace tadah { +namespace mlip { /** * @brief A factory that provides an appropriate IStructureReader @@ -26,4 +28,6 @@ private: static std::string guessFormatFromContent(const std::string &filePath); }; +} // namespace mlip +} // namespace tadah #endif // STRUCTURE_READER_SELECTOR_H diff --git a/include/tadah/mlip/structure_readers/vasp_poscar_reader.h b/include/tadah/mlip/structure_readers/vasp_poscar_reader.h index 106ed27c1bdaa7c2d6a7c4b07358c71a89cc9923..f1db6ee79de1c9877d5fa7d215eefa6efba4fd8e 100644 --- a/include/tadah/mlip/structure_readers/vasp_poscar_reader.h +++ b/include/tadah/mlip/structure_readers/vasp_poscar_reader.h @@ -2,6 +2,8 @@ #define VASP_POSCAR_READER_H #include <tadah/mlip/structure_readers/istructure_reader.h> +namespace tadah { +namespace mlip { /** * @brief Reads a VASP POSCAR/CONTCAR file. @@ -10,7 +12,7 @@ * 1) Comment line * 2) Scaling factor * 3-5) Lattice vectors - * 6) Element symbols or counts + * 6) tadah::core::Element symbols or counts * 7) Possibly "Selective dynamics" line * 8) "Direct" or "Cartesian" * 9+) Atomic coordinates @@ -27,4 +29,6 @@ private: void parsePoscar(const std::vector<std::string> &lines); }; +} // namespace mlip +} // namespace tadah #endif // VASP_POSCAR_READER_H diff --git a/include/tadah/mlip/structure_transformations.h b/include/tadah/mlip/structure_transformations.h index d3144d2d4e4e44164737bdf99cb095518da94ca5..8eaa65c9baa01c261530b2fc114bbbf91e725728 100644 --- a/include/tadah/mlip/structure_transformations.h +++ b/include/tadah/mlip/structure_transformations.h @@ -2,6 +2,8 @@ #define STRUCTURE_TRANSFORMATION_H #include <tadah/mlip/structure.h> +namespace tadah { +namespace mlip { /** * @class StructureTransformation @@ -48,7 +50,7 @@ public: * pos' = R * pos. * Stress => S' = R * S * R^T. */ - static void rotate(Structure &st, const Matrix3d &R); + static void rotate(Structure &st, const tadah::core::Matrix3d &R); /** * Shears cell and atoms by shearMatrix: @@ -56,7 +58,7 @@ public: * pos' = shearMatrix * pos, * S' = shearMatrix * S * (shearMatrix^T). */ - static void shear(Structure &st, const Matrix3d &shearMatrix); + static void shear(Structure &st, const tadah::core::Matrix3d &shearMatrix); /** * Replicates the structure nx, ny, nz times along cell vectors. @@ -68,7 +70,7 @@ public: /** * Shifts all atomic positions by shiftVec. Cell and stress remain unchanged. */ - static void shift(Structure &st, const Vec3d &shiftVec); + static void shift(Structure &st, const tadah::core::Vec3d &shiftVec); /** * Mirrors about origin => pos' = -pos. @@ -81,7 +83,7 @@ public: * Reflects positions via p' = p - 2*(p·n_hat) * n_hat. * Then S' = M*S*M^T, M = (I - 2n_hat n_hat^T). */ - static void mirrorPlane(Structure &st, const Vec3d &normalVec); + static void mirrorPlane(Structure &st, const tadah::core::Vec3d &normalVec); /** * Mirrors about a plane with Miller indices (h,k,l) through origin. @@ -120,7 +122,7 @@ public: * Checks distance from all existing atoms. If below minDistance, prints warning. */ static void addAtom(Structure &st, const Atom &atomTemplate, bool useRandomPosition = false, - const Vec3d &pos = Vec3d(0.0, 0.0, 0.0), double minDistance = 0.8); + const tadah::core::Vec3d &pos = tadah::core::Vec3d(0.0, 0.0, 0.0), double minDistance = 0.8); /** * Removes an atom with a given global index from the structure if valid. @@ -137,7 +139,7 @@ public: static void shakeAtoms(Structure &st, double maxDisplacement); private: - static void transformStress(Structure &st, const Matrix3d &M); + static void transformStress(Structure &st, const tadah::core::Matrix3d &M); static void checkNearSingular(const Structure &st); /** @@ -146,4 +148,6 @@ private: static double rand01(); }; +} // namespace mlip +} // namespace tadah #endif // STRUCTURE_TRANSFORMATION_H diff --git a/include/tadah/mlip/structure_writers/castep_cell_writer.h b/include/tadah/mlip/structure_writers/castep_cell_writer.h index 221578759466f9fa3e77f52b5fe498cd27786ba8..8958dc806962b22998a50d1374caaf8d63b80c61 100644 --- a/include/tadah/mlip/structure_writers/castep_cell_writer.h +++ b/include/tadah/mlip/structure_writers/castep_cell_writer.h @@ -10,6 +10,8 @@ #include <sstream> #include <vector> #include <stdexcept> +namespace tadah { +namespace mlip { class CastepCellWriter : public StructureWriter { public: CastepCellWriter(StructureDB& db); @@ -18,6 +20,8 @@ public: }; +} // namespace mlip +} // namespace tadah #endif // CASTEP_CELL_WRITER_H diff --git a/include/tadah/mlip/structure_writers/lammps_structure_writer.h b/include/tadah/mlip/structure_writers/lammps_structure_writer.h index 8d76b4d19643166ee32c14c7e1672644f77c1295..7db3b3a8cb7d25e707fb47bae8fbfc175b538e8a 100644 --- a/include/tadah/mlip/structure_writers/lammps_structure_writer.h +++ b/include/tadah/mlip/structure_writers/lammps_structure_writer.h @@ -10,6 +10,8 @@ #include <sstream> #include <vector> #include <stdexcept> +namespace tadah { +namespace mlip { class LammpsStructureWriter : public StructureWriter { public: LammpsStructureWriter(StructureDB& db); @@ -18,4 +20,6 @@ public: }; +} // namespace mlip +} // namespace tadah #endif // LAMMPS_STRUCTURE_WRITER_H diff --git a/include/tadah/mlip/structure_writers/structure_writer.h b/include/tadah/mlip/structure_writers/structure_writer.h index d736922129b622b5c96207c9fb2a4d112f365ca2..abddb0a2568184171bf378306158f0d7c34fc6a7 100644 --- a/include/tadah/mlip/structure_writers/structure_writer.h +++ b/include/tadah/mlip/structure_writers/structure_writer.h @@ -4,6 +4,8 @@ #include <tadah/mlip/structure_db.h> #include <string> #include <vector> +namespace tadah { +namespace mlip { class StructureWriter { public: @@ -20,4 +22,6 @@ class StructureWriter { double p = 10; // output precision double w = p+6; // column width }; +} // namespace mlip +} // namespace tadah #endif // STRUCTURE_WRITER_H diff --git a/include/tadah/mlip/structure_writers/structure_writer_selector.h b/include/tadah/mlip/structure_writers/structure_writer_selector.h index 7630c918f8c93100ee45440786d1183a028796f0..2c0a9cec0a84ce2e67729ef717e3ef2a53f840f8 100644 --- a/include/tadah/mlip/structure_writers/structure_writer_selector.h +++ b/include/tadah/mlip/structure_writers/structure_writer_selector.h @@ -5,6 +5,8 @@ #include <tadah/mlip/structure_writers/structure_writer.h> #include <string> #include <memory> +namespace tadah { +namespace mlip { class StructureWriterSelector { public: @@ -12,4 +14,6 @@ class StructureWriterSelector { }; +} // namespace mlip +} // namespace tadah #endif // STRUCTURE_WRITER_SELECTOR_H diff --git a/include/tadah/mlip/structure_writers/vasp_poscar_writer.h b/include/tadah/mlip/structure_writers/vasp_poscar_writer.h index 1215c01735c1d851d6b76332f720a79c5c7ffdc4..8e5297bdd31b0b720089126cc74c4c7a2afdc9ba 100644 --- a/include/tadah/mlip/structure_writers/vasp_poscar_writer.h +++ b/include/tadah/mlip/structure_writers/vasp_poscar_writer.h @@ -10,6 +10,8 @@ #include <sstream> #include <vector> #include <stdexcept> +namespace tadah { +namespace mlip { class VaspPoscarWriter : public StructureWriter { public: VaspPoscarWriter(StructureDB& db); @@ -18,4 +20,6 @@ public: }; +} // namespace mlip +} // namespace tadah #endif // VASP_POSCAR_WRITER_H diff --git a/include/tadah/mlip/trainer.h b/include/tadah/mlip/trainer.h index e7a77763502a8b69c924b65b5dbe5b040471ba78..ed577fd145b1f7e44fa463afecd5c77810d46f3e 100644 --- a/include/tadah/mlip/trainer.h +++ b/include/tadah/mlip/trainer.h @@ -14,7 +14,7 @@ class Trainer { public: - Config config; + tadah::core::Config config; DC_Selector DCS; DescriptorsCalc<> dc; NNFinder nnf; @@ -28,15 +28,15 @@ class Trainer { if(fb) delete fb; } - Trainer (Config &c, tadah::mlip::memory::IMLIPWorkspaceManager& workspaceManager): + Trainer (tadah::core::Config &c, tadah::mlip::memory::IMLIPWorkspaceManager& workspaceManager): config(c), DCS(config), dc(config,*DCS.d2b,*DCS.d3b,*DCS.dmb, *DCS.c2b,*DCS.c3b,*DCS.cmb), nnf(config), - fb(CONFIG::factory<DM_Function_Base,Config&>( + fb(tadah::core::factory<DM_Function_Base,tadah::core::Config&>( config.get<std::string>("MODEL",1),config)), - model(CONFIG::factory<M_Tadah_Base,DM_Function_Base&,Config&,tadah::mlip::memory::IMLIPWorkspaceManager&> + model(tadah::core::factory<M_Tadah_Base,DM_Function_Base&,tadah::core::Config&,tadah::mlip::memory::IMLIPWorkspaceManager&> (config.get<std::string>("MODEL",0),*fb,config,workspaceManager)), dm(*fb, config, workspaceManager) { @@ -49,7 +49,7 @@ class Trainer { model->train(stdb,dc); } - Config get_param_file() { + tadah::core::Config get_param_file() { return model->get_param_file(); } @@ -58,6 +58,8 @@ class Trainer { #ifdef TADAH_BUILD_MPI #include <mpi.h> +namespace tadah { +namespace mlip { extern "C" void blacs_get_(int*, int*, int*); extern "C" void blacs_pinfo_(int*, int*); @@ -111,7 +113,7 @@ class MPI_Trainer: public Trainer { int rank; int ncpu; - MPI_Trainer(Config &c, int &rank, int &ncpu): + MPI_Trainer(tadah::core::Config &c, int &rank, int &ncpu): Trainer(c), rank(rank), ncpu(ncpu) @@ -284,7 +286,7 @@ class MPI_Trainer: public Trainer { dm.T.ptr(), &ione, &ione, descB, &context1); if (rank==0) { - t_type w(dm.T.ptr(), PHI_cols); + tadah::core::t_type w(dm.T.ptr(), PHI_cols); model->set_weights(w); // model->trained=true; // still can't train with this model } @@ -302,7 +304,7 @@ class TrainerHost: public MPI_Trainer { std::vector<std::tuple<std::string,int,int>> wpckgs; public: - TrainerHost(Config &c, int &rank, int &ncpu): + TrainerHost(tadah::core::Config &c, int &rank, int &ncpu): MPI_Trainer(c, rank, ncpu) {} @@ -461,7 +463,7 @@ class TrainerHost: public MPI_Trainer { class TrainerWorker: public MPI_Trainer { public: - TrainerWorker(Config &c, int &rank, int &ncpu): + TrainerWorker(tadah::core::Config &c, int &rank, int &ncpu): MPI_Trainer(c, rank, ncpu) {} @@ -630,4 +632,6 @@ class TrainerWorker: public MPI_Trainer { } }; #endif +} // namespace mlip +} // namespace tadah #endif diff --git a/include/tadah/mlip/version.h b/include/tadah/mlip/version.h index 7ab75cce5fb4f6463a4a6e2b69dca4c21b35da45..5b269e4c58d41efb267de14a0f20f23793e35c20 100644 --- a/include/tadah/mlip/version.h +++ b/include/tadah/mlip/version.h @@ -7,5 +7,7 @@ #define STRING(s) #s +} // namespace mlip +} // namespace tadah #endif diff --git a/src/DesignMatrixWorkspace.cpp b/src/DesignMatrixWorkspace.cpp index 51053e9e8dde1841187848e1928dc6a94763210f..40aa31d7aa19fcfbfdf72b65ecf05c52cb162957 100644 --- a/src/DesignMatrixWorkspace.cpp +++ b/src/DesignMatrixWorkspace.cpp @@ -3,7 +3,6 @@ #include <stdexcept> #include <tadah/core/lapack.h> #include <tadah/mlip/memory/DesignMatrixWorkspace.h> - namespace tadah { namespace mlip { namespace memory { @@ -30,4 +29,3 @@ bool DesignMatrixWorkspace::isSufficient(size_t m_, size_t n_) const { } // namespace memory } // namespace mlip } // namespace tadah - diff --git a/src/IMLIPWorkspaceManager.cpp b/src/IMLIPWorkspaceManager.cpp index 268d1c1e21723eb70a2b63822378e68f3a6af771..793d2b3ac645e1fa449e60e85d37ee119111c4e4 100644 --- a/src/IMLIPWorkspaceManager.cpp +++ b/src/IMLIPWorkspaceManager.cpp @@ -1,5 +1,4 @@ #include <tadah/mlip/memory/IMLIPWorkspaceManager.h> - namespace tadah { namespace mlip { namespace memory { @@ -9,4 +8,3 @@ IMLIPWorkspaceManager::~IMLIPWorkspaceManager() = default; } // namespace memory } // namespace mlip } // namespace tadah - diff --git a/src/MLIPWorkspaceManager.cpp b/src/MLIPWorkspaceManager.cpp index a077f45cfd3a48af578f9681caa258b491bd7c82..8d41a987b134df3a44bc7410028cd7ac821f92f0 100644 --- a/src/MLIPWorkspaceManager.cpp +++ b/src/MLIPWorkspaceManager.cpp @@ -1,6 +1,5 @@ #include <tadah/mlip/memory/MLIPWorkspaceManager.h> #include <tadah/mlip/memory/DesignMatrixWorkspace.h> - namespace tadah { namespace mlip { namespace memory { diff --git a/src/aflow_data_provider.cpp b/src/aflow_data_provider.cpp index 35e276853d119f823a6fd8fd321dd864cf0953c6..b5c2a91744193a28a3fd2f46ac2a5067c9a318b5 100644 --- a/src/aflow_data_provider.cpp +++ b/src/aflow_data_provider.cpp @@ -3,6 +3,8 @@ #include <curl/curl.h> #include <stdexcept> #include <sstream> +namespace tadah { +namespace mlip { size_t AFLOWDataProvider::writeCallback(char* ptr, size_t size, size_t nmemb, void* userdata) { @@ -124,3 +126,5 @@ RawResponse AFLOWDataProvider::fetchAndParseAflowByAuid(const std::string &auid) // Step 2) GET final data from 'aurl' return httpGet(aurl); } +} // namespace mlip +} // namespace tadah diff --git a/src/aflow_reader.cpp b/src/aflow_reader.cpp index 05e6fb4a22eee33bd0529694d6618ac9e1efb0d8..326d27ae2ef58464fab7866d7a860a986bf0fdd4 100644 --- a/src/aflow_reader.cpp +++ b/src/aflow_reader.cpp @@ -4,6 +4,8 @@ #include <sstream> #include <cmath> #include <vector> +namespace tadah { +namespace mlip { AflowReader::AflowReader() : m_dataProvider(std::make_unique<AFLOWDataProvider>()) { @@ -190,8 +192,8 @@ void AflowReader::parseAflowJson(const std::string &jsonContent) { // If mismatch, label everything "X". for (auto &coord : positions) { Atom atom; - auto unknown = PeriodicTable().find_by_symbol("X"); - static_cast<Element &>(atom) = unknown; + auto unknown = tadah::core::PeriodicTable().find_by_symbol("X"); + static_cast<tadah::core::Element &>(atom) = unknown; atom.position[0] = coord[0]; atom.position[1] = coord[1]; atom.position[2] = coord[2]; @@ -203,10 +205,10 @@ void AflowReader::parseAflowJson(const std::string &jsonContent) { // Distribute species among positions in order. size_t idxPos = 0; for (size_t iSpec = 0; iSpec < speciesList.size(); ++iSpec) { - Element e = PeriodicTable().find_by_symbol(speciesList[iSpec]); + tadah::core::Element e = tadah::core::PeriodicTable().find_by_symbol(speciesList[iSpec]); for (int rep = 0; rep < stoichCount[iSpec]; ++rep) { Atom atom; - static_cast<Element &>(atom) = e; + static_cast<tadah::core::Element &>(atom) = e; atom.position[0] = positions[idxPos][0]; atom.position[1] = positions[idxPos][1]; atom.position[2] = positions[idxPos][2]; @@ -261,3 +263,5 @@ void AflowReader::makeCellMatrix(double a, double b, double c, cell[2][2] = c * std::sqrt(term > 0.0 ? term : 0.0); // Remaining off-diagonal elements are zero-initialized by default. } +} // namespace mlip +} // namespace tadah diff --git a/src/analytics.cpp b/src/analytics.cpp index 57d1dca8ea035056caf01c8aa65f34a3292b920a..51c2f3e5d6d8c7def2df3522c908c03360f5a2b5 100644 --- a/src/analytics.cpp +++ b/src/analytics.cpp @@ -1,5 +1,7 @@ #include <tadah/mlip/analytics/analytics.h> #include <tadah/mlip/analytics/statistics.h> +namespace tadah { +namespace mlip { Analytics::Analytics(const StructureDB &st, const StructureDB &stp): st(st), @@ -9,9 +11,9 @@ Analytics::Analytics(const StructureDB &st, const StructureDB &stp): throw std::runtime_error("Containers differ in size."); } -t_type Analytics::calc_e_mae() const{ +tadah::core::t_type Analytics::calc_e_mae() const{ - t_type emae_vec(st.dbidx.size()-1); + tadah::core::t_type emae_vec(st.dbidx.size()-1); double emae=0; size_t dbidx=0; size_t N=0; @@ -29,9 +31,9 @@ t_type Analytics::calc_e_mae() const{ return emae_vec; } -t_type Analytics::calc_f_mae() const{ +tadah::core::t_type Analytics::calc_f_mae() const{ - t_type fmae_vec(st.dbidx.size()-1); + tadah::core::t_type fmae_vec(st.dbidx.size()-1); double fmae=0; size_t dbidx=0; size_t N=0; @@ -55,9 +57,9 @@ t_type Analytics::calc_f_mae() const{ return fmae_vec; } -t_type Analytics::calc_s_mae() const { +tadah::core::t_type Analytics::calc_s_mae() const { - t_type smae_vec(st.dbidx.size()-1); + tadah::core::t_type smae_vec(st.dbidx.size()-1); double smae=0; size_t dbidx=0; size_t N=0; @@ -78,8 +80,8 @@ t_type Analytics::calc_s_mae() const { return smae_vec; } -t_type Analytics::calc_e_rrmse() const { - t_type errmse_vec(st.dbidx.size()-1); +tadah::core::t_type Analytics::calc_e_rrmse() const { + tadah::core::t_type errmse_vec(st.dbidx.size()-1); double errmse=0; size_t dbidx=0; size_t N=0; @@ -98,9 +100,9 @@ t_type Analytics::calc_e_rrmse() const { return errmse_vec; } -t_type Analytics::calc_e_rmse() const{ +tadah::core::t_type Analytics::calc_e_rmse() const{ - t_type ermse_vec(st.dbidx.size()-1); + tadah::core::t_type ermse_vec(st.dbidx.size()-1); double ermse=0; size_t dbidx=0; size_t N=0; @@ -118,9 +120,9 @@ t_type Analytics::calc_e_rmse() const{ return ermse_vec; } -t_type Analytics::calc_f_rmse() const{ +tadah::core::t_type Analytics::calc_f_rmse() const{ - t_type frmse_vec(st.dbidx.size()-1); + tadah::core::t_type frmse_vec(st.dbidx.size()-1); double frmse=0; size_t dbidx=0; size_t N=0; @@ -144,9 +146,9 @@ t_type Analytics::calc_f_rmse() const{ return frmse_vec; } -t_type Analytics::calc_s_rmse() const { +tadah::core::t_type Analytics::calc_s_rmse() const { - t_type srmse_vec(st.dbidx.size()-1); + tadah::core::t_type srmse_vec(st.dbidx.size()-1); double srmse=0; size_t dbidx=0; size_t N=0; @@ -167,11 +169,11 @@ t_type Analytics::calc_s_rmse() const { return srmse_vec; } -t_type Analytics::calc_e_r_sq() const { - t_type e_r_sq_vec(st.dbidx.size()-1); +tadah::core::t_type Analytics::calc_e_r_sq() const { + tadah::core::t_type e_r_sq_vec(st.dbidx.size()-1); size_t dbidx=0; - t_type obs(st.size(dbidx)); - t_type pred(st.size(dbidx)); + tadah::core::t_type obs(st.size(dbidx)); + tadah::core::t_type pred(st.size(dbidx)); size_t idx=0; for (size_t i=0; i<st.size(); ++i) { obs(idx) = st(i).energy/st(i).natoms(); @@ -190,11 +192,11 @@ t_type Analytics::calc_e_r_sq() const { return e_r_sq_vec; } -t_type Analytics::calc_f_r_sq() const { - t_type f_r_sq_vec(st.dbidx.size()-1); +tadah::core::t_type Analytics::calc_f_r_sq() const { + tadah::core::t_type f_r_sq_vec(st.dbidx.size()-1); size_t dbidx=0; - t_type obs(3*st.calc_natoms(dbidx)); - t_type pred(3*st.calc_natoms(dbidx)); + tadah::core::t_type obs(3*st.calc_natoms(dbidx)); + tadah::core::t_type pred(3*st.calc_natoms(dbidx)); size_t idx=0; for (size_t i=0; i<st.size(); ++i) { for (size_t a=0; a<st(i).natoms(); ++a) { @@ -217,11 +219,11 @@ t_type Analytics::calc_f_r_sq() const { return f_r_sq_vec; } -t_type Analytics::calc_s_r_sq() const { - t_type s_r_sq_vec(st.dbidx.size()-1); +tadah::core::t_type Analytics::calc_s_r_sq() const { + tadah::core::t_type s_r_sq_vec(st.dbidx.size()-1); size_t dbidx=0; - t_type obs(6*st.size(dbidx)); - t_type pred(6*st.size(dbidx)); + tadah::core::t_type obs(6*st.size(dbidx)); + tadah::core::t_type pred(6*st.size(dbidx)); size_t idx=0; for (size_t i=0; i<st.size(); ++i) { @@ -245,3 +247,5 @@ t_type Analytics::calc_s_r_sq() const { } return s_r_sq_vec; } +} // namespace mlip +} // namespace tadah diff --git a/src/atom.cpp b/src/atom.cpp index 38abf459884b67c8f68adbc2eb9adc26e534afb1..450669b089b6619c1ef78ff47ba9c52bb4934f46 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -1,26 +1,28 @@ #include <tadah/mlip/atom.h> #include <tadah/core/periodic_table.h> #include <iomanip> +namespace tadah { +namespace mlip { Atom::Atom() {} -Atom::Atom(const Element &element, +Atom::Atom(const tadah::core::Element &element, const double px, const double py, const double pz, const double fx, const double fy, const double fz): - Element(element), + tadah::core::Element(element), position(px,py,pz), force(fx,fy,fz) {} -Atom::Atom(const Element &element, +Atom::Atom(const tadah::core::Element &element, const double px, const double py, const double pz): - Element(element), + tadah::core::Element(element), position(px,py,pz), force(0,0,0) {} std::ostream& operator<<(std::ostream& os, const Atom& atom) { - os << (Element&)atom; + os << (tadah::core::Element&)atom; os << "Coordinates: " << std::left << atom.position << std::endl; os << "Force: " << std::left << atom.force << std::endl; return os; @@ -30,12 +32,14 @@ bool Atom::operator==(const Atom &a) const { return position.isApprox(a.position, EPSILON) && force.isApprox(a.force, EPSILON) - && Element::operator==(a) + && tadah::core::Element::operator==(a) ; } bool Atom::is_the_same(const Atom &a, double thr) const { return position.isApprox(a.position, thr) - && Element::operator==(a) + && tadah::core::Element::operator==(a) ; } +} // namespace mlip +} // namespace tadah diff --git a/src/castep_castep_reader.cpp b/src/castep_castep_reader.cpp index bc9a05505244fb4abbfd46569175a66548a45d4a..582a517268962d2c88d371c5c6ae559765fad777 100644 --- a/src/castep_castep_reader.cpp +++ b/src/castep_castep_reader.cpp @@ -5,6 +5,8 @@ #include <tadah/mlip/structure.h> #include <tadah/mlip/structure_db.h> #include <tadah/mlip/dataset_readers/castep_castep_reader.h> +namespace tadah { +namespace mlip { CastepCastepReader::CastepCastepReader(StructureDB& db) : DatasetReader(db) {} @@ -334,7 +336,7 @@ void CastepCastepReader::parse_data() { break; } // Create Atom, convert fractional to absolute using s.cell - Atom a(Element(species), px, py, pz, 0.0, 0.0, 0.0); + Atom a(tadah::core::Element(species), px, py, pz, 0.0, 0.0, 0.0); atoms.push_back(a); // keep it fractional for now } simLabel.positionsStopLine = line_counter; @@ -377,7 +379,7 @@ void CastepCastepReader::parse_data() { break; } if (i < atoms.size()) { - atoms[i].force = Vec3d(fx, fy, fz); + atoms[i].force = tadah::core::Vec3d(fx, fy, fz); } } simLabel.forcesStopLine = line_counter; @@ -507,3 +509,5 @@ void CastepCastepReader::print_summary() const { std::string CastepCastepReader::get_summary() const { return stdb.summary(); } +} // namespace mlip +} // namespace tadah diff --git a/src/castep_cell_reader.cpp b/src/castep_cell_reader.cpp index 4451c5fb13b893f4ee7eb365bf8586c7bd33d3b1..3a9c836709209c0e2b5bb931f78a4c820b51cf1b 100644 --- a/src/castep_cell_reader.cpp +++ b/src/castep_cell_reader.cpp @@ -7,6 +7,8 @@ #include <sstream> #include <stdexcept> #include <vector> +namespace tadah { +namespace mlip { //-------------------------------------------------------------------- // Helper to split a line by whitespace @@ -156,7 +158,7 @@ void CastepCellReader::parseCellContents(const std::string &contents) { } // parse species - Element e = parseSpecies(toks[0]); + tadah::core::Element e = parseSpecies(toks[0]); // fractional coords double fx = std::stod(toks[1]); @@ -168,7 +170,7 @@ void CastepCellReader::parseCellContents(const std::string &contents) { Atom a; // Copy base element data into 'a' - static_cast<Element&>(a) = e; + static_cast<tadah::core::Element&>(a) = e; // Now set the position a.position = {cx, cy, cz}; @@ -182,14 +184,14 @@ void CastepCellReader::parseCellContents(const std::string &contents) { continue; } - Element e = parseSpecies(toks[0]); + tadah::core::Element e = parseSpecies(toks[0]); double x = std::stod(toks[1]); double y = std::stod(toks[2]); double z = std::stod(toks[3]); Atom a; - static_cast<Element&>(a) = e; + static_cast<tadah::core::Element&>(a) = e; a.position = {x, y, z}; m_structure.atoms.push_back(a); @@ -292,6 +294,8 @@ void CastepCellReader::fracToAbs(double fx, double fy, double fz, //-------------------------------------------------------------------- // parseSpecies //-------------------------------------------------------------------- -Element CastepCellReader::parseSpecies(const std::string &sym) { - return PeriodicTable().find_by_symbol(sym); +tadah::core::Element CastepCellReader::parseSpecies(const std::string &sym) { + return tadah::core::PeriodicTable().find_by_symbol(sym); } +} // namespace mlip +} // namespace tadah diff --git a/src/castep_cell_writer.cpp b/src/castep_cell_writer.cpp index 8d78f74d9458200da91c6e0996a2bc3fd755fc19..ae143cc8b7a01013a0668a4e69abcd9adee53c86 100644 --- a/src/castep_cell_writer.cpp +++ b/src/castep_cell_writer.cpp @@ -1,6 +1,8 @@ #include <tadah/mlip/structure.h> #include <tadah/mlip/structure_db.h> #include <tadah/mlip/structure_writers/castep_cell_writer.h> +namespace tadah { +namespace mlip { CastepCellWriter::CastepCellWriter(StructureDB& db) : StructureWriter(db) {} @@ -51,3 +53,5 @@ void CastepCellWriter::write_data(const std::string& filename, const size_t i) { file << "%ENDBLOCK POSITIONS_ABS " << std::endl; file.close(); } +} // namespace mlip +} // namespace tadah diff --git a/src/castep_geom_reader.cpp b/src/castep_geom_reader.cpp index 9cd0894ea5435131b2c0c196b74eada4f36461eb..70b48e98802837202351a4b4b59e874b0cf9b5ae 100644 --- a/src/castep_geom_reader.cpp +++ b/src/castep_geom_reader.cpp @@ -1,6 +1,8 @@ #include <tadah/core/utils.h> #include <tadah/mlip/dataset_readers/castep_geom_reader.h> #include <tadah/mlip/dataset_readers/castep_md_reader.h> +namespace tadah { +namespace mlip { CastepGeomReader::CastepGeomReader(StructureDB& db) : CastepMDReader(db) {} @@ -18,3 +20,5 @@ std::string CastepGeomReader::get_first_label(std::string &step) { std::string CastepGeomReader::get_label(std::string &step) { return "Step: " + step; } +} // namespace mlip +} // namespace tadah diff --git a/src/castep_md_reader.cpp b/src/castep_md_reader.cpp index d75b260c441f298c11273da9dc44d661e446bad2..cf846fad78a4bfe2c3c17522dc282bcbb81b59ca 100644 --- a/src/castep_md_reader.cpp +++ b/src/castep_md_reader.cpp @@ -1,5 +1,7 @@ #include <tadah/core/utils.h> #include <tadah/mlip/dataset_readers/castep_md_reader.h> +namespace tadah { +namespace mlip { CastepMDReader::CastepMDReader(StructureDB& db) : DatasetReader(db) {} @@ -162,7 +164,7 @@ void CastepMDReader::parse_data() { std::istringstream iss(line); if (!(iss >> element >> temp >> px >> py >> pz)) std::cerr << "Warning: Unexpected end of data when reading atomic positions:\n" << line << std::endl; - s.add_atom(Atom(Element(element),px*d_conv,py*d_conv,pz*d_conv,0,0,0)); + s.add_atom(Atom(tadah::core::Element(element),px*d_conv,py*d_conv,pz*d_conv,0,0,0)); R_flag=true; } else if (ends_with(line,"<-- F")) { @@ -183,7 +185,7 @@ void CastepMDReader::parse_data() { F_flag=true; if (force_idx==s.natoms()) complete_structure=true; } - else if (is_blank_line(line)) { + else if (tadah::core::is_blank_line(line)) { if (!error && complete_structure) postproc_structure(s); @@ -224,3 +226,5 @@ void CastepMDReader::print_summary() const { std::string CastepMDReader::get_summary() const { return stdb.summary(); } +} // namespace mlip +} // namespace tadah diff --git a/src/cif_reader.cpp b/src/cif_reader.cpp index 5fb292aea2fd37a19ea5bf774116bfb4e2710781..90616ac5b1d1bb6f63c0790e3b1e7013984143d2 100644 --- a/src/cif_reader.cpp +++ b/src/cif_reader.cpp @@ -8,6 +8,8 @@ #include <fstream> #include <sstream> #include <stdexcept> +namespace tadah { +namespace mlip { void CifReader::read(const std::string &path) { std::ifstream ifs(path); @@ -53,7 +55,7 @@ void CifReader::parseCifContents(const std::string &fileContents) { for (const auto &site : sites) { auto p = struc.cell.orthogonalize(site.fract); auto label = site.element.name(); - Element e = PeriodicTable().find_by_symbol(label); + tadah::core::Element e = tadah::core::PeriodicTable().find_by_symbol(label); Atom a(e, p.x, p.y, p.z, 0, 0, 0); m_structure.atoms.push_back(a); } @@ -64,3 +66,5 @@ void CifReader::parseCifContents(const std::string &fileContents) { } } } +} // namespace mlip +} // namespace tadah diff --git a/src/cod_data_provider.cpp b/src/cod_data_provider.cpp index e5179a90b14d9a9c92b746ce5847e898ff35e633..1440b5bc0994805fedfd4bf4cdd1baef0a3a4d55 100644 --- a/src/cod_data_provider.cpp +++ b/src/cod_data_provider.cpp @@ -2,6 +2,8 @@ #include <curl/curl.h> #include <stdexcept> #include <sstream> +namespace tadah { +namespace mlip { size_t CODDataProvider::writeDataCallback(void* ptr, size_t size, size_t nmemb, void* userData) { @@ -72,3 +74,5 @@ RawResponse CODDataProvider::fetchFromURL(const std::string &url) return rr; } +} // namespace mlip +} // namespace tadah diff --git a/src/cod_reader.cpp b/src/cod_reader.cpp index 076bc6cfba3dc6edfb2b9f7735388c09bab29b71..02d3857a44916bab1ac5706daa1f895255a88ff4 100644 --- a/src/cod_reader.cpp +++ b/src/cod_reader.cpp @@ -1,6 +1,8 @@ #include <tadah/mlip/structure_readers/cod_reader.h> #include <stdexcept> #include <algorithm> +namespace tadah { +namespace mlip { CODReader::CODReader() : m_dataProvider(std::make_unique<CODDataProvider>()) { @@ -71,3 +73,5 @@ void CODReader::read(const std::string &path) { Structure CODReader::getStructure() const { return m_structure; } +} // namespace mlip +} // namespace tadah diff --git a/src/dataset_reader.cpp b/src/dataset_reader.cpp index 048bbd6b1481a5f76ec8306541b701b6dd259a68..12fdf3da5c6b7d7a940761d94ca130405025f9a6 100644 --- a/src/dataset_reader.cpp +++ b/src/dataset_reader.cpp @@ -1,4 +1,8 @@ #include <tadah/mlip/dataset_readers/dataset_reader.h> +namespace tadah { +namespace mlip { std::string DatasetReader::get_first_label(std::string &) { return std::string(); } std::string DatasetReader::get_label(std::string &) { return std::string(); } +} // namespace mlip +} // namespace tadah diff --git a/src/dataset_reader_selector.cpp b/src/dataset_reader_selector.cpp index ef5d8b1cd6ce3d692796a424c5cb36f4b8a1353c..f1a7844d81fc2a37586e7f35dffc7ffe88df2725 100644 --- a/src/dataset_reader_selector.cpp +++ b/src/dataset_reader_selector.cpp @@ -7,6 +7,8 @@ #include <fstream> #include <iostream> +namespace tadah { +namespace mlip { // Factory method implementation std::unique_ptr<DatasetReader> DatasetReaderSelector::get_reader(const std::string& filepath, StructureDB& db) { @@ -59,3 +61,5 @@ std::string DatasetReaderSelector::determine_file_type_by_content(const std::str return "Unknown file type"; } +} // namespace mlip +} // namespace tadah diff --git a/src/dm_bf_base.cpp b/src/dm_bf_base.cpp index 946f455176b336eb33ee5e35f45d76ef6177a422..11a65873063fbd144309dcf3cb8e75d5e0e92482 100644 --- a/src/dm_bf_base.cpp +++ b/src/dm_bf_base.cpp @@ -1,9 +1,13 @@ #include "tadah/mlip/design_matrix/functions/dm_function_base.h" #include "tadah/models/functions/basis_functions/bf_base.h" #include <tadah/mlip/design_matrix/functions/basis_functions/dm_bf_base.h> +namespace tadah { +namespace mlip { DM_BF_Base::DM_BF_Base() {} -DM_BF_Base::DM_BF_Base(const Config &c): +DM_BF_Base::DM_BF_Base(const tadah::core::Config &c): Function_Base(c), BF_Base(c), DM_Function_Base(c) {} DM_BF_Base::~DM_BF_Base() {} +} // namespace mlip +} // namespace tadah diff --git a/src/dm_bf_linear.cpp b/src/dm_bf_linear.cpp index a19ad70a303c4d627a22ec90be66fb5c001c778f..5fd5f139bdbd12b79b608ab3c06bd75fb981f1db 100644 --- a/src/dm_bf_linear.cpp +++ b/src/dm_bf_linear.cpp @@ -1,31 +1,33 @@ #include <tadah/mlip/design_matrix/functions/basis_functions/dm_bf_linear.h> +namespace tadah { +namespace mlip { //CONFIG::Registry<DM_Function_Base>::Register<DM_BF_Linear> DM_BF_Linear_1( "BF_Linear" ); -//CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_BF_Linear> DM_BF_Linear_2( "BF_Linear" ); +//CONFIG::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_BF_Linear> DM_BF_Linear_2( "BF_Linear" ); DM_BF_Linear::DM_BF_Linear() {} -DM_BF_Linear::DM_BF_Linear(const Config &c): +DM_BF_Linear::DM_BF_Linear(const tadah::core::Config &c): Function_Base(c), DM_BF_Base(c), BF_Linear(c) {} -size_t DM_BF_Linear::get_phi_cols(const Config &config) +size_t DM_BF_Linear::get_phi_cols(const tadah::core::Config &config) { size_t cols = config.get<size_t>("DSIZE"); return cols; } -void DM_BF_Linear::calc_phi_energy_row(phi_type &Phi, size_t &row, +void DM_BF_Linear::calc_phi_energy_row(tadah::core::phi_type &Phi, size_t &row, const Structure &, const StDescriptors &st_d) { for (size_t i=0; i<st_d.naed(); ++i) { - const aed_type &aed = st_d.get_aed(i); + const tadah::core::aed_type &aed = st_d.get_aed(i); for (size_t j=0; j<aed.size(); ++j) { Phi(row,j)+=aed[j]; } } row++; } -void DM_BF_Linear::calc_phi_force_rows(phi_type &Phi, size_t &row, +void DM_BF_Linear::calc_phi_force_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) { @@ -33,8 +35,8 @@ void DM_BF_Linear::calc_phi_force_rows(phi_type &Phi, size_t &row, for (size_t jj=0; jj<st_d.fd[a].size(); ++jj) { const size_t j=st.near_neigh_idx[a][jj]; const size_t aa = st.get_nn_iindex(a,j,jj); - const fd_type &fij = st_d.fd[a][jj]; - const fd_type &fji = st_d.fd[j][aa]; + const tadah::core::fd_type &fij = st_d.fd[a][jj]; + const tadah::core::fd_type &fji = st_d.fd[j][aa]; for (size_t k=0; k<3; ++k) { for (size_t d=0; d<fij.rows(); ++d) { Phi(row+k,d) -= (fij(d,k)-fji(d,k)); @@ -44,18 +46,18 @@ void DM_BF_Linear::calc_phi_force_rows(phi_type &Phi, size_t &row, row+=3; } } -void DM_BF_Linear::calc_phi_stress_rows(phi_type &Phi, size_t &row, +void DM_BF_Linear::calc_phi_stress_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) { double V_inv = 1/st.get_volume(); for (size_t i=0; i<st.natoms(); ++i) { - const Vec3d &ri = st(i).position; + const tadah::core::Vec3d &ri = st(i).position; for (size_t jj=0; jj<st_d.fd[i].size(); ++jj) { const size_t j=st.near_neigh_idx[i][jj]; const size_t ii = st.get_nn_iindex(i,j,jj); - const fd_type &fdij = st_d.fd[i][jj]; - const fd_type &fdji = st_d.fd[j][ii]; - const Vec3d &rj = st.nn_pos(i,jj); + const tadah::core::fd_type &fdij = st_d.fd[i][jj]; + const tadah::core::fd_type &fdji = st_d.fd[j][ii]; + const tadah::core::Vec3d &rj = st.nn_pos(i,jj); size_t mn=0; for (size_t x=0; x<3; ++x) { for (size_t y=x; y<3; ++y) { @@ -69,3 +71,5 @@ void DM_BF_Linear::calc_phi_stress_rows(phi_type &Phi, size_t &row, } row += 6; } +} // namespace mlip +} // namespace tadah diff --git a/src/dm_bf_polynomial2.cpp b/src/dm_bf_polynomial2.cpp index f63f0ce5f513e0a0cbfc70b348c0e953cff3cc01..0dfc14a7d0736e4b7e3e2f02b5de24f7e9601248 100644 --- a/src/dm_bf_polynomial2.cpp +++ b/src/dm_bf_polynomial2.cpp @@ -1,28 +1,30 @@ #include "tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h" #include "tadah/models/functions/function_base.h" #include <tadah/mlip/design_matrix/functions/basis_functions/dm_bf_polynomial2.h> +namespace tadah { +namespace mlip { //CONFIG::Registry<DM_Function_Base>::Register<DM_BF_Polynomial2> DM_BF_Polynomial2_1( "BF_Polynomial2" ); -//CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_BF_Polynomial2> DM_BF_Polynomial2_2( "BF_Polynomial2" ); +//CONFIG::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_BF_Polynomial2> DM_BF_Polynomial2_2( "BF_Polynomial2" ); DM_BF_Polynomial2::DM_BF_Polynomial2() {} -DM_BF_Polynomial2::DM_BF_Polynomial2(const Config &c): +DM_BF_Polynomial2::DM_BF_Polynomial2(const tadah::core::Config &c): Function_Base(c), DM_BF_Base(c), BF_Polynomial2(c) {} -size_t DM_BF_Polynomial2::get_phi_cols(const Config &config) +size_t DM_BF_Polynomial2::get_phi_cols(const tadah::core::Config &config) { size_t cols = config.get<size_t>("DSIZE"); return (cols*cols+cols)/2; } -void DM_BF_Polynomial2::calc_phi_energy_row(phi_type &Phi, +void DM_BF_Polynomial2::calc_phi_energy_row(tadah::core::phi_type &Phi, size_t &row, const Structure &, const StDescriptors &st_d) { for (size_t a=0; a<st_d.naed();++a) { - const aed_type& aed = st_d.get_aed(a); + const tadah::core::aed_type& aed = st_d.get_aed(a); size_t b=0; for (size_t i=0; i<st_d.dim(); ++i) { for (size_t ii=i; ii<st_d.dim(); ++ii) { @@ -32,19 +34,19 @@ void DM_BF_Polynomial2::calc_phi_energy_row(phi_type &Phi, } row++; } -void DM_BF_Polynomial2::calc_phi_force_rows(phi_type &Phi, +void DM_BF_Polynomial2::calc_phi_force_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) { for (size_t a=0; a<st.natoms(); ++a) { - const aed_type& aedi = st_d.get_aed(a); + const tadah::core::aed_type& aedi = st_d.get_aed(a); for (size_t jj=0; jj<st_d.fd[a].size(); ++jj) { const size_t j=st.near_neigh_idx[a][jj]; size_t aa = st.get_nn_iindex(a,j,jj); - const fd_type &fdji = st_d.fd[j][aa]; - const fd_type &fdij = st_d.fd[a][jj]; - const aed_type& aedj = st_d.get_aed(j); + const tadah::core::fd_type &fdji = st_d.fd[j][aa]; + const tadah::core::fd_type &fdij = st_d.fd[a][jj]; + const tadah::core::aed_type& aedj = st_d.get_aed(j); for (size_t k=0; k<3; ++k) { size_t b=0; @@ -61,22 +63,22 @@ void DM_BF_Polynomial2::calc_phi_force_rows(phi_type &Phi, row+=3; } } -void DM_BF_Polynomial2::calc_phi_stress_rows(phi_type &Phi, +void DM_BF_Polynomial2::calc_phi_stress_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) { double V_inv = 1/st.get_volume(); for (size_t a=0; a<st.natoms(); ++a) { - const Vec3d &ri = st(a).position; - const aed_type& aedi = st_d.get_aed(a); + const tadah::core::Vec3d &ri = st(a).position; + const tadah::core::aed_type& aedi = st_d.get_aed(a); for (size_t jj=0; jj<st_d.fd[a].size(); ++jj) { const size_t j=st.near_neigh_idx[a][jj]; size_t aa = st.get_nn_iindex(a,j,jj); - const fd_type &fdji = st_d.fd[j][aa]; - const fd_type &fdij = st_d.fd[a][jj]; - const Vec3d &rj = st.nn_pos(a,jj); - const aed_type& aedj = st_d.get_aed(j); + const tadah::core::fd_type &fdji = st_d.fd[j][aa]; + const tadah::core::fd_type &fdij = st_d.fd[a][jj]; + const tadah::core::Vec3d &rj = st.nn_pos(a,jj); + const tadah::core::aed_type& aedj = st_d.get_aed(j); size_t mn=0; for (size_t x=0; x<3; ++x) { for (size_t y=x; y<3; ++y) { @@ -96,3 +98,5 @@ void DM_BF_Polynomial2::calc_phi_stress_rows(phi_type &Phi, } row += 6; } +} // namespace mlip +} // namespace tadah diff --git a/src/dm_f_all.cpp b/src/dm_f_all.cpp index 64a583a2ead0ea791730a3e0b5d00f8d0e78e84c..6faeda68dff06e3dfcf7e20e8005f1ceadbe35b4 100644 --- a/src/dm_f_all.cpp +++ b/src/dm_f_all.cpp @@ -1,22 +1,27 @@ #include <tadah/mlip/design_matrix/functions/dm_f_all.h> +namespace tadah { +namespace mlip { -template<> CONFIG::Registry<DM_Function_Base>::Map CONFIG::Registry<DM_Function_Base>::registry{}; -template<> CONFIG::Registry<DM_Function_Base,Config&>::Map CONFIG::Registry<DM_Function_Base,Config&>::registry{}; +template<> tadah::core::Registry<DM_Function_Base>::Map tadah::core::Registry<DM_Function_Base>::registry{}; +template<> tadah::core::Registry<DM_Function_Base,tadah::core::Config&>::Map tadah::core::Registry<DM_Function_Base,tadah::core::Config&>::registry{}; -CONFIG::Registry<DM_Function_Base>::Register<DM_BF_Linear> DM_BF_Linear_1( "BF_Linear" ); -CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_BF_Linear> DM_BF_Linear_2( "BF_Linear" ); -CONFIG::Registry<DM_Function_Base>::Register<DM_BF_Polynomial2> DM_BF_Polynomial2_1( "BF_Polynomial2" ); -CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_BF_Polynomial2> DM_BF_Polynomial2_2( "BF_Polynomial2" ); -CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_Linear> DM_Kern_Linear_1( "Kern_Linear" ); -CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_Linear> DM_Kern_Linear_2( "Kern_Linear" ); -CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_LQ> DM_Kern_LQ_1( "Kern_LQ" ); -CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_LQ> DM_Kern_LQ_2( "Kern_LQ" ); -CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_Polynomial> DM_Kern_Polynomial_1( "Kern_Polynomial" ); -CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_Polynomial> DM_Kern_Polynomial_2( "Kern_Polynomial" ); -CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_Quadratic> DM_Kern_Quadratic_1( "Kern_Quadratic" ); -CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_Quadratic> DM_Kern_Quadratic_2( "Kern_Quadratic" ); -CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_RBF> DM_Kern_RBF_1( "Kern_RBF" ); -CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_RBF> DM_Kern_RBF_2( "Kern_RBF" ); -CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_Sigmoid> DM_Kern_Sigmoid_1( "Kern_Sigmoid" ); -CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_Sigmoid> DM_Kern_Sigmoid_2( "Kern_Sigmoid" ); +tadah::core::Registry<DM_Function_Base>::Register<DM_BF_Linear> DM_BF_Linear_1( "BF_Linear" ); +tadah::core::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_BF_Linear> DM_BF_Linear_2( "BF_Linear" ); +tadah::core::Registry<DM_Function_Base>::Register<DM_BF_Polynomial2> DM_BF_Polynomial2_1( "BF_Polynomial2" ); +tadah::core::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_BF_Polynomial2> DM_BF_Polynomial2_2( "BF_Polynomial2" ); +tadah::core::Registry<DM_Function_Base>::Register<DM_Kern_Linear> DM_Kern_Linear_1( "Kern_Linear" ); +tadah::core::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_Linear> DM_Kern_Linear_2( "Kern_Linear" ); +tadah::core::Registry<DM_Function_Base>::Register<DM_Kern_LQ> DM_Kern_LQ_1( "Kern_LQ" ); +tadah::core::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_LQ> DM_Kern_LQ_2( "Kern_LQ" ); +tadah::core::Registry<DM_Function_Base>::Register<DM_Kern_Polynomial> DM_Kern_Polynomial_1( "Kern_Polynomial" ); +tadah::core::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_Polynomial> DM_Kern_Polynomial_2( "Kern_Polynomial" ); +tadah::core::Registry<DM_Function_Base>::Register<DM_Kern_Quadratic> DM_Kern_Quadratic_1( "Kern_Quadratic" ); +tadah::core::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_Quadratic> DM_Kern_Quadratic_2( "Kern_Quadratic" ); +tadah::core::Registry<DM_Function_Base>::Register<DM_Kern_RBF> DM_Kern_RBF_1( "Kern_RBF" ); +tadah::core::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_RBF> DM_Kern_RBF_2( "Kern_RBF" ); +tadah::core::Registry<DM_Function_Base>::Register<DM_Kern_Sigmoid> DM_Kern_Sigmoid_1( "Kern_Sigmoid" ); +tadah::core::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_Sigmoid> DM_Kern_Sigmoid_2( "Kern_Sigmoid" ); + +} // namespace mlip +} // namespace tadah diff --git a/src/dm_function_base.cpp b/src/dm_function_base.cpp index 945c4344841ae7c84c896e0cd66ac226cf2a1cdb..72490e28bd797435beca005852a4db5e5691176a 100644 --- a/src/dm_function_base.cpp +++ b/src/dm_function_base.cpp @@ -1,5 +1,9 @@ #include "tadah/models/functions/function_base.h" #include <tadah/mlip/design_matrix/functions/dm_function_base.h> +namespace tadah { +namespace mlip { DM_Function_Base::DM_Function_Base() {} -DM_Function_Base::DM_Function_Base(const Config &c): Function_Base(c) {} +DM_Function_Base::DM_Function_Base(const tadah::core::Config &c): Function_Base(c) {} DM_Function_Base::~DM_Function_Base() {} +} // namespace mlip +} // namespace tadah diff --git a/src/dm_kern_base.cpp b/src/dm_kern_base.cpp index 7a07443045318934e115a4ddf8b92f68ae64b27d..0c32977c640917ba818b7817df26924f8622e1cd 100644 --- a/src/dm_kern_base.cpp +++ b/src/dm_kern_base.cpp @@ -2,18 +2,20 @@ #include "tadah/mlip/design_matrix/functions/dm_function_base.h" #include "tadah/models/functions/kernels/kern_base.h" #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h> +namespace tadah { +namespace mlip { DM_Kern_Base::~DM_Kern_Base() {} DM_Kern_Base::DM_Kern_Base() {} -DM_Kern_Base::DM_Kern_Base(const Config &c): +DM_Kern_Base::DM_Kern_Base(const tadah::core::Config &c): Function_Base(c), Kern_Base(c), DM_Function_Base(c) {} -size_t DM_Kern_Base::get_phi_cols(const Config &) +size_t DM_Kern_Base::get_phi_cols(const tadah::core::Config &) { return basis.cols(); } -void DM_Kern_Base::calc_phi_energy_row(phi_type &Phi, size_t &row, +void DM_Kern_Base::calc_phi_energy_row(tadah::core::phi_type &Phi, size_t &row, const Structure &, const StDescriptors &st_d) { for (size_t a=0; a<st_d.naed();++a) { @@ -23,16 +25,16 @@ void DM_Kern_Base::calc_phi_energy_row(phi_type &Phi, size_t &row, } row++; } -void DM_Kern_Base::calc_phi_force_rows(phi_type &Phi, size_t &row, +void DM_Kern_Base::calc_phi_force_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) { for (size_t i=0; i<st.natoms(); ++i) { - const aed_type& aedi = st_d.get_aed(i); + const tadah::core::aed_type& aedi = st_d.get_aed(i); for (size_t jj=0; jj<st_d.fd[i].size(); ++jj) { size_t j=st.near_neigh_idx[i][jj]; size_t ii = st.get_nn_iindex(i,j,jj); - const fd_type &fdji = st_d.fd[j][ii]; - const fd_type &fdij = st_d.fd[i][jj]; - const aed_type& aedj = st_d.get_aed(j); + const tadah::core::fd_type &fdji = st_d.fd[j][ii]; + const tadah::core::fd_type &fdij = st_d.fd[i][jj]; + const tadah::core::aed_type& aedj = st_d.get_aed(j); for (size_t b=0; b<basis.cols(); ++b) { for (size_t k=0; k<3; ++k) { Phi(row+k,b) -= ((*this).prime(basis.col(b), aedi,fdij(k)) - @@ -43,20 +45,20 @@ void DM_Kern_Base::calc_phi_force_rows(phi_type &Phi, size_t &row, row+=3; } } -void DM_Kern_Base::calc_phi_stress_rows(phi_type &Phi, size_t &row, +void DM_Kern_Base::calc_phi_stress_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) { double V_inv = 1/st.get_volume(); for (size_t i=0; i<st.natoms(); ++i) { - const Vec3d &ri = st(i).position; - const aed_type& aedi = st_d.get_aed(i); + const tadah::core::Vec3d &ri = st(i).position; + const tadah::core::aed_type& aedi = st_d.get_aed(i); for (size_t jj=0; jj<st_d.fd[i].size(); ++jj) { size_t j=st.near_neigh_idx[i][jj]; size_t ii = st.get_nn_iindex(i,j,jj); - const fd_type &fdji = st_d.fd[j][ii]; - const fd_type &fdij = st_d.fd[i][jj]; - const aed_type& aedj = st_d.get_aed(j); - const Vec3d &rj = st.nn_pos(i,jj); + const tadah::core::fd_type &fdji = st_d.fd[j][ii]; + const tadah::core::fd_type &fdij = st_d.fd[i][jj]; + const tadah::core::aed_type& aedj = st_d.get_aed(j); + const tadah::core::Vec3d &rj = st.nn_pos(i,jj); size_t mn=0; for (size_t x=0; x<3; ++x) { for (size_t y=x; y<3; ++y) { @@ -72,3 +74,5 @@ void DM_Kern_Base::calc_phi_stress_rows(phi_type &Phi, size_t &row, } row+=6; } +} // namespace mlip +} // namespace tadah diff --git a/src/dm_kern_linear.cpp b/src/dm_kern_linear.cpp index ca36e2a3e2918e874e183022caf573113fbccbfb..339052673fe67a8c5cb5fe1ca27b86912dc71462 100644 --- a/src/dm_kern_linear.cpp +++ b/src/dm_kern_linear.cpp @@ -1,32 +1,34 @@ #include "tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h" #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_linear.h> +namespace tadah { +namespace mlip { //CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_Linear> DM_Kern_Linear_1( "Kern_Linear" ); -//CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_Linear> DM_Kern_Linear_2( "Kern_Linear" ); +//CONFIG::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_Linear> DM_Kern_Linear_2( "Kern_Linear" ); DM_Kern_Linear::DM_Kern_Linear() {} -DM_Kern_Linear::DM_Kern_Linear (const Config &c): +DM_Kern_Linear::DM_Kern_Linear (const tadah::core::Config &c): Function_Base(c), DM_Kern_Base(c), Kern_Linear(c) {} -size_t DM_Kern_Linear::get_phi_cols(const Config &config) +size_t DM_Kern_Linear::get_phi_cols(const tadah::core::Config &config) { size_t cols = config.get<size_t>("DSIZE"); return cols; } -void DM_Kern_Linear::calc_phi_energy_row(phi_type &Phi, size_t &row, +void DM_Kern_Linear::calc_phi_energy_row(tadah::core::phi_type &Phi, size_t &row, const Structure &, const StDescriptors &st_d) { for (size_t a=0; a<st_d.naed();++a) { - const aed_type &aed = st_d.get_aed(a); // TODO + const tadah::core::aed_type &aed = st_d.get_aed(a); // TODO for (size_t j=0; j<aed.size(); ++j) { Phi(row,j)+=aed[j]; } } row++; } -void DM_Kern_Linear::calc_phi_force_rows(phi_type &Phi, size_t &row, +void DM_Kern_Linear::calc_phi_force_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) { for (size_t a=0; a<st.natoms(); ++a) { @@ -34,7 +36,7 @@ void DM_Kern_Linear::calc_phi_force_rows(phi_type &Phi, size_t &row, const size_t j=st.near_neigh_idx[a][jj]; const size_t aa = st.get_nn_iindex(a,j,jj); for (size_t k=0; k<3; ++k) { - aed_type temp = (st_d.fd[a][jj](k)- + tadah::core::aed_type temp = (st_d.fd[a][jj](k)- st_d.fd[j][aa](k)); for (size_t d=0; d<temp.size(); ++d) { Phi(row+k,d) -= temp[d]; @@ -45,22 +47,22 @@ void DM_Kern_Linear::calc_phi_force_rows(phi_type &Phi, size_t &row, } } -void DM_Kern_Linear::calc_phi_stress_rows(phi_type &Phi, size_t &row, +void DM_Kern_Linear::calc_phi_stress_rows(tadah::core::phi_type &Phi, size_t &row, const Structure &st, const StDescriptors &st_d) { double V_inv = 1/st.get_volume(); for (size_t i=0; i<st.natoms(); ++i) { - const Vec3d &ri = st(i).position; + const tadah::core::Vec3d &ri = st(i).position; for (size_t jj=0; jj<st_d.fd[i].size(); ++jj) { const size_t j=st.near_neigh_idx[i][jj]; const size_t ii = st.get_nn_iindex(i,j,jj); - const fd_type &fdij = st_d.fd[i][jj]; - const fd_type &fdji = st_d.fd[j][ii]; - const Vec3d &rj = st.nn_pos(i,jj); + const tadah::core::fd_type &fdij = st_d.fd[i][jj]; + const tadah::core::fd_type &fdji = st_d.fd[j][ii]; + const tadah::core::Vec3d &rj = st.nn_pos(i,jj); size_t mn=0; for (size_t x=0; x<3; ++x) { for (size_t y=x; y<3; ++y) { - aed_type temp = V_inv*(fdij(y)-fdji(y))*0.5*(ri(x)-rj(x)); + tadah::core::aed_type temp = V_inv*(fdij(y)-fdji(y))*0.5*(ri(x)-rj(x)); for (size_t d=0; d<temp.size(); ++d) { Phi(row+mn,d) += temp[d]; } @@ -71,3 +73,5 @@ void DM_Kern_Linear::calc_phi_stress_rows(phi_type &Phi, size_t &row, } row += 6; } +} // namespace mlip +} // namespace tadah diff --git a/src/dm_kern_lq.cpp b/src/dm_kern_lq.cpp index dbef59e32ef1d37e7899c0f43994a076948f3374..d9be6865493fbab7fc4872c93700116e36d4ce43 100644 --- a/src/dm_kern_lq.cpp +++ b/src/dm_kern_lq.cpp @@ -1,14 +1,18 @@ #include "tadah/mlip/design_matrix/functions/kernels/dm_kern_base.h" #include "tadah/models/functions/function_base.h" #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_lq.h> +namespace tadah { +namespace mlip { //CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_LQ> DM_Kern_LQ_1( "Kern_LQ" ); -//CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_LQ> DM_Kern_LQ_2( "Kern_LQ" ); +//CONFIG::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_LQ> DM_Kern_LQ_2( "Kern_LQ" ); DM_Kern_LQ::DM_Kern_LQ() {} -DM_Kern_LQ::DM_Kern_LQ(const Config &c): +DM_Kern_LQ::DM_Kern_LQ(const tadah::core::Config &c): Function_Base(c), DM_Kern_Base(c), Kern_LQ(c) {} +} // namespace mlip +} // namespace tadah diff --git a/src/dm_kern_polynomial.cpp b/src/dm_kern_polynomial.cpp index e8637b1625d9647309ae46496f0f63263a464b3e..b2d1c7d7155949f098b936f774e44d683ac01363 100644 --- a/src/dm_kern_polynomial.cpp +++ b/src/dm_kern_polynomial.cpp @@ -1,12 +1,16 @@ #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_polynomial.h> +namespace tadah { +namespace mlip { //CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_Polynomial> DM_Kern_Polynomial_1( "Kern_Polynomial" ); -//CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_Polynomial> DM_Kern_Polynomial_2( "Kern_Polynomial" ); +//CONFIG::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_Polynomial> DM_Kern_Polynomial_2( "Kern_Polynomial" ); DM_Kern_Polynomial::DM_Kern_Polynomial() {} -DM_Kern_Polynomial::DM_Kern_Polynomial(const Config &c): +DM_Kern_Polynomial::DM_Kern_Polynomial(const tadah::core::Config &c): Function_Base(c), DM_Kern_Base(c), Kern_Polynomial(c) {} +} // namespace mlip +} // namespace tadah diff --git a/src/dm_kern_quadratic.cpp b/src/dm_kern_quadratic.cpp index 72ab0d47e6ca382c31204f4c2baaf54e837b09d0..b8a1efe48287368399e9304cce4900d6a1ff8dd8 100644 --- a/src/dm_kern_quadratic.cpp +++ b/src/dm_kern_quadratic.cpp @@ -1,13 +1,17 @@ #include "tadah/models/functions/function_base.h" #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_quadratic.h> +namespace tadah { +namespace mlip { //CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_Quadratic> DM_Kern_Quadratic_1( "Kern_Quadratic" ); -//CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_Quadratic> DM_Kern_Quadratic_2( "Kern_Quadratic" ); +//CONFIG::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_Quadratic> DM_Kern_Quadratic_2( "Kern_Quadratic" ); DM_Kern_Quadratic::DM_Kern_Quadratic() {} -DM_Kern_Quadratic::DM_Kern_Quadratic(const Config &c): +DM_Kern_Quadratic::DM_Kern_Quadratic(const tadah::core::Config &c): Function_Base(c), DM_Kern_Base(c), Kern_Quadratic(c) {} +} // namespace mlip +} // namespace tadah diff --git a/src/dm_kern_rbf.cpp b/src/dm_kern_rbf.cpp index 41d57bea8461d633b3241263b4ccc5905fb00bfe..4489073b2661ec53e05b6cda569816e16fcdeccd 100644 --- a/src/dm_kern_rbf.cpp +++ b/src/dm_kern_rbf.cpp @@ -1,12 +1,16 @@ #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_rbf.h> +namespace tadah { +namespace mlip { //CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_RBF> DM_Kern_RBF_1( "Kern_RBF" ); -//CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_RBF> DM_Kern_RBF_2( "Kern_RBF" ); +//CONFIG::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_RBF> DM_Kern_RBF_2( "Kern_RBF" ); DM_Kern_RBF::DM_Kern_RBF() {} -DM_Kern_RBF::DM_Kern_RBF(const Config &c): +DM_Kern_RBF::DM_Kern_RBF(const tadah::core::Config &c): Function_Base(c), DM_Kern_Base(c), Kern_RBF(c) {} +} // namespace mlip +} // namespace tadah diff --git a/src/dm_kern_sigmoid.cpp b/src/dm_kern_sigmoid.cpp index 1c3d25bfc432591378a3c4948d76ac3ea6965ecd..fb1482cd68fdb275311b69232d47d62f10e30df3 100644 --- a/src/dm_kern_sigmoid.cpp +++ b/src/dm_kern_sigmoid.cpp @@ -1,12 +1,16 @@ #include <tadah/mlip/design_matrix/functions/kernels/dm_kern_sigmoid.h> +namespace tadah { +namespace mlip { //CONFIG::Registry<DM_Function_Base>::Register<DM_Kern_Sigmoid> DM_Kern_Sigmoid_1( "Kern_Sigmoid" ); -//CONFIG::Registry<DM_Function_Base,Config&>::Register<DM_Kern_Sigmoid> DM_Kern_Sigmoid_2( "Kern_Sigmoid" ); +//CONFIG::Registry<DM_Function_Base,tadah::core::Config&>::Register<DM_Kern_Sigmoid> DM_Kern_Sigmoid_2( "Kern_Sigmoid" ); DM_Kern_Sigmoid::DM_Kern_Sigmoid() {} -DM_Kern_Sigmoid::DM_Kern_Sigmoid(const Config &c): +DM_Kern_Sigmoid::DM_Kern_Sigmoid(const tadah::core::Config &c): Function_Base(c), DM_Kern_Base(c), Kern_Sigmoid(c) {} +} // namespace mlip +} // namespace tadah diff --git a/src/environment_key_storage.cpp b/src/environment_key_storage.cpp index f28444d169e8e6331edde8207a54deea0656780d..7e6320e4e364169be580c18451df1dcd5eb4a50d 100644 --- a/src/environment_key_storage.cpp +++ b/src/environment_key_storage.cpp @@ -6,6 +6,8 @@ #include <tadah/mlip/key_storage/environment_key_storage.h> #include <cstdlib> // getenv, setenv #include <iostream> +namespace tadah { +namespace mlip { std::string EnvironmentKeyStorage::retrieveKey(const std::string& keyName) { @@ -28,3 +30,5 @@ bool EnvironmentKeyStorage::storeKey(const std::string& keyName, const std::stri return false; } +} // namespace mlip +} // namespace tadah diff --git a/src/fallback_key_storage.cpp b/src/fallback_key_storage.cpp index 0a5a5c3ffc83e6a2972be2fcd580da63cb4b8996..8567ef6dd990e3c765f9fa707e0a92cf96146fb1 100644 --- a/src/fallback_key_storage.cpp +++ b/src/fallback_key_storage.cpp @@ -4,6 +4,8 @@ */ #include <tadah/mlip/key_storage/fallback_key_storage.h> +namespace tadah { +namespace mlip { FallbackKeyStorage::FallbackKeyStorage(std::vector<std::unique_ptr<IKeyStorage>> storages) : m_storages(std::move(storages)) @@ -31,3 +33,5 @@ bool FallbackKeyStorage::storeKey(const std::string& keyName, const std::string& return m_storages.back()->storeKey(keyName, keyValue); } +} // namespace mlip +} // namespace tadah diff --git a/src/key_manager.cpp b/src/key_manager.cpp index 4fb5a0600c5fe6da928c02f83fa28edb246b6e5e..913119934d3980291d41be7ab6c38c50f0efae8b 100644 --- a/src/key_manager.cpp +++ b/src/key_manager.cpp @@ -9,6 +9,8 @@ #include <iostream> #include <string> #include <cstdlib> // setenv on Unix-likes +namespace tadah { +namespace mlip { std::string KeyManager::getServiceKey(ServiceType service, bool allowPrompt) { @@ -160,3 +162,5 @@ void KeyManager::showShellExportInstructions(const std::string &keyName, const s << "Then re-run this program, and it will see that environment variable.\n\n"; } +} // namespace mlip +} // namespace tadah diff --git a/src/key_storage_factory.cpp b/src/key_storage_factory.cpp index a250c87161c9f0d563d87f6afe2b4069a9d904d7..67826cc53c22c5d94d63ac1a4eb0a7fc0d02b70b 100644 --- a/src/key_storage_factory.cpp +++ b/src/key_storage_factory.cpp @@ -8,6 +8,8 @@ #include <tadah/mlip/key_storage/fallback_key_storage.h> #include <tadah/mlip/key_storage/key_storage_factory.h> #include <vector> +namespace tadah { +namespace mlip { std::unique_ptr<IKeyStorage> KeyStorageFactory::createEnvThenFile() { @@ -28,3 +30,5 @@ std::unique_ptr<IKeyStorage> KeyStorageFactory::createEnvironmentOnly() return std::make_unique<EnvironmentKeyStorage>(); } +} // namespace mlip +} // namespace tadah diff --git a/src/lammps_structure_writer.cpp b/src/lammps_structure_writer.cpp index f0b1ba63dd4baa466df45d960e9f2d7a11b37c36..bbdc017bf90dd3c0faba794dbcd37fca80697407 100644 --- a/src/lammps_structure_writer.cpp +++ b/src/lammps_structure_writer.cpp @@ -1,6 +1,8 @@ #include <tadah/mlip/structure.h> #include <tadah/mlip/structure_db.h> #include <tadah/mlip/structure_writers/lammps_structure_writer.h> +namespace tadah { +namespace mlip { LammpsStructureWriter::LammpsStructureWriter(StructureDB& db) : StructureWriter(db) {} @@ -61,7 +63,7 @@ void LammpsStructureWriter::write_data(const std::string& filename, const size_t file << "Masses" << std::endl; file << std::endl; for (const auto &t: type) { - file << t.second << " " << PeriodicTable::get_mass(t.first) << " # " << t.first << std::endl; + file << t.second << " " << tadah::core::PeriodicTable::get_mass(t.first) << " # " << t.first << std::endl; } file << std::endl; @@ -86,3 +88,5 @@ void LammpsStructureWriter::write_data(const std::string& filename, const size_t file.close(); } +} // namespace mlip +} // namespace tadah diff --git a/src/m_all.cpp b/src/m_all.cpp index c8387e66f3a0677daf42b1c2a97e5b478ca85bf6..6ddcebe56684173c0d1bd20da72d2ed2d9fb917a 100644 --- a/src/m_all.cpp +++ b/src/m_all.cpp @@ -1,24 +1,28 @@ #include <tadah/mlip/models/m_all.h> #include <tadah/models/memory/IModelsWorkspaceManager.h> #include <tadah/mlip/memory/IMLIPWorkspaceManager.h> +namespace tadah { +namespace mlip { template<> -CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&>::Map -CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&>::registry{}; +CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&>::Map +CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&>::registry{}; -CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&>::Register<M_KRR<>> M_KRR_1("M_KRR"); -CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&>::Register<M_BLR<>> M_BLR_1("M_BLR"); +CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&>::Register<M_KRR<>> M_KRR_1("M_KRR"); +CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&>::Register<M_BLR<>> M_BLR_1("M_BLR"); /*template<>*/ -/*CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&, tadah::models::memory::IModelsWorkspaceManager&>::Map*/ -/*CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&, tadah::models::memory::IModelsWorkspaceManager&>::registry{};*/ +/*CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&, tadah::models::memory::IModelsWorkspaceManager&>::Map*/ +/*CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&, tadah::models::memory::IModelsWorkspaceManager&>::registry{};*/ /**/ -/*CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&, tadah::models::memory::IModelsWorkspaceManager&>::Register<M_BLR<>> M_BLR_2("M_BLR");*/ -/*CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&, tadah::models::memory::IModelsWorkspaceManager&>::Register<M_KRR<>> M_KRR_2("M_KRR");*/ +/*CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&, tadah::models::memory::IModelsWorkspaceManager&>::Register<M_BLR<>> M_BLR_2("M_BLR");*/ +/*CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&, tadah::models::memory::IModelsWorkspaceManager&>::Register<M_KRR<>> M_KRR_2("M_KRR");*/ template<> -CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&, tadah::mlip::memory::IMLIPWorkspaceManager&>::Map -CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&, tadah::mlip::memory::IMLIPWorkspaceManager&>::registry{}; +CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&, tadah::mlip::memory::IMLIPWorkspaceManager&>::Map +CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&, tadah::mlip::memory::IMLIPWorkspaceManager&>::registry{}; -CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&, tadah::mlip::memory::IMLIPWorkspaceManager&>::Register<M_BLR<>> M_BLR_3("M_BLR"); -CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, Config&, tadah::mlip::memory::IMLIPWorkspaceManager&>::Register<M_KRR<>> M_KRR_3("M_KRR"); +CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&, tadah::mlip::memory::IMLIPWorkspaceManager&>::Register<M_BLR<>> M_BLR_3("M_BLR"); +CONFIG::Registry<M_Tadah_Base, DM_Function_Base&, tadah::core::Config&, tadah::mlip::memory::IMLIPWorkspaceManager&>::Register<M_KRR<>> M_KRR_3("M_KRR"); +} // namespace mlip +} // namespace tadah diff --git a/src/m_blr.cpp b/src/m_blr.cpp index bdb85a73602412308a15ce55a4977f548d0ba742..3fb2376aa4dd46e657cd64ed55988d1e9743818a 100644 --- a/src/m_blr.cpp +++ b/src/m_blr.cpp @@ -1,2 +1,6 @@ #include <tadah/mlip/models/m_blr.h> #include <tadah/core/registry.h> +namespace tadah { +namespace mlip { +} // namespace mlip +} // namespace tadah diff --git a/src/m_krr.cpp b/src/m_krr.cpp index d3cff341128e424be5e57afe5723901340524082..fe0b1e599bb3f58b0bd6752c39e60010bb74e083 100644 --- a/src/m_krr.cpp +++ b/src/m_krr.cpp @@ -1,2 +1,6 @@ #include <tadah/mlip/models/m_krr.h> #include <tadah/core/registry.h> +namespace tadah { +namespace mlip { +} // namespace mlip +} // namespace tadah diff --git a/src/m_tadah_base.cpp b/src/m_tadah_base.cpp index bdba3571b40fd87a99c37fa4e1bab55fdd69952f..46982f3d8741da8218d75f5dded091d86ebd004e 100644 --- a/src/m_tadah_base.cpp +++ b/src/m_tadah_base.cpp @@ -1,24 +1,26 @@ #include <tadah/mlip/models/m_tadah_base.h> +namespace tadah { +namespace mlip { void M_Tadah_Base:: -fpredict(const size_t a, force_type &v, +fpredict(const size_t a, tadah::core::force_type &v, const StDescriptors &std, const Structure &st) { for (size_t jj=0; jj<st.nn_size(a); ++jj) { size_t j=st.near_neigh_idx[a][jj]; const size_t aa = st.get_nn_iindex(a,j,jj); - const fd_type &fdji = std.fd[j][aa]; - const fd_type &fdij = std.fd[a][jj]; - const aed_type &aedi = std.get_aed(a); - const aed_type &aedj = std.get_aed(j); + const tadah::core::fd_type &fdji = std.fd[j][aa]; + const tadah::core::fd_type &fdij = std.fd[a][jj]; + const tadah::core::aed_type &aedi = std.get_aed(a); + const tadah::core::aed_type &aedj = std.get_aed(j); v += fpredict(fdij,aedi); v -= fpredict(fdji,aedj); } } -force_type M_Tadah_Base:: +tadah::core::force_type M_Tadah_Base:: fpredict(const size_t a, const StDescriptors &std, const Structure &st) { - force_type v; + tadah::core::force_type v; fpredict(a,v,std,st); return v; } @@ -33,7 +35,7 @@ epredict(const StDescriptors &std) } Structure M_Tadah_Base:: -predict(const Config &c, StDescriptors &std, const Structure &st) +predict(const tadah::core::Config &c, StDescriptors &std, const Structure &st) { if(c.get<bool>("NORM") && !std.normalised && c("MODEL")[1].find("Linear") == std::string::npos) @@ -59,7 +61,7 @@ predict(const Config &c, StDescriptors &std, const Structure &st) } StructureDB M_Tadah_Base:: -predict(const Config &c, StDescriptorsDB &st_desc_db, const StructureDB &stdb) +predict(const tadah::core::Config &c, StDescriptorsDB &st_desc_db, const StructureDB &stdb) { StructureDB stdb_; stdb_.structures.resize(stdb.size()); @@ -73,7 +75,7 @@ predict(const Config &c, StDescriptorsDB &st_desc_db, const StructureDB &stdb) } StructureDB M_Tadah_Base:: -predict(Config &c, const StructureDB &stdb, DC_Base &dc) +predict(tadah::core::Config &c, const StructureDB &stdb, DC_Base &dc) { StructureDB stdb_; stdb_.structures.resize(stdb.size()); @@ -87,40 +89,40 @@ predict(Config &c, const StructureDB &stdb, DC_Base &dc) return stdb_; } -stress_type M_Tadah_Base:: +tadah::core::stress_type M_Tadah_Base:: spredict(const StDescriptors &std, const Structure &st) { - stress_type s; + tadah::core::stress_type s; s.set_zero(); for (size_t a=0; a<st.natoms(); ++a) { s += spredict(a,std,st); } return s; } -stress_type M_Tadah_Base:: +tadah::core::stress_type M_Tadah_Base:: spredict(const size_t a, const StDescriptors &std, const Structure &st) { - stress_type s; + tadah::core::stress_type s; s.set_zero(); spredict(a,s,std,st); return s; } void M_Tadah_Base:: -spredict(const size_t a, stress_type &s, +spredict(const size_t a, tadah::core::stress_type &s, const StDescriptors &std, const Structure &st) { double V_inv = 1/st.get_volume(); - const Vec3d &ri = st.atoms[a].position; - const aed_type &aedi = std.get_aed(a); + const tadah::core::Vec3d &ri = st.atoms[a].position; + const tadah::core::aed_type &aedi = std.get_aed(a); for (size_t jj=0; jj<st.nn_size(a); ++jj) { size_t j=st.near_neigh_idx[a][jj]; const size_t aa = st.get_nn_iindex(a,j,jj); - const Vec3d &rj = st.nn_pos(a,jj); - const fd_type &fdij = std.fd[a][jj]; - const fd_type &fdji = std.fd[j][aa]; - const aed_type &aedj = std.get_aed(j); - const force_type fij = fpredict(fdij,aedi); - const force_type fji = fpredict(fdji,aedj); + const tadah::core::Vec3d &rj = st.nn_pos(a,jj); + const tadah::core::fd_type &fdij = std.fd[a][jj]; + const tadah::core::fd_type &fdji = std.fd[j][aa]; + const tadah::core::aed_type &aedj = std.get_aed(j); + const tadah::core::force_type fij = fpredict(fdij,aedi); + const tadah::core::force_type fji = fpredict(fdji,aedj); // S_xy = (\sum nn of i) r_i[x]f_i(y) + rj[x]f_j(y) // where f_i and f_j are the forces on the atom i and j respectively @@ -136,22 +138,22 @@ spredict(const size_t a, stress_type &s, void M_Tadah_Base:: stress_force_predict(const StDescriptors &std, Structure &st_) { - stress_type s; + tadah::core::stress_type s; s.set_zero(); double V_inv = 1/st_.get_volume(); for (size_t a=0; a<st_.natoms(); ++a) { - force_type v; - const Vec3d &ri = st_.atoms[a].position; - const aed_type &aedi = std.get_aed(a); + tadah::core::force_type v; + const tadah::core::Vec3d &ri = st_.atoms[a].position; + const tadah::core::aed_type &aedi = std.get_aed(a); for (size_t jj=0; jj<st_.nn_size(a); ++jj) { size_t j=st_.near_neigh_idx[a][jj]; const size_t aa = st_.get_nn_iindex(a,j,jj); - const Vec3d &rj = st_.nn_pos(a,jj); - const fd_type &fdij = std.fd[a][jj]; - const fd_type &fdji = std.fd[j][aa]; - const aed_type &aedj = std.get_aed(j); - const force_type fij = fpredict(fdij,aedi); - const force_type fji = fpredict(fdji,aedj); + const tadah::core::Vec3d &rj = st_.nn_pos(a,jj); + const tadah::core::fd_type &fdij = std.fd[a][jj]; + const tadah::core::fd_type &fdji = std.fd[j][aa]; + const tadah::core::aed_type &aedj = std.get_aed(j); + const tadah::core::force_type fij = fpredict(fdij,aedi); + const tadah::core::force_type fji = fpredict(fdji,aedj); v += fij; v -= fji; @@ -166,3 +168,5 @@ stress_force_predict(const StDescriptors &std, Structure &st_) } st_.stress = s; } +} // namespace mlip +} // namespace tadah diff --git a/src/materials_project_data_provider.cpp b/src/materials_project_data_provider.cpp index 35f86104a76d641e8399f764df5c1a0eb312b684..251ea0289bead235c35b60dd9557ec316dafb89a 100644 --- a/src/materials_project_data_provider.cpp +++ b/src/materials_project_data_provider.cpp @@ -2,6 +2,8 @@ #include <curl/curl.h> #include <stdexcept> #include <sstream> +namespace tadah { +namespace mlip { MaterialsProjectDataProvider::MaterialsProjectDataProvider(const std::string &apiKey) : m_apiKey(apiKey) @@ -91,3 +93,5 @@ RawResponse MaterialsProjectDataProvider::httpGet(const std::string &url) return rr; } +} // namespace mlip +} // namespace tadah diff --git a/src/materials_project_reader.cpp b/src/materials_project_reader.cpp index 51751d03065e5888170b2625abfdec101406a15f..3cb5e4eb56be49e88e2ceb6c30ac58faefe1c3a0 100644 --- a/src/materials_project_reader.cpp +++ b/src/materials_project_reader.cpp @@ -3,10 +3,12 @@ #include <nlohmann/json.hpp> #include <stdexcept> #include <sstream> +namespace tadah { +namespace mlip { -static Element parse_element_mp(const std::string &elemName) { +static tadah::core::Element parse_element_mp(const std::string &elemName) { // Same helper from your original code - return PeriodicTable().find_by_symbol(elemName); + return tadah::core::PeriodicTable().find_by_symbol(elemName); } MaterialsProjectReader::MaterialsProjectReader(const std::string &apiKey) @@ -108,7 +110,7 @@ void MaterialsProjectReader::parseMpJson(const std::string &jsonContent) { double y = fx*m_structure.cell(0,1) + fy*m_structure.cell(1,1) + fz*m_structure.cell(2,1); double z = fx*m_structure.cell(0,2) + fy*m_structure.cell(1,2) + fz*m_structure.cell(2,2); - // Element from either "label" or "species[0].element" + // tadah::core::Element from either "label" or "species[0].element" std::string elemSymbol; if (st.contains("label") && st["label"].is_string()) { elemSymbol = st["label"].get<std::string>(); @@ -119,11 +121,13 @@ void MaterialsProjectReader::parseMpJson(const std::string &jsonContent) { } Atom a; - Element e = parse_element_mp(elemSymbol); - static_cast<Element&>(a) = e; + tadah::core::Element e = parse_element_mp(elemSymbol); + static_cast<tadah::core::Element&>(a) = e; a.position[0] = x; a.position[1] = y; a.position[2] = z; m_structure.atoms.push_back(a); } } +} // namespace mlip +} // namespace tadah diff --git a/src/nn_finder.cpp b/src/nn_finder.cpp index 0c85f811a85ac9151e37898630e1bc6acc568c47..006fb2de9180d9d51885af978fc8d4b99c7331b6 100644 --- a/src/nn_finder.cpp +++ b/src/nn_finder.cpp @@ -7,9 +7,11 @@ #include <chrono> #include <iostream> #include <vector> +namespace tadah { +namespace mlip { // Constructor -NNFinder::NNFinder(Config &config) +NNFinder::NNFinder(tadah::core::Config &config) { cutoff = config.get<double>("RCUTMAX"); cutoff_sq = cutoff * cutoff; @@ -32,7 +34,7 @@ bool NNFinder::check_box(Structure &st) // --------------------------------------------------------------------------- void NNFinder::num_shifts(Structure &st, int N[3]) { - Matrix3d cell_inv = st.cell.inverse(); + tadah::core::Matrix3d cell_inv = st.cell.inverse(); double l1 = cell_inv.col(0).norm(); double l2 = cell_inv.col(1).norm(); @@ -67,20 +69,20 @@ void NNFinder::calc_naive(Structure &st) num_shifts(st, N); // Precompute shifts (both real displacement and integer triple if needed) - std::vector<Vec3d> shifts; - std::vector<Vec3d> shiftIdx; + std::vector<tadah::core::Vec3d> shifts; + std::vector<tadah::core::Vec3d> shiftIdx; shifts.reserve((2*N[0]+1)*(2*N[1]+1)*(2*N[2]+1)); shiftIdx.reserve((2*N[0]+1)*(2*N[1]+1)*(2*N[2]+1)); for (int n1 = -N[0]; n1 <= N[0]; n1++) { for (int n2 = -N[1]; n2 <= N[1]; n2++) { for (int n3 = -N[2]; n3 <= N[2]; n3++) { - Vec3d disp; + tadah::core::Vec3d disp; disp[0] = st.cell(0,0)*n1 + st.cell(1,0)*n2 + st.cell(2,0)*n3; disp[1] = st.cell(0,1)*n1 + st.cell(1,1)*n2 + st.cell(2,1)*n3; disp[2] = st.cell(0,2)*n1 + st.cell(1,2)*n2 + st.cell(2,2)*n3; shifts.push_back(disp); - shiftIdx.push_back(Vec3d(n1, n2, n3)); + shiftIdx.push_back(tadah::core::Vec3d(n1, n2, n3)); } } } @@ -96,8 +98,8 @@ void NNFinder::calc_naive(Structure &st) // Distance checks for (size_t s = 0; s < shifts.size(); s++) { - const Vec3d &disp = shifts[s]; - const Vec3d &dispIdxVal = shiftIdx[s]; + const tadah::core::Vec3d &disp = shifts[s]; + const tadah::core::Vec3d &dispIdxVal = shiftIdx[s]; bool selfShift = (dispIdxVal[0] == 0 && dispIdxVal[1] == 0 && dispIdxVal[2] == 0); size_t startA2 = (selfShift ? 1ul : 0ul); @@ -220,7 +222,7 @@ void NNFinder::calc_binned(Structure &st) double fracZ = double(dC)/double(nBinsC); // Real shift - Vec3d shiftDisp( + tadah::core::Vec3d shiftDisp( st.cell(0,0)*fracX + st.cell(0,1)*fracY + st.cell(0,2)*fracZ, st.cell(1,0)*fracX + st.cell(1,1)*fracY + st.cell(1,2)*fracZ, st.cell(2,0)*fracX + st.cell(2,1)*fracY + st.cell(2,2)*fracZ @@ -234,11 +236,11 @@ void NNFinder::calc_binned(Structure &st) if (dist2 < cutSQ) { // forward st.near_neigh_idx[idxA].push_back(idxB); - st.near_neigh_shift[idxA].push_back(Vec3d(dA, dB, dC)); + st.near_neigh_shift[idxA].push_back(tadah::core::Vec3d(dA, dB, dC)); // reverse st.near_neigh_idx[idxB].push_back(idxA); - st.near_neigh_shift[idxB].push_back(Vec3d(-dA, -dB, -dC)); + st.near_neigh_shift[idxB].push_back(tadah::core::Vec3d(-dA, -dB, -dC)); } } } @@ -284,3 +286,5 @@ void NNFinder::calc(StructureDB &stdb) // << seconds << " seconds\n"; } +} // namespace mlip +} // namespace tadah diff --git a/src/nomad_data_provider.cpp b/src/nomad_data_provider.cpp index eb638aac9bf081df98bc958f133d7f3e322e1476..b7fd559109ccfcccaf877531d21f79d4f2b42ce8 100644 --- a/src/nomad_data_provider.cpp +++ b/src/nomad_data_provider.cpp @@ -2,6 +2,8 @@ #include <curl/curl.h> #include <stdexcept> #include <sstream> +namespace tadah { +namespace mlip { size_t NomadDataProvider::writeCallback(char* ptr, size_t size, size_t nmemb, void* userdata) { @@ -88,3 +90,5 @@ RawResponse NomadDataProvider::httpPost(const std::string &url, const std::strin return rr; } +} // namespace mlip +} // namespace tadah diff --git a/src/nomad_reader.cpp b/src/nomad_reader.cpp index 4a15d35c3e11f7c4045d5bbb97805d02cf5f883e..d05dbcfa5254186163904a01538c123e9c4432ae 100644 --- a/src/nomad_reader.cpp +++ b/src/nomad_reader.cpp @@ -4,6 +4,8 @@ #include <stdexcept> #include <sstream> #include <cmath> +namespace tadah { +namespace mlip { NomadReader::NomadReader() : m_dataProvider(std::make_unique<NomadDataProvider>()) { @@ -113,8 +115,8 @@ void NomadReader::parseNomadJson(const std::string &jsonContent) { double z = pos[2].get<double>(); Atom atom; - Element e = PeriodicTable().find_by_symbol(speciesSites[i].get<std::string>()); - static_cast<Element &>(atom) = e; + tadah::core::Element e = tadah::core::PeriodicTable().find_by_symbol(speciesSites[i].get<std::string>()); + static_cast<tadah::core::Element &>(atom) = e; atom.position[0] = x; atom.position[1] = y; atom.position[2] = z; @@ -141,3 +143,5 @@ void NomadReader::makeCellMatrix(double a, double b, double c, cell[2][2] = c * std::sqrt(term > 0.0 ? term : 0.0); } +} // namespace mlip +} // namespace tadah diff --git a/src/plain_text_key_storage.cpp b/src/plain_text_key_storage.cpp index 014ba23191d0275bbb26c6de0bc8c39fe9235dea..8885c768f300899117fcabed175caf3ec9f5ba3b 100644 --- a/src/plain_text_key_storage.cpp +++ b/src/plain_text_key_storage.cpp @@ -11,6 +11,8 @@ #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> +namespace tadah { +namespace mlip { PlainTextKeyStorage::PlainTextKeyStorage() { @@ -138,3 +140,5 @@ bool PlainTextKeyStorage::writeAllKeys(const std::vector<std::pair<std::string, return true; } +} // namespace mlip +} // namespace tadah diff --git a/src/st_descriptors.cpp b/src/st_descriptors.cpp index a0407e8e1eb6f130332b15ad4121ab2bea6a14d2..6c495091e5d06fd7b318bff55c9adc62499bbfca 100644 --- a/src/st_descriptors.cpp +++ b/src/st_descriptors.cpp @@ -1,6 +1,8 @@ #include <tadah/mlip/st_descriptors.h> +namespace tadah { +namespace mlip { -StDescriptors::StDescriptors(const Structure &s, const Config &c): +StDescriptors::StDescriptors(const Structure &s, const tadah::core::Config &c): // fully initialize aed aeds(c.get<size_t>("DSIZE"), s.natoms()), // partially init fd @@ -9,10 +11,10 @@ StDescriptors::StDescriptors(const Structure &s, const Config &c): //sd(c.get<bool>("STRESS") ? c.get<size_t>("DSIZE"),6 : 0,6) { // fd: we still need to resize nn individually for each atom - // and init fd_type with size + // and init tadah::core::fd_type with size if (c.get<bool>("FORCE") || c.get<bool>("STRESS")) { for (size_t i=0; i<fd.size(); ++i) { - fd[i].resize(s.nn_size(i),fd_type(c.get<size_t>("DSIZE"))); + fd[i].resize(s.nn_size(i),tadah::core::fd_type(c.get<size_t>("DSIZE"))); //for (auto &v:fd[i]) v.set_zero(); } } @@ -31,14 +33,14 @@ StDescriptors::StDescriptors(const Structure &s, const Config &c): } StDescriptors::StDescriptors() {} -aed_type & StDescriptors::get_aed(const size_t i) { +tadah::core::aed_type & StDescriptors::get_aed(const size_t i) { return aeds.col(i); } -const aed_type &StDescriptors::get_aed(const size_t i) const { +const tadah::core::aed_type &StDescriptors::get_aed(const size_t i) const { return aeds.col(i); } -rho_type& StDescriptors::get_rho(const size_t i) { +tadah::core::rho_type& StDescriptors::get_rho(const size_t i) { return rhos.col(i); } size_t StDescriptors::naed() const { @@ -47,3 +49,5 @@ size_t StDescriptors::naed() const { size_t StDescriptors::dim() const { return aeds.rows(); } +} // namespace mlip +} // namespace tadah diff --git a/src/st_descriptors_db.cpp b/src/st_descriptors_db.cpp index 3dce74f8c5e21d70596c39a810406923ebbd990c..db43c70d95686bbcd9b30eb433ff7ee53bdacf58 100644 --- a/src/st_descriptors_db.cpp +++ b/src/st_descriptors_db.cpp @@ -1,6 +1,8 @@ #include <tadah/mlip/st_descriptors_db.h> +namespace tadah { +namespace mlip { -StDescriptorsDB::StDescriptorsDB(const StructureDB &stdb, Config &config): +StDescriptorsDB::StDescriptorsDB(const StructureDB &stdb, tadah::core::Config &config): st_descs(stdb.size()) { // init all StDescriptors @@ -33,3 +35,5 @@ std::vector<StDescriptors>::const_iterator StDescriptorsDB::begin() const { std::vector<StDescriptors>::const_iterator StDescriptorsDB::end() const { return st_descs.cend(); } +} // namespace mlip +} // namespace tadah diff --git a/src/statistics.cpp b/src/statistics.cpp index 255d86761eb19c2008b62246bdf9f8ea181677bd..e1af0544198d995ee3ce9b59c96884d6ffb9e018 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -1,6 +1,8 @@ #include <tadah/mlip/analytics/statistics.h> #include <cmath> +namespace tadah { +namespace mlip { double Statistics::res_sum_sq(const vec &obs, const vec &pred) { if (obs.size() != pred.size()) @@ -33,3 +35,5 @@ double Statistics::variance(const vec &v) { double Statistics::mean(const vec &v) { return v.mean(); } +} // namespace mlip +} // namespace tadah diff --git a/src/structure.cpp b/src/structure.cpp index fcb275c835763062bf6c9891c37f3822832938b0..8d6b1f00d8d1d225575332176f132f6f4b59e1bd 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -10,18 +10,20 @@ #include <sstream> #include <algorithm> #include <cstddef> +namespace tadah { +namespace mlip { /** * Creates and initializes a Structure object with default parameters. * Reason: Ensures all member variables are set to meaningful defaults. - * PeriodicTable is initialized to allow symbol lookups. + * tadah::core::PeriodicTable is initialized to allow symbol lookups. * * Example usage: * Structure st; // Creates an empty structure with zeroed data */ Structure::Structure() { - // PeriodicTable is prepared for atomic symbol lookups - PeriodicTable::initialize(); + // tadah::core::PeriodicTable is prepared for atomic symbol lookups + tadah::core::PeriodicTable::initialize(); // Zero or default values assigned to all members so there are no uninitialized values label.clear(); @@ -53,7 +55,7 @@ const Atom& Structure::operator()(const size_t i) const { * * Example usage: * Structure st; - * Atom a(Element("H"), 0.0, 0.1, 0.2); + * Atom a(tadah::core::Element("H"), 0.0, 0.1, 0.2); * st.add_atom(a); */ void Structure::add_atom(Atom a) { @@ -77,20 +79,20 @@ void Structure::remove_atom(const size_t i) { * * Example usage: * // Retrieve the neighbor's position (the 2nd neighbor of atom 0) - * Vec3d neighborPos = st.nn_pos(0, 1); + * tadah::core::Vec3d neighborPos = st.nn_pos(0, 1); */ -Vec3d Structure::nn_pos(const size_t i, const size_t n) const { +tadah::core::Vec3d Structure::nn_pos(const size_t i, const size_t n) const { // (A) Global index of this neighbor const size_t neighborIndex = near_neigh_idx[i][n]; // (B) Atom's original "unshifted" position - const Vec3d &posNeighbor = atoms[neighborIndex].position; + const tadah::core::Vec3d &posNeighbor = atoms[neighborIndex].position; // (C) Convert the stored shift -> real displacement shiftDisp // If near_neigh_shift[i][n] is an integer triple (n1, n2, n3), // multiply by the cell. Otherwise, if it's already in real space, it may simply be added. - Vec3d shift = near_neigh_shift[i][n]; // Possibly an integer triple - Vec3d shiftDisp; + tadah::core::Vec3d shift = near_neigh_shift[i][n]; // Possibly an integer triple + tadah::core::Vec3d shiftDisp; shiftDisp[0] = shift[0] * cell(0,0) + shift[1] * cell(0,1) + shift[2] * cell(0,2); shiftDisp[1] = shift[0] * cell(1,0) + shift[1] * cell(1,1) + shift[2] * cell(1,2); shiftDisp[2] = shift[0] * cell(2,0) + shift[1] * cell(2,1) + shift[2] * cell(2,2); @@ -190,7 +192,7 @@ int Structure::read(std::ifstream &ifs) { std::istringstream tmp(line); tmp >> symbol >> px >> py >> pz >> fx >> fy >> fz; - Element e = PeriodicTable::find_by_symbol(symbol); + tadah::core::Element e = tadah::core::PeriodicTable::find_by_symbol(symbol); atoms.push_back(Atom(e, px, py, pz, fx, fy, fz)); } return 0; @@ -283,7 +285,7 @@ void Structure::save(const std::string fn) const { * size_t ii = get_nn_iindex(i, j, jj); */ size_t Structure::get_nn_iindex(const size_t i, const size_t j, const size_t jj) const { - Vec3d shift_ijj = -near_neigh_shift[i][jj]; + tadah::core::Vec3d shift_ijj = -near_neigh_shift[i][jj]; size_t ii = 0; for (size_t x = 0; x < near_neigh_idx[j].size(); ++x) { if (near_neigh_idx[j][x] == i) { @@ -317,7 +319,7 @@ double Structure::get_density() const { double amu = 1.66053906660e-24; // 1 atomic mass unit in grams double mass = 0.0; for (const auto& a : atoms) { - mass += PeriodicTable::get_mass(a.Z); // sum of atomic masses + mass += tadah::core::PeriodicTable::get_mass(a.Z); // sum of atomic masses } return amu * mass / V; } @@ -550,13 +552,15 @@ void Structure::dump_to_file(const std::string &filepath, size_t prec) const { * Reason: Identifies the chemical variety present in the structure. * * Example usage: - * std::set<Element> elements = st.get_unique_elements(); + * std::set<tadah::core::Element> elements = st.get_unique_elements(); */ -std::set<Element> Structure::get_unique_elements() const { - std::set<Element> unique_elements; +std::set<tadah::core::Element> Structure::get_unique_elements() const { + std::set<tadah::core::Element> unique_elements; for (const auto &a : atoms) { unique_elements.insert(a); } return unique_elements; } +} // namespace mlip +} // namespace tadah diff --git a/src/structure_db.cpp b/src/structure_db.cpp index 698ad4223a682b31efba6e386d6d2ca0ca19af1a..7028155cf4ea0c6f8446bcd5b1ae09b719be2630 100644 --- a/src/structure_db.cpp +++ b/src/structure_db.cpp @@ -3,12 +3,14 @@ #include <tadah/core/periodic_table.h> #include <cstdio> #include <cctype> // For std::isspace +namespace tadah { +namespace mlip { StructureDB::StructureDB() { - PeriodicTable::initialize(); + tadah::core::PeriodicTable::initialize(); } -StructureDB::StructureDB(Config &config) { - PeriodicTable::initialize(); +StructureDB::StructureDB(tadah::core::Config &config) { + tadah::core::PeriodicTable::initialize(); add(config); } @@ -68,7 +70,7 @@ void StructureDB::remove(size_t i) { structures.erase(structures.begin()+i); } -void StructureDB::add(Config &config) { +void StructureDB::add(tadah::core::Config &config) { for (const std::string &s : config("DBFILE")) { dbidx.push_back(size()); add(s); @@ -109,16 +111,16 @@ size_t StructureDB::calc_natoms(size_t n) const { } return natoms; } -std::set<Element> StructureDB::get_unique_elements() const { - std::set<Element> s; +std::set<tadah::core::Element> StructureDB::get_unique_elements() const { + std::set<tadah::core::Element> s; for (const auto & st: structures) { - std::set<Element> u = st.get_unique_elements(); + std::set<tadah::core::Element> u = st.get_unique_elements(); s.insert(u.cbegin(),u.cend()); } return s; } -std::set<Element> StructureDB::find_unique_elements(const std::string &fn) { - std::set<Element> s; +std::set<tadah::core::Element> StructureDB::find_unique_elements(const std::string &fn) { + std::set<tadah::core::Element> s; std::ifstream ifs(fn); std::string line; @@ -144,16 +146,16 @@ std::set<Element> StructureDB::find_unique_elements(const std::string &fn) { while (std::getline(ifs, line)) { if(line.empty()) break; sscanf(line.c_str(), "%2s", symbol); - s.insert(PeriodicTable::find_by_symbol(symbol)); + s.insert(tadah::core::PeriodicTable::find_by_symbol(symbol)); } } return s; } -std::set<Element> StructureDB::find_unique_elements(const Config &c) { - std::set<Element> s; +std::set<tadah::core::Element> StructureDB::find_unique_elements(const tadah::core::Config &c) { + std::set<tadah::core::Element> s; for (const auto& fn: c("DBFILE")) { - std::set<Element> temp = find_unique_elements(fn); + std::set<tadah::core::Element> temp = find_unique_elements(fn); s.insert(temp.begin(), temp.end()); } return s; @@ -163,7 +165,7 @@ template <typename T,typename U> std::pair<T,U> operator+(const std::pair<T,U> &l,const std::pair<T,U> &r) { return {l.first+r.first,l.second+r.second}; } -std::pair<int,int> StructureDB::count(const Config &config) { +std::pair<int,int> StructureDB::count(const tadah::core::Config &config) { std::pair<int, int> res=std::make_pair(0,0); for (const std::string &fn : config("DBFILE")) { res = res + count(fn); @@ -192,7 +194,7 @@ std::pair<int,int> StructureDB::count(const std::string fn){ void StructureDB::clear_nn() { for (auto &struc: structures) struc.clear_nn(); } -void StructureDB::check_atoms_key(Config &config, std::set<Element> &unique_elements) { +void StructureDB::check_atoms_key(tadah::core::Config &config, std::set<tadah::core::Element> &unique_elements) { bool error=false; if (config.exist("ATOMS")) { @@ -221,7 +223,7 @@ void StructureDB::check_atoms_key(Config &config, std::set<Element> &unique_elem for (const auto &s : unique_elements) config.add("ATOMS", s.symbol); } } -void StructureDB::check_watoms_key(Config &config, std::set<Element> &unique_elements) { +void StructureDB::check_watoms_key(tadah::core::Config &config, std::set<tadah::core::Element> &unique_elements) { bool error=false; if (config.exist("WATOMS")) { @@ -286,7 +288,7 @@ std::string StructureDB::summary() const { str += " | # of atoms : " + to_string(calc_natoms()); str += " | Elements : "; - std::set<Element> ue = get_unique_elements(); + std::set<tadah::core::Element> ue = get_unique_elements(); for (const auto &e: ue) str+= e.symbol + " "; str+="\n"; return str; @@ -366,3 +368,5 @@ bool StructureDB::isBlankLine(const std::string& line) const } return true; } +} // namespace mlip +} // namespace tadah diff --git a/src/structure_properties.cpp b/src/structure_properties.cpp index 3f61064792b689ee0fac6fc668b1181c4efc703f..c7a7db662f720a0e266b93dc48925da61d19e494 100644 --- a/src/structure_properties.cpp +++ b/src/structure_properties.cpp @@ -2,13 +2,15 @@ #include <tadah/core/periodic_table.h> #include <stdexcept> #include <cmath> +namespace tadah { +namespace mlip { double StructureProperties::getVolume(const Structure &st) { // Columns of st.cell => a1, a2, a3 - Vec3d a1(st.cell(0,0), st.cell(1,0), st.cell(2,0)); - Vec3d a2(st.cell(0,1), st.cell(1,1), st.cell(2,1)); - Vec3d a3(st.cell(0,2), st.cell(1,2), st.cell(2,2)); + tadah::core::Vec3d a1(st.cell(0,0), st.cell(1,0), st.cell(2,0)); + tadah::core::Vec3d a2(st.cell(0,1), st.cell(1,1), st.cell(2,1)); + tadah::core::Vec3d a3(st.cell(0,2), st.cell(1,2), st.cell(2,2)); double volume = a1 * (a2.cross(a3)); // scalar triple product return volume; // [Å^3] @@ -25,7 +27,7 @@ double StructureProperties::getDensity(const Structure &st) // Sum atomic mass in amu double totalMassAmu = 0.0; for (const auto &atom : st.atoms) { - totalMassAmu += PeriodicTable::get_mass(atom.Z); + totalMassAmu += tadah::core::PeriodicTable::get_mass(atom.Z); } // Convert Å^3 => cm^3 double volumeCm3 = volumeA3 * 1.0e-24; @@ -38,16 +40,16 @@ double StructureProperties::getDensity(const Structure &st) return rho; } -Vec3d StructureProperties::getCentreOfMass(const Structure &st) +tadah::core::Vec3d StructureProperties::getCentreOfMass(const Structure &st) { if (st.atoms.empty()) { - return Vec3d(0.0, 0.0, 0.0); + return tadah::core::Vec3d(0.0, 0.0, 0.0); } double totalMass = 0.0; - Vec3d com(0.0, 0.0, 0.0); + tadah::core::Vec3d com(0.0, 0.0, 0.0); for (const auto &atom : st.atoms) { - double mass = PeriodicTable::get_mass(atom.Z); // amu + double mass = tadah::core::PeriodicTable::get_mass(atom.Z); // amu com += atom.position * mass; totalMass += mass; } @@ -57,15 +59,17 @@ Vec3d StructureProperties::getCentreOfMass(const Structure &st) return com; } -Vec3d StructureProperties::getGeometricCenter(const Structure &st) +tadah::core::Vec3d StructureProperties::getGeometricCenter(const Structure &st) { if (st.atoms.empty()) { - return Vec3d(0.0, 0.0, 0.0); + return tadah::core::Vec3d(0.0, 0.0, 0.0); } - Vec3d c(0.0, 0.0, 0.0); + tadah::core::Vec3d c(0.0, 0.0, 0.0); for (auto &atom : st.atoms) { c += atom.position; } c /= (double)st.atoms.size(); return c; } +} // namespace mlip +} // namespace tadah diff --git a/src/structure_reader_selector.cpp b/src/structure_reader_selector.cpp index 1fb86aa9a281a83d8e0eb814516ea26485abc6aa..526776916bc169d8a052f38290359dd1fe64a857 100644 --- a/src/structure_reader_selector.cpp +++ b/src/structure_reader_selector.cpp @@ -13,6 +13,8 @@ #include <fstream> #include <stdexcept> #include <sys/stat.h> +namespace tadah { +namespace mlip { std::unique_ptr<IStructureReader> StructureReaderSelector::getReader(const std::string &pathOrId) { @@ -129,7 +131,7 @@ bool isLikelyPoscar(const std::string &filepath) { // 3) Lattice vector line #1 // 4) Lattice vector line #2 // 5) Lattice vector line #3 - // 6) Element symbols or counts + // 6) tadah::core::Element symbols or counts // 7) Possibly more lines (atom counts / Selective Dynamics / coordinates, etc.) std::string line; @@ -327,3 +329,5 @@ StructureReaderSelector::guessFormatFromContent(const std::string &filePath) { return "UNKNOWN"; } +} // namespace mlip +} // namespace tadah diff --git a/src/structure_transformations.cpp b/src/structure_transformations.cpp index f0c8ecdd97f017f2b12c40e0a7c7e42be825af06..d0ade235fd2673a750c3507a178ccf81536b0a36 100644 --- a/src/structure_transformations.cpp +++ b/src/structure_transformations.cpp @@ -4,13 +4,15 @@ #include <iostream> #include <stdexcept> #include <cmath> +namespace tadah { +namespace mlip { namespace { /** Local utility function: multiply 3x3 matrices. */ -Matrix3d matMul(const Matrix3d &A, const Matrix3d &B) +tadah::core::Matrix3d matMul(const tadah::core::Matrix3d &A, const tadah::core::Matrix3d &B) { - Matrix3d C; + tadah::core::Matrix3d C; for (int i=0; i<3; i++) { for (int j=0; j<3; j++) { C(i,j) = A(i,0)*B(0,j) + A(i,1)*B(1,j) + A(i,2)*B(2,j); @@ -35,10 +37,10 @@ double StructureTransformation::rand01() return dist(globalRng()); } -void StructureTransformation::transformStress(Structure &st, const Matrix3d &M) +void StructureTransformation::transformStress(Structure &st, const tadah::core::Matrix3d &M) { - Matrix3d tmp = matMul(M, st.stress); - Matrix3d Mt = M.transpose(); + tadah::core::Matrix3d tmp = matMul(M, st.stress); + tadah::core::Matrix3d Mt = M.transpose(); st.stress = matMul(tmp, Mt); } @@ -86,7 +88,7 @@ void StructureTransformation::scaleVolumeToDensity(Structure &st, double targetD // total mass in grams double totalMassAmu = 0.0; for (auto &atom : st.atoms) { - totalMassAmu += PeriodicTable::get_mass(atom.Z); + totalMassAmu += tadah::core::PeriodicTable::get_mass(atom.Z); } double totalMassGrams = totalMassAmu * 1.66053906660e-24; // amu->g @@ -98,7 +100,7 @@ void StructureTransformation::scaleVolumeToDensity(Structure &st, double targetD scaleToVolume(st, volumeA3); } -void StructureTransformation::rotate(Structure &st, const Matrix3d &R) +void StructureTransformation::rotate(Structure &st, const tadah::core::Matrix3d &R) { st.cell = matMul(R, st.cell); for (auto &atom : st.atoms) { @@ -108,7 +110,7 @@ void StructureTransformation::rotate(Structure &st, const Matrix3d &R) checkNearSingular(st); } -void StructureTransformation::shear(Structure &st, const Matrix3d &shearMatrix) +void StructureTransformation::shear(Structure &st, const tadah::core::Matrix3d &shearMatrix) { st.cell = matMul(shearMatrix, st.cell); for (auto &atom : st.atoms) { @@ -126,7 +128,7 @@ void StructureTransformation::replicate(Structure &st, int nx, int ny, int nz) size_t origNatoms = st.atoms.size(); std::vector<Atom> originalAtoms = st.atoms; - Matrix3d oldCell = st.cell; + tadah::core::Matrix3d oldCell = st.cell; // Scale cell st.cell(0,0) *= nx; @@ -141,10 +143,10 @@ void StructureTransformation::replicate(Structure &st, int nx, int ny, int nz) for (int iy=0; iy<ny; iy++) { for (int iz=0; iz<nz; iz++) { // shift vector in oldCell coords - Vec3d shiftVec = - ix*Vec3d(oldCell(0,0), oldCell(1,0), oldCell(2,0)) + - iy*Vec3d(oldCell(0,1), oldCell(1,1), oldCell(2,1)) + - iz*Vec3d(oldCell(0,2), oldCell(1,2), oldCell(2,2)); + tadah::core::Vec3d shiftVec = + ix*tadah::core::Vec3d(oldCell(0,0), oldCell(1,0), oldCell(2,0)) + + iy*tadah::core::Vec3d(oldCell(0,1), oldCell(1,1), oldCell(2,1)) + + iz*tadah::core::Vec3d(oldCell(0,2), oldCell(1,2), oldCell(2,2)); for (const auto &atom : originalAtoms) { Atom newAtom = atom; newAtom.position += shiftVec; @@ -158,7 +160,7 @@ void StructureTransformation::replicate(Structure &st, int nx, int ny, int nz) checkNearSingular(st); } -void StructureTransformation::shift(Structure &st, const Vec3d &shiftVec) +void StructureTransformation::shift(Structure &st, const tadah::core::Vec3d &shiftVec) { for (auto &atom : st.atoms) { atom.position += shiftVec; @@ -174,9 +176,9 @@ void StructureTransformation::mirrorOrigin(Structure &st) // Reflection M = -I => S'=S. (No net effect if we do M*S*M^T.) } -void StructureTransformation::mirrorPlane(Structure &st, const Vec3d &normalVec) +void StructureTransformation::mirrorPlane(Structure &st, const tadah::core::Vec3d &normalVec) { - Vec3d n = normalVec; + tadah::core::Vec3d n = normalVec; double len = n.norm(); if (len < 1e-14) { throw std::invalid_argument("Plane normal is near zero length."); @@ -189,7 +191,7 @@ void StructureTransformation::mirrorPlane(Structure &st, const Vec3d &normalVec) } // M = I - 2 n n^T - Matrix3d M = Matrix3d::Identity(); + tadah::core::Matrix3d M = tadah::core::Matrix3d::Identity(); for (int i=0; i<3; i++) { for (int j=0; j<3; j++) { M(i,j) -= 2.0 * n[i]*n[j]; @@ -204,28 +206,28 @@ void StructureTransformation::mirrorHkl(Structure &st, int h, int k, int l) throw std::invalid_argument("Miller indices (0,0,0) do not define a plane."); } // Build a1,a2,a3 from st.cell columns: - Vec3d a1(st.cell(0,0), st.cell(1,0), st.cell(2,0)); - Vec3d a2(st.cell(0,1), st.cell(1,1), st.cell(2,1)); - Vec3d a3(st.cell(0,2), st.cell(1,2), st.cell(2,2)); + tadah::core::Vec3d a1(st.cell(0,0), st.cell(1,0), st.cell(2,0)); + tadah::core::Vec3d a2(st.cell(0,1), st.cell(1,1), st.cell(2,1)); + tadah::core::Vec3d a3(st.cell(0,2), st.cell(1,2), st.cell(2,2)); - Vec3d crossA2A3 = a2.cross(a3); + tadah::core::Vec3d crossA2A3 = a2.cross(a3); double denomA1 = a1.dot(crossA2A3); - Vec3d b1 = crossA2A3 / denomA1; + tadah::core::Vec3d b1 = crossA2A3 / denomA1; - Vec3d crossA3A1 = a3.cross(a1); + tadah::core::Vec3d crossA3A1 = a3.cross(a1); double denomA2 = a2.dot(crossA3A1); - Vec3d b2 = crossA3A1 / denomA2; + tadah::core::Vec3d b2 = crossA3A1 / denomA2; - Vec3d crossA1A2 = a1.cross(a2); + tadah::core::Vec3d crossA1A2 = a1.cross(a2); double denomA3 = a3.dot(crossA1A2); - Vec3d b3 = crossA1A2 / denomA3; + tadah::core::Vec3d b3 = crossA1A2 / denomA3; - Vec3d g = (double)h*b1 + (double)k*b2 + (double)l*b3; + tadah::core::Vec3d g = (double)h*b1 + (double)k*b2 + (double)l*b3; double normG = g.norm(); if (normG < 1e-14) { throw std::runtime_error("Plane normal is near zero. Check cell or (h,k,l)."); } - Vec3d n = g / normG; + tadah::core::Vec3d n = g / normG; // reflection for (auto &atom : st.atoms) { @@ -234,7 +236,7 @@ void StructureTransformation::mirrorHkl(Structure &st, int h, int k, int l) } // reflection matrix - Matrix3d M = Matrix3d::Identity(); + tadah::core::Matrix3d M = tadah::core::Matrix3d::Identity(); for (int i=0; i<3; i++) { for (int j=0; j<3; j++) { M(i,j) -= 2.0 * n[i]*n[j]; @@ -245,7 +247,7 @@ void StructureTransformation::mirrorHkl(Structure &st, int h, int k, int l) void StructureTransformation::center(Structure &st, bool useCenterOfMass, bool shiftCell) { - Vec3d c; + tadah::core::Vec3d c; if (useCenterOfMass) { c = StructureProperties::getCentreOfMass(st); } else { @@ -281,10 +283,10 @@ void StructureTransformation::remapToCell(Structure &st) if (std::fabs(vol) < 1e-14) { throw std::runtime_error("Volume is near zero, cannot remap to cell."); } - Matrix3d invCell = st.cell.inverse(); + tadah::core::Matrix3d invCell = st.cell.inverse(); for (auto &atom : st.atoms) { - Vec3d frac = invCell * atom.position; + tadah::core::Vec3d frac = invCell * atom.position; for (int i=0; i<3; i++) { frac[i] -= std::floor(frac[i]); } @@ -296,20 +298,20 @@ void StructureTransformation::addAtom( Structure &st, const Atom &atomTemplate, bool useRandomPosition, - const Vec3d &pos, + const tadah::core::Vec3d &pos, double minDistance ){ Atom newAtom = atomTemplate; if (useRandomPosition) { // place randomly in [0,1) fractional, then convert => Cartesian - Matrix3d invCell = st.cell.inverse(); + tadah::core::Matrix3d invCell = st.cell.inverse(); double vol = StructureProperties::getVolume(st); if (std::fabs(vol) < 1e-14) { throw std::runtime_error("Cannot add atom randomly: volume near zero."); } - Vec3d frac(rand01(), rand01(), rand01()); + tadah::core::Vec3d frac(rand01(), rand01(), rand01()); newAtom.position = st.cell * frac; } else { newAtom.position = pos; @@ -355,3 +357,5 @@ void StructureTransformation::shakeAtoms(Structure &st, double maxDisplacement) } } +} // namespace mlip +} // namespace tadah diff --git a/src/structure_writer_selector.cpp b/src/structure_writer_selector.cpp index c469534b40e25e8f3c7533ea240d5355ae14af1d..653647646ef7566b44ba5ea075f1dbba7e5585b8 100644 --- a/src/structure_writer_selector.cpp +++ b/src/structure_writer_selector.cpp @@ -2,6 +2,8 @@ #include <tadah/mlip/structure_writers/castep_cell_writer.h> #include <tadah/mlip/structure_writers/vasp_poscar_writer.h> #include <tadah/mlip/structure_writers/lammps_structure_writer.h> +namespace tadah { +namespace mlip { // Factory method implementation std::unique_ptr<StructureWriter> StructureWriterSelector::get_writer(const std::string& type, StructureDB& db) { @@ -18,3 +20,5 @@ std::unique_ptr<StructureWriter> StructureWriterSelector::get_writer(const std:: } } +} // namespace mlip +} // namespace tadah diff --git a/src/vasp_outcar_reader.cpp b/src/vasp_outcar_reader.cpp index d1ead35e7ecb00f1c860d7559574f78e475af0e9..74dc8e704bcaa7a1b2b77b928355cca796a89239 100644 --- a/src/vasp_outcar_reader.cpp +++ b/src/vasp_outcar_reader.cpp @@ -6,6 +6,8 @@ #include <fstream> #include <iostream> #include <stdexcept> +namespace tadah { +namespace mlip { VaspOutcarReader::VaspOutcarReader(StructureDB& db) : DatasetReader(db) {} @@ -140,7 +142,7 @@ void VaspOutcarReader::parse_data() { } size_t count = 0; for (size_t j = 0; j < natom_types.size(); ++j) { - Element element(atom_types[j]); + tadah::core::Element element(atom_types[j]); for (size_t i = 0; i < natom_types[j]; ++i) { if (!std::getline(stream, line)) { std::cerr << "Warning: Unexpected end of data when reading atom information at atom " << count+1 << std::endl; @@ -208,3 +210,5 @@ void VaspOutcarReader::print_summary() const { std::string VaspOutcarReader::get_summary() const { return stdb.summary(); } +} // namespace mlip +} // namespace tadah diff --git a/src/vasp_poscar_reader.cpp b/src/vasp_poscar_reader.cpp index d349c0403376ce3deb8e5f8110f94a64b24a9693..c0a72f6b99dd7e9f90408338ad7040dae0983dce 100644 --- a/src/vasp_poscar_reader.cpp +++ b/src/vasp_poscar_reader.cpp @@ -5,6 +5,8 @@ #include <stdexcept> #include <tadah/mlip/structure_readers/vasp_poscar_reader.h> #include <vector> +namespace tadah { +namespace mlip { // A small helper to parse each line into tokens static std::vector<std::string> split(const std::string &str); @@ -168,8 +170,8 @@ void VaspPoscarReader::parsePoscar(const std::vector<std::string> &lines) { Atom a; // parse element from atomSymbols[i] if you maintain a map // For brevity, store minimal approach: - Element e = PeriodicTable().find_by_symbol(atomSymbols[i]); - static_cast<Element &>(a) = e; + tadah::core::Element e = tadah::core::PeriodicTable().find_by_symbol(atomSymbols[i]); + static_cast<tadah::core::Element &>(a) = e; if (directCoords) { // Convert fractional -> cart @@ -202,3 +204,5 @@ static std::vector<std::string> split(const std::string &str) { } return tokens; } +} // namespace mlip +} // namespace tadah diff --git a/src/vasp_poscar_writer.cpp b/src/vasp_poscar_writer.cpp index f37897d3870bc92bbb0c2305ae9f4bef60299694..1fdf354f45573a1572784b0ce5d29d6f8a3ac836 100644 --- a/src/vasp_poscar_writer.cpp +++ b/src/vasp_poscar_writer.cpp @@ -3,6 +3,8 @@ #include <tadah/mlip/structure_writers/vasp_poscar_writer.h> #include <fstream> +namespace tadah { +namespace mlip { VaspPoscarWriter::VaspPoscarWriter(StructureDB& db) : StructureWriter(db) {} @@ -77,3 +79,5 @@ void VaspPoscarWriter::write_data(const std::string& filename, const size_t i) { file.close(); } +} // namespace mlip +} // namespace tadah diff --git a/src/vasp_vasprun_reader.cpp b/src/vasp_vasprun_reader.cpp index c6917d31174be17004b1f9e8be6c6ef6c14a04d6..82e35f5f49bfdaf16c035f0063e075d61d61bd9e 100644 --- a/src/vasp_vasprun_reader.cpp +++ b/src/vasp_vasprun_reader.cpp @@ -1,4 +1,6 @@ #include <tadah/mlip/dataset_readers/vasp_vasprun_reader.h> +namespace tadah { +namespace mlip { VaspVasprunReader::VaspVasprunReader(StructureDB& stdb) : DatasetReader(stdb), stdb(stdb) {} @@ -194,7 +196,7 @@ void VaspVasprunReader::extract_basis_vectors_and_positions(rx::xml_node<> *stru if (index < atom_types.size()) { std::stringstream ss(v_node->value()); if (ss >> x >> y >> z) { // relative positions - _s.add_atom(Atom(Element(atom_types[index]), x, y, z, 0, 0, 0)); + _s.add_atom(Atom(tadah::core::Element(atom_types[index]), x, y, z, 0, 0, 0)); _s.atoms.back().position = _s.cell * _s.atoms.back().position; // convert to abs } else { std::cerr << "Error parsing atom positions." << std::endl; @@ -240,3 +242,5 @@ void VaspVasprunReader::print_summary() const { std::string VaspVasprunReader::get_summary() const { return stdb.summary(); } +} // namespace mlip +} // namespace tadah